-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add QoL change to GroundMotor.movingPlatform.movementTransfer
- Loading branch information
1 parent
da6c280
commit 9578635
Showing
2 changed files
with
79 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
NitroxPatcher/Patches/Dynamic/SubRoot_OnPlayerExited_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using NitroxModel.Helper; | ||
|
||
namespace NitroxPatcher.Patches.Dynamic; | ||
|
||
public sealed partial class SubRoot_OnPlayerEntered_Patch : NitroxPatch, IDynamicPatch | ||
{ | ||
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((SubRoot t) => t.OnPlayerEntered(default(Player))); | ||
private static readonly OpCode START_INJECTION_CODE = OpCodes.Ldarg_0; | ||
private static readonly OpCode START_INJECTION_CODE_INVINCIBLE = OpCodes.Stfld; | ||
private static readonly FieldInfo LIVEMIXIN_INVINCIBLE = Reflect.Field((LiveMixin t) => t.invincible); | ||
|
||
/* There is a bug, where Subroot.live is not loaded when starting in a cyclops. Therefore this codepiece needs to check that and jump accordingly if not present | ||
* | ||
* For this change | ||
* | ||
* this.live.invincible = false | ||
* | ||
* to | ||
* | ||
* if (this.live != null) | ||
* { | ||
* this.live.invincible = false | ||
* } | ||
*/ | ||
public static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> instructionList = instructions.ToList(); | ||
|
||
int injectionPoint = 0; | ||
Label newJumpPoint = generator.DefineLabel(); | ||
for (int i = 3; i < instructionList.Count; i++) | ||
{ | ||
if (instructionList[i].opcode == START_INJECTION_CODE_INVINCIBLE && | ||
Equals(instructionList[i].operand, LIVEMIXIN_INVINCIBLE)) | ||
{ | ||
if (instructionList[i - 3].opcode == START_INJECTION_CODE) | ||
{ | ||
instructionList[i + 1].labels.Add(newJumpPoint); | ||
injectionPoint = i - 3; | ||
} | ||
} | ||
} | ||
if (injectionPoint != 0) | ||
{ | ||
MethodInfo op_inequality_method = typeof(UnityEngine.Object).GetMethod("op_Inequality"); | ||
List<CodeInstruction> injectedInstructions = new() | ||
{ | ||
new CodeInstruction(OpCodes.Ldarg_0), | ||
new CodeInstruction(OpCodes.Ldfld, Reflect.Field((SubRoot t) => t.live)), | ||
new CodeInstruction(OpCodes.Ldnull), | ||
new CodeInstruction(OpCodes.Call, op_inequality_method), | ||
new CodeInstruction(OpCodes.Brfalse, newJumpPoint) | ||
}; | ||
instructionList.InsertRange(injectionPoint, injectedInstructions); | ||
} | ||
return instructionList; | ||
} | ||
|
||
public static void Prefix() | ||
{ | ||
PlayerMotor motor = Player.main.playerController.activeController; | ||
if (motor is GroundMotor groundMotor) | ||
{ | ||
groundMotor.movingPlatform.movementTransfer = GroundMotor.MovementTransferOnJump.PermaLocked; | ||
} | ||
} | ||
} |