using ADOFAIRenderer.Core; using HarmonyLib; namespace ADOFAIRenderer.Patch.Game; /// /// Overrides two player settings read from Persistence during a render: the "skip intro" option and the planet colors. /// [HarmonyPatch(typeof(Persistence))] public static class PersistencePatch { /// /// Postfix of the Persistence.skipIntroBehavior getter (setting values Off / AfterFirstTry / Always). /// /// scrConductor.StartMusicCo reads this setting when the song is scheduled and, for AfterFirstTry (after a death) or /// Always (long intro, no checkpoint), sets skipOffset, which moves dspTimeSong back by the level offset and /// starts the song part-way in. While (stage >= OnScene) and the song has not /// started yet (scrConductor.hasSongStarted false), the getter returns Off, so skipOffset stays false and the /// song always plays from its start. The mod's offline BGM mixing, spectrum and video background timing assume this. /// /// /// Value returned by the getter; replaced with SkipIntroBehavior.Off under the conditions above. [HarmonyPostfix] [HarmonyPatch("skipIntroBehavior", MethodType.Getter)] // ReSharper disable once InconsistentNaming public static void LockSkipIntroBehavior(ref SkipIntroBehavior __result) { if (RenderManager.IsActive && scrConductor.instance != null && !scrConductor.instance.hasSongStarted) { __result = SkipIntroBehavior.Off; } } /// /// Postfix of Persistence.GetPlayerColor(bool red), which returns the player's saved planet color /// (preset name or hex color from the general preferences; default red/blue otherwise). PlanetRenderer uses it to /// color the fire (red) and ice (blue) planets. /// /// Active from stage Load (render started, scene loading) until the stage returns to None. When the render configuration /// sets AdvancedConfig.firePlanetColor (red) or AdvancedConfig.icePlanetColor (blue), that color replaces the /// saved color; an unset (null) override keeps the game value. The saved preference itself is not changed. /// /// /// True for the fire (red) planet, false for the ice (blue) planet. /// Color returned by the game; replaced by the configured override when set. [HarmonyPostfix] [HarmonyPatch("GetPlayerColor")] // ReSharper disable once InconsistentNaming public static void OverridePlayerColor(bool red, ref PlanetColor __result) { if (!RenderManager.Instance || RenderManager.Instance.stage == RenderStage.None) return; var advConf = RenderManager.Instance.Configuration.AdvancedConfig; __result = red switch { true when advConf.firePlanetColor.HasValue => new PlanetColor(advConf.firePlanetColor.Value), false when advConf.icePlanetColor.HasValue => new PlanetColor(advConf.icePlanetColor.Value), _ => __result }; } }