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 Landfall.TABS.UnitPlacement;
using Landfall.TABS.Workshop;
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<DatabaseID, GameObject> 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<UnitBaseWrapper> list = new List<UnitBaseWrapper>(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<GameObject> hashSet = new HashSet<GameObject>();
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<GameObject> list2 = new List<GameObject>();
Dictionary<GameObject, UnitBlueprint> dictionary = new Dictionary<GameObject, UnitBlueprint>();
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<UnitBaseWrapper> list3 = new List<UnitBaseWrapper>();
foreach (GameObject item2 in list2)
{
if (hashSet.Add(item2))
{
Unit component = item2.GetComponent<Unit>();
if ((Object)(object)component == (Object)null || component.Entity == null)
{
num++;
continue;
}
if ((Object)(object)item2.GetComponentInChildren<Torso>(true) == (Object)null || (Object)(object)item2.GetComponentInChildren<HealthHandler>(true) == (Object)null || (Object)(object)item2.GetComponentInChildren<RigidbodyHolder>(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<Unit>();
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<DatabaseID, Object> dictionary = (Dictionary<DatabaseID, Object>)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<UnitBlueprint> list = new List<UnitBlueprint>(val.GetAllUnitBlueprints());
if (s_rigsByGuid == null || list.Count != s_rigsBuiltFromCount)
{
Dictionary<DatabaseID, GameObject> dictionary = new Dictionary<DatabaseID, GameObject>();
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<Unit>();
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<Sprite>)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<Sprite>)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<IDatabaseEntity> selected = new HashSet<IDatabaseEntity>();
private static readonly List<GameObject> overlays = new List<GameObject>();
private static bool selectMode = false;
private static Button deleteButton;
private static TextMeshProUGUI deleteButtonLabel;
private static Type deleteButtonOwnerType;
private static MonoBehaviour sideBarInstance;
private static MethodInfo deleteBCSCMethod;
private static Type contentTypeFilterType;
[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)
{
if (!((Object)(object)unit == (Object)null))
{
AddOverlay(((Component)__instance).gameObject, (IDatabaseEntity)(object)unit);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CustomContentLevelButton), "Setup")]
public static void OnLevelButtonSetup(CustomContentLevelButton __instance, CustomMap customMap)
{
if (!((Object)(object)customMap == (Object)null))
{
AddOverlay(((Component)__instance).gameObject, (IDatabaseEntity)(object)customMap);
}
}
private static void AddOverlay(GameObject go, IDatabaseEntity entity)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: 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_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Expected O, but got Unknown
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)go.transform.Find("BulkSelectOverlay") != (Object)null)
{
return;
}
GameObject val = new GameObject("BulkSelectOverlay", new Type[1] { typeof(RectTransform) });
val.transform.SetParent(go.transform, false);
val.SetActive(selectMode);
overlays.Add(val);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
Image val2 = val.AddComponent<Image>();
((Graphic)val2).color = new Color(0f, 0f, 0f, 0f);
Button val3 = val.AddComponent<Button>();
((Selectable)val3).targetGraphic = (Graphic)(object)val2;
((Selectable)val3).transition = (Transition)0;
GameObject val4 = new GameObject("Checkbox", new Type[1] { typeof(RectTransform) });
val4.transform.SetParent(val.transform, false);
RectTransform component2 = val4.GetComponent<RectTransform>();
component2.anchorMin = new Vector2(0f, 1f);
component2.anchorMax = new Vector2(0f, 1f);
component2.pivot = new Vector2(0f, 1f);
component2.anchoredPosition = new Vector2(4f, -4f);
component2.sizeDelta = new Vector2(28f, 28f);
Image val5 = val4.AddComponent<Image>();
((Graphic)val5).color = new Color(0f, 0f, 0f, 0.55f);
GameObject val6 = new GameObject("Check", new Type[1] { typeof(RectTransform) });
val6.transform.SetParent(val4.transform, false);
RectTransform component3 = val6.GetComponent<RectTransform>();
component3.anchorMin = Vector2.zero;
component3.anchorMax = Vector2.one;
component3.offsetMin = Vector2.zero;
component3.offsetMax = Vector2.zero;
TextMeshProUGUI val7 = val6.AddComponent<TextMeshProUGUI>();
((TMP_Text)val7).text = "";
((TMP_Text)val7).fontSize = 18f;
((TMP_Text)val7).alignment = (TextAlignmentOptions)514;
((Graphic)val7).color = Color.white;
IDatabaseEntity capturedEntity = entity;
TextMeshProUGUI capturedCheck = val7;
Image capturedBg = val5;
((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
{
//IL_009c: 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)
if (selectMode)
{
if (selected.Contains(capturedEntity))
{
selected.Remove(capturedEntity);
((TMP_Text)capturedCheck).text = "";
((Graphic)capturedBg).color = new Color(0f, 0f, 0f, 0.55f);
}
else
{
selected.Add(capturedEntity);
((TMP_Text)capturedCheck).text = "✔";
((Graphic)capturedBg).color = new Color(0.18f, 0.65f, 0.18f, 0.85f);
}
RefreshDeleteButton();
}
});
if (selected.Contains(entity))
{
((TMP_Text)val7).text = "✔";
((Graphic)val5).color = new Color(0.18f, 0.65f, 0.18f, 0.85f);
}
}
private static void EnsureDeleteButton(CustomContentGridBrowser browser)
{
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Expected O, but got Unknown
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: 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: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_031a: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Expected O, but got Unknown
CustomContentUnitBrowser componentInChildren = ((Component)browser).GetComponentInChildren<CustomContentUnitBrowser>(true);
Component layout;
string text;
Type typeFromHandle;
if ((Object)(object)componentInChildren != (Object)null)
{
layout = GetLayout01((Component)(object)componentInChildren);
text = "New Unit";
typeFromHandle = typeof(CustomContentUnitBrowser);
}
else
{
CustomContentLevelBrowser componentInChildren2 = ((Component)browser).GetComponentInChildren<CustomContentLevelBrowser>(true);
if ((Object)(object)componentInChildren2 == (Object)null)
{
Debug.LogWarning((object)"[TABSUXMod] Neither CustomContentUnitBrowser nor CustomContentLevelBrowser found.");
return;
}
layout = GetLayout01((Component)(object)componentInChildren2);
text = "NewLevel";
typeFromHandle = typeof(CustomContentLevelBrowser);
}
if ((Object)(object)deleteButton != (Object)null && (Object)(object)((Component)deleteButton).gameObject != (Object)null && deleteButtonOwnerType == typeFromHandle)
{
return;
}
if ((Object)(object)deleteButton != (Object)null && (Object)(object)((Component)deleteButton).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)deleteButton).gameObject);
}
deleteButton = null;
deleteButtonLabel = null;
if ((Object)(object)layout == (Object)null)
{
Debug.LogWarning((object)"[TABSUXMod] layout01 field not found.");
return;
}
Transform parent = layout.transform.parent;
Button val = null;
foreach (Transform item in parent)
{
Transform val2 = item;
if (((Object)val2).name == text)
{
val = ((Component)val2).GetComponent<Button>();
break;
}
}
if ((Object)(object)val == (Object)null)
{
Debug.LogWarning((object)("[TABSUXMod] '" + text + "' not found in grid. Siblings:"));
{
foreach (Transform item2 in parent)
{
Transform val3 = item2;
Debug.Log((object)("[TABSUXMod] sibling: '" + ((Object)val3).name + "'"));
}
return;
}
}
GameObject val4 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent, false);
((Object)val4).name = "BulkDeleteBtn";
deleteButton = val4.GetComponent<Button>();
deleteButtonOwnerType = typeFromHandle;
deleteButton.onClick = new ButtonClickedEvent();
((UnityEvent)deleteButton.onClick).AddListener(new UnityAction(OnDeleteButtonClicked));
RectTransform component = ((Component)val).GetComponent<RectTransform>();
RectTransform component2 = val4.GetComponent<RectTransform>();
component2.anchorMin = component.anchorMin;
component2.anchorMax = component.anchorMax;
component2.pivot = component.pivot;
component2.sizeDelta = component.sizeDelta;
component2.anchoredPosition = component.anchoredPosition + new Vector2(component.sizeDelta.x + 8f, 0f);
val4.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
TextMeshProUGUI[] componentsInChildren = val4.GetComponentsInChildren<TextMeshProUGUI>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
Object.Destroy((Object)(object)((Component)componentsInChildren[i]).gameObject);
}
GameObject val5 = new GameObject("Label", new Type[1] { typeof(RectTransform) });
val5.transform.SetParent(val4.transform, false);
RectTransform component3 = val5.GetComponent<RectTransform>();
component3.anchorMin = Vector2.zero;
component3.anchorMax = Vector2.one;
component3.offsetMin = Vector2.zero;
component3.offsetMax = Vector2.zero;
deleteButtonLabel = val5.AddComponent<TextMeshProUGUI>();
((TMP_Text)deleteButtonLabel).alignment = (TextAlignmentOptions)514;
((TMP_Text)deleteButtonLabel).fontSize = 18f;
((Graphic)deleteButtonLabel).color = Color.white;
CacheSideBar();
}
private static Component GetLayout01(Component browser)
{
object? obj = ((object)browser).GetType().GetField("layout01", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(browser);
return (Component)((obj is Component) ? obj : null);
}
private static void OnDeleteButtonClicked()
{
if (!selectMode)
{
selectMode = true;
SetOverlaysVisible(visible: true);
RefreshDeleteButton();
}
else if (selected.Count > 0)
{
DeleteSelected();
}
else
{
ExitSelectMode();
}
}
private static void ExitSelectMode()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
selectMode = false;
selected.Clear();
SetOverlaysVisible(visible: false);
foreach (GameObject overlay in overlays)
{
if (!((Object)(object)overlay == (Object)null))
{
Transform val = overlay.transform.Find("Checkbox");
Image val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : null);
if ((Object)(object)val2 != (Object)null)
{
((Graphic)val2).color = new Color(0f, 0f, 0f, 0.55f);
}
TextMeshProUGUI componentInChildren = overlay.GetComponentInChildren<TextMeshProUGUI>();
if ((Object)(object)componentInChildren != (Object)null)
{
((TMP_Text)componentInChildren).text = "";
}
}
}
RefreshDeleteButton();
}
private static void SetOverlaysVisible(bool visible)
{
overlays.RemoveAll((GameObject o) => (Object)(object)o == (Object)null);
foreach (GameObject overlay in overlays)
{
overlay.SetActive(visible);
}
}
private static void CacheSideBar()
{
if ((Object)(object)sideBarInstance != (Object)null)
{
return;
}
Assembly assembly = typeof(CustomContentGridBrowser).Assembly;
Type type = assembly.GetType("Landfall.TABS.CustomContentSideBar");
if (!(type == null))
{
Object obj = Object.FindObjectOfType(type);
sideBarInstance = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
if (!((Object)(object)sideBarInstance == (Object)null))
{
deleteBCSCMethod = type.GetMethod("DeleteBattleCreatorSharedCommandsContent", BindingFlags.Instance | BindingFlags.NonPublic);
contentTypeFilterType = assembly.GetType("Landfall.TABS.Workshop.ContentTypeFilter");
}
}
}
private static void RefreshDeleteButton()
{
if (!((Object)(object)deleteButtonLabel == (Object)null))
{
if (!selectMode)
{
((TMP_Text)deleteButtonLabel).text = "SELECT TO DELETE";
((Selectable)deleteButton).interactable = true;
}
else if (selected.Count == 0)
{
((TMP_Text)deleteButtonLabel).text = "CANCEL";
((Selectable)deleteButton).interactable = true;
}
else
{
((TMP_Text)deleteButtonLabel).text = $"DELETE ({selected.Count})";
((Selectable)deleteButton).interactable = true;
}
}
}
private static void DeleteSelected()
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
if (selected.Count == 0)
{
return;
}
CacheSideBar();
if ((Object)(object)sideBarInstance == (Object)null || deleteBCSCMethod == null || contentTypeFilterType == null)
{
Debug.LogError((object)"[TABSUXMod] Could not resolve deletion methods via reflection.");
return;
}
object obj = Enum.ToObject(contentTypeFilterType, 4);
object obj2 = Enum.ToObject(contentTypeFilterType, 32);
foreach (IDatabaseEntity item in selected)
{
UnitBlueprint val = (UnitBlueprint)(object)((item is UnitBlueprint) ? item : null);
if (val != null)
{
string text = CustomContentFilePaths.UnitDirectoryPath + ((object)val.Entity.GUID/*cast due to .constrained prefix*/).ToString();
deleteBCSCMethod.Invoke(sideBarInstance, new object[3] { obj, val, text });
continue;
}
CustomMap val2 = (CustomMap)(object)((item is CustomMap) ? item : null);
if (val2 != null)
{
deleteBCSCMethod.Invoke(sideBarInstance, new object[3] { obj2, val2, val2.FolderPath });
}
}
ExitSelectMode();
CustomContentGridBrowser obj3 = Object.FindObjectOfType<CustomContentGridBrowser>();
if (obj3 != null)
{
obj3.Refresh();
}
}
}
public static class DoubleClickEditUnitPatch
{
private const float DoubleClickWindow = 0.4f;
private static UnitBlueprint lastClickedUnit;
private static float lastClickTime = -1f;
[HarmonyPostfix]
[HarmonyPatch(typeof(CustomContentUnitButton), "OnClick")]
public static void OnUnitButtonClick(CustomContentUnitButton __instance)
{
lastClickedUnit = ((UnitButtonBase)__instance).GetUnit();
lastClickTime = Time.unscaledTime;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FactionCreatorFadeBG), "OnPointerClick")]
public static bool OnFadePointerClickForUnit(FactionCreatorFadeBG __instance)
{
if ((Object)(object)lastClickedUnit == (Object)null)
{
return true;
}
if (Time.unscaledTime - lastClickTime > 0.4f)
{
return true;
}
CustomContentSideBar sidebar = __instance.sidebar;
if ((Object)(object)sidebar == (Object)null || (Object)(object)sidebar.unitParent == (Object)null || !sidebar.unitParent.activeSelf)
{
return true;
}
lastClickedUnit = null;
lastClickTime = -1f;
sidebar.Edit();
return false;
}
}
public static class DoubleClickPlayMapPatch
{
private const float DoubleClickWindow = 0.4f;
private static CustomMap lastClickedMap;
private static float lastClickTime = -1f;
[HarmonyPostfix]
[HarmonyPatch(typeof(CustomContentLevelButton), "OnPointerClick")]
public static void OnLevelButtonPointerClick(CustomContentLevelButton __instance, PointerEventData eventData)
{
lastClickedMap = __instance.customMap;
lastClickTime = Time.unscaledTime;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FactionCreatorFadeBG), "OnPointerClick")]
public static bool OnFadePointerClick(FactionCreatorFadeBG __instance)
{
if ((Object)(object)lastClickedMap == (Object)null)
{
return true;
}
if (Time.unscaledTime - lastClickTime > 0.4f)
{
return true;
}
CustomContentSideBar sidebar = __instance.sidebar;
if ((Object)(object)sidebar == (Object)null || (Object)(object)sidebar.levelParent == (Object)null || !sidebar.levelParent.activeSelf)
{
return true;
}
lastClickedMap = null;
lastClickTime = -1f;
sidebar.Play();
return false;
}
}
[BepInPlugin("joshbaier.tabsuxmod", "Better UX", "2.0.5")]
public class Launcher : BaseUnityPlugin
{
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
Harmony val = new Harmony("joshbaier.tabsuxmod");
val.PatchAll(typeof(BulkDeletePatch));
val.PatchAll(typeof(DoubleClickPlayMapPatch));
val.PatchAll(typeof(DoubleClickEditUnitPatch));
val.PatchAll(typeof(AllUnitBasesPatch));
val.PatchAll(typeof(MiddleClickSelectPatch));
SuppressLaunchInvitePatch.Apply(val);
AutoConfirmLoadModsPatch.Apply(val);
foreach (MethodBase patchedMethod in val.GetPatchedMethods())
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched: " + patchedMethod.DeclaringType?.Name + "." + patchedMethod.Name));
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Better UX loaded.");
}
}
public static class MiddleClickSelectPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(UnitPlacementBrush), "Update")]
public static void OnUpdate(UnitPlacementBrush __instance, GameObject ___m_hoveredUnit)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)___m_hoveredUnit == (Object)null) && Input.GetMouseButtonDown(2))
{
Unit component = ((Component)___m_hoveredUnit.transform.root).GetComponent<Unit>();
if (!((Object)(object)component == (Object)null) && !((Object)(object)component.unitBlueprint == (Object)null))
{
__instance.SetBrushUnit(component.unitBlueprint.Entity.GUID);
}
}
}
}
public static class SuppressLaunchInvitePatch
{
private static bool declinedFirstInvite;
public static void Apply(Harmony harmony)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: 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 — launch invite suppression skipped.");
return;
}
Type type = assembly.GetType("TFBGames.SocialProfileService");
if (type == null)
{
Debug.LogWarning((object)"[TABSUXMod] SocialProfileService not found — launch invite suppression skipped.");
return;
}
MethodInfo method = type.GetMethod("SetState", BindingFlags.Instance | BindingFlags.NonPublic);
if (method == null)
{
Debug.LogWarning((object)"[TABSUXMod] SocialProfileService.SetState not found — launch invite suppression skipped.");
return;
}
MethodInfo method2 = typeof(SuppressLaunchInvitePatch).GetMethod("SetStatePrefix", BindingFlags.Static | BindingFlags.NonPublic);
harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Debug.Log((object)"[TABSUXMod] Launch invite suppression active (first invite of the session will be auto-declined).");
}
private static bool SetStatePrefix(ref object __0)
{
if (declinedFirstInvite)
{
return true;
}
int num = Convert.ToInt32(__0);
if (num == 1 || num == 2)
{
declinedFirstInvite = true;
Debug.Log((object)("[TABSUXMod] Auto-declined spurious launch invite (redirected SetState(" + num + ") to Idle). Later invites are untouched."));
__0 = Enum.ToObject(__0.GetType(), 0);
}
return true;
}
}