2021-12-28 09:48:33 +00:00
|
|
|
|
using Mirror.Weaver;
|
|
|
|
|
using Mono.Cecil;
|
2022-02-21 07:27:47 +00:00
|
|
|
|
using Mono.Cecil.Cil;
|
2021-12-28 09:48:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace MirrorWeaver
|
2021-12-28 05:56:00 +00:00
|
|
|
|
{
|
2021-12-28 13:59:54 +00:00
|
|
|
|
public class ConsoleLogger : Logger
|
2021-12-28 05:56:00 +00:00
|
|
|
|
{
|
2021-12-28 09:48:33 +00:00
|
|
|
|
public void Warning(string message) => Warning(message, null);
|
|
|
|
|
|
|
|
|
|
public void Warning(string message, MemberReference mr)
|
2021-12-28 05:56:00 +00:00
|
|
|
|
{
|
2022-02-25 05:09:49 +00:00
|
|
|
|
if (mr != null)
|
|
|
|
|
{
|
|
|
|
|
message = $"{message} (at {mr})";
|
|
|
|
|
}
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(string message) => Error(message, null);
|
|
|
|
|
|
|
|
|
|
public void Error(string message, MemberReference mr)
|
|
|
|
|
{
|
2022-02-25 05:09:49 +00:00
|
|
|
|
if (mr != null)
|
|
|
|
|
{
|
|
|
|
|
message = $"{message} (at {mr})";
|
|
|
|
|
}
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
|
|
|
|
Console.Error.WriteLine(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 12:57:24 +00:00
|
|
|
|
public static class Program
|
2021-12-28 09:48:33 +00:00
|
|
|
|
{
|
2021-12-28 12:57:24 +00:00
|
|
|
|
public static void Main(string[] args)
|
2021-12-28 09:48:33 +00:00
|
|
|
|
{
|
2022-01-01 07:17:58 +00:00
|
|
|
|
var qsbDll = Path.GetFullPath(args[0]);
|
2022-02-01 03:14:02 +00:00
|
|
|
|
var unityDir = Path.GetFullPath(args[1]);
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-01-01 07:17:58 +00:00
|
|
|
|
var qsbDir = Path.GetDirectoryName(qsbDll)!;
|
|
|
|
|
|
|
|
|
|
var resolver = new DefaultAssemblyResolver();
|
|
|
|
|
resolver.AddSearchDirectory(qsbDir);
|
2022-02-01 03:14:02 +00:00
|
|
|
|
resolver.AddSearchDirectory(unityDir);
|
2022-01-01 07:17:58 +00:00
|
|
|
|
var assembly = AssemblyDefinition.ReadAssembly(qsbDll, new ReaderParameters
|
2021-12-28 09:48:33 +00:00
|
|
|
|
{
|
2022-01-01 07:17:58 +00:00
|
|
|
|
ReadWrite = true,
|
2022-02-21 07:27:47 +00:00
|
|
|
|
AssemblyResolver = resolver,
|
|
|
|
|
SymbolReaderProvider = new DefaultSymbolReaderProvider(false)
|
2022-01-01 07:17:58 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var log = new ConsoleLogger();
|
|
|
|
|
var weaver = new Weaver(log);
|
2022-01-14 02:46:52 +00:00
|
|
|
|
if (!weaver.Weave(assembly, resolver, out _))
|
|
|
|
|
{
|
2022-01-14 03:19:45 +00:00
|
|
|
|
Environment.Exit(1);
|
2022-01-14 02:46:52 +00:00
|
|
|
|
}
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-21 07:27:47 +00:00
|
|
|
|
assembly.Write(new WriterParameters { WriteSymbols = assembly.MainModule.HasSymbols });
|
2021-12-28 05:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|