From 275774a10ac2a0c7db60a9d60c9207526a28a383 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 17 May 2024 09:27:00 +0200 Subject: [PATCH] fix: C# OnLoad method not being run correctly --- .../source/loaders/dotnet/dotnet_loader.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp index 639c77ac2..cac14a7e6 100644 --- a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp +++ b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp @@ -261,17 +261,21 @@ namespace hex::script::loader { if (!std::fs::exists(scriptPath)) continue; - if (m_methodExists("Main", scriptPath)) { + const bool hasMain = m_methodExists("Main", scriptPath); + const bool hasOnLoad = m_methodExists("OnLoad", scriptPath); + + if (hasMain) { this->addScript(entry.path().stem().string(), false, [this, scriptPath] { hex::unused(m_runMethod("Main", false, scriptPath)); }); + } else if (hasOnLoad) { + this->addScript(entry.path().stem().string(), true, [] {}); } - if (m_methodExists("OnLoad", scriptPath)) { - this->addScript(entry.path().stem().string(), true, [this, scriptPath] { - hex::unused(m_runMethod("OnLoad", true, scriptPath)); - }); + if (hasOnLoad) { + hex::unused(m_runMethod("OnLoad", true, scriptPath)); } + } }