Decompiled source of Unit Appearance Reset v0.1.1

UnitAppearanceReset.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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 BepInEx;
using DM;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.UnitEditor;
using SLMA;
using UnityEngine;
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: AssemblyTitle("UnitAppearanceReset")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("UnitAppearanceReset")]
[assembly: AssemblyProduct("UnitAppearanceReset")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UnitAppearanceReset;

public static class UManager
{
	public class Utility : MonoBehaviour
	{
		public static class PrimitiveHelper
		{
			private static Dictionary<PrimitiveType, Mesh> primitiveMeshes;

			public static GameObject CreatePrimitive(PrimitiveType type, bool withCollider)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				if (withCollider)
				{
					return GameObject.CreatePrimitive(type);
				}
				GameObject val = new GameObject(((object)(PrimitiveType)(ref type)).ToString());
				val.AddComponent<MeshFilter>().sharedMesh = GetPrimitiveMesh(type);
				val.AddComponent<MeshRenderer>();
				return val;
			}

			public static Mesh GetPrimitiveMesh(PrimitiveType type)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!primitiveMeshes.ContainsKey(type))
				{
					CreatePrimitiveMesh(type);
				}
				return primitiveMeshes[type];
			}

			private static Mesh CreatePrimitiveMesh(PrimitiveType type)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				GameObject obj = GameObject.CreatePrimitive(type);
				Mesh sharedMesh = obj.GetComponent<MeshFilter>().sharedMesh;
				Object.Destroy((Object)(object)obj);
				primitiveMeshes[type] = sharedMesh;
				return sharedMesh;
			}

			static PrimitiveHelper()
			{
				primitiveMeshes = new Dictionary<PrimitiveType, Mesh>();
			}
		}

		public static GameObject LoadBundleGameObject(string name)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (GameObject)bundle.LoadAsset(name);
		}

		public static Material LoadBundleMaterial(string name)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (Material)bundle.LoadAsset(name);
		}

		public static Sprite LoadBundleTextureToSprite(string name)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = (Texture2D)bundle.LoadAsset(name);
			((Texture)val).filterMode = (FilterMode)0;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}

	private static string comment;

	public static AssetBundle bundle;

	public static UnitBlueprint[] unitBasesBlueprints;

	public static void SetBlueprint(UnitBlueprint unit, LandfallContentDatabase db)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_VIKING_JARL"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Jarl");
			unit.m_props = (GameObject[])(object)new GameObject[1] { Utility.LoadBundleGameObject("NewJarlSuit") };
		}
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_VIKING_BERSERKER"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Berserker");
			unit.LeftWeapon = UPool.MyPool.GetObject("SturdierBerserkerAxe");
			unit.RightWeapon = UPool.MyPool.GetObject("SturdierBerserkerAxe");
			unit.m_props = (GameObject[])(object)new GameObject[1] { Utility.LoadBundleGameObject("NewBerserkerSuit") };
		}
		if (unit.Entity.Name == "Reskinned Jarl")
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Jarl");
			s.SetField<UnitBlueprint>(unit, "VocalRef", (object)"Viking Attack Vocals/Jarl");
			s.SetField<UnitBlueprint>(unit, "DeathRef", (object)"Viking Death Vocals/Jarl");
		}
		if (unit.Entity.Name == "Reskinned Berserker")
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Berserker");
			s.SetField<UnitBlueprint>(unit, "VocalRef", (object)"Viking Attack Vocals/Berserker");
			s.SetField<UnitBlueprint>(unit, "DeathRef", (object)"Viking Death Vocals/Berserker");
		}
	}

	public static void SetClothes(GameObject cloth, CharacterItem item, PropItemData data, LandfallContentDatabase db)
	{
	}

	public static void SetMoves(GameObject move, LandfallContentDatabase db)
	{
	}

	public static void SetUnits(Unit unit, LandfallContentDatabase db)
	{
		if (((Object)((Component)unit).gameObject).name == ((Object)UPool.MyPool.GetObject("Humanoid_Jarl")).name)
		{
			SkinnedMeshRenderer[] componentsInChildren = ((Component)unit).GetComponentsInChildren<SkinnedMeshRenderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.tag = "UnitMesh";
			}
		}
		if (((Object)((Component)unit).gameObject).name == ((Object)UPool.MyPool.GetObject("Humanoid_Berserker")).name)
		{
			SkinnedMeshRenderer[] componentsInChildren2 = ((Component)unit).GetComponentsInChildren<SkinnedMeshRenderer>();
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				((Component)componentsInChildren2[j]).gameObject.tag = "UnitMesh";
			}
		}
	}

	public static void Init(LandfallContentDatabase db)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		LoadBundle("unitappearanceresetbundle");
		Sprite val = (Sprite)SLMALoader.SDic["sprites"]["Icons_128x128_Giant"];
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Custom Weapon Items";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		UPool.MyPool.AddObject("SturdierBerserkerAxe", Utility.LoadBundleGameObject("SturdierBerserkerAxe"), true, (HideFlags)52, val, 6345243, true);
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Custom Unit Bases Items";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		UPool.MyPool.AddObject("Humanoid_Jarl", Utility.LoadBundleGameObject("Humanoid_Jarl"), true, (HideFlags)52, val, 63454342, true);
		UPool.MyPool.AddObject("Humanoid_Berserker", Utility.LoadBundleGameObject("Humanoid_Berserker"), true, (HideFlags)52, val, 6363342, true);
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Inserting Unit Bases";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		unitBasesBlueprints = new List<UnitBlueprint>
		{
			SLMATool.CreateUnit("Reskinned Jarl", (UnitBlueprint)null, (Faction)SLMALoader.SDic["factions"]["Subunits"], val),
			SLMATool.CreateUnit("Reskinned Berserker", (UnitBlueprint)null, (Faction)SLMALoader.SDic["factions"]["Subunits"], val)
		}.ToArray();
	}

	public static void SetWeapon(GameObject weapon, MeleeWeapon melee, RangeWeapon range, LandfallContentDatabase db)
	{
	}

	public static void SetEffects(GameObject effect)
	{
	}

	public static void LoadBundle(string assetBundleName)
	{
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetBundleName);
		bundle = AssetBundle.LoadFromStream(stream);
	}

	public static void SetExplosion(GameObject explosion)
	{
	}

	public static void SetProjectile(GameObject proj, ProjectileHit projhit, LandfallContentDatabase db)
	{
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("GeeztJeez.UnitAppearanceReset", "UnitAppearanceReset", "1.0.1")]
internal class Loader : BaseUnityPlugin
{
	private void Awake()
	{
		((MonoBehaviour)this).StartCoroutine("Call");
	}

