From 766e393a58c1192a90f557cf2d2fb99be2339db0 Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Sat, 12 Jul 2025 04:49:20 +0300 Subject: [PATCH] Add LethalConfig with suitable custom options The custom callback attempts to prevent modifications mid-round. Use IsHost to check for permissions, as IsClient is always true for everyone even in local single-player setting. There is a bug in LethalConfig which makes it possible to modify entries bypassing the callback once per round, but it is pretty hard to abuse: https://github.com/AinaVT/LethalConfig/issues/60 --- MuzikaGromche/MuzikaGromche.csproj | 1 + MuzikaGromche/Plugin.cs | 29 +++++++++++++++++++++++++++++ NuGet.Config | 1 + manifest.json | 3 ++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/MuzikaGromche/MuzikaGromche.csproj b/MuzikaGromche/MuzikaGromche.csproj index 0c60c9e..e555969 100644 --- a/MuzikaGromche/MuzikaGromche.csproj +++ b/MuzikaGromche/MuzikaGromche.csproj @@ -17,6 +17,7 @@ + diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 048554b..565567f 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -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 = CanModifyWeightsNow, + }); + 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 CanModifyWeightsNow() + { + 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))] diff --git a/NuGet.Config b/NuGet.Config index fffd918..a58b3de 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,5 +2,6 @@ + diff --git a/manifest.json b/manifest.json index c6b419f..e9b793f 100644 --- a/manifest.json +++ b/manifest.json @@ -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" ] }