1
0
mirror of https://github.com/misternebula/quantum-space-buddies.git synced 2025-01-27 03:35:20 +00:00

64 lines
1.3 KiB
C#
Raw Normal View History

2021-12-28 01:48:33 -08:00
using Mirror.Weaver;
using Mono.Cecil;
using Mono.Cecil.Cil;
2021-12-28 01:48:33 -08:00
using System;
using System.IO;
2022-03-02 19:46:33 -08:00
namespace MirrorWeaver;
public class ConsoleLogger : Logger
2021-12-27 21:56:00 -08:00
{
2022-03-02 19:46:33 -08:00
public void Warning(string message) => Warning(message, null);
2022-03-02 19:46:33 -08:00
public void Warning(string message, MemberReference mr)
{
if (mr != null)
2021-12-27 21:56:00 -08:00
{
2022-03-02 19:46:33 -08:00
message = $"{message} (at {mr})";
}
2021-12-28 01:48:33 -08:00
2022-03-02 19:46:33 -08:00
Console.WriteLine(message);
}
2021-12-28 01:48:33 -08:00
2022-03-02 19:46:33 -08:00
public void Error(string message) => Error(message, null);
2022-03-02 19:46:33 -08:00
public void Error(string message, MemberReference mr)
{
if (mr != null)
{
message = $"{message} (at {mr})";
}
2022-03-02 19:46:33 -08:00
Console.Error.WriteLine(message);
2021-12-28 01:48:33 -08:00
}
2022-03-02 19:46:33 -08:00
}
2021-12-28 01:48:33 -08:00
2022-03-02 19:46:33 -08:00
public static class Program
{
public static void Main(string[] args)
2021-12-28 01:48:33 -08:00
{
2022-03-02 19:46:33 -08:00
var qsbDll = args[0];
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(Path.GetDirectoryName(qsbDll));
var assembly = AssemblyDefinition.ReadAssembly(qsbDll, new ReaderParameters
{
ReadWrite = true,
AssemblyResolver = resolver,
SymbolReaderProvider = new DefaultSymbolReaderProvider(false)
});
var log = new ConsoleLogger();
var weaver = new Weaver(log);
2023-05-16 11:00:21 -07:00
if (!weaver.Weave(assembly, resolver, out var modified))
{
2022-03-02 19:46:33 -08:00
Environment.Exit(1);
}
2022-03-02 19:46:33 -08:00
2023-05-16 11:00:21 -07:00
if (modified)
{
assembly.Write(new WriterParameters { WriteSymbols = assembly.MainModule.HasSymbols });
}
2021-12-27 21:56:00 -08:00
}
2023-05-16 11:00:21 -07:00
}