Decompiled source of CWissKnife v1.1.2

CWissKnife.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CWissKnife;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CWissKnife")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("CWissKnife")]
[assembly: AssemblyTitle("CWissKnife")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch]
public class BatteryPatch
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		Type baseType = typeof(ItemInstanceBehaviour);
		IEnumerable<Type> source = from t in baseType.Assembly.GetTypes()
			where t.IsSubclassOf(baseType) && t.GetMethod("Update", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null
			select t;
		return source.Select((Type t) => AccessTools.Method(t, "Update", (Type[])null, (Type[])null));
	}

	[HarmonyPrefix]
	private static void Prefix(object __instance)
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() || !Plugin.configToggleInfiniteBattery.Value)
		{
			return;
		}
		IEnumerable<FieldInfo> enumerable = from t2 in __instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
			where t2.FieldType.Equals(typeof(BatteryEntry))
			select t2;
		if (enumerable == null || !enumerable.Any())
		{
			return;
		}
		foreach (FieldInfo item in enumerable)
		{
			BatteryEntry val = (BatteryEntry)item.GetValue(__instance);
			val.m_charge = val.m_maxCharge;
		}
	}
}
[HarmonyPatch(typeof(VideoCamera), "Update")]
public class CameraPatch
{
	private static void Prefix(VideoInfoEntry ___m_recorderInfoEntry)
	{
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleInfiniteCamera.Value)
		{
			___m_recorderInfoEntry.timeLeft = ___m_recorderInfoEntry.maxTime;
		}
	}
}
[HarmonyPatch(typeof(Player), "TakeDamage")]
public class DamagePatch
{
	private static void Prefix(ref float damage)
	{
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleInfiniteHealth.Value)
		{
			damage = 0f;
		}
	}
}
[HarmonyPatch(typeof(Player), "Die")]
public class DamagePatch2
{
	private static bool Prefix()
	{
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			return true;
		}
		if (!Plugin.configToggleInfiniteHealth.Value)
		{
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(PlayerController), "Update")]
public class NoClipPatch
{
	private static bool wereCollisionsFixed = true;

	private static List<Collider> disabledColliders = new List<Collider>();

	private static bool jumpPressed = false;

	private static bool crouchPressed = false;

	private static BodypartType bodypart;

