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;
|
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
namespace MirrorWeaver;
|
|
|
|
|
|
|
|
|
|
public class ConsoleLogger : Logger
|
2021-12-28 05:56:00 +00:00
|
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public void Warning(string message) => Warning(message, null);
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public void Warning(string message, MemberReference mr)
|
|
|
|
|
{
|
|
|
|
|
if (mr != null)
|
2021-12-28 05:56:00 +00:00
|
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
message = $"{message} (at {mr})";
|
2021-12-28 09:48:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
}
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public void Error(string message) => Error(message, null);
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public void Error(string message, MemberReference mr)
|
|
|
|
|
{
|
|
|
|
|
if (mr != null)
|
|
|
|
|
{
|
|
|
|
|
message = $"{message} (at {mr})";
|
2021-12-28 09:48:33 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
|
|
|
|
Console.Error.WriteLine(message);
|
2021-12-28 09:48:33 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public static class Program
|
|
|
|
|
{
|
|
|
|
|
public static void Main(string[] args)
|
2021-12-28 09:48:33 +00:00
|
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
var qsbDll = Path.GetFullPath(args[0]);
|
|
|
|
|
var unityDir = Path.GetFullPath(args[1]);
|
2022-01-01 07:17:58 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
var qsbDir = Path.GetDirectoryName(qsbDll)!;
|
2022-01-01 07:17:58 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
var resolver = new DefaultAssemblyResolver();
|
|
|
|
|
resolver.AddSearchDirectory(qsbDir);
|
|
|
|
|
resolver.AddSearchDirectory(unityDir);
|
|
|
|
|
var assembly = AssemblyDefinition.ReadAssembly(qsbDll, new ReaderParameters
|
|
|
|
|
{
|
|
|
|
|
ReadWrite = true,
|
|
|
|
|
AssemblyResolver = resolver,
|
|
|
|
|
SymbolReaderProvider = new DefaultSymbolReaderProvider(false)
|
|
|
|
|
});
|
2021-12-28 09:48:33 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
var log = new ConsoleLogger();
|
|
|
|
|
var weaver = new Weaver(log);
|
|
|
|
|
if (!weaver.Weave(assembly, resolver, out _))
|
|
|
|
|
{
|
|
|
|
|
Environment.Exit(1);
|
2021-12-28 05:56:00 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
|
|
|
|
assembly.Write(new WriterParameters { WriteSymbols = assembly.MainModule.HasSymbols });
|
2021-12-28 05:56:00 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|