Skip to content

Commit

Permalink
Fix airlaunches and other setrotation cases
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell committed Nov 5, 2023
1 parent f5c4c0e commit 93e3112
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
34 changes: 34 additions & 0 deletions Source/Harmony/Vessel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using HarmonyLib;
using UnityEngine;

namespace RealismOverhaul.Harmony
{
[HarmonyPatch(typeof(Vessel))]
internal class PatchVessel
{
[HarmonyPrefix]
[HarmonyPatch(nameof(Vessel.SetRotation), typeof(Quaternion), typeof(bool))]
internal static bool Prefix_SetRotation(Vessel __instance, Quaternion rotation, bool setPos)
{
VesselModuleRotationRO mod = null;
foreach (var vm in __instance.vesselModules)
{
if (vm is VesselModuleRotationRO vmr)
{
mod = vmr;
break;
}
}
if (mod == null)
return true;

mod.StoreRot(rotation);
if (!setPos)
return true;

mod.SetPosRot(rotation, __instance.transform.position);

return false;
}
}
}
1 change: 1 addition & 0 deletions Source/RealismOverhaul.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Compile Include="DebugTools\DrawTools.cs" />
<Compile Include="Harmony\ModuleEngines.cs" />
<Compile Include="Harmony\KSPUtil.cs" />
<Compile Include="Harmony\Vessel.cs" />
<Compile Include="Harmony\PartLoader.cs" />
<Compile Include="Harmony\OrbitDriver.cs" />
<Compile Include="Harmony\UIPartActionResourceEditor.cs" />
Expand Down
10 changes: 7 additions & 3 deletions Source/VesselModuleRotationRO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ private bool IsOverThreshold(Vector3 rot)
return Mathf.Abs(rot.x) > thresh || Mathf.Abs(rot.y) > thresh || Mathf.Abs(rot.z) > thresh;
}

private void StoreRot()
public void StoreRot()
{
StoreRot(vessel.transform.rotation);
}

public void StoreRot(QuaternionD rot)
{
QuaternionD rot = vessel.transform.rotation;
vesselRot = Planetarium.Zup.Rotation * rot.swizzle;
}

Expand All @@ -124,7 +128,7 @@ private void SetRot()
vessel.SetRotation(UnityRot(), true);
}

private void SetPosRot(Quaternion rotation, Vector3d position)
public void SetPosRot(Quaternion rotation, Vector3d position)
{
if (!vessel.loaded)
{
Expand Down

0 comments on commit 93e3112

Please sign in to comment.