Decompiled source of SelBure v1.1.0

SellBodies/SellBodies.dll

Decompiled 10 months ago
using 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")]
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("Entity378.sellbodies", "Sell Bodies", "1.0.0")]
	[BepInDependency("evaisa.lethallib", "0.10.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("Entity378.sellbodies");

		private const string GUID = "Entity378.sellbodies";

		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 + "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 + "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 + "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 + "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)
		{
			PhysicsProp val = default(PhysicsProp);
			((NetworkBehaviourReference)(ref netRef)).TryGet<PhysicsProp>(ref val, (NetworkManager)null);
			if ((Object)(object)val != (Object)null)
			{
				((GrabbableObject)val).scrapValue = price;
				((GrabbableObject)val).itemProperties.creditsWorth = price;
				((Component)val).GetComponentInChildren<ScanNodeProperties>().subText = $"Value: ${price}";
				Debug.Log((object)"Successfully synced body values");
			}
			else
			{
				Debug.LogError((object)"Failed to resolve network reference!");
			}
		}
	}
}
namespace CleaningCompany.Misc
{
	public class PluginConfig
	{
		private readonly ConfigFile configFile;

		public bool SPIDER { get; set; }

		public bool THUMPER { 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 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 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 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, "");
			BRACKEN_MAX = ConfigEntry("Body Values", "Max price of Bracken Bodies", 140, "");
			BRACKEN_MIN = ConfigEntry("Body Values", "Min price of Bracken Bodies", 100, "");
			BABOON_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, "");
			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, "");
			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, "");
		}
	}
}