From 573e540ba47fec5c3335683fe59308bf2fe705fc844a20e6d7be51e3f147d569 Mon Sep 17 00:00:00 2001 From: copecone Date: Wed, 16 Sep 2026 20:52:16 +0900 Subject: [PATCH] Refactor `RenderMod` --- RenderMod.cs | 107 +++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/RenderMod.cs b/RenderMod.cs index 93b9d35..1b03ab1 100644 --- a/RenderMod.cs +++ b/RenderMod.cs @@ -13,68 +13,67 @@ using Object = UnityEngine.Object; [assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.2-BETA", "ADOFAI Editor Forum")] [assembly: MelonGame("7th Beat Games", "A Dance of Fire and Ice")] -namespace ADOFAIRenderer +namespace ADOFAIRenderer; + +internal class RenderMod : MelonMod { - internal class RenderMod : MelonMod + public static AssetBundle FontBundle = null!; + // ReSharper disable once MemberCanBePrivate.Global + public static AssetBundle SceneBundle = null!; + // ReSharper disable once MemberCanBePrivate.Global + public static AssetBundle ShaderBundle = null!; + public static ComputeShader ColorConversionShader = null!; + public static bool IsFeatureDisabled = false; + public static DateTime ExpirationTime = new(2026, 09, 21, 0, 0, 0, DateTimeKind.Utc); + + public override void OnInitializeMelon() { - public static AssetBundle FontBundle = null!; - // ReSharper disable once MemberCanBePrivate.Global - public static AssetBundle SceneBundle = null!; - // ReSharper disable once MemberCanBePrivate.Global - public static AssetBundle ShaderBundle = null!; - public static ComputeShader ColorConversionShader = null!; - public static bool IsFeatureDisabled = false; - public static DateTime ExpirationTime = new(2026, 09, 21, 0, 0, 0, DateTimeKind.Utc); - - public override void OnInitializeMelon() - { - GlobalSettings.Load(); - ffmpeg.RootPath = MelonEnvironment.UserLibsDirectory; + GlobalSettings.Load(); + ffmpeg.RootPath = MelonEnvironment.UserLibsDirectory; - var renderManagerObj = new GameObject("Render Manager"); - var updateHookerObj = new GameObject("Update Hooker"); - Object.DontDestroyOnLoad(renderManagerObj); - Object.DontDestroyOnLoad(updateHookerObj); + var renderManagerObj = new GameObject("Render Manager"); + var updateHookerObj = new GameObject("Update Hooker"); + Object.DontDestroyOnLoad(renderManagerObj); + Object.DontDestroyOnLoad(updateHookerObj); - renderManagerObj.AddComponent(); - updateHookerObj.AddComponent(); - LoadBundles(); - } + renderManagerObj.AddComponent(); + updateHookerObj.AddComponent(); + LoadBundles(); + } - private static void LoadBundles() + private static void LoadBundles() + { + FontBundle = BundleLoader.GetBundle("fonts"); + SceneBundle = BundleLoader.GetBundle("scenes"); + SceneBundle.GetAllScenePaths(); + try { - FontBundle = BundleLoader.GetBundle("fonts"); - SceneBundle = BundleLoader.GetBundle("scenes"); - SceneBundle.GetAllScenePaths(); - try - { - ShaderBundle = BundleLoader.GetBundle("shaders"); - ColorConversionShader = ShaderBundle.LoadAsset("ColorConversion"); - Melon.Logger.Msg("Color conversion Compute Shader loaded successfully."); - } - catch (Exception ex) - { - Melon.Logger.Warning($"Failed to load Shader AssetBundle. GPU color conversion will be disabled and fallback to CPU. Error: {ex.Message}"); - } + ShaderBundle = BundleLoader.GetBundle("shaders"); + ColorConversionShader = ShaderBundle.LoadAsset("ColorConversion"); + Melon.Logger.Msg("Color conversion Compute Shader loaded successfully."); } - - public static void FixEventSystem() + catch (Exception ex) { - if (EventSystem.current == null) return; - var currentModule = EventSystem.current.currentInputModule; - - if (currentModule) return; - Melon.Logger.Msg("Ported Unity 6 Input Module."); - - var newModule = EventSystem.current.gameObject.AddComponent(); - newModule.enabled = true; - } - - public override void OnApplicationQuit() - { - if (RenderManager.Instance == null) return; - Melon.Logger.Msg("MelonLoader shutdown detected: Forcefully terminating and cleaning up active RenderManager processes."); - RenderManager.Instance.CleanUpActiveRender(); + Melon.Logger.Warning($"Failed to load Shader AssetBundle. GPU color conversion will be disabled and fallback to CPU. Error: {ex.Message}"); } } + + public static void FixEventSystem() + { + if (EventSystem.current == null) return; + var currentModule = EventSystem.current.currentInputModule; + + if (currentModule) return; + Melon.Logger.Msg("Ported Unity 6 Input Module."); + + var newModule = EventSystem.current.gameObject.AddComponent(); + newModule.enabled = true; + } + + public override void OnApplicationQuit() + { + if (RenderManager.Instance == null) return; + Melon.Logger.Msg("MelonLoader shutdown detected: Forcefully terminating and cleaning up active RenderManager processes."); + RenderManager.Instance.CleanUpActiveRender(); + } } \ No newline at end of file