using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Lamb.UI; using MMTools; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; using src.UINavigator; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Upgrade Build Tools")] [assembly: AssemblyProduct("Upgrade Build Tools")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace UpgradeBuildTools { [BepInPlugin("com.cotl.betterbuildertools.upgradebuildtools", "Upgrade Build Tools", "0.1.1")] public sealed class UpgradeBuildToolsPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(PlacementRegion), "Upgrade")] private static class PlacementRegionUpgradePatch { private static bool Prefix(PlacementRegion __instance) { if ((Object)(object)Instance == (Object)null) { return true; } if (Instance.ShouldSkipNativeUpgrade(__instance)) { return false; } Instance.ObserveNativeUpgrade(__instance); return true; } } public const string PluginGuid = "com.cotl.betterbuildertools.upgradebuildtools"; public const string PluginName = "Upgrade Build Tools"; public const string PluginVersion = "0.1.1"; private static readonly FieldInfo CurrentUpgradeField = AccessTools.Field(typeof(PlacementRegion), "CurrentStructureToUpgrade"); private static readonly FieldInfo PlacementObjectField = AccessTools.Field(typeof(PlacementRegion), "placementObject"); private static readonly FieldInfo PlacementUiField = AccessTools.Field(typeof(PlacementRegion), "placementUI"); private static readonly FieldInfo TilesField = AccessTools.Field(typeof(PlacementRegion), "Tiles"); private static readonly FieldInfo TilesInitiatedField = AccessTools.Field(typeof(PlacementRegion), "tilesInitiated"); private static readonly FieldInfo InputDelayField = AccessTools.Field(typeof(PlacementRegion), "InputDelay"); private static readonly MethodInfo ClearPrefabsMethod = AccessTools.Method(typeof(PlacementRegion), "ClearPrefabs", (Type[])null, (Type[])null); private static readonly MethodInfo UpgradeMethod = AccessTools.Method(typeof(PlacementRegion), "Upgrade", (Type[])null, (Type[])null); private static readonly MethodInfo GetMousePositionWorldMethod = AccessTools.Method(typeof(PlacementRegion), "GetMousePositionWorld", (Type[])null, (Type[])null); private Harmony _harmony; private KeyCode _upgradeAllKey; private KeyCode _controllerUpgradeAllKey; private Coroutine _batchRoutine; private float _lastHeldUpgradeTime; private int _suppressNativeUpgradeUntilFrame = -1; private bool _invokingCustomUpgrade; private PlacementRegion _activeRegion; private bool _awaitingMouseRelease; private readonly HashSet _handledWhileHeld = new HashSet(); private Indicator _promptOwner; private GameObject _promptRowObject; private GameObject _promptCellObject; private GameObject _promptObject; private MMControlPrompt _promptControl; private TMP_Text _promptText; private bool? _promptWasController; private bool _promptCreationWarningLogged; internal static ManualLogSource Log { get; private set; } internal static UpgradeBuildToolsPlugin Instance { get; private set; } private void Awake() { //IL_0029: 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) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; UpgradeBuildToolsConfig.Bind(((BaseUnityPlugin)this).Config); _upgradeAllKey = ParseKey(UpgradeBuildToolsConfig.UpgradeAllKey.Value, (KeyCode)103); _controllerUpgradeAllKey = ParseKey(UpgradeBuildToolsConfig.ControllerUpgradeAllKey.Value, (KeyCode)333); _harmony = new Harmony("com.cotl.betterbuildertools.upgradebuildtools"); _harmony.PatchAll(typeof(UpgradeBuildToolsPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Upgrade Build Tools 0.1.1 loaded."); } private void OnDestroy() { if (_batchRoutine != null) { ((MonoBehaviour)this).StopCoroutine(_batchRoutine); _batchRoutine = null; } DestroyPromptUi(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; Instance = null; } private void Update() { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) if (!UpgradeBuildToolsConfig.Enabled.Value) { ResetPlacementState(null); return; } PlacementRegion instance = PlacementRegion.Instance; if (!IsUpgradePlacement(instance, out var info)) { ResetPlacementState(instance); return; } if ((Object)(object)_activeRegion != (Object)(object)instance) { _activeRegion = instance; _handledWhileHeld.Clear(); _lastHeldUpgradeTime = 0f; _awaitingMouseRelease = true; } if (_awaitingMouseRelease) { if (Input.GetMouseButton(0)) { return; } _awaitingMouseRelease = false; } if (_batchRoutine == null && UpgradeAllPressed()) { _batchRoutine = ((MonoBehaviour)this).StartCoroutine(UpgradeAllRoutine(instance, info)); } if (_batchRoutine != null || !UpgradeBuildToolsConfig.EnableHoldToUpgrade.Value) { return; } if (!IsPlaceHeld()) { _handledWhileHeld.Clear(); } else { if (!Input.GetMouseButton(0)) { return; } bool mouseButtonDown = Input.GetMouseButtonDown(0); if (mouseButtonDown || !(Time.unscaledTime - _lastHeldUpgradeTime < UpgradeBuildToolsConfig.UpgradeInterval.Value)) { Structure val = FindCursorUpgradeTarget(instance, info.UpgradeFromType); if (!((Object)(object)val == (Object)null) && val.Brain != null && val.Brain.Data != null && !_handledWhileHeld.Contains(val.Brain.Data.ID) && TryUpgradeTarget(instance, val, mouseButtonDown)) { _handledWhileHeld.Add(val.Brain.Data.ID); _lastHeldUpgradeTime = Time.unscaledTime; } } } } private void LateUpdate() { UpdatePrompt(); if (_suppressNativeUpgradeUntilFrame >= 0 && Time.frameCount > _suppressNativeUpgradeUntilFrame) { _suppressNativeUpgradeUntilFrame = -1; } } private void ResetPlacementState(PlacementRegion region) { if (_batchRoutine != null) { ((MonoBehaviour)this).StopCoroutine(_batchRoutine); _batchRoutine = null; } _activeRegion = null; _awaitingMouseRelease = false; _handledWhileHeld.Clear(); _lastHeldUpgradeTime = 0f; } private bool UpgradeAllPressed() { //IL_0001: 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) if (Input.GetKeyDown(_upgradeAllKey)) { return true; } if (UpgradeBuildToolsConfig.EnableControllerUpgradeAll.Value) { return Input.GetKeyDown(_controllerUpgradeAllKey); } return false; } private bool IsPlaceHeld() { if (Input.GetMouseButton(0)) { return true; } try { return InputManager.Gameplay.GetPlaceMoveUpgradeButtonHeld(MonoSingleton.Instance.AllowInputOnlyFromPlayer); } catch { return false; } } private static bool IsUpgradePlacement(PlacementRegion region, out StructuresData info) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 info = null; if ((Object)(object)region == (Object)null || (int)region.CurrentMode != 2) { return false; } try { info = StructuresData.GetInfoByType(region.StructureType, 0); return info != null && info.IsUpgrade && (int)info.UpgradeFromType > 0; } catch { return false; } } private IEnumerator UpgradeAllRoutine(PlacementRegion region, StructuresData upgradeInfo) { _handledWhileHeld.Clear(); Structure currentUpgrade = GetCurrentUpgrade(region); if ((Object)(object)currentUpgrade != (Object)null && (Object)(object)((Component)currentUpgrade).gameObject != (Object)null && !((Component)currentUpgrade).gameObject.activeSelf) { ((Component)currentUpgrade).gameObject.SetActive(true); } List targets = FindEligibleStructures(region, upgradeInfo.UpgradeFromType); if (IsEligibleUpgradeTarget(region, currentUpgrade, upgradeInfo.UpgradeFromType)) { targets.Remove(currentUpgrade); targets.Insert(0, currentUpgrade); } int upgraded = 0; if (targets.Count == 0 || !StructuresData.CanAfford(region.StructureType)) { _batchRoutine = null; yield break; } ((MonoBehaviour)region).StopAllCoroutines(); for (int i = 0; i < targets.Count; i++) { if ((Object)(object)PlacementRegion.Instance != (Object)(object)region) { break; } if ((int)region.CurrentMode != 2) { break; } Structure target = targets[i]; if (!IsEligibleUpgradeTarget(region, target, upgradeInfo.UpgradeFromType) || !StructuresData.CanAfford(region.StructureType)) { break; } if (TryUpgradeTarget(region, target, suppressNativeClick: false)) { upgraded++; } yield return null; } if (upgraded > 0) { Log.LogInfo((object)$"Upgraded {upgraded} {upgradeInfo.UpgradeFromType} structure(s) to {region.StructureType}."); } _handledWhileHeld.Clear(); _batchRoutine = null; FinishUpgradeBatch(region); } private static void FinishUpgradeBatch(PlacementRegion region) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Invalid comparison between Unknown and I4 if ((Object)(object)region == (Object)null) { Time.timeScale = 1f; return; } ((MonoBehaviour)region).StopAllCoroutines(); try { DestroyPlacementTiles(region); ClearPrefabsMethod?.Invoke(region, null); DestroyPrivateObject(region, PlacementObjectField); DestroyPrivateObject(region, PlacementUiField); } catch (Exception ex) { Log.LogWarning((object)("Upgrade batch placement cleanup failed: " + ex.GetBaseException().Message)); } region.CurrentMode = (Mode)0; region.StructureType = (TYPES)0; region.PlacementPosition = Vector3.zero; TilesInitiatedField?.SetValue(region, false); GameManager.overridePlayerPosition = false; if ((Object)(object)DLCLandController.Instance != (Object)null) { DLCLandController.Instance.ShowBridge(); } if ((Object)(object)HUD_Manager.Instance != (Object)null) { HUD_Manager.Instance.Show(1, false); HUD_Manager.Instance.ShowEditMode(false); } if ((Object)(object)WeatherSystemController.Instance != (Object)null) { WeatherSystemController.Instance.ShowWeather(false, true); } if ((Object)(object)LightingManager.Instance != (Object)null) { LightingManager.Instance.inOverride = false; LightingManager.Instance.overrideSettings = null; LightingManager.Instance.transitionDurationMultiplier = 0.2f; LightingManager.Instance.lerpActive = false; LightingManager.Instance.UpdateLighting(true, false, false); LightingManager.Instance.PrepareLightingSettings(false); } if ((Object)(object)GameManager.GetInstance() != (Object)null) { if ((Object)(object)GameManager.GetInstance().CamFollowTarget != (Object)null) { ((Behaviour)GameManager.GetInstance().CamFollowTarget).enabled = true; } GameManager.GetInstance().RemoveAllFromCamera(); GameManager.GetInstance().AddPlayerToCamera(); GameManager.GetInstance().CameraResetTargetZoom(); } if (PlayerFarming.players != null) { for (int i = 0; i < PlayerFarming.players.Count; i++) { PlayerFarming val = PlayerFarming.players[i]; if ((Object)(object)val != (Object)null && (Object)(object)val.state != (Object)null && (int)val.state.CURRENT_STATE == 13) { val.state.CURRENT_STATE = (State)0; } } } if ((Object)(object)AudioManager.Instance != (Object)null) { AudioManager.Instance.SetBuildSnapshotEnabled(false); } Time.timeScale = 1f; if ((Object)(object)MonoSingleton.Instance != (Object)null && (Object)(object)MonoSingleton.Instance.BuildMenuTemplate != (Object)null) { Time.timeScale = 0f; MonoSingleton.Instance.ShowBuildMenu((TYPES)0); } } private static void DestroyPlacementTiles(PlacementRegion region) { if (!(TilesField?.GetValue(region) is List list)) { return; } PlacementTile[] array = list.ToArray(); for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null) { Object.Destroy((Object)(object)((Component)array[i]).gameObject); } } list.Clear(); } private static void DestroyPrivateObject(PlacementRegion region, FieldInfo field) where T : Component { object? obj = field?.GetValue(region); T val = (T)((obj is T) ? obj : null); if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)((Component)val).gameObject); field.SetValue(region, null); } } private bool TryUpgradeTarget(PlacementRegion region, Structure target, bool suppressNativeClick) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (UpgradeMethod == null || CurrentUpgradeField == null || PlacementObjectField == null || (Object)(object)target == (Object)null || target.Brain == null || target.Brain.Data == null) { Log.LogWarning((object)"Native upgrade members were not found; upgrade tools are unavailable for this game build."); return false; } StructuresData infoByType = StructuresData.GetInfoByType(region.StructureType, 0); if (infoByType == null || !IsEligibleUpgradeTarget(region, target, infoByType.UpgradeFromType) || !StructuresData.CanAfford(region.StructureType)) { return false; } Structure currentUpgrade = GetCurrentUpgrade(region); if ((Object)(object)currentUpgrade != (Object)null && (Object)(object)currentUpgrade != (Object)(object)target && (Object)(object)((Component)currentUpgrade).gameObject != (Object)null && !((Component)currentUpgrade).gameObject.activeSelf && !_handledWhileHeld.Contains(GetStructureId(currentUpgrade))) { ((Component)currentUpgrade).gameObject.SetActive(true); } CurrentUpgradeField.SetValue(region, target); ((Component)target).gameObject.SetActive(false); if (InputDelayField != null) { InputDelayField.SetValue(region, 0.2f); } if (suppressNativeClick) { _suppressNativeUpgradeUntilFrame = Time.frameCount + 1; } try { _invokingCustomUpgrade = true; UpgradeMethod.Invoke(region, null); _invokingCustomUpgrade = false; return true; } catch (Exception ex) { _invokingCustomUpgrade = false; if ((Object)(object)((Component)target).gameObject != (Object)null) { ((Component)target).gameObject.SetActive(true); } Log.LogWarning((object)("Upgrade action failed: " + ex.GetBaseException().Message)); return false; } } private Structure FindCursorUpgradeTarget(PlacementRegion region, TYPES fromType) { //IL_001c: 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) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) if (GetMousePositionWorldMethod == null) { return null; } Vector3 val; try { val = (Vector3)GetMousePositionWorldMethod.Invoke(region, null); } catch { return null; } PlacementTile closestTileAtWorldPosition = region.GetClosestTileAtWorldPosition(val, -1f); if ((Object)(object)closestTileAtWorldPosition == (Object)null) { return null; } TileGridTile tileGridTile = region.GetTileGridTile(closestTileAtWorldPosition.GridPosition); if (tileGridTile != null && tileGridTile.ObjectID >= 0) { Structure val2 = FindStructureById(tileGridTile.ObjectID); if (IsEligibleUpgradeTarget(region, val2, fromType)) { return val2; } } Structure[] array = Structure.Structures.ToArray(); foreach (Structure val3 in array) { if (IsEligibleUpgradeTarget(region, val3, fromType)) { Vector2Int gridTilePosition = val3.Brain.Data.GridTilePosition; Vector2Int bounds = val3.Brain.Data.Bounds; if (((Vector2Int)(ref closestTileAtWorldPosition.GridPosition)).x >= ((Vector2Int)(ref gridTilePosition)).x && ((Vector2Int)(ref closestTileAtWorldPosition.GridPosition)).x < ((Vector2Int)(ref gridTilePosition)).x + ((Vector2Int)(ref bounds)).x && ((Vector2Int)(ref closestTileAtWorldPosition.GridPosition)).y >= ((Vector2Int)(ref gridTilePosition)).y && ((Vector2Int)(ref closestTileAtWorldPosition.GridPosition)).y < ((Vector2Int)(ref gridTilePosition)).y + ((Vector2Int)(ref bounds)).y) { return val3; } } } return null; } private static List FindEligibleStructures(PlacementRegion region, TYPES fromType) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) List list = new List(); Structure[] array = Structure.Structures.ToArray(); foreach (Structure val in array) { if (IsEligibleUpgradeTarget(region, val, fromType)) { list.Add(val); } } return list; } private static bool IsEligibleUpgradeTarget(PlacementRegion region, Structure target, TYPES fromType) { //IL_002c: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0077: Invalid comparison between Unknown and I4 //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Invalid comparison between Unknown and I4 //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Invalid comparison between Unknown and I4 if ((Object)(object)target == (Object)null || !((Component)target).gameObject.activeInHierarchy || target.Brain == null || target.Brain.Data == null || target.Type != fromType) { return false; } if ((Object)(object)region != (Object)null && region.StructureInfo != null && target.Structure_Info.Location != region.StructureInfo.Location) { return false; } TYPES type = target.Type; if (target.Structure_Info.ClaimedByPlayer && ((int)type == 2 || (int)type == 40 || (int)type == 41)) { return false; } return true; } private static Structure FindStructureById(int id) { Structure[] array = Structure.Structures.ToArray(); foreach (Structure val in array) { if ((Object)(object)val != (Object)null && val.Brain != null && val.Brain.Data != null && val.Brain.Data.ID == id) { return val; } } return null; } private static Structure GetCurrentUpgrade(PlacementRegion region) { object? obj = CurrentUpgradeField?.GetValue(region); return (Structure)((obj is Structure) ? obj : null); } private static int GetStructureId(Structure structure) { if (!((Object)(object)structure != (Object)null) || structure.Brain == null || structure.Brain.Data == null) { return -1; } return structure.Brain.Data.ID; } internal void ObserveNativeUpgrade(PlacementRegion region) { if (!_invokingCustomUpgrade && !((Object)(object)region == (Object)null) && IsPlaceHeld()) { int structureId = GetStructureId(GetCurrentUpgrade(region)); if (structureId >= 0) { _handledWhileHeld.Add(structureId); } } } internal bool ShouldSkipNativeUpgrade(PlacementRegion region) { if (_invokingCustomUpgrade || (Object)(object)region == (Object)null || _suppressNativeUpgradeUntilFrame < Time.frameCount) { return false; } _suppressNativeUpgradeUntilFrame = -1; return true; } private void UpdatePrompt() { if (!UpgradeBuildToolsConfig.ShowUpgradeAllPrompt.Value || !UpgradeBuildToolsConfig.Enabled.Value || (Object)(object)PlayerFarming.Instance == (Object)null || (Object)(object)PlayerFarming.Instance.indicator == (Object)null) { HidePrompt(); return; } if (!IsUpgradePlacement(PlacementRegion.Instance, out var _)) { HidePrompt(); return; } Indicator indicator = PlayerFarming.Instance.indicator; if (EnsurePrompt(indicator)) { bool flag = IsControllerInput(); _promptControl.playerFarming = PlayerFarming.Instance; _promptControl.PrioritizeMouse = false; _promptText.text = "Upgrade all"; _promptCellObject.SetActive(true); SizePromptRow(_promptRowObject); _promptRowObject.SetActive(true); if (_promptWasController != flag) { _promptWasController = flag; RefreshPromptGlyph(flag); } } } private bool EnsurePrompt(Indicator indicator) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_promptOwner == (Object)(object)indicator && (Object)(object)_promptCellObject != (Object)null && (Object)(object)_promptControl != (Object)null && (Object)(object)_promptText != (Object)null) { return true; } DestroyPromptUi(); if ((Object)(object)indicator == (Object)null || (Object)(object)indicator.FourthControlPrompt == (Object)null || (Object)(object)((Transform)indicator.FourthControlPrompt).parent == (Object)null || (Object)(object)indicator.Fourthtext == (Object)null) { return false; } EnsurePromptRow(indicator); if ((Object)(object)_promptRowObject == (Object)null) { return false; } GameObject val = new GameObject("UpgradeBuildTools_UpgradeAllCell"); ((Transform)val.AddComponent()).SetParent(_promptRowObject.transform, false); LayoutElement obj = val.AddComponent(); obj.preferredWidth = 150f; obj.minWidth = 150f; HorizontalLayoutGroup obj2 = val.AddComponent(); ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f; ((LayoutGroup)obj2).childAlignment = (TextAnchor)4; ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true; GameObject val2 = Object.Instantiate(((Component)indicator.FourthControlPrompt).gameObject, val.transform, false); ((Object)val2).name = "UpgradeBuildTools_UpgradeAllKey"; val2.SetActive(true); val2.transform.localScale = Vector3.one; MMControlPrompt val3 = val2.GetComponent() ?? val2.GetComponentInChildren(true); LayoutElement obj3 = val2.GetComponent() ?? val2.AddComponent(); obj3.preferredWidth = 50f; obj3.minWidth = 42f; obj3.preferredHeight = 40f; TMP_Text val4 = (TMP_Text)(object)Object.Instantiate(indicator.Fourthtext, val.transform, false); ((Object)val4).name = "UpgradeBuildTools_UpgradeAllLabel"; ((Component)val4).gameObject.SetActive(true); val4.transform.localScale = Vector3.one; val4.alignment = (TextAlignmentOptions)4097; val4.enableAutoSizing = true; val4.fontSizeMin = 12f; val4.fontSizeMax = 22f; LayoutElement obj4 = ((Component)val4).GetComponent() ?? ((Component)val4).gameObject.AddComponent(); obj4.preferredWidth = 92f; obj4.minWidth = 92f; Behaviour[] components = ((Component)val4).GetComponents(); foreach (Behaviour val5 in components) { if ((Object)(object)val5 != (Object)null && ((object)val5).GetType().FullName == "I2.Loc.Localize") { val5.enabled = false; } } if ((Object)(object)val3 == (Object)null) { Object.Destroy((Object)(object)val); if (!_promptCreationWarningLogged) { _promptCreationWarningLogged = true; Log.LogWarning((object)"Could not create the standalone Upgrade All control prompt."); } return false; } _promptOwner = indicator; _promptCellObject = val; _promptObject = val2; _promptControl = val3; _promptText = val4; _promptWasController = null; _promptCreationWarningLogged = false; return true; } private void EnsurePromptRow(Indicator indicator) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown Transform promptParent = GetPromptParent(indicator); if (!((Object)(object)promptParent == (Object)null)) { Transform val = promptParent.Find("RemoteBuildCancel_BuilderToolsPromptRow"); if ((Object)(object)val != (Object)null) { ConfigurePromptRow(((Component)val).gameObject); AddVanillaPromptBackground(((Component)val).gameObject, indicator); _promptOwner = indicator; _promptRowObject = ((Component)val).gameObject; } else { GameObject val2 = new GameObject("RemoteBuildCancel_BuilderToolsPromptRow"); ((Transform)val2.AddComponent()).SetParent(promptParent, false); ConfigurePromptRow(val2); AddVanillaPromptBackground(val2, indicator); val2.transform.SetAsLastSibling(); _promptOwner = indicator; _promptRowObject = val2; } } } private static void ConfigurePromptRow(GameObject row) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown RectTransform obj = row.GetComponent() ?? row.AddComponent(); obj.anchorMin = new Vector2(0.5f, 0f); obj.anchorMax = new Vector2(0.5f, 0f); obj.pivot = new Vector2(0f, 0f); obj.anchoredPosition = new Vector2(240f, 112f); obj.sizeDelta = new Vector2(0f, 52f); LayoutElement obj2 = row.GetComponent() ?? row.AddComponent(); obj2.minWidth = 0f; obj2.preferredWidth = 0f; obj2.flexibleWidth = 0f; obj2.minHeight = 52f; obj2.preferredHeight = 52f; obj2.flexibleHeight = 0f; ContentSizeFitter obj3 = row.GetComponent() ?? row.AddComponent(); obj3.horizontalFit = (FitMode)2; obj3.verticalFit = (FitMode)0; ((Behaviour)obj3).enabled = false; HorizontalLayoutGroup obj4 = row.GetComponent() ?? row.AddComponent(); ((LayoutGroup)obj4).padding = new RectOffset(18, 18, 5, 5); ((HorizontalOrVerticalLayoutGroup)obj4).spacing = 18f; ((LayoutGroup)obj4).childAlignment = (TextAnchor)4; ((HorizontalOrVerticalLayoutGroup)obj4).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj4).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandHeight = true; } private static void SizePromptRow(GameObject row) { if ((Object)(object)row == (Object)null) { return; } RectTransform component = row.GetComponent(); HorizontalLayoutGroup component2 = row.GetComponent(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null) { return; } float num = ((LayoutGroup)component2).padding.left + ((LayoutGroup)component2).padding.right; int num2 = 0; for (int i = 0; i < row.transform.childCount; i++) { GameObject gameObject = ((Component)row.transform.GetChild(i)).gameObject; if (gameObject.activeSelf && ((Object)gameObject).name.IndexOf("VanillaPromptBackground", StringComparison.Ordinal) < 0) { LayoutElement component3 = gameObject.GetComponent(); float num3 = (((Object)(object)component3 != (Object)null) ? Mathf.Max(component3.minWidth, component3.preferredWidth) : 0f); if (num3 <= 0f) { num3 = 40f; } if (num2 > 0) { num += ((HorizontalOrVerticalLayoutGroup)component2).spacing; } num += num3; num2++; } } num = Mathf.Max(num, 1f); component.SetSizeWithCurrentAnchors((Axis)0, num); component.SetSizeWithCurrentAnchors((Axis)1, 52f); LayoutElement component4 = row.GetComponent(); if ((Object)(object)component4 != (Object)null) { component4.minWidth = num; component4.preferredWidth = num; } } private static Transform GetPromptParent(Indicator indicator) { Transform val = (((Object)(object)indicator != (Object)null && (Object)(object)indicator.ControlPromptUI != (Object)null) ? indicator.ControlPromptUI.transform : (((Object)(object)indicator != (Object)null) ? ((Component)indicator).transform : null)); if ((Object)(object)val == (Object)null) { return null; } Canvas val2 = ((Component)val).GetComponent() ?? ((Component)val).GetComponentInParent(); if (!((Object)(object)val2 != (Object)null)) { if (!((Object)(object)val.parent != (Object)null)) { return val; } return val.parent; } return ((Component)val2).transform; } private static void AddVanillaPromptBackground(GameObject row, Indicator indicator) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) Image val = (((Object)(object)indicator != (Object)null && (Object)(object)indicator.BG != (Object)null) ? (((Component)indicator.BG).GetComponent() ?? ((Component)indicator.BG).GetComponentInChildren(true)) : null); Image val2 = row.GetComponent() ?? row.AddComponent(); ((Behaviour)val2).enabled = true; ((Graphic)val2).raycastTarget = false; val2.sprite = (((Object)(object)val != (Object)null) ? val.sprite : null); val2.type = (Type)(((Object)(object)val != (Object)null) ? ((int)val.type) : 0); if ((Object)(object)val2.sprite == (Object)null) { val2.sprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f)); val2.type = (Type)0; } ((Graphic)val2).color = new Color(0f, 0f, 0f, 0.88f); ((Graphic)val2).canvasRenderer.SetColor(((Graphic)val2).color); } private void RefreshPromptGlyph(bool controller) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_promptControl == (Object)null)) { SetCustomPromptKey(_promptControl, controller ? ControllerButtonLabel(_controllerUpgradeAllKey) : ((object)Unsafe.As(ref _upgradeAllKey)/*cast due to .constrained prefix*/).ToString()); } } private static void SetCustomPromptKey(MMControlPrompt prompt, string label) { prompt.IgnoreControllerChange = true; object? obj = AccessTools.Field(typeof(MMControlPrompt), "_text")?.GetValue(prompt); TMP_Text val = (TMP_Text)((obj is TMP_Text) ? obj : null); object? obj2 = AccessTools.Field(typeof(MMControlPrompt), "_iconText")?.GetValue(prompt); TMP_Text val2 = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null); object? obj3 = AccessTools.Field(typeof(MMControlPrompt), "_icon")?.GetValue(prompt); Image val3 = (Image)((obj3 is Image) ? obj3 : null); if ((Object)(object)val != (Object)null) { val.text = label; val.fontSize = 20f; val.enableAutoSizing = true; val.fontSizeMin = 8f; val.fontSizeMax = 20f; ((Component)val).gameObject.SetActive(true); } if ((Object)(object)val2 != (Object)null) { ((Component)val2).gameObject.SetActive(false); } if ((Object)(object)val3 != (Object)null) { ((Component)val3).gameObject.SetActive(true); } } private static bool IsControllerInput() { try { return (Object)(object)PlayerFarming.Instance != (Object)null && InputManager.General.InputIsController(PlayerFarming.Instance); } catch { return false; } } private unsafe static string ControllerButtonLabel(KeyCode key) { //IL_0000: 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_0034: Expected I4, but got Unknown return (key - 330) switch { 0 => "A", 1 => "B", 2 => "X", 3 => "Y", 4 => "LB", 5 => "RB", 6 => "Back", 7 => "Start", 8 => "LS", 9 => "RS", _ => ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString().Replace("JoystickButton", "Pad "), }; } private void HidePrompt() { if ((Object)(object)_promptCellObject != (Object)null) { _promptCellObject.SetActive(false); } RefreshPromptRowVisibility(_promptRowObject); } private static void RefreshPromptRowVisibility(GameObject row) { if ((Object)(object)row == (Object)null) { return; } bool active = false; for (int i = 0; i < row.transform.childCount; i++) { GameObject gameObject = ((Component)row.transform.GetChild(i)).gameObject; if (gameObject.activeSelf && ((Object)gameObject).name.IndexOf("VanillaPromptBackground", StringComparison.Ordinal) < 0) { active = true; break; } } SizePromptRow(row); row.SetActive(active); } private void DestroyPromptUi() { if ((Object)(object)_promptCellObject != (Object)null) { Object.Destroy((Object)(object)_promptCellObject); } _promptOwner = null; _promptRowObject = null; _promptCellObject = null; _promptObject = null; _promptControl = null; _promptText = null; _promptWasController = null; } private static KeyCode ParseKey(string raw, KeyCode fallback) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_001b: 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) try { return (KeyCode)Enum.Parse(typeof(KeyCode), raw, ignoreCase: true); } catch { return fallback; } } } internal static class UpgradeBuildToolsConfig { internal static ConfigEntry Enabled; internal static ConfigEntry EnableHoldToUpgrade; internal static ConfigEntry EnableControllerUpgradeAll; internal static ConfigEntry ShowUpgradeAllPrompt; internal static ConfigEntry UpgradeAllKey; internal static ConfigEntry ControllerUpgradeAllKey; internal static ConfigEntry UpgradeInterval; internal static void Bind(ConfigFile config) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown Enabled = config.Bind("General", "Enabled", true, "Enable Upgrade Build Tools."); ShowUpgradeAllPrompt = config.Bind("General", "ShowUpgradeAllPrompt", true, "Show the vanilla-style Upgrade all prompt while an upgrade is selected."); EnableHoldToUpgrade = config.Bind("Behavior", "EnableHoldToUpgrade", true, "Upgrade each new structure under the mouse while the normal place input is held."); UpgradeInterval = config.Bind("Behavior", "UpgradeInterval", 0.16f, new ConfigDescription("Minimum seconds between held upgrades. Matches Path Brush Plus by default.", (AcceptableValueBase)(object)new AcceptableValueRange(0.05f, 1f), Array.Empty())); UpgradeAllKey = config.Bind("Controls", "UpgradeAllKey", "G", "Keyboard key that upgrades every eligible previous-tier structure to the selected upgrade."); EnableControllerUpgradeAll = config.Bind("Controls", "EnableControllerUpgradeAll", true, "Enable the controller shortcut for Upgrade all."); ControllerUpgradeAllKey = config.Bind("Controls", "ControllerUpgradeAllKey", "JoystickButton3", "Controller button used for Upgrade all. JoystickButton3 is Y on the standard layout."); } } }