Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion SecretAPI.Examples/ExampleEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ExampleEntry : Plugin
/// <inheritdoc/>
public override void Enable()
{
CustomSetting.Register(new ExampleKeybindSetting(), new ExampleDropdownSetting());
CustomSetting.Register(new ExampleKeybindSetting(), new ExampleDropdownSetting(), new ExampleButtonSetting(), new ExampleFakeSyncButton());
}

/// <inheritdoc/>
Expand Down
38 changes: 38 additions & 0 deletions SecretAPI.Examples/Settings/ExampleButtonSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace SecretAPI.Examples.Settings;

using LabApi.Features.Wrappers;
using SecretAPI.Features.Effects;
using SecretAPI.Features.UserSettings;

/// <summary>
/// Example version of <see cref="CustomButtonSetting"/>.
/// </summary>
public class ExampleButtonSetting : CustomButtonSetting
{
/// <summary>
/// Initializes a new instance of the <see cref="ExampleButtonSetting"/> class.
/// </summary>
public ExampleButtonSetting()
: base(typeof(ExampleButtonSetting).FullName?.GetHashCode(), "Example Button", "Press!!")
{
}

/// <inheritdoc />
public override CustomHeader Header => CustomHeader.Examples;

/// <inheritdoc/>
protected override bool CanView(Player player) => player.RemoteAdminAccess;

/// <inheritdoc />
protected override CustomSetting CreateDuplicate() => new ExampleButtonSetting();

/// <inheritdoc />
protected override void HandleSettingUpdate()
{
if (KnownOwner == null)
return;

KnownOwner.EnableEffect<Depleted>(duration: 30);
KnownOwner.EnableEffect<BlastResistance>(200, 30);
}
}
2 changes: 1 addition & 1 deletion SecretAPI.Examples/Settings/ExampleDropdownSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExampleDropdownSetting : CustomDropdownSetting
/// Initializes a new instance of the <see cref="ExampleDropdownSetting"/> class.
/// </summary>
public ExampleDropdownSetting()
: base(901, "Example dropdown", ExampleOptions)
: base(typeof(ExampleDropdownSetting).FullName?.GetHashCode(), "Example dropdown", ExampleOptions)
{
}

Expand Down
53 changes: 53 additions & 0 deletions SecretAPI.Examples/Settings/ExampleFakeSyncButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace SecretAPI.Examples.Settings;

using LabApi.Features.Wrappers;
using MEC;
using Mirror;
using SecretAPI.Extensions;
using SecretAPI.Features.UserSettings;

/// <summary>
/// Example version for fake syncing on a <see cref="CustomButtonSetting"/>.
/// </summary>
public class ExampleFakeSyncButton : CustomButtonSetting
{
/// <summary>
/// Initializes a new instance of the <see cref="ExampleFakeSyncButton"/> class.
/// </summary>
public ExampleFakeSyncButton()
: base(typeof(ExampleFakeSyncButton).FullName?.GetHashCode(), "Example Fake Sync Button", "Fake!")
{
}

/// <inheritdoc />
public override CustomHeader Header => CustomHeader.Examples;

/// <inheritdoc/>
protected override bool CanView(Player player) => player.RemoteAdminAccess;

/// <inheritdoc />
protected override CustomSetting CreateDuplicate() => new ExampleFakeSyncButton();

/// <inheritdoc />
protected override void HandleSettingUpdate()
{
if (KnownOwner == null)
return;

TextToy textToy = TextToy.Create(KnownOwner.Position, KnownOwner.Rotation);
textToy.TextFormat = "{0}";
textToy.Arguments.Add("Default Text!");

Timing.CallDelayed(5, () =>
{
MirrorExtensions.SyncListChange<string> change = new()
{
Operation = SyncList<string>.Operation.OP_SET,
Index = 0,
Item = "Fake synced text!",
};

KnownOwner.SendFakeSyncListData(textToy.Base, 1L, change);
});
}
}
2 changes: 1 addition & 1 deletion SecretAPI.Examples/Settings/ExampleKeybindSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ExampleKeybindSetting : CustomKeybindSetting
/// Initializes a new instance of the <see cref="ExampleKeybindSetting"/> class.
/// </summary>
public ExampleKeybindSetting()
: base(900, "Example Kill Button", KeyCode.G, allowSpectatorTrigger: false)
: base(typeof(ExampleKeybindSetting).FullName?.GetHashCode(), "Example Kill Button", KeyCode.G, allowSpectatorTrigger: false)
{
}

Expand Down
4 changes: 2 additions & 2 deletions SecretAPI/Debugging/PatchDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace SecretAPI.Debugging;
using SecretAPI.Attributes;

/// <summary>
/// Patch debugger.
/// Ensures all patches are loaded for debug purposes.
/// </summary>
internal static class PatchDebugger
{
/// <summary>
/// Loads the debugs for patches and ensures all patches have loaded.
/// Loads the debug.
/// </summary>
[CallOnLoad]
internal static void Load()
Expand Down
14 changes: 11 additions & 3 deletions SecretAPI/Debugging/PrefabDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ namespace SecretAPI.Debugging;

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using HarmonyLib;
using LabApi.Events.Handlers;
using LabApi.Loader.Features.Paths;
using Mirror;
using SecretAPI.Attributes;
using SecretAPI.Features;
using UnityEngine;
using Logger = LabApi.Features.Console.Logger;

/// <summary>
/// Debugs basegame prefabs by logging information about them.
/// Debugs base-game prefabs by logging information about them.
/// </summary>
//? Possibly write to file instead of server console?
// ? Possibly write to file instead of server console?
internal static class PrefabDebugger
{
/// <summary>
Expand All @@ -29,6 +32,7 @@ internal static void Load()

private static void OnWaiting()
{
List<string> logTexts = new();
foreach (PropertyInfo properties in typeof(PrefabManager).GetProperties())
{
try
Expand All @@ -44,8 +48,12 @@ private static void OnWaiting()

foreach (KeyValuePair<uint, GameObject> pair in NetworkClient.prefabs)
{
Logger.Debug($"[PrefabDebugging] Key ({pair.Key}) - Value ({pair.Value.name})");
// Logger.Debug(txt);
string txt = $"Prefab Key ({pair.Key}) - Value ({pair.Value.name})";
logTexts.Add(txt);
}

File.WriteAllLines(Path.Combine(SecretApi.ConfigDirectory.FullName, "debug_prefabs.txt"), logTexts);
}
}

Expand Down
7 changes: 1 addition & 6 deletions SecretAPI/Extensions/CodeMatcherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ public static class CodeMatcherExtensions
/// </summary>
/// <param name="backtrackCount">The amount to reverse. Must be positive number.</param>
/// <returns>The current <see cref="CodeMatcher"/>.</returns>
public CodeMatcher EndAndBacktrack(int backtrackCount)
{
matcher.End();
matcher.Advance(-backtrackCount);
return matcher;
}
public CodeMatcher EndAndBacktrack(int backtrackCount) => matcher.End().Advance(-backtrackCount);

/// <summary>
/// Declares a local to be used of a certain <see cref="Type"/>.
Expand Down
Loading
Loading