using HarmonyLib; using UnityEngine; using UnityModManagerNet; namespace RailroaderPhysicsOverhaul; public static class Main { internal static UnityModManager.ModEntry ModEntry { get; private set; } public static ModSettings Settings { get; private set; } public static bool Load(UnityModManager.ModEntry modEntry) { ModEntry = modEntry; // Load persisted settings (creates defaults if Settings.xml doesn't exist yet). Settings = ModSettings.Load(modEntry); // Apply settings to runtime state before any patches run. ConsistLOD.Enabled = Settings.OptimizerEnabled; ConsistLOD.DistanceThreshold = Settings.DistanceThreshold; ConsistLOD.ResyncInterval = Settings.ResyncInterval; ConsistLOD.BlacklistEnabled = Settings.BlacklistEnabled; ConsistLOD.IsBlacklist = Settings.IsBlacklist; foreach (string name in Settings.RoadNumberList) ConsistLOD.RoadNumberList.Add(name); ConsistLOD.ExcludeLocomotives = Settings.ExcludeLocosFromLOD; ConsistFreezer.ExcludeLocomotives = Settings.ExcludeLocosFromFreeze; ConsistFreezer.AutoFreezeEnabled = Settings.AutoFreezeEnabled; ConsistFreezer.AutoFreezeDistance = Settings.AutoFreezeDistance; ConsistFreezer.AutoFreezeSpeedThreshold = Settings.AutoFreezeSpeedThreshold; var harmony = new Harmony(modEntry.Info.Id); harmony.PatchAll(); PhysicsTimer.TryPatchPositionCars(harmony, modEntry.Logger); var go = new GameObject("RailroaderPhysicsOverhaul.Overlay"); Object.DontDestroyOnLoad(go); var overlay = go.AddComponent(); overlay.Visible = Settings.ShowOverlay; overlay.Opacity = Settings.OverlayOpacity; go.AddComponent(); // UMM settings panel callbacks. modEntry.OnGUI = entry => SettingsGUI.Draw(entry, Settings); modEntry.OnSaveGUI = entry => Settings.Save(entry); modEntry.Logger.Log("RailroaderPhysicsOverhaul loaded."); return true; } }