	private static void Prefix(PlayerRagdoll ___ragdoll, Player ___player)
	{
		if (!Plugin.configToggleNoclip.Value || !PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			if (wereCollisionsFixed)
			{
				return;
			}
			foreach (Collider disabledCollider in disabledColliders)
			{
				if ((Object)(object)disabledCollider != (Object)null)
				{
					disabledCollider.isTrigger = false;
				}
			}
			wereCollisionsFixed = true;
			___player.data.sinceGrounded = 0.1f;
			disabledColliders.Clear();
		}
		else
		{
			if (!___player.data.isLocal)
			{
				return;
			}
			Collider[] componentsInChildren = ((Component)___ragdoll).GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (!componentsInChildren[i].isTrigger || !disabledColliders.Contains(componentsInChildren[i]))
				{
					if (Enum.TryParse<BodypartType>(((Object)((Component)componentsInChildren[i]).transform.parent).name, out bodypart))
					{
						disabledColliders.Add(componentsInChildren[i]);
					}
					componentsInChildren[i].isTrigger = true;
				}
			}
			wereCollisionsFixed = false;
			jumpPressed = ___player.input.jumpIsPressed;
			crouchPressed = ___player.input.crouchIsPressed;
			___player.input.jumpWasPressed = false;
			___player.input.jumpIsPressed = false;
		}
	}

	private static void Postfix(PlayerRagdoll ___ragdoll, Player ___player)
	{
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleNoclip.Value && ___player.data.isLocal)
		{
			if (jumpPressed)
			{
				jumpPressed = false;
				float num = (Plugin.configToggleSpeedMultiplier.Value ? Plugin.configSpeedMultiplier.Value : 1f);
				MethodInfo method = typeof(PlayerRagdoll).GetMethod("AddForce", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(Vector3),
					typeof(ForceMode)
				}, null);
				method.Invoke(___ragdoll, new object[2]
				{
					Vector3.up * num * 7f,
					(object)(ForceMode)5
				});
			}
			if (crouchPressed)
			{
				crouchPressed = false;
				float num2 = (Plugin.configToggleSpeedMultiplier.Value ? Plugin.configSpeedMultiplier.Value : 1f);
				MethodInfo method2 = typeof(PlayerRagdoll).GetMethod("AddForce", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(Vector3),
					typeof(ForceMode)
				}, null);
				method2.Invoke(___ragdoll, new object[2]
				{
					Vector3.down * num2 * 7f,
					(object)(ForceMode)5
				});
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerController), "Gravity")]
public class NoClipPatch2
{
	private static bool Prefix(Player ___player)
	{
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			return true;
		}
		if (!Plugin.configToggleNoclip.Value || !___player.data.isLocal)
		{
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(PlayerController), "ConstantGravity")]
public class NoClipPatch3
{
	private static bool Prefix(Player ___player)
	{
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			return true;
		}
		if (!Plugin.configToggleNoclip.Value || !___player.data.isLocal)
		{
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(PlayerController), "MovementStateChanges")]
public class NoClipPatch4
{
	private static void Postfix(Player ___player)
	{
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleNoclip.Value && ___player.data.isLocal)
		{
			___player.data.isCrouching = false;
		}
	}
}
[HarmonyPatch(typeof(PlayerController), "TryJump")]
public class NoClipPatch5
{
	private static bool Prefix(Player ___player)
	{
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			return true;
		}
		if (!Plugin.configToggleNoclip.Value || !___player.data.isLocal)
		{
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(PlayerRagdoll), "BodyChanged")]
public class NoClipPatch6
{
	private static bool Prefix(Player ___player, List<Rigidbody> ___rigList)
	{
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms())
		{
			return true;
		}
		if (!Plugin.configToggleNoclip.Value || !___player.data.isLocal)
		{
			return true;
		}
		for (int i = 0; i < ___rigList.Count; i++)
		{
			___rigList[i].mass = 10f;
		}
		___player.data.totalMass = 190f;
		return false;
	}
}
[HarmonyPatch(typeof(DiveBellPlayerDetector), "CheckForPlayers")]
public class NoClipPatch7
{
	private static void Postfix(ref ICollection<Player> __result, DiveBellPlayerDetector __instance, Collider[] ___results)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsMasterClient || MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() || !Plugin.configToggleNoclip.Value)
		{
			return;
		}
		Transform[] detectors = __instance.m_detectors;
		foreach (Transform val in detectors)
		{
			int num = Physics.OverlapBoxNonAlloc(val.position, val.lossyScale * 0.5f, ___results, val.rotation);
			for (int j = 0; j < num; j++)
			{
				Collider val2 = ___results[j];
				Player componentInParent = ((Component)val2).GetComponentInParent<Player>();
				if (Object.op_Implicit((Object)(object)componentInParent) && !__result.Contains(componentInParent))
				{
					__result.Add(componentInParent);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerData), "UpdateValues")]
