Decompiled source of GetStinky v1.1.2

GetStinky.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: AssemblyMetadata("Notice", "Copyright (c) casualexpie. All rights reserved. Do NOT decompile, disassemble, or reverse-engineer this assembly. Report bug symptoms on the Nexus Bugs page; do not post decompiled or reconstructed source. Reverse-engineering this DLL is not authorized.")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GetStinky;

[BepInPlugin("getstinky", "Get Stinky", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Version = "1.1.0";

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> StayStinky;

	internal static ConfigEntry<KeyCode> MenuKey;

	private void Awake()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		StayStinky = ((BaseUnityPlugin)this).Config.Bind<bool>("Stinky", "StayStinkyForever", false, "Your dirtiness never goes down: water, showers and everything else can't clean you.");
		MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Stinky", "MenuKey", (KeyCode)287, "Opens the Get Stinky menu.");
		GameObject val = new GameObject("GetStinkyRunner");
		((Object)val).hideFlags = (HideFlags)61;
		Object.DontDestroyOnLoad((Object)(object)val);
		val.AddComponent<StinkMenu>();
		Harmony h = new Harmony("getstinky");
		int num = 0;
		num += Hook(h, typeof(Locale), "GetCharacter", new Type[2]
		{
			typeof(string),
			typeof(int)
		}, null, "LinesPostfix");
		num += Hook(h, typeof(Locale), "GetCharacter", new Type[1] { typeof(string) }, null, "LinesPlayerPostfix");
		num += Hook(h, typeof(Locale), "GetCharacter", new Type[3]
		{
			typeof(string),
			typeof(int),
			typeof(int)
		}, null, "LineIndexPostfix");
		num += Hook(h, typeof(Body), "HandlePeriodicChecks", Type.EmptyTypes, null, "ImmunityPostfix");
		num += Hook(h, typeof(Body), "Eat", new Type[3]
		{
			typeof(float),
			typeof(float),
			typeof(int)
		}, "EatPrefix", "EatPostfix");
		num += Hook(h, typeof(Locale), "GetMoodle", new Type[1] { typeof(string) }, null, "MoodlePostfix");
		num += Hook(h, typeof(Body), "get_totalHappiness", Type.EmptyTypes, null, "HappinessPostfix");
		Log.LogInfo((object)string.Concat("Get Stinky 1.1.0 loaded (", num, "/7 hooks). ", MenuKey.Value, " opens the menu. Game version ", Application.version, "."));
	}

	private static int Hook(Harmony h, Type t, string name, Type[] args, string prefix, string postfix)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			MethodInfo methodInfo = AccessTools.Method(t, name, args, (Type[])null);
			if (methodInfo == null)
			{
				Log.LogWarning((object)("Couldn't find " + t.Name + "." + name + ", skipping it."));
				return 0;
			}
			h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return 1;
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Couldn't patch " + t.Name + "." + name + ": " + ex.Message));
			return 0;
		}
	}
}
internal static class Lines
{
	private static readonly string[][] Dirty = new string[3][]
	{
		new string[19]
		{
			"Man i reek...", "*sniffs pits* sour...", "I'm all musky!", "How bad do i smell to the others...?", "mmh... My fur is all dirty.", "I want to take a shower, but... I like this feeling...", "It might just be me, but I think I'm starting to smell.", "All this dirt on me... goodness...", "This is not very hygienic... or is it?", "Being smelly ain't so bad.",
			"I shouldn't clean myself.", "Way too dirty? Who cares.", "Let's get THIS unclean...", "Time for a bath! ...I'm joking, by the way", "How'd I get so dirty?", "Gosh, I am COVERED in gunk!", "My fur is so yucky! I think i like it...", "Guh! I'm completely covered in filth.", "There's soot in my fur."
		},
		new string[9] { "I guess smelling like ass isn't so bad.", "I am filthy. I like seeing myself in this state.", "mmph.. I'm dirty.", "I shouldn't get this dirt off of me.", "Suboptimal hygiene.", "I appear to be covered in filth.", "My ass reeks, oh god.", "This cannot be hygienic.", "My fur is covered in dirt." },
		new string[8] { "Du-ne... Dir-ty..?", "Du-ne d-doesn't need bat-h...", "Du-ne feel smell.", "Feel dirt.", "Sme-ll smell.", "Stin-ky.", "Stink. Good~", "Too stin-k." }
	};

