Skip to content

Commit

Permalink
Even better mod compatibility
Browse files Browse the repository at this point in the history
If this doesn't do it, I don't know what will.
  • Loading branch information
SabreML committed Feb 19, 2023
1 parent 9be33e6 commit 70d3220
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
30 changes: 20 additions & 10 deletions SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using BepInEx;
using System.Reflection;
using System.Security.Permissions;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using System;
using System.Reflection;
using System.Security.Permissions;
using UnityEngine;

#pragma warning disable CS0618
Expand All @@ -11,7 +12,7 @@

namespace SingleplayerCoopEmotes
{
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.3")]
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.4")]
public class SingleplayerCoopEmotes : BaseUnityPlugin
{
public void OnEnable()
Expand Down Expand Up @@ -39,9 +40,11 @@ private static void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)
On.Player.JollyUpdate += JollyUpdateHK;
On.Player.JollyPointUpdate += JollyPointUpdateHK;
On.Player.GraphicsModuleUpdated += GraphicsModuleUpdatedHK;
On.Player.checkInput += checkInputHK;
On.PlayerGraphics.PlayerBlink += PlayerBlinkHK;

// IL hook to remove all `ModManager.CoopAvailable` checks.
IL.Player.checkInput += checkInputHK_IL;

// Manual hook to override the `Player.RevealMap` property getter.
new Hook(
typeof(Player).GetProperty("RevealMap", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(),
Expand Down Expand Up @@ -125,17 +128,24 @@ private static void GraphicsModuleUpdatedHK(On.Player.orig_GraphicsModuleUpdated

// 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)
private static void checkInputHK_IL(ILContext il)
{
// Temporarily make the method think that Jolly Co-op is loaded so that it checks for `jollyButtonDown`.
if (!self.isNPC)
ILCursor cursor = new ILCursor(il);

// Go to each `ModManager.CoopAvailable` check, and set its label target to the next instruction.
//
// (This results in the same behaviour as just removing the check, but after multiple days of trying I couldn't get that to work.)
ILLabel label = null;
while (cursor.TryGotoNext(MoveType.After,
i => i.MatchLdsfld<ModManager>("CoopAvailable"),
i => i.MatchBrfalse(out label)
))
{
ModManager.CoopAvailable = true; // Don't do this for NPCs because it can break their AI.
cursor.MarkLabel(label);
}
orig(self);
ModManager.CoopAvailable = false;
}


// Called by `PlayerGraphics.Update()` when the player has fully curled up to sleep.
//
// This override is the same as the original except without the Spearmaster check, as it made them inconsistent with
Expand Down
8 changes: 8 additions & 0 deletions SingleplayerCoopEmotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@
<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
2 changes: 1 addition & 1 deletion SingleplayerCoopEmotes/modinfo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "sabreml.singleplayercoopemotes",
"name": "Singleplayer Co-op Emotes",
"version": "1.1.3",
"version": "1.1.4",
"target_game_version": "v1.9.05",
"authors": "SabreML",
"description": "Makes the Jolly Co-op emotes work in singleplayer!"
Expand Down

0 comments on commit 70d3220

Please sign in to comment.