using 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 UnityEngine;
[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")]
namespace Calculator;
[BepInPlugin("Poseidon.Calculator", "Calculator", "1.0.0.5")]
public class CalculatorBase : BaseUnityPlugin
{
private const string modGUID = "Poseidon.Calculator";
private const string modName = "Calculator";
private const string modVersion = "1.0.0.5";
private readonly Harmony harmony = new Harmony("Poseidon.Calculator");
private 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 help", new CommandInfo
{
Category = "other",
Description = "To open the 'calc' command catalog",
DisplayTextSupplier = OnCalcCommand
}, "check", true);
}
private string OnCalcCommand()
{
string terminalInput = TerminalApi.GetTerminalInput();
string[] array = terminalInput.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;
int quotaFulfilled = TimeOfDay.Instance.quotaFulfilled;
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";
}
int num2;
try
{
num2 = ((!text.Contains("+") && !text.Contains("-") && !text.Contains("*") && !text.Contains("/")) ? int.Parse(text) : EvaluateExpression(text));
}
catch (Exception ex)
{
return "Error parsing input: " + ex.Message;
}
string text2 = quotaFulfilled.ToString();
string formattedResult = num.ToString();
int groupCredits = TerminalApi.Terminal.groupCredits;
int num3 = num2 - groupCredits;
float num4 = ((float)(5 * num3) + num + 75f) / 6f;
float num5 = (float)Math.Ceiling(num4);
string text3 = ((num5 % 1f == 0f) ? num5.ToString("0") : num5.ToString("0.##"));
if (num4 <= num)
{
ShowHUDTip(formattedResult);
return $"You should sell ${num}(your quota)\n Reason:\n The result of the calculation was either \n 1. As much as your quota \n or\n 2. Smaller than your quota.\n\n";
}
ShowHUDTip(text3);
return $"You should sell ${text3:F2} worth of scrap.\n Calculations:\n (5 * ({num2}(wanted) - {groupCredits}(credits))\n + {num}(quota) + 75) / 6\n \nA message to the chat has also 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 void ShowHUDTip(string formattedResult)
{
string chatMessage = "You should sell $" + formattedResult + " worth of scrap.";
string userWhoTyped = "Credit Calculator";
string text = "Credit Calculator:";
string text2 = "A message has been sent to the chat.";
bool flag = false;
bool flag2 = false;
string text3 = "LC_Tip1";
int playerId = 0;
try
{
HUDManager.Instance.DisplayTip(text, text2, flag, flag2, text3);
AddMessageToChat(chatMessage, userWhoTyped, playerId);
}
catch (Exception arg)
{
mls.LogError((object)$"Error while calling HUDManager.displayTip: {arg}");
}
}
public void AddMessageToChat(string chatMessage, string userWhoTyped = "", int playerId = -1)
{
try
{
MethodInfo method = typeof(HUDManager).GetMethod("AddChatMessage", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method2 = typeof(HUDManager).GetMethod("AddPlayerChatMessageServerRpc", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(HUDManager.Instance, new object[2] { chatMessage, userWhoTyped });
if (playerId >= 0 && playerId < StartOfRound.Instance.allPlayerScripts.Length)
{
method2.Invoke(HUDManager.Instance, new object[2] { chatMessage, playerId });
}
else
{
mls.LogInfo((object)$"Invalid playerId: {playerId}. Skipping AddPlayerChatMessageServerRpc.");
}
}
catch (Exception arg)
{
mls.LogError((object)$"Error invoking AddChatMessage: {arg}");
}
}
}