Decompiled source of CustomStartingCredits v1.0.1

CustomStartingCredits.dll

Decompiled 36 minutes ago
using System;
using System.Diagnostics;
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 CustomStartingCredits.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("CustomStartingCredits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod para configurar los créditos iniciales en Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomStartingCredits")]
[assembly: AssemblyTitle("CustomStartingCredits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 CustomStartingCredits
{
	[BepInPlugin("vhaals.customstartingcredits", "CustomStartingCredits", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<int> StartingCredits;

		internal static ConfigEntry<bool> ApplyOnFired;

		private readonly Harmony _harmony = new Harmony("vhaals.customstartingcredits");

		private void Awake()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			StartingCredits = ((BaseUnityPlugin)this).Config.Bind<int>("Initial Credits", "Credits", 60, new ConfigDescription("Starting Credits at the beginning of a new game. Default Credits 60.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 99999), Array.Empty<object>()));
			ApplyOnFired = ((BaseUnityPlugin)this).Config.Bind<bool>("Initial Credits", "Apply when being fired", true, "If enabled, also apply custom credits when The Company is dismissed for not meeting the quota.");
			_harmony.PatchAll();
			GameObject val = new GameObject("CustomCreditsGUI");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<CreditsGUI>();
			Log.LogInfo((object)string.Format("[{0}] Loaded. Credits: {1}", "CustomStartingCredits", StartingCredits.Value));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "vhaals.customstartingcredits";

		public const string PLUGIN_NAME = "CustomStartingCredits";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CustomStartingCredits.Patches
{
	public class CreditsGUI : MonoBehaviour
	{
		public static CreditsGUI Instance;

		private bool visible = false;

		private Rect windowRect = new Rect(10f, 10f, 280f, 160f);

		private string inputText = "";

		private bool stylesInitialized = false;

		private GUIStyle windowStyle;

		private GUIStyle labelStyle;

		private GUIStyle inputStyle;

		private GUIStyle buttonStyle;

		private GameObject lobbyHostSettings;

		private float checkTimer = 0f;

		private string statusMessage = "";

		private float statusTimer = 0f;

		private bool statusSuccess = false;

		public void SetVisible(bool v)
		{
			visible = v;
			if (v)
			{
				inputText = Plugin.StartingCredits.Value.ToString();
			}
		}

		private void Awake()
		{
			Instance = this;
			inputText = Plugin.StartingCredits.Value.ToString();
			Plugin.Log.LogInfo((object)"CreditsGUI Started.");
		}

		private void Update()
		{
			if (statusTimer > 0f)
			{
				statusTimer -= Time.deltaTime;
			}
			if (!visible)
			{
				return;
			}
			checkTimer += Time.deltaTime;
			if (!(checkTimer < 0.1f))
			{
				checkTimer = 0f;
				if ((Object)(object)lobbyHostSettings == (Object)null)
				{
					lobbyHostSettings = GameObject.Find("Canvas/MenuContainer/LobbyHostSettings");
				}
				if ((Object)(object)lobbyHostSettings != (Object)null && !lobbyHostSettings.activeSelf)
				{
					SetVisible(v: false);
					Plugin.Log.LogInfo((object)"GUI Hidden");
				}
			}
		}

		private void InitStyles()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00fc: 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)
			//IL_011c: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			windowStyle = new GUIStyle(GUI.skin.window);
			windowStyle.normal.background = MakeText(2, 2, new Color(0.1f, 0.1f, 0.12f, 0.95f));
			windowStyle.fontSize = 15;
			windowStyle.normal.textColor = new Color(0.9f, 0.5f, 0.1f);
			windowStyle.fontStyle = (FontStyle)1;
			labelStyle = new GUIStyle(GUI.skin.label);
			labelStyle.fontSize = 14;
			labelStyle.normal.textColor = Color.white;
			inputStyle = new GUIStyle(GUI.skin.textField);
			inputStyle.fontSize = 16;
			inputStyle.alignment = (TextAnchor)4;
			inputStyle.normal.textColor = Color.white;
			buttonStyle = new GUIStyle(GUI.skin.button);
			buttonStyle.fontSize = 13;
			buttonStyle.fontStyle = (FontStyle)1;
			buttonStyle.normal.textColor = Color.white;
			stylesInitialized = true;
		}

		private void OnGUI()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (visible)
			{
				if (!stylesInitialized)
				{
					InitStyles();
				}
				windowRect = GUI.Window(987654321, windowRect, new WindowFunction(DrawWindow), "Custom Starting Credits", windowStyle);
			}
		}

		private void DrawWindow(int windowID)
		{
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Space(5f);
			GUILayout.Label("Starting Credits:", labelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(3f);
			string text = GUILayout.TextField(inputText, 5, inputStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			string text2 = "";
			string text3 = text;
			for (int i = 0; i < text3.Length; i++)
			{
				char c = text3[i];
				if (char.IsDigit(c))
				{
					text2 += c;
				}
			}
			inputText = text2;
			GUILayout.Space(5f);
			if (GUILayout.Button("Apply", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				if (inputText.Length > 0 && int.TryParse(inputText, out var result))
				{
					result = Mathf.Clamp(result, 0, 99999);
					Plugin.StartingCredits.Value = result;
					inputText = result.ToString();
					statusMessage = "Saved! Credits: " + result;
					statusSuccess = true;
					statusTimer = 3f;
					Plugin.Log.LogInfo((object)$"Credits Applied: {result}");
				}
				else
				{
					statusMessage = "Invalid value!";
					statusSuccess = false;
					statusTimer = 3f;
				}
			}
			if (statusTimer > 0f)
			{
				GUIStyle val = new GUIStyle(labelStyle);
				val.alignment = (TextAnchor)4;
				val.normal.textColor = (statusSuccess ? Color.green : Color.red);
				GUILayout.Space(3f);
				GUILayout.Label(statusMessage, val, Array.Empty<GUILayoutOption>());
			}
			GUI.DragWindow();
		}

		private Texture2D MakeText(int w, int h, Color col)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[w * h];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(w, h);
			val.SetPixels(array);
			val.Apply();
			return val;
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatch
	{
		[HarmonyPatch("ClickHostButton")]
		[HarmonyPostfix]
		private static void ShowOnHost()
		{
			if ((Object)(object)CreditsGUI.Instance != (Object)null)
			{
				CreditsGUI.Instance.SetVisible(v: true);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal class HideOnGameStart
	{
		private static void Postfix()
		{
			if ((Object)(object)CreditsGUI.Instance != (Object)null)
			{
				CreditsGUI.Instance.SetVisible(v: false);
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "Awake")]
	internal class StartOfRoundPatch
	{
		private static void Postfix(TimeOfDay __instance)
		{
			if (__instance.quotaVariables != null)
			{
				int value = Plugin.StartingCredits.Value;
				__instance.quotaVariables.startingCredits = value;
				Plugin.Log.LogInfo((object)$"quotaVariables.startingCredits → {value}");
			}
		}
	}
}