Decompiled source of Unit Appearance Reset v0.5.0

UnitAppearanceReset.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 FhpSLib;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.UnitEditor;
using SLMA;
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("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.5.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 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Expected O, but got Unknown
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Expected O, but got Unknown
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Expected O, but got Unknown
		//IL_0320: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Expected O, but got Unknown
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_FANTASYEVIL_WARGLAIVE"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_DeathBringer");
			unit.LeftWeapon = UPool.MyPool.GetObject("WarGlaiveCurvedExtended");
			unit.RightWeapon = UPool.MyPool.GetObject("WarGlaiveCurvedExtended");
			unit.m_props = (GameObject[])(object)new GameObject[4]
			{
				UPool.MyPool.GetObject("DeathBringerNewDevilHorn"),
				UPool.MyPool.GetObject("DeathBringerNewMask"),
				UPool.MyPool.GetObject("DeathBringerSkullTrophy"),
				UPool.MyPool.GetObject("DeathBringerSuit")
			};
		}
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_SECRET_REDJADE"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Female");
			unit.RightWeapon = UPool.MyPool.GetObject("RedJadeLongblade");
			unit.m_props = (GameObject[])(object)new GameObject[1] { UPool.MyPool.GetObject("RedJadeSuit") };
		}
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_SECRET_SHOGUN"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Shogun");
			unit.RightWeapon = UPool.MyPool.GetObject("ShogunKatana");
			unit.m_props = (GameObject[])(object)new GameObject[2]
			{
				UPool.MyPool.GetObject("ShoGunSuit"),
				UPool.MyPool.GetObject("ShogunSkin")
			};
		}
		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] { UPool.MyPool.GetObject("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] { UPool.MyPool.GetObject("NewBerserkerSuit") };
		}
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_ASIA_MONK"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Monk");
			unit.RightWeapon = UPool.MyPool.GetObject("MonkNaginata");
			unit.m_props = (GameObject[])(object)new GameObject[2]
			{
				UPool.MyPool.GetObject("NewMonkSuit"),
				UPool.MyPool.GetObject("NewMonkClothSuit")
			};
		}
		if ((Object)(object)unit == (Object)(UnitBlueprint)SLMALoader.SDic["blueprints"]["UNIT_MEDIEVAL_KNIGHT"])
		{
			unit.UnitBase = UPool.MyPool.GetObject("Humanoid_Berserker");
			unit.LeftWeapon = UPool.MyPool.GetObject("NewKnightShield");
			unit.RightWeapon = UPool.MyPool.GetObject("NewKnightSword");
			unit.m_propData = (PropItemData[])(object)new PropItemData[0];
			unit.m_props = (GameObject[])(object)new GameObject[1] { UPool.MyPool.GetObject("KnightClothes") };
		}
	}

	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_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		Sprite val = (Sprite)SLMALoader.SDic["sprites"]["Icons_128x128_Giant"];
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Custom Weapon Items";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		UPool.MyPool.AddObject("WarGlaiveCurvedExtended", Utility.LoadBundleGameObject("WarGlaiveCurvedExtended"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 625432412), true);
		UPool.MyPool.AddObject("RedJadeLongblade", Utility.LoadBundleGameObject("RedJadeLongblade"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 625432421), true);
		UPool.MyPool.AddObject("ShogunKatana", Utility.LoadBundleGameObject("ShogunKatana"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 625432422), true);
		UPool.MyPool.AddObject("NewKnightShield", Utility.LoadBundleGameObject("NewKnightShield"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 625432423), true);
		UPool.MyPool.AddObject("NewKnightSword", Utility.LoadBundleGameObject("NewKnightSword"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 62323234), true);
		UPool.MyPool.AddObject("SturdierBerserkerAxe", Utility.LoadBundleGameObject("SturdierBerserkerAxe"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 6345243), true);
		UPool.MyPool.AddObject("MonkNaginata", Utility.LoadBundleGameObject("MonkNaginata"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Weapon, 73453454), true);
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Custom Clothes Items";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		UPool.MyPool.AddObject("DeathBringerNewDevilHorn", Utility.LoadBundleGameObject("DeathBringerNewDevilHorn"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 21312312), true);
		UPool.MyPool.AddObject("DeathBringerNewMask", Utility.LoadBundleGameObject("DeathBringerNewMask"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 52342342), true);
		UPool.MyPool.AddObject("DeathBringerSkullTrophy", Utility.LoadBundleGameObject("DeathBringerSkullTrophy"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 51231321), true);
		UPool.MyPool.AddObject("DeathBringerSuit", Utility.LoadBundleGameObject("DeathBringerSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 53242332), true);
		UPool.MyPool.AddObject("RedJadeSuit", Utility.LoadBundleGameObject("RedJadeSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7253231), true);
		UPool.MyPool.AddObject("ShogunSkin", Utility.LoadBundleGameObject("ShogunSkin"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7253232), true);
		UPool.MyPool.AddObject("ShoGunSuit", Utility.LoadBundleGameObject("ShoGunSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7253233), true);
		UPool.MyPool.AddObject("NewBerserkerSuit", Utility.LoadBundleGameObject("NewBerserkerSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7253234), true);
		UPool.MyPool.AddObject("NewMonkSuit", Utility.LoadBundleGameObject("NewMonkSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7642433), true);
		UPool.MyPool.AddObject("NewMonkClothSuit", Utility.LoadBundleGameObject("NewMonkClothSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 1251232), true);
		UPool.MyPool.AddObject("KnightClothes", Utility.LoadBundleGameObject("KnightClothes"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 7645324), true);
		UPool.MyPool.AddObject("NewJarlSuit", Utility.LoadBundleGameObject("NewJarlSuit"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.Prop, 1254123), true);
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		comment = "Custom Unit Bases Items";
		comment = "----------------------------------------------------------------------------------------------------------------------------";
		UPool.MyPool.AddObject("Humanoid_DeathBringer", Utility.LoadBundleGameObject("Humanoid_DeathBringer"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 63456345), true);
		UPool.MyPool.AddObject("Humanoid_Shogun", Utility.LoadBundleGameObject("Humanoid_Shogun"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 63454340), true);
		UPool.MyPool.AddObject("Humanoid_Jarl", Utility.LoadBundleGameObject("Humanoid_Jarl"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 63454341), true);
		UPool.MyPool.AddObject("Humanoid_Berserker", Utility.LoadBundleGameObject("Humanoid_Berserker"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 6363342), true);
		UPool.MyPool.AddObject("Humanoid_Monk", Utility.LoadBundleGameObject("Humanoid_Monk"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 7345454), true);
		UPool.MyPool.AddObject("Humanoid_Female", Utility.LoadBundleGameObject("Humanoid_Female"), true, (HideFlags)52, val, Utilities.Utility.IDChecker(Utilities.AssetType.UnitBase, 7345455), true);
	}

	public static void SetWeapon(GameObject weapon, MeleeWeapon melee, RangeWeapon range, LandfallContentDatabase db)
	{
		if ((Object)(object)weapon == (Object)(object)UPool.MyPool.GetObject("WarGlaiveCurvedExtended"))
		{
			weapon.AddComponent<FollowTransformDynamicBehaviour>();
		}
	}

	public static void SetEffects(GameObject effect)
	{
	}

	public static void LoadBundle(string assetBundleName)
	{
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetBundleName);
		if (manifestResourceStream == null)
		{
			Debug.LogError((object)("[LoadBundle] Failed to find resource: " + assetBundleName));
		}
		else if (!manifestResourceStream.CanRead)
		{
			Debug.LogError((object)("[LoadBundle] Resource stream is not readable: " + assetBundleName));
		}
		else
		{
			bundle = AssetBundle.LoadFromStream(manifestResourceStream);
		}
	}

	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.5")]
internal class Loader : BaseUnityPlugin
{
	private void Awake()
	{
		((MonoBehaviour)this).StartCoroutine(Load());
	}

	private IEnumerator Load()
	{
		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();
		LandfallContentDatabase landfallContentDatabase = ContentDatabase.Instance().LandfallContentDatabase;
		Utilities.bundle = (UManager.bundle = LoadBundle("unitappearanceresetbundle"));
		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 AssetBundle LoadBundle(string assetBundleName)
	{
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetBundleName);
		if (manifestResourceStream == null)
		{
			return null;
		}
		if (!manifestResourceStream.CanRead)
		{
			return null;
		}
		return AssetBundle.LoadFromStream(manifestResourceStream);
	}
}
public sealed class Utilities
{
	public class Utility : MonoBehaviour
	{
		public static class PrimitiveHelper
		{
			private static Dictionary<PrimitiveType, Mesh> primitiveMeshes = new Dictionary<PrimitiveType, Mesh>();

			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;
			}
		}

		public static class GameObjectHelper
		{
			public static GameObject InstantiateEmpty(string name, Vector3 position, Quaternion rotation, Transform parent)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: 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: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Expected O, but got Unknown
				GameObject val = new GameObject(name);
				val.transform.position = position;
				val.transform.rotation = rotation;
				val.transform.parent = parent;
				return val;
			}
		}

		public static class ItemCategorizer
		{
			public static GameObject SetTag(GameObject item, string categoryName = "Expansionary", TagType tagType = 0)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					CharacterItem componentInChildren = item.GetComponentInChildren<CharacterItem>();
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						componentInChildren.tags = new List<Tag>
						{
							new Tag
							{
								tagType = tagType,
								value = categoryName
							}
						};
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
				return item;
			}
		}

		private static Dictionary<DatabaseID, GameObject> CombatMoves
		{
			get
			{
				Dictionary<DatabaseID, GameObject> dictionary = HelpLibrary.m_combatMoves;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_combatMoves = new Dictionary<DatabaseID, GameObject>());
				}
				return dictionary;
			}
		}

		private static Dictionary<DatabaseID, GameObject> CharacterProps
		{
			get
			{
				Dictionary<DatabaseID, GameObject> dictionary = HelpLibrary.m_characterProps;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_characterProps = new Dictionary<DatabaseID, GameObject>());
				}
				return dictionary;
			}
		}

		private static Dictionary<DatabaseID, GameObject> UnitBases
		{
			get
			{
				Dictionary<DatabaseID, GameObject> dictionary = HelpLibrary.m_unitBases;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_unitBases = new Dictionary<DatabaseID, GameObject>());
				}
				return dictionary;
			}
		}

		private static Dictionary<DatabaseID, Faction> Factions
		{
			get
			{
				Dictionary<DatabaseID, Faction> dictionary = HelpLibrary.m_factions;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_factions = new Dictionary<DatabaseID, Faction>());
				}
				return dictionary;
			}
		}

		private static Dictionary<DatabaseID, GameObject> Weapons
		{
			get
			{
				Dictionary<DatabaseID, GameObject> dictionary = HelpLibrary.m_weapons;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_weapons = new Dictionary<DatabaseID, GameObject>());
				}
				return dictionary;
			}
		}

		private static Dictionary<DatabaseID, GameObject> Projectiles
		{
			get
			{
				Dictionary<DatabaseID, GameObject> dictionary = HelpLibrary.m_projectiles;
				if (dictionary == null)
				{
					dictionary = (HelpLibrary.m_projectiles = new Dictionary<DatabaseID, GameObject>());
				}
				return dictionary;
			}
		}

		public AssetBundle LoadBundle(string assetBundleName)
		{
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assetBundleName);
			if (manifestResourceStream == null)
			{
				Debug.LogError((object)("[LoadBundle] Failed to find resource: " + assetBundleName));
				return null;
			}
			if (!manifestResourceStream.CanRead)
			{
				Debug.LogError((object)("[LoadBundle] Resource stream is not readable: " + assetBundleName));
				return null;
			}
			return AssetBundle.LoadFromStream(manifestResourceStream);
		}

		public static Sprite LoadBundleTextureToSprite(string name)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)("Loading the texture named: " + name));
			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));
		}

		public static GameObject LoadBundleGameObject(string name)
		{
			return bundle.LoadAsset<GameObject>(name);
		}

		public static AudioClip LoadBundleAudioClip(string name)
		{
			return bundle.LoadAsset<AudioClip>(name);
		}

		public static Material LoadBundleMaterial(string name)
		{
			return bundle.LoadAsset<Material>(name);
		}

		public static int IDChecker(AssetType type, int startId = 1)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			int num = Math.Max(1, startId);
			DatabaseID id = default(DatabaseID);
			((DatabaseID)(ref id))..ctor(num);
			while (IsOccupied(type, id))
			{
				Debug.LogWarning((object)$"[IDChecker] ID {num} in use for {type}, trying {num + 1}…");
				num++;
				((DatabaseID)(ref id))..ctor(num);
			}
			Debug.Log((object)$"[IDChecker] Found free ID for {type}: {num}");
			return num;
		}

		private static bool IsOccupied(AssetType type, DatabaseID id)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			return type switch
			{
				AssetType.Prop => CharacterProps.ContainsKey(id), 
				AssetType.UnitBase => UnitBases.ContainsKey(id), 
				AssetType.Faction => Factions.ContainsKey(id), 
				AssetType.Ability => CombatMoves.ContainsKey(id), 
				AssetType.Weapon => Weapons.ContainsKey(id), 
				AssetType.Projectile => Projectiles.ContainsKey(id), 
				_ => throw new ArgumentOutOfRangeException("type", type, null), 
			};
		}
	}

	public enum AssetType
	{
		Prop,
		UnitBase,
		Faction,
		Ability,
		Weapon,
		Projectile
	}

	public static AssetBundle bundle;
}
public class FollowTransformDynamicBehaviour : MonoBehaviour
{
	public Unit unit;

