Skip to content

Commit

Permalink
Basic support for 'Aim Anywhere'
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreML committed Mar 15, 2023
1 parent 92c6aed commit 153e24e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions SingleplayerCoopEmotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Compile Include="src\Mod Support\AimAnywhereSupport.cs" />
<Compile Include="src\SingleplayerCoopEmotes.cs" />
<Compile Include="src\SPCoopEmotesConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
21 changes: 21 additions & 0 deletions src/Mod Support/AimAnywhereSupport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;

namespace SingleplayerCoopEmotes
{
public static class AimAnywhereSupport
{
// Mostly taken from Aim Anywhere's `WeaponPatch.WeaponThrownPatch()`.
public static void UpdatePointDirection(Player self)
{
if (self.room.game.cameras[0] == null)
{
return;
}

Vector2 aimDirection = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
aimDirection += (self.room.game.cameras[0].pos - self.mainBodyChunk.pos);

self.pointInput.analogueDir = aimDirection.normalized;
}
}
}
20 changes: 20 additions & 0 deletions src/SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using System;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;
using UnityEngine;
Expand All @@ -18,14 +19,18 @@ public class SingleplayerCoopEmotes : BaseUnityPlugin
// The current mod version.
public static string Version;

private static bool aimAnywhereEnabled = false;

public void OnEnable()
{
// Take the version number that was given to `BepInPlugin()` above.
Version = Info.Metadata.Version.ToString();

On.RainWorld.OnModsInit += Init;
On.RainWorld.PostModsInit += PostInit;
}


private void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
Expand Down Expand Up @@ -64,6 +69,16 @@ private void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)
}


private void PostInit(On.RainWorld.orig_PostModsInit orig, RainWorld self)
{
orig(self);
if (ModManager.ActiveMods.Any(mod => mod.id == "demo.aimanywhere"))
{
aimAnywhereEnabled = true;
}
}


private void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu)
{
// If this is hooked then the checks above must have passed, so we don't need to worry about it trying to emote twice.
Expand Down Expand Up @@ -116,6 +131,11 @@ private void UpdateJollyButton(Player self)
{
self.jollyButtonDown = Input.GetKey(customKeybind);
}

if (aimAnywhereEnabled)
{
AimAnywhereSupport.UpdatePointDirection(self);
}
}


Expand Down

0 comments on commit 153e24e

Please sign in to comment.