Please disclose if any significant portion of your mod was created 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 TruckPersistence v1.0.2
TruckPersistence.dll
Decompiled 10 months agousing 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 HarmonyLib; 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("TruckPersistence")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("TruckPersistence")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("702fbac3-3360-41e3-94cd-8234d7d34202")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] public class TruckPersistedValuable : MonoBehaviour { } [BepInPlugin("tread.repo.truckpersistence", "Truck Persistence", "1.0.2")] public class TruckPersistencePlugin : BaseUnityPlugin { private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown ((BaseUnityPlugin)this).Logger.LogInfo((object)"Truck Persistence loaded!"); Harmony val = new Harmony("tread.repo.truckpersistence"); val.PatchAll(); } } [HarmonyPatch(typeof(RoundDirector), "StartRound")] internal class Patch_StartRound { [HarmonyPatch(typeof(RoundDirector), "StartRoundLogic")] private class Patch_StartRoundLogic { private static void Postfix() { Debug.Log((object)"[TruckPersistence] StartRoundLogic Postfix"); ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>(); foreach (ValuableObject val in array) { if ((Object)(object)((Component)val).GetComponent<TruckPersistedValuable>() != (Object)null) { KeepInTruck(val); } } } } [HarmonyPatch(typeof(ShopManager), "ShopInitialize")] private class Patch_ShopInitialize { private static void Prefix() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)"[TruckPersistence] ShopInitialize Prefix called"); ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>(); foreach (ValuableObject val in array) { if (IsInsideTruck(((Component)val).transform.position) && (Object)(object)((Component)val).GetComponent<TruckPersistedValuable>() == (Object)null) { ((Component)val).gameObject.AddComponent<TruckPersistedValuable>(); Debug.Log((object)("[TruckPersistence] Marked " + ((Object)val).name + " for persistence")); } } } private static bool IsInsideTruck(Vector3 pos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) return pos.y > 0f && pos.z > 5f; } } private static void Prefix() { Debug.Log((object)"[TruckPersistence] StartRound Prefix called"); ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>(); foreach (ValuableObject val in array) { if ((Object)(object)((Component)val).GetComponent<TruckPersistedValuable>() != (Object)null) { KeepInTruck(val); } } } private static Transform FindTruck() { GameObject val = GameObject.Find("Truck"); if ((Object)(object)val == (Object)null) { Debug.LogError((object)"[TruckPersistence] Truck not found!"); return null; } return val.transform; } private static void KeepInTruck(ValuableObject v) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) TruckHealer val = Object.FindObjectOfType<TruckHealer>(); if (!((Object)(object)val == (Object)null)) { Transform transform = ((Component)val).transform; ((Component)v).transform.SetParent(transform, true); Rigidbody component = ((Component)v).GetComponent<Rigidbody>(); if ((Object)(object)component != (Object)null) { component.isKinematic = true; component.velocity = Vector3.zero; component.angularVelocity = Vector3.zero; } Debug.Log((object)("[TruckPersistence] Restored " + ((Object)v).name)); } } private static bool IsInsideTruck(ValuableObject v) { //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_0059: Unknown result type (might be due to invalid IL or missing references) TruckHealer val = Object.FindObjectOfType<TruckHealer>(); if ((Object)(object)val == (Object)null) { return false; } Transform healSphere = val.healSphere; if ((Object)(object)healSphere == (Object)null) { return false; } Collider component = ((Component)healSphere).GetComponent<Collider>(); if ((Object)(object)component == (Object)null) { return false; } Bounds bounds = component.bounds; return ((Bounds)(ref bounds)).Contains(((Component)v).transform.position); } } [HarmonyPatch(typeof(ShopManager), "ShopInitialize")] internal class Patch_ShopInitialize { private static void Postfix(ShopManager __instance) { if (__instance.potentialItems == null) { return; } List<ValuableObject> truckValuables = (from v in Object.FindObjectsOfType<ValuableObject>() where (Object)(object)((Component)v).GetComponent<TruckPersistedValuable>() != (Object)null select v).ToList(); __instance.potentialItems.RemoveAll((Item item) => truckValuables.Any((ValuableObject v) => ((Object)v).name == ((Object)item).name)); Debug.Log((object)"[TruckPersistence] Removed truck-persisted items from potentialItems"); } } [HarmonyPatch(typeof(RoundDirector), "EndRound")] internal class Patch_EndRound { private static void Prefix() { ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>(); foreach (ValuableObject val in array) { if (IsInsideTruck(val)) { ((Component)val).gameObject.AddComponent<TruckPersistedValuable>(); Debug.Log((object)("[TruckPersistence] Marked " + ((Object)val).name)); } } } private static bool IsInsideTruck(ValuableObject v) { //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_0059: Unknown result type (might be due to invalid IL or missing references) TruckHealer val = Object.FindObjectOfType<TruckHealer>(); if ((Object)(object)val == (Object)null) { return false; } Transform healSphere = val.healSphere; if ((Object)(object)healSphere == (Object)null) { return false; } Collider component = ((Component)healSphere).GetComponent<Collider>(); if ((Object)(object)component == (Object)null) { return false; } Bounds bounds = component.bounds; return ((Bounds)(ref bounds)).Contains(((Component)v).transform.position); } }