-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPupifier.cs
108 lines (95 loc) · 3.37 KB
/
Pupifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Security.Permissions;
using BepInEx;
using System.Reflection;
using BepInEx.Bootstrap;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Serialization;
[assembly: AssemblyVersion(PluginInfo.PluginVersion)]
#pragma warning disable CS0618
#pragma warning disable CS8618
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
namespace Pupifier;
[BepInDependency("henpemaz.rainmeadow", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("elumenix.pupify", BepInDependency.DependencyFlags.SoftDependency)]
[BepInPlugin(PluginInfo.PluginGUID, PluginInfo.PluginName, PluginInfo.PluginVersion)]
public partial class Pupifier : BaseUnityPlugin
{
public static Pupifier Instance;
public static Harmony HarmonyInstance;
public static PupifierOptions Options;
public void OnEnable()
{
Instance = this;
Options = new PupifierOptions();
HarmonyInstance = new Harmony(PluginInfo.PluginGUID);
On.RainWorld.OnModsInit += RainWorldOnOnModsInit;
}
private void Update()
{
if (!_isInit || Options == null) return;
if (Input.GetKeyDown(Options.SlugpupKey.Value) || (Options.UseSecondaryKeyToggle.Value && Input.GetKeyDown(Options.SlugpupSecondaryKey.Value)))
{
slugpupEnabled = !slugpupEnabled;
if (Options.LoggingPupEnabled.Value)
{
Log($"Key pressed, will change to {(slugpupEnabled ? "pup" : "adult")}");
}
}
}
private bool _isInit;
private void RainWorldOnOnModsInit(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
try
{
if (_isInit) return;
if (!IsModEnabled("elumenix.pupify") || Options.ModAutoDisabledToggle.Value)
{
PlayerHooks();
Log("Hooked into methods...");
}
else
{
Log("Pupify is installed, we do not support this mod.");
Log("Check the remix options if you want to enable this mod anyway. (Experimental Tab)");
Log("Skipped hooking into methods.");
}
On.RainWorldGame.ShutDownProcess += RainWorldGameOnShutDownProcess;
On.GameSession.ctor += GameSessionOnctor;
MachineConnector.SetRegisteredOI(PluginInfo.PluginGUID, Options);
Log($"Registered OI...");
_isInit = true;
Log($"Fully initialized!");
}
catch (Exception ex)
{
LogError(ex, $"Failed to initialize mod {PluginInfo.PluginGUID}");
throw;
}
}
private void RainWorldGameOnShutDownProcess(On.RainWorldGame.orig_ShutDownProcess orig, RainWorldGame self)
{
orig(self);
ClearMemory();
}
private void GameSessionOnctor(On.GameSession.orig_ctor orig, GameSession self, RainWorldGame game)
{
orig(self, game);
ClearMemory();
}
private void ClearMemory()
{
//List/Dict.Clear();
}
public static bool IsModEnabled(string modGuid)
{
if (Chainloader.PluginInfos.TryGetValue(modGuid, out var pluginInfo))
{
// Check the "Enabled" state in the plugin's config
return pluginInfo.Instance.isActiveAndEnabled;
}
return false; // Mod not found
}
}