From a7e7a60c6b0e227f5661fe745244d9b9f8449fea Mon Sep 17 00:00:00 2001 From: Gustavo Ribeiro Date: Fri, 12 Nov 2021 14:57:31 -0300 Subject: [PATCH 1/2] fixed thursters power override, fixed so unstable components actually shows a message --- .../Content/Components/ComponentModBase.cs | 20 ++++++++++++++++++- .../Components/Thruster/ThrusterModManager.cs | 2 +- .../InertiaThrusterModManager.cs | 2 +- .../ManeuverThrusterModManager.cs | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/PulsarModLoader/Content/Components/ComponentModBase.cs b/PulsarModLoader/Content/Components/ComponentModBase.cs index 56d30bb..207e3a0 100644 --- a/PulsarModLoader/Content/Components/ComponentModBase.cs +++ b/PulsarModLoader/Content/Components/ComponentModBase.cs @@ -70,7 +70,25 @@ 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) { diff --git a/PulsarModLoader/Content/Components/Thruster/ThrusterModManager.cs b/PulsarModLoader/Content/Components/Thruster/ThrusterModManager.cs index 972dae3..26c0538 100644 --- a/PulsarModLoader/Content/Components/Thruster/ThrusterModManager.cs +++ b/PulsarModLoader/Content/Components/Thruster/ThrusterModManager.cs @@ -82,7 +82,7 @@ public static PLThruster CreateThruster(int Subtype, int level) InThruster.Desc = ThrusterType.Description; InThruster.GetType().GetField("m_IconTexture", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InThruster, ThrusterType.IconTexture); InThruster.GetType().GetField("m_MaxOutput", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InThruster, ThrusterType.MaxOutput); - InThruster.GetType().GetField("m_MaxPowerUsage_Watts", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InThruster, ThrusterType.MaxPowerUsage_Watts); + InThruster.GetType().GetField("m_BaseMaxPower", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InThruster, ThrusterType.MaxPowerUsage_Watts); InThruster.GetType().GetField("m_MarketPrice", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InThruster, (ObscuredInt)ThrusterType.MarketPrice); InThruster.CargoVisualPrefabID = ThrusterType.CargoVisualID; InThruster.CanBeDroppedOnShipDeath = ThrusterType.CanBeDroppedOnShipDeath; diff --git a/PulsarModLoader/Content/Components/ThrusterInertia/InertiaThrusterModManager.cs b/PulsarModLoader/Content/Components/ThrusterInertia/InertiaThrusterModManager.cs index 6839f57..f49c505 100644 --- a/PulsarModLoader/Content/Components/ThrusterInertia/InertiaThrusterModManager.cs +++ b/PulsarModLoader/Content/Components/ThrusterInertia/InertiaThrusterModManager.cs @@ -82,7 +82,7 @@ public static PLInertiaThruster CreateInertiaThruster(int Subtype, int level) InInertiaThruster.Desc = InertiaThrusterType.Description; InInertiaThruster.GetType().GetField("m_IconTexture", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InInertiaThruster, InertiaThrusterType.IconTexture); InInertiaThruster.GetType().GetField("m_MaxOutput", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InInertiaThruster, InertiaThrusterType.MaxOutput); - InInertiaThruster.GetType().GetField("m_MaxPowerUsage_Watts", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InInertiaThruster, InertiaThrusterType.MaxPowerUsage_Watts); + InInertiaThruster.GetType().GetField("m_BaseMaxPower", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InInertiaThruster, InertiaThrusterType.MaxPowerUsage_Watts); InInertiaThruster.GetType().GetField("m_MarketPrice", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InInertiaThruster, (ObscuredInt)InertiaThrusterType.MarketPrice); InInertiaThruster.CargoVisualPrefabID = InertiaThrusterType.CargoVisualID; InInertiaThruster.CanBeDroppedOnShipDeath = InertiaThrusterType.CanBeDroppedOnShipDeath; diff --git a/PulsarModLoader/Content/Components/ThrusterManeuver/ManeuverThrusterModManager.cs b/PulsarModLoader/Content/Components/ThrusterManeuver/ManeuverThrusterModManager.cs index 04052af..6e04f5c 100644 --- a/PulsarModLoader/Content/Components/ThrusterManeuver/ManeuverThrusterModManager.cs +++ b/PulsarModLoader/Content/Components/ThrusterManeuver/ManeuverThrusterModManager.cs @@ -82,7 +82,7 @@ public static PLManeuverThruster CreateManeuverThruster(int Subtype, int level) InManeuverThruster.Desc = ManeuverThrusterType.Description; InManeuverThruster.GetType().GetField("m_IconTexture", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InManeuverThruster, ManeuverThrusterType.IconTexture); InManeuverThruster.GetType().GetField("m_MaxOutput", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InManeuverThruster, ManeuverThrusterType.MaxOutput); - InManeuverThruster.GetType().GetField("m_MaxPowerUsage_Watts", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InManeuverThruster, ManeuverThrusterType.MaxPowerUsage_Watts); + InManeuverThruster.GetType().GetField("m_BaseMaxPower", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InManeuverThruster, ManeuverThrusterType.MaxPowerUsage_Watts); InManeuverThruster.GetType().GetField("m_MarketPrice", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(InManeuverThruster, (ObscuredInt)ManeuverThrusterType.MarketPrice); InManeuverThruster.CargoVisualPrefabID = ManeuverThrusterType.CargoVisualID; InManeuverThruster.CanBeDroppedOnShipDeath = ManeuverThrusterType.CanBeDroppedOnShipDeath; From de620d8d2b4e023f69330dd15cdaff8a6ff7629f Mon Sep 17 00:00:00 2001 From: DragonFire47 <46509577+DragonFire47@users.noreply.github.com> Date: Sun, 16 Jan 2022 17:30:25 -0800 Subject: [PATCH 2/2] -WarpDriveProgram GetActiveTimer patch now has harmony load the value rather than using reflection -Removed virtual method OnWarp code, added notification as a patch --- .../Content/Components/ComponentModBase.cs | 20 +---------- .../OnWarpUnstableNotificationPatch.cs | 34 +++++++++++++++++++ .../WarpDriveProgramModManager.cs | 4 +-- PulsarModLoader/PulsarModLoader.csproj | 1 + 4 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 PulsarModLoader/Content/Components/OnWarpUnstableNotificationPatch.cs diff --git a/PulsarModLoader/Content/Components/ComponentModBase.cs b/PulsarModLoader/Content/Components/ComponentModBase.cs index 207e3a0..56d30bb 100644 --- a/PulsarModLoader/Content/Components/ComponentModBase.cs +++ b/PulsarModLoader/Content/Components/ComponentModBase.cs @@ -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) { diff --git a/PulsarModLoader/Content/Components/OnWarpUnstableNotificationPatch.cs b/PulsarModLoader/Content/Components/OnWarpUnstableNotificationPatch.cs new file mode 100644 index 0000000..bba72bc --- /dev/null +++ b/PulsarModLoader/Content/Components/OnWarpUnstableNotificationPatch.cs @@ -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 Transpiler(IEnumerable instructions) + { + List targetSequence = new List() + { + new CodeInstruction(OpCodes.Ldloc_0), + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Sub), + new CodeInstruction(OpCodes.Call), + }; + + List injectedSequence = new List() + { + 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)); + } + } +} diff --git a/PulsarModLoader/Content/Components/WarpDriveProgram/WarpDriveProgramModManager.cs b/PulsarModLoader/Content/Components/WarpDriveProgram/WarpDriveProgramModManager.cs index ffc1192..cd73694 100644 --- a/PulsarModLoader/Content/Components/WarpDriveProgram/WarpDriveProgramModManager.cs +++ b/PulsarModLoader/Content/Components/WarpDriveProgram/WarpDriveProgramModManager.cs @@ -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); } } } diff --git a/PulsarModLoader/PulsarModLoader.csproj b/PulsarModLoader/PulsarModLoader.csproj index cc0af9d..a3b6fde 100644 --- a/PulsarModLoader/PulsarModLoader.csproj +++ b/PulsarModLoader/PulsarModLoader.csproj @@ -159,6 +159,7 @@ +