using System; using System.Collections.Generic; using System.Linq; using AmongUs.GameOptions; namespace EHR; public class OptionBackupData { public List AllValues; public OptionBackupData(IGameOptions option) { AllValues = new(32); foreach (ByteOptionNames name in EnumHelper.GetValues()) { if (option.TryGetByte(name, out byte value)) AllValues.Add(new ByteOptionBackupValue(name, value)); } foreach (BoolOptionNames name in EnumHelper.GetValues()) { if (option.TryGetBool(name, out bool value) && name is not BoolOptionNames.GhostsDoTasks and not BoolOptionNames.Roles) AllValues.Add(new BoolOptionBackupValue(name, value)); } foreach (FloatOptionNames name in EnumHelper.GetValues()) { if (option.TryGetFloat(name, out float value)) AllValues.Add(new FloatOptionBackupValue(name, value)); } foreach (Int32OptionNames name in EnumHelper.GetValues()) { if (option.TryGetInt(name, out int value)) AllValues.Add(new IntOptionBackupValue(name, value)); } // [Vanilla bug] Get the number of people in the room separately, since GetInt cannot get the number of people in the room AllValues.Add(new IntOptionBackupValue(Int32OptionNames.MaxPlayers, option.MaxPlayers)); // Since TryGetUInt is not implemented, get it separately AllValues.Add(new UIntOptionBackupValue(UInt32OptionNames.Keywords, (uint)option.Keywords)); RoleTypes[] array = [RoleTypes.Scientist, RoleTypes.Engineer, RoleTypes.GuardianAngel, RoleTypes.Shapeshifter, RoleTypes.Noisemaker, RoleTypes.Phantom, RoleTypes.Tracker, RoleTypes.Viper, RoleTypes.Detective, RoleTypes.Judge, RoleTypes.SpiritGuide]; foreach (RoleTypes role in array) AllValues.Add(new RoleRateBackupValue(role, option.RoleOptions.GetNumPerGame(role), option.RoleOptions.GetChancePerGame(role))); } public IGameOptions Restore(IGameOptions option) { AllValues.ForEach(o => o.Restore(option)); return option; } public byte GetByte(ByteOptionNames name) { return Get(name); } public bool GetBool(BoolOptionNames name) { return Get(name); } public float GetFloat(FloatOptionNames name) { return Get(name); } public int GetInt(Int32OptionNames name) { return Get(name); } public uint GetUInt(UInt32OptionNames name) { return Get(name); } public TValue Get(TKey name) where TKey : Enum { OptionBackupValueBase value = AllValues .OfType>() .FirstOrDefault(val => val.OptionName.Equals(name)); return value == null ? default(TValue) : value.Value; } }