using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
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("PurchaseLogger")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PurchaseLogger")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ff798af5-342f-41e2-b24c-485c33987a97")]
[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 PurchaseLogger;
internal class Patches
{
private static string ApproximateTerminalUser(Terminal terminal)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
string result = "Unknown";
RaycastHit[] source = Physics.SphereCastAll(((Component)terminal.placeableObject).transform.position, 2f, Vector3.forward);
List<RaycastHit> list = source.OrderBy((RaycastHit x) => ((RaycastHit)(ref x)).distance).ToList();
IHittable val = default(IHittable);
foreach (RaycastHit item in list)
{
RaycastHit current = item;
if (!((Component)((RaycastHit)(ref current)).transform).TryGetComponent<IHittable>(ref val) || !(val is PlayerControllerB))
{
continue;
}
result = ((PlayerControllerB)val).playerUsername;
break;
}
return result;
}
private static void LogPurchase(string purchase)
{
PurchaseLogger.mls.LogInfo((object)purchase);
if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
object[] args = new object[1] { purchase };
((object)HUDManager.Instance).GetType().InvokeMember("DisplaySpectatorTip", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, HUDManager.Instance, args);
}
HUDManager.Instance.AddTextToChatOnServer(purchase, -1);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Terminal), "BuyItemsServerRpc")]
private static void PostBuyItemsServerRpc(Terminal __instance, int[] boughtItems)
{
if (NetworkManager.Singleton.IsHost)
{
string purchase = string.Format("[Purchase Logger] {0} bought {1} {2}{3}", ApproximateTerminalUser(__instance), boughtItems.Length, __instance.buyableItemsList[boughtItems[0]].itemName, (boughtItems.Length > 1) ? "s" : "");
LogPurchase(purchase);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Terminal), "BuyVehicleServerRpc")]
private static void PostBuyVehicleServerRpc(Terminal __instance, int vehicleID)
{
if (NetworkManager.Singleton.IsHost)
{
string purchase = "[Purchase Logger] " + ApproximateTerminalUser(__instance) + " bought the Company Cruiser";
LogPurchase(purchase);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "BuyShipUnlockableServerRpc")]
private static void PostBuyShipUnlockableServerRpc(int unlockableID)
{
if (NetworkManager.Singleton.IsHost)
{
Terminal terminal = Object.FindObjectOfType<Terminal>();
string text = ApproximateTerminalUser(terminal);
if (!text.Equals(GameNetworkManager.Instance.localPlayerController.playerUsername))
{
string purchase = "[Purchase Logger] " + text + " bought the " + StartOfRound.Instance.unlockablesList.unlockables[unlockableID].unlockableName;
LogPurchase(purchase);
}
}
}
}
[BepInPlugin("slapitnow.purchaselogger", "PurchaseLogger", "22.0.1")]
public class PurchaseLogger : BaseUnityPlugin
{
private const string modGUID = "slapitnow.purchaselogger";
private const string modName = "PurchaseLogger";
private const string modVersion = "22.0.1";
private readonly Harmony harmony = new Harmony("slapitnow.purchaselogger");
public static ManualLogSource mls;
private void Awake()
{
mls = Logger.CreateLogSource("slapitnow.purchaselogger");
harmony.PatchAll(typeof(PurchaseLogger));
harmony.PatchAll(typeof(Patches));
mls.LogInfo((object)"Version 22.0.1 loaded!");
}
}