Decompiled source of LTOWDougDimmadomeHatMod v1.0.0

LTOWDougDimmadomeHatMod.dll

Decompiled 2 weeks ago
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
[BepInPlugin("local.SimonTendo.LTOWDougDimmadomeHatMod", "LTOWDougDimmadomeHatMod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(MenuToGameBridger), "Awake")]
	public class NewMenuToGameBridgerAwake
	{
		[HarmonyPostfix]
		public static void Postfix(MenuToGameBridger __instance)
		{
			if ((Object)(object)dougDimmaHatPrefhat == (Object)null || (Object)(object)dougDimmaHatPrefhatNormal == (Object)null)
			{
				Logger.LogError((object)"hat prefab somehow null, returning");
				return;
			}
			Material val = RetrieveHaterial(__instance);
			if ((Object)(object)val != (Object)null)
			{
				ApplyHaterialToPrefhat(dougDimmaHatPrefhat, val);
				ApplyHaterialToPrefhat(dougDimmaHatPrefhatNormal, val);
			}
			AddHatToPrefhatList(__instance);
		}
	}

	[HarmonyPatch(typeof(LocTableHelpers), "GetStringFromTable")]
	public class NewLocalization
	{
		[HarmonyPostfix]
		public static void InterceptName(string _locTableKey, ref string __result)
		{
			if ((Object)(object)dougDimmaHatPrefhat == (Object)null || (Object)(object)dougDimmaHatPrefhatNormal == (Object)null)
			{
				return;
			}
			HumanCustomizerAccessory component = dougDimmaHatPrefhat.GetComponent<HumanCustomizerAccessory>();
			HumanCustomizerAccessory component2 = dougDimmaHatPrefhatNormal.GetComponent<HumanCustomizerAccessory>();
			if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
			{
				Logger.LogError((object)"failed to find HumanCustomizerAccessory in localization");
				return;
			}
			string displayName = component.displayName;
			string displayName2 = component2.displayName;
			bool flag = false;
			if (_locTableKey == displayName)
			{
				__result = displayName;
				flag = true;
			}
			else if (_locTableKey == displayName2)
			{
				__result = displayName2;
				flag = true;
			}
			if (flag)
			{
				Logger.LogDebug((object)("Intercepted GetStringFromTable(" + _locTableKey + "): __result = " + __result));
			}
		}
	}

	internal static ManualLogSource Logger;

	public static GameObject dougDimmaHatPrefhat;

	public static GameObject dougDimmaHatPrefhatNormal;

	private void Awake()
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		Logger = ((BaseUnityPlugin)this).Logger;
		Logger.LogInfo((object)"Plugin LTOWDougDimmadomeHatMod is loaded!");
		AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dougdimmadundle"));
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogError((object)"Failed to load AssetBundle");
			return;
		}
		dougDimmaHatPrefhat = val.LoadAsset<GameObject>("Assets/LTOWDougDimmadomeHatMod/Prefabs/DougDimmadomeHat Infinite Prefab.prefab");
		dougDimmaHatPrefhatNormal = val.LoadAsset<GameObject>("Assets/LTOWDougDimmadomeHatMod/Prefabs/DougDimmadomeHat Normal Prefab.prefab");
		if ((Object)(object)dougDimmaHatPrefhat == (Object)null || (Object)(object)dougDimmaHatPrefhatNormal == (Object)null)
		{
			Logger.LogError((object)"Failed to load either Prefab");
			return;
		}
		Logger.LogDebug((object)"Successfully loaded AssetBundle and Prefabs");
		new Harmony("LTOWDougDimmadomeHatMod").PatchAll();
	}

	private static void AddHatToPrefhatList(MenuToGameBridger __instance)
	{
		if ((Object)(object)__instance == (Object)null || __instance.hat_Prefabs == null || (Object)(object)dougDimmaHatPrefhat == (Object)null || (Object)(object)dougDimmaHatPrefhatNormal == (Object)null)
		{
			Logger.LogError((object)"could not find MenuToGameBridger.hat_Prefabs or dougDimmadomeHat");
			return;
		}
		__instance.hat_Prefabs.Add(dougDimmaHatPrefhatNormal);
		Logger.LogDebug((object)$"successfully applied {dougDimmaHatPrefhatNormal} to MenuToGameBridger.Single.hat_Prefabs at index {__instance.hat_Prefabs.Count - 1}");
		__instance.hat_Prefabs.Add(dougDimmaHatPrefhat);
		Logger.LogDebug((object)$"successfully applied {dougDimmaHatPrefhat} to MenuToGameBridger.Single.hat_Prefabs at index {__instance.hat_Prefabs.Count - 1}");
	}

	private static Material RetrieveHaterial(MenuToGameBridger __instance)
	{
		if ((Object)(object)__instance == (Object)null || __instance.hat_Prefabs == null || __instance.hat_Prefabs.Count < 2 || (Object)(object)__instance.hat_Prefabs[1] == (Object)null || (Object)(object)__instance.hat_Prefabs[1].gameObject == (Object)null || __instance.hat_Prefabs[1].gameObject.transform.childCount <= 0)
		{
			Logger.LogError((object)"cannot find template hat when trying to get hat material! error 1");
			return null;
		}
		Transform child = __instance.hat_Prefabs[1].gameObject.transform.GetChild(0);
		if ((Object)(object)child == (Object)null)
		{
			Logger.LogError((object)"cannot find template hat when trying to get hat material! error 2");
			return null;
		}
		MeshRenderer component = ((Component)child).GetComponent<MeshRenderer>();
		if ((Object)(object)component == (Object)null || (Object)(object)((Renderer)component).material == (Object)null)
		{
			Logger.LogError((object)"cannot find template hat when trying to get hat material! error 3");
			return null;
		}
		Material material = ((Renderer)((Component)__instance.hat_Prefabs[1].gameObject.transform.GetChild(0)).GetComponent<MeshRenderer>()).material;
		Logger.LogDebug((object)$"retrieved haterial: {material}");
		return material;
	}

	private static void ApplyHaterialToPrefhat(GameObject hatToApply, Material accessoriesHaterial)
	{
		if ((Object)(object)hatToApply == (Object)null || (Object)(object)accessoriesHaterial == (Object)null)
		{
			Logger.LogError((object)"null dougdimmadome hat prefab or haterial");
			return;
		}
		MeshRenderer componentInChildren = hatToApply.GetComponentInChildren<MeshRenderer>();
		if ((Object)(object)componentInChildren == (Object)null)
		{
			Logger.LogError((object)"null mRenderer");
			return;
		}
		Material[] array = (Material[])(object)new Material[2];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = accessoriesHaterial;
		}
		((Renderer)componentInChildren).materials = array;
		Logger.LogDebug((object)"applied haterials successfully");
	}
}
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Never)]
[GeneratedCode("Unity.MonoScriptGenerator.MonoScriptInfoGenerator", null)]
internal class UnitySourceGeneratedAssemblyMonoScriptTypes_v1
{
	private struct MonoScriptData
	{
		public byte[] FilePathsData;