	public Transform targetTransform;

	private Holdable holdable;

	private HoldingHandler holdingHandler;

	private GameObject weaponObject;

	public Rigidbody weaponRig;

	public bool doRotation = true;

	public bool doPosition = true;

	private void Start()
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Invalid comparison between Unknown and I4
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Invalid comparison between Unknown and I4
		//IL_0069: 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)
		unit = ((Component)((Component)this).transform.root).GetComponentInChildren<Unit>();
		holdable = ((Component)this).GetComponentInParent<Holdable>();
		holdingHandler = holdable.holdingHandler;
		weaponObject = ((Component)((Component)this).transform).gameObject;
		weaponRig = weaponObject.GetComponentInChildren<Rigidbody>();
		if (((int)holdingHandler.leftHandActivity == 2 || (int)holdingHandler.leftHandActivity == 0) && ((int)holdingHandler.rightHandActivity == 1 || (int)holdingHandler.leftHandActivity == 0))
		{
			if (Object.op_Implicit((Object)(object)holdingHandler.leftObject) && (Object)(object)weaponObject == (Object)(object)((Component)holdingHandler.leftObject).gameObject)
			{
				targetTransform = unit.data.leftHand;
			}
			if (Object.op_Implicit((Object)(object)holdingHandler.rightObject) && (Object)(object)weaponObject == (Object)(object)((Component)holdingHandler.rightObject).gameObject)
			{
				targetTransform = unit.data.rightHand;
			}
		}
		if (Object.op_Implicit((Object)(object)weaponRig))
		{
			weaponRig.interpolation = (RigidbodyInterpolation)0;
			weaponRig.angularDrag = 30f;
		}
	}

	private void LateUpdate()
	{
		//IL_0022: 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)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)targetTransform))
		{
			return;
		}
		if (doPosition)
		{
			((Component)this).transform.position = targetTransform.position;
		}
		if (doRotation)
		{
			((Component)this).transform.rotation = targetTransform.rotation;
		}
		if (Object.op_Implicit((Object)(object)weaponRig))
		{
			if (doPosition)
			{
				weaponRig.MovePosition(targetTransform.position);
			}
			if (doRotation)
			{
				weaponRig.MoveRotation(targetTransform.rotation);
			}
		}
	}
}