diff --git a/plugins/script_loader/dotnet/AssemblyLoader/Program.cs b/plugins/script_loader/dotnet/AssemblyLoader/Program.cs
index c25936c10..2ebcd8a23 100644
--- a/plugins/script_loader/dotnet/AssemblyLoader/Program.cs
+++ b/plugins/script_loader/dotnet/AssemblyLoader/Program.cs
@@ -16,7 +16,7 @@ namespace ImHex
}
catch (Exception e)
{
- Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.Message);
+ Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.ToString());
return 1;
}
}
@@ -24,10 +24,22 @@ namespace ImHex
private static bool ExecuteScript(string path)
{
- AssemblyLoadContext? context = new("ScriptDomain_" + Path.GetFileNameWithoutExtension(path), true);
+ string? basePath = Path.GetDirectoryName(path);
+ if (basePath == null)
+ {
+ Console.WriteLine("[.NET Script] Failed to get base path");
+ return false;
+ }
+
+ AssemblyLoadContext? context = new("ScriptDomain_" + basePath, true);
try
{
+ foreach (var file in Directory.GetFiles(basePath, "*.dll"))
+ {
+ context.LoadFromStream(new MemoryStream(File.ReadAllBytes(file)));
+ }
+
var assembly = context.LoadFromStream(new MemoryStream(File.ReadAllBytes(path)));
var entryPointType = assembly.GetType("Script");
@@ -48,7 +60,7 @@ namespace ImHex
}
catch (Exception e)
{
- Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.Message);
+ Console.WriteLine("[.NET Script] Exception in AssemblyLoader: " + e.ToString());
return false;
}
finally
diff --git a/plugins/script_loader/dotnet/CMakeLists.txt b/plugins/script_loader/dotnet/CMakeLists.txt
index 61d4a2b8e..eac6e0e05 100644
--- a/plugins/script_loader/dotnet/CMakeLists.txt
+++ b/plugins/script_loader/dotnet/CMakeLists.txt
@@ -4,14 +4,14 @@ function(add_dotnet_assembly name)
set(OUTPUT_DLL ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll)
set(OUTPUT_RUNTIMECONFIG ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.runtimeconfig.json)
+ file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cs)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../../${name}.dll
COMMAND ${DOTNET_EXECUTABLE} build ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj --nologo -c Release -o ${CMAKE_CURRENT_BINARY_DIR}/../.. && ${CMAKE_COMMAND} -DOUTPUT_RUNTIMECONFIG="${OUTPUT_RUNTIMECONFIG}" -P ${CMAKE_CURRENT_SOURCE_DIR}/post_process_runtimeconfig.cmake
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.csproj ${sources}
COMMENT "Building ${name}.dll"
)
-
add_custom_target(${name} ALL DEPENDS ${OUTPUT_DLL})
install(FILES
@@ -20,9 +20,6 @@ function(add_dotnet_assembly name)
DESTINATION
${PLUGINS_INSTALL_LOCATION}
)
-
- file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cs)
- target_sources(${name} PRIVATE ${sources})
endfunction()
add_dotnet_assembly(AssemblyLoader)
\ No newline at end of file
diff --git a/plugins/script_loader/templates/CSharp/.gitignore b/plugins/script_loader/templates/CSharp/.gitignore
index 0e859db29..947f22307 100644
--- a/plugins/script_loader/templates/CSharp/.gitignore
+++ b/plugins/script_loader/templates/CSharp/.gitignore
@@ -1,3 +1,3 @@
.vs/
-ImHexScript/bin/
-ImHexScript/obj/
\ No newline at end of file
+*/bin/
+*/obj/
\ No newline at end of file
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Bookmarks.cs b/plugins/script_loader/templates/CSharp/ImHexLibrary/Bookmarks.cs
similarity index 100%
rename from plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Bookmarks.cs
rename to plugins/script_loader/templates/CSharp/ImHexLibrary/Bookmarks.cs
diff --git a/plugins/script_loader/templates/CSharp/ImHexLibrary/ImHexLibrary.csproj b/plugins/script_loader/templates/CSharp/ImHexLibrary/ImHexLibrary.csproj
new file mode 100644
index 000000000..dbb92e597
--- /dev/null
+++ b/plugins/script_loader/templates/CSharp/ImHexLibrary/ImHexLibrary.csproj
@@ -0,0 +1,10 @@
+
+
+
+ net7.0
+ enable
+ enable
+ True
+
+
+
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Impl/Library.cs b/plugins/script_loader/templates/CSharp/ImHexLibrary/Impl/Library.cs
similarity index 100%
rename from plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Impl/Library.cs
rename to plugins/script_loader/templates/CSharp/ImHexLibrary/Impl/Library.cs
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Memory.cs b/plugins/script_loader/templates/CSharp/ImHexLibrary/Memory.cs
similarity index 100%
rename from plugins/script_loader/templates/CSharp/ImHexScript/ImHex/Memory.cs
rename to plugins/script_loader/templates/CSharp/ImHexLibrary/Memory.cs
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/ImHex/UI.cs b/plugins/script_loader/templates/CSharp/ImHexLibrary/UI.cs
similarity index 100%
rename from plugins/script_loader/templates/CSharp/ImHexScript/ImHex/UI.cs
rename to plugins/script_loader/templates/CSharp/ImHexLibrary/UI.cs
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript.sln b/plugins/script_loader/templates/CSharp/ImHexScript.sln
index d8c2cdd8a..ebe8d997f 100644
--- a/plugins/script_loader/templates/CSharp/ImHexScript.sln
+++ b/plugins/script_loader/templates/CSharp/ImHexScript.sln
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImHexScript", "ImHexScript\ImHexScript.csproj", "{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImHexScript", "ImHexScript\ImHexScript.csproj", "{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImHexLibrary", "ImHexLibrary\ImHexLibrary.csproj", "{B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5DDEF0E-0CD2-4724-87A6-96FAF1FD64B0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B70BCC4E-7E54-45CD-AF85-9D56CA9E64B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/ImHexScript.csproj b/plugins/script_loader/templates/CSharp/ImHexScript/ImHexScript.csproj
index e43f613ea..7bdc2e6b2 100644
--- a/plugins/script_loader/templates/CSharp/ImHexScript/ImHexScript.csproj
+++ b/plugins/script_loader/templates/CSharp/ImHexScript/ImHexScript.csproj
@@ -6,7 +6,7 @@
enable
enable
Main
- True
+ False
true
@@ -14,4 +14,12 @@
true
+
+
+
+
+
+
+
+
diff --git a/plugins/script_loader/templates/CSharp/ImHexScript/Program.cs b/plugins/script_loader/templates/CSharp/ImHexScript/Program.cs
index f96a4e40e..597dd1d1c 100644
--- a/plugins/script_loader/templates/CSharp/ImHexScript/Program.cs
+++ b/plugins/script_loader/templates/CSharp/ImHexScript/Program.cs
@@ -5,6 +5,6 @@ class Script
{
public static void Main()
{
-
+ UI.ShowMessageBox("Hello World!");
}
}
\ No newline at end of file