Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BetterBuildingMode v1.1.1
BetterBuildingMode.dll
Decompiled 4 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [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: AssemblyCompany("BetterBuildingMode")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BetterBuildingMode")] [assembly: AssemblyTitle("BetterBuildingMode")] [assembly: AssemblyVersion("1.0.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 BetterBuildingMode { [BepInPlugin("BetterBuildingMode", "Better Building Mode", "1.1.1")] [BepInProcess("valheim.exe")] public sealed class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(Player), "SetControls")] private static class PlayerSetControlsPatch { private static void Prefix(ref Vector3 movedir, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool block, ref bool blockHold, ref bool jump, ref bool crouch, ref bool run, ref bool autoRun) { //IL_0033: 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_004c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Instance == (Object)null)) { if (Instance.IsAreaFillHudMoveModeActive) { attack = false; attackHold = false; } if (Instance.IsFreeCamActive) { Instance.CapturePlayerControls(movedir, jump, crouch, run); movedir = Vector3.zero; jump = false; crouch = false; run = false; autoRun = false; } } } } [HarmonyPatch(typeof(Player), "PlacePiece")] private static class PlayerPlacePiecePatch { private static void Postfix(Player __instance) { if ((Object)(object)Instance != (Object)null) { Instance.OnSuccessfulAreaFillPlacement(__instance); } } } [HarmonyPatch(typeof(Player), "Repair")] private static class PlayerRepairAreaRepairPatch { private static void Prefix(Player __instance, Piece repairPiece) { if ((Object)(object)Instance != (Object)null) { Instance.BeginAreaRepair(__instance, repairPiece); } } private static void Postfix(Player __instance) { if ((Object)(object)Instance != (Object)null) { Instance.CompleteAreaRepair(__instance); } } private static Exception Finalizer(Exception __exception) { if (__exception != null && (Object)(object)Instance != (Object)null) { Instance.ResetAreaRepairTracking("Player.Repair exception: " + __exception.GetBaseException().Message); } return __exception; } } [HarmonyPatch(typeof(WearNTear), "Repair")] private static class WearNTearAreaRepairPatch { private static void Postfix(WearNTear __instance, bool __result) { if ((Object)(object)Instance != (Object)null) { Instance.ObserveAreaRepairWearRepair(__instance, __result); } } } [HarmonyPatch(typeof(GameCamera), "LateUpdate")] private static class GameCameraLateUpdatePatch { private static void Postfix(GameCamera __instance) { if ((Object)(object)Instance != (Object)null) { Instance.ApplyCameraOverride(__instance); } } } public const string PluginGuid = "BetterBuildingMode"; public const string PluginName = "Better Building Mode"; public const string PluginVersion = "1.1.1"; private const float MaxFreeCamDistance = 100f; private const float FreeCamPickupRadius = 5f; private const float FreeCamPickupScanInterval = 0.15f; private const float AreaRepairRadius = 50f; private float nextFreeCamPickupScanTime; private static readonly MethodInfo ItemDropInteractMethod = ResolveItemDropInteractMethod(); internal static Plugin Instance; private ConfigEntry<float> CameraMoveSpeed; private ConfigEntry<float> VerticalMoveSpeed; private ConfigEntry<float> FastMoveMultiplier; private ConfigEntry<KeyboardShortcut> ForwardKey; private ConfigEntry<KeyboardShortcut> BackwardKey; private ConfigEntry<KeyboardShortcut> LeftKey; private ConfigEntry<KeyboardShortcut> RightKey; private ConfigEntry<KeyboardShortcut> UpKey; private ConfigEntry<KeyboardShortcut> DownKey; private ConfigEntry<KeyboardShortcut> FastMoveKey; private ConfigEntry<KeyboardShortcut> AreaFillToggleKey; private ConfigEntry<KeyboardShortcut> AreaFillCancelKey; private ConfigEntry<KeyboardShortcut> AreaFillConfirmKey; private ConfigEntry<KeyboardShortcut> AreaFillMoveHudKey; private ConfigEntry<KeyboardShortcut> AreaFillPoleSpacingKey; private ConfigEntry<float> AreaFillHudPositionX; private ConfigEntry<float> AreaFillHudPositionY; private bool areaFillEnabled; private bool areaFillHasPointA; private Vector3 areaFillPointA; private Quaternion areaFillReferenceRotation; private Vector3 areaFillReferenceSize; private string areaFillReferencePieceName = ""; private int areaFillAxisA = -1; private int areaFillAxisB = -1; private float areaFillSpacingA; private float areaFillSpacingB; private bool areaFillReferencePoleLike; private bool areaFillReferenceLinear; private Vector3 areaFillLinearLocalVector; private float areaFillLinearPreviewWidth; private Vector3 areaFillLinearPreviewCenterOffsetLocal; private GameObject areaFillPreviewRoot; private const int MaxAreaFillPreviewPositions = 500; private readonly List<Vector3> areaFillPendingPositions = new List<Vector3>(); private Coroutine areaFillPlacementCoroutine; private bool areaFillInternalPlacement; private bool areaFillShowSummary; private string areaFillSummaryText = ""; private GameObject areaFillHudRoot; private Component areaFillHudText; private Component areaFillHudRect; private Component areaFillHudCanvas; private float areaFillHudRefreshTimer; private bool areaFillHudDragging; private Vector3 areaFillHudLastMousePosition; private int areaFillPoleSpacingMode; private static MethodInfo InputGetMouseButtonMethod; private static PropertyInfo InputMousePositionProperty; private static readonly MethodInfo PlayerPlacePieceMethod = ResolvePlayerPlacePieceMethod(); private static readonly MethodInfo PlayerHaveRequirementsPieceMethod = ResolvePlayerHaveRequirementsPieceMethod(); private static readonly MethodInfo PlayerConsumeResourcesMethod = ResolvePlayerConsumeResourcesMethod(); private static readonly FieldInfo PieceSnapPointsField = typeof(Piece).GetField("m_snapPoints", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo PlacementGhostField = typeof(Player).GetField("m_placementGhost", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private bool freeCamActive; private bool wasBuildToolEquipped; private bool wasBuildStationInRange; private Vector3 freeCamPosition; private Vector3 capturedMoveDir; private bool capturedJump; private bool capturedCrouch; private bool capturedRun; private Harmony harmony; private float originalMaxPlaceDistance; private bool placementRangeOverridden; private Piece areaRepairDirectTarget; private WearNTear areaRepairDirectWear; private bool areaRepairDirectRepairSucceeded; private bool areaRepairPlayerRepairInProgress; private WearNTear areaRepairSuccessfulWear; private bool areaRepairBatchInProgress; private static readonly FieldInfo MaxPlaceDistanceField = typeof(Player).GetField("m_maxPlaceDistance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static MethodInfo InputGetKeyMethod; private static bool inputReflectionResolved; private static readonly FieldInfo StationRangeField = typeof(CraftingStation).GetField("m_rangeBuild", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal bool IsAreaFillHudMoveModeActive { get { //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)areaFillHudRoot != (Object)null && AreaFillMoveHudKey != null) { return IsShortcutHeld(AreaFillMoveHudKey.Value); } return false; } } internal bool IsFreeCamActive => freeCamActive; private static MethodInfo ResolveItemDropInteractMethod() { MethodInfo[] methods = typeof(ItemDrop).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "Interact")) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 3 && parameters[0].ParameterType.IsAssignableFrom(typeof(Player)) && parameters[1].ParameterType == typeof(bool) && parameters[2].ParameterType == typeof(bool)) { return methodInfo; } } } return null; } private static MethodInfo ResolvePlayerPlacePieceMethod() { MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "PlacePiece")) { ParameterInfo[] parameters = methodInfo.GetParameters(); if ((parameters.Length == 4 || parameters.Length == 5) && parameters[0].ParameterType == typeof(Piece) && parameters[1].ParameterType == typeof(Vector3) && parameters[2].ParameterType == typeof(Quaternion) && parameters[3].ParameterType == typeof(bool) && (parameters.Length == 4 || parameters[4].ParameterType == typeof(bool))) { return methodInfo; } } } return null; } private static MethodInfo ResolvePlayerHaveRequirementsPieceMethod() { MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "HaveRequirements") && !(methodInfo.ReturnType != typeof(bool))) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 2 && parameters[0].ParameterType == typeof(Piece) && parameters[1].ParameterType.IsEnum) { return methodInfo; } } } return null; } private static MethodInfo ResolvePlayerConsumeResourcesMethod() { MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "ConsumeResources")) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 4 && parameters[0].ParameterType == typeof(Requirement[]) && parameters[1].ParameterType == typeof(int) && parameters[2].ParameterType == typeof(int) && parameters[3].ParameterType == typeof(int)) { return methodInfo; } } } return null; } private bool IsAreaFillFreeBuild(Player player, Piece piece) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[2] { "m_noPlacementCost", "m_noCostCheat" }; foreach (string name in array) { FieldInfo field = typeof(Player).GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool) && (bool)field.GetValue(player)) { return true; } } if ((Object)(object)ZoneSystem.instance != (Object)null) { return ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey()); } return false; } private bool HasAreaFillBuildRequirements(Player player, Piece piece) { if (PlayerHaveRequirementsPieceMethod == null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Area Fill] Player.HaveRequirements(Piece, RequirementMode) could not be resolved; nothing was placed."); return false; } object obj = Enum.ToObject(PlayerHaveRequirementsPieceMethod.GetParameters()[1].ParameterType, 0); return (bool)PlayerHaveRequirementsPieceMethod.Invoke(player, new object[2] { piece, obj }); } private bool ConsumeAreaFillBuildResources(Player player, Piece piece) { if (PlayerConsumeResourcesMethod == null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Area Fill] Player.ConsumeResources(Requirement[], int, int, int) could not be resolved."); return false; } PlayerConsumeResourcesMethod.Invoke(player, new object[4] { piece.m_resources, 0, -1, 1 }); return true; } private void Awake() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown //IL_00d8: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: 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_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033f: Expected O, but got Unknown Instance = this; CameraMoveSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CameraMoveSpeed", 10f, new ConfigDescription("Normal free-camera movement speed in metres per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>())); VerticalMoveSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "VerticalMoveSpeed", 10f, new ConfigDescription("Free-camera rise/descend speed in metres per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>())); FastMoveMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FastMoveMultiplier", 3f, new ConfigDescription("Movement-speed multiplier while holding Left Shift.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); ForwardKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "1. Forward", new KeyboardShortcut((KeyCode)119, Array.Empty<KeyCode>()), "Free-camera forward key."); BackwardKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "2. Backward", new KeyboardShortcut((KeyCode)115, Array.Empty<KeyCode>()), "Free-camera backward key."); LeftKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "3. Left", new KeyboardShortcut((KeyCode)97, Array.Empty<KeyCode>()), "Free-camera left key."); RightKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "4. Right", new KeyboardShortcut((KeyCode)100, Array.Empty<KeyCode>()), "Free-camera right key."); UpKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "5. Up", new KeyboardShortcut((KeyCode)32, Array.Empty<KeyCode>()), "Free-camera rise key."); DownKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "6. Down", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), "Free-camera descend key."); FastMoveKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "7. FastMove", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Free-camera speed modifier."); AreaFillToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Area Fill", "1. ToggleAreaFill", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Enable or disable placement-based Area Fill mode."); AreaFillCancelKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Area Fill", "2. Cancel", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Clear the current Area Fill selection and preview."); AreaFillConfirmKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Area Fill", "3. ConfirmFill", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Confirm the current Area Fill preview and build all missing positions."); AreaFillMoveHudKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Area Fill", "4. MoveHud", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Hold this key to unlock the Area Fill HUD. While held, normal building placement is blocked; left-click and drag the HUD to reposition it."); AreaFillPoleSpacingKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Area Fill", "5. PoleSpacing", new KeyboardShortcut((KeyCode)292, Array.Empty<KeyCode>()), "Toggle compatible vertical pole pieces between normal adjacent Area Fill spacing and fixed 2 metre horizontal spacing."); AreaFillHudPositionX = ((BaseUnityPlugin)this).Config.Bind<float>("Area Fill HUD", "PositionX", 0f, "Saved horizontal Area Fill HUD position. Updated automatically when the HUD is dragged."); AreaFillHudPositionY = ((BaseUnityPlugin)this).Config.Bind<float>("Area Fill HUD", "PositionY", 105f, "Saved vertical Area Fill HUD position. Updated automatically when the HUD is dragged."); harmony = new Harmony("BetterBuildingMode"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Building Mode 1.1.1 loaded."); } private void Update() { Player localPlayer = Player.m_localPlayer; GameCamera instance = GameCamera.instance; if ((Object)(object)localPlayer == (Object)null || (Object)(object)instance == (Object)null) { if (freeCamActive) { ExitFreeCam(); } wasBuildToolEquipped = false; wasBuildStationInRange = false; return; } UpdateAreaFill(localPlayer); UpdateAreaFillHud(localPlayer); UpdateAreaFillHudDrag(); bool flag = HasBuildToolEquipped(localPlayer); bool flag2 = HasValidBuildStationInRange(localPlayer); if (freeCamActive) { if (!flag || !flag2) { ExitFreeCam(); } else { UpdateFreeCamPosition(localPlayer, instance); UpdateFreeCamItemPickup(localPlayer); } } else if (flag && !wasBuildToolEquipped && wasBuildStationInRange && flag2) { EnterFreeCam(instance); UpdateFreeCamPosition(localPlayer, instance); } wasBuildToolEquipped = flag; wasBuildStationInRange = flag2; } private void UpdateFreeCamItemPickup(Player player) { //IL_006f: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) if (!freeCamActive || (Object)(object)player == (Object)null || Time.unscaledTime < nextFreeCamPickupScanTime) { return; } nextFreeCamPickupScanTime = Time.unscaledTime + 0.15f; if (ItemDropInteractMethod == null) { return; } ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>(); float num = 25f; ItemDrop[] array2 = array; foreach (ItemDrop val in array2) { if ((Object)(object)val == (Object)null || !((Behaviour)val).isActiveAndEnabled) { continue; } Vector3 val2 = ((Component)val).transform.position - freeCamPosition; if (!(((Vector3)(ref val2)).sqrMagnitude > num)) { try { ItemDropInteractMethod.Invoke(val, new object[3] { player, false, false }); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Build Free Cam] Item pickup failed for " + ((Object)val).name + ": " + ex.GetBaseException().Message)); } } } } private void EnterFreeCam(GameCamera camera) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) freeCamActive = true; freeCamPosition = ((Component)camera).transform.position; nextFreeCamPickupScanTime = 0f; EnableCameraBasedPlacementRange(Player.m_localPlayer); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Build Free Cam] ENTER"); } private void ExitFreeCam() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) RestorePlacementRange(Player.m_localPlayer); ClearAreaFillPreview(); DestroyAreaFillHud(); freeCamActive = false; capturedMoveDir = Vector3.zero; capturedJump = false; capturedCrouch = false; capturedRun = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Build Free Cam] EXIT"); } private void UpdateFreeCamPosition(Player player, GameCamera camera) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0050: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) Vector3 forward = ((Component)camera).transform.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f) { forward = ((Component)player).transform.forward; } forward.y = 0f; ((Vector3)(ref forward)).Normalize(); Vector3 val = new Vector3(forward.z, 0f, 0f - forward.x) * capturedMoveDir.x + forward * capturedMoveDir.z; if (((Vector3)(ref val)).sqrMagnitude > 1f) { ((Vector3)(ref val)).Normalize(); } float num = 0f; if (IsShortcutHeld(UpKey.Value)) { num += 1f; } if (IsShortcutHeld(DownKey.Value)) { num -= 1f; } float num2 = (capturedRun ? FastMoveMultiplier.Value : 1f); Vector3 val2 = freeCamPosition; val2 += val * (CameraMoveSpeed.Value * num2 * Time.unscaledDeltaTime); val2 += Vector3.up * (num * VerticalMoveSpeed.Value * num2 * Time.unscaledDeltaTime); Vector3 val3 = val2 - ((Component)player).transform.position; if (((Vector3)(ref val3)).sqrMagnitude > 10000f) { val2 = ((Component)player).transform.position + ((Vector3)(ref val3)).normalized * 100f; } freeCamPosition = val2; } private void UpdateAreaFill(Player player) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = AreaFillToggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { if (areaFillPlacementCoroutine != null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] Area Fill is currently building; toggle ignored until it finishes."); return; } areaFillEnabled = !areaFillEnabled; ClearAreaFillSelection(); ClearAreaFillPreview(); ClearAreaFillPendingPositions(); ((BaseUnityPlugin)this).Logger.LogInfo((object)(areaFillEnabled ? "[Area Fill] ENABLED - place one piece for Point A, then place the same piece at Point B." : "[Area Fill] DISABLED")); } if (!areaFillEnabled) { return; } value = AreaFillPoleSpacingKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { areaFillPoleSpacingMode = (areaFillPoleSpacingMode + 1) % 3; string text = ((areaFillPoleSpacingMode == 1) ? "2m" : ((areaFillPoleSpacingMode == 2) ? "4m" : "Normal")); ShowAreaFillTransientMessage(player, "Area Fill Pole Spacing: " + text); ((BaseUnityPlugin)this).Logger.LogInfo((object)("[Area Fill] Pole spacing mode: " + text + ".")); if (areaFillHasPointA) { ClearAreaFillSelection(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] Active Point A cleared because pole spacing mode changed."); } } value = AreaFillCancelKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { if (areaFillPlacementCoroutine != null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] Area Fill is currently building; cancel ignored until it finishes."); return; } ClearAreaFillSelection(); ClearAreaFillPreview(); ClearAreaFillPendingPositions(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] Selection and preview cleared."); } value = AreaFillConfirmKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { TryStartAreaFill(player); } } private void ShowAreaFillTransientMessage(Player player, string text) { if ((Object)(object)player == (Object)null || string.IsNullOrEmpty(text)) { return; } try { MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != "Message") { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length < 2 || !parameters[0].ParameterType.IsEnum || parameters[1].ParameterType != typeof(string)) { continue; } object[] array = new object[parameters.Length]; array[0] = Enum.ToObject(parameters[0].ParameterType, 1); array[1] = text; for (int j = 2; j < parameters.Length; j++) { if (parameters[j].HasDefaultValue) { array[j] = parameters[j].DefaultValue; } else if (parameters[j].ParameterType == typeof(int)) { array[j] = 0; } else if (parameters[j].ParameterType == typeof(bool)) { array[j] = false; } else { array[j] = null; } } methodInfo.Invoke(player, array); break; } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Area Fill] Could not show pole-spacing indicator: " + ex.Message)); } } internal void OnSuccessfulAreaFillPlacement(Player player) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0203: 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_0533: Unknown result type (might be due to invalid IL or missing references) //IL_0543: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_024c: 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_0255: 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_025c: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) if (!areaFillEnabled || (Object)(object)player == (Object)null || areaFillInternalPlacement) { return; } GameObject placementGhost = GetPlacementGhost(player); if ((Object)(object)placementGhost == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Area Fill] A piece was placed, but the placement ghost could not be read."); return; } string text = CleanCloneName(((Object)placementGhost).name); Vector3 position = placementGhost.transform.position; Quaternion rotation = placementGhost.transform.rotation; Vector3 ghostWorldSize = GetGhostWorldSize(placementGhost); if (!areaFillHasPointA) { ClearAreaFillPreview(); ClearAreaFillPendingPositions(); areaFillHasPointA = true; areaFillPointA = position; areaFillReferenceRotation = rotation; areaFillReferenceSize = ghostWorldSize; areaFillReferencePieceName = text; areaFillLinearPreviewCenterOffsetLocal = GetGhostRendererCenterOffsetLocal(placementGhost); ResolveAreaFillGrid(placementGhost); ((BaseUnityPlugin)this).Logger.LogInfo((object)("[Area Fill] Point A placed: piece=" + areaFillReferencePieceName + ", pos=" + FormatVector(areaFillPointA) + ", rot=" + FormatVector(((Quaternion)(ref areaFillReferenceRotation)).eulerAngles) + ", gridAxes=" + AxisName(areaFillAxisA) + "/" + AxisName(areaFillAxisB) + ", " + $"spacing={areaFillSpacingA:0.###}/{areaFillSpacingB:0.###}. " + "Place the same piece at the opposite corner for Point B.")); return; } if (!string.Equals(text, areaFillReferencePieceName, StringComparison.OrdinalIgnoreCase)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Area Fill] Point B rejected: expected " + areaFillReferencePieceName + ", but placed " + text + ". Point A is still active.")); return; } Vector3 val = Quaternion.Inverse(areaFillReferenceRotation) * (position - areaFillPointA); int num4; int num5; int num6; float num7; float num8; if (areaFillReferenceLinear) { float sqrMagnitude = ((Vector3)(ref areaFillLinearLocalVector)).sqrMagnitude; float num = ((sqrMagnitude > 0.0001f) ? (Vector3.Dot(val, areaFillLinearLocalVector) / sqrMagnitude) : 0f); int num2 = Mathf.Max(0, Mathf.RoundToInt(Mathf.Abs(num))); float num3 = ((num < 0f) ? (-1f) : 1f); Vector3 val2 = areaFillLinearLocalVector * ((float)num2 * num3); Vector3 val3 = val - val2; num4 = num2 + 1; num5 = 1; num6 = num4; num7 = num; num8 = 0f; float magnitude = ((Vector3)(ref val3)).magnitude; float num9 = 0f; float magnitude2 = ((Vector3)(ref val3)).magnitude; ((BaseUnityPlugin)this).Logger.LogInfo((object)("[Area Fill] Point B placed (linear): piece=" + text + ", A=" + FormatVector(areaFillPointA) + ", B=" + FormatVector(position) + ", " + $"localDelta={FormatVector(val)}, linearVector={FormatVector(areaFillLinearLocalVector)}, intervals={num2}, line={num4} positions, " + $"vectorError={magnitude:0.###}.")); } else { num7 = GetAxis(val, areaFillAxisA); num8 = GetAxis(val, areaFillAxisB); float magnitude2 = GetAxis(val, RemainingAxis(areaFillAxisA, areaFillAxisB)); num4 = Mathf.Max(1, Mathf.RoundToInt(Mathf.Abs(num7) / areaFillSpacingA) + 1); num5 = Mathf.Max(1, Mathf.RoundToInt(Mathf.Abs(num8) / areaFillSpacingB) + 1); num6 = num4 * num5; float magnitude = Mathf.Abs(Mathf.Abs(num7) - (float)(num4 - 1) * areaFillSpacingA); float num9 = Mathf.Abs(Mathf.Abs(num8) - (float)(num5 - 1) * areaFillSpacingB); ((BaseUnityPlugin)this).Logger.LogInfo((object)("[Area Fill] Point B placed: piece=" + text + ", A=" + FormatVector(areaFillPointA) + ", B=" + FormatVector(position) + ", " + $"localDelta={FormatVector(val)}, grid={num4} x {num5} = {num6} positions, " + $"snapError={magnitude:0.###}/{num9:0.###}, offPlane={magnitude2:0.###}.")); } if (num6 > 500) { ClearAreaFillPreview(); ClearAreaFillPendingPositions(); areaFillHasPointA = false; ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Fill rejected: {num6} total grid positions exceeds the safety limit of {500}. The two endpoint pieces remain placed."); return; } if (areaFillReferenceLinear) { PrepareLinearAreaFillPositions(num4, num7); } else { PrepareAreaFillPositions(num4, num5, num7, num8); } CreateAreaFillWirePreview(num6); areaFillHasPointA = false; UpdateAreaFillSummary(player); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Preview ready: {areaFillPendingPositions.Count} missing positions. Press {AreaFillConfirmKey.Value} to build, or {AreaFillCancelKey.Value} to cancel."); } private void UpdateAreaFillSummary(Player player) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) areaFillShowSummary = areaFillPendingPositions.Count > 0; if (!areaFillShowSummary) { areaFillSummaryText = ""; return; } Piece val = (((Object)(object)player != (Object)null) ? player.GetSelectedPiece() : null); if ((Object)(object)val == (Object)null || val.m_resources == null || val.m_resources.Length == 0) { areaFillSummaryText = $"Area Fill: {areaFillPendingPositions.Count} pieces\nPress {AreaFillConfirmKey.Value} to fill · {AreaFillCancelKey.Value} to cancel"; EnsureAreaFillHud(); SetAreaFillHudText(areaFillSummaryText); return; } List<string> list = new List<string>(); Requirement[] resources = val.m_resources; foreach (Requirement val2 in resources) { if (val2 != null && !((Object)(object)val2.m_resItem == (Object)null) && val2.m_amount > 0) { int num = val2.m_amount * areaFillPendingPositions.Count; string arg = LocalizeAreaFillResourceName(val2.m_resItem.m_itemData.m_shared.m_name); int inventoryItemCount = GetInventoryItemCount(player, val2.m_resItem.m_itemData.m_shared.m_name); list.Add($"{num} {arg} required ({inventoryItemCount} available)"); } } string text = ((list.Count > 0) ? string.Join(", ", list.ToArray()) : "No materials required"); areaFillSummaryText = $"Area Fill: {areaFillPendingPositions.Count} pieces — {text}\nPress {AreaFillConfirmKey.Value} to fill · {AreaFillCancelKey.Value} to cancel"; EnsureAreaFillHud(); SetAreaFillHudText(areaFillSummaryText); } private string LocalizeAreaFillResourceName(string sharedName) { try { Type type = AccessTools.TypeByName("Localization"); if (type != null) { FieldInfo field = type.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); object obj = ((field != null) ? field.GetValue(null) : null); MethodInfo method = type.GetMethod("Localize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null); if (obj != null && method != null) { string text = method.Invoke(obj, new object[1] { sharedName }) as string; if (!string.IsNullOrEmpty(text)) { return text; } } } } catch { } string text2 = sharedName ?? "Material"; if (text2.StartsWith("$item_", StringComparison.OrdinalIgnoreCase)) { text2 = text2.Substring(6); } else if (text2.StartsWith("$", StringComparison.Ordinal)) { text2 = text2.Substring(1); } if (text2.Length <= 0) { return "Material"; } return char.ToUpperInvariant(text2[0]) + text2.Substring(1); } private void UpdateAreaFillHud(Player player) { if (!areaFillEnabled || (Object)(object)areaFillPreviewRoot == (Object)null || areaFillPendingPositions.Count == 0) { DestroyAreaFillHud(); return; } areaFillHudRefreshTimer -= Time.unscaledDeltaTime; if (areaFillHudRefreshTimer <= 0f) { areaFillHudRefreshTimer = 0.25f; UpdateAreaFillSummary(player); } } private void EnsureAreaFillHud() { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)areaFillHudRoot != (Object)null && (Object)(object)areaFillHudText != (Object)null) { return; } try { Type type = AccessTools.TypeByName("UnityEngine.Canvas"); Type type2 = AccessTools.TypeByName("UnityEngine.UI.CanvasScaler"); Type type3 = AccessTools.TypeByName("UnityEngine.UI.Text"); Type type4 = AccessTools.TypeByName("UnityEngine.RectTransform"); if (type == null || type3 == null || type4 == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Area Fill] Static HUD UI types are unavailable; material summary will remain in the log only."); return; } areaFillHudRoot = new GameObject("BetterBuildingMode_AreaFillHud"); Component target = (areaFillHudCanvas = areaFillHudRoot.AddComponent(type)); SetEnumProperty(target, "renderMode", "ScreenSpaceOverlay"); SetProperty(target, "sortingOrder", 1000); if (type2 != null) { Component target2 = areaFillHudRoot.AddComponent(type2); SetEnumProperty(target2, "uiScaleMode", "ScaleWithScreenSize"); SetProperty(target2, "referenceResolution", (object)new Vector2(1920f, 1080f)); SetProperty(target2, "matchWidthOrHeight", 0.5f); } GameObject val = new GameObject("AreaFillStatus", new Type[1] { type4 }); val.transform.SetParent(areaFillHudRoot.transform, false); areaFillHudText = val.AddComponent(type3); Component target3 = (areaFillHudRect = val.GetComponent(type4)); SetProperty(target3, "anchorMin", (object)new Vector2(0.5f, 0.5f)); SetProperty(target3, "anchorMax", (object)new Vector2(0.5f, 0.5f)); SetProperty(target3, "pivot", (object)new Vector2(0.5f, 0.5f)); SetProperty(target3, "anchoredPosition", (object)new Vector2(AreaFillHudPositionX.Value, AreaFillHudPositionY.Value)); SetProperty(target3, "sizeDelta", (object)new Vector2(760f, 70f)); SetProperty(areaFillHudText, "fontSize", 18); SetProperty(areaFillHudText, "color", Color.white); SetEnumProperty(areaFillHudText, "alignment", "MiddleCenter"); SetEnumProperty(areaFillHudText, "horizontalOverflow", "Overflow"); SetEnumProperty(areaFillHudText, "verticalOverflow", "Overflow"); SetProperty(areaFillHudText, "supportRichText", true); object obj = FindLoadedUiFont(); if (obj != null) { SetProperty(areaFillHudText, "font", obj); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Area Fill] Could not create static HUD: " + ex.Message)); DestroyAreaFillHud(); } } private object FindLoadedUiFont() { try { Type type = AccessTools.TypeByName("UnityEngine.Font"); if (type == null) { return null; } MethodInfo method = typeof(Resources).GetMethod("FindObjectsOfTypeAll", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(Type) }, null); if (method == null) { return null; } if (method.Invoke(null, new object[1] { type }) is Array { Length: >0 } array) { return array.GetValue(0); } MethodInfo method2 = type.GetMethod("CreateDynamicFontFromOSFont", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(string), typeof(int) }, null); return (method2 != null) ? method2.Invoke(null, new object[2] { "Arial", 18 }) : null; } catch { return null; } } private void UpdateAreaFillHudDrag() { //IL_0032: 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) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)areaFillHudRect == (Object)null || (Object)(object)areaFillHudRoot == (Object)null || AreaFillMoveHudKey == null) { areaFillHudDragging = false; } else if (!IsShortcutHeld(AreaFillMoveHudKey.Value)) { areaFillHudDragging = false; } else { if (!TryGetMouseState(out var position, out var leftHeld)) { return; } if (!leftHeld) { areaFillHudDragging = false; return; } if (!areaFillHudDragging) { areaFillHudDragging = true; areaFillHudLastMousePosition = position; return; } Vector3 val = position - areaFillHudLastMousePosition; areaFillHudLastMousePosition = position; float num = 1f; if ((Object)(object)areaFillHudCanvas != (Object)null) { PropertyInfo property = ((object)areaFillHudCanvas).GetType().GetProperty("scaleFactor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { object value = property.GetValue(areaFillHudCanvas, null); if (value is float && (float)value > 0.001f) { num = (float)value; } } } PropertyInfo property2 = ((object)areaFillHudRect).GetType().GetProperty("anchoredPosition", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(property2 == null)) { Vector2 val2 = (Vector2)property2.GetValue(areaFillHudRect, null) + new Vector2(val.x / num, val.y / num); property2.SetValue(areaFillHudRect, val2, null); AreaFillHudPositionX.Value = val2.x; AreaFillHudPositionY.Value = val2.y; } } } private static bool TryGetMouseState(out Vector3 position, out bool leftHeld) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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) position = Vector3.zero; leftHeld = false; try { ResolveInputReflection(); if (InputMousePositionProperty == null || InputGetMouseButtonMethod == null) { return false; } position = (Vector3)InputMousePositionProperty.GetValue(null, null); leftHeld = (bool)InputGetMouseButtonMethod.Invoke(null, new object[1] { 0 }); return true; } catch { return false; } } private static void ResolveInputReflection() { if (inputReflectionResolved && InputGetMouseButtonMethod != null && InputMousePositionProperty != null) { return; } inputReflectionResolved = true; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { Type type = assemblies[i].GetType("UnityEngine.Input", throwOnError: false); if (!(type == null)) { if (InputGetKeyMethod == null) { InputGetKeyMethod = type.GetMethod("GetKey", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(KeyCode) }, null); } InputGetMouseButtonMethod = type.GetMethod("GetMouseButton", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(int) }, null); InputMousePositionProperty = type.GetProperty("mousePosition", BindingFlags.Static | BindingFlags.Public); break; } } } private void SetAreaFillHudText(string text) { if (!((Object)(object)areaFillHudText == (Object)null)) { SetProperty(areaFillHudText, "text", text); } } private static void SetProperty(object target, string propertyName, object value) { if (target != null) { PropertyInfo property = target.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanWrite) { property.SetValue(target, value, null); } } } private static void SetEnumProperty(object target, string propertyName, string enumName) { if (target != null) { PropertyInfo property = target.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanWrite && property.PropertyType.IsEnum) { property.SetValue(target, Enum.Parse(property.PropertyType, enumName), null); } } } private void DestroyAreaFillHud() { if ((Object)(object)areaFillHudRoot != (Object)null) { Object.Destroy((Object)(object)areaFillHudRoot); } areaFillHudRoot = null; areaFillHudText = null; areaFillHudRect = null; areaFillHudCanvas = null; areaFillHudDragging = false; areaFillHudRefreshTimer = 0f; } private int GetInventoryItemCount(Player player, string sharedName) { if ((Object)(object)player == (Object)null) { return 0; } object inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return 0; } MethodInfo[] methods = inventory.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != "CountItems" || methodInfo.ReturnType != typeof(int)) { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 0 || parameters[0].ParameterType != typeof(string)) { continue; } object[] array = new object[parameters.Length]; array[0] = sharedName; bool flag = true; for (int j = 1; j < parameters.Length; j++) { if (parameters[j].HasDefaultValue) { array[j] = parameters[j].DefaultValue; continue; } if (parameters[j].ParameterType == typeof(int)) { array[j] = -1; continue; } if (parameters[j].ParameterType == typeof(bool)) { array[j] = true; continue; } flag = false; break; } if (flag) { try { return (int)methodInfo.Invoke(inventory, array); } catch { } } } return 0; } private void PrepareLinearAreaFillPositions(int count, float alongDelta) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_006d: 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) ClearAreaFillPendingPositions(); float num = ((alongDelta < 0f) ? (-1f) : 1f); Vector3 val = areaFillReferenceRotation * ((Vector3)(ref areaFillLinearLocalVector)).normalized * ((Vector3)(ref areaFillLinearLocalVector)).magnitude * num; Piece[] pieces = Object.FindObjectsOfType<Piece>(); int num2 = 0; for (int i = 1; i < count - 1; i++) { Vector3 val2 = areaFillPointA + val * (float)i; if (HasMatchingAreaFillPiece(pieces, val2)) { num2++; } else { areaFillPendingPositions.Add(val2); } } if (num2 > 0) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Existing-piece check: skipped {num2} matching occupied linear position(s)."); } } private void PrepareAreaFillPositions(int countA, int countB, float deltaA, float deltaB) { //IL_0032: 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_0042: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) ClearAreaFillPendingPositions(); float num = ((deltaA < 0f) ? (-1f) : 1f); float num2 = ((deltaB < 0f) ? (-1f) : 1f); Vector3 val = areaFillReferenceRotation * AxisVector(areaFillAxisA); Vector3 val2 = areaFillReferenceRotation * AxisVector(areaFillAxisB); Piece[] pieces = Object.FindObjectsOfType<Piece>(); int num3 = 0; for (int i = 0; i < countA; i++) { for (int j = 0; j < countB; j++) { bool num4 = i == 0 && j == 0; bool flag = i == countA - 1 && j == countB - 1; if (!(num4 || flag)) { Vector3 val3 = areaFillPointA + val * ((float)i * areaFillSpacingA * num) + val2 * ((float)j * areaFillSpacingB * num2); if (HasMatchingAreaFillPiece(pieces, val3)) { num3++; } else { areaFillPendingPositions.Add(val3); } } } } if (num3 > 0) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Existing-piece check: skipped {num3} matching occupied grid position(s)."); } } private bool HasMatchingAreaFillPiece(Piece[] pieces, Vector3 target) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (pieces == null) { return false; } float num = 0.0225f; foreach (Piece val in pieces) { if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null) && string.Equals(CleanCloneName(((Object)((Component)val).gameObject).name), areaFillReferencePieceName, StringComparison.OrdinalIgnoreCase)) { Vector3 val2 = ((Component)val).transform.position - target; if (!(((Vector3)(ref val2)).sqrMagnitude > num) && !(Quaternion.Angle(((Component)val).transform.rotation, areaFillReferenceRotation) > 2f)) { return true; } } } return false; } private bool HasAreaFillBatchRequirements(Player player, Piece piece, int pieceCount) { if (pieceCount <= 0 || IsAreaFillFreeBuild(player, piece)) { return true; } if (piece.m_resources == null || piece.m_resources.Length == 0) { return true; } int[] array = new int[piece.m_resources.Length]; try { for (int i = 0; i < piece.m_resources.Length; i++) { Requirement val = piece.m_resources[i]; if (val != null) { array[i] = val.m_amount; long num = (long)val.m_amount * (long)pieceCount; if (num > int.MaxValue) { return false; } val.m_amount = (int)num; } } return HasAreaFillBuildRequirements(player, piece); } finally { for (int j = 0; j < piece.m_resources.Length; j++) { Requirement val2 = piece.m_resources[j]; if (val2 != null) { val2.m_amount = array[j]; } } } } private void TryStartAreaFill(Player player) { if (areaFillPlacementCoroutine != null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] Fill is already running."); return; } if (areaFillPendingPositions.Count == 0) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Fill] No preview is waiting for confirmation. Place Point A and Point B first."); return; } if (areaFillPendingPositions.Count > 500) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Fill refused: {areaFillPendingPositions.Count} missing positions exceeds the safety limit of {500}."); return; } if (PlayerPlacePieceMethod == null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[Area Fill] Build failed: compatible Valheim Player.PlacePiece overload could not be resolved."); return; } GameObject placementGhost = GetPlacementGhost(player); if ((Object)(object)placementGhost == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Area Fill] Build not started: placement ghost is unavailable."); return; } string text = CleanCloneName(((Object)placementGhost).name); if (!string.Equals(text, areaFillReferencePieceName, StringComparison.OrdinalIgnoreCase)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Area Fill] Build not started: selected piece changed from " + areaFillReferencePieceName + " to " + text + "; fill not started.")); return; } Piece selectedPiece = player.GetSelectedPiece(); if ((Object)(object)selectedPiece == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Area Fill] Build not started: selected piece is unavailable."); return; } bool flag = IsAreaFillFreeBuild(player, selectedPiece); try { if (!flag && !HasAreaFillBatchRequirements(player, selectedPiece, areaFillPendingPositions.Count)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Insufficient resources for all {areaFillPendingPositions.Count} missing pieces. Nothing was placed."); return; } } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"[Area Fill] Resource precheck failed; nothing was placed: {arg}"); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Building: {areaFillPendingPositions.Count} missing pieces, freeBuild={flag}. One placement per frame."); areaFillPlacementCoroutine = ((MonoBehaviour)this).StartCoroutine(PlaceAreaFillCoroutine(player, selectedPiece, flag)); } private IEnumerator PlaceAreaFillCoroutine(Player player, Piece selectedPiece, bool freeBuild) { List<Vector3> positions = new List<Vector3>(areaFillPendingPositions); int placed = 0; try { foreach (Vector3 item in positions) { if ((Object)(object)player == (Object)null || (Object)(object)selectedPiece == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Build stopped after {placed}/{positions.Count}: player or selected piece became unavailable."); yield break; } GameObject placementGhost = GetPlacementGhost(player); if ((Object)(object)placementGhost == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Build stopped after {placed}/{positions.Count}: placement ghost became unavailable."); yield break; } Vector3 position = placementGhost.transform.position; Quaternion rotation = placementGhost.transform.rotation; try { placementGhost.transform.position = item; placementGhost.transform.rotation = areaFillReferenceRotation; areaFillInternalPlacement = true; object[] parameters = ((PlayerPlacePieceMethod.GetParameters().Length != 5) ? new object[4] { selectedPiece, item, areaFillReferenceRotation, false } : new object[5] { selectedPiece, item, areaFillReferenceRotation, false, false }); PlayerPlacePieceMethod.Invoke(player, parameters); if (!freeBuild && !ConsumeAreaFillBuildResources(player, selectedPiece)) { ((BaseUnityPlugin)this).Logger.LogError((object)$"[Area Fill] Build stopped after placing {placed + 1}/{positions.Count}: resource consumption could not be invoked."); yield break; } placed++; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)$"[Area Fill] Placement failed at {FormatVector(item)} after {placed}/{positions.Count}: {ex}"); yield break; } finally { areaFillInternalPlacement = false; if ((Object)(object)placementGhost != (Object)null) { placementGhost.transform.position = position; placementGhost.transform.rotation = rotation; } } yield return null; } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] COMPLETE: placed {placed}/{positions.Count} missing pieces. Endpoints were excluded."); ClearAreaFillPreview(); ClearAreaFillPendingPositions(); ClearAreaFillSelection(); } finally { Plugin plugin = this; plugin.areaFillInternalPlacement = false; plugin.areaFillPlacementCoroutine = null; } } private void ClearAreaFillPendingPositions() { areaFillPendingPositions.Clear(); areaFillShowSummary = false; areaFillSummaryText = ""; DestroyAreaFillHud(); } private void CreateAreaFillWirePreview(int total) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_00b8: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: 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_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_005d: 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_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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_013c: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0124: 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_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) ClearAreaFillPreview(); if (total > 500) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"[Area Fill] Preview skipped: {total} positions exceeds the safety limit of {500}."); return; } areaFillPreviewRoot = new GameObject("BetterBuildingMode_AreaFillPreview"); Vector3 axisA; Vector3 axisB; float magnitude; float sizeB; if (areaFillReferenceLinear) { axisA = areaFillReferenceRotation * ((Vector3)(ref areaFillLinearLocalVector)).normalized; Vector3 val = Vector3.Cross(((Vector3)(ref areaFillLinearLocalVector)).normalized, Vector3.forward); if (((Vector3)(ref val)).sqrMagnitude < 0.01f) { val = Vector3.up; } axisB = areaFillReferenceRotation * ((Vector3)(ref val)).normalized; magnitude = ((Vector3)(ref areaFillLinearLocalVector)).magnitude; sizeB = areaFillLinearPreviewWidth; } else { axisA = areaFillReferenceRotation * AxisVector(areaFillAxisA); axisB = areaFillReferenceRotation * AxisVector(areaFillAxisB); magnitude = areaFillSpacingA; sizeB = areaFillSpacingB; } if (areaFillReferencePoleLike) { sizeB = 0.5f; } foreach (Vector3 areaFillPendingPosition in areaFillPendingPositions) { Vector3 val2 = areaFillPendingPosition; if (areaFillReferenceLinear) { val2 += areaFillReferenceRotation * areaFillLinearPreviewCenterOffsetLocal; } CreateWireCell(val2, axisA, axisB, magnitude, sizeB); } int num = Mathf.Max(0, total - areaFillPendingPositions.Count); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Preview created: {areaFillPendingPositions.Count} missing positions shown ({total} total grid positions; endpoints and matching existing pieces excluded, {num} excluded/occupied total)."); } private void CreateWireCell(Vector3 center, Vector3 axisA, Vector3 axisB, float sizeA, float sizeB) { //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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00ba: 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_00c2: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_006e: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("AreaFillPreviewCell"); val.transform.SetParent(areaFillPreviewRoot.transform, false); LineRenderer val2 = val.AddComponent<LineRenderer>(); val2.useWorldSpace = true; val2.loop = false; val2.positionCount = 5; val2.startWidth = 0.035f; val2.endWidth = 0.035f; Shader val3 = Shader.Find("Sprites/Default"); if ((Object)(object)val3 != (Object)null) { Material val4 = new Material(val3); val4.color = new Color(1f, 1f, 1f, 0.8f); ((Renderer)val2).material = val4; } Vector3 val5 = ((Vector3)(ref axisA)).normalized * (sizeA * 0.46f); Vector3 val6 = ((Vector3)(ref axisB)).normalized * (sizeB * 0.46f); val2.SetPosition(0, center - val5 - val6); val2.SetPosition(1, center + val5 - val6); val2.SetPosition(2, center + val5 + val6); val2.SetPosition(3, center - val5 + val6); val2.SetPosition(4, center - val5 - val6); } private void ClearAreaFillPreview() { if ((Object)(object)areaFillPreviewRoot != (Object)null) { Object.Destroy((Object)(object)areaFillPreviewRoot); areaFillPreviewRoot = null; } DestroyAreaFillHud(); } private static Vector3 AxisVector(int axis) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) return (Vector3)(axis switch { 1 => Vector3.up, 0 => Vector3.right, _ => Vector3.forward, }); } private void ResolveAreaFillGrid(GameObject ghost) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) areaFillReferenceLinear = false; areaFillLinearLocalVector = Vector3.zero; areaFillLinearPreviewWidth = 0.5f; if (TryGetDiagonalLinearSnapVector(ghost, out var vector)) { areaFillReferenceLinear = true; areaFillReferencePoleLike = false; areaFillLinearLocalVector = vector; areaFillSpacingA = ((Vector3)(ref vector)).magnitude; areaFillSpacingB = 0f; areaFillAxisA = 0; areaFillAxisB = 1; float num = Mathf.Min(new float[3] { Mathf.Abs(areaFillReferenceSize.x), Mathf.Abs(areaFillReferenceSize.y), Mathf.Abs(areaFillReferenceSize.z) }); areaFillLinearPreviewWidth = Mathf.Clamp(num, 0.35f, 0.75f); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Linear diagonal geometry detected: vector={FormatVector(vector)}, step={((Vector3)(ref vector)).magnitude:0.###}m, previewWidth={areaFillLinearPreviewWidth:0.###}m."); return; } float[] snapPointRanges = GetSnapPointRanges(ghost); int num2 = 0; for (int i = 1; i < 3; i++) { if (snapPointRanges[i] > snapPointRanges[num2]) { num2 = i; } } int num3 = ((num2 == 0) ? 1 : 0); for (int j = 0; j < 3; j++) { if (j != num2 && snapPointRanges[j] > snapPointRanges[num3]) { num3 = j; } } if (areaFillReferencePoleLike = num2 == 1 && snapPointRanges[num2] > 0.1f && snapPointRanges[0] <= 0.1f && snapPointRanges[2] <= 0.1f) { Vector3 val = Quaternion.Inverse(areaFillReferenceRotation) * areaFillReferenceSize; float num4 = Mathf.Max(0.5f, Mathf.Round(Mathf.Abs(val.x) * 2f) / 2f); float num5 = Mathf.Max(0.5f, Mathf.Round(Mathf.Abs(val.z) * 2f) / 2f); areaFillAxisA = 1; areaFillAxisB = ((!(num4 >= num5)) ? 2 : 0); areaFillSpacingA = snapPointRanges[1]; float num6 = Mathf.Max(0.5f, (areaFillAxisB == 0) ? num4 : num5); areaFillSpacingB = ((areaFillPoleSpacingMode == 1) ? 2f : ((areaFillPoleSpacingMode == 2) ? 4f : num6)); string arg = ((areaFillPoleSpacingMode == 1) ? "2m" : ((areaFillPoleSpacingMode == 2) ? "4m" : "Normal")); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Pole geometry detected: vertical={areaFillSpacingA:0.###}m, horizontal={areaFillSpacingB:0.###}m, mode={arg}."); return; } if (snapPointRanges[num2] > 0.1f && snapPointRanges[num3] > 0.1f) { areaFillAxisA = num2; areaFillAxisB = num3; areaFillSpacingA = snapPointRanges[num2]; areaFillSpacingB = snapPointRanges[num3]; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Fill] Using snap-hierarchy geometry: axes={AxisName(num2)}/{AxisName(num3)}, spacing={areaFillSpacingA:0.###}/{areaFillSpacingB:0.###}."); return; } Vector3 val2 = Quaternion.Inverse(areaFillReferenceRotation) * areaFillReferenceSize; float[] array = new float[3] { Mathf.Max(0.5f, Mathf.Round(Mathf.Abs(val2.x))), Mathf.Max(0.5f, Mathf.Round(Mathf.Abs(val2.y))), Mathf.Max(0.5f, Mathf.Round(Mathf.Abs(val2.z))) }; areaFillAxisA = 0; areaFillAxisB = 1; if (array[2] > array[areaFillAxisB]) { areaFillAxisB = 2; } if (array[areaFillAxisB] > array[areaFillAxisA]) { int num7 = areaFillAxisA; areaFillAxisA = areaFillAxisB; areaFillAxisB = num7; } areaFillSpacingA = array[areaFillAxisA]; areaFillSpacingB = array[areaFillAxisB]; ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Area Fill] No usable snap hierarchy found; using rounded visual-size fallback."); } private static bool TryGetDiagonalLinearSnapVector(GameObject ghost, out Vector3 vector) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_015e: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) vector = Vector3.zero; if ((Object)(object)ghost == (Object)null) { return false; } try { List<Vector3> list = new List<Vector3>(); Transform[] componentsInChildren = ghost.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)ghost.transform || ((Object)val).name.IndexOf("snappoint", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Vector3 val2 = ghost.transform.InverseTransformPoint(val.position); bool flag = false; foreach (Vector3 item in list) { Vector3 val3 = item - val2; if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { flag = true; break; } } if (!flag) { list.Add(val2); } } if (list.Count != 2) { return false; } Vector3 val4 = list[1] - list[0]; int num = 0; if (Mathf.Abs(val4.x) > 0.1f) { num++; } if (Mathf.Abs(val4.y) > 0.1f) { num++; } if (Mathf.Abs(val4.z) > 0.1f) { num++; } if (num < 2 || ((Vector3)(ref val4)).magnitude <= 0.1f) { return false; } vector = val4; return true; } catch { return false; } } private static float[] GetSnapPointRanges(GameObject ghost) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_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_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: 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) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_01bd: 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_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) float[] array = new float[3]; if ((Object)(object)ghost == (Object)null) { return array; } try { Transform[] componentsInChildren = ghost.GetComponentsInChildren<Transform>(true); bool flag = false; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(float.MinValue, float.MinValue, float.MinValue); Transform[] array2 = componentsInChildren; foreach (Transform val3 in array2) { if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3 == (Object)(object)ghost.transform) && ((Object)val3).name.IndexOf("snappoint", StringComparison.OrdinalIgnoreCase) >= 0) { Vector3 val4 = ghost.transform.InverseTransformPoint(val3.position); val = Vector3.Min(val, val4); val2 = Vector3.Max(val2, val4); flag = true; } } if (flag) { Vector3 val5 = val2 - val; array[0] = Mathf.Abs(val5.x); array[1] = Mathf.Abs(val5.y); array[2] = Mathf.Abs(val5.z); return array; } } catch { } if (PieceSnapPointsField == null) { return array; } Piece component = ghost.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { return array; } try { if (!(PieceSnapPointsField.GetValue(component) is IEnumerable enumerable)) { return array; } bool flag2 = false; Vector3 val6 = default(Vector3); ((Vector3)(ref val6))..ctor(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 val7 = default(Vector3); ((Vector3)(ref val7))..ctor(float.MinValue, float.MinValue, float.MinValue); foreach (object item in enumerable) { Transform val8 = (Transform)((item is Transform) ? item : null); if (!((Object)(object)val8 == (Object)null)) { Vector3 val9 = ghost.transform.InverseTransformPoint(val8.position); val6 = Vector3.Min(val6, val9); val7 = Vector3.Max(val7, val9); flag2 = true; } } if (flag2) { Vector3 val10 = val7 - val6; array[0] = Mathf.Abs(val10.x); array[1] = Mathf.Abs(val10.y); array[2] = Mathf.Abs(val10.z); } } catch { } return array; } private static int RemainingAxis(int a, int b) { for (int i = 0; i < 3; i++) { if (i != a && i != b) { return i; } } return 2; } private static float GetAxis(Vector3 value, int axis) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) return axis switch { 1 => value.y, 0 => value.x, _ => value.z, }; } private static string AxisName(int axis) { return axis switch { 2 => "Z", 1 => "Y", 0 => "X", _ => "?", }; } private static GameObject GetPlacementGhost(Player player) { if ((Object)(object)player == (Object)null || PlacementGhostField == null) { return null; } try { object? value = PlacementGhostField.GetValue(player); return (GameObject)((value is GameObject) ? value : null); } catch { return null; } } private static Vector3 GetGhostWorldSize(GameObject ghost) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) Renderer[] componentsInChildren = ghost.GetComponentsInChildren<Renderer>(true); if (componentsInChildren == null || componentsInChildren.Length == 0) { return Vector3.zero; } Bounds bounds = componentsInChildren[0].bounds; for (int i = 1; i < componentsInChildren.Length; i++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds); } return ((Bounds)(ref bounds)).size; } private static Vector3 GetGhostRendererCenterOffsetLocal(GameObject ghost) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ghost == (Object)null) { return Vector3.zero; } Renderer[] componentsInChildren = ghost.GetComponentsInChildren<Renderer>(true); if (componentsInChildren == null || componentsInChildren.Length == 0) { return Vector3.zero; } Bounds bounds = componentsInChildren[0].bounds; for (int i = 1; i < componentsInChildren.Length; i++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds); } return Quaternion.Inverse(ghost.transform.rotation) * (((Bounds)(ref bounds)).center - ghost.transform.position); } private void ClearAreaFillSelection() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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) areaFillHasPointA = false; areaFillPointA = Vector3.zero; areaFillReferenceRotation = Quaternion.identity; areaFillReferenceSize = Vector3.zero; areaFillReferencePieceName = ""; areaFillAxisA = -1; areaFillAxisB = -1; areaFillSpacingA = 0f; areaFillSpacingB = 0f; areaFillReferencePoleLike = false; areaFillReferenceLinear = false; areaFillLinearPreviewCenterOffsetLocal = Vector3.zero; areaFillLinearLocalVector = Vector3.zero; areaFillLinearPreviewWidth = 0.5f; } private static string CleanCloneName(string value) { if (!string.IsNullOrEmpty(value)) { return value.Replace("(Clone)", ""); } return "<unknown>"; } private static string FormatVector(Vector3 value) { //IL_0005: 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_001b: Unknown result type (might be due to invalid IL or missing references) return $"({value.x:0.###}, {value.y:0.###}, {value.z:0.###})"; } private void EnableCameraBasedPlacementRange(Player player) { if ((Object)(object)player == (Object)null || MaxPlaceDistanceField == null || placementRangeOverridden) { return; } try { originalMaxPlaceDistance = (float)MaxPlaceDistanceField.GetValue(player); float num = 100f + originalMaxPlaceDistance; MaxPlaceDistanceField.SetValue(player, num); placementRangeOverridden = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Build Free Cam] Placement range temporarily {num:0.##} m (original {originalMaxPlaceDistance:0.##} m)."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Build Free Cam] Could not override placement range: " + ex.Message)); } } private void RestorePlacementRange(Player player) { if (!placementRangeOverridden) { return; } try { if ((Object)(object)player != (Object)null && MaxPlaceDistanceField != null) { MaxPlaceDistanceField.SetValue(player, originalMaxPlaceDistance); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Build Free Cam] Could not restore placement range: " + ex.Message)); } finally { placementRangeOverridden = false; } } internal void CapturePlayerControls(Vector3 movedir, bool jump, bool crouch, bool run) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) capturedMoveDir = movedir; capturedJump = jump; capturedCrouch = crouch; capturedRun = run; } internal void ApplyCameraOverride(GameCamera camera) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (freeCamActive && (Object)(object)camera != (Object)null) { ((Component)camera).transform.position = freeCamPosition; } } private static bool IsShortcutHeld(KeyboardShortcut shortcut) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0) { return false; } ResolveInputReflection(); if (InputGetKeyMethod == null) { return ((KeyboardShortcut)(ref shortcut)).IsPressed(); } try { if (!(bool)InputGetKeyMethod.Invoke(null, new object[1] { ((KeyboardShortcut)(ref shortcut)).MainKey })) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers) { if (!(bool)InputGetKeyMethod.Invoke(null, new object[1] { modifier })) { return false; } } return true; } catch { return ((KeyboardShortcut)(ref shortcut)).IsPressed(); } } private void BeginAreaRepair(Player player, Piece targetPiece) { areaRepairBatchInProgress = false; areaRepairPlayerRepairInProgress = false; areaRepairDirectTarget = null; areaRepairDirectWear = null; areaRepairDirectRepairSucceeded = false; areaRepairSuccessfulWear = null; areaRepairPlayerRepairInProgress = (Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)Player.m_localPlayer && freeCamActive; if (areaRepairPlayerRepairInProgress && !((Object)(object)targetPiece == (Object)null)) { areaRepairDirectTarget = targetPiece; areaRepairDirectWear = ((Component)targetPiece).GetComponent<WearNTear>(); } } private void ObserveAreaRepairWearRepair(WearNTear wear, bool repaired) { if (!areaRepairBatchInProgress && areaRepairPlayerRepairInProgress && repaired && (Object)(object)wear != (Object)null) { areaRepairDirectRepairSucceeded = true; areaRepairSuccessfulWear = wear; } } private void CompleteAreaRepair(Player player) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || !areaRepairDirectRepairSucceeded || (Object)(object)areaRepairSuccessfulWear == (Object)null) { return; } if (!freeCamActive) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Repair] Successful normal repair detected, but Free Cam is not active; Area Repair did not trigger."); } else if (!HasValidBuildStationInRange(player)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Area Repair] Successful normal repair detected, but the character is not inside crafting-station range; Area Repair did not trigger."); } else { if (areaRepairBatchInProgress) { return; } Vector3 val = freeCamPosition; float num = 2500f; WearNTear[] array = Object.FindObjectsOfType<WearNTear>(); int num2 = 0; int num3 = 0; int num4 = 0; areaRepairBatchInProgress = true; WearNTear[] array2 = array; foreach (WearNTear val2 in array2) { if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled || (Object)(object)val2 == (Object)(object)areaRepairSuccessfulWear) { continue; } Vector3 val3 = ((Component)val2).transform.position - val; if (!(((Vector3)(ref val3)).sqrMagnitude > num) && !(val2.GetHealthPercentage() >= 0.9999f)) { num2++; bool flag = false; try { flag = val2.Repair(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Area Repair] Repair call failed for " + CleanCloneName(((Object)((Component)val2).gameObject).name) + ": " + ex.GetBaseException().Message)); } if (flag) { num3++; CreateAreaRepairPieceEffect(val2); } else { num4++; } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Area Repair] COMPLETE: found {num2} additional damaged object(s) within {50f:0}m of Free Cam; repaired {num3}, failed {num4}. Directly repaired target excluded fr