	private static readonly string[][] Reply = new string[3][]
	{
		new string[1] { "You're fucking disgusting, you know that?" },
		new string[1] { "Please get the hell away from me, you reek." },
		new string[1] { "D-Dirty..? oou..?" }
	};

	internal static string[] For(string key, int chr)
	{
		string[][] array;
		if (key == "dirty")
		{
			array = Dirty;
		}
		else
		{
			if (!(key == "dirtyresponse"))
			{
				return null;
			}
			array = Reply;
		}
		if (chr < 0 || chr >= array.Length)
		{
			chr = 0;
		}
		return array[chr];
	}

	internal static string Moodle(string key)
	{
		return key switch
		{
			"dirty1" => "Slightly stinky", 
			"dirty1dsc" => "You're starting to reek. (<>%)", 
			"dirty2" => "Uh oh, stinky~", 
			"dirty2dsc" => "Your whole body reeks, your pits smell, your ass is rank. Your paws... well.. are sour...  (<>%)", 
			_ => null, 
		};
	}

	internal static int PlayerChar()
	{
		try
		{
			if ((Object)(object)PlayerCamera.main != (Object)null && (Object)(object)PlayerCamera.main.body != (Object)null)
			{
				return PlayerCamera.main.body.charType;
			}
		}
		catch
		{
		}
		return 0;
	}
}
internal static class Patches
{
	public static void LinesPostfix(string str, int chr, ref List<string> __result)
	{
		string[] array = Lines.For(str, chr);
		if (array != null)
		{
			__result = new List<string>(array);
		}
	}

	public static void LinesPlayerPostfix(string str, ref List<string> __result)
	{
		string[] array = Lines.For(str, Lines.PlayerChar());
		if (array != null)
		{
			__result = new List<string>(array);
		}
	}

	public static void LineIndexPostfix(string str, int chr, int index, ref string __result)
	{
		string[] array = Lines.For(str, chr);
		if (array != null)
		{
			__result = ((index >= 0 && index < array.Length) ? array[index] : "");
		}
	}

	public static void HappinessPostfix(Body __instance, ref float __result)
	{
		if (!((Object)(object)__instance == (Object)null) && !(__instance.dirtyness <= 50f) && !Object.op_Implicit((Object)(object)__instance.mindWipe) && IsPlayer(__instance))
		{
			__result = Mathf.Clamp(__result + 15f, -100f, 100f);
		}
	}

	public static void MoodlePostfix(string str, ref string __result)
	{
		string text = Lines.Moodle(str);
		if (text != null)
		{
			__result = text;
		}
	}

	private static bool IsPlayer(Body b)
	{
		if ((Object)(object)b != (Object)null && (Object)(object)PlayerCamera.main != (Object)null)
		{
			return (Object)(object)PlayerCamera.main.body == (Object)(object)b;
		}
		return false;
	}

	public static void ImmunityPostfix(Body __instance)
	{
		if (IsPlayer(__instance))
		{
			__instance.immunity = 100f;
			if (__instance.immunityInfectionSpeed != null)
			{
				__instance.curImmunityMult = __instance.immunityInfectionSpeed.Evaluate(100f);
			}
		}
	}

	public static void EatPrefix(Body __instance, out float __state)
	{
		__state = -1f;
		if (IsPlayer(__instance) && !(__instance.dirtyness < 75f))
		{
			__state = __instance.dirtyness;
			__instance.dirtyness = 74.9f;
		}
	}

	public static void EatPostfix(Body __instance, float __state)
	{
		if (__state >= 0f)
		{
			__instance.dirtyness = __state;
		}
	}
}
internal class StinkMenu : MonoBehaviour
{
	private bool open;

	private Rect win = new Rect(40f, 120f, 300f, 10f);

	private Body heldBody;

	private float held = -1f;

	private GUIStyle text;

	private GUIStyle head;

	private GameObject blocker;

	private static Body Player()
	{
		try
		{
			if ((Object)(object)PlayerCamera.main != (Object)null && (Object)(object)PlayerCamera.main.body != (Object)null && (Object)(object)WorldGeneration.world != (Object)null)
			{
				return PlayerCamera.main.body;
			}
		}
		catch
		{
		}
		return null;
	}