	private IEnumerator Call()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
		yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
		Debug.Log((object)"Loading UnitAppearanceReset!");
		SLMALoader.GetInstance();
		SceneManager.sceneLoaded += SceneLoaded;
		LandfallContentDatabase landfallContentDatabase = ContentDatabase.Instance().LandfallContentDatabase;
		UManager.Init(landfallContentDatabase);
		new Harmony("UnitAppearanceReset").PatchAll();
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<Explosion>()))
			{
				UManager.SetExplosion(array[i]);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<ProjectileHit>()))
			{
				UManager.SetProjectile(array[i], array[i].GetComponent<ProjectileHit>(), landfallContentDatabase);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<Unit>()))
			{
				UManager.SetUnits(array[i].GetComponent<Unit>(), landfallContentDatabase);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<WeaponItem>()))
			{
				UManager.SetWeapon(array[i], array[i].GetComponent<MeleeWeapon>(), array[i].GetComponent<RangeWeapon>(), landfallContentDatabase);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<PlaySoundEffect>()))
			{
				UManager.SetEffects(array[i]);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<SpecialAbility>()))
			{
				UManager.SetMoves(array[i], landfallContentDatabase);
			}
			if (Object.op_Implicit((Object)(object)array[i].GetComponent<PropItem>()))
			{
				UManager.SetClothes(array[i], array[i].GetComponent<CharacterItem>(), array[i].GetComponent<PropItemData>(), landfallContentDatabase);
			}
		}
		UnitBlueprint[] array2 = Resources.FindObjectsOfTypeAll<UnitBlueprint>();
		for (int j = 0; j < array2.Length; j++)
		{
			UManager.SetBlueprint(array2[j], landfallContentDatabase);
			array2[j].Validate();
		}
		Debug.Log((object)"Loaded UnitAppearanceReset Successfully!");
	}

	public void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		if (!(((Scene)(ref scene)).name == "UnitCreator_GamepadUI"))
		{
			return;
		}
		UnitEditorManager component = ((Scene)(ref scene)).GetRootGameObjects().ToList().Find((GameObject x) => Object.op_Implicit((Object)(object)x.GetComponent<UnitEditorManager>()))
			.GetComponent<UnitEditorManager>();
		List<UnitBaseWrapper> list = new List<UnitBaseWrapper>(component.UnitBases);
		UnitBlueprint[] unitBasesBlueprints = UManager.unitBasesBlueprints;
		foreach (UnitBlueprint val in unitBasesBlueprints)
		{
			UnitBaseWrapper wrapper = new UnitBaseWrapper
			{
				BaseDisplayName = val.Entity.Name,
				UnitBaseBlueprint = val,
				UnitBaseRestriction = (UnitBaseRestrictions)0
			};
			val.Entity.GetSpriteIconAsync((Action<Sprite>)delegate(Sprite sprite)
			{
				wrapper.BaseIcon = sprite;
			});
			list.Add(wrapper);
		}
		component.UnitBases = list.ToArray();
	}
}