SHA256
Refactor RenderMod
This commit is contained in:
1 parent
43763b0b35
commit
573e540ba4
1 file changed
+53
-54
+53
-54
@@ -13,68 +13,67 @@ using Object = UnityEngine.Object;
|
|||||||
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.2-BETA", "ADOFAI Editor Forum")]
|
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.2-BETA", "ADOFAI Editor Forum")]
|
||||||
[assembly: MelonGame("7th Beat Games", "A Dance of Fire and Ice")]
|
[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!;
|
GlobalSettings.Load();
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
ffmpeg.RootPath = MelonEnvironment.UserLibsDirectory;
|
||||||
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 renderManagerObj = new GameObject("Render Manager");
|
||||||
var updateHookerObj = new GameObject("Update Hooker");
|
var updateHookerObj = new GameObject("Update Hooker");
|
||||||
Object.DontDestroyOnLoad(renderManagerObj);
|
Object.DontDestroyOnLoad(renderManagerObj);
|
||||||
Object.DontDestroyOnLoad(updateHookerObj);
|
Object.DontDestroyOnLoad(updateHookerObj);
|
||||||
|
|
||||||
renderManagerObj.AddComponent<RenderManager>();
|
renderManagerObj.AddComponent<RenderManager>();
|
||||||
updateHookerObj.AddComponent<FirstUpdateHook>();
|
updateHookerObj.AddComponent<FirstUpdateHook>();
|
||||||
LoadBundles();
|
LoadBundles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadBundles()
|
private static void LoadBundles()
|
||||||
|
{
|
||||||
|
FontBundle = BundleLoader.GetBundle("fonts");
|
||||||
|
SceneBundle = BundleLoader.GetBundle("scenes");
|
||||||
|
SceneBundle.GetAllScenePaths();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
FontBundle = BundleLoader.GetBundle("fonts");
|
ShaderBundle = BundleLoader.GetBundle("shaders");
|
||||||
SceneBundle = BundleLoader.GetBundle("scenes");
|
ColorConversionShader = ShaderBundle.LoadAsset<ComputeShader>("ColorConversion");
|
||||||
SceneBundle.GetAllScenePaths();
|
Melon<RenderMod>.Logger.Msg("Color conversion Compute Shader loaded successfully.");
|
||||||
try
|
|
||||||
{
|
|
||||||
ShaderBundle = BundleLoader.GetBundle("shaders");
|
|
||||||
ColorConversionShader = ShaderBundle.LoadAsset<ComputeShader>("ColorConversion");
|
|
||||||
Melon<RenderMod>.Logger.Msg("Color conversion Compute Shader loaded successfully.");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Melon<RenderMod>.Logger.Warning($"Failed to load Shader AssetBundle. GPU color conversion will be disabled and fallback to CPU. Error: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
public static void FixEventSystem()
|
|
||||||
{
|
{
|
||||||
if (EventSystem.current == null) return;
|
Melon<RenderMod>.Logger.Warning($"Failed to load Shader AssetBundle. GPU color conversion will be disabled and fallback to CPU. Error: {ex.Message}");
|
||||||
var currentModule = EventSystem.current.currentInputModule;
|
|
||||||
|
|
||||||
if (currentModule) return;
|
|
||||||
Melon<RenderMod>.Logger.Msg("Ported Unity 6 Input Module.");
|
|
||||||
|
|
||||||
var newModule = EventSystem.current.gameObject.AddComponent<StandaloneInputModule>();
|
|
||||||
newModule.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnApplicationQuit()
|
|
||||||
{
|
|
||||||
if (RenderManager.Instance == null) return;
|
|
||||||
Melon<RenderMod>.Logger.Msg("MelonLoader shutdown detected: Forcefully terminating and cleaning up active RenderManager processes.");
|
|
||||||
RenderManager.Instance.CleanUpActiveRender();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void FixEventSystem()
|
||||||
|
{
|
||||||
|
if (EventSystem.current == null) return;
|
||||||
|
var currentModule = EventSystem.current.currentInputModule;
|
||||||
|
|
||||||
|
if (currentModule) return;
|
||||||
|
Melon<RenderMod>.Logger.Msg("Ported Unity 6 Input Module.");
|
||||||
|
|
||||||
|
var newModule = EventSystem.current.gameObject.AddComponent<StandaloneInputModule>();
|
||||||
|
newModule.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
if (RenderManager.Instance == null) return;
|
||||||
|
Melon<RenderMod>.Logger.Msg("MelonLoader shutdown detected: Forcefully terminating and cleaning up active RenderManager processes.");
|
||||||
|
RenderManager.Instance.CleanUpActiveRender();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user