mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-08-05 07:40:12 +08:00
ModFeatureRegistry is a static class with shared collections accumulating features from all mods. Dependent mods (CheatEnabler, UniverseGenTweaks) each independently called InitAll/StartAll/OnInputUpdateAll/OnUpdateAll/ UninitAll, re-running lifecycle for ALL accumulated features including other mods' — per-frame Update ran 2-3x (breaking CheatEnabler key toggles to net no-ops), Init/Start/Uninit ran 2-3x (double RegisterExporter causing save corruption, double SettingChanged subscriptions, double keybind registration). Fix: - Init now runs eagerly at Discover/Register time (Awake-phase), preserving the original timing that keybind registration depends on (game's UIOptionWindow._OnCreate copies keybinds only after all plugins load) - InitAll removed entirely - StartAll/UninitAll/OnInputUpdateAll/OnUpdateAll made internal so only UXAssist (host, same assembly, no InternalsVisibleTo) can drive them - Start deferred to UXAssist.Start (after all dependents' Awake complete; BepInEx runs all Awakes before any Start) - Per-feature Started idempotency + per-frame Time.frameCount guards as defense-in-depth - Dependent mods reduced to Discover-only in Awake Document the Init/Start timing contract on IModFeature and ModFeatureAttribute so future mods can rely on it.
87 lines
4.1 KiB
C#
87 lines
4.1 KiB
C#
using System.IO;
|
|
using System.Reflection;
|
|
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using crecheng.DSPModSave;
|
|
using UXAssist.Common;
|
|
using UXAssist.Common.GameConstants;
|
|
using UXAssist.Common.ModFeatures;
|
|
|
|
namespace UniverseGenTweaks;
|
|
|
|
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
|
[BepInDependency(UXAssist.PluginInfo.PLUGIN_GUID)]
|
|
[BepInDependency(DSPModSavePlugin.MODGUID)]
|
|
[ModSaveSettings(LoadOrder = LoadOrder.Preload)]
|
|
public class UniverseGenTweaks : BaseUnityPlugin, IModCanSave
|
|
{
|
|
public new static readonly BepInEx.Logging.ManualLogSource Logger =
|
|
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
|
|
|
private void Awake()
|
|
{
|
|
I18N.Init();
|
|
|
|
MoreSettings.Enabled = Config.Bind("MoreSettings", "Enabled", true, "Enable more settings on Universe Generation");
|
|
MoreSettings.MaxStarCount = Config.Bind("MoreSettings", "MaxStarCount", UniverseGenConstants.DefaultMaxStarCount,
|
|
new ConfigDescription($"({UniverseGenConstants.MinStarCount} ~ {UniverseGenConstants.MaxStarCount})\nMaximum star count for Universe Generation, enable MoreSettings.Enabled to take effect",
|
|
new AcceptableValueRange<int>(UniverseGenConstants.MinStarCount, UniverseGenConstants.MaxStarCount), new { }));
|
|
|
|
EpicDifficulty.Enabled = Config.Bind("EpicDifficulty", "Enabled", true, "Enable Epic difficulty");
|
|
EpicDifficulty.ResourceMultiplier = Config.Bind("EpicDifficulty", "ResourceMultiplier", 0.01f,
|
|
new ConfigDescription("Resource multiplier for Epic difficulty",
|
|
new AcceptableValueRange<float>(0.0001f, 0.05f), new { }));
|
|
EpicDifficulty.OilMultiplier = Config.Bind("EpicDifficulty", "OilMultiplier", 0.5f,
|
|
new ConfigDescription("Oil multiplier for Epic difficulty relative to the Very-Hard difficulty",
|
|
new AcceptableValueRange<float>(0.1f, 1f), new { }));
|
|
|
|
BirthPlanetPatch.SitiVeinsOnBirthPlanet = Config.Bind("Birth", "SiTiVeinsOnBirthPlanet", false,
|
|
"Silicon/Titanium on birth planet");
|
|
BirthPlanetPatch.FireIceOnBirthPlanet = Config.Bind("Birth", "FireIceOnBirthPlanet", false,
|
|
"Fire ice on birth planet");
|
|
BirthPlanetPatch.KimberliteOnBirthPlanet = Config.Bind("Birth", "KimberliteOnBirthPlanet", false,
|
|
"Kimberlite on birth planet");
|
|
BirthPlanetPatch.FractalOnBirthPlanet = Config.Bind("Birth", "FractalOnBirthPlanet", false,
|
|
"Fractal silicon on birth planet");
|
|
BirthPlanetPatch.OrganicOnBirthPlanet = Config.Bind("Birth", "OrganicOnBirthPlanet", false,
|
|
"Organic crystal on birth planet");
|
|
BirthPlanetPatch.OpticalOnBirthPlanet = Config.Bind("Birth", "OpticalOnBirthPlanet", false,
|
|
"Optical grating crystal on birth planet");
|
|
BirthPlanetPatch.SpiniformOnBirthPlanet = Config.Bind("Birth", "SpiniformOnBirthPlanet", false,
|
|
"Spiniform stalagmite crystal on birth planet");
|
|
BirthPlanetPatch.UnipolarOnBirthPlanet = Config.Bind("Birth", "UnipolarOnBirthPlanet", false,
|
|
"Unipolar magnet on birth planet");
|
|
BirthPlanetPatch.FlatBirthPlanet = Config.Bind("Birth", "FlatBirthPlanet", false,
|
|
"Birth planet is solid flat (no water at all)");
|
|
BirthPlanetPatch.HighLuminosityBirthStar = Config.Bind("Birth", "HighLuminosityBirthStar", false,
|
|
"Birth star has high luminosity");
|
|
|
|
Localization.Register();
|
|
UIConfigWindow.Init();
|
|
// Register features (Init runs eagerly here); UXAssist drives the deferred lifecycle (Start/Uninit/Update).
|
|
ModFeatureRegistry.Discover(Assembly.GetExecutingAssembly());
|
|
|
|
I18N.Apply();
|
|
}
|
|
|
|
#region IModCanSave
|
|
private const ushort ModSaveVersion = 1;
|
|
|
|
public void Export(BinaryWriter w)
|
|
{
|
|
w.Write(ModSaveVersion);
|
|
GalaxyGenSave.Export(w);
|
|
}
|
|
|
|
public void Import(BinaryReader r)
|
|
{
|
|
var version = r.ReadUInt16();
|
|
if (version <= 0) return;
|
|
GalaxyGenSave.Import(r);
|
|
}
|
|
|
|
public void IntoOtherSave()
|
|
{
|
|
}
|
|
#endregion
|
|
} |