Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix:加载内嵌的依赖
  • Loading branch information
THEXN committed May 18, 2025
commit 2f67437d3035c36682395c19a84b5ffe764bf8b1
19 changes: 17 additions & 2 deletions src/QRCoder/QRCoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using static Net.Codecrete.QrCodeGenerator.QrCode;
using System.Linq;
using static TShockAPI.GetDataHandlers;
using System.Reflection;

namespace QRCoder;

Expand Down Expand Up @@ -38,7 +39,7 @@ public override void Initialize()
});

GetDataHandlers.TileEdit += this.OnTileEdit;

AppDomain.CurrentDomain.AssemblyResolve += this.CurrentDomain_AssemblyResolve;
TShock.RestApi.Register(new SecureRestCommand("/tool/qrcoder", this.QRtest, "tool.rest.qrcoder"));
}

Expand All @@ -48,15 +49,29 @@ protected override void Dispose(bool Disposing)
{
Commands.ChatCommands.RemoveAll(c => c.CommandDelegate == this.QREncoder);
Commands.ChatCommands.RemoveAll(c => c.CommandDelegate == this.SetQRPosition);
AppDomain.CurrentDomain.AssemblyResolve -= this.CurrentDomain_AssemblyResolve;
GetDataHandlers.TileEdit -= this.OnTileEdit;
Comment thread
THEXN marked this conversation as resolved.
((List<RestCommand>) typeof(Rest)
((List<RestCommand>) typeof(Rest)
.GetField("commands", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
.GetValue(TShock.RestApi)!)
.RemoveAll(x => x.Name == "/tool/qrcoder");
}
base.Dispose(Disposing);
}
private Assembly? CurrentDomain_AssemblyResolve(object? sender, ResolveEventArgs args)
{
var resourceName =
$"{Assembly.GetExecutingAssembly().GetName().Name}.{new AssemblyName(args.Name).Name}.dll";
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
if (stream == null)
{
return null;
}

var assemblyData = new byte[stream.Length];
_ = stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
private void OnTileEdit(object? sender, TileEditEventArgs args)
{
if (args.Handled)
Expand Down
Loading