Skip to content

Commit

Permalink
Revert targetMethod changes
Browse files Browse the repository at this point in the history
  • Loading branch information
killzoms committed Nov 23, 2023
1 parent eba67c7 commit 1b2e431
Show file tree
Hide file tree
Showing 214 changed files with 326 additions and 346 deletions.
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/ArmsController_Start_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Reflection;
using NitroxModel.Helper;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class ArmsController_Start_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((ArmsController t) => t.Start());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((ArmsController t) => t.Start());

public static void Postfix(ArmsController __instance)
{
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/ArmsController_Update_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Reflection;
using NitroxModel.Helper;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class ArmsController_Update_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((ArmsController t) => t.Update());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((ArmsController t) => t.Update());

public static bool Prefix(ArmsController __instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class BaseDeconstructable_Deconstruct_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((BaseDeconstructable t) => t.Deconstruct());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((BaseDeconstructable t) => t.Deconstruct());

private static TemporaryBuildData Temp => BuildingHandler.Main.Temp;
private static BuildPieceIdentifier cachedPieceIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class BaseDeconstructable_DeconstructionAllowed_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((BaseDeconstructable t) => t.DeconstructionAllowed(out Reflect.Ref<string>.Field));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((BaseDeconstructable t) => t.DeconstructionAllowed(out Reflect.Ref<string>.Field));

public static void Postfix(BaseDeconstructable __instance, ref bool __result, ref string reason)
{
Expand Down
2 changes: 1 addition & 1 deletion NitroxPatcher/Patches/Dynamic/Base_OnPreDestroy_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NitroxPatcher.Patches.Dynamic;
/// </summary>
public sealed partial class Base_OnPreDestroy_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Base t) => t.OnPreDestroy());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Base t) => t.OnPreDestroy());

public static void Prefix(Base __instance)
{
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/Bed_EnterInUseMode_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.Communication.Abstract;
using NitroxModel.Core;
using NitroxModel.Helper;
Expand All @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Bed_EnterInUseMode_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Bed t) => t.EnterInUseMode(default(Player)));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Bed t) => t.EnterInUseMode(default(Player)));

public static void Postfix()
{
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/Bench_ExitSittingMode_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.ChatUI;
Expand All @@ -11,7 +11,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Bench_ExitSittingMode_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Bench t) => t.ExitSittingMode(default, default));
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Bench t) => t.ExitSittingMode(default, default));

public static void Prefix(ref bool __runOriginal)
{
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/Bench_OnHandClick_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.HUD.Components;
using NitroxClient.GameLogic.Simulation;
Expand All @@ -10,7 +10,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Bench_OnHandClick_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Bench t) => t.OnHandClick(default(GUIHand)));
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Bench t) => t.OnHandClick(default(GUIHand)));
private static bool skipPrefix;

public static bool Prefix(Bench __instance, GUIHand hand)
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/Bench_OnPlayerDeath_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures;
Expand All @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Bench_OnPlayerDeath_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Bench t) => t.OnPlayerDeath(default(Player)));
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Bench t) => t.OnPlayerDeath(default(Player)));

public static void Postfix(Bench __instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class BreakableResource_BreakIntoResources_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((BreakableResource t) => t.BreakIntoResources());
private static MethodInfo TARGET_METHOD = Reflect.Method((BreakableResource t) => t.BreakIntoResources());

public static void Prefix(BreakableResource __instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace NitroxPatcher.Patches.Dynamic;
/// </summary>
public sealed partial class BreakableResource_SpawnResourceFromPrefab_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = AccessTools.EnumeratorMoveNext(Reflect.Method(() => BreakableResource.SpawnResourceFromPrefab(default, default, default)));
public static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method(() => BreakableResource.SpawnResourceFromPrefab(default, default, default)));

private static readonly InstructionsPattern SpawnResFromPrefPattern = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class BuilderTool_Construct_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((BuilderTool t) => t.Construct(default, default, default));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((BuilderTool t) => t.Construct(default, default, default));

public static bool Prefix(Constructable c)
{
Expand Down
16 changes: 5 additions & 11 deletions NitroxPatcher/Patches/Dynamic/Builder_TryPlace_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
Expand All @@ -18,7 +17,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Builder_TryPlace_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method(() => Builder.TryPlace());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method(() => Builder.TryPlace());

public static readonly InstructionsPattern AddInstructionPattern1 = new()
{
Expand All @@ -44,16 +43,11 @@ public sealed partial class Builder_TryPlace_Patch : NitroxPatch, IDynamicPatch
{ new() { OpCode = Callvirt, Operand = new(nameof(Constructable), nameof(Constructable.SetIsInside)) }, "Insert2" }
};

public static List<CodeInstruction> InstructionsToAdd2;

public Builder_TryPlace_Patch()
public static readonly List<CodeInstruction> InstructionsToAdd2 = new()
{
InstructionsToAdd2 = new()
{
targetMethod.Ldloc<Constructable>(),
new(Call, Reflect.Method(() => GhostCreated(default)))
};
}
TARGET_METHOD.Ldloc<Constructable>(),
new(Call, Reflect.Method(() => GhostCreated(default)))
};

public static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions) =>
instructions.Transform(AddInstructionPattern1, (label, instruction) =>
Expand Down
2 changes: 1 addition & 1 deletion NitroxPatcher/Patches/Dynamic/Builder_Update_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NitroxPatcher.Patches.Dynamic;
/// </summary>
public sealed partial class Builder_Update_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method(() => Builder.Update());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method(() => Builder.Update());
private static readonly Color DESYNCED_COLOR = Color.magenta;

public static void Postfix()
Expand Down
15 changes: 5 additions & 10 deletions NitroxPatcher/Patches/Dynamic/ConstructableBase_SetState_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class ConstructableBase_SetState_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((ConstructableBase t) => t.SetState(default, default));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((ConstructableBase t) => t.SetState(default, default));

/*
* Make it become
Expand All @@ -29,16 +29,11 @@ public sealed partial class ConstructableBase_SetState_Patch : NitroxPatch, IDyn
{ Brfalse, "Insert" }
};

public static List<CodeInstruction> InstructionsToAdd;
public ConstructableBase_SetState_Patch()
public static readonly List<CodeInstruction> InstructionsToAdd = new()
{
InstructionsToAdd = new()
{
targetMethod.Ldloc<GameObject>(),
new(Call, Reflect.Method(() => BeforeDestroy(default)))
};

}
TARGET_METHOD.Ldloc<GameObject>(),
new(Call, Reflect.Method(() => BeforeDestroy(default)))
};

public static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions) =>
instructions.Transform(InstructionPattern, (label, instruction) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Constructable_Construct_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Constructable t) => t.Construct());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Constructable t) => t.Construct());

private static TemporaryBuildData Temp => BuildingHandler.Main.Temp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Constructable_DeconstructAsync_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = AccessTools.EnumeratorMoveNext(Reflect.Method((Constructable t) => t.DeconstructAsync(default, default)));
public static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method((Constructable t) => t.DeconstructAsync(default, default)));

public static readonly InstructionsPattern InstructionsPattern = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NitroxPatcher.Patches.Dynamic;
/// </summary>
public sealed partial class Constructable_DeconstructionAllowed_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Constructable t) => t.DeconstructionAllowed(out Reflect.Ref<string>.Field));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Constructable t) => t.DeconstructionAllowed(out Reflect.Ref<string>.Field));

public static void Postfix(Constructable __instance, ref bool __result, ref string reason)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace NitroxPatcher.Patches.Dynamic
{
public sealed partial class ConstructorInput_OnCraftingBegin_Patch : NitroxPatch, IDynamicPatch
{
private static readonly Type TARGET_TYPE = typeof(ConstructorInput);
public override MethodInfo targetMethod { get; } = AccessTools.EnumeratorMoveNext(Reflect.Method((ConstructorInput t) => t.OnCraftingBeginAsync(default(TechType), default(float))));
public static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method((ConstructorInput t) => t.OnCraftingBeginAsync(default(TechType), default(float))));

public static readonly OpCode INJECTION_OPCODE = OpCodes.Call;
public static readonly object INJECTION_OPERAND = Reflect.Method(() => CrafterLogic.NotifyCraftEnd(default(GameObject), default(TechType)));
Expand All @@ -33,9 +32,9 @@ public static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnum
yield return original.Ldloc<ConstructorInput>(0);
yield return original.Ldloc<GameObject>(0);
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, TARGET_TYPE.GetField("techType", BindingFlags.Instance | BindingFlags.Public));
yield return new CodeInstruction(OpCodes.Ldfld, TARGET_METHOD.DeclaringType.GetField("techType", BindingFlags.Instance | BindingFlags.Public));
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, TARGET_TYPE.GetField("duration", BindingFlags.Instance | BindingFlags.Public));
yield return new CodeInstruction(OpCodes.Ldfld, TARGET_METHOD.DeclaringType.GetField("duration", BindingFlags.Instance | BindingFlags.Public));
yield return new CodeInstruction(OpCodes.Call, ((Action<ConstructorInput, GameObject, TechType, float>)Callback).Method);
}
}
Expand Down
2 changes: 1 addition & 1 deletion NitroxPatcher/Patches/Dynamic/Constructor_Deploy_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Constructor_Deploy_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Constructor t) => t.Deploy(default(bool)));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Constructor t) => t.Deploy(default(bool)));

public static void Prefix(Constructor __instance, bool value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace NitroxPatcher.Patches.Dynamic;
*/
public sealed partial class CrafterLogic_TryPickupSingleAsync_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = AccessTools.EnumeratorMoveNext(Reflect.Method((CrafterLogic t) => t.TryPickupSingleAsync(default(TechType), default(IOut<bool>))));
public static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method((CrafterLogic t) => t.TryPickupSingleAsync(default(TechType), default(IOut<bool>))));

