chore(all): resolve lint findings, update example plugin, refine docs and add LGPL licenses
This commit is contained in:
@@ -2,11 +2,24 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<!-- Adjust these settings as needed. -->
|
||||
<EnableNETAnalyzers>false</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
|
||||
<AssemblyName>ExamplePlugin</AssemblyName>
|
||||
<BD2GameVersion>2.35.10</BD2GameVersion>
|
||||
<BD2ManagedDir Condition="'$(BD2ManagedDir)' == ''">$(GameDir)/BrownDust II_Data/Managed</BD2ManagedDir>
|
||||
<!-- GameDir belongs in local Directory.Build.props or on the command line. -->
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BD2.GameSdk" Version="0.2.1-game.2.35.10" PrivateAssets="all" />
|
||||
<PackageReference Include="BD2.GameSdk" Version="0.2.2-game.2.35.10" PrivateAssets="all" />
|
||||
<!-- Adjust these references as needed. -->
|
||||
<Reference Include="Unity.TextMeshPro">
|
||||
<HintPath>$(BD2ManagedDir)/Unity.TextMeshPro.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>$(BD2ManagedDir)/UnityEngine.UI.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<!-- Repository sample consumes the packages produced by GameSdk/Pack.ps1. -->
|
||||
<!-- Repository sample consumes the packages produced by bd2w sdk pack. -->
|
||||
<add key="bd2-local" value="../../../../.build/nuget" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
|
||||
@@ -3,36 +3,31 @@ using System.Reflection;
|
||||
using BD2.GameNames;
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using TMPro;
|
||||
|
||||
namespace ExamplePlugin;
|
||||
|
||||
[BepInPlugin("example.readable-names", "Readable Names Example", "1.0.0")]
|
||||
[BepInPlugin("example.plugin", "example plugin", "1.0.0")]
|
||||
public sealed class Plugin : BaseUnityPlugin
|
||||
{
|
||||
private Harmony harmony;
|
||||
private const string Greeting = "\nHello! Brown Dust Ⅱ";
|
||||
private static FieldInfo versionTextField;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Fail before installing any game patches when binary/table/plugin versions differ.
|
||||
Game.Validate(typeof(Plugin).Assembly, message => Logger.LogInfo(message));
|
||||
MethodInfo target = Game.Method<IntroUI>(ui => ui.SendMaintenanceInfo(false));
|
||||
harmony = new Harmony("example.readable-names");
|
||||
harmony.Patch(target, prefix: new HarmonyMethod(typeof(Plugin), nameof(BeforeMaintenance)));
|
||||
|
||||
// Private members require the runtime string channel. The prefix expression above
|
||||
// and the Unity callback name below belong to separate channels.
|
||||
var awake = typeof(IntroUI).GetGameMethod("Awake",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
|
||||
Logger.LogInfo("Resolved IntroUI.Awake: " + (awake != null));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.LogError("Readable Names Example initialization failed: " + exception);
|
||||
}
|
||||
Game.Validate(typeof(Plugin).Assembly);
|
||||
MethodInfo target = Game.Method<IntroUI>(ui => ui.SetVersionText());
|
||||
versionTextField = typeof(IntroUI).GetGameField("_textVersion", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
?? throw new MissingFieldException("IntroUI._textVersion");
|
||||
var harmony = new Harmony("example.plugin");
|
||||
harmony.Patch(target, postfix: new HarmonyMethod(typeof(Plugin), nameof(AfterSetVersionText)));
|
||||
}
|
||||
|
||||
private static void BeforeMaintenance() { }
|
||||
private void OnDestroy() => harmony?.UnpatchSelf();
|
||||
private static void AfterSetVersionText(IntroUI __instance)
|
||||
{
|
||||
if (versionTextField.GetValue(__instance) is not TMP_Text versionText) return;
|
||||
string current = versionText.text ?? string.Empty;
|
||||
if (current.EndsWith(Greeting, StringComparison.Ordinal)) return;
|
||||
versionText.text = current + Greeting;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user