Skip to content

Commit

Permalink
-WarpDriveProgram GetActiveTimer patch now has harmony load the value…
Browse files Browse the repository at this point in the history
… rather than using reflection

-Removed virtual method OnWarp code, added notification as a patch
  • Loading branch information
Nagord committed Jan 17, 2022
1 parent a7e7a60 commit de620d8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
20 changes: 1 addition & 19 deletions PulsarModLoader/Content/Components/ComponentModBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,7 @@ public virtual void AddStats(PLShipComponent InComp)
}
public virtual void OnWarp(PLShipComponent InComp)
{
if (InComp.Unstable)
{
int num = InComp.Unstable_JumpCounter;
InComp.Unstable_JumpCounter = num + 1;
}
if (InComp.Level == 0)
{
InComp.Unstable_JumpCounter = 0;
}
if (InComp.Unstable_JumpCounter > 6)
{
InComp.Unstable_JumpCounter = 0;
if (InComp.Level > 0)
{
int num = InComp.Level;
InComp.Level = num - 1;
PulsarModLoader.Utilities.Messaging.Notification(InComp.GetItemName(true) + " has degraded to Level " + (InComp.Level + 1));
}
}

}
public virtual void Tick(PLShipComponent InComp)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection.Emit;
using static PulsarModLoader.Patches.HarmonyHelpers;

namespace PulsarModLoader.Content.Components
{
[HarmonyPatch()]
class OnWarpUnstableNotificationPatch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> targetSequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Ldloc_0),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Sub),
new CodeInstruction(OpCodes.Call),
};

List<CodeInstruction> injectedSequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(OnWarpUnstableNotificationPatch), "PatchMethod"))
};

return PatchBySequence(instructions, targetSequence, injectedSequence, checkMode: CheckMode.NEVER);
}
static void PatchMethod(PLShipComponent InComp)
{
PulsarModLoader.Utilities.Messaging.Notification(InComp.GetItemName(true) + " has degraded to Level " + (InComp.Level + 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ private static IEnumerator LateAddToSendQueueReplacement(int shipID, int sendQue
[HarmonyPatch(typeof(PLWarpDriveProgram), "GetActiveTimerAlpha")]
class WarpDriveProgramGetActiveTimerAlphaPatch
{
static void Postfix(PLWarpDriveProgram __instance, ref float __result)
static void Postfix(PLWarpDriveProgram __instance, ref float __result, float __ShieldBooster_LastActivationTime)
{
int subtypeformodded = __instance.SubType - WarpDriveProgramModManager.Instance.VanillaWarpDriveProgramMaxType;
if (subtypeformodded > -1 && subtypeformodded < WarpDriveProgramModManager.Instance.WarpDriveProgramTypes.Count)
{
__result = Mathf.Clamp01((Time.time - (float)__instance.GetType().GetField("ShieldBooster_LastActivationTime", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance)) / WarpDriveProgramModManager.Instance.WarpDriveProgramTypes[subtypeformodded].ActiveTime);
__result = Mathf.Clamp01((Time.time - __ShieldBooster_LastActivationTime) / WarpDriveProgramModManager.Instance.WarpDriveProgramTypes[subtypeformodded].ActiveTime);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions PulsarModLoader/PulsarModLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<Compile Include="Content\Components\MissionShipComponent\MissionShipComponentModManager.cs" />
<Compile Include="Content\Components\NuclearDevice\NuclearDeviceMod.cs" />
<Compile Include="Content\Components\NuclearDevice\NuclearDeviceModManager.cs" />
<Compile Include="Content\Components\OnWarpUnstableNotificationPatch.cs" />
<Compile Include="Content\Components\PolytechModule\PolytechModuleMod.cs" />
<Compile Include="Content\Components\PolytechModule\PolytechModuleModManager.cs" />
<Compile Include="Content\Components\Reactors\ReactorMod.cs" />
Expand Down

0 comments on commit de620d8

Please sign in to comment.