public static readonly OpCode INJECTION_OPCODE = OpCodes.Call;
public static readonly object INJECTION_OPERAND = Reflect.Method(() => CrafterLogic.NotifyCraftEnd(default(GameObject), default(TechType)));
Expand Down
4 changes: 2 additions & 2 deletions NitroxPatcher/Patches/Dynamic/CrashHome_Spawn_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Reflection;
using NitroxModel.Helper;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class CrashHome_Spawn_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CrashHome t) => t.Spawn());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CrashHome t) => t.Spawn());

public static bool Prefix() // Disables Crashfish automatic spawning on the client
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.Unity.Helper;
using NitroxModel.DataStructures;
Expand All @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Creature_ChooseBestAction_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((Creature t) => t.ChooseBestAction(default(float)));
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Creature t) => t.ChooseBestAction(default(float)));

private static CreatureAction previousAction;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxModel.Helper;

Expand All @@ -10,7 +10,7 @@ namespace NitroxPatcher.Patches.Dynamic;
/// </summary>
public sealed partial class CyclopsDamagePoint_OnRepair_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsDamagePoint t) => t.OnRepair());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsDamagePoint t) => t.OnRepair());

public static void Postfix(CyclopsDamagePoint __instance)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxModel.Core;
using NitroxModel.DataStructures;
Expand All @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class CyclopsDecoyLaunchButton_OnClick_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsDecoyLaunchButton t) => t.OnClick());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsDecoyLaunchButton t) => t.OnClick());

public static void Postfix(CyclopsHornButton __instance)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.PlayerLogic;
using NitroxModel.DataStructures;
Expand All @@ -8,7 +8,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class CyclopsDestructionEvent_DestroyCyclops_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsDestructionEvent t) => t.DestroyCyclops());
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsDestructionEvent t) => t.DestroyCyclops());

public static void Prefix(CyclopsDestructionEvent __instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class CyclopsEngineChangeState_OnClick_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsEngineChangeState t) => t.OnClick());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsEngineChangeState t) => t.OnClick());

public static void Postfix(CyclopsEngineChangeState __instance)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxModel.DataStructures;
using NitroxModel.Helper;
Expand All @@ -7,7 +7,7 @@ namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class CyclopsExternalDamageManager_CreatePoint_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsExternalDamageManager t) => t.CreatePoint());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsExternalDamageManager t) => t.CreatePoint());

public static bool Prefix(CyclopsExternalDamageManager __instance, out bool __state)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxModel.Core;
using NitroxModel.DataStructures;
Expand All @@ -12,7 +12,7 @@ namespace NitroxPatcher.Patches.Dynamic;
*/
public sealed partial class CyclopsFireSuppressionButton_StartCooldown_Patch : NitroxPatch, IDynamicPatch
{
public override MethodInfo targetMethod { get; } = Reflect.Method((CyclopsFireSuppressionSystemButton t) => t.StartCooldown());
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsFireSuppressionSystemButton t) => t.StartCooldown());

public static void Postfix(CyclopsFireSuppressionSystemButton __instance)
{
Expand Down
Loading

0 comments on commit 1b2e431

Please sign in to comment.