using System; using ADOFAIRenderer; using ADOFAIRenderer.Core; using ADOFAIRenderer.Data; using ADOFAIRenderer.Util; using FFmpeg.AutoGen; using MelonLoader; using MelonLoader.Utils; using UnityEngine; using UnityEngine.EventSystems; 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; 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() { GlobalSettings.Load(); ffmpeg.RootPath = MelonEnvironment.UserLibsDirectory; var renderManagerObj = new GameObject("Render Manager"); var updateHookerObj = new GameObject("Update Hooker"); Object.DontDestroyOnLoad(renderManagerObj); Object.DontDestroyOnLoad(updateHookerObj); renderManagerObj.AddComponent(); updateHookerObj.AddComponent(); LoadBundles(); } private static void LoadBundles() { 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}"); } } 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(); } }