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 SellBodies v1.1.0
BepInEx/plugins/SellBodies/SellBodies.dll
Decompiled 2 years agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using CleaningCompany.Misc; using CleaningCompany.Monos; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SellBodies")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SellBodies")] [assembly: AssemblyTitle("SellBodies")] [assembly: AssemblyVersion("1.0.0.0")] 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; } } } namespace CleaningCompany { [BepInPlugin("malco.sell_bodies", "Sell Bodies", "1.0.0")] [BepInDependency("evaisa.lethallib", "0.10.0")] public class Plugin : BaseUnityPlugin { private readonly Harmony harmony = new Harmony("malco.sell_bodies"); private const string GUID = "malco.sell_bodies"; private const string NAME = "Sell Bodies"; private const string VERSION = "1.0.0"; private static string root = "Assets/CleaningAssets/"; private Dictionary<string, int> minBodyValues; private Dictionary<string, bool> BodiesToDrop; private Dictionary<string, int> maxBodyValues; private Dictionary<string, float> bodyWeights; private Dictionary<string, string> pathToName = new Dictionary<string, string> { { root + "HoarderItem.asset", "Hoarding bug" }, { root + "SpiderItem.asset", "Bunker Spider" }, { root + "ThumperItem.asset", "Crawler" }, { root + "CentipedeItem.asset", "Centipede" }, { root + "NutcrackerItem.asset", "Nutcracker" }, { root + "BrackenBodyItem.asset", "Flowerman" }, { root + "BaboonItem.asset", "Baboon hawk" }, { root + "MouthDogItem.asset", "MouthDog" } }; public Dictionary<string, Item> BodySpawns = new Dictionary<string, Item>(); public List<GameObject> tools = new List<GameObject>(); private AssetBundle bundle; public static Plugin instance; public static PluginConfig cfg { get; private set; } private void Awake() { cfg = new PluginConfig(((BaseUnityPlugin)this).Config); cfg.InitBindings(); 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); } } } string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sellbodies"); bundle = AssetBundle.LoadFromFile(text); instance = this; ApplyConfig(); SetupScrap(); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Sell Bodies is patched!"); } private void ApplyConfig() { bodyWeights = new Dictionary<string, float> { { root + "HoarderItem.asset", cfg.HOARDER_WEIGHT }, { root + "SpiderItem.asset", cfg.SPIDER_WEIGHT }, { root + "ThumperItem.asset", cfg.THUMPER_WEIGHT }, { root + "NutcrackerItem.asset", cfg.NUTCRACKER_WEIGHT }, { root + "CentipedeItem.asset", cfg.CENTIPEDE_WEIGHT }, { root + "BrackenBodyItem.asset", cfg.BRACKEN_WEIGHT }, { root + "BaboonItem.asset", cfg.BABOON_WEIGHT }, { root + "MouthDogItem.asset", cfg.MOUTHDOG_WEIGHT } }; maxBodyValues = new Dictionary<string, int> { { root + "HoarderItem.asset", cfg.HOARDER_MAX }, { root + "SpiderItem.asset", cfg.SPIDER_MAX }, { root + "ThumperItem.asset", cfg.THUMPER_MAX }, { root + "NutcrackerItem.asset", cfg.NUTCRACKER_MAX }, { root + "CentipedeItem.asset", cfg.CENTIPEDE_MAX }, { root + "BrackenBodyItem.asset", cfg.BRACKEN_MAX }, { root + "BaboonItem.asset", cfg.BABOON_MAX }, { root + "MouthDogItem.asset", cfg.MOUTHDOG_MAX } }; minBodyValues = new Dictionary<string, int> { { root + "HoarderItem.asset", cfg.HOARDER_MIN }, { root + "SpiderItem.asset", cfg.SPIDER_MIN }, { root + "ThumperItem.asset", cfg.THUMPER_MIN }, { root + "NutcrackerItem.asset", cfg.NUTCRACKER_MIN }, { root + "CentipedeItem.asset", cfg.CENTIPEDE_MIN }, { root + "BrackenBodyItem.asset", cfg.BRACKEN_MIN }, { root + "BaboonItem.asset", cfg.BABOON_MIN }, { root + "MouthDogItem.asset", cfg.MOUTHDOG_MIN } }; BodiesToDrop = new Dictionary<string, bool> { { root + "HoarderItem.asset", cfg.HOARDER }, { root + "SpiderItem.asset", cfg.SPIDER }, { root + "ThumperItem.asset", cfg.THUMPER }, { root + "NutcrackerItem.asset", cfg.NUTCRACKER }, { root + "CentipedeItem.asset", cfg.CENTIPEDE }, { root + "BrackenBodyItem.asset", cfg.BRACKEN }, { root + "BaboonItem.asset", cfg.BABOON }, { root + "MouthDogItem.asset", cfg.MOUTHDOG } }; } private void SetupScrap() { foreach (KeyValuePair<string, string> item in pathToName) { Item val = bundle.LoadAsset<Item>(item.Key); Utilities.FixMixerGroups(val.spawnPrefab); val.twoHanded = true; val.spawnPrefab.AddComponent<BodySyncer>(); val.maxValue = maxBodyValues[item.Key]; val.minValue = minBodyValues[item.Key]; val.weight = bodyWeights[item.Key]; NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab); Items.RegisterItem(val); if (BodiesToDrop[item.Key]) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Set " + item.Value + " to drop " + val.itemName)); BodySpawns.Add(item.Value, val); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Disregarding " + val.itemName + " - disabled in config")); } } } } } namespace CleaningCompany.Patches { [HarmonyPatch(typeof(EnemyAI))] internal class EnemyAIPatcher { private static ulong currentEnemy = 9999999uL; [HarmonyPostfix] [HarmonyPatch("KillEnemyServerRpc")] private static void SpawnScrapBody(EnemyAI __instance) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (currentEnemy != ((NetworkBehaviour)__instance).NetworkObject.NetworkObjectId && ((NetworkBehaviour)__instance).IsHost) { currentEnemy = ((NetworkBehaviour)__instance).NetworkObject.NetworkObjectId; string enemyName = __instance.enemyType.enemyName; if (Plugin.instance.BodySpawns.ContainsKey(enemyName)) { GameObject val = Object.Instantiate<GameObject>(Plugin.instance.BodySpawns[enemyName].spawnPrefab, ((Component)__instance).transform.position + Vector3.up, Quaternion.identity); val.GetComponent<NetworkObject>().Spawn(false); ((Component)__instance).GetComponent<NetworkObject>().Despawn(true); } } } } } namespace CleaningCompany.Monos { internal class BodySyncer : NetworkBehaviour { public override void OnNetworkSpawn() { if (((NetworkBehaviour)this).IsHost || ((NetworkBehaviour)this).IsServer) { ((MonoBehaviour)this).StartCoroutine(WaitToSync()); } ((NetworkBehaviour)this).OnNetworkSpawn(); } private IEnumerator WaitToSync() { yield return (object)new WaitForSeconds(1f); PhysicsProp prop = ((Component)this).GetComponent<PhysicsProp>(); int price = Random.Range(((GrabbableObject)prop).itemProperties.minValue, ((GrabbableObject)prop).itemProperties.maxValue); SyncDetailsClientRpc(price, new NetworkBehaviourReference((NetworkBehaviour)(object)prop)); } [ClientRpc] private void SyncDetailsClientRpc(int price, NetworkBehaviourReference netRef) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val = default(ClientRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1512427331u, val, (RpcDelivery)0); BytePacker.WriteValueBitPacked(val2, price); ((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref netRef, default(ForNetworkSerializable)); ((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1512427331u, val, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost)) { PhysicsProp val3 = default(PhysicsProp); ((NetworkBehaviourReference)(ref netRef)).TryGet<PhysicsProp>(ref val3, (NetworkManager)null); if ((Object)(object)val3 != (Object)null) { ((GrabbableObject)val3).scrapValue = price; ((GrabbableObject)val3).itemProperties.creditsWorth = price; ((Component)val3).GetComponentInChildren<ScanNodeProperties>().subText = $"Value: ${price}"; Debug.Log((object)"Successfully synced body values"); } else { Debug.LogError((object)"Failed to resolve network reference!"); } } } protected override void __initializeVariables() { ((NetworkBehaviour)this).__initializeVariables(); } [RuntimeInitializeOnLoadMethod] internal static void InitializeRPCS_BodySyncer() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown NetworkManager.__rpc_func_table.Add(1512427331u, new RpcReceiveHandler(__rpc_handler_1512427331)); } private static void __rpc_handler_1512427331(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { int price = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref price); NetworkBehaviourReference netRef = default(NetworkBehaviourReference); ((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref netRef, default(ForNetworkSerializable)); target.__rpc_exec_stage = (__RpcExecStage)2; ((BodySyncer)(object)target).SyncDetailsClientRpc(price, netRef); target.__rpc_exec_stage = (__RpcExecStage)0; } } protected internal override string __getTypeName() { return "BodySyncer"; } } } namespace CleaningCompany.Misc { public class PluginConfig { private readonly ConfigFile configFile; public bool SPIDER { get; set; } public bool THUMPER { get; set; } public bool NUTCRACKER { get; set; } public bool CENTIPEDE { get; set; } public bool HOARDER { get; set; } public bool BRACKEN { get; set; } public bool MOUTHDOG { get; set; } public bool BABOON { get; set; } public int SPIDER_MIN { get; set; } public int THUMPER_MIN { get; set; } public int NUTCRACKER_MIN { get; set; } public int CENTIPEDE_MIN { get; set; } public int HOARDER_MIN { get; set; } public int BRACKEN_MIN { get; set; } public int MOUTHDOG_MIN { get; set; } public int BABOON_MIN { get; set; } public int NUTCRACKER_MAX { get; set; } public int SPIDER_MAX { get; set; } public int THUMPER_MAX { get; set; } public int CENTIPEDE_MAX { get; set; } public int HOARDER_MAX { get; set; } public int BRACKEN_MAX { get; set; } public int MOUTHDOG_MAX { get; set; } public int BABOON_MAX { get; set; } public float NUTCRACKER_WEIGHT { get; set; } public float SPIDER_WEIGHT { get; set; } public float THUMPER_WEIGHT { get; set; } public float CENTIPEDE_WEIGHT { get; set; } public float HOARDER_WEIGHT { get; set; } public float BRACKEN_WEIGHT { get; set; } public float MOUTHDOG_WEIGHT { get; set; } public float BABOON_WEIGHT { get; set; } public PluginConfig(ConfigFile cfg) { configFile = cfg; } private T ConfigEntry<T>(string section, string key, T defaultVal, string description) { return configFile.Bind<T>(section, key, defaultVal, description).Value; } public void InitBindings() { CENTIPEDE_MIN = ConfigEntry("Body Values", "Min price of Centipede Bodies", 45, ""); CENTIPEDE_MAX = ConfigEntry("Body Values", "Max price of Centipede Bodies", 70, ""); HOARDER_MIN = ConfigEntry("Body Values", "Min price of Hoarding Bug Bodies", 55, ""); HOARDER_MAX = ConfigEntry("Body Values", "Max price of Hoarding Bug Bodies", 88, ""); SPIDER_MIN = ConfigEntry("Body Values", "Min price of Spider Bodies", 70, ""); SPIDER_MAX = ConfigEntry("Body Values", "Max price of Spider Bodies", 110, ""); THUMPER_MIN = ConfigEntry("Body Values", "Min price of Thumper Bodies", 120, ""); THUMPER_MAX = ConfigEntry("Body Values", "Max price of Thumper Bodies", 160, ""); NUTCRACKER_MIN = ConfigEntry("Body Values", "Min price of Nutcracker Bodies", 125, ""); NUTCRACKER_MAX = ConfigEntry("Body Values", "Max price of Nutcracker Bodies", 150, ""); BRACKEN_MAX = ConfigEntry("Body Values", "Max price of Bracken Bodies", 140, ""); BRACKEN_MIN = ConfigEntry("Body Values", "Min price of Bracken Bodies", 100, ""); BRACKEN_MAX = ConfigEntry("Body Values", "Max price of Baboon Hawk Bodies", 155, ""); BABOON_MIN = ConfigEntry("Body Values", "Min price of Baboon Hawk Bodies", 105, ""); MOUTHDOG_MAX = ConfigEntry("Body Values", "Max price of Eyeless Dog Bodies", 200, ""); MOUTHDOG_MIN = ConfigEntry("Body Values", "Min price of Eyeless Dog Bodies", 175, ""); CENTIPEDE = ConfigEntry("Body Weights", "Enable selling of centipede bodies", defaultVal: true, ""); HOARDER = ConfigEntry("Body Weights", "Enable selling of hoarder bodies", defaultVal: true, ""); SPIDER = ConfigEntry("Body Weights", "Enable selling of spider bodies", defaultVal: true, ""); THUMPER = ConfigEntry("Body Weights", "Enable selling of crawler / half / thumper bodies", defaultVal: true, ""); NUTCRACKER = ConfigEntry("Body Weights", "Enable selling of nutcracker bodies", defaultVal: true, ""); MOUTHDOG = ConfigEntry("Body Weights", "Enable selling of eyeless dog bodies", defaultVal: true, ""); BABOON = ConfigEntry("Body Weights", "Enable selling of baboon hawk bodies", defaultVal: true, ""); BRACKEN = ConfigEntry("Body Weights", "Enable selling of bracken bodies", defaultVal: true, ""); CENTIPEDE_WEIGHT = ConfigEntry("Body Weights", "Weight of Centipede Bodies", 1.65f, ""); HOARDER_WEIGHT = ConfigEntry("Body Weights", "Weight of Hoarding Bug Bodies", 1.6f, ""); SPIDER_WEIGHT = ConfigEntry("Body Weights", "Weight of Spider Bodies", 2.3f, ""); THUMPER_WEIGHT = ConfigEntry("Body Weights", "Weight of Thumper Bodies", 2.9f, ""); NUTCRACKER_WEIGHT = ConfigEntry("Body Weights", "Weight of Nutcracker Bodies", 2.9f, ""); MOUTHDOG_WEIGHT = ConfigEntry("Body Weights", "Weight of Eyeless Dog Bodies", 3f, ""); BABOON_WEIGHT = ConfigEntry("Body Weights", "Weight of Baboon Hawk Bodies", 2.5f, ""); BRACKEN_WEIGHT = ConfigEntry("Body Weights", "Weight of Bracken Bodies", 1.9f, ""); } } }