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
This commit is contained in:
parent
34e72da748
commit
13fd51c366
|
@ -20,6 +20,7 @@
|
||||||
of generating code at compile time. See https://github.com/lc-sigurd/CSync/issues/11
|
of generating code at compile time. See https://github.com/lc-sigurd/CSync/issues/11
|
||||||
-->
|
-->
|
||||||
<PackageReference Include="Sigurd.BepInEx.CSync" Version="5.0.1" Publicize="true" />
|
<PackageReference Include="Sigurd.BepInEx.CSync" Version="5.0.1" Publicize="true" />
|
||||||
|
<PackageReference Include="AinaVT-LethalConfig" Version="1.4.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -7,6 +7,9 @@ using BepInEx;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using CSync.Extensions;
|
using CSync.Extensions;
|
||||||
using CSync.Lib;
|
using CSync.Lib;
|
||||||
|
using LethalConfig;
|
||||||
|
using LethalConfig.ConfigItems;
|
||||||
|
using LethalConfig.ConfigItems.Options;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
@ -15,6 +18,7 @@ namespace MuzikaGromche
|
||||||
{
|
{
|
||||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||||
[BepInDependency("com.sigurd.csync", "5.0.1")]
|
[BepInDependency("com.sigurd.csync", "5.0.1")]
|
||||||
|
[BepInDependency("ainavt.lc.lethalconfig", "1.4.6")]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
internal new static Config Config { get; private set; } = null;
|
internal new static Config Config { get; private set; } = null;
|
||||||
|
@ -299,6 +303,13 @@ namespace MuzikaGromche
|
||||||
new ConfigDefinition("Tracks", track.Name),
|
new ConfigDefinition("Tracks", track.Name),
|
||||||
50,
|
50,
|
||||||
new ConfigDescription(description, chanceRange, track));
|
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
|
// HACK because CSync doesn't provide an API to register a list of config entries
|
||||||
|
@ -312,6 +323,24 @@ namespace MuzikaGromche
|
||||||
|
|
||||||
ConfigManager.Register(this);
|
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))]
|
[HarmonyPatch(typeof(JesterAI))]
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
|
<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>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
"website_url": "https://git.vilunov.me/nikita/muzika-gromche",
|
"website_url": "https://git.vilunov.me/nikita/muzika-gromche",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"BepInEx-BepInExPack-5.4.2100",
|
"BepInEx-BepInExPack-5.4.2100",
|
||||||
"Sigurd-CSync-5.0.1"
|
"Sigurd-CSync-5.0.1",
|
||||||
|
"ainavt.lc.lethalconfig-1.4.6"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue