Decompiled source of AdminMode v1.0.0

AdminMode.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AdminMode.Patches;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AdminMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdminMode")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("deccf9ef-8561-4a1f-bcce-851b4506848f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AdminMode
{
	[BepInPlugin("AdminMode", "Testing AdminMode", "1.0.0")]
	public class AdminBase : BaseUnityPlugin
	{
		private const string modGUID = "AdminMode";

		private const string modName = "Testing AdminMode";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("AdminMode");

		private static AdminBase Instance;

		internal ManualLogSource mls;

		public static Texture2D mainLogo;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("AdminMode");
			mls.LogInfo((object)"This mod has started");
			harmony.PatchAll(typeof(AdminBase));
			harmony.PatchAll(typeof(TerminalInterfacePatch));
			harmony.PatchAll(typeof(PlayerControllerPatch));
			harmony.PatchAll(typeof(TimeOfDayPatch));
			harmony.PatchAll(typeof(KillPlayerPatch));
			harmony.PatchAll(typeof(EnemyPatch));
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(GrabbableObjectPatch));
			harmony.PatchAll(typeof(DoorPatch));
			mls.LogInfo((object)"Mod completed loading patches");
		}
	}
}
namespace AdminMode.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void InfiniteBattery(ref Battery ___insertedBattery)
		{
			if (TerminalInterfacePatch.ImprovedStats)
			{
				___insertedBattery.charge = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(DoorLock))]
	internal class DoorPatch
	{
		[HarmonyPatch("LockDoor")]
		[HarmonyPrefix]
		private static bool LockDoor(ref InteractTrigger ___doorTrigger, ref bool ___isLocked, ref DoorLock ___twinDoor)
		{
			if (TerminalInterfacePatch.OpenDoors)
			{
				___doorTrigger.interactable = true;
				___doorTrigger.hoverTip = "No longer locked";
				___isLocked = false;
				if ((Object)(object)___twinDoor != (Object)null)
				{
					___twinDoor.isLocked = false;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyPatch
	{
		[HarmonyPatch("PlayerIsTargetable")]
		[HarmonyPrefix]
		private static bool DontTargetPlayer(ref bool __result)
		{
			if (TerminalInterfacePatch.CantDie)
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPatch("HitEnemy")]
		[HarmonyPostfix]
		private static void InstantKill(ref int ___enemyHP)
		{
			if (TerminalInterfacePatch.HandOfGod)
			{
				___enemyHP = 0;
			}
		}

		[HarmonyPatch("KillEnemyOnOwnerClient")]
		[HarmonyPrefix]
		private static void EnemyCanDie(ref EnemyType ___enemyType)
		{
			if (TerminalInterfacePatch.HandOfGod)
			{
				___enemyType.canDie = true;
				___enemyType.destroyOnDeath = true;
			}
		}
	}
	[HarmonyPatch(typeof(KillLocalPlayer))]
	internal class KillPlayerPatch
	{
		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool DontKillPlayer()
		{
			if (TerminalInterfacePatch.CantDie)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("MeetsScanNodeRequirements")]
		private static bool InfiniteScan(ref bool __result)
		{
			if (TerminalInterfacePatch.ImprovedStats)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch
	{
		[HarmonyPatch("SetBuyingRateForDay")]
		[HarmonyPostfix]
		private static void BuyingRate()
		{
			if (TerminalInterfacePatch.BuyingPower)
			{
				StartOfRound.Instance.companyBuyingRate = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void InfiniteUpdatePatch(ref float ___sprintMeter, ref bool ___isPlayerDead, ref float ___drunkness, ref bool ___jetpackControls, ref bool ___isSinking, ref Light ___helmetLight, ref Light[] ___allHelmetLights, ref Light ___nightVision, ref float ___insanityLevel, ref float ___sinkingValue, ref float ___jumpForce)
		{
			if (TerminalInterfacePatch.ImprovedStats)
			{
				___sprintMeter = 1f;
				___isPlayerDead = false;
				___drunkness = 0f;
				___isSinking = false;
				((Behaviour)___allHelmetLights[0]).enabled = true;
				___helmetLight = ___allHelmetLights[1];
				((Behaviour)___nightVision).enabled = true;
				___insanityLevel = 0f;
				___sinkingValue = 0f;
				___jumpForce = 20f;
			}
		}

		[HarmonyPatch("Interact_performed")]
		[HarmonyPrefix]
		private static void HandsNeverFull(ref bool ___twoHanded)
		{
			if (TerminalInterfacePatch.TwoHands)
			{
				___twoHanded = false;
			}
		}

		[HarmonyPatch("SetFaceUnderwaterFilters")]
		[HarmonyPostfix]
		private static void DrownPatch()
		{
			if (TerminalInterfacePatch.CantDie)
			{
				StartOfRound.Instance.drowningTimer = 1f;
			}
		}

		[HarmonyPatch("DamagePlayer")]
		[HarmonyPrefix]
		private static void InfiniteHealthPatch(ref int ___health, ref int damageNumber)
		{
			if (TerminalInterfacePatch.CantDie)
			{
				___health = 100;
				damageNumber = 0;
			}
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool StopDeathPatch(ref bool ___isPlayerDead)
		{
			if (TerminalInterfacePatch.CantDie)
			{
				___isPlayerDead = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalInterfacePatch
	{
		public static bool AdminMode = false;

		public static bool TwoHands = false;

		public static bool CantDie = false;

		public static bool BuyingPower = false;

		public static bool ImprovedStats = false;

		public static bool HandOfGod = false;

		public static bool OpenDoors = false;

		public static bool[] patchBoolList = new bool[7] { AdminMode, TwoHands, CantDie, BuyingPower, ImprovedStats, HandOfGod, OpenDoors };

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void AddMenu(ref TextMeshProUGUI ___topRightText, ref int ___groupCredits)
		{
			if (AdminMode || ___groupCredits == 999)
			{
				TextMeshProUGUI obj = ___topRightText;
				((TMP_Text)obj).text = ((TMP_Text)obj).text + "ADMIN";
				___groupCredits = 999;
			}
			else
			{
				TextMeshProUGUI obj2 = ___topRightText;
				((TMP_Text)obj2).text = ((TMP_Text)obj2).text + "USER";
			}
		}

		[HarmonyPatch("LoadNewNodeIfAffordable")]
		[HarmonyPostfix]
		private static void AlwaysPurchase(ref int ___groupCredits, ref int ___totalCostOfItems)
		{
			if (AdminMode)
			{
				___groupCredits += ___totalCostOfItems;
			}
		}

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPrefix]
		private static bool DisplayCommands(ref int ___textAdded, ref TMP_InputField ___screenText, ref TerminalNodesList ___terminalNodes, ref TerminalNode __result)
		{
			string text = ___screenText.text.Substring(___screenText.text.Length - ___textAdded);
			if (text == "admin")
			{
				__result = ___terminalNodes.specialNodes[24];
				if (!AdminMode)
				{
					AdminMode = true;
				}
				return false;
			}
			if (text == "user")
			{
				Console.WriteLine("Admin mode has been de-activated!");
				AdminMode = false;
			}
			if (AdminMode)
			{
				switch (text)
				{
				case "unkillable":
					CantDie = true;
					__result = ___terminalNodes.specialNodes[25];
					return false;
				case "two hands":
					TwoHands = true;
					__result = ___terminalNodes.specialNodes[26];
					return false;
				case "improved stats":
					ImprovedStats = true;
					__result = ___terminalNodes.specialNodes[27];
					return false;
				case "open doors":
					OpenDoors = true;
					__result = ___terminalNodes.specialNodes[28];
					return false;
				case "hand of god":
					HandOfGod = true;
					__result = ___terminalNodes.specialNodes[29];
					return false;
				case "buying power":
					BuyingPower = true;
					__result = ___terminalNodes.specialNodes[30];
					return false;
				case "all":
					CantDie = true;
					TwoHands = true;
					ImprovedStats = true;
					OpenDoors = true;
					HandOfGod = true;
					BuyingPower = true;
					__result = ___terminalNodes.specialNodes[31];
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void GenerateCommands(ref TerminalNodesList ___terminalNodes)
		{
			string[] array = new string[8] { "ADMIN MODE ACTIVATED:\n----------\n\n>All\n-Activate all admin abilities\n\n>Unkillable\n-Player can't die (works for the most part)\n\n>Two Hands\n-Player can interact with objects while both hands are full\n\n>Improved Stats\n-Player stats are improved. Infnite sprint, big jump, infnite battery, better vision\n\n>Open Doors\n-All locked doors are open (doesn't work for double doors)\n\n>Hand of God\n-Player can one shot enimies\n\n>Buying Power\n-Company buying rate set to 0 + Infinite Spending\n", "UNKILLABLE ENABLED:\n\n>You are now unkillable\n", "TWO HANDS ENABLED\n\n>You can now do things with two hands\n", "YOU NOW HAVE:\nInfinite Sprint\nBig Jumps\nInfinite Battery\nHead flashlight\nMore features soon\n", "ALL DOORS UNLOCKED\n\n>Still working on double doors :(\n", "HAND OF GOD ENABLED\n\n>You can now one shot things\n", "BUYING POWER ENABLED\n\n>Spend away!!\n", "ALL MODS ACTIVATED\n" };
			string[] array2 = new string[8] { "Admin", "Unkillable", "Two Hands", "Improved Stats", "Open Doors", "Hand of God", "Buying Power", "All" };
			string[] array3 = new string[8] { "admin", "unkillable", "two hands", "improved stats", "open doors", "hand of god", "buying power", "All" };
			for (int i = 0; i < array3.Length; i++)
			{
				TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
				TerminalKeyword val2 = ScriptableObject.CreateInstance<TerminalKeyword>();
				val.clearPreviousText = true;
				val.displayText = array[i];
				val.terminalEvent = array2[i];
				((Object)val).name = array2[i];
				((Object)val2).name = array2[i];
				val2.word = array3[i];
				___terminalNodes.terminalNodes.Add(val);
				___terminalNodes.specialNodes.Add(val);
				CollectionExtensions.AddToArray<TerminalKeyword>(___terminalNodes.allKeywords, val2);
			}
		}
	}
}