mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Remove check invalid setting (no needed) (#606)
This commit is contained in:
1 parent
89de63729b
commit
1c9a229f69
6 files changed
+16
-95
No files matched your search
@@ -19,7 +19,7 @@ public abstract class GameOptionsSender
|
||||
|
||||
private Il2CppStructArray<byte> BuildOptionArray()
|
||||
{
|
||||
IGameOptions opt = BuildSendableGameOptions();
|
||||
IGameOptions opt = BuildGameOptions();
|
||||
var currentGameMode = AprilFoolsMode.IsAprilFoolsModeToggledOn ? opt.AprilFoolsOnMode : opt.GameMode;
|
||||
|
||||
// option => byte[]
|
||||
@@ -109,59 +109,6 @@ public abstract class GameOptionsSender
|
||||
}
|
||||
|
||||
public abstract IGameOptions BuildGameOptions();
|
||||
|
||||
protected IGameOptions BuildSendableGameOptions()
|
||||
{
|
||||
return SanitizeForOfficialServer(BuildGameOptions());
|
||||
}
|
||||
|
||||
protected static IGameOptions SanitizeForOfficialServer(IGameOptions opt)
|
||||
{
|
||||
if (CurrentServerType != ServerType.Vanilla || opt == null || !opt.TryCast(out NormalGameOptionsV10 normalOpt))
|
||||
return opt;
|
||||
|
||||
int originalMaxPlayers = normalOpt.MaxPlayers;
|
||||
int originalImpostors = normalOpt.NumImpostors;
|
||||
int originalKillDistance = normalOpt.KillDistance;
|
||||
float originalPlayerSpeed = normalOpt.PlayerSpeedMod;
|
||||
bool changed = false;
|
||||
|
||||
if (normalOpt.MaxPlayers > 15)
|
||||
{
|
||||
normalOpt.SetInt(Int32OptionNames.MaxPlayers, 15);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int impostors = Mathf.Clamp(normalOpt.NumImpostors, 1, 3);
|
||||
if (impostors != normalOpt.NumImpostors)
|
||||
{
|
||||
normalOpt.SetInt(Int32OptionNames.NumImpostors, impostors);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int killDistance = Mathf.Clamp(normalOpt.KillDistance, 0, 2);
|
||||
if (killDistance != normalOpt.KillDistance)
|
||||
{
|
||||
normalOpt.SetInt(Int32OptionNames.KillDistance, killDistance);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
float playerSpeed = Mathf.Clamp(normalOpt.PlayerSpeedMod, Main.MinSpeed, 3f);
|
||||
if (!Mathf.Approximately(playerSpeed, normalOpt.PlayerSpeedMod))
|
||||
{
|
||||
normalOpt.SetFloat(FloatOptionNames.PlayerSpeedMod, playerSpeed);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
Logger.Warn(
|
||||
$"Clamped outgoing official game options: MaxPlayers={originalMaxPlayers}->{normalOpt.MaxPlayers}, NumImpostors={originalImpostors}->{normalOpt.NumImpostors}, KillDistance={originalKillDistance}->{normalOpt.KillDistance}, PlayerSpeedMod={originalPlayerSpeed:0.###}->{normalOpt.PlayerSpeedMod:0.###}",
|
||||
nameof(GameOptionsSender));
|
||||
}
|
||||
|
||||
return normalOpt.CastFast<IGameOptions>();
|
||||
}
|
||||
|
||||
protected virtual bool AmValid()
|
||||
{
|
||||
|
||||
@@ -110,7 +110,7 @@ public sealed class PlayerGameOptionsSender(PlayerControl player) : GameOptionsS
|
||||
{
|
||||
if (player.AmOwner)
|
||||
{
|
||||
IGameOptions opt = BuildSendableGameOptions();
|
||||
IGameOptions opt = BuildGameOptions();
|
||||
|
||||
if (GameManager.Instance?.LogicComponents != null)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ public sealed class PlayerGameOptionsSender(PlayerControl player) : GameOptionsS
|
||||
{
|
||||
if (player.AmOwner)
|
||||
{
|
||||
IGameOptions opt = BuildSendableGameOptions();
|
||||
IGameOptions opt = BuildGameOptions();
|
||||
|
||||
if (GameManager.Instance?.LogicComponents != null)
|
||||
{
|
||||
|
||||
+2
-5
@@ -98,7 +98,7 @@ internal static class Crowded
|
||||
playerButton.OnClick.AddListener((Action)(() =>
|
||||
{
|
||||
byte maxPlayers = byte.Parse(text.text);
|
||||
int maxImp = Math.Clamp(Mathf.Min(__instance.GetTargetOptions().NumImpostors, maxPlayers / 2), 1, 3);
|
||||
int maxImp = Mathf.Min(__instance.GetTargetOptions().NumImpostors, maxPlayers / 2);
|
||||
__instance.GetTargetOptions().SetInt(Int32OptionNames.NumImpostors, maxImp);
|
||||
__instance.ImpostorButtons[1].TextMesh.text = maxImp.ToString();
|
||||
__instance.SetMaxPlayersButtons(maxPlayers);
|
||||
@@ -379,10 +379,7 @@ internal static class Crowded
|
||||
if (CurrentGameOptions.MaxPlayers > 15)
|
||||
CurrentGameOptions.SetInt(Int32OptionNames.MaxPlayers, 15);
|
||||
|
||||
if (CurrentGameOptions.NumImpostors > 3)
|
||||
CurrentGameOptions.SetInt(Int32OptionNames.NumImpostors, 3);
|
||||
|
||||
if (CurrentGameOptions.NumImpostors < 1)
|
||||
if (CurrentGameOptions.NumImpostors < 0)
|
||||
CurrentGameOptions.SetInt(Int32OptionNames.NumImpostors, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@ public static class ToggleOptionPatch
|
||||
[HarmonyPatch(typeof(NumberOption))]
|
||||
public static class NumberOptionPatch
|
||||
{
|
||||
private static bool IsVanillaServer => GameStates.CurrentServerType == GameStates.ServerType.Vanilla;
|
||||
//private static bool IsVanillaServer => GameStates.CurrentServerType == GameStates.ServerType.Vanilla;
|
||||
|
||||
private static int IncrementMultiplier
|
||||
{
|
||||
@@ -669,9 +669,6 @@ public static class NumberOptionPatch
|
||||
__instance.Value = (float)Math.Round(__instance.Value, 2);
|
||||
break;
|
||||
case StringNames.GamePlayerSpeed:
|
||||
if (IsVanillaServer)
|
||||
__instance.ValidRange = new(Main.MinSpeed, 3f);
|
||||
|
||||
__instance.Increment = 0.05f;
|
||||
__instance.Value = Mathf.Clamp((float)Math.Round(__instance.Value, 2), __instance.ValidRange.min, __instance.ValidRange.max);
|
||||
break;
|
||||
@@ -681,13 +678,12 @@ public static class NumberOptionPatch
|
||||
__instance.Value = (float)Math.Round(__instance.Value, 2);
|
||||
break;
|
||||
case StringNames.GameNumImpostors:
|
||||
__instance.ValidRange = GameStates.CurrentServerType != GameStates.ServerType.Vanilla
|
||||
? new(0, Crowded.MaxImpostors) : new(1, 3);
|
||||
__instance.ValidRange = new(0, Crowded.MaxImpostors);
|
||||
__instance.Value = Mathf.Clamp((float)Math.Round(__instance.Value, 2), __instance.ValidRange.min, __instance.ValidRange.max);
|
||||
if (DebugModeManager.AmDebugger) __instance.ValidRange.min = 0;
|
||||
break;
|
||||
case StringNames.CapacityLabel:
|
||||
__instance.ValidRange = IsVanillaServer ? new(4, 15) : new(4, 127);
|
||||
__instance.ValidRange = new(4, 127);
|
||||
__instance.Value = Mathf.Clamp(__instance.Value, __instance.ValidRange.min, __instance.ValidRange.max);
|
||||
break;
|
||||
}
|
||||
@@ -816,27 +812,12 @@ public static class StringOptionPatch
|
||||
{
|
||||
private static long HelpShowEndTS;
|
||||
|
||||
private static bool IsVanillaServer => GameStates.CurrentServerType == GameStates.ServerType.Vanilla;
|
||||
|
||||
private static void ClampOfficialStringOption(StringOption option)
|
||||
{
|
||||
if (!IsVanillaServer) return;
|
||||
|
||||
switch (option.Title)
|
||||
{
|
||||
case StringNames.GameKillDistance:
|
||||
option.Value = Mathf.Clamp(option.Value, 0, Math.Min(2, option.Values.Length - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(StringOption.Initialize))]
|
||||
[HarmonyPrefix]
|
||||
private static bool InitializePrefix(StringOption __instance)
|
||||
{
|
||||
if (__instance.name.StartsWith(nameof(OnlinePresetsManager))) return true;
|
||||
ClampOfficialStringOption(__instance);
|
||||
|
||||
if (__instance.name.StartsWith(nameof(OnlinePresetsManager))) return true;
|
||||
|
||||
if (ModGameOptionsMenu.OptionList.TryGetValue(__instance, out int index))
|
||||
{
|
||||
OptionItem item = OptionItem.AllOptions[index];
|
||||
@@ -1040,8 +1021,6 @@ public static class StringOptionPatch
|
||||
return false;
|
||||
}
|
||||
|
||||
ClampOfficialStringOption(__instance);
|
||||
|
||||
if (ModGameOptionsMenu.OptionList.TryGetValue(__instance, out int index))
|
||||
{
|
||||
__instance.MinusBtn.SetInteractable(true);
|
||||
|
||||
@@ -613,7 +613,6 @@ internal static class UnrestrictedNumImpostorsPatch
|
||||
{
|
||||
public static bool Prefix(ref int __result)
|
||||
{
|
||||
if (GameStates.CurrentServerType == GameStates.ServerType.Vanilla) return true;
|
||||
__result = Main.NormalOptions.NumImpostors;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -289,7 +289,6 @@ internal static class ChangeRoleSettings
|
||||
{
|
||||
(OptionItem MinSetting, OptionItem MaxSetting) impLimits = Options.FactionMinMaxSettings[Team.Impostor];
|
||||
int optImpNum = IRandom.Instance.Next(impLimits.MinSetting.GetInt(), impLimits.MaxSetting.GetInt() + 1);
|
||||
if (GameStates.CurrentServerType == GameStates.ServerType.Vanilla) optImpNum = Math.Clamp(optImpNum, 1, 3);
|
||||
GameOptionsManager.Instance.currentNormalGameOptions.NumImpostors = optImpNum;
|
||||
GameOptionsManager.Instance.CurrentGameOptions.SetInt(Int32OptionNames.NumImpostors, optImpNum);
|
||||
}
|
||||
@@ -395,12 +394,12 @@ internal static class ChangeRoleSettings
|
||||
Damocles.Initialize();
|
||||
Stressed.Init();
|
||||
Asthmatic.Init();
|
||||
DoubleShot.Init();
|
||||
Circumvent.Init();
|
||||
Commited.Init();
|
||||
Reroll.Init();
|
||||
}
|
||||
catch (Exception ex) { Logger.Exception(ex, "Init Roles"); }
|
||||
DoubleShot.Init();
|
||||
Circumvent.Init();
|
||||
Commited.Init();
|
||||
Reroll.Init();
|
||||
}
|
||||
catch (Exception ex) { Logger.Exception(ex, "Init Roles"); }
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user