Skip to content

Commit

Permalink
NPC AI fix
Browse files Browse the repository at this point in the history
Hopefully this solves the freezing problem.
  • Loading branch information
SabreML committed Feb 14, 2023
1 parent 9e64f5b commit f22fe20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace SingleplayerCoopEmotes
{
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.0")]
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.1")]
public class SingleplayerCoopEmotes : BaseUnityPlugin
{
public void OnEnable()
Expand All @@ -38,8 +38,8 @@ 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;
On.Player.checkInput += checkInputHK;

// Manual hook to override the `Player.RevealMap` property getter.
new Hook(
Expand All @@ -51,8 +51,12 @@ private static void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)

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.
// If this is hooked then the checks above must have passed, so we don't need to worry about it trying to emote twice.
orig(self, eu);
if (self.isNPC || self.room == null)
{
return;
}

// Sleeping emote things.
self.JollyEmoteUpdate();
Expand Down Expand Up @@ -93,25 +97,28 @@ private static void JollyPointUpdateHK(On.Player.orig_JollyPointUpdate orig, Pla
}


// 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)
// 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)
{
// Temporarily make the method think that Jolly Co-op is loaded so that it properly checks for `jollyButtonDown`.
// (Doing it this way is a lot easier than trying to edit the method.)
ModManager.CoopAvailable = true;
orig(self);
orig(self, actuallyViewed, eu);
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)
// 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)
{
// And the same thing as above here. It's a bit hacky, but it works.
ModManager.CoopAvailable = true;
orig(self, actuallyViewed, eu);
// And a similar thing as above here. It's a bit hacky, but it works.
if (!self.isNPC)
{
ModManager.CoopAvailable = true; // Don't do this for NPCs because it can break their AI.
}
orig(self);
ModManager.CoopAvailable = false;
}

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.0",
"version": "1.1.1",
"target_game_version": "v1.9.05",
"authors": "SabreML",
"description": "Makes the Jolly Co-op emotes work in singleplayer!"
Expand Down

0 comments on commit f22fe20

Please sign in to comment.