Skip to content

Commit

Permalink
add mod
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Jul 9, 2023
1 parent edce3b6 commit 12040ad
Show file tree
Hide file tree
Showing 23 changed files with 747 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DevEnv.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<GameDir>F:\Steam\steamapps\common\Outer Wilds</GameDir>
<OwmlDir>$(AppData)\OuterWildsModManager\OWML</OwmlDir>
<UnityAssetsDir>$(SolutionDir)\qsb-unityproject\Assets</UnityAssetsDir>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions DevEnv.template.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OwmlDir>$(AppData)\OuterWildsModManager\OWML</OwmlDir>
</PropertyGroup>
</Project>
29 changes: 29 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project>

<PropertyGroup>
<DevEnvLoc>$(MSBuildThisFileDirectory)DevEnv.targets</DevEnvLoc>
</PropertyGroup>
<Import Project="$(DevEnvLoc)" Condition="Exists('$(DevEnvLoc)')" />

<PropertyGroup Label="Common Properties">
<TargetFramework>net48</TargetFramework>
<LangVersion>default</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Company>Henry Pointer</Company>
<Copyright>Copyright © Henry Pointer 2023</Copyright>
</PropertyGroup>

<PropertyGroup Label="Default Locations" Condition="!Exists('$(DevEnvLoc)')">
<OwmlDir>$(AppData)\OuterWildsModManager\OWML</OwmlDir>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>none</DebugType>
</PropertyGroup>

</Project>
49 changes: 49 additions & 0 deletions QSBMultipleShips/Core.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using OWML.ModHelper;
using QSB;
using QSB.Utility;
using QSBMultipleShips.TransformSyncs;
using UnityEngine;

namespace QSBMultipleShips;

public class Core : ModBehaviour
{
public static Core Instance { get; private set; }

public GameObject CockpitPrefab { get; private set; }
public GameObject CabinPrefab { get; private set; }
public GameObject SuppliesPrefab { get; private set; }
public GameObject EnginePrefab { get; private set; }
public GameObject FrontLandingPrefab { get; private set; }
public GameObject LeftLandingPrefab { get; private set; }
public GameObject RightLandingPrefab { get; private set; }

public void Awake()
{
Instance = this;
}

public void Start()
{
CockpitPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_Cockpit", typeof(ShipCockpitTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(CockpitPrefab);

CabinPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_Cabin", typeof(ShipCabinTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(CabinPrefab);

FrontLandingPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_FrontLanding", typeof(ShipFrontLandingGearTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(FrontLandingPrefab);

LeftLandingPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_LeftLanding", typeof(ShipLeftLandingGearTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(LeftLandingPrefab);

RightLandingPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_RightLanding", typeof(ShipRightLandingGearTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(RightLandingPrefab);

SuppliesPrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_Supplies", typeof(ShipSuppliesTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(SuppliesPrefab);

EnginePrefab = QSBNetworkManager.MakeNewNetworkObject("NetworkShip_Engine", typeof(ShipEngineTransformSync));
QSBNetworkManager.singleton.spawnPrefabs.Add(EnginePrefab);
}
}
83 changes: 83 additions & 0 deletions QSBMultipleShips/CustomHatchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using UnityEngine;

