Decompiled source of SelectableInteriors v1.0.0

NoteBoxz.SelectableInteriors.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using LLLselect.Patches;
using LethalLevelLoader;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("NoteBoxz.SelectableInteriors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-dev")]
[assembly: AssemblyProduct("LLLselect")]
[assembly: AssemblyTitle("NoteBoxz.SelectableInteriors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
}
namespace LLLselect
{
	[BepInPlugin("NoteBoxz.SelectableInteriors", "LLLselect", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LLLselect : BaseUnityPlugin
	{
		public const string PLUGIN_VERSION = "1.0.0";

		public static TerminalKeyword InteriorViewKeyword = null;

		public static TerminalNode InteriorViewNode = null;

		public static List<TerminalKeyword> InteriorChangeKeywords = null;

		public static List<TerminalNode> InteriorChangeNodes = null;

		public static int LVidForceing = -1;

		public static List<int> ValidIDs = new List<int>();

		public static LLLselect Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		public static bool IsDependencyLoaded(string pluginGUID)
		{
			return Chainloader.PluginInfos.ContainsKey(pluginGUID);
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			RegisterNodes();
			Logger.LogInfo((object)"NoteBoxz.SelectableInteriors v1.0.0 has loaded!");
		}

		public void RegisterNodes()
		{
			InteriorViewNode = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)InteriorViewNode).name = "Interior View";
			InteriorViewNode.displayText = "cur level flows:";
			InteriorViewNode.clearPreviousText = true;
			InteriorViewNode.maxCharactersToType = 35;
			InteriorViewNode.buyItemIndex = -1;
			InteriorViewNode.buyVehicleIndex = -1;
			InteriorViewNode.isConfirmationNode = false;
			InteriorViewNode.buyRerouteToMoon = -1;
			InteriorViewNode.displayPlanetInfo = -1;
			InteriorViewNode.shipUnlockableID = -1;
			InteriorViewNode.buyUnlockable = true;
			InteriorViewNode.returnFromStorage = false;
			InteriorViewNode.itemCost = 0;
			InteriorViewNode.creatureFileID = -1;
			InteriorViewNode.creatureName = "";
			InteriorViewNode.storyLogFileID = -1;
			InteriorViewNode.overrideOptions = false;
			InteriorViewNode.acceptAnything = false;
			InteriorViewNode.loadImageSlowly = false;
			InteriorViewNode.persistentImage = false;
			InteriorViewKeyword = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)InteriorViewKeyword).name = "Interior ViewKW";
			InteriorViewKeyword.word = "EditInside";
			InteriorViewKeyword.specialKeywordResult = InteriorViewNode;
		}

		public static void AddNoneChangeNode()
		{
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)val).name = "forceNone";
			val.displayText = "No Interior will be forced!";
			val.clearPreviousText = true;
			val.maxCharactersToType = 35;
			val.buyItemIndex = -1;
			val.buyVehicleIndex = -1;
			val.isConfirmationNode = false;
			val.buyRerouteToMoon = -1;
			val.displayPlanetInfo = -1;
			val.shipUnlockableID = -1;
			val.buyUnlockable = true;
			val.returnFromStorage = false;
			val.itemCost = 0;
			val.creatureFileID = -1;
			val.creatureName = "";
			val.storyLogFileID = -1;
			val.overrideOptions = false;
			val.acceptAnything = false;
			val.loadImageSlowly = false;
			val.persistentImage = false;
			val.terminalEvent = "SetLV -1";
			TerminalKeyword val2 = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)val2).name = "forcenonekw";
			val2.word = "SetInside none";
			val2.specialKeywordResult = val;
			int num = TerminalPatch.nList.allKeywords.Length;
			Array.Resize(ref TerminalPatch.nList.allKeywords, num + 1);
			TerminalPatch.nList.allKeywords[num] = val2;
			Logger.LogInfo((object)("Added " + val2.word + " (" + ((Object)TerminalPatch.nList.allKeywords[num]).name + ") keyword to Terminal.allKeywords"));
		}

		public static void AddChangeNode(int ID, string name)
		{
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)val).name = $"force{ID}";
			val.displayText = $"Forcing level {name} ({ID}) to be loaded!";
			val.clearPreviousText = true;
			val.maxCharactersToType = 35;
			val.buyItemIndex = -1;
			val.buyVehicleIndex = -1;
			val.isConfirmationNode = false;
			val.buyRerouteToMoon = -1;
			val.displayPlanetInfo = -1;
			val.shipUnlockableID = -1;
			val.buyUnlockable = true;
			val.returnFromStorage = false;
			val.itemCost = 0;
			val.creatureFileID = -1;
			val.creatureName = "";
			val.storyLogFileID = -1;
			val.overrideOptions = false;
			val.acceptAnything = false;
			val.loadImageSlowly = false;
			val.persistentImage = false;
			val.terminalEvent = $"SetLV {ID}";
			TerminalKeyword val2 = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)val2).name = $"force{ID}kw";
			val2.word = $"SetInside {ID}";
			val2.specialKeywordResult = val;
			int num = TerminalPatch.nList.allKeywords.Length;
			Array.Resize(ref TerminalPatch.nList.allKeywords, num + 1);
			TerminalPatch.nList.allKeywords[num] = val2;
			Logger.LogInfo((object)("Added " + val2.word + " (" + ((Object)TerminalPatch.nList.allKeywords[num]).name + ") keyword to Terminal.allKeywords"));
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.SelectableInteriors");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.SelectableInteriors";

		public const string PLUGIN_NAME = "LLLselect";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace LLLselect.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		public static Dictionary<SelectableLevel, IntWithRarity[]> InitalRaries = new Dictionary<SelectableLevel, IntWithRarity[]>();

		public static bool Newfloor;

		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPrefix]
		public static void GenerateNewFloorPreFix()
		{
			Newfloor = true;
		}

		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPostfix]
		public static void GenerateNewFloorPostFix()
		{
			Newfloor = false;
		}

		[HarmonyPatch("GetRandomWeightedIndex")]
		[HarmonyPrefix]
		public static bool Prefix(int[] weights, Random randomSeed, ref int __result)
		{
			LLLselect.Logger.LogInfo((object)$"RandomWeightIndex called with {randomSeed} seed and {weights.Length} weights");
			if (Newfloor)
			{
				if (LLLselect.ValidIDs.Contains(LLLselect.LVidForceing))
				{
					__result = LLLselect.LVidForceing;
					LLLselect.Logger.LogMessage((object)$"Forced ID: {LLLselect.LVidForceing}");
					if (RoundManager.Instance.currentLevel.dungeonFlowTypes.Length - 1 < __result)
					{
						LLLselect.Logger.LogWarning((object)$"Current Level doesn't have {__result} as a flow type! Injecting flow...");
						if (!InitalRaries.ContainsKey(RoundManager.Instance.currentLevel))
						{
							InitalRaries.Add(RoundManager.Instance.currentLevel, RoundManager.Instance.currentLevel.dungeonFlowTypes);
						}
						Array.Resize(ref RoundManager.Instance.currentLevel.dungeonFlowTypes, __result + 1);
					}
					if (RoundManager.Instance.currentLevel.dungeonFlowTypes[__result] != StartOfRoundPatch.FlowTypes[__result])
					{
						RoundManager.Instance.currentLevel.dungeonFlowTypes[__result] = StartOfRoundPatch.FlowTypes[__result];
						LLLselect.Logger.LogMessage((object)$"Injected flow at index {__result}");
					}
					return false;
				}
				if (InitalRaries.ContainsKey(RoundManager.Instance.currentLevel))
				{
					int num = RoundManager.Instance.currentLevel.dungeonFlowTypes.Length;
					int num2 = InitalRaries[RoundManager.Instance.currentLevel].Length;
					LLLselect.Logger.LogMessage((object)("Resetting " + RoundManager.Instance.currentLevel.PlanetName + "'s flows back to default" + $" ({num} -> {num2})"));
					RoundManager.Instance.currentLevel.dungeonFlowTypes = InitalRaries[RoundManager.Instance.currentLevel];
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		public static List<IntWithRarity> FlowTypes = new List<IntWithRarity>();

		public static void SetFlows(StartOfRound __instance)
		{
			List<string> list = new List<string>();
			list.AddRange(LLL_GETMOONFLOWS());
			PopulateFlowTypes();
			LLLselect.AddNoneChangeNode();
			string text = string.Join(", ", list);
			LLLselect.InteriorViewNode.displayText = "Possible Flows: \n " + text + " \n \n Use the command 'SetInside ID' to force an interior to be loaded \n";
		}

		public static void PopulateFlowTypes()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			FlowTypes = new List<IntWithRarity>();
			for (int i = 0; i < LLLselect.ValidIDs.Count; i++)
			{
				FlowTypes.Add(new IntWithRarity());
			}
			foreach (ExtendedDungeonFlow extendedDungeonFlow in PatchedContent.ExtendedDungeonFlows)
			{
				if (LLLselect.ValidIDs.Contains(extendedDungeonFlow.DungeonID))
				{
					LLLselect.Logger.LogWarning((object)$"Adding {extendedDungeonFlow.DungeonName} ({extendedDungeonFlow.DungeonID}) to the flowTypes list");
					IntWithRarity val = new IntWithRarity();
					val.id = extendedDungeonFlow.DungeonID;
					val.overrideLevelAmbience = null;
					FlowTypes[extendedDungeonFlow.DungeonID] = val;
				}
			}
		}

		public static List<string> LLL_GETMOONFLOWS()
		{
			List<string> list = new List<string>();
			foreach (ExtendedDungeonFlow extendedDungeonFlow in PatchedContent.ExtendedDungeonFlows)
			{
				list.Add($"{extendedDungeonFlow.DungeonName} ({extendedDungeonFlow.DungeonID})");
				if (!LLLselect.ValidIDs.Contains(extendedDungeonFlow.DungeonID))
				{
					LLLselect.ValidIDs.Add(extendedDungeonFlow.DungeonID);
				}
				LLLselect.AddChangeNode(extendedDungeonFlow.DungeonID, ((Object)RoundManager.Instance.dungeonFlowTypes[extendedDungeonFlow.DungeonID].dungeonFlow).name);
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		public static TerminalNodesList nList;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start(Terminal __instance)
		{
			if (__instance.terminalNodes.allKeywords != null)
			{
				nList = __instance.terminalNodes;
				int num = __instance.terminalNodes.allKeywords.Length;
				Array.Resize(ref __instance.terminalNodes.allKeywords, num + 1);
				__instance.terminalNodes.allKeywords[num] = LLLselect.InteriorViewKeyword;
				LLLselect.Logger.LogInfo((object)"Added LLLselect keyword to Terminal.allKeywords");
				StartOfRoundPatch.SetFlows(StartOfRound.Instance);
			}
			else
			{
				LLLselect.Logger.LogWarning((object)"Unable to add LLLselect keyword: allKeywords is null");
			}
		}

		[HarmonyPatch("RunTerminalEvents")]
		[HarmonyPostfix]
		public static void RunTerminalEventsPatch(TerminalNode node)
		{
			try
			{
				if (node.terminalEvent.StartsWith("SetLV"))
				{
					string[] array = node.terminalEvent.Split(' ');
					int num = (LLLselect.LVidForceing = int.Parse(array[1]));
					LLLselect.Logger.LogInfo((object)$"Changed level to {num}");
				}
			}
			catch
			{
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}