WIP: Add LethalConfig with suitable custom options

Draft because needs testing in multiplayer environment. Apparently,
both isClinet and isHost are true in single player.

FIXME:
If LethalConfig panel opened while orbiting, and then the round has started, it would still
be possible to modify the values at least once. This is presumably a bug in LethalConfig,
because it doesn't check the callback again before actually applying the change.
This commit is contained in:
ivan tkachenko 2025-07-12 04:49:20 +03:00
parent 26fb620173
commit 54e88b08a8
4 changed files with 33 additions and 1 deletions

View File

@ -17,6 +17,7 @@
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" />
<!-- Publicize internal methods, so we could generate config entries for tracks at runtime instead of generating code at compile time -->
<PackageReference Include="Sigurd.BepInEx.CSync" Version="5.0.1" Publicize="true" />
<PackageReference Include="AinaVT-LethalConfig" Version="1.4.6" />
</ItemGroup>
<ItemGroup>

View File

@ -7,6 +7,9 @@ using BepInEx;
using BepInEx.Configuration;
using CSync.Extensions;
using CSync.Lib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
@ -15,6 +18,7 @@ namespace MuzikaGromche
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInDependency("com.sigurd.csync", "5.0.1")]
[BepInDependency("ainavt.lc.lethalconfig", "1.4.6")]
public class Plugin : BaseUnityPlugin
{
internal new static Config Config { get; private set; } = null;
@ -299,6 +303,13 @@ namespace MuzikaGromche
new ConfigDefinition("Tracks", track.Name),
50,
new ConfigDescription(description, chanceRange, track));
var slider = new IntSliderConfigItem(track.Weight.Entry, new IntSliderOptions
{
RequiresRestart = false,
CanModifyCallback = CanModifyCallback,
});
LethalConfigManager.AddConfigItem(slider);
}
// HACK because CSync doesn't provide an API to register a list of config entries
@ -311,6 +322,24 @@ namespace MuzikaGromche
ConfigManager.Register(this);
}
public static CanModifyResult CanModifyCallback()
{
var startOfRound = StartOfRound.Instance;
if (!startOfRound)
{
return CanModifyResult.True(); // Main menu
}
if (!startOfRound.IsHost)
{
return CanModifyResult.False("Only for host");
}
if (!startOfRound.inShipPhase)
{
return CanModifyResult.False("Only while orbiting");
}
return CanModifyResult.True();
}
}
[HarmonyPatch(typeof(JesterAI))]

View File

@ -2,5 +2,6 @@
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
<add key="AAron Thunderstore" value="https://nuget.windows10ce.com/nuget/v3/index.json" />
</packageSources>
</configuration>

View File

@ -6,6 +6,7 @@
"website_url": "https://git.vilunov.me/nikita/muzika-gromche",
"dependencies": [
"BepInEx-BepInExPack-5.4.2100",
"Sigurd-CSync-5.0.1"
"Sigurd-CSync-5.0.1",
"ainavt.lc.lethalconfig-1.4.6"
]
}