Skip to content

Commit

Permalink
Interacting scp330 compile fix (#43)
Browse files Browse the repository at this point in the history
* My scp built with no issues.. no idea why.

* Fixes issue

* Harmony suppresses NON harmony errors.

---------

Co-authored-by: Yamato <[email protected]>
  • Loading branch information
Undid-Iridium and louis1706 authored Aug 10, 2024
1 parent a1ae554 commit 2c41d7d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

Label shouldNotSever = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();
Label enableEffectLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(InteractingScp330EventArgs));

Expand Down Expand Up @@ -74,14 +75,14 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
});

// This is to find the location of RpcMakeSound to remove the original code and add a new sever logic structure (Start point)
int addShouldSeverOffset = 1;
int addShouldSeverOffset = -1;
int addShouldSeverIndex = newInstructions.FindLastIndex(
instruction => instruction.Calls(Method(typeof(Scp330Interobject), nameof(Scp330Interobject.RpcMakeSound)))) + addShouldSeverOffset;

int serverEffectLocationStart = -1;
int enableEffect = newInstructions.FindLastIndex(
instruction => instruction.LoadsField(Field(typeof(PlayerEffectsController), nameof(ReferenceHub.playerEffectsController)))) + serverEffectLocationStart;

instruction => instruction.LoadsField(Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController)))) + serverEffectLocationStart;
newInstructions[enableEffect].WithLabels(enableEffectLabel);
newInstructions.InsertRange(
addShouldSeverIndex,
new[]
Expand All @@ -91,7 +92,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
new(OpCodes.Brfalse, shouldNotSever),
new(OpCodes.Br, enableEffect),
new(OpCodes.Br, enableEffectLabel),
});

// This will let us jump to the taken candies code and lock until ldarg_0, meaning we allow base game logic handle candy adding.
Expand Down

0 comments on commit 2c41d7d

Please sign in to comment.