	private void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(Plugin.MenuKey.Value))
		{
			open = !open;
		}
		if (open && (Object)(object)blocker == (Object)null)
		{
			MakeBlocker();
		}
		if (!open && (Object)(object)blocker != (Object)null)
		{
			Object.Destroy((Object)(object)blocker);
			blocker = null;
		}
	}

	private void LateUpdate()
	{
		Body val = Player();
		if ((Object)(object)val == (Object)null || !Plugin.StayStinky.Value)
		{
			held = -1f;
			heldBody = null;
		}
		else if ((Object)(object)val != (Object)(object)heldBody)
		{
			heldBody = val;
			held = val.dirtyness;
		}
		else if (val.dirtyness < held)
		{
			val.dirtyness = held;
		}
		else
		{
			held = val.dirtyness;
		}
	}

	private void SetDirt(Body b, float v)
	{
		b.dirtyness = Mathf.Clamp(v, 0f, 100f);
		heldBody = b;
		held = b.dirtyness;
	}

	private void MakeBlocker()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		blocker = new GameObject("GetStinkyClickBlocker");
		((Object)blocker).hideFlags = (HideFlags)61;
		Canvas val = blocker.AddComponent<Canvas>();
		val.renderMode = (RenderMode)0;
		val.sortingOrder = 32765;
		blocker.AddComponent<GraphicRaycaster>();
		GameObject val2 = new GameObject("Block");
		val2.transform.SetParent(blocker.transform, false);
		Image val3 = val2.AddComponent<Image>();
		((Graphic)val3).color = new Color(0f, 0f, 0f, 0f);
		RectTransform component = val2.GetComponent<RectTransform>();
		component.anchorMin = Vector2.zero;
		component.anchorMax = Vector2.zero;
		component.pivot = Vector2.zero;
		Object.DontDestroyOnLoad((Object)(object)blocker);
	}

	private void OnGUI()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		if (open)
		{
			if (text == null)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.richText = true;
				val.wordWrap = true;
				val.fontSize = 13;
				text = val;
				GUIStyle val2 = new GUIStyle(text);
				val2.fontSize = 14;
				head = val2;
			}
			win = GUILayout.Window(358940, win, new WindowFunction(Draw), string.Concat("Get Stinky  (", Plugin.MenuKey.Value, " to close)"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			if ((Object)(object)blocker != (Object)null)
			{
				RectTransform component = ((Component)blocker.transform.GetChild(0)).GetComponent<RectTransform>();
				component.anchoredPosition = new Vector2(((Rect)(ref win)).x, (float)Screen.height - ((Rect)(ref win)).yMax);
				component.sizeDelta = new Vector2(((Rect)(ref win)).width, ((Rect)(ref win)).height);
			}
		}
	}

	private void Draw(int id)
	{
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label("<b><color=#b5d36a>STINK</color></b>", head, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		bool flag = GUILayout.Toggle(Plugin.StayStinky.Value, " Stay stinky forever", (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (flag != Plugin.StayStinky.Value)
		{
			Plugin.StayStinky.Value = flag;
			held = -1f;
			heldBody = null;
			Plugin.Log.LogInfo((object)("Stay stinky forever: " + (flag ? "ON" : "OFF")));
		}
		GUILayout.Label("<color=#999999>Water, showers and everything else can't clean you. You can still get dirtier.</color>", text, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Body val = Player();
		bool enabled = GUI.enabled;
		GUI.enabled = (Object)(object)val != (Object)null;
		if ((Object)(object)val != (Object)null)
		{
			GUILayout.Label("Dirtiness: <b>" + Mathf.RoundToInt(val.dirtyness) + "%</b>" + (Plugin.StayStinky.Value ? "  <color=#b5d36a>(locked)</color>" : ""), text, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		else
		{
			GUILayout.Label("<color=#999999>Not in a run.</color>", text, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button("Max stink", (GUILayoutOption[])(object)new GUILayoutOption[0]) && (Object)(object)val != (Object)null)
		{
			SetDirt(val, 100f);
		}
		if (GUILayout.Button("+25%", (GUILayoutOption[])(object)new GUILayoutOption[0]) && (Object)(object)val != (Object)null)
		{
			SetDirt(val, val.dirtyness + 25f);
		}
		if (GUILayout.Button("Clean me", (GUILayoutOption[])(object)new GUILayoutOption[0]) && (Object)(object)val != (Object)null)
		{
			SetDirt(val, 0f);
		}
		GUILayout.EndHorizontal();
		GUI.enabled = enabled;
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
	}
}