mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fixed Script Scheduler bug
This commit is contained in:
parent
5b13e740ef
commit
a5423211ad
6 changed files with 131 additions and 55 deletions
|
|
@ -13,9 +13,9 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
{
|
||||
internal class CompileRunner
|
||||
{
|
||||
public object? Execute(byte[] compiledAssembly, string[] args, Dictionary<string, object>? localVars, ChatBot apiHandler)
|
||||
public object? Execute(byte[] compiledAssembly, string[] args, Dictionary<string, object>? localVars, ChatBot apiHandler, string? scriptOwnerKey = null)
|
||||
{
|
||||
var assemblyLoadContextWeakRef = LoadAndExecute(compiledAssembly, args, localVars, apiHandler);
|
||||
var assemblyLoadContextWeakRef = LoadAndExecute(compiledAssembly, args, localVars, apiHandler, scriptOwnerKey);
|
||||
|
||||
for (var i = 0; i < 8 && assemblyLoadContextWeakRef.Item1.IsAlive; i++)
|
||||
{
|
||||
|
|
@ -28,18 +28,18 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static Tuple<WeakReference, object?> LoadAndExecute(byte[] compiledAssembly, string[] args, Dictionary<string, object>? localVars, ChatBot apiHandler)
|
||||
private static Tuple<WeakReference, object?> LoadAndExecute(byte[] compiledAssembly, string[] args, Dictionary<string, object>? localVars, ChatBot apiHandler, string? scriptOwnerKey)
|
||||
{
|
||||
using var asm = new MemoryStream(compiledAssembly);
|
||||
var assemblyLoadContext = new SimpleUnloadableAssemblyLoadContext();
|
||||
|
||||
var assembly = assemblyLoadContext.LoadFromStream(asm);
|
||||
var compiledScript = assembly.CreateInstance("ScriptLoader.Script")!;
|
||||
var execResult = compiledScript.GetType().GetMethod("__run")!.Invoke(compiledScript, new object[] { new CSharpAPI(apiHandler, localVars), args });
|
||||
var execResult = compiledScript.GetType().GetMethod("__run")!.Invoke(compiledScript, new object[] { new CSharpAPI(apiHandler, localVars, scriptOwnerKey), args });
|
||||
|
||||
assemblyLoadContext.Unload();
|
||||
|
||||
return new(new WeakReference(assemblyLoadContext), execResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue