using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("SimsStartAtLevel1")] [assembly: AssemblyDescription("Newly created Erenshor SimPlayers start at level 1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SimsStartAtLevel1")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("24d0c162-35eb-49cc-b21f-0da653d2f5b1")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.1.0.0")] namespace LevelOneSims; [BepInPlugin("com.erenshor.levelonesims", "Level 1 Sims", "1.1.0")] public class LevelOneSimsPlugin : BaseUnityPlugin { private static ConfigEntry _cfgExcludedSims; private static readonly HashSet _excluded = new HashSet(StringComparer.OrdinalIgnoreCase); private void Awake() { _cfgExcludedSims = ((BaseUnityPlugin)this).Config.Bind("General", "ExcludedSims", "", "Comma-separated sim names that keep their designed starting level instead of being forced to 1 (example: GM-Burgee, Paul). Case-insensitive; spaces around commas are ignored. NOTE: this only affects sims being created fresh (no save file on disk yet). A sim that already exists at level 1 keeps its save until that file is deleted and the sim is recreated."); ParseExcluded(); _cfgExcludedSims.SettingChanged += delegate { ParseExcluded(); }; Harmony.CreateAndPatchAll(typeof(LevelOneSimsPlugin), (string)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)("All newly created sims will start at level 1." + ((_excluded.Count > 0) ? (" Excluded: " + string.Join(", ", _excluded) + ".") : ""))); } private static void ParseExcluded() { _excluded.Clear(); string value = _cfgExcludedSims.Value; if (string.IsNullOrEmpty(value)) { return; } string[] array = value.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { _excluded.Add(text); } } } [HarmonyPatch(typeof(SimPlayerDataManager), "CheckLoadData")] [HarmonyPrefix] public static void CheckLoadData_Prefix(string _name, ref int _level) { if (_excluded.Count <= 0 || _name == null || !_excluded.Contains(_name)) { _level = 1; } } }