Decompiled source of SceneSaveEverywhere v0.1.0

NGA.SaveItAll.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("NGA.SaveItAll")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.SaveItAll", "SaveItAll", "0.1.0")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	public class SaveItAll : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRSceneSettings))]
		[HarmonyPatch("Awake")]
		private class FVRSceneSettingsAwakeHook
		{
			private static void Prefix(FVRSceneSettings __instance)
			{
				//IL_01af: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0226: Unknown result type (might be due to invalid IL or missing references)
				//IL_022b: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02be: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
				bool isSceneSavingEnabled = false;
				List<string> list = new List<string>
				{
					"Grillhouse_2Story", "IndoorRange", "GP_Hangar", "SniperRange", "ArizonaTargets", "WarehouseRange_Rebuilt", "Friendly45_New", "ArizonaTargets_Night", "BreachAndClear_TestScene1", "ProvingGround",
					"ObstacleCourseScene1", "NewSnowGlobe", "Wurstwurld1", "MF2_MainScene", "Boomskee", "Testing3_LaserSword", "MeatGrinder", "OmnisequencerTesting3", "WinterWasteland", "Cappocolosseum",
					"SamplerPlatter"
				};
				List<string> list2 = new List<string> { "Institution", "TakeAndHoldClassic", "TakeAndHold_WinterWasteland" };
				List<string> list3 = config_include_ids.Value.Split(new char[1] { ',' }).ToList();
				List<string> list4 = config_exclude_ids.Value.Split(new char[1] { ',' }).ToList();
				List<string> list5 = new List<string>();
				if (config_enable_vanilla.Value)
				{
					list5.AddRange(list);
				}
				if (config_enable_tnh.Value)
				{
					list5.AddRange(list2);
				}
				Scene activeScene = SceneManager.GetActiveScene();
				if (list5.Contains(((Scene)(ref activeScene)).name))
				{
					isSceneSavingEnabled = true;
				}
				if (config_enable_modded.Value)
				{
					activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).buildIndex == -1)
					{
						Logger.LogMessage((object)"Detected modded map, setting to true.");
						isSceneSavingEnabled = true;
					}
				}
				activeScene = SceneManager.GetActiveScene();
				if (list3.Contains(((Scene)(ref activeScene)).name))
				{
					isSceneSavingEnabled = true;
				}
				activeScene = SceneManager.GetActiveScene();
				if (list4.Contains(((Scene)(ref activeScene)).name))
				{
					isSceneSavingEnabled = false;
				}
				Logger.LogMessage((object)("Scene manager num scenes " + SceneManager.sceneCount));
				if (!__instance.IsSceneSavingEnabled)
				{
					Logger.LogMessage((object)"Modifying scene save, it was originally set to False!");
					__instance.IsSceneSavingEnabled = isSceneSavingEnabled;
				}
				ManualLogSource logger = Logger;
				string[] obj = new string[6]
				{
					"Scene saving is set to ",
					__instance.IsSceneSavingEnabled.ToString(),
					" in ",
					null,
					null,
					null
				};
				activeScene = SceneManager.GetActiveScene();
				obj[3] = ((Scene)(ref activeScene)).name;
				obj[4] = " w build index: ";
				activeScene = SceneManager.GetActiveScene();
				obj[5] = ((Scene)(ref activeScene)).buildIndex.ToString();
				logger.LogMessage((object)string.Concat(obj));
				PrintLists(list, list2, list3, list4, list5);
			}

			private static void PrintLists(List<string> vanillaScenes, List<string> tnhScenes, List<string> customIncludedList, List<string> customExcludedList, List<string> allowedList)
			{
				Logger.LogMessage((object)"===== Printing Lists =====");
				Logger.LogMessage((object)"Vanilla Scenes:");
				foreach (string vanillaScene in vanillaScenes)
				{
					Logger.LogMessage((object)vanillaScene);
				}
				Logger.LogMessage((object)"TNH Scenes:");
				foreach (string tnhScene in tnhScenes)
				{
					Logger.LogMessage((object)tnhScene);
				}
				Logger.LogMessage((object)"Allowed List:");
				foreach (string allowed in allowedList)
				{
					Logger.LogMessage((object)allowed);
				}
				Logger.LogMessage((object)"Custom Included List:");
				foreach (string customIncluded in customIncludedList)
				{
					Logger.LogMessage((object)customIncluded);
				}
				Logger.LogMessage((object)"Custom Excluded List:");
				foreach (string customExcluded in customExcludedList)
				{
					Logger.LogMessage((object)customExcluded);
				}
				Logger.LogMessage((object)"==========================");
			}

			private static void Postfix(FVRSceneSettings __instance)
			{
				Logger.LogMessage((object)("Confirming scene save set to: " + __instance.IsSceneSavingEnabled));
			}
		}

		private static ConfigEntry<bool> config_enable_vanilla;

		private static ConfigEntry<bool> config_enable_tnh;

		private static ConfigEntry<bool> config_enable_modded;

		private static ConfigEntry<string> config_exclude_ids;

		private static ConfigEntry<string> config_include_ids;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("NGA.SaveItAll");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.SaveItAll 0.0.1");
		}

		private void SetUpConfigFields()
		{
			config_enable_vanilla = ((BaseUnityPlugin)this).Config.Bind<bool>("Scenes Saving Allowed", "All Vanilla Scenes", true, "Enables scene saving in all Main Menu accessible scenes");
			config_enable_modded = ((BaseUnityPlugin)this).Config.Bind<bool>("Scenes Saving Allowed", "Any Modded Map", true, "Enables scene saving in any Atlas map installed from Thundersore. !!Wurstmod maps DONT work!!");
			config_enable_tnh = ((BaseUnityPlugin)this).Config.Bind<bool>("Scenes Saving Allowed", "Vanilla TnH Maps", false, "Enables scene saving in all vanilla TnH Menu accessible maps");
			config_include_ids = ((BaseUnityPlugin)this).Config.Bind<string>("Custom Include/Exclude", "Scenes IDs to INCLUDE", "sampleID5,sampleID7", "Comma, separated list of scene IDs to INCLUDE from scene saving. Enforced after all conditions above.");
			config_exclude_ids = ((BaseUnityPlugin)this).Config.Bind<string>("Custom Include/Exclude", "Scenes IDs to EXCLUDE", "sampleID1,sampleID2", "Comma, separated list of scene IDs to EXCLUDE from scene saving. Enforced after all conditions above.");
		}
	}
}