Decompiled source of MoreGatesExtended v1.0.2

MoreGatesExtended.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
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("MoreGatesExtended")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreGatesExtended")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b890b5fc-3fb7-4e37-8819-3fd25c94ab62")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace MoreGatesExtended;

[BepInPlugin("shudnal.MoreGatesExtended", "More Gates Extended", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInIncompatibility("hayze.Moregates")]
public class MoreGatesExtended : BaseUnityPlugin
{
	public const string pluginID = "shudnal.MoreGatesExtended";

	public const string pluginName = "More Gates Extended";

	public const string pluginVersion = "1.0.2";

	private readonly Harmony harmony = new Harmony("shudnal.MoreGatesExtended");

	internal static MoreGatesExtended instance;

	internal static ConfigEntry<bool> loggingEnabled;

	internal static ConfigEntry<string> buildTool;

	internal static ConfigEntry<string> buildCategory;

	internal static ConfigEntry<string> disabledPieces;

	internal static ConfigEntry<string> customRecipes;

	internal static readonly Dictionary<string, string> customRecipesList = new Dictionary<string, string>();

	internal static HashSet<string> disablePiecesList = new HashSet<string>();

	internal static AssetBundle bundleFromResources;

	private void Awake()
	{
		harmony.PatchAll();
		instance = this;
		ConfigInit();
		Game.isModded = true;
		LoadTranslation("jotunn.json", "English");
		LoadTranslation("jotunn.json", "Russian");
		LoadTranslation("moregates.json", "English");
		LoadTranslation("moregates.json", "Russian");
		FillCustomRecipesAndDisabledPieces();
		RegisterPrefabs();
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
		instance = null;
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	internal static void LogInfo(object data)
	{
		if (loggingEnabled.Value)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo(data);
		}
	}

	internal void ConfigInit()
	{
		loggingEnabled = config("General", "Logging enabled", defaultValue: false, "Enable logging. [Not Synced with Server]", synchronizedSetting: false);
		buildTool = config("General", "Tool", "Hammer", "Identifier of tool to place new objects. This is what is set in PieceTable property of PieceConfig. Restart to see effect.");
		buildCategory = config("General", "Category", "moregates", "Identifier of category to place new objects. This is what is set in Category property of PieceConfig.\nIf you have created your own category then don't forget to add related entry starting with \"jotunn_cat_\" to localization file.\nRestart to see effect.");
		disabledPieces = config("Pieces", "Disabled pieces", "h_logshort26,h_logshort45,corewood_stack", "Prefab names comma separated case insensitive. Piece from that list will not be loaded. Restart to see effect.");
		customRecipes = config("Pieces", "Custom recipes", "h_drawbridge02:Wood:55:Bronze:8:Chain:4", "Custom pieces recipies, comma separated, starts with prefab name then requirement:amount. \nDefault value is given for example. Restart to see effect.");
	}

	private ConfigEntry<T> config<T>(string group, string name, T defaultValue, string description, bool synchronizedSetting = true)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = synchronizedSetting
		} }));
	}

	internal static void LoadTranslation(string file, string lang)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(file) && str.IndexOf(lang) >= 0);
		Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(name);
		LocalizationManager.Instance.GetLocalization().AddJsonFile(lang, new StreamReader(manifestResourceStream, Encoding.UTF8).ReadToEnd());
	}

	internal static void FillCustomRecipesAndDisabledPieces()
	{
		string[] array = customRecipes.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
		foreach (string text in array)
		{
			int num = text.IndexOf(":");
			if (num == 0)
			{
				customRecipesList.Add(text, "");
			}
			else
			{
				customRecipesList.Add(text.Substring(0, num), text.Substring(num + 1));
			}
		}
		disablePiecesList = new HashSet<string>(disabledPieces.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries));
	}

	private static RequirementConfig[] ParseRequirements(string itemRecipe)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		List<RequirementConfig> list = new List<RequirementConfig>();
		if (!string.IsNullOrEmpty(itemRecipe))
		{
			string[] array = itemRecipe.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length && i != array.Length; i += 2)
			{
				int num = int.Parse(array[i + 1]);
				if (num > 0)
				{
					list.Add(new RequirementConfig(array[i].Trim(), num, 0, true));
				}
			}
		}
		return list.ToArray();
	}

	private static void LoadAsset(string name, RequirementConfig[] requirements)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		if (!disablePiecesList.Contains(name))
		{
			if (customRecipesList.ContainsKey(name))
			{
				requirements = ParseRequirements(customRecipesList[name]);
			}
			PieceConfig val = new PieceConfig
			{
				Name = "$piece_mg_" + name,
				PieceTable = (Utility.IsNullOrWhiteSpace(buildTool.Value) ? "Hammer" : buildTool.Value),
				Category = (Utility.IsNullOrWhiteSpace(buildCategory.Value) ? "moregates" : buildCategory.Value),
				Requirements = requirements,
				Description = "$piece_mg_" + name + "_desc",
				CraftingStation = "Workbench"
			};
			PieceManager.Instance.AddPiece(new CustomPiece(bundleFromResources, name, true, val));
		}
	}

	public static void RegisterPrefabs()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected O, but got Unknown
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Expected O, but got Unknown
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Expected O, but got Unknown
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Expected O, but got Unknown
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Expected O, but got Unknown
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Expected O, but got Unknown
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Expected O, but got Unknown
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Expected O, but got Unknown
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Expected O, but got Unknown
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Expected O, but got Unknown
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Expected O, but got Unknown
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Expected O, but got Unknown
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Expected O, but got Unknown
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Expected O, but got Unknown
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Expected O, but got Unknown
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Expected O, but got Unknown
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Expected O, but got Unknown
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Expected O, but got Unknown
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e3: Expected O, but got Unknown
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Expected O, but got Unknown
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Expected O, but got Unknown
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Expected O, but got Unknown
		//IL_0465: Unknown result type (might be due to invalid IL or missing references)
		//IL_046b: Expected O, but got Unknown
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_048d: Expected O, but got Unknown
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04af: Expected O, but got Unknown
		//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Expected O, but got Unknown
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e1: Expected O, but got Unknown
		//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0503: Expected O, but got Unknown
		//IL_050d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0513: Expected O, but got Unknown
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0535: Expected O, but got Unknown
		//IL_053f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Expected O, but got Unknown
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0567: Expected O, but got Unknown
		//IL_0571: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Expected O, but got Unknown
		//IL_0593: Unknown result type (might be due to invalid IL or missing references)
		//IL_0599: Expected O, but got Unknown
		//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a9: Expected O, but got Unknown
		//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ca: Expected O, but got Unknown
		//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Expected O, but got Unknown
		//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fb: Expected O, but got Unknown
		//IL_0616: Unknown result type (might be due to invalid IL or missing references)
		//IL_061c: Expected O, but got Unknown
		//IL_0637: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Expected O, but got Unknown
		//IL_0658: Unknown result type (might be due to invalid IL or missing references)
		//IL_065e: Expected O, but got Unknown
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_067f: Expected O, but got Unknown
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a1: Expected O, but got Unknown
		bundleFromResources = AssetUtils.LoadAssetBundleFromResources("moregates");
		LoadAsset("h_drawbridge01", (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("Wood", 60, 0, true),
			new RequirementConfig("Iron", 10, 0, true),
			new RequirementConfig("Chain", 4, 0, true)
		});
		LoadAsset("h_drawbridge02", (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("Wood", 55, 0, true),
			new RequirementConfig("Bronze", 8, 0, true),
			new RequirementConfig("Chain", 4, 0, true)
		});
		LoadAsset("lift_gate", (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("Iron", 20, 0, true),
			new RequirementConfig("Stone", 8, 0, true),
			new RequirementConfig("Chain", 4, 0, true)
		});
		LoadAsset("lift_gate2", (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("Wood", 75, 0, true),
			new RequirementConfig("Bronze", 8, 0, true),
			new RequirementConfig("Chain", 4, 0, true)
		});
		LoadAsset("Hayze_gate_01", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 18, 0, true)
		});
		LoadAsset("Hayze_gate_02", (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("Wood", 20, 0, true),
			new RequirementConfig("RoundLog", 20, 0, true),
			new RequirementConfig("Bronze", 20, 0, true)
		});
		LoadAsset("Hayze_gate_03", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 15, 0, true)
		});
		LoadAsset("Hayze_gate_04", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 18, 0, true)
		});
		LoadAsset("Hayze_gate_05", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 25, 0, true)
		});
		LoadAsset("Hayze_gate_06", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 18, 0, true),
			new RequirementConfig("IronNails", 3, 0, true)
		});
		LoadAsset("h_door_01", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 5, 0, true)
		});
		LoadAsset("h_door_02", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 6, 0, true)
		});
		LoadAsset("h_door_03", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 6, 0, true)
		});
		LoadAsset("h_shutter_01", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 7, 0, true)
		});
		LoadAsset("h_trapdoor", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 5, 0, true)
		});
		LoadAsset("h_trapdoorbig", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 10, 0, true)
		});
		LoadAsset("h_trapdoor2", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 5, 0, true),
			new RequirementConfig("Iron", 1, 0, true)
		});
		LoadAsset("h_trapdoorbig2", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 10, 0, true),
			new RequirementConfig("Iron", 2, 0, true)
		});
		LoadAsset("Hayze_halfgate_01", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 6, 0, true)
		});
		LoadAsset("Hayze_halfgate_02", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 8, 0, true)
		});
		LoadAsset("h_window_01", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 10, 0, true)
		});
		LoadAsset("h_window_02", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 12, 0, true)
		});
		LoadAsset("h_window_03", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 14, 0, true)
		});
		LoadAsset("h_window_04", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 11, 0, true)
		});
		LoadAsset("h_window_05", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 14, 0, true)
		});
		LoadAsset("h_window_06", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 18, 0, true)
		});
		LoadAsset("h_window_07", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 21, 0, true)
		});
		LoadAsset("h_window_08", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 21, 0, true)
		});
		LoadAsset("h_window_09", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Wood", 21, 0, true)
		});
		LoadAsset("h_window_10", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 21, 0, true),
			new RequirementConfig("Crystal", 1, 0, true)
		});
		LoadAsset("h_window_11", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 21, 0, true),
			new RequirementConfig("Crystal", 1, 0, true)
		});
		LoadAsset("h_window_12", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 21, 0, true),
			new RequirementConfig("Crystal", 1, 0, true)
		});
		LoadAsset("h_window_13", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 21, 0, true),
			new RequirementConfig("Crystal", 1, 0, true)
		});
		LoadAsset("h_window_14", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 21, 0, true),
			new RequirementConfig("Crystal", 1, 0, true)
		});
		LoadAsset("h_chain", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("Chain", 1, 0, true)
		});
		LoadAsset("hayzestake_01", (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig("Wood", 4, 0, true),
			new RequirementConfig("RoundLog", 7, 0, true)
		});
		LoadAsset("h_loglong26", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("RoundLog", 2, 0, true)
		});
		LoadAsset("h_loglong45", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("RoundLog", 2, 0, true)
		});
		LoadAsset("h_logshort26", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("RoundLog", 1, 0, true)
		});
		LoadAsset("h_logshort45", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("RoundLog", 1, 0, true)
		});
		LoadAsset("corewood_stack", (RequirementConfig[])(object)new RequirementConfig[1]
		{
			new RequirementConfig("RoundLog", 50, 0, true)
		});
	}
}