Decompiled source of Melanies NPCs v0.0.3

MelanieMeliciousNPCs.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MelMelNPC;
using MelanieMeliciousNPCs.NetcodePatcher;
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: AssemblyTitle("MelanieMeliciousNPC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MelanieMelicious")]
[assembly: AssemblyProduct("Melanie's NPCs")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class MelMelNPCsCfg
{
	internal static ConfigEntry<string> NPC0Shop0Buy;

	internal static ConfigEntry<string> NPC0Shop0Sell;

	internal static ConfigEntry<string> NPC0Shop0Trade;

	internal static void SetupConfig(ConfigFile config)
	{
		NPC0Shop0Buy = config.Bind<string>("Abandoned Scavenger 1", "Shop 1 Buyables", "40;Easter egg", "Add custom entries to this shop's buy section. Cost to buy, and item given.");
		NPC0Shop0Sell = config.Bind<string>("Abandoned Scavenger 1", "Shop 1 Sellables", "Toy cube;1.1", "Add custom entries to this shop's sell section. Item to sell, and sell multiplier.");
		NPC0Shop0Trade = config.Bind<string>("Abandoned Scavenger 1", "Shop 1 Tradables", "Apparatus;Jetpack,Key;Shovel,Key;Pro-flashlight", "Add custom entries to this shop's trade section. Item to trade, and item given.");
	}
}
namespace MelMelNPCs
{
	public class HarmonyPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "SpawnSyncedProps")]
		private static void SpawnCompanyNPCs(RoundManager __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (GameNetworkManager.Instance.isHostingGame && __instance.currentLevel.levelID == 3)
			{
				GameObject val = Object.Instantiate<GameObject>(Plugin.bundle.LoadAsset<GameObject>("Assets/MelanieNPC/Prefab/MelMelNPC0.prefab"), new Vector3(-18f, -2.6f, -32.6f), Quaternion.identity, __instance.mapPropsContainer.transform);
				NetworkObject component = val.GetComponent<NetworkObject>();
				component.Spawn(true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		private static void PostStart(StartOfRound __instance)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Expected O, but got Unknown
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Expected O, but got Unknown
			NPCShopNode val = Plugin.bundle.LoadAsset<NPCShopNode>("Assets/MelanieNPC/Asset/NPCs/MelMelNPC0/MelMelNPCShop0.asset");
			try
			{
				string[] array = MelMelNPCsCfg.NPC0Shop0Buy.Value.Split(',');
				foreach (string text in array)
				{
					string[] array2 = text.Split(';');
					foreach (Item items in __instance.allItemsList.itemsList)
					{
						if (items.itemName == array2[1])
						{
							val.buyList.Add(new NPCShopBuy
							{
								buy = items,
								buyCost = int.Parse(array2[0], CultureInfo.InvariantCulture)
							});
							break;
						}
					}
				}
			}
			catch
			{
				Plugin.mls.LogError((object)"Invalid config input for Abandoned Scavenger 1 Shop 1 Buyables config!");
			}
			try
			{
				string[] array3 = MelMelNPCsCfg.NPC0Shop0Sell.Value.Split(',');
				foreach (string text2 in array3)
				{
					string[] array4 = text2.Split(';');
					foreach (Item items2 in __instance.allItemsList.itemsList)
					{
						if (items2.itemName == array4[0])
						{
							val.sellList.Add(new NPCShopSell
							{
								sell = items2,
								sellMulti = float.Parse(array4[1], CultureInfo.InvariantCulture)
							});
							break;
						}
					}
				}
			}
			catch
			{
				Plugin.mls.LogError((object)"Invalid config input for Abandoned Scavenger 1 Shop 1 Sellables config!");
			}
			try
			{
				string[] array5 = MelMelNPCsCfg.NPC0Shop0Trade.Value.Split(',');
				foreach (string text3 in array5)
				{
					string[] array6 = text3.Split(';');
					Item val2 = null;
					Item val3 = null;
					foreach (Item items3 in __instance.allItemsList.itemsList)
					{
						if (items3.itemName == array6[0])
						{
							val2 = items3;
						}
						if (items3.itemName == array6[1])
						{
							val3 = items3;
						}
						if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
						{
							continue;
						}
						val.tradeList.Add(new NPCShopTrade
						{
							tradeWant = val2,
							tradeGive = val3
						});
						break;
					}
				}
			}
			catch
			{
				Plugin.mls.LogError((object)"Invalid config input for Abandoned Scavenger 1 Shop 1 Tradables config!");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static void NetworkPatch(ref GameNetworkManager __instance)
		{
			((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Plugin.bundle.LoadAsset<GameObject>("Assets/MelanieNPC/Prefab/MelMelNPC0.prefab"));
		}
	}
	[BepInPlugin("MelanieMelicious.NPCs", "MelanieMelicious - Melanie NPCs", "0.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "MelanieMelicious.NPCs";

		private const string NAME = "MelanieMelicious - Melanie NPCs";

		private const string VERSION = "0.0.3";

		public const string NAMESPACE = "melanienpcs";

		private readonly Harmony harmony = new Harmony("MelanieMelicious.NPCs");

		public static ManualLogSource mls;

		public static AssetBundle bundle;

		public static Plugin instance;

		private void Awake()
		{
			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);
					}
				}
			}
			instance = this;
			MelMelNPCsCfg.SetupConfig(((BaseUnityPlugin)this).Config);
			mls = Logger.CreateLogSource("MelanieMelicious - Melanie NPCs");
			mls = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "melanienpc");
			bundle = AssetBundle.LoadFromFile(text);
			harmony.PatchAll(typeof(HarmonyPatches));
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace MelanieMeliciousNPCs.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}