namespace QSBMultipleShips;
public class CustomHatchController : MonoBehaviour
{
public Transform _hatch;

private bool _hatchOpening;
private bool _hatchClosing;
private float _timeSinceRotation;
private Quaternion _hatchClosedQuaternion;
private Quaternion _hatchOpenedQuaternion;

private void Awake()
{
_hatchClosedQuaternion = Quaternion.Euler(new Vector3(180, 0, 0));
_hatchOpenedQuaternion = Quaternion.Euler(new Vector3(0, 0, 0));
enabled = false;
}

private void FixedUpdate()
{
if (_hatchOpening && _hatch.localRotation != _hatchOpenedQuaternion)
{
if (_timeSinceRotation == 0.5f)
{
_timeSinceRotation = 0f;
}

_hatch.localRotation = Quaternion.Lerp(_hatchClosedQuaternion, _hatchOpenedQuaternion, _timeSinceRotation / 0.5f);
_timeSinceRotation += Time.deltaTime;
if (_timeSinceRotation >= 0.5f)
{
_hatch.localRotation = _hatchOpenedQuaternion;
_timeSinceRotation = 0.5f;
_hatchOpening = false;
enabled = false;
return;
}
}
else if (_hatchClosing && _hatch.localRotation != _hatchClosedQuaternion)
{
if (_timeSinceRotation == 0.5f)
{
_timeSinceRotation = 0f;
}

_hatch.localRotation = Quaternion.Lerp(_hatchOpenedQuaternion, _hatchClosedQuaternion, _timeSinceRotation / 0.5f);
_timeSinceRotation += Time.deltaTime;
if (_timeSinceRotation >= 0.5f)
{
_hatch.localRotation = _hatchClosedQuaternion;
_timeSinceRotation = 0.5f;
_hatchClosing = false;
enabled = false;
}
}
}

public void OpenHatch()
{
/*if (this._shipAudioController == null)
{
this._shipAudioController = Locator.GetShipTransform().GetComponentInChildren<ShipAudioController>();
}
this._shipAudioController.PlayOpenHatch();*/
enabled = true;
_hatchOpening = true;
_hatchClosing = false;
}

public void CloseHatch()
{
/*if (this._shipAudioController == null)
{
this._shipAudioController = Locator.GetShipTransform().GetComponentInChildren<ShipAudioController>();
}
this._shipAudioController.PlayCloseHatch();*/
enabled = true;
_hatchClosing = true;
_hatchOpening = false;
}
}
43 changes: 43 additions & 0 deletions QSBMultipleShips/CustomPulsingLight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEngine;

namespace QSBMultipleShips;
internal class CustomPulsingLight : MonoBehaviour
{
private static MaterialPropertyBlock s_matPropBlock;
private static int s_propID_EmissionColor;
private Light _light;

public Renderer _emissiveRenderer;
public int _materialIndex;
public float _pulseRate = 1f;
public float _intensityFluctuation;
public float _rangeFluctuation;
public float _timeOffset;

public float _initLightIntensity;
public float _initLightRange;
public Color _initEmissionColor;

private void Awake()
{
_light = GetComponent<Light>();
if (s_matPropBlock == null)
{
s_matPropBlock = new MaterialPropertyBlock();
s_propID_EmissionColor = Shader.PropertyToID("_EmissionColor");
}
}

private void Update()
{
var num = Mathf.Sin((Time.time + _timeOffset) * _pulseRate);
_light.intensity = num * _intensityFluctuation + _initLightIntensity;
_light.range = num * _rangeFluctuation + _initLightRange;
if (_emissiveRenderer != null)
{
var num2 = Mathf.Max(_light.intensity / _initLightIntensity, 0f);
s_matPropBlock.SetColor(s_propID_EmissionColor, num2 * num2 * _initEmissionColor);
_emissiveRenderer.SetPropertyBlock(s_matPropBlock);
}
}
}
28 changes: 28 additions & 0 deletions QSBMultipleShips/Messages/HatchMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using QSB.Messaging;
using QSB.Player;
using QSBMultipleShips.TransformSyncs;

namespace QSBMultipleShips.Messages;
internal class HatchMessage : QSBMessage<bool>
{
public HatchMessage(bool open) : base(open) { }

public override void OnReceiveRemote()
{
var cabin = QSBPlayerManager.GetPlayer(From).GetCustomData<ShipCabinTransformSync>("Cabin");

if (cabin == null)
{
return;
}

if (Data)
{
cabin.Hatch.OpenHatch();
}
else
{
cabin.Hatch.CloseHatch();
}
}
}
24 changes: 24 additions & 0 deletions QSBMultipleShips/Messages/HeadlightMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
using QSBMultipleShips.TransformSyncs;

