Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CreditCalculator v1.3.0
Calculator.dll
Decompiled 10 months agousing System; using System.Data; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using TerminalApi; using TerminalApi.Classes; using Unity.Netcode; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Calculator")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Calculator")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("aa396dea-3468-46fe-9b38-d43e231b13f1")] [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")] public static class ChatUtils { public static void SendChat(string message, string sender = "Credit Calculator", int playerId = -1) { try { HUDManager instance = HUDManager.Instance; if ((Object)(object)instance == (Object)null) { Debug.LogError((object)"HUDManager.Instance is null!"); return; } MethodInfo method = typeof(HUDManager).GetMethod("AddChatMessage", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method2 = typeof(HUDManager).GetMethod("AddPlayerChatMessageServerRpc", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(instance, new object[4] { message, sender, playerId, false }); } if (method2 != null && NetworkManager.Singleton.IsHost) { int num = (int)GameNetworkManager.Instance.localPlayerController.playerClientId; method2.Invoke(instance, new object[2] { message, num }); } } catch (Exception arg) { Debug.LogError((object)$"[ChatUtils] Failed to send chat message: {arg}"); } } } public class HUDTipBroadcaster : NetworkBehaviour { public static HUDTipBroadcaster Instance; private void Awake() { if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this) { Object.Destroy((Object)(object)((Component)this).gameObject); Debug.Log((object)"Destroyed duplicate HUDTipBroadcaster"); } else { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); Debug.Log((object)"HUDTipBroadcaster Instance assigned"); } } public static void ShowHUDTip(string formattedResult) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Instance == (Object)null) { Debug.LogError((object)"HUDTipBroadcaster Instance is null!"); } else { Instance.RequestShowHUDTipServerRpc(formattedResult); } } [ServerRpc(RequireOwnership = false)] private void RequestShowHUDTipServerRpc(string formattedResult, ServerRpcParams rpcParams = default(ServerRpcParams)) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) BroadcastShowHUDTipClientRpc(formattedResult); } [ClientRpc] private void BroadcastShowHUDTipClientRpc(string formattedResult, ClientRpcParams rpcParams = default(ClientRpcParams)) { string text = "Credit Calculator:"; string text2 = "You should sell $" + formattedResult + " worth of scrap."; bool flag = false; bool flag2 = false; string text3 = "LC_Tip1"; if ((Object)(object)HUDManager.Instance != (Object)null) { HUDManager.Instance.DisplayTip(text, text2, flag, flag2, text3); } else { Debug.LogWarning((object)"HUDManager.Instance is null on client"); } } } namespace Calculator; [BepInPlugin("Poseidon.Calculator", "Calculator", "1.3.0")] public class CalculatorBase : BaseUnityPlugin { private const string modGUID = "Poseidon.Calculator"; private const string modName = "Calculator"; private const string modVersion = "1.3.0"; private readonly Harmony harmony = new Harmony("Poseidon.Calculator"); public static CalculatorBase Instance; internal ManualLogSource mls; private void Awake() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("Poseidon.Calculator"); mls.LogInfo((object)"The Calculator has awoken :D"); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); TerminalApi.AddCommand("calc [wanted credits]", new CommandInfo { Category = "other", Description = "To calculate how much scrap you should sell to achieve your wanted value of money", DisplayTextSupplier = OnCalcCommand }, "check", true); } private void Start() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)HUDTipBroadcaster.Instance == (Object)null) { Debug.Log((object)"Creating HUDTipBroadcaster GameObject"); GameObject val = new GameObject("HUDTipBroadcaster"); val.AddComponent<NetworkObject>(); val.AddComponent<HUDTipBroadcaster>(); Object.DontDestroyOnLoad((Object)(object)val); } else { Debug.Log((object)"HUDTipBroadcaster Instance already exists"); } SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode) { Debug.Log((object)("[CalculatorMod AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] Scene loaded: " + ((Scene)(ref scene)).name)); }; } private string OnCalcCommand() { //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Expected O, but got Unknown string[] array = TerminalApi.GetTerminalInput().Split(); if (array.Length != 2) { return "Invalid input format. Please enter a valid expression or a single value: 'calc [wanted credits, or expression, e.g.(1500+400)]'\n\n"; } string text = array[1]; float num = TimeOfDay.Instance.profitQuota; int quota = (int)num; string text2 = num.ToString(); int quotaFulfilled = TimeOfDay.Instance.quotaFulfilled; int daysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline; int groupCredits = TerminalApi.Terminal.groupCredits; if (text.Contains("quota")) { return CalculateQuota(quota, quotaFulfilled); } if (text.Contains("help")) { return "CreditCalculator commands:\n\n>CALC [wanted value of money or expression]\nTo calculate how much scrap you need to sell to achieve your wanted value of money.\n\n>CALC QUOTA\nTo subtract the already sold money from your quota.\n\n>CALC OVERTIME\nTo calculate how much overtime pay you'll get. \n\n"; } if (text.Contains("overtime")) { return CalculateOvertime(quotaFulfilled, quota, daysUntilDeadline, groupCredits); } try { int num2 = ((!text.Contains("+") && !text.Contains("-") && !text.Contains("*") && !text.Contains("/")) ? int.Parse(text) : EvaluateExpression(text)); } catch (Exception ex) { return "Error parsing input: " + ex.Message; } string text3 = quotaFulfilled.ToString(); int num3 = ((!array[1].Contains("+") && !array[1].Contains("-") && !array[1].Contains("*") && !array[1].Contains("/")) ? int.Parse(array[1]) : EvaluateExpression(array[1])); int num4 = num3 - groupCredits; float num5 = ((float)(5 * num4) + num + 75f) / 6f; float num6 = (float)Math.Ceiling(num5); string text4 = ((num6 % 1f == 0f) ? num6.ToString("0") : num6.ToString("0.##")); if (num5 <= num) { return $"You should sell ${num}(your quota)\n Reason:\n The result of the calculation was as much or less than you quota.\n\n"; } if ((Object)(object)HUDTipBroadcaster.Instance == (Object)null) { Debug.Log((object)"[CalculatorMod] HUDTipBroadcaster is null, creating new instance."); GameObject val = new GameObject("HUDTipBroadcaster"); val.AddComponent<HUDTipBroadcaster>(); val.AddComponent<NetworkObject>(); Object.DontDestroyOnLoad((Object)(object)val); } else { Debug.Log((object)"[CalculatorMod] HUDTipBroadcaster already exists, reusing."); } HUDTipBroadcaster.ShowHUDTip(text4); ChatUtils.SendChat($"You should sell ${text4:F2} worth of scrap."); return $"You should sell ${text4:F2} worth of scrap.\n Calculations:\n (5 * ({num3}(wanted) - {groupCredits}(credits))\n + {num}(quota) + 75) / 6\n \nA message to the chat has been sent.\n\n"; } private int EvaluateExpression(string expression) { DataTable dataTable = new DataTable(); object value = dataTable.Compute(expression, string.Empty); return Convert.ToInt32(value); } private string CalculateQuota(int quota, int quotaFulfilled) { return $"You should sell ${quota - quotaFulfilled} worth of scrap to achieve your quota.\n Calculations:\n {quota}(Your quota) - {quotaFulfilled}(sold) = {quota - quotaFulfilled}\n\n"; } private string CalculateOvertime(int quotaFulfilled, int quota, int daysUntilDeadline, int currentCredits) { int num = (quotaFulfilled - quota) / 5 + 15 * daysUntilDeadline; return $"If you leave now, you'll get ${num} of overtime bonus. \n Calculations:\n (({quotaFulfilled}(sold) - {quota}(quota) / 5) + (15 * {daysUntilDeadline}(Days until deadline) \n\nThe total amount of credits you'll get is ${currentCredits + num}. \n Calculations:\n {currentCredits}(credits) + {num}(Overtime pay)\n\n"; } }