Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3a19c31
Le harmony update
obvEve Sep 16, 2026
c6faf19
Lib.Harmony.Thin
obvEve Sep 16, 2026
0efa6b2
DecalHelpers.CleanUpDecals
obvEve Sep 16, 2026
5ce0662
Obsolete
obvEve Sep 16, 2026
754015c
Remove publicize
obvEve Sep 16, 2026
28eda5a
Use: HarmonyArgument
obvEve Sep 16, 2026
f20ef45
CopyDll
obvEve Sep 16, 2026
15ad173
Merge branch 'dev' into harmony-update
obvEve Sep 17, 2026
9c6e0a7
Remove breaking change
obvEve Sep 17, 2026
2021673
IRegister: Support IPriority
obvEve Sep 21, 2026
645e75e
Obsolete Registry<T>
obvEve Sep 21, 2026
99f7451
CustomButtonSetting::TimesPressed
obvEve Sep 21, 2026
1245ace
Merge branch 'dev' into harmony-update
obvEve Sep 21, 2026
a50eb46
3.5.0-beta1 bump
obvEve Sep 24, 2026
afc7e84
Extra condition to CustomPlayerEffect.Register(Type)
obvEve Oct 13, 2026
323d7ca
Version Bump: 3.5.0-beta1
obvEve Oct 13, 2026
b9422f0
Merge branch 'dev' into harmony-update
obvEve Oct 13, 2026
65b214c
Version bump
obvEve Oct 14, 2026
9f25e81
Fix: Validation logic is incorrect + Invalid settings being registere…
obvEve Oct 20, 2026
73b7dd3
Merge branch 'dev' into harmony-update
obvEve Oct 20, 2026
1e1e434
Version bump
obvEve Oct 20, 2026
d3eaaa1
Fix: Effects registering failing incorrectly | Fixed type name not be…
obvEve Nov 6, 2026
93ba02e
Harmony exception logger + Obsolete SafePatch(Type)
obvEve Nov 7, 2026
7d56fd3
Fix github action error
obvEve Nov 7, 2026
819d6d5
Merge pull request #112 from obvEve/harmony-update
obvEve Nov 14, 2026
28bee27
Merge branch 'main' into dev
obvEve Nov 14, 2026
9b40e82
Merge branch 'main' into dev
obvEve Nov 14, 2026
b2317ad
Fix: Nuget workflow
obvEve Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
run: dotnet nuget push SecretAPI.*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<Version>3.4.1</Version>
<Version>3.5.0-beta.3</Version> <!-- BetaX = Incorrect (3.5.0-beta3) | Beta.X = Correct (3.5.0-beta.3) -->
</PropertyGroup>

<PropertyGroup Label="Nuget">
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
<WriteLinesToFile File="$(Props)" Lines="$(Template)" Condition="!Exists($(Props))" />
<Error Text="The ReferencePath property is not specified! Make sure to set the property in the ReferencePath.props.user file." />
</Target>

<!-- Output dlls into Build folder -->
<Target Name="CopyDll" AfterTargets="Build">
<Copy SourceFiles="$(OutDir)$(TargetFileName)" DestinationFolder="$(SolutionDir)/.builds" />
</Target>
</Project>
20 changes: 17 additions & 3 deletions SecretAPI.Examples/ExampleEntry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
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;
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;

/// <summary>
/// Defines the entry for the plugin.
Expand All @@ -29,11 +38,16 @@ public class ExampleEntry : Plugin
/// <inheritdoc/>
public override Version RequiredApiVersion { get; } = new(LabApi.Features.LabApiProperties.CompiledVersion);

/// <summary>
/// Gets the <see cref="Assembly"/> of SecretAPI.Examples.
/// </summary>
internal Assembly Assembly { get; } = typeof(ExampleEntry).Assembly;

/// <inheritdoc/>
public override void Enable()
{
CustomSetting.Register(new ExampleKeybindSetting(), new ExampleDropdownSetting(), new ExampleButtonSetting(), new ExampleFakeSyncButton());
harmony.PatchCategory(nameof(ExampleFakeSyncButton));
harmony.PatchCategory(Assembly, nameof(ExampleFakeSyncButton));
}

/// <inheritdoc/>
Expand Down
8 changes: 3 additions & 5 deletions SecretAPI.Examples/Patches/ExampleAmmoPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 1 addition & 4 deletions SecretAPI.Examples/SecretAPI.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