namespace QSBMultipleShips.Messages;
internal class HeadlightMessage : QSBMessage<bool>
{
public HeadlightMessage(bool on) : base(on) { }

public override void OnReceiveRemote()
{
var landingGear = QSBPlayerManager.GetPlayer(From).GetCustomData<ShipFrontLandingGearTransformSync>("FrontLandingGear");

if (landingGear == null)
{
return;
}

DebugLog.DebugWrite($"headlight SetOn {Data}");
var shipLight = landingGear.Headlight;
shipLight.SetOn(Data);
}
}
20 changes: 20 additions & 0 deletions QSBMultipleShips/Patches/HatchControllerPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HarmonyLib;
using QSB.Messaging;
using QSB.Patches;
using QSBMultipleShips.Messages;

namespace QSBMultipleShips.Patches;

[HarmonyPatch(typeof(HatchController))]
internal class HatchControllerPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;

[HarmonyPrefix]
[HarmonyPatch(nameof(HatchController.OpenHatch))]
public static void OpenHatch() => new HatchMessage(true).Send();

[HarmonyPrefix]
[HarmonyPatch(nameof(HatchController.CloseHatch))]
public static void CloseHatch() => new HatchMessage(false).Send();
}
25 changes: 25 additions & 0 deletions QSBMultipleShips/Patches/QSBNetworkManagerPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using HarmonyLib;
using Mirror;
using QSB;
using QSB.Patches;

namespace QSBMultipleShips.Patches;

[HarmonyPatch(typeof(QSBNetworkManager))]
internal class QSBNetworkManagerPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;

[HarmonyPostfix]
[HarmonyPatch(nameof(QSBNetworkManager.OnServerAddPlayer))]
public static void OnServerAddPlayer(NetworkConnectionToClient connection)
{
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.CockpitPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.CabinPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.FrontLandingPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.LeftLandingPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.RightLandingPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.SuppliesPrefab), connection);
NetworkServer.Spawn(UnityEngine.Object.Instantiate(Core.Instance.EnginePrefab), connection);
}
}
29 changes: 29 additions & 0 deletions QSBMultipleShips/Patches/QSBPatchPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using HarmonyLib;
using QSB.Patches;
using QSB.ShipSync;
using QSB.ShipSync.Patches;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QSBMultipleShips.Patches;

[HarmonyPatch(typeof(QSBPatch))]
internal class QSBPatchPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;

[HarmonyPrefix]
[HarmonyPatch(nameof(QSBPatch.DoPatches))]
public static bool DoPatches(QSBPatch __instance)
{
if (__instance is ShipAudioPatches or ShipPatches or ShipDetachableModulePatches or ShipFlameWashPatches)
{
return false;
}

return true;
}
}
26 changes: 26 additions & 0 deletions QSBMultipleShips/Patches/ShipCockpitControllerPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HarmonyLib;
using QSB.Messaging;
using QSB.Patches;
using QSB.Utility;
using QSBMultipleShips.Messages;

namespace QSBMultipleShips.Patches;

[HarmonyPatch(typeof(ShipCockpitController))]
internal class ShipCockpitControllerPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;

[HarmonyPostfix]
[HarmonyPatch(nameof(ShipCockpitController.SetEnableShipLights))]
public static void SetEnableShipLights(ShipCockpitController __instance, bool enableLights, bool playAudio)
{
DebugLog.DebugWrite($"SetEnableShipLights enableLights:{enableLights} usingLandingCam:{__instance._usingLandingCam}");
new HeadlightMessage(enableLights && !__instance._usingLandingCam).Send();
// TODO landing light
if (playAudio)
{
// TODO headlight noise
}
}
}
Loading

0 comments on commit 12040ad

Please sign in to comment.