Decompiled source of Pocket Rooms MelanieMelicious v1.1.0

MelanieMeliciousPocketRoom.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dawn;
using HarmonyLib;
using LethalLevelLoader;
using MelanieMeliciousPocketRoom.NetcodePatcher;
using Microsoft.CodeAnalysis;
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("MelaniePocketRoom")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MelanieMelicious")]
[assembly: AssemblyProduct("MelaniePocketRoom")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[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.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;
		}
	}
	[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 PocketRoomCfg
{
	internal enum mat
	{
		Wood,
		WoodPlank,
		MetalFlat,
		Glass,
		Blank
	}

	internal static ConfigEntry<bool> stockRoom0;

	internal static ConfigEntry<int> stockRoom0Cost;

	internal static ConfigEntry<bool> bedRoom0;

	internal static ConfigEntry<bool> bedRoom1;

	internal static ConfigEntry<int> bedRoom0Cost;

	internal static ConfigEntry<bool> cellar0;

	internal static ConfigEntry<int> cellar0Cost;

	internal static ConfigEntry<mat> stockRoom0Floor;

	internal static ConfigEntry<string> stockRoom0FloorHex;

	internal static ConfigEntry<mat> stockRoom0Wall;

	internal static ConfigEntry<string> stockRoom0WallHex;

	internal static ConfigEntry<string> stockRoom0Furniture;

	internal static ConfigEntry<mat> bedRoom0Floor;

	internal static ConfigEntry<string> bedRoom0FloorHex;

	internal static ConfigEntry<mat> bedRoom0Wall;

	internal static ConfigEntry<string> bedRoom0WallHex;

	internal static ConfigEntry<string> bedRoom0Furniture;

	internal static ConfigEntry<mat> bedRoom1Floor;

	internal static ConfigEntry<string> bedRoom1FloorHex;

	internal static ConfigEntry<mat> bedRoom1Wall;

	internal static ConfigEntry<string> bedRoom1WallHex;

	internal static ConfigEntry<string> bedRoom1Furniture;

	internal static ConfigEntry<mat> cellar0Floor;

	internal static ConfigEntry<string> cellar0FloorHex;

	internal static ConfigEntry<mat> cellar0Wall;

	internal static ConfigEntry<string> cellar0WallHex;

	internal static ConfigEntry<string> cellar0Furniture;

	private const string instruction = "Modify furniture for this room. Uses local position and rotation, relative to room. Separated by semicolon ';' per furniture item. Format: FurnitureName,XPos,YPos,ZPos,XRot,YRot,ZRot";

	internal static void SetupConfig(ConfigFile config)
	{
		stockRoom0 = config.Bind<bool>("Store Toggle", "Enable Stock Room 0", true, "Toggle StockRoom0");
		stockRoom0Cost = config.Bind<int>("Store Toggle", "Stock Room 0 Cost", 500, "Modify the price for StockRoom0.");
		bedRoom0 = config.Bind<bool>("Store Toggle", "Enable Bed Room 0", true, "Toggle BedRoom0");
		bedRoom1 = config.Bind<bool>("Store Toggle", "Enable Bed Room 1", true, "Toggle BedRoom1");
		bedRoom0Cost = config.Bind<int>("Store Toggle", "Small Bed Room Costs", 300, "Modify the prices for Small bedrooms.");
		cellar0 = config.Bind<bool>("Store Toggle", "Enable Cellar A", true, "Toggle BedRoom1");
		cellar0Cost = config.Bind<int>("Store Toggle", "Cellar Cost", 500, "Modify the prices for CellarA.");
		stockRoom0Floor = config.Bind<mat>("Customization", "StockRoom0 Floor Material.", mat.MetalFlat, "Modify material for StockRoom0 floor.");
		stockRoom0FloorHex = config.Bind<string>("Customization", "StockRoom0 Floor Color.", "847A66", "Modify color for StockRoom0 floor.");
		stockRoom0Wall = config.Bind<mat>("Customization", "StockRoom0 Wall Material.", mat.MetalFlat, "Modify material for StockRoom0 wall.");
		stockRoom0WallHex = config.Bind<string>("Customization", "StockRoom0 Wall Color.", "60594F", "Modify color for StockRoom0 wall.");
		stockRoom0Furniture = config.Bind<string>("Customization", "StockRoom0 Furniture.", "Shelf0,-2,2.7,-1,0,0,90;Shelf0,-5.8,-2.5,-1,0,0,180", "Modify furniture for this room. Uses local position and rotation, relative to room. Separated by semicolon ';' per furniture item. Format: FurnitureName,XPos,YPos,ZPos,XRot,YRot,ZRot");
		bedRoom0Floor = config.Bind<mat>("Customization", "BedRoom0 Floor Material.", mat.WoodPlank, "Modify material for BedRoom0 floor.");
		bedRoom0FloorHex = config.Bind<string>("Customization", "BedRoom0 Floor Color.", "955B25", "Modify color for BedRoom0 floor.");
		bedRoom0Wall = config.Bind<mat>("Customization", "BedRoom0 Wall Material.", mat.Wood, "Modify material for BedRoom0 wall.");
		bedRoom0WallHex = config.Bind<string>("Customization", "BedRoom0 Wall Color.", "F5BFC5", "Modify color for BedRoom0 wall.");
		bedRoom0Furniture = config.Bind<string>("Customization", "BedRoom0 Furniture.", string.Empty, "Modify furniture for this room. Uses local position and rotation, relative to room. Separated by semicolon ';' per furniture item. Format: FurnitureName,XPos,YPos,ZPos,XRot,YRot,ZRot");
		bedRoom1Floor = config.Bind<mat>("Customization", "BedRoom1 Floor Material.", mat.WoodPlank, "Modify material for BedRoom1 floor.");
		bedRoom1FloorHex = config.Bind<string>("Customization", "BedRoom1 Floor Color.", "594949", "Modify color for BedRoom1 floor.");
		bedRoom1Wall = config.Bind<mat>("Customization", "BedRoom1 Wall Material.", mat.Wood, "Modify material for BedRoom1 wall.");
		bedRoom1WallHex = config.Bind<string>("Customization", "BedRoom1 Wall Color.", "1D4D1F", "Modify color for BedRoom1 wall.");
		bedRoom1Furniture = config.Bind<string>("Customization", "BedRoom1 Furniture.", string.Empty, "Modify furniture for this room. Uses local position and rotation, relative to room. Separated by semicolon ';' per furniture item. Format: FurnitureName,XPos,YPos,ZPos,XRot,YRot,ZRot");
		cellar0Floor = config.Bind<mat>("Customization", "CellarA Floor Material.", mat.WoodPlank, "Modify material for CellarA floor.");
		cellar0FloorHex = config.Bind<string>("Customization", "CellarA Floor Color.", "594949", "Modify color for CellarA floor.");
		cellar0Wall = config.Bind<mat>("Customization", "CellarA Wall Material.", mat.Wood, "Modify material for CellarA wall.");
		cellar0WallHex = config.Bind<string>("Customization", "CellarA Wall Color.", "6F4A27", "Modify color for CellarA wall.");
		cellar0Furniture = config.Bind<string>("Customization", "CellarA Furniture.", string.Empty, "Modify furniture for this room. Uses local position and rotation, relative to room. Separated by semicolon ';' per furniture item. Format: FurnitureName,XPos,YPos,ZPos,XRot,YRot,ZRot");
	}
}
namespace MelaniePocketRooms
{
	public class HarmonyPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "Awake")]
		private static void PostText(Terminal __instance)
		{
			try
			{
				TerminalNode specialKeywordResult = __instance.terminalNodes.allKeywords[7].specialKeywordResult;
				if (!specialKeywordResult.displayText.Contains("SHIP UPGRADES:") || specialKeywordResult.displayText.Contains("StockRoomA") || specialKeywordResult.displayText.Contains("BedRoomA"))
				{
					return;
				}
				string text = string.Empty;
				foreach (ExtendedUnlockableItem extendedUnlockableItem in Plugin.extMod.ExtendedUnlockableItems)
				{
					text += $"\n* {extendedUnlockableItem.UnlockableItem.unlockableName}    //    Price: ${extendedUnlockableItem.ItemCost}";
				}
				specialKeywordResult.displayText = specialKeywordResult.displayText.Insert(specialKeywordResult.displayText.IndexOf(":") + 1, text);
			}
			catch
			{
				Plugin.mls.LogError((object)"Could not find vanilla store terminal node!");
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("MelanieMelicious.pocketRoom", "Melanie Melicious - Pocket Rooms", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "MelanieMelicious.pocketRoom";

		private const string NAME = "Melanie Melicious - Pocket Rooms";

		private const string VERSION = "1.1.0";

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

		private const string path = "Assets/MelaniePocketRoom/";

		public static ManualLogSource mls;

		public static AssetBundle bundle;

		public UnlockableItem[] unlockList;

		internal static ExtendedMod extMod;

		private bool alt = false;

		private void Awake()
		{
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			PocketRoomCfg.SetupConfig(((BaseUnityPlugin)this).Config);
			mls = Logger.CreateLogSource("MelanieMelicious - Pocket Rooms");
			mls = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "melaniepocketroom");
			bundle = AssetBundle.LoadFromFile(text);
			extMod = bundle.LoadAsset<ExtendedMod>("Assets/MelaniePocketRoom/MelaniePocketRoom.asset");
			if (Chainloader.PluginInfos.ContainsKey("com.github.teamxiaolan.dawnlib"))
			{
				unlockList = bundle.LoadAsset<UnlockablesList>("Assets/MelaniePocketRoom/Asset/RoomAlt.asset").unlockables.ToArray();
				alt = true;
			}
			else
			{
				unlockList = bundle.LoadAsset<UnlockablesList>("Assets/MelaniePocketRoom/Asset/Room.asset").unlockables.ToArray();
				harmony.PatchAll(typeof(HarmonyPatches));
			}
			Material[] array = (Material[])(object)new Material[5]
			{
				bundle.LoadAsset<Material>("Assets/MelaniePocketRoom/Material/Wood0.mat"),
				bundle.LoadAsset<Material>("Assets/MelaniePocketRoom/Material/Plank0.mat"),
				bundle.LoadAsset<Material>("Assets/MelaniePocketRoom/Material/MetalFlat0.mat"),
				bundle.LoadAsset<Material>("Assets/MelaniePocketRoom/Material/Glass.mat"),
				bundle.LoadAsset<Material>("Assets/MelaniePocketRoom/Material/Blank.mat")
			};
			LethalLevelLoaderNetworkManager.RegisterNetworkPrefab(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/StockRoom0Light.prefab"));
			LethalLevelLoaderNetworkManager.RegisterNetworkPrefab(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/BedRoom0Light.prefab"));
			LethalLevelLoaderNetworkManager.RegisterNetworkPrefab(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/Cellar0Light.prefab"));
			LethalLevelLoaderNetworkManager.RegisterNetworkPrefab(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Furniture/Shelf0.prefab"));
			if (Chainloader.PluginInfos.ContainsKey("MelanieMelicious.FarmAndCook"))
			{
				GameObject val = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/FurnitureSpawn.prefab"), Vector3.zero, Quaternion.identity);
				val.transform.parent = unlockList[3].prefabObject.transform.Find("Cellar0.1");
				val.GetComponent<PocketSyncSpawn>().prefab = bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/CellarPlace.prefab");
			}
			if (PocketRoomCfg.stockRoom0.Value)
			{
				RoomSetup((Material[])(object)new Material[2]
				{
					array[(short)PocketRoomCfg.stockRoom0Floor.Value],
					array[(short)PocketRoomCfg.stockRoom0Wall.Value]
				}, new string[2]
				{
					PocketRoomCfg.stockRoom0FloorHex.Value,
					PocketRoomCfg.stockRoom0WallHex.Value
				}, unlockList[0], PocketRoomCfg.stockRoom0Furniture.Value, PocketRoomCfg.stockRoom0Cost.Value);
			}
			if (PocketRoomCfg.bedRoom0.Value)
			{
				RoomSetup((Material[])(object)new Material[3]
				{
					array[(short)PocketRoomCfg.bedRoom0Floor.Value],
					array[(short)PocketRoomCfg.bedRoom0Wall.Value],
					array[3]
				}, new string[2]
				{
					PocketRoomCfg.bedRoom0FloorHex.Value,
					PocketRoomCfg.bedRoom0WallHex.Value
				}, unlockList[1], PocketRoomCfg.bedRoom0Furniture.Value, PocketRoomCfg.bedRoom0Cost.Value);
			}
			if (PocketRoomCfg.bedRoom1.Value)
			{
				RoomSetup((Material[])(object)new Material[3]
				{
					array[(short)PocketRoomCfg.bedRoom1Floor.Value],
					array[(short)PocketRoomCfg.bedRoom1Wall.Value],
					array[3]
				}, new string[2]
				{
					PocketRoomCfg.bedRoom1FloorHex.Value,
					PocketRoomCfg.bedRoom1WallHex.Value
				}, unlockList[2], PocketRoomCfg.bedRoom1Furniture.Value, PocketRoomCfg.bedRoom0Cost.Value);
			}
			if (PocketRoomCfg.cellar0.Value)
			{
				Room(unlockList[3], PocketRoomCfg.cellar0Cost.Value);
			}
			if (!alt)
			{
				PatchedContent.RegisterExtendedMod(extMod);
			}
		}

		private void RoomSetup(Material[] mat, string[] hex, UnlockableItem unlock, string furnitureList, int cost)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer component = ((Component)unlock.prefabObject.GetComponent<PocketRoom>().room.transform.Find("Model0")).GetComponent<MeshRenderer>();
			((Renderer)component).materials = mat;
			Material[] materials = ((Renderer)component).materials;
			Color color = default(Color);
			ColorUtility.TryParseHtmlString("#" + hex[0], ref color);
			Color color2 = default(Color);
			ColorUtility.TryParseHtmlString("#" + hex[1], ref color2);
			materials[0].color = color;
			materials[1].color = color2;
			string[] array = furnitureList.Split(';');
			foreach (string text in array)
			{
				List<string> list = new List<string>();
				string[] array2 = text.Split(',');
				foreach (string item in array2)
				{
					list.Add(item);
				}
				if (list.Count == 7)
				{
					GameObject val = Object.Instantiate<GameObject>(bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Prefab/FurnitureSpawn.prefab"));
					val.transform.parent = ((Component)component).transform.parent;
					val.transform.localPosition = new Vector3(float.Parse(list[1], CultureInfo.InvariantCulture), float.Parse(list[2], CultureInfo.InvariantCulture), float.Parse(list[3], CultureInfo.InvariantCulture));
					val.transform.localEulerAngles = new Vector3(float.Parse(list[4], CultureInfo.InvariantCulture), float.Parse(list[5], CultureInfo.InvariantCulture), float.Parse(list[6], CultureInfo.InvariantCulture));
					val.GetComponent<PocketSyncSpawn>().prefab = bundle.LoadAsset<GameObject>("Assets/MelaniePocketRoom/Furniture/" + list[0] + ".prefab");
				}
			}
			Room(unlock, cost);
		}

		private void Room(UnlockableItem unlock, int cost)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (!alt)
			{
				extMod.ExtendedUnlockableItems.Add(new ExtendedUnlockableItem
				{
					UnlockableItem = unlock,
					ItemCost = cost
				});
			}
			else
			{
				RoomAlt(unlock, cost);
			}
		}

		private void RoomAlt(UnlockableItem unlock, int cost)
		{
			DawnLib.RegisterNetworkPrefab(unlock.prefabObject);
			DawnLib.DefineUnlockable(NamespacedKey<DawnUnlockableItemInfo>.From("MelaniePocketRoom", ((Object)unlock.prefabObject).name), unlock, (Action<UnlockableInfoBuilder>)delegate(UnlockableInfoBuilder builder)
			{
				builder.SetCost(cost);
			});
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace MelanieMeliciousPocketRoom.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}