using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using src.UINavigator; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Drag Place Structures")] [assembly: AssemblyProduct("Drag Place Structures")] [assembly: ComVisible(false)] [assembly: Guid("abefcbd5-7fec-41fa-8ba5-b14640519f34")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyVersion("0.1.1.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 DragPlaceStructures { [BepInPlugin("com.cotl.betterbuildertools.dragplacestructures", "Drag Place Structures", "0.1.4")] public sealed class DragPlaceStructuresPlugin : BaseUnityPlugin { public const string PluginGuid = "com.cotl.betterbuildertools.dragplacestructures"; public const string PluginName = "Drag Place Structures"; public const string PluginVersion = "0.1.4"; private Harmony _harmony; private KeyCode _modifierKey; private KeyCode _repeatKey; private float _lastPlaceTime; private Vector2Int _lastPlaceGrid = new Vector2Int(9999, 9999); private TYPES _lastStructureType; private Mode _lastMode; private int _lastCustomBuildFrame = -1; private bool _invokingBuild; private static readonly MethodInfo BuildMethod = AccessTools.Method(typeof(PlacementRegion), "Build", (Type[])null, (Type[])null); internal static ManualLogSource Log { get; private set; } internal static DragPlaceStructuresPlugin Instance { get; private set; } private void Awake() { //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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; DragPlaceStructuresConfig.Bind(((BaseUnityPlugin)this).Config); _modifierKey = ParseKey(DragPlaceStructuresConfig.ModifierKey.Value, (KeyCode)304); _repeatKey = ParseKey(DragPlaceStructuresConfig.RepeatKey.Value, (KeyCode)323); _harmony = new Harmony("com.cotl.betterbuildertools.dragplacestructures"); _harmony.PatchAll(typeof(DragPlaceStructuresPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Drag Place Structures 0.1.4 loaded."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; Instance = null; } private void Update() { TryDragPlace(PlacementRegion.Instance); } internal void TryDragPlace(PlacementRegion region) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 //IL_0043: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Invalid comparison between Unknown and I4 //IL_0069: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0148: 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_0158: Unknown result type (might be due to invalid IL or missing references) if (!DragPlaceStructuresConfig.Enabled.Value || (Object)(object)region == (Object)null || (Object)(object)PlacementObject.Instance == (Object)null) { ResetPlacementSession(); return; } if ((int)region.CurrentMode != 5 && (int)region.CurrentMode != 1) { ResetPlacementSession(); return; } if (region.StructureType != _lastStructureType || region.CurrentMode != _lastMode) { _lastPlaceGrid = new Vector2Int(9999, 9999); _lastPlaceTime = -1f; _lastStructureType = region.StructureType; _lastMode = region.CurrentMode; } if ((DragPlaceStructuresConfig.RequireModifier.Value && !Input.GetKey(_modifierKey)) || !IsRepeatHeld() || Time.unscaledTime - _lastPlaceTime < DragPlaceStructuresConfig.PlaceInterval.Value) { return; } TYPES structureType = region.StructureType; if (!DragPlaceStructuresConfig.AllowPathsToo.Value && StructureBrain.IsPath(structureType)) { return; } TileGridTile gridTile = GetGridTile(region); if (gridTile != null && !(Vector2Int.Distance(gridTile.Position, _lastPlaceGrid) < DragPlaceStructuresConfig.MinDistance.Value)) { Vector2Int bounds = (((Object)(object)PlacementObject.Instance != (Object)null) ? PlacementObject.Instance.Bounds : Vector2Int.one); if (CanPlaceBounds(region, gridTile.Position, bounds) && InvokeVanillaBuild(region, structureType, gridTile, bounds)) { _lastPlaceGrid = gridTile.Position; _lastPlaceTime = Time.unscaledTime; } } } private void ResetPlacementSession() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0029: Unknown result type (might be due to invalid IL or missing references) _lastPlaceGrid = new Vector2Int(9999, 9999); _lastPlaceTime = -1f; _lastStructureType = (TYPES)0; _lastMode = (Mode)0; _lastCustomBuildFrame = -1; } private bool IsRepeatHeld() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) if ((int)_repeatKey == 323 && Input.GetMouseButton(0)) { return true; } if (Input.GetKey(_repeatKey)) { return true; } try { return InputManager.Gameplay.GetPlaceMoveUpgradeButtonHeld(MonoSingleton.Instance.AllowInputOnlyFromPlayer); } catch { return false; } } private static TileGridTile GetGridTile(PlacementRegion region) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) try { return region.GetClosestTileGridTileAtWorldPosition(region.PlacementPosition); } catch { return null; } } private static bool CanPlaceBounds(PlacementRegion region, Vector2Int origin, Vector2Int bounds) { //IL_0009: 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_0011: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < ((Vector2Int)(ref bounds)).x; i++) { for (int j = 0; j < ((Vector2Int)(ref bounds)).y; j++) { TileGridTile tileGridTile = region.GetTileGridTile(origin + new Vector2Int(i, j)); if (tileGridTile == null || !tileGridTile.CanPlaceStructure) { return false; } } } return true; } private bool InvokeVanillaBuild(PlacementRegion region, TYPES type, TileGridTile tile, Vector2Int bounds) { //IL_0033: 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_004b: 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_0015: Unknown result type (might be due to invalid IL or missing references) //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_00c4: Unknown result type (might be due to invalid IL or missing references) try { _invokingBuild = true; if (BuildMethod == null) { region.PlaceStructureAtWorldPosition(type, tile.WorldPosition, bounds); } else { BuildMethod.Invoke(region, new object[6] { type, tile.WorldPosition, tile.Position, bounds, false, false }); } } catch (Exception ex) { Log.LogWarning((object)("Drag placement build failed: " + ex.GetBaseException().Message)); RepairFailedTile(tile); return false; } finally { _invokingBuild = false; } _lastCustomBuildFrame = Time.frameCount; if (tile == null || tile.ObjectID < 0 || (int)tile.ObjectOnTile == 0) { RepairFailedTile(tile); Log.LogWarning((object)"Drag placement did not commit a structure; restored the touched grid tile."); return false; } return true; } private static void RepairFailedTile(TileGridTile tile) { if (tile != null && tile.ObjectID < 0) { tile.Occupied = false; tile.Obstructed = false; tile.ReservedForWaste = false; tile.IsUpgrade = false; tile.Collapsed = false; } } internal bool ShouldSuppressNativeBuild() { if (!_invokingBuild) { return _lastCustomBuildFrame == Time.frameCount; } return false; } 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; } } } [HarmonyPatch(typeof(PlacementRegion), "Build")] internal static class PlacementRegionBuildPatch { private static bool Prefix() { if (!((Object)(object)DragPlaceStructuresPlugin.Instance == (Object)null)) { return !DragPlaceStructuresPlugin.Instance.ShouldSuppressNativeBuild(); } return true; } } internal static class DragPlaceStructuresConfig { internal static ConfigEntry Enabled; internal static ConfigEntry RequireModifier; internal static ConfigEntry ModifierKey; internal static ConfigEntry RepeatKey; internal static ConfigEntry PlaceInterval; internal static ConfigEntry MinDistance; internal static ConfigEntry AllowPathsToo; internal static void Bind(ConfigFile config) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown Enabled = config.Bind("General", "Enabled", true, "Enable Drag Place Structures."); RequireModifier = config.Bind("Controls", "RequireModifier", false, "Require a modifier while dragging to place repeated structures."); ModifierKey = config.Bind("Controls", "ModifierKey", "LeftShift", "KeyCode held while dragging to place repeated structures."); RepeatKey = config.Bind("Controls", "RepeatKey", "Mouse0", "KeyCode held to place repeated structures. For controller confirm, try JoystickButton0."); PlaceInterval = config.Bind("Behavior", "PlaceInterval", 0.16f, new ConfigDescription("Minimum seconds between drag placements. Matches Path Brush Plus by default.", (AcceptableValueBase)(object)new AcceptableValueRange(0.05f, 1f), Array.Empty())); MinDistance = config.Bind("Behavior", "MinDistance", 0.75f, new ConfigDescription("Minimum world distance from the last drag placement.", (AcceptableValueBase)(object)new AcceptableValueRange(0.1f, 5f), Array.Empty())); AllowPathsToo = config.Bind("Behavior", "AllowPathsToo", false, "Also run for path types. Usually Path Brush Plus should handle paths instead."); } } }