public class O2Patch
{
	private static void Prefix(ref float ___remainingOxygen, float ___maxOxygen)
	{
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleInfiniteOxygen.Value)
		{
			___remainingOxygen = ___maxOxygen;
		}
	}
}
[HarmonyPatch(typeof(PlayerController), "Movement")]
public class SpeedPatch
{
	public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
	{
		bool foundGlobal = false;
		bool lastAddInstructionFound = false;
		CodeInstruction lastAddInstructionOnStack = null;
		foreach (CodeInstruction instruction in instructions)
		{
			if (!foundGlobal && instruction.opcode == OpCodes.Ldc_R4)
			{
				lastAddInstructionOnStack = new CodeInstruction(instruction);
				lastAddInstructionFound = true;
			}
			else if (lastAddInstructionFound && instruction.opcode == OpCodes.Stloc_S)
			{
				foundGlobal = true;
				lastAddInstructionFound = false;
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldfld, (object)typeof(PlayerController).GetField("player", BindingFlags.Instance | BindingFlags.NonPublic));
				yield return new CodeInstruction(OpCodes.Ldfld, (object)typeof(Player).GetField("ai", BindingFlags.Instance | BindingFlags.Public));
				Label toOriginalSpeedjumpLabel = il.DefineLabel();
				yield return new CodeInstruction(OpCodes.Brtrue_S, (object)toOriginalSpeedjumpLabel);
				yield return new CodeInstruction(OpCodes.Ldsfld, (object)typeof(Plugin).GetField("configToggleSpeedMultiplier", BindingFlags.Static | BindingFlags.Public));
				yield return new CodeInstruction(OpCodes.Callvirt, (object)typeof(ConfigEntry<bool>).GetProperty("Value").GetGetMethod());
				yield return new CodeInstruction(OpCodes.Brfalse_S, (object)toOriginalSpeedjumpLabel);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(PhotonNetwork).GetProperty("IsMasterClient", BindingFlags.Static | BindingFlags.Public).GetGetMethod());
				yield return new CodeInstruction(OpCodes.Brfalse_S, (object)toOriginalSpeedjumpLabel);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(MainMenuHandler).GetProperty("SteamLobbyHandler", BindingFlags.Static | BindingFlags.Public).GetGetMethod());
				yield return new CodeInstruction(OpCodes.Callvirt, (object)typeof(SteamLobbyHandler).GetMethod("IsPlayingWithRandoms", BindingFlags.Instance | BindingFlags.Public));
				yield return new CodeInstruction(OpCodes.Brtrue_S, (object)toOriginalSpeedjumpLabel);
				yield return lastAddInstructionOnStack;
				yield return new CodeInstruction(OpCodes.Ldsfld, (object)typeof(Plugin).GetField("configSpeedMultiplier", BindingFlags.Static | BindingFlags.Public));
				yield return new CodeInstruction(OpCodes.Callvirt, (object)typeof(ConfigEntry<float>).GetProperty("Value").GetGetMethod());
				yield return new CodeInstruction(OpCodes.Mul, (object)null);
				yield return new CodeInstruction(instruction);
				Label skipOriginalSpeedJumpLabel = il.DefineLabel();
				yield return new CodeInstruction(OpCodes.Br_S, (object)skipOriginalSpeedJumpLabel);
				CodeInstruction cleanLoadFloat = new CodeInstruction(lastAddInstructionOnStack.opcode, lastAddInstructionOnStack.operand);
				cleanLoadFloat.labels.Add(toOriginalSpeedjumpLabel);
				yield return cleanLoadFloat;
				yield return instruction;
				CodeInstruction nopInstr = new CodeInstruction(OpCodes.Nop, (object)null);
				nopInstr.labels.Add(skipOriginalSpeedJumpLabel);
				yield return nopInstr;
			}
			else
			{
				if (lastAddInstructionFound)
				{
					yield return lastAddInstructionOnStack;
				}
				lastAddInstructionFound = false;
				yield return instruction;
			}
		}
		if (!foundGlobal)
		{
			Plugin.Log.LogError((object)"Cannot find local var <float num> = [something] in PlayerController.Movement");
		}
	}
}
[HarmonyPatch(typeof(PlayerController), "Update")]
public class StaminaPatch
{
	private static void Prefix(PlayerController __instance, Player ___player)
	{
		if (PhotonNetwork.IsMasterClient && !MainMenuHandler.SteamLobbyHandler.IsPlayingWithRandoms() && Plugin.configToggleInfiniteStamina.Value)
		{
			___player.data.currentStamina = __instance.maxStamina;
		}
	}
}
namespace CWissKnife
{
	[BepInPlugin("CWissKnife", "CWissKnife", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static readonly Harmony Harmony = new Harmony("CWissKnife");

		public static ConfigEntry<bool> configToggleInfiniteBattery;

		public static ConfigEntry<bool> configToggleInfiniteCamera;

		public static ConfigEntry<bool> configToggleInfiniteHealth;

		public static ConfigEntry<bool> configToggleInfiniteOxygen;

		public static ConfigEntry<bool> configToggleInfiniteStamina;

		public static ConfigEntry<bool> configToggleSpeedMultiplier;

		public static ConfigEntry<float> configSpeedMultiplier;

		public static ConfigEntry<bool> configToggleNoclip;

		public static bool isRandomLobby = false;

		private void Awake()
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CWissKnife is loaded!");
			Log = ((BaseUnityPlugin)this).Logger;
			configToggleInfiniteBattery = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ToggleInfiniteBattery", false, "Toggle infinite battery in items that have one");
			configToggleInfiniteCamera = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ToggleInfiniteCamera", false, "Toggle infinite camera video length. Use with caution");
			configToggleInfiniteHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ToggleInfiniteHealth", false, "Toggle infinite health");
			configToggleInfiniteOxygen = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ToggleInfiniteOxygen", false, "Toggle infinite oxygen");
			configToggleInfiniteStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ToggleInfiniteStamina", false, "Toggle infinite stamina");
			configToggleSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<bool>("Speed", "ToggleSpeedMultiplier", false, "Toggle movement speed multiplier");
			configSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "SpeedMultiplier", 2f, new ConfigDescription("Speed multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			configToggleNoclip = ((BaseUnityPlugin)this).Config.Bind<bool>("Noclip", "ToggleNoclip", false, "Toggle Noclip. Use regular movement keys to move. Crouch to go down / jump to go up. Use movement speed multiplier to move faster");
			Harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CWissKnife";

		public const string PLUGIN_NAME = "CWissKnife";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}