quantum-space-buddies/MirrorWeaver/Program.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2021-12-28 09:48:33 +00:00
using Mirror.Weaver;
using Mono.Cecil;
using System;
using System.IO;
namespace MirrorWeaver
2021-12-28 05:56:00 +00:00
{
2021-12-28 09:48:33 +00:00
internal 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
{
2021-12-28 09:48:33 +00:00
if (mr != null) message = $"{message} (at {mr})";
Console.WriteLine(message);
}
public void Error(string message) => Error(message, null);
public void Error(string message, MemberReference mr)
{
if (mr != null) message = $"{message} (at {mr})";
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
{
var log = new ConsoleLogger();
var weaver = new Weaver(log);
2021-12-28 12:57:24 +00:00
var qsbDll = args[0];
if (!File.Exists(qsbDll))
2021-12-28 09:48:33 +00:00
{
2021-12-28 12:57:24 +00:00
throw new Exception($"qsb dll could not be located at {qsbDll}!");
2021-12-28 09:48:33 +00:00
}
2021-12-28 12:57:24 +00:00
Console.WriteLine("Start weaving process.");
var assembly = AssemblyDefinition.ReadAssembly(qsbDll);
weaver.Weave(assembly, new DefaultAssemblyResolver(), out var modified);
assembly.Write(new WriterParameters { WriteSymbols = true });
Console.WriteLine($"Finish weaving process. modified = {modified}");
2021-12-28 05:56:00 +00:00
}
}
}