Decompiled source of OvertimeBonusCalculator v1.0.0

BepInEx/plugins/PugKing.ShowBonus.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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PugKing.ShowBonus.NetcodePatcher;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PugKing.ShowBonus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShowBonus")]
[assembly: AssemblyTitle("PugKing.ShowBonus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ShowBonus
{
	[BepInPlugin("PugKing.ShowBonus", "ShowBonus", "1.0.0")]
	public class ShowBonus : BaseUnityPlugin
	{
		public const string BONUS_EVENT = "[showbonus]";

		public static TerminalNode? node;

		public static TerminalKeyword? cmd;

		public static ShowBonus Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public static int CalculateBonus()
		{
			if ((Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return -99999999;
			}
			Logger.LogDebug((object)("Sold Scrap: " + TimeOfDay.Instance.quotaFulfilled));
			Logger.LogDebug((object)("Profit Quota: " + TimeOfDay.Instance.profitQuota));
			Logger.LogDebug((object)("Days Left: " + TimeOfDay.Instance.daysUntilDeadline));
			Logger.LogDebug((object)("Result: " + (TimeOfDay.Instance.quotaFulfilled - TimeOfDay.Instance.profitQuota) / 5 + 15 * TimeOfDay.Instance.daysUntilDeadline));
			int num = TimeOfDay.Instance.quotaFulfilled - TimeOfDay.Instance.profitQuota;
			return num / 5 + -15;
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			NetcodePatcher();
			Patch();
			node = ScriptableObject.CreateInstance<TerminalNode>();
			node.displayText = "[showbonus]";
			node.clearPreviousText = true;
			node.terminalEvent = "[showbonus]";
			Logger.LogDebug((object)"Created node");
			cmd = ScriptableObject.CreateInstance<TerminalKeyword>();
			cmd.word = "bonus";
			cmd.isVerb = false;
			cmd.specialKeywordResult = node;
			Logger.LogDebug((object)"Created keyword");
			Logger.LogInfo((object)"PugKing.ShowBonus v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: 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_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("PugKing.ShowBonus");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PugKing.ShowBonus";

		public const string PLUGIN_NAME = "ShowBonus";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ShowBonus.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void AwakePrefix(Terminal __instance)
		{
			if ((Object)(object)ShowBonus.cmd == (Object)null)
			{
				ShowBonus.Logger.LogError((object)"Failed to register command because it's invalid!");
				return;
			}
			List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
			list.Add(ShowBonus.cmd);
			__instance.terminalNodes.allKeywords = list.ToArray();
		}

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPostfix]
		private static void ParsePostfix(Terminal __instance, ref TerminalNode __result)
		{
			ShowBonus.Logger.LogDebug((object)"Parse patch");
			if ((Object)(object)__result == (Object)(object)ShowBonus.node)
			{
				ShowBonus.Logger.LogDebug((object)"Found node");
				int num = ShowBonus.CalculateBonus();
				num = Mathf.Max(0, num);
				__result.displayText = $"Your overtime bonus will be ${num}\n";
			}
		}
	}
}
namespace PugKing.ShowBonus.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}