Skip to content

Commit

Permalink
The better method
Browse files Browse the repository at this point in the history
This will be actually added in the next update.
  • Loading branch information
SabreML committed Feb 13, 2023
1 parent 39eec89 commit 9e64f5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
30 changes: 12 additions & 18 deletions SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BepInEx;
using System.Reflection;
using System.Security.Permissions;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using System;
using UnityEngine;
Expand Down Expand Up @@ -38,19 +37,18 @@ private static void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)

// Regular hooks.
On.Player.JollyUpdate += JollyUpdateHK;
On.Player.JollyPointUpdate += JollyPointUpdateHK;
On.Player.checkInput += checkInputHK;
On.Player.GraphicsModuleUpdated += GraphicsModuleUpdatedHK;

// IL hook to remove a check in `JollyPointUpdate()`.
IL.Player.JollyPointUpdate += JollyPointUpdateHK_IL;

// Manual hook to override the `Player.RevealMap` property getter.
new Hook(
typeof(Player).GetProperty("RevealMap", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(),
typeof(SingleplayerCoopEmotes).GetMethod(nameof(get_RevealMapHK), BindingFlags.NonPublic | BindingFlags.Static)
);
}


private static void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu)
{
// If this is hooked then the check above must have passed, so we don't need to worry about conflicts.
Expand Down Expand Up @@ -79,27 +77,22 @@ private static void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self,
self.JollyPointUpdate();
}

// Removes the `if (vector == Vector2.zero)` check from `JollyPointUpdate()`.

// Restores the (most likely unintentional) functionality from the 1.5 version of
// pointing with no movement input making your slugcat face towards the screen.
// (Technically, making them face towards the hand rendered behind their body.)
//
// This is to restore the (likely unintentional) functionality of pointing with no movement input
// making your slugcat face towards the screen.
// Added by request :)
private static void JollyPointUpdateHK_IL(ILContext il)
private static void JollyPointUpdateHK(On.Player.orig_JollyPointUpdate orig, Player self)
{
ILCursor cursor = new ILCursor(il);

// Try to move the cursor onto the line that gets `Vector2.zero`.
if (!cursor.TryGotoNext(i => i.MatchCall<Vector2>("get_zero")))
orig(self);
if (self.jollyButtonDown && self.PointDir() == Vector2.zero)
{
Debug.Log("(SPCoopEmotes) Unable to find IL call.");
return;
(self.graphicsModule as PlayerGraphics).LookAtPoint(self.mainBodyChunk.pos, 10f);
}
// Move the cursor back one line to `ldloc.2`.
cursor.Index--;
// Remove 5 lines. (`ldloc.2` to `ret`)
cursor.RemoveRange(5);
}


// When Jolly Co-op is active and the jolly button is held, the `checkInput()` method skips opening the map
// and sets the player's movement input as the pointing direction.
private static void checkInputHK(On.Player.orig_checkInput orig, Player self)
Expand All @@ -111,6 +104,7 @@ private static void checkInputHK(On.Player.orig_checkInput orig, Player self)
ModManager.CoopAvailable = false;
}


// When Jolly Co-op is active and the jolly button is held, the `GraphicsModuleUpdated()` method makes held spears
// point in the direction indicated by the player.
private static void GraphicsModuleUpdatedHK(On.Player.orig_GraphicsModuleUpdated orig, Player self, bool actuallyViewed, bool eu)
Expand Down
8 changes: 0 additions & 8 deletions SingleplayerCoopEmotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,10 @@
<HintPath>..\..\DLLs\HOOKS-Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\..\DLLs\Additional\Mono.Cecil.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\..\DLLs\Additional\MonoMod.RuntimeDetour.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.Utils">
<HintPath>..\..\DLLs\Additional\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\DLLs\UnityEngine.dll</HintPath>
<Private>False</Private>
Expand Down

0 comments on commit 9e64f5b

Please sign in to comment.