Skip to content

Commit

Permalink
Pointing! (Also a full rename)
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreML committed Feb 12, 2023
1 parent 8ed53bb commit 51932c1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SingleplayerSleepEmote")]
[assembly: AssemblyTitle("SingleplayerCoopEmotes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SingleplayerSleepEmote")]
[assembly: AssemblyProduct("SingleplayerCoopEmotes")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
82 changes: 82 additions & 0 deletions SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BepInEx;
using System.Reflection;
using System.Security.Permissions;
using MonoMod.RuntimeDetour;
using UnityEngine;
using System;

#pragma warning disable CS0618
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
#pragma warning restore CS0618

namespace SingleplayerCoopEmotes
{
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.0")]
public class SingleplayerCoopEmotes : BaseUnityPlugin
{
public void OnEnable()
{
On.RainWorld.OnModsInit += Init;
}

private void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
// If the DLC is installed on Steam, and Jolly Co-op isn't currently loaded. (No reason to change anything otherwise)
if (RWCustom.Custom.rainWorld.dlcVersion > 0 && !ModManager.JollyCoop)
{
On.Player.JollyUpdate += JollyUpdateHK;
On.Player.checkInput += checkInputHK;

// 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.
orig(self, eu);

// Sleeping emote things.
self.JollyEmoteUpdate();

// Update the jolly button. (Taken from `JollyInputUpdate()`)
if (!self.input[0].mp) // If the button isn't being held down at all.
{
self.jollyButtonDown = false;
}
else if (!self.input[1].mp) // If the button was down this frame, but not last frame.
{
self.jollyButtonDown = false;
for (int i = 2; i < self.input.Length - 1; i++)
{
if (self.input[i].mp && !self.input[i + 1].mp) // Look for a double tap.
{
self.jollyButtonDown = true;
}
}
}
// Pointing emote things.
self.JollyPointUpdate();
}

private static void checkInputHK(On.Player.orig_checkInput orig, Player self)
{
// Temporarily make it think that Jolly Co-op is loaded so that it checks for `jollyButtonDown`.
// (Doing it this way is a lot easier than trying to edit the method.)
ModManager.CoopAvailable = true;
orig(self);
ModManager.CoopAvailable = false;
}

// Same as the original getter except without a `ModManager.CoopAvailable` check.
private static bool get_RevealMapHK(Func<Player, bool> orig, Player self)
{
return !self.jollyButtonDown && self.input[0].mp && !self.inVoidSea;
}
}
}
10 changes: 7 additions & 3 deletions SingleplayerSleepEmote.csproj → SingleplayerCoopEmotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{32FB7380-F5F5-498D-B802-78E17EFB66BB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SingleplayerSleepEmote</RootNamespace>
<AssemblyName>SingleplayerSleepEmote</AssemblyName>
<RootNamespace>SingleplayerCoopEmotes</RootNamespace>
<AssemblyName>SingleplayerCoopEmotes</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand All @@ -34,7 +34,7 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Compile Include="SingleplayerSleepEmote.cs" />
<Compile Include="SingleplayerCoopEmotes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -50,6 +50,10 @@
<HintPath>..\..\DLLs\HOOKS-Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\..\DLLs\Additional\MonoMod.RuntimeDetour.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\DLLs\UnityEngine.dll</HintPath>
<Private>False</Private>
Expand Down
4 changes: 2 additions & 2 deletions SingleplayerSleepEmote.sln → SingleplayerCoopEmotes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleplayerSleepEmote", "SingleplayerSleepEmote.csproj", "{32FB7380-F5F5-498D-B802-78E17EFB66BB}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleplayerCoopEmotes", "SingleplayerCoopEmotes.csproj", "{32FB7380-F5F5-498D-B802-78E17EFB66BB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ED14B559-DB0C-4B19-9A63-1F374E0DFD2A}"
ProjectSection(SolutionItems) = preProject
SingleplayerSleepEmote\modinfo.json = SingleplayerSleepEmote\modinfo.json
SingleplayerCoopEmotes\modinfo.json = SingleplayerCoopEmotes\modinfo.json
EndProjectSection
EndProject
Global
Expand Down
8 changes: 8 additions & 0 deletions SingleplayerCoopEmotes/modinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "sabreml.singleplayercoopemotes",
"name": "Singleplayer Co-op Emotes",
"version": "1.1.0",
"target_game_version": "v1.9.05",
"authors": "SabreML",
"description": "Makes the Jolly Co-op emotes work in singleplayer!"
}
File renamed without changes
29 changes: 0 additions & 29 deletions SingleplayerSleepEmote.cs

This file was deleted.

8 changes: 0 additions & 8 deletions SingleplayerSleepEmote/modinfo.json

This file was deleted.

0 comments on commit 51932c1

Please sign in to comment.