Decompiled source of LethallyExtended v0.1.0

LethallyExtended.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCasino.Config;
using LethallyExtended.Patches.LethalCasino;
using Microsoft.CodeAnalysis;

[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("LethallyExtended")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("Lethally Extended")]
[assembly: AssemblyTitle("LethallyExtended")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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;
		}
	}
}
namespace LethallyExtended
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class ModLoaderPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Logger.LogInfo((object)"All plugins are loaded. Checking for dependencies...");
			if (IsModInstalled("mrgrm7.LethalCasino"))
			{
				Plugin.Logger.LogInfo((object)"LethalCasino is installed. Applying patches...");
				new Harmony("LethallyExtended").PatchAll(typeof(LethalCasinoPatch));
			}
			else
			{
				Plugin.Logger.LogWarning((object)"LethalCasino is not installed. Skipping patches.");
			}
			Plugin.Logger.LogInfo((object)"Plugin LethallyExtended setup is complete!");
		}

		public static bool IsModInstalled(string modAssemblyName)
		{
			Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetName().Name == modAssemblyName);
			if (assembly2 != null)
			{
				Plugin.Logger.LogInfo((object)("Mod '" + modAssemblyName + "' is installed."));
				return true;
			}
			Plugin.Logger.LogWarning((object)("Mod '" + modAssemblyName + "' is not installed."));
			return false;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("LethallyExtended", "Lethally Extended", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static bool developing;

		private readonly Harmony _harmony = new Harmony("LethallyExtended");

		private ConfigEntry<string> configCasinoWheelCheaters;

		private ConfigEntry<string> configCasinoWheelCheatedStats;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LethallyExtended is initialized.");
			if (IsModInstalled("mrgrm7.LethalCasino"))
			{
				new Harmony("LethallyExtended").PatchAll(typeof(LethalCasinoPatch));
			}
			Logger.LogInfo((object)"Plugin LethallyExtended setup is complete!");
		}

		public static bool IsModInstalled(string modAssemblyName)
		{
			Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetName().Name == modAssemblyName);
			if (assembly2 != null)
			{
				Logger.LogInfo((object)("Mod '" + modAssemblyName + "' is installed."));
				return true;
			}
			Logger.LogWarning((object)("Mod '" + modAssemblyName + "' is not installed."));
			return false;
		}

		private void SetUpConfig()
		{
			configCasinoWheelCheaters = ((BaseUnityPlugin)this).Config.Bind<string>("LethalCasino", "WheelCheaters", "playerA,playerB,key", "List of _lowercase_ usernames of players who should have better odds at The Wheel game (the big one1)\nThese are separated by commas AND NO SPACES (See default value for example)");
			configCasinoWheelCheatedStats = ((BaseUnityPlugin)this).Config.Bind<string>("LethalCasino", "WheelCheaterStats", "JACKPOT:30.60,WIN:50.50,LOSE:0.30,ZERO:0.10", "Groups of settings for each prize type to get at The Wheel for any cheating buddy.\nThey should look like this: TYPE_OF_PRIZE:SURE_CHANCE.RANDOM_CHANCE,OTHER_PRIZE:SURE_CHANCE.RANDOM_CHANCE (NO SPACES, see default value for example)\nTYPE_OF_PRIZE is the type of the prize to get, options are:\n  - JACKPOT: Get a huge win (250 or 500)\n  - WIN: Anything above 25\n  - LOSE: Anything below 25 but higher than 0\n  - ZERO: Literally get 0 (I think? didn't test it)\nSURE_CHANCE is the assured probability (in % from 0 to 100 but set by you) to get the TYPE_OF_PRIZE\nRANDOM_CHANCE is a randomly generated chance (in % from 0 to RANDOM_CHANCE) to be added to SURE_CHANCE for the final %\nIn the default value for JACKPOT (JACKPOT:30.60), this means that there is a chance between 30% (SURE_CHANCE)\n and 90% (SURE_CHANCE + RANDOM_CHANCE = 30% + 60% = 90%) to get JACKPOT\nTotal chances CAN ADD TO MORE THAN 100, but whichever has the highest chance when The Wheel gets spinned will be the granted prize");
			Logger.LogInfo((object)"Config initialized.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LethallyExtended";

		public const string PLUGIN_NAME = "Lethally Extended";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace LethallyExtended.Patches.LethalCasino
{
	[HarmonyPatch]
	public class LethalCasinoPatch
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("LethalCasino.Custom.TheWheel");
			Plugin.Logger.LogInfo((object)"PATCHING getCumulativeProbabilities...");
			if (type == null)
			{
				if (Plugin.developing)
				{
					Plugin.Logger.LogError((object)"Type 'LethalCasino.Custom.TheWheel' not found.");
				}
				return null;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "getCumulativeProbabilities", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				if (Plugin.developing)
				{
					Plugin.Logger.LogError((object)"Method 'getCumulativeProbabilities' not found in 'LethalCasino.Custom.TheWheel'.");
				}
				return null;
			}
			Plugin.Logger.LogInfo((object)"Found method: getCumulativeProbabilities");
			return methodInfo;
		}

		[HarmonyPrefix]
		private static bool Prefix(object __instance, ref Dictionary<string, float> __result)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "gamblingPlayer");
			if (fieldInfo != null)
			{
				PlayerControllerB val = (PlayerControllerB)fieldInfo.GetValue(__instance);
				string playerUsername = val.playerUsername;
				if (playerUsername != null)
				{
					if (Plugin.developing)
					{
						Plugin.Logger.LogInfo((object)("Gambling Player Name: " + playerUsername));
					}
					if (string.Equals(playerUsername, "key", StringComparison.OrdinalIgnoreCase))
					{
						if (Plugin.developing)
						{
							Plugin.Logger.LogInfo((object)("Player" + playerUsername + " is cheating The Wheel ♥"));
						}
						Random random = new Random();
						__result = new Dictionary<string, float>
						{
							{
								Constants.WHEEL_CHANCE_JACKPOT,
								30f + (float)random.NextDouble() * 60f
							},
							{
								Constants.WHEEL_CHANCE_WIN,
								50f + (float)random.NextDouble() * 50f
							},
							{
								Constants.WHEEL_CHANCE_LOSE,
								(float)random.NextDouble() * 30f
							},
							{
								Constants.WHEEL_CHANCE_ZERO,
								0f + (float)random.NextDouble() * 10f
							}
						};
						return false;
					}
				}
				else if (Plugin.developing)
				{
					Plugin.Logger.LogError((object)"Property 'playerUsername' not found on gamblingPlayer.");
				}
			}
			else if (Plugin.developing)
			{
				Plugin.Logger.LogError((object)"Field 'gamblingPlayer' not found.");
			}
			return true;
		}

		private static void Postfix(ref Dictionary<string, float> __result, object __instance)
		{
		}
	}
}