<ItemGroup>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2" PrivateAssets="all" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<!--
<PackageReference Include="Northwood.LabAPI" Version="1.1.4" IncludeAssets="All" PrivateAssets="All" />
-->
<PackageReference Include="Lib.Harmony" Version="2.4.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" IncludeAssets="All" PrivateAssets="All" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion SecretAPI/Attributes/HarmonyPatchCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
/// Category handling for <see cref="HarmonyExtensions"/>.
/// </summary>
[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
{
/// <summary>
/// Initializes a new instance of the <see cref="HarmonyPatchCategory"/> class.
/// </summary>
/// <param name="category">The category of the patch.</param>
public HarmonyPatchCategory(string category)
: base(category)
{
Category = category;
}
Expand Down
12 changes: 12 additions & 0 deletions SecretAPI/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SecretAPI;

/// <summary>
/// Handles config for SecretAPI.
/// </summary>
public sealed class Config
{
/// <summary>
/// Gets or sets a value indicating whether PatchClassProcessor.ReportException should be edited to log instead of throwing exception.
/// </summary>
public bool LogHarmonyReplaceThrow { get; set; } = false;
}
11 changes: 4 additions & 7 deletions SecretAPI/Extensions/CodeMatcherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ public static class CodeMatcherExtensions
/// <param name="localType">The <see cref="Type"/> of the local to declare.</param>
/// <param name="localBuilder">The <see cref="LocalBuilder"/> declared.</param>
/// <returns>The current <see cref="CodeMatcher"/>.</returns>
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);

/// <summary>
/// Declares a local to be used of a certain <see cref="Type"/>.
Expand All @@ -39,7 +36,7 @@ public CodeMatcher DeclareLocal(Type localType, out LocalBuilder localBuilder)
/// <returns>The current <see cref="CodeMatcher"/>.</returns>
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;
}
Expand All @@ -63,7 +60,7 @@ public CodeMatcher GetFirstLabel(out Label label)
/// <returns>The current <see cref="CodeMatcher"/>.</returns>
public CodeMatcher GetFirstLabelAt(int position, out Label label)
{
label = matcher.codes[position].labels.FirstOrDefault();
label = matcher.Instructions()[position].labels.FirstOrDefault();
return matcher;
}
}
Expand Down
17 changes: 11 additions & 6 deletions SecretAPI/Extensions/HarmonyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,43 @@ public static class HarmonyExtensions
/// </summary>
/// <param name="category">The category to patch.</param>
/// <param name="assembly">The assembly to find patches in.</param>
[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<HarmonyPatchCategory> categories = type.GetCustomAttributes<HarmonyPatchCategory>();
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));*/
}

/// <summary>
/// Patches all patches that don't have a <see cref="HarmonyPatchCategory"/>.
/// </summary>
/// <param name="assembly">The assembly to look for patches.</param>
[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<HarmonyPatchCategory> categories = type.GetCustomAttributes<HarmonyPatchCategory>();
return !categories.Any();
})
.Do(type => SafePatch(harmony, type));
.Do(type => SafePatch(harmony, type));*/
}

/// <summary>
/// Attempts to safely patch a <see cref="Type"/>, logging any errors.
/// </summary>
/// <param name="type">The <see cref="Type"/> to attempt to patch.</param>
[Obsolete]
public void SafePatch(Type type)
{
try
Expand All @@ -61,7 +66,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}");
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions SecretAPI/Features/DecalHelpers.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

/// <summary>
/// Cleans up decals for all players.
/// </summary>
/// <param name="decalType">The <see cref="DecalPoolType"/> to cleanup.</param>
/// <param name="amount">The amount of that decal to cleanup.</param>
public static void CleanupDecals(DecalPoolType decalType, int amount = int.MaxValue) => new DecalCleanupMessage(decalType, amount).SendToAuthenticated();

/// <summary>
/// Cleans up decals for a specific player.
/// </summary>
/// <param name="player">The player to clean up decals for.</param>
/// <param name="decalType">The <see cref="DecalPoolType"/> to cleanup.</param>
/// <param name="amount">The amount of that decal to cleanup.</param>
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)
Expand Down
6 changes: 3 additions & 3 deletions SecretAPI/Features/Effects/CustomPlayerEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Energized>();
Register<Depleted>();
Register<BlastResistance>();

// it would probably be better to patch PlayerEffectsController::Awake instead of using sceneLoaded
// this would also allow registering after players join
Expand Down
2 changes: 1 addition & 1 deletion SecretAPI/Features/IPriority.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SecretAPI.Features;

/// <summary>
/// Handles IPriority.
/// Handles priority on certain things.
/// </summary>
public interface IPriority
{
Expand Down
13 changes: 10 additions & 3 deletions SecretAPI/Features/IRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

/// <summary>
/// Interface used to define a type that should auto register.
/// </summary>
/// <remarks>This supports <see cref="IPriority"/>, will default to 0 if not implemented.</remarks>
// TODO: Source generate this
public interface IRegister
{
Expand All @@ -25,7 +27,7 @@ public interface IRegister
/// </summary>
public void TryUnregister()
{
// default empty to prevent breaking change
// default to empty
}

/// <summary>
Expand All @@ -38,6 +40,7 @@ public static void RegisterAll(Assembly? assembly = null)

registerables.TryAdd(assembly, new());

List<IRegister> registers = new();
foreach (Type type in assembly.GetTypes())
{
if (type.IsAbstract || type.IsInterface)
Expand All @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions SecretAPI/Features/Registry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace SecretAPI.Features;

using System;
using System.Collections.Generic;

/// <summary>
/// Handles the registration of objects and ids.
/// </summary>
/// <typeparam name="T">The type of the registry.</typeparam>
[Obsolete("This will be removed in 4.0")]
public static class Registry<T>
{
/// <summary>
Expand Down
Loading
Loading