From 3a19c311ec17623eed0fe22d8858e2e076a8b0f0 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:31:13 +0200 Subject: [PATCH 01/21] Le harmony update --- SecretAPI.Examples/Patches/ExampleAmmoPatch.cs | 8 +++----- SecretAPI.Examples/SecretAPI.Examples.csproj | 2 +- SecretAPI/SecretAPI.csproj | 12 +++++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SecretAPI.Examples/Patches/ExampleAmmoPatch.cs b/SecretAPI.Examples/Patches/ExampleAmmoPatch.cs index 46467c6..e119515 100644 --- a/SecretAPI.Examples/Patches/ExampleAmmoPatch.cs +++ b/SecretAPI.Examples/Patches/ExampleAmmoPatch.cs @@ -20,15 +20,13 @@ private static void Prefix() // gets called after the original method is called // We grab the method params of ammoType and player, the names must be correct - // ref __result will become a reference to the return value -#pragma warning disable SA1313 - private static void Postfix(ItemType ammoType, ReferenceHub player, ref ushort __result) -#pragma warning restore SA1313 + // ref result will become a reference to the return value + private static void Postfix(ItemType ammoType, ReferenceHub player, [HarmonyArgument("__result")] ref ushort result) { // make sure we don't modify the max ammo if its not the correct ammo type or the player hasn't been fake synced if (ammoType != ExampleFakeSyncButton.AmmoFakeSync || !ExampleFakeSyncButton.FakeSyncs.TryGetValue(player, out ushort sync)) return; - __result = sync; + result = sync; } } \ No newline at end of file diff --git a/SecretAPI.Examples/SecretAPI.Examples.csproj b/SecretAPI.Examples/SecretAPI.Examples.csproj index 7dbfccb..09de51d 100644 --- a/SecretAPI.Examples/SecretAPI.Examples.csproj +++ b/SecretAPI.Examples/SecretAPI.Examples.csproj @@ -7,7 +7,7 @@ - + diff --git a/SecretAPI/SecretAPI.csproj b/SecretAPI/SecretAPI.csproj index db3c6ac..c31687d 100644 --- a/SecretAPI/SecretAPI.csproj +++ b/SecretAPI/SecretAPI.csproj @@ -4,6 +4,8 @@ net48 latest true + true + false @@ -23,10 +25,7 @@ - - + @@ -40,11 +39,14 @@ - + + + + From c6faf191f6d559e50cda7ddacd9d9b14d08dfaf9 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 13:43:05 +0200 Subject: [PATCH 02/21] Lib.Harmony.Thin --- SecretAPI.Examples/SecretAPI.Examples.csproj | 2 +- SecretAPI/SecretAPI.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SecretAPI.Examples/SecretAPI.Examples.csproj b/SecretAPI.Examples/SecretAPI.Examples.csproj index 09de51d..5248071 100644 --- a/SecretAPI.Examples/SecretAPI.Examples.csproj +++ b/SecretAPI.Examples/SecretAPI.Examples.csproj @@ -7,7 +7,7 @@ - + diff --git a/SecretAPI/SecretAPI.csproj b/SecretAPI/SecretAPI.csproj index c31687d..b06bcdb 100644 --- a/SecretAPI/SecretAPI.csproj +++ b/SecretAPI/SecretAPI.csproj @@ -25,7 +25,7 @@ - + From 0efa6b2327d0050b78dee7a4f65ffe8d3a360bac Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 13:50:30 +0200 Subject: [PATCH 03/21] DecalHelpers.CleanUpDecals --- SecretAPI/Features/DecalHelpers.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SecretAPI/Features/DecalHelpers.cs b/SecretAPI/Features/DecalHelpers.cs index ce5f76e..acd9fac 100644 --- a/SecretAPI/Features/DecalHelpers.cs +++ b/SecretAPI/Features/DecalHelpers.cs @@ -1,10 +1,12 @@ namespace SecretAPI.Features; using System; +using CommandSystem.Commands.RemoteAdmin.Cleanup; using Decals; using InventorySystem.Items; using InventorySystem.Items.Autosync; using InventorySystem.Items.Firearms.Modules; +using LabApi.Features.Wrappers; using Mirror; using RelativePositioning; using UnityEngine; @@ -86,6 +88,21 @@ public static void SpawnDecalFromDirection(Vector3 position, Vector3 direction, public static void SpawnDecalFromDirection(Vector3 position, Quaternion direction, DecalPoolType type = DecalPoolType.Blood) => GetDecalMessage(position, position - (direction * Vector3.forward), type).SendToAuthenticated(); + /// + /// Cleans up decals for all players. + /// + /// The to cleanup. + /// The amount of that decal to cleanup. + public static void CleanupDecals(DecalPoolType decalType, int amount = int.MaxValue) => new DecalCleanupMessage(decalType, amount).SendToAuthenticated(); + + /// + /// Cleans up decals for a specific player. + /// + /// The player to clean up decals for. + /// The to cleanup. + /// The amount of that decal to cleanup. + public static void CleanUpDecals(this Player player, DecalPoolType decalType, int amount = int.MaxValue) => new DecalCleanupMessage(decalType, amount).SendToHubsConditionally(hub => hub == player.ReferenceHub); + private static AutoSyncData GetAutoSyncData() { if (autoSyncData != null) From 5ce0662269a0fcecc6ee992e4ebc2d8bf8f409f8 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 14:29:26 +0200 Subject: [PATCH 04/21] Obsolete --- SecretAPI/Attributes/HarmonyPatchCategory.cs | 4 ++-- SecretAPI/Extensions/HarmonyExtensions.cs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/SecretAPI/Attributes/HarmonyPatchCategory.cs b/SecretAPI/Attributes/HarmonyPatchCategory.cs index 4257803..9de4637 100644 --- a/SecretAPI/Attributes/HarmonyPatchCategory.cs +++ b/SecretAPI/Attributes/HarmonyPatchCategory.cs @@ -1,4 +1,4 @@ -namespace SecretAPI.Attributes; +/*namespace SecretAPI.Attributes; using System; using SecretAPI.Extensions; @@ -22,4 +22,4 @@ public HarmonyPatchCategory(string category) /// Gets the patch category. /// public string Category { get; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/SecretAPI/Extensions/HarmonyExtensions.cs b/SecretAPI/Extensions/HarmonyExtensions.cs index 1eee37b..d44831f 100644 --- a/SecretAPI/Extensions/HarmonyExtensions.cs +++ b/SecretAPI/Extensions/HarmonyExtensions.cs @@ -21,32 +21,36 @@ public static class HarmonyExtensions /// /// The category to patch. /// The assembly to find patches in. + [Obsolete("Use Harmony::PatchCategory(Assembly, string)")] public void PatchCategory(string category, Assembly? assembly = null) { assembly ??= Assembly.GetCallingAssembly(); + harmony.PatchCategory(assembly, category); - assembly.GetTypes().Where(type => + /*assembly.GetTypes().Where(type => { IEnumerable categories = type.GetCustomAttributes(); - return categories.Any(c => c.Category == category); + return categories.Any(c => c.info.category == category); }) - .Do(type => SafePatch(harmony, type)); + .Do(type => SafePatch(harmony, type));*/ } /// /// Patches all patches that don't have a . /// /// The assembly to look for patches. + [Obsolete("Use Harmony::PatchAllUncategorized(Assembly)")] public void PatchAllNoCategory(Assembly? assembly = null) { assembly ??= Assembly.GetCallingAssembly(); + harmony.PatchAllUncategorized(assembly); - assembly.GetTypes().Where(type => + /*assembly.GetTypes().Where(type => { IEnumerable categories = type.GetCustomAttributes(); return !categories.Any(); }) - .Do(type => SafePatch(harmony, type)); + .Do(type => SafePatch(harmony, type));*/ } /// @@ -61,7 +65,7 @@ public void SafePatch(Type type) } catch (Exception ex) { - Logger.Error($"[HarmonyExtensions] failed to safely patch {harmony.Id} ({type.FullName}): {ex}"); + Logger.Error($"[HarmonyExtensions] Failed to safely patch {harmony.Id} ({type.FullName}): {ex}"); } } } From 754015ce3048ab32d29a45e9218537f1126a2a9d Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:00:08 +0200 Subject: [PATCH 05/21] Remove publicize --- SecretAPI.Examples/ExampleEntry.cs | 9 +++++++-- SecretAPI.Examples/SecretAPI.Examples.csproj | 5 +---- SecretAPI/Extensions/CodeMatcherExtensions.cs | 11 ++++------- SecretAPI/Features/UserSettings/CustomSetting.cs | 3 +-- SecretAPI/SecretAPI.csproj | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/SecretAPI.Examples/ExampleEntry.cs b/SecretAPI.Examples/ExampleEntry.cs index 1839237..5fd53a0 100644 --- a/SecretAPI.Examples/ExampleEntry.cs +++ b/SecretAPI.Examples/ExampleEntry.cs @@ -1,10 +1,10 @@ namespace SecretAPI.Examples; using System; +using System.Reflection; using HarmonyLib; using LabApi.Loader.Features.Plugins; using SecretAPI.Examples.Settings; -using SecretAPI.Extensions; using SecretAPI.Features.UserSettings; /// @@ -29,11 +29,16 @@ public class ExampleEntry : Plugin /// public override Version RequiredApiVersion { get; } = new(LabApi.Features.LabApiProperties.CompiledVersion); + /// + /// Gets the of SecretAPI.Examples. + /// + internal Assembly Assembly { get; } = typeof(ExampleEntry).Assembly; + /// public override void Enable() { CustomSetting.Register(new ExampleKeybindSetting(), new ExampleDropdownSetting(), new ExampleButtonSetting(), new ExampleFakeSyncButton()); - harmony.PatchCategory(nameof(ExampleFakeSyncButton)); + harmony.PatchCategory(Assembly, nameof(ExampleFakeSyncButton)); } /// diff --git a/SecretAPI.Examples/SecretAPI.Examples.csproj b/SecretAPI.Examples/SecretAPI.Examples.csproj index 5248071..cce57e4 100644 --- a/SecretAPI.Examples/SecretAPI.Examples.csproj +++ b/SecretAPI.Examples/SecretAPI.Examples.csproj @@ -7,10 +7,7 @@ - - + diff --git a/SecretAPI/Extensions/CodeMatcherExtensions.cs b/SecretAPI/Extensions/CodeMatcherExtensions.cs index 6bfd06a..a2b849e 100644 --- a/SecretAPI/Extensions/CodeMatcherExtensions.cs +++ b/SecretAPI/Extensions/CodeMatcherExtensions.cs @@ -25,11 +25,8 @@ public static class CodeMatcherExtensions /// The of the local to declare. /// The declared. /// The current . - public CodeMatcher DeclareLocal(Type localType, out LocalBuilder localBuilder) - { - localBuilder = matcher.generator.DeclareLocal(localType); - return matcher; - } + [Obsolete("Use CodeMatcher::DeclareLocal(Type, out LocalBuilder)")] + public CodeMatcher DeclareLocal(Type localType, out LocalBuilder localBuilder) => matcher.DeclareLocal(localType, out localBuilder); /// /// Declares a local to be used of a certain . @@ -39,7 +36,7 @@ public CodeMatcher DeclareLocal(Type localType, out LocalBuilder localBuilder) /// The current . public CodeMatcher DeclareLocal(Type localType, out int localIndex) { - DeclareLocal(matcher, localType, out LocalBuilder builder); + matcher.DeclareLocal(localType, out LocalBuilder builder); localIndex = builder.LocalIndex; return matcher; } @@ -63,7 +60,7 @@ public CodeMatcher GetFirstLabel(out Label label) /// The current . public CodeMatcher GetFirstLabelAt(int position, out Label label) { - label = matcher.codes[position].labels.FirstOrDefault(); + label = matcher.Instructions()[position].labels.FirstOrDefault(); return matcher; } } diff --git a/SecretAPI/Features/UserSettings/CustomSetting.cs b/SecretAPI/Features/UserSettings/CustomSetting.cs index 5715e44..2b5fc03 100644 --- a/SecretAPI/Features/UserSettings/CustomSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSetting.cs @@ -12,7 +12,6 @@ using LabApi.Features.Wrappers; using Mirror; using NorthwoodLib.Pools; -using SecretAPI.Extensions; /// /// Wraps . @@ -23,7 +22,7 @@ public abstract class CustomSetting : ISetting static CustomSetting() { - SecretApi.Harmony.PatchCategory(nameof(CustomSetting), SecretApi.Assembly); + SecretApi.Harmony.PatchCategory(SecretApi.Assembly, nameof(CustomSetting)); ServerSpecificSettingsSync.SendOnJoinFilter = null; ServerSpecificSettingsSync.DefinedSettings ??= []; // fix null ref diff --git a/SecretAPI/SecretAPI.csproj b/SecretAPI/SecretAPI.csproj index b06bcdb..1689e92 100644 --- a/SecretAPI/SecretAPI.csproj +++ b/SecretAPI/SecretAPI.csproj @@ -25,7 +25,7 @@ - + From 28eda5a3f5225fb4373e196dfc84ccb66c072706 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:19:01 +0200 Subject: [PATCH 06/21] Use: HarmonyArgument --- .../Features/Settings/SettingsOriginalDefinitionFix.cs | 8 +++----- .../Patches/Features/Settings/SettingsSyncValidateFix.cs | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/SecretAPI/Patches/Features/Settings/SettingsOriginalDefinitionFix.cs b/SecretAPI/Patches/Features/Settings/SettingsOriginalDefinitionFix.cs index c3f0a7f..77cb9aa 100644 --- a/SecretAPI/Patches/Features/Settings/SettingsOriginalDefinitionFix.cs +++ b/SecretAPI/Patches/Features/Settings/SettingsOriginalDefinitionFix.cs @@ -12,14 +12,12 @@ [HarmonyPatch(typeof(ServerSpecificSettingBase), nameof(ServerSpecificSettingBase.OriginalDefinition), MethodType.Getter)] internal static class SettingsOriginalDefinitionFix { -#pragma warning disable SA1313 // Parameter '__result' should begin with lower-case letter - private static void Postfix(ServerSpecificSettingBase __instance, ref ServerSpecificSettingBase __result) -#pragma warning restore SA1313 + private static void Postfix([HarmonyArgument("__instance")] ServerSpecificSettingBase instance, [HarmonyArgument("__result")] ref ServerSpecificSettingBase result) { // Prevent handling non SecretAPI settings. - if (__result != null) + if (result != null) return; - __result = CustomSetting.Get(__instance.GetType(), __instance.SettingId)?.Base ?? null!; + result = CustomSetting.Get(instance.GetType(), instance.SettingId)?.Base ?? null!; } } \ No newline at end of file diff --git a/SecretAPI/Patches/Features/Settings/SettingsSyncValidateFix.cs b/SecretAPI/Patches/Features/Settings/SettingsSyncValidateFix.cs index 31cb578..51d29b7 100644 --- a/SecretAPI/Patches/Features/Settings/SettingsSyncValidateFix.cs +++ b/SecretAPI/Patches/Features/Settings/SettingsSyncValidateFix.cs @@ -12,14 +12,12 @@ [HarmonyPatch(typeof(ServerSpecificSettingsSync), nameof(ServerSpecificSettingsSync.ServerPrevalidateClientResponse))] internal static class SettingsSyncValidateFix { -#pragma warning disable SA1313 // Parameter '__result' should begin with lower-case letter - private static void Postfix(SSSClientResponse msg, ref bool __result) -#pragma warning restore SA1313 + private static void Postfix(SSSClientResponse msg, [HarmonyArgument("__result")] ref bool result) { // prevent overriding already validated settings - if (__result) + if (result) return; - __result = CustomSetting.Get(msg.SettingType, msg.Id) != null; + result = CustomSetting.Get(msg.SettingType, msg.Id) != null; } } \ No newline at end of file From f20ef458ab77c90072059b0922a9121a105e95f0 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 16 Sep 2026 18:00:47 +0200 Subject: [PATCH 07/21] CopyDll --- Directory.Build.targets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Directory.Build.targets b/Directory.Build.targets index 38f22b4..d961ed5 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -19,4 +19,9 @@ + + + + + \ No newline at end of file From 9c6e0a7cb21930d1a9d1d6418d9c9f03eb3859c6 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Thu, 17 Sep 2026 11:51:08 +0200 Subject: [PATCH 08/21] Remove breaking change --- SecretAPI.Examples/ExampleEntry.cs | 9 ++++++++- SecretAPI/Attributes/HarmonyPatchCategory.cs | 8 +++++--- SecretAPI/SecretApi.cs | 9 ++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/SecretAPI.Examples/ExampleEntry.cs b/SecretAPI.Examples/ExampleEntry.cs index 5fd53a0..58f82bc 100644 --- a/SecretAPI.Examples/ExampleEntry.cs +++ b/SecretAPI.Examples/ExampleEntry.cs @@ -1,4 +1,11 @@ -namespace SecretAPI.Examples; +/* + Temp until 4.0 +*/ +#pragma warning disable SA1200 +global using HarmonyPatchCategoryAttribute = HarmonyLib.HarmonyPatchCategory; +#pragma warning restore SA1200 + +namespace SecretAPI.Examples; using System; using System.Reflection; diff --git a/SecretAPI/Attributes/HarmonyPatchCategory.cs b/SecretAPI/Attributes/HarmonyPatchCategory.cs index 9de4637..00026d9 100644 --- a/SecretAPI/Attributes/HarmonyPatchCategory.cs +++ b/SecretAPI/Attributes/HarmonyPatchCategory.cs @@ -1,4 +1,4 @@ -/*namespace SecretAPI.Attributes; +namespace SecretAPI.Attributes; using System; using SecretAPI.Extensions; @@ -7,13 +7,15 @@ /// Category handling for . /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] -public class HarmonyPatchCategory : Attribute +[Obsolete("Please use HarmonyLib.HarmonyPatchCategoryAttribute - This will be removed in 4.0")] +public class HarmonyPatchCategory : HarmonyLib.HarmonyPatchCategory { /// /// Initializes a new instance of the class. /// /// The category of the patch. public HarmonyPatchCategory(string category) + : base(category) { Category = category; } @@ -22,4 +24,4 @@ public HarmonyPatchCategory(string category) /// Gets the patch category. /// public string Category { get; } -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/SecretAPI/SecretApi.cs b/SecretAPI/SecretApi.cs index 2268034..d1b14a6 100644 --- a/SecretAPI/SecretApi.cs +++ b/SecretAPI/SecretApi.cs @@ -1,4 +1,11 @@ -namespace SecretAPI; +/* + Temp until 4.0 +*/ +#pragma warning disable SA1200 +global using HarmonyPatchCategoryAttribute = HarmonyLib.HarmonyPatchCategory; +#pragma warning restore SA1200 + +namespace SecretAPI; using System; using System.IO; From 202167387b8271d338b6ad284ba57d04e5788fbd Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:11:37 +0200 Subject: [PATCH 09/21] IRegister: Support IPriority --- SecretAPI/Features/IPriority.cs | 2 +- SecretAPI/Features/IRegister.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SecretAPI/Features/IPriority.cs b/SecretAPI/Features/IPriority.cs index 6f0666b..24214c6 100644 --- a/SecretAPI/Features/IPriority.cs +++ b/SecretAPI/Features/IPriority.cs @@ -1,7 +1,7 @@ namespace SecretAPI.Features; /// -/// Handles IPriority. +/// Handles priority on certain things. /// public interface IPriority { diff --git a/SecretAPI/Features/IRegister.cs b/SecretAPI/Features/IRegister.cs index 91bb494..a5a5bab 100644 --- a/SecretAPI/Features/IRegister.cs +++ b/SecretAPI/Features/IRegister.cs @@ -2,11 +2,13 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; /// /// Interface used to define a type that should auto register. /// +/// This supports , will default to 0 if not implemented. // TODO: Source generate this public interface IRegister { @@ -25,7 +27,7 @@ public interface IRegister /// public void TryUnregister() { - // default empty to prevent breaking change + // default to empty } /// @@ -38,6 +40,7 @@ public static void RegisterAll(Assembly? assembly = null) registerables.TryAdd(assembly, new()); + List registers = new(); foreach (Type type in assembly.GetTypes()) { if (type.IsAbstract || type.IsInterface) @@ -46,10 +49,14 @@ public static void RegisterAll(Assembly? assembly = null) if (!typeof(IRegister).IsAssignableFrom(type)) continue; - object obj = Activator.CreateInstance(type); - if (obj is not IRegister register) + if (Activator.CreateInstance(type) is not IRegister register) continue; + registers.Add(register); + } + + foreach (IRegister register in registers.OrderBy(x => x is IPriority priority ? priority.Priority : 0)) + { registerables[assembly].Add(register); register.TryRegister(); } From 645e75e0f253a9b9f210def2bc5c01953a891099 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:11:45 +0200 Subject: [PATCH 10/21] Obsolete Registry --- SecretAPI/Features/Registry.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SecretAPI/Features/Registry.cs b/SecretAPI/Features/Registry.cs index 2aae151..8103a70 100644 --- a/SecretAPI/Features/Registry.cs +++ b/SecretAPI/Features/Registry.cs @@ -1,11 +1,13 @@ namespace SecretAPI.Features; +using System; using System.Collections.Generic; /// /// Handles the registration of objects and ids. /// /// The type of the registry. +[Obsolete("This will be removed in 4.0")] public static class Registry { /// From 99f7451383167e4b410b82a0a92a0c412f80de6c Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:46:25 +0200 Subject: [PATCH 11/21] CustomButtonSetting::TimesPressed --- .../Features/UserSettings/CustomButtonSetting.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SecretAPI/Features/UserSettings/CustomButtonSetting.cs b/SecretAPI/Features/UserSettings/CustomButtonSetting.cs index df65faa..b79dc4e 100644 --- a/SecretAPI/Features/UserSettings/CustomButtonSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomButtonSetting.cs @@ -56,6 +56,11 @@ protected CustomButtonSetting(int? id, string label, string buttonText, float? h /// public bool EverPressed => LastPressWatch.IsRunning; + /// + /// Gets the amount of times the button has been pressed. + /// + public uint TimesPressed { get; private set; } + /// /// Gets or sets the text of the button. /// @@ -82,6 +87,13 @@ public float RequiredHoldTime } } + /// + protected override void HandleBeforeSettingUpdate() + { + base.HandleBeforeSettingUpdate(); + TimesPressed++; + } + /// /// Sends an update to that or has updated. /// From a50eb468dc7cdf87741e6cabaafbf3299114ca4e Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Thu, 24 Sep 2026 18:12:10 +0200 Subject: [PATCH 12/21] 3.5.0-beta1 bump --- .github/README.md | 26 +++++++++++++++++++------- Directory.Build.props | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/README.md b/.github/README.md index d353b21..1f11f0e 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,14 +1,26 @@ # SecretAPI ![Downloads](https://img.shields.io/github/downloads/Misfiy/SecretAPI/total) * SecretAPI is a plugin that extends [LabAPI](https://github.com/northwood-studios/LabAPI) by providing extra features to help devs. +# Dependencies +- SecretAPI relies on Harmony to implement features + - You can find the latest version [here](https://github.com/pardeike/Harmony/releases/latest) + - You should download Harmony-Fat and put the **0harmony.dll** (found in /net48) into your dependencies folder! + # Features -- CollectionExtensions: Extensions to provide utility for collections like lists and arrays. -- RoomExtensions: Extensions to help with room specific tasks, like checking if a room is safe to teleport to. -- HarmonyExtensions: Extensions to provide more utility to Harmony patching, like adding some updated Harmony features which can't be utilised, i.e. patching by category. -- CustomPlayerEffect: Create custom status effects using the base-game system. -- IRegister: Handle auto registering certain plugin features inheriting this interface and then running `IRegister.RegisterAll(Assembly)` in your plugin's initialise method. -- CallOnLoadAttribute: Allows calling static initialize methods on enable via ``CallOnLoadAttribute.Load(Assembly)`` -- CustomSetting: Server Specific Settings without the management hassle, control everything for 1 setting in 1 class, including permissions. A better setting system overall. +- **CustomPlayerEffect**: Create custom status effects using the base-game system. + - BlastResistance: Grants 0.5% resistance to explosion damage + - Depleted: Disables stamina and its regen + - Energized: Disables stamina usage +- **IRegister**: Handle auto registering certain plugin features inheriting this interface and then running `IRegister.RegisterAll(Assembly)` in your plugin's initialize method. +- **CallOnLoadAttribute**: Allows calling static initialize methods on enable via ``CallOnLoadAttribute.Load(Assembly)`` +- **CustomSetting**: Server Specific Settings without the management hassle, control everything for 1 setting in 1 class, including permissions. A better setting system overall. +- **PrefabStore** and **PrefabManager**: Designed to help access prefabs in a clean way +- Extensions: + - CodeMatcherExtensions: Extensions related to ``HarmonyLib.CodeMatcher``. + - CollectionExtensions: Extensions to provide utility for collections like lists and arrays. + - MirrorExtensions: Extensions providing help with fake-syncing ``SyncVar``, ``SyncList`` and ``Rpc`` + - ReflectionExtensions: Extensions related to C# Reflection + - RoomExtensions: Extensions to help with room specific tasks, like checking if a room is safe to teleport to. # Examples You can find examples inside the `SecretAPI.Examples` folder above, this contains some example settings, patches using categories and some more. diff --git a/Directory.Build.props b/Directory.Build.props index 24401c1..52706c7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  enable - 3.4.0 + 3.5.0-beta1 From afc7e84bf308e9b9cf7e3e8e9f21bd5ccb05d886 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:35:11 +0200 Subject: [PATCH 13/21] Extra condition to CustomPlayerEffect.Register(Type) --- SecretAPI/Features/Effects/CustomPlayerEffect.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SecretAPI/Features/Effects/CustomPlayerEffect.cs b/SecretAPI/Features/Effects/CustomPlayerEffect.cs index 13699b4..394d3a3 100644 --- a/SecretAPI/Features/Effects/CustomPlayerEffect.cs +++ b/SecretAPI/Features/Effects/CustomPlayerEffect.cs @@ -55,6 +55,12 @@ public static void Register(Type type) } #pragma warning disable CS0618 // Type or member is obsolete + if (EffectsToRegister.Contains(type)) + { + Logger.Error("[CustomPlayerEffect.Register] {type} is already registered!"); + return; + } + EffectsToRegister.Add(type); } From 323d7ca2a99fb00cef71eeedaa2ce1ff026dccaa Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:36:33 +0200 Subject: [PATCH 14/21] Version Bump: 3.5.0-beta1 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 24401c1..52706c7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  enable - 3.4.0 + 3.5.0-beta1 From 65b214c1bfe30bfb539213ac1754aa3cc63390c3 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:12:55 +0200 Subject: [PATCH 15/21] Version bump --- Directory.Build.props | 2 +- SecretAPI/SecretApi.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 52706c7..e8a7e85 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  enable - 3.5.0-beta1 + 3.5.0-beta2 diff --git a/SecretAPI/SecretApi.cs b/SecretAPI/SecretApi.cs index d1b14a6..bfeca84 100644 --- a/SecretAPI/SecretApi.cs +++ b/SecretAPI/SecretApi.cs @@ -1,7 +1,7 @@ /* Temp until 4.0 */ -#pragma warning disable SA1200 +#pragma warning disable SA1200 // Using directive should appear within a namespace declaration global using HarmonyPatchCategoryAttribute = HarmonyLib.HarmonyPatchCategory; #pragma warning restore SA1200 From 9f25e813660a40ff9643b6a9c554ab15c77e96cf Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Tue, 20 Oct 2026 14:53:50 +0200 Subject: [PATCH 16/21] Fix: Validation logic is incorrect + Invalid settings being registered in DefinedSettings --- SecretAPI.Examples/ExampleEntry.cs | 2 ++ SecretAPI/Features/UserSettings/CustomSetting.cs | 9 ++++++--- .../Features/Settings/ReportDefinedSettingPatch.cs | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/SecretAPI.Examples/ExampleEntry.cs b/SecretAPI.Examples/ExampleEntry.cs index 1839237..8c0afc1 100644 --- a/SecretAPI.Examples/ExampleEntry.cs +++ b/SecretAPI.Examples/ExampleEntry.cs @@ -2,10 +2,12 @@ using System; using HarmonyLib; +using LabApi.Features.Console; using LabApi.Loader.Features.Plugins; using SecretAPI.Examples.Settings; using SecretAPI.Extensions; using SecretAPI.Features.UserSettings; +using UserSettings.ServerSpecific; /// /// Defines the entry for the plugin. diff --git a/SecretAPI/Features/UserSettings/CustomSetting.cs b/SecretAPI/Features/UserSettings/CustomSetting.cs index 5715e44..2e51bc7 100644 --- a/SecretAPI/Features/UserSettings/CustomSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSetting.cs @@ -164,7 +164,7 @@ public static void Register(IEnumerable settings) { foreach (CustomSetting setting in settings) { - if (ValidateSettingInternal(setting, null)) + if (ValidateSettingInternal(setting, null, null)) CustomSettings.Add(setting); } } @@ -346,9 +346,12 @@ public static void SendSettingsToPlayer(Player player, int? version = null) /// /// The to validate. /// The to validate. + /// The current . /// Whether the setting is validated and considered fine. - internal static bool ValidateSettingInternal(CustomSetting? setting, ServerSpecificSettingBase? settingBase) + internal static bool ValidateSettingInternal(CustomSetting? setting, ServerSpecificSettingBase? settingBase, ServerSpecificSettingBase[]? definedSettings) { + definedSettings ??= ServerSpecificSettingsSync.DefinedSettings; + if (settingBase == null && setting == null) { Logger.Error("[CustomSetting.TryValidateSetting] Failed to validate null setting! " + new StackTrace(1)); @@ -362,7 +365,7 @@ internal static bool ValidateSettingInternal(CustomSetting? setting, ServerSpeci string validateSettingName = setting?.GetType().FullName ?? settingBase?.Label ?? "[Unknown]"; int? id = setting?.Id ?? settingBase?.SettingId; - string? sharedIdInfo = CustomSettings.FirstOrDefault(s => s.Id == id)?.GetType().FullName ?? ServerSpecificSettingsSync.DefinedSettings.FirstOrDefault(s => s.SettingId == id && s is not SSGroupHeader)?.Label; + string? sharedIdInfo = CustomSettings.FirstOrDefault(s => s.Id == id && setting != s)?.GetType().FullName ?? definedSettings.FirstOrDefault(s => s.SettingId == id && s != settingBase && s is not SSGroupHeader)?.Label; if (sharedIdInfo != null) { Logger.Error($"[CustomSetting.TryValidateSetting] {validateSettingName} is being registered with a duplicate ID ({id}) shared by {sharedIdInfo} {new StackTrace(1)}"); diff --git a/SecretAPI/Patches/Features/Settings/ReportDefinedSettingPatch.cs b/SecretAPI/Patches/Features/Settings/ReportDefinedSettingPatch.cs index 30ec0c5..acfd1b5 100644 --- a/SecretAPI/Patches/Features/Settings/ReportDefinedSettingPatch.cs +++ b/SecretAPI/Patches/Features/Settings/ReportDefinedSettingPatch.cs @@ -8,22 +8,22 @@ using UserSettings.ServerSpecific; /// -/// Logs issues with . +/// Logs issues with and prevents them being registered. /// [HarmonyPatchCategory(nameof(CustomSetting))] [HarmonyPatch(typeof(ServerSpecificSettingsSync), nameof(ServerSpecificSettingsSync.DefinedSettings), MethodType.Setter)] internal static class ReportDefinedSettingPatch { - private static void Postfix(ref ServerSpecificSettingBase[] value) + private static void Prefix(ref ServerSpecificSettingBase[] value) { - // OLD : value.ForEach(setting => CustomSetting.ValidateSettingInternal(null, setting)); List settings = ListPool.Shared.Rent(); foreach (ServerSpecificSettingBase setting in value) { - if (CustomSetting.ValidateSettingInternal(null, setting)) + if (CustomSetting.ValidateSettingInternal(null, setting, value)) settings.Add(setting); } value = settings.ToArray(); + ListPool.Shared.Return(settings); } } \ No newline at end of file From 1e1e434ed3556f0e5298bfbb03d1f7f4ddb2df2e Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:01:05 +0200 Subject: [PATCH 17/21] Version bump --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index e8a7e85..daaab19 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  enable - 3.5.0-beta2 + 3.5.0-beta.3 From d3eaaa11dbe925bfb723b6520f5296744630618f Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Fri, 6 Nov 2026 20:47:49 +0100 Subject: [PATCH 18/21] Fix: Effects registering failing incorrectly | Fixed type name not being output as part of error --- SecretAPI/Features/Effects/CustomPlayerEffect.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SecretAPI/Features/Effects/CustomPlayerEffect.cs b/SecretAPI/Features/Effects/CustomPlayerEffect.cs index 394d3a3..058fb1d 100644 --- a/SecretAPI/Features/Effects/CustomPlayerEffect.cs +++ b/SecretAPI/Features/Effects/CustomPlayerEffect.cs @@ -42,22 +42,22 @@ public static void Register() /// The to register. May not be abstract and must inherit . public static void Register(Type type) { - if (!type.IsAssignableFrom(typeof(StatusEffectBase))) + if (type.IsAbstract) { - Logger.Error($"[CustomPlayerEffect.Register] {type.FullName} does not inherit StatusEffectBase!"); + Logger.Error($"[CustomPlayerEffect.Register] {type.FullName} is abstract and cannot be registered!"); return; } - if (type.IsAbstract) + if (!typeof(StatusEffectBase).IsAssignableFrom(type)) { - Logger.Error($"[CustomPlayerEffect.Register] {type.FullName} is abstract!"); + Logger.Error($"[CustomPlayerEffect.Register] {type.FullName} does not inherit StatusEffectBase!"); return; } #pragma warning disable CS0618 // Type or member is obsolete if (EffectsToRegister.Contains(type)) { - Logger.Error("[CustomPlayerEffect.Register] {type} is already registered!"); + Logger.Error($"[CustomPlayerEffect.Register] {type.FullName} is already registered!"); return; } @@ -74,9 +74,9 @@ public static void Register(Type type) [CallOnLoad] internal static void Initialize() { - EffectsToRegister.Add(typeof(Energized)); - EffectsToRegister.Add(typeof(Depleted)); - EffectsToRegister.Add(typeof(BlastResistance)); + Register(); + Register(); + Register(); // it would probably be better to patch PlayerEffectsController::Awake instead of using sceneLoaded // this would also allow registering after players join From 93ba02eee77c3b999257ed5315c25d1a0b446f54 Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Sat, 7 Nov 2026 14:59:45 +0100 Subject: [PATCH 19/21] Harmony exception logger + Obsolete SafePatch(Type) --- SecretAPI/Config.cs | 12 +++++++ SecretAPI/Extensions/HarmonyExtensions.cs | 1 + SecretAPI/Patches/Features/HarmonyLogger.cs | 37 +++++++++++++++++++++ SecretAPI/SecretApi.cs | 6 +++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 SecretAPI/Config.cs create mode 100644 SecretAPI/Patches/Features/HarmonyLogger.cs diff --git a/SecretAPI/Config.cs b/SecretAPI/Config.cs new file mode 100644 index 0000000..1483b11 --- /dev/null +++ b/SecretAPI/Config.cs @@ -0,0 +1,12 @@ +namespace SecretAPI; + +/// +/// Handles config for SecretAPI. +/// +public sealed class Config +{ + /// + /// Gets or sets a value indicating whether PatchClassProcessor.ReportException should be edited to log instead of throwing exception. + /// + public bool LogHarmonyReplaceThrow { get; set; } = false; +} \ No newline at end of file diff --git a/SecretAPI/Extensions/HarmonyExtensions.cs b/SecretAPI/Extensions/HarmonyExtensions.cs index d44831f..fde6878 100644 --- a/SecretAPI/Extensions/HarmonyExtensions.cs +++ b/SecretAPI/Extensions/HarmonyExtensions.cs @@ -57,6 +57,7 @@ public void PatchAllNoCategory(Assembly? assembly = null) /// Attempts to safely patch a , logging any errors. /// /// The to attempt to patch. + [Obsolete] public void SafePatch(Type type) { try diff --git a/SecretAPI/Patches/Features/HarmonyLogger.cs b/SecretAPI/Patches/Features/HarmonyLogger.cs new file mode 100644 index 0000000..4f620e4 --- /dev/null +++ b/SecretAPI/Patches/Features/HarmonyLogger.cs @@ -0,0 +1,37 @@ +namespace SecretAPI.Patches.Features; + +using System; +using System.Collections.Generic; +using System.Reflection.Emit; +using HarmonyLib; +using LabApi.Features.Console; + +/// +/// Changes to log instead of throwing the exception. +/// +[HarmonyPatch(typeof(PatchClassProcessor), "ReportException")] +internal static class HarmonyLogger +{ + private static IEnumerable Transpiler(IEnumerable instructions) + { + CodeMatcher matcher = new(instructions); + + while (matcher.MatchEndForward(new CodeMatch(OpCodes.Throw)).IsValid) + { + CodeInstruction callInstruction = CodeInstruction.Call(typeof(HarmonyLogger), nameof(Log)); + callInstruction.labels.AddRange(matcher.Labels); + callInstruction.blocks.AddRange(matcher.Blocks); + + matcher.SetInstruction(callInstruction); + matcher.InsertAfter(new CodeInstruction(OpCodes.Ret)); + matcher.Advance(); + } + + return matcher.InstructionEnumeration(); + } + + private static void Log(Exception exception) + { + Logger.Error($"Prevented Harmony Exception: {exception.Message}"); + } +} \ No newline at end of file diff --git a/SecretAPI/SecretApi.cs b/SecretAPI/SecretApi.cs index bfeca84..edd0143 100644 --- a/SecretAPI/SecretApi.cs +++ b/SecretAPI/SecretApi.cs @@ -15,11 +15,12 @@ namespace SecretAPI; using LabApi.Loader.Features.Paths; using LabApi.Loader.Features.Plugins; using LabApi.Loader.Features.Plugins.Enums; +using SecretAPI.Patches.Features; /// /// Main class handling loading API. /// -public class SecretApi : Plugin +public class SecretApi : Plugin { /// public override string Name => "SecretAPI"; @@ -61,6 +62,9 @@ public class SecretApi : Plugin /// public override void Enable() { + if (Config.LogHarmonyReplaceThrow) + Harmony.CreateClassProcessor(typeof(HarmonyLogger)).Patch(); + SecretApiGenerated.OnLoad(); } From 7d56fd30025492d6083d6d5d8dae5f7d91cec22b Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Sat, 7 Nov 2026 21:14:56 +0100 Subject: [PATCH 20/21] Fix github action error --- SecretAPI/Patches/Features/HarmonyLogger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SecretAPI/Patches/Features/HarmonyLogger.cs b/SecretAPI/Patches/Features/HarmonyLogger.cs index 4f620e4..6b74ad5 100644 --- a/SecretAPI/Patches/Features/HarmonyLogger.cs +++ b/SecretAPI/Patches/Features/HarmonyLogger.cs @@ -7,7 +7,7 @@ using LabApi.Features.Console; /// -/// Changes to log instead of throwing the exception. +/// Changes 's ReportException to log instead of throwing the exception. /// [HarmonyPatch(typeof(PatchClassProcessor), "ReportException")] internal static class HarmonyLogger From b2317adec11cb57d59cfe65c3d289ff7afed81eb Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:51:54 +0100 Subject: [PATCH 21/21] Fix: Nuget workflow --- .github/workflows/nuget.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index ca52a08..c22172e 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -21,7 +21,13 @@ jobs: - name: Build run: dotnet build -c Release --output ${{ env.BUILD_OUTPUT }} + + - name: NuGet login (OIDC → temp API key) + uses: NuGet/login@v1 + id: login + with: + user: obvEve - name: Push NuGet package working-directory: ${{ env.BUILD_OUTPUT }} - run: dotnet nuget push SecretAPI.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json \ No newline at end of file + run: dotnet nuget push SecretAPI.*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json \ No newline at end of file