Skip to content

Commit 46cb6ff

Browse files
committed
Cleanup and docs
1 parent 741a6d9 commit 46cb6ff

File tree

12 files changed

+27
-25
lines changed

12 files changed

+27
-25
lines changed

SecretAPI.Examples/ExampleEntry.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/// </summary>
1414
public class ExampleEntry : Plugin
1515
{
16-
private Harmony? harmony;
16+
private readonly Assembly assembly = typeof(ExampleEntry).Assembly;
1717

1818
/// <inheritdoc/>
1919
public override string Name { get; } = "SecretAPI.Examples";
@@ -22,7 +22,7 @@ public class ExampleEntry : Plugin
2222
public override string Description { get; } = "An example plugin";
2323

2424
/// <inheritdoc/>
25-
public override string Author { get; } = "@misfiy";
25+
public override string Author { get; } = "@misfiy / @obvEvelyn";
2626

2727
/// <inheritdoc/>
2828
public override Version Version { get; } = typeof(SecretApi).Assembly.GetName().Version;
@@ -33,13 +33,7 @@ public class ExampleEntry : Plugin
3333
/// <inheritdoc/>
3434
public override void Enable()
3535
{
36-
Assembly assembly = typeof(ExampleEntry).Assembly;
37-
3836
CustomSetting.Register(new ExampleKeybindSetting(), new ExampleDropdownSetting());
39-
40-
harmony = new Harmony(nameof(ExampleEntry) + DateTime.Now.Ticks);
41-
harmony.PatchAllNoCategory(assembly);
42-
harmony.PatchCategory(nameof(ExampleEntry), assembly);
4337
}
4438

4539
/// <inheritdoc/>

SecretAPI.Examples/Patches/ExamplePatch.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
/*[HarmonyPatch]*/
1010
public static class ExamplePatch
1111
{
12+
// gets called before the original method is called
1213
private static bool Prefix()
1314
{
15+
// prevent original method from running
1416
return false;
1517
}
1618

19+
// gets called after the original method is called
1720
private static void Postfix()
1821
{
1922
}

SecretAPI.Examples/SecretAPI.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2" PrivateAssets="all" />
1111
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
12-
<PackageReference Include="Northwood.LabAPI" Version="1.1.1" IncludeAssets="All" PrivateAssets="All" />
12+
<PackageReference Include="Northwood.LabAPI" Version="1.1.3" IncludeAssets="All" PrivateAssets="All" />
1313
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" IncludeAssets="All" PrivateAssets="All" />
1414
</ItemGroup>
1515

SecretAPI.Examples/Settings/ExampleDropdownSetting.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
/// </summary>
1010
public class ExampleDropdownSetting : CustomDropdownSetting
1111
{
12-
private static string[] exampleOptions = ["hi", "test", "yum", "fish", "nugget"];
13-
private static string[] exampleSupporterOptions = ["bucket", "lava", "wanted", "globe"];
12+
private static readonly string[] ExampleOptions = ["hi", "test", "yum", "fish", "nugget"];
13+
private static readonly string[] ExampleSupporterOptions = ["bucket", "lava", "wanted", "globe"];
1414

1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="ExampleDropdownSetting"/> class.
1717
/// </summary>
1818
public ExampleDropdownSetting()
19-
: base(901, "Example dropdown", exampleOptions)
19+
: base(901, "Example dropdown", ExampleOptions)
2020
{
2121
}
2222

2323
/// <inheritdoc/>
24-
public override CustomHeader Header { get; } = CustomHeader.Examples;
24+
public override CustomHeader Header => CustomHeader.Examples;
2525

2626
/// <inheritdoc/>
2727
protected override CustomSetting CreateDuplicate() => new ExampleDropdownSetting();
@@ -32,7 +32,7 @@ protected override void PersonalizeSetting()
3232
if (KnownOwner == null || !KnownOwner.HasAnyPermission("example.supporter"))
3333
return;
3434

35-
Options = exampleSupporterOptions;
35+
Options = ExampleSupporterOptions;
3636
}
3737

3838
/// <inheritdoc/>

SecretAPI.Examples/Settings/ExampleKeybindSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ExampleKeybindSetting()
1717
}
1818

1919
/// <inheritdoc />
20-
public override CustomHeader Header { get; } = CustomHeader.Examples;
20+
public override CustomHeader Header => CustomHeader.Examples;
2121

2222
/// <inheritdoc />
2323
protected override CustomSetting CreateDuplicate() => new ExampleKeybindSetting();

SecretAPI/Features/IRegister.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface IRegister
2020
public void TryRegister();
2121

2222
/// <summary>
23-
/// Attemps to unregister the object.
23+
/// Attempts to unregister the object.
2424
/// </summary>
2525
public void TryUnregister()
2626
{

SecretAPI/Features/UserSettings/CustomDropdownSetting.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ protected CustomDropdownSetting(
4141
/// <inheritdoc/>
4242
public new SSDropdownSetting Base { get; }
4343

44+
/// <summary>
45+
/// Gets the index the client is claiming to have selected.
46+
/// </summary>
47+
/// <remarks>This is not validated, if you need it validated use <see cref="ValidatedSelectedIndex"/>.</remarks>
48+
public int SyncedIndex => Base.SyncSelectionIndexRaw;
49+
4450
/// <summary>
4551
/// Gets the selected index after validation.
4652
/// </summary>
47-
public int ValidatedSelectedIndex => Math.Clamp(Base.SyncSelectionIndexRaw, 0, Options.Length - 1);
53+
public int ValidatedSelectedIndex => Math.Clamp(SyncedIndex, 0, Options.Length - 1);
4854

4955
/// <summary>
5056
/// Gets or sets the options.

SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace SecretAPI.Features.UserSettings
22
{
3-
using System;
43
using global::UserSettings.ServerSpecific;
54
using TMPro;
65

SecretAPI/Features/UserSettings/CustomSetting.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,12 @@ private static void OnSettingsUpdated(ReferenceHub hub, ServerSpecificSettingBas
300300
if (setting == null || !setting.CanView(player))
301301
return;
302302

303+
// validate setting existence and then write data from client
303304
CustomSetting newSettingPlayer = EnsurePlayerSpecificSetting(player, setting);
304-
305-
// NetworkWriter entryWriter = new();
306-
// settingBase.SerializeEntry(entryWriter);
307-
// newSettingPlayer.Base.DeserializeEntry(new NetworkReader(entryWriter.buffer));
308305
NetworkWriterPooled valueWriter = NetworkWriterPool.Get();
309306
settingBase.SerializeValue(valueWriter);
310307
newSettingPlayer.Base.DeserializeValue(new NetworkReader(valueWriter.buffer));
308+
311309
NetworkWriterPool.Return(valueWriter);
312310

313311
newSettingPlayer.HandleSettingUpdate();

SecretAPI/Features/UserSettings/CustomSliderSetting.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace SecretAPI.Features.UserSettings
22
{
3-
using System;
43
using global::UserSettings.ServerSpecific;
54

65
/// <summary>

0 commit comments

Comments
 (0)