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 HammerFreedom v1.0.11
Landoria.HammerFreedom.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Landoria.Shared; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Landoria.HammerFreedom")] [assembly: AssemblyDescription("Adds client-side creative freedoms to Hammer worlds.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Landoria")] [assembly: AssemblyProduct("Landoria.HammerFreedom")] [assembly: AssemblyCopyright("Copyright © 2026 End3rbyte")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("DDA10461-612F-42CD-A050-B2634758E942")] [assembly: AssemblyFileVersion("1.0.11")] [assembly: AssemblyInformationalVersion("1.0.11")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.11.34229")] namespace Landoria.Shared { internal static class ConfigWatcher { private const int ReloadDelayMilliseconds = 250; private const int MaximumReloadAttempts = 5; private static ConfigFile config; private static string configPath; private static ManualLogSource logger; private static FileSystemWatcher watcher; private static long lastChangeTicks; private static int reloadPending; private static int reloadAttempts; private static long ignoredWriteTicks; private static string displayName; private static Action restoreDefaults; private static Action applyConfiguration; internal static void Initialize(ConfigFile configFile, ManualLogSource logSource, string configurationDisplayName, Action restoreDefaultsAction, Action applyConfigurationAction = null) { Dispose(); config = configFile; logger = logSource; displayName = configurationDisplayName; restoreDefaults = restoreDefaultsAction; applyConfiguration = applyConfigurationAction; configPath = Path.GetFullPath(config.ConfigFilePath); watcher = new FileSystemWatcher(Path.GetDirectoryName(configPath), Path.GetFileName(configPath)); watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime; watcher.Changed += OnChanged; watcher.Created += OnChanged; watcher.Deleted += OnChanged; watcher.Renamed += OnRenamed; watcher.EnableRaisingEvents = true; } internal static void IgnoreCurrentFileVersion() { if (string.IsNullOrEmpty(configPath) || !File.Exists(configPath)) { return; } try { Interlocked.Exchange(ref ignoredWriteTicks, File.GetLastWriteTimeUtc(configPath).Ticks); Interlocked.Exchange(ref reloadPending, 0); } catch (IOException) { ManualLogSource obj = logger; if (obj != null) { obj.LogDebug((object)"Could not mark the internal configuration write."); } } } internal static void Update() { if (Volatile.Read(in reloadPending) == 0 || !ReloadDelayElapsed()) { return; } Interlocked.Exchange(ref reloadPending, 0); try { bool flag = !File.Exists(configPath); if (flag) { restoreDefaults?.Invoke(); } else { config.Reload(); } applyConfiguration?.Invoke(); reloadAttempts = 0; logger.LogInfo((object)(flag ? "Recreated the deleted configuration with default values." : "Reloaded configuration after a file change.")); ShowReloadMessage(flag); } catch (Exception exception) { RetryReload(exception); } } internal static void Dispose() { if (watcher != null) { watcher.EnableRaisingEvents = false; watcher.Dispose(); watcher = null; } Interlocked.Exchange(ref reloadPending, 0); Interlocked.Exchange(ref ignoredWriteTicks, 0L); reloadAttempts = 0; displayName = null; restoreDefaults = null; applyConfiguration = null; } private static void OnChanged(object sender, FileSystemEventArgs eventArgs) { QueueReload(); } private static void OnRenamed(object sender, RenamedEventArgs eventArgs) { QueueReload(); } private static void QueueReload() { if (!IsIgnoredWrite()) { Interlocked.Exchange(ref lastChangeTicks, DateTime.UtcNow.Ticks); Interlocked.Exchange(ref reloadPending, 1); reloadAttempts = 0; } } private static bool IsIgnoredWrite() { try { long num = (File.Exists(configPath) ? File.GetLastWriteTimeUtc(configPath).Ticks : 0); return num != 0L && num == Interlocked.Read(in ignoredWriteTicks); } catch (IOException) { return false; } } private static bool ReloadDelayElapsed() { return DateTime.UtcNow.Ticks - Interlocked.Read(in lastChangeTicks) >= 2500000; } private static void RetryReload(Exception exception) { reloadAttempts++; logger.LogWarning((object)("Configuration reload failed: " + exception.Message)); if (reloadAttempts < 5) { Interlocked.Exchange(ref lastChangeTicks, DateTime.UtcNow.Ticks); Interlocked.Exchange(ref reloadPending, 1); } } private static void ShowReloadMessage(bool recreated) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, recreated ? (displayName + " configuration restored to defaults.") : (displayName + " configuration reloaded."), 0, (Sprite)null, false); } } } } namespace Landoria.HammerFreedom { [HarmonyPatch(typeof(SEMan), "AddStatusEffect", new Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })] internal static class ColdStatusApplicationPatch { private static bool Prefix(Character ___m_character, int nameHash) { if ((Object)(object)___m_character != (Object)(object)Player.m_localPlayer || !Mode.IsHammer()) { return true; } if (nameHash != SEMan.s_statusEffectCold) { return nameHash != SEMan.s_statusEffectFreezing; } return false; } } [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] internal static class ColdStatusPatch { private static void Postfix(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && Mode.IsHammer()) { SEMan sEMan = ((Character)__instance).GetSEMan(); sEMan.RemoveStatusEffect(SEMan.s_statusEffectCold, true); sEMan.RemoveStatusEffect(SEMan.s_statusEffectFreezing, true); } } } [HarmonyPatch(typeof(Character), "Damage")] internal static class FrostDamagePatch { private static void Prefix(Character __instance, HitData hit) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && Mode.IsHammer()) { hit.m_damage.m_frost = 0f; } } } [HarmonyPatch(typeof(Player), "DamageArmorDurability")] internal static class ArmorDurabilityPatch { private static bool Prefix(Player __instance) { return !DurabilityProtection.IsActive((Humanoid)(object)__instance); } } [HarmonyPatch(typeof(Attack), "OnAttackTrigger")] internal static class AttackDurabilityPatch { private static void Prefix(Humanoid ___m_character, ItemData ___m_weapon, out DurabilitySnapshot __state) { __state = new DurabilitySnapshot(___m_weapon, DurabilityProtection.IsActive(___m_character)); } private static void Postfix(DurabilitySnapshot __state) { __state.Restore(); } } [HarmonyPatch(typeof(Humanoid), "BlockAttack")] internal static class BlockDurabilityPatch { private static void Prefix(Humanoid __instance, ItemData ___m_rightItem, ItemData ___m_leftItem, out DurabilitySnapshot[] __state) { bool preserve = DurabilityProtection.IsActive(__instance); __state = new DurabilitySnapshot[2] { new DurabilitySnapshot(___m_rightItem, preserve), new DurabilitySnapshot(___m_leftItem, preserve) }; } private static void Postfix(DurabilitySnapshot[] __state) { foreach (DurabilitySnapshot durabilitySnapshot in __state) { durabilitySnapshot.Restore(); } } } internal static class DurabilityProtection { internal static bool IsActive(Humanoid humanoid) { if ((Object)(object)humanoid == (Object)(object)Player.m_localPlayer) { return Mode.IsHammer(); } return false; } } internal struct DurabilitySnapshot { private readonly ItemData _item; private readonly float _durability; internal DurabilitySnapshot(ItemData item, bool preserve) { _item = (preserve ? item : null); _durability = item?.m_durability ?? 0f; } internal void Restore() { if (_item != null) { _item.m_durability = _durability; } } } [HarmonyPatch(typeof(Humanoid), "DrainEquipedItemDurability")] internal static class EquippedDurabilityPatch { private static bool Prefix(Humanoid __instance) { return !DurabilityProtection.IsActive(__instance); } } [HarmonyPatch(typeof(Character), "Damage")] internal static class FallDamagePatch { private static bool Prefix(Character __instance, HitData hit) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && (int)hit.m_hitType == 3) { return !Mode.IsHammer(); } return true; } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class FlightScrollSpeedPatch { private static void Prefix(out int __state) { Player localPlayer = Player.m_localPlayer; __state = (((Object)(object)localPlayer != (Object)null && ((Character)localPlayer).IsDebugFlying() && Mode.IsHammer()) ? Character.m_debugFlySpeed : (-1)); } private static void Postfix(int __state) { if (__state >= 0) { Character.m_debugFlySpeed = __state; } } } [HarmonyPatch(typeof(Character), "UpdateDebugFly")] internal static class FlightSpeedPatch { private static void Prefix(Character __instance, ref bool ___m_run) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && Mode.IsHammer() && (ZInput.GetButton("Jump") || ZInput.GetButton("JoyJump") || ZInput.GetKey((KeyCode)306, true) || ZInput.GetButtonPressedTimer("JoyCrouch") > 0.33f) && (ZInput.GetButton("Run") || ZInput.GetButton("JoyRun"))) { ___m_run = true; } } private static void Postfix(Character __instance, bool ___m_run, ref Vector3 ___m_currentVel, Rigidbody ___m_body) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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) if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && Mode.IsHammer()) { float num = Preference.FlightSpeed * (___m_run ? 4f : 1f); float magnitude = ((Vector3)(ref ___m_currentVel)).magnitude; float num2 = ((magnitude > num) ? (num / magnitude) : 1f); if (num2 < 1f) { ___m_currentVel *= num2; ___m_body.linearVelocity = ___m_currentVel; } } } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class FlightZoomPatch { private static void Prefix(GameCamera __instance, ref float ___m_distance) { Apply(__instance, ref ___m_distance); } private static void Postfix(GameCamera __instance, ref float ___m_distance) { Apply(__instance, ref ___m_distance); } private static void Apply(GameCamera camera, ref float distance) { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && ((Character)localPlayer).IsDebugFlying() && Mode.IsHammer()) { distance = camera.m_minDistance; } } } internal static class FlyController { private const float InitialLift = 5f; internal static void Toggle() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && Mode.IsHammer()) { SetEnabled(!((Character)localPlayer).IsDebugFlying()); } } internal static void SetEnabled(bool enabled) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && (!enabled || Mode.IsHammer()) && ((Character)localPlayer).IsDebugFlying() != enabled) { localPlayer.ToggleDebugFly(); if (enabled) { Lift(localPlayer); } } } private static void Lift(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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)player).transform.position + Vector3.up * 5f; Rigidbody component = ((Component)player).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component)) { component.position = position; component.linearVelocity = Vector3.zero; } ((Component)player).transform.position = position; } } internal static class FlyInput { internal static bool ShouldApplyGroundAction(Character character) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)character != (Object)(object)localPlayer) && !((Object)(object)localPlayer == (Object)null) && ((Character)localPlayer).IsDebugFlying()) { return !Mode.IsHammer(); } return true; } internal static bool IsAvailable() { if (Mode.IsHammer() && (Object)(object)Player.m_localPlayer != (Object)null && !Console.IsVisible() && !TextInput.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible()) { if (!((Object)(object)Chat.instance == (Object)null)) { return !Chat.instance.HasFocus(); } return true; } return false; } } [HarmonyPatch(typeof(Player), "SetCrouch")] internal static class FlyingCrouchPatch { private static bool Prefix(Player __instance, bool crouch) { if (crouch) { return FlyInput.ShouldApplyGroundAction((Character)(object)__instance); } return true; } } [HarmonyPatch(typeof(Character), "Jump")] internal static class FlyingJumpPatch { private static bool Prefix(Character __instance) { return FlyInput.ShouldApplyGroundAction(__instance); } } internal static class VisibilityController { private static readonly HashSet<Renderer> HiddenRenderers = new HashSet<Renderer>(); private static Player hiddenPlayer; private static bool wasAirborne; internal static void Update(Player player, bool enabled, bool flying) { if (!enabled || !Object.op_Implicit((Object)(object)player)) { Restore(); } else if (flying) { wasAirborne |= !((Character)player).IsOnGround(); SetHidden(player); } else { RestoreAfterLanding(player); } } private static void SetHidden(Player player) { if ((Object)(object)hiddenPlayer != (Object)(object)player) { Restore(); hiddenPlayer = player; HideCurrentVisuals(); } } internal static void Refresh(Player player) { if (Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)hiddenPlayer) { HideCurrentVisuals(); } } internal static void Restore() { foreach (Renderer hiddenRenderer in HiddenRenderers) { if (Object.op_Implicit((Object)(object)hiddenRenderer)) { hiddenRenderer.forceRenderingOff = false; } } HiddenRenderers.Clear(); hiddenPlayer = null; wasAirborne = false; } private static void RestoreAfterLanding(Player player) { if (!((Object)(object)hiddenPlayer != (Object)(object)player)) { if (!((Character)player).IsOnGround()) { wasAirborne = true; } else if (wasAirborne) { Restore(); } } } private static void HideCurrentVisuals() { Renderer[] componentsInChildren = ((Component)hiddenPlayer).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (Object.op_Implicit((Object)(object)val) && !val.forceRenderingOff) { val.forceRenderingOff = true; HiddenRenderers.Add(val); } } } } [HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")] internal static class VisualVisibilityPatch { private static void Postfix(VisEquipment __instance) { Player componentInParent = ((Component)__instance).GetComponentInParent<Player>(); if ((Object)(object)componentInParent == (Object)(object)Player.m_localPlayer) { VisibilityController.Refresh(componentInParent); } } } internal static class Mode { internal static bool IsHammer() { if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey((GlobalKeys)24)) { return ZoneSystem.instance.GetGlobalKey((GlobalKeys)30); } return false; } internal static void Update() { if (!IsHammer()) { FlyController.SetEnabled(enabled: false); } } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] internal static class PlacementDurabilityPatch { private static void Prefix(Player __instance, ItemData ___m_rightItem, out DurabilitySnapshot __state) { __state = new DurabilitySnapshot(___m_rightItem, DurabilityProtection.IsActive((Humanoid)(object)__instance)); } private static void Postfix(DurabilitySnapshot __state) { __state.Restore(); } } internal static class Preference { internal const float DefaultFlightSpeed = 5f; internal const bool DefaultHideCharacterWhileFlying = true; private const float MinimumFlightSpeed = 1f; private const float MaximumFlightSpeed = 10f; private static ConfigEntry<KeyboardShortcut> toggleShortcut; private static ConfigEntry<float> flightSpeed; private static ConfigEntry<bool> hideCharacterWhileFlying; internal static KeyboardShortcut ToggleShortcut => toggleShortcut.Value; internal static float FlightSpeed => flightSpeed.Value; internal static bool HideCharacterWhileFlying => hideCharacterWhileFlying.Value; internal static void Initialize(ConfigFile config) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown toggleShortcut = config.Bind<KeyboardShortcut>("Controls", "ToggleShortcut", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), "Shortcut used to enable or disable flight.\n\nExamples: Mouse2 for the middle mouse button.\n\nMouse3/Mouse4 for the Forward/Back side button.\n\nSpace + LeftControl for Left Ctrl + Space.\n\nOn QWERTZ keyboards, use Y for the physical Z key.\n\nhttps://docs.unity3d.com/ScriptReference/KeyCode.html"); flightSpeed = config.Bind<float>("Flight", "Speed", 5f, new ConfigDescription("Maximum flight speed in metres per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); hideCharacterWhileFlying = config.Bind<bool>("Flight", "HideCharacter", true, "Hide your character and held item while flying."); } internal static void RestoreDefaults(ConfigFile config) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) toggleShortcut.Value = new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()); flightSpeed.Value = 5f; hideCharacterWhileFlying.Value = true; config.Save(); ConfigWatcher.IgnoreCurrentFileVersion(); } } [BepInPlugin("Landoria.HammerFreedom", "Landoria.HammerFreedom", "1.0.11")] public sealed class Plugin : BaseUnityPlugin { internal const string PluginGuid = "Landoria.HammerFreedom"; internal const string PluginName = "Landoria.HammerFreedom"; internal const string PluginVersion = "1.0.11"; private Harmony _harmony; internal static ManualLogSource ModLogger { get; private set; } private void Awake() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown ModLogger = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"AssemblyVersion: {((object)this).GetType().Assembly.GetName().Version}."); _harmony = new Harmony("Landoria.HammerFreedom"); _harmony.PatchAll(); Preference.Initialize(((BaseUnityPlugin)this).Config); ConfigWatcher.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger, "Hammer Freedom", delegate { Preference.RestoreDefaults(((BaseUnityPlugin)this).Config); }); ModLogger.LogInfo((object)"Landoria.HammerFreedom 1.0.11 is loaded."); } private void Update() { ConfigWatcher.Update(); Mode.Update(); HandleShortcuts(); UpdatePlayerVisibility(); } private static void UpdatePlayerVisibility() { Player localPlayer = Player.m_localPlayer; bool enabled = Preference.HideCharacterWhileFlying && Mode.IsHammer(); bool flying = Object.op_Implicit((Object)(object)localPlayer) && ((Character)localPlayer).IsDebugFlying(); VisibilityController.Update(localPlayer, enabled, flying); } private void HandleShortcuts() { //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) if (FlyInput.IsAvailable()) { KeyboardShortcut toggleShortcut = Preference.ToggleShortcut; if (((KeyboardShortcut)(ref toggleShortcut)).IsDown()) { FlyController.Toggle(); } } } private void OnDestroy() { VisibilityController.Restore(); ConfigWatcher.Dispose(); ManualLogSource modLogger = ModLogger; if (modLogger != null) { modLogger.LogInfo((object)"Landoria.HammerFreedom 1.0.11 is unloaded."); } Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; ModLogger = null; } } [HarmonyPatch(typeof(Player), "RPC_UseStamina")] internal static class StaminaApplicationPatch { private static bool Prefix(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { return !Mode.IsHammer(); } return true; } } [HarmonyPatch(typeof(Player), "UseStamina")] internal static class StaminaConsumptionPatch { private static bool Prefix(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { return !Mode.IsHammer(); } return true; } } }