		public byte[] TypesData;

		public int TotalTypes;

		public int TotalFiles;

		public bool IsEditorOnly;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private static MonoScriptData Get()
	{
		MonoScriptData result = default(MonoScriptData);
		result.FilePathsData = new byte[57]
		{
			0, 0, 0, 3, 0, 0, 0, 49, 92, 65,
			115, 115, 101, 116, 115, 92, 76, 84, 79, 87,
			68, 111, 117, 103, 68, 105, 109, 109, 97, 100,
			111, 109, 101, 72, 97, 116, 77, 111, 100, 92,
			83, 99, 114, 105, 112, 116, 115, 92, 80, 108,
			117, 103, 105, 110, 46, 99, 115
		};
		result.TypesData = new byte[76]
		{
			0, 0, 0, 0, 7, 124, 80, 108, 117, 103,
			105, 110, 0, 0, 0, 0, 32, 80, 108, 117,
			103, 105, 110, 124, 78, 101, 119, 77, 101, 110,
			117, 84, 111, 71, 97, 109, 101, 66, 114, 105,
			100, 103, 101, 114, 65, 119, 97, 107, 101, 0,
			0, 0, 0, 22, 80, 108, 117, 103, 105, 110,
			124, 78, 101, 119, 76, 111, 99, 97, 108, 105,
			122, 97, 116, 105, 111, 110
		};
		result.TotalFiles = 1;
		result.TotalTypes = 3;
		result.IsEditorOnly = false;
		return result;
	}
}