using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using DM; using HarmonyLib; using Landfall.TABS; using Landfall.TABS.UnitEditor; using LevelCreator; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace TABSUXMod; public static class AllUnitBasesPatch { private static FieldInfo s_nonStreamableAssetsField; private static Dictionary s_rigsByGuid; private static int s_rigsBuiltFromCount = -1; private static bool s_resolving; [HarmonyPrefix] [HarmonyPatch(typeof(UnitEditorManager), "Start")] public static void BeforeUnitEditorStart(UnitEditorManager __instance) { Debug.Log((object)"[TABSUXMod] UnitEditorManager.Start prefix fired."); try { Inject(__instance); } catch (Exception ex) { Debug.LogError((object)("[TABSUXMod] Failed to add unit bases to the Unit Creator: " + ex)); } } [HarmonyPrefix] [HarmonyPatch(typeof(UnitEditorUnitBaseGrid), "SpawnUnitBaseButtons")] public static void BeforeSpawnUnitBaseButtons(ref UnitBaseWrapper[] unitBaseWrappers, UnitEditorManager unitEditorManager) { Debug.Log((object)("[TABSUXMod] SpawnUnitBaseButtons prefix fired with " + ((unitBaseWrappers != null) ? unitBaseWrappers.Length : (-1)) + " wrappers.")); try { if (!((Object)(object)unitEditorManager == (Object)null)) { Inject(unitEditorManager); unitBaseWrappers = unitEditorManager.UnitBases; } } catch (Exception ex) { Debug.LogError((object)("[TABSUXMod] Failed to add unit bases to the Unit Creator: " + ex)); } } private static void Inject(UnitEditorManager manager) { //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Expected O, but got Unknown List list = new List(manager.UnitBases); if (list.Count == 0) { Debug.LogWarning((object)"[TABSUXMod] UnitBases is empty; nothing to use as a template, skipping."); return; } UnitBlueprint unitBaseBlueprint = list[0].UnitBaseBlueprint; if ((Object)(object)unitBaseBlueprint == (Object)null) { Debug.LogWarning((object)"[TABSUXMod] UnitBases[0] has no blueprint to use as a template, skipping."); return; } HashSet hashSet = new HashSet(); foreach (UnitBaseWrapper item in list) { if (item != null && (Object)(object)item.UnitBaseBlueprint != (Object)null && (Object)(object)item.UnitBaseBlueprint.UnitBase != (Object)null) { hashSet.Add(item.UnitBaseBlueprint.UnitBase); } } ContentDatabase val = ContentDatabase.Instance(); List list2 = new List(); Dictionary dictionary = new Dictionary(); foreach (GameObject allUnitBasis in val.GetAllUnitBases()) { if ((Object)(object)allUnitBasis != (Object)null) { list2.Add(allUnitBasis); } } int count = list2.Count; foreach (UnitBlueprint allUnitBlueprint in val.GetAllUnitBlueprints()) { if ((Object)(object)allUnitBlueprint == (Object)null) { continue; } GameObject unitBase; try { unitBase = allUnitBlueprint.UnitBase; } catch { continue; } if (!((Object)(object)unitBase == (Object)null)) { list2.Add(unitBase); if (!dictionary.ContainsKey(unitBase)) { dictionary[unitBase] = allUnitBlueprint; } } } int num = 0; List list3 = new List(); foreach (GameObject item2 in list2) { if (hashSet.Add(item2)) { Unit component = item2.GetComponent(); if ((Object)(object)component == (Object)null || component.Entity == null) { num++; continue; } if ((Object)(object)item2.GetComponentInChildren(true) == (Object)null || (Object)(object)item2.GetComponentInChildren(true) == (Object)null || (Object)(object)item2.GetComponentInChildren(true) == (Object)null) { num++; continue; } UnitBlueprint val2 = new UnitBlueprint(unitBaseBlueprint); val2.UnitBase = item2; val2.Entity.Name = component.Entity.Name; UnitBaseWrapper val3 = new UnitBaseWrapper { UnitBaseBlueprint = val2, BaseDisplayName = component.Entity.Name, UnitBaseRestriction = (UnitBaseRestrictions)0 }; dictionary.TryGetValue(item2, out var value); LoadIcon(val3, component.Entity, value); list3.Add(val3); } } list3.Sort((UnitBaseWrapper a, UnitBaseWrapper b) => string.Compare(a.BaseDisplayName, b.BaseDisplayName, StringComparison.OrdinalIgnoreCase)); list.AddRange(list3); manager.UnitBases = list.ToArray(); int num2 = 0; foreach (UnitBaseWrapper item3 in list) { GameObject val4 = ((item3 != null && (Object)(object)item3.UnitBaseBlueprint != (Object)null) ? item3.UnitBaseBlueprint.UnitBase : null); if ((Object)(object)val4 != (Object)null && RegisterRig(val, val4)) { num2++; } } Debug.Log((object)("[TABSUXMod] Added " + list3.Count + " unit bases to the Unit Creator (" + list.Count + " total; " + count + " registered rigs, " + (list2.Count - count) + " blueprint rigs, " + num + " skipped as unusable, " + num2 + " rigs newly registered in AssetLoader).")); } private static bool RegisterRig(ContentDatabase db, GameObject rig) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) Unit component = rig.GetComponent(); if ((Object)(object)component == (Object)null || component.Entity == null) { return false; } if (s_nonStreamableAssetsField == null) { s_nonStreamableAssetsField = typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.NonPublic); } Dictionary dictionary = (Dictionary)s_nonStreamableAssetsField.GetValue(db.AssetLoader); if (dictionary.ContainsKey(component.Entity.GUID)) { return false; } dictionary.Add(component.Entity.GUID, (Object)(object)rig); return true; } [HarmonyPostfix] [HarmonyPatch(typeof(ContentDatabase), "GetGameObject")] public unsafe static void AfterGetGameObject(DatabaseID databaseId, ref GameObject __result) { //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__result != (Object)null || s_resolving) { return; } try { s_resolving = true; ContentDatabase val = ContentDatabase.Instance(); List list = new List(val.GetAllUnitBlueprints()); if (s_rigsByGuid == null || list.Count != s_rigsBuiltFromCount) { Dictionary dictionary = new Dictionary(); foreach (UnitBlueprint item in list) { if ((Object)(object)item == (Object)null) { continue; } GameObject unitBase; try { unitBase = item.UnitBase; } catch { continue; } if (!((Object)(object)unitBase == (Object)null)) { Unit component = unitBase.GetComponent(); if ((Object)(object)component != (Object)null && component.Entity != null && !dictionary.ContainsKey(component.Entity.GUID)) { dictionary[component.Entity.GUID] = unitBase; } } } s_rigsByGuid = dictionary; s_rigsBuiltFromCount = list.Count; } if (s_rigsByGuid.TryGetValue(databaseId, out var value)) { RegisterRig(val, value); __result = value; string[] obj2 = new string[5] { "[TABSUXMod] Resolved unit base '", ((Object)value).name, "' (", null, null }; DatabaseID val2 = databaseId; obj2[3] = ((object)(*(DatabaseID*)(&val2))/*cast due to .constrained prefix*/).ToString(); obj2[4] = ") via blueprint fallback."; Debug.Log((object)string.Concat(obj2)); } } catch (Exception ex) { Debug.LogError((object)("[TABSUXMod] GetGameObject fallback failed: " + ex)); } finally { s_resolving = false; } } private static void LoadIcon(UnitBaseWrapper wrapper, DatabaseEntity rigEntity, UnitBlueprint fallback) { rigEntity.GetSpriteIconAsync((Action)delegate(Sprite sprite) { if ((Object)(object)sprite != (Object)null) { wrapper.BaseIcon = sprite; } else if ((Object)(object)fallback != (Object)null && fallback.Entity != null) { fallback.Entity.GetSpriteIconAsync((Action)delegate(Sprite fallbackSprite) { wrapper.BaseIcon = fallbackSprite; }); } }); } } public static class AutoConfirmLoadModsPatch { private static MethodInfo setPermission; private static MethodInfo onCheckedPermission; public static void Apply(Harmony harmony) { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown Assembly assembly = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (assembly2.GetName().Name == "Assembly-CSharp") { assembly = assembly2; break; } } if (assembly == null) { Debug.LogWarning((object)"[TABSUXMod] Assembly-CSharp not found — load-mods auto-confirm skipped."); return; } Type type = assembly.GetType("Landfall.TABS.Workshop.CustomContentLoaderModIO"); if (type == null) { Debug.LogWarning((object)"[TABSUXMod] CustomContentLoaderModIO not found — load-mods auto-confirm skipped."); return; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic; PropertyInfo property = type.GetProperty("DidGivePermissionToLoadMods", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); setPermission = ((property != null) ? property.GetSetMethod(nonPublic: true) : null); onCheckedPermission = type.GetMethod("OnCheckedPermissionToLoadMods", bindingAttr); MethodInfo method = type.GetMethod("CheckPermissionToLoadMods", BindingFlags.Instance | BindingFlags.Public); if (setPermission == null || onCheckedPermission == null || method == null) { Debug.LogWarning((object)"[TABSUXMod] CustomContentLoaderModIO members not found — load-mods auto-confirm skipped."); return; } MethodInfo method2 = typeof(AutoConfirmLoadModsPatch).GetMethod("CheckPermissionPrefix", BindingFlags.Static | BindingFlags.NonPublic); harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Debug.Log((object)"[TABSUXMod] Load-mods warning auto-confirm active."); } private static bool CheckPermissionPrefix(object __instance, bool refresh, object doneCallback) { Debug.Log((object)"[TABSUXMod] Auto-confirming 'load mods?' warning."); setPermission.Invoke(__instance, new object[1] { true }); onCheckedPermission.Invoke(__instance, new object[2] { refresh, doneCallback }); return false; } } public static class BulkDeletePatch { private static readonly HashSet selected = new HashSet(); private static readonly List overlays = new List(); private static bool selectMode = false; private static Button deleteButton; private static TextMeshProUGUI deleteButtonLabel; private static MonoBehaviour sideBarInstance; private static MethodInfo deleteBCSCMethod; private static Type contentTypeFilterType; private static Type customContentFilePathsType; [HarmonyPostfix] [HarmonyPatch(typeof(CustomContentGridBrowser), "OnEnable")] public static void OnBrowserOpen(CustomContentGridBrowser __instance) { ExitSelectMode(); } [HarmonyPostfix] [HarmonyPatch(typeof(CustomContentGridBrowser), "Populate")] public static void OnBrowserPopulate(CustomContentGridBrowser __instance) { EnsureDeleteButton(__instance); RefreshDeleteButton(); } [HarmonyPostfix] [HarmonyPatch(typeof(UnitButtonBase), "Setup")] public static void OnUnitButtonSetup(UnitButtonBase __instance, UnitBlueprint unit) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Expected O, but got Unknown //IL_02a5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)unit == (Object)null) { return; } GameObject gameObject = ((Component)__instance).gameObject; if ((Object)(object)gameObject.transform.Find("BulkSelectOverlay") != (Object)null) { return; } GameObject val = new GameObject("BulkSelectOverlay", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(gameObject.transform, false); val.SetActive(selectMode); overlays.Add(val); RectTransform component = val.GetComponent(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; Image val2 = val.AddComponent(); ((Graphic)val2).color = new Color(0f, 0f, 0f, 0f); Button val3 = val.AddComponent