Explorar o código

Write log source when logging preloader logger events in chainloader
Rebase of 9d164bc3b85d69c516292f4402794525235d0184

Bepis %!s(int64=4) %!d(string=hai) anos
pai
achega
3c8415c00e

+ 1 - 16
BepInEx.IL2CPP/IL2CPPChainloader.cs

@@ -139,22 +139,7 @@ namespace BepInEx.IL2CPP
 			//}
 
 
-
-
-			// Temporarily disable the console log listener as we replay the preloader logs
-
-			var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);
-
-			if (logListener != null)
-				Logger.Listeners.Remove(logListener);
-
-			foreach (var preloaderLogEvent in PreloaderConsoleListener.LogEvents)
-			{
-				PreloaderLogger.Log.Log(preloaderLogEvent.Level, preloaderLogEvent.Data);
-			}
-
-			if (logListener != null)
-				Logger.Listeners.Add(logListener);
+			ChainloaderLogHelper.RewritePreloaderLogs();
 
 
 			//UnityEngine.Application.s_LogCallbackHandler = DelegateSupport.ConvertDelegate<Application.LogCallback>(new Action<string>(UnityLogCallback));

+ 1 - 1
BepInEx.IL2CPP/Preloader.cs

@@ -32,7 +32,7 @@ namespace BepInEx.IL2CPP
 					Logger.Listeners.Add(new ConsoleLogListener());
 				}
 
-				BasicLogInfo.PrintLogInfo(Log);
+				ChainloaderLogHelper.PrintLogInfo(Log);
 
 				Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}");
 

+ 3 - 3
BepInEx.Preloader.Core/BepInEx.Preloader.Core.csproj

@@ -36,7 +36,7 @@
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Logging\BasicLogInfo.cs" />
+    <Compile Include="Logging\ChainloaderLogHelper.cs" />
     <Compile Include="Logging\PreloaderLogWriter.cs" />
     <Compile Include="Patching\AssemblyPatcher.cs" />
     <Compile Include="Patching\PatcherPlugin.cs" />
@@ -58,10 +58,10 @@
       <Version>0.10.4</Version>
     </PackageReference>
     <PackageReference Include="MonoMod.RuntimeDetour">
-      <Version>20.5.21.5</Version>
+      <Version>20.8.3.5</Version>
     </PackageReference>
     <PackageReference Include="MonoMod.Utils">
-      <Version>20.5.21.5</Version>
+      <Version>20.8.3.5</Version>
     </PackageReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 0 - 26
BepInEx.Preloader.Core/Logging/BasicLogInfo.cs

@@ -1,26 +0,0 @@
-using System.Diagnostics;
-using BepInEx.Logging;
-
-namespace BepInEx.Preloader.Core.Logging
-{
-	public static class BasicLogInfo
-	{
-		public static void PrintLogInfo(ManualLogSource log)
-		{
-			string consoleTile = $"BepInEx {typeof(Paths).Assembly.GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
-			log.LogMessage(consoleTile);
-
-			if (ConsoleManager.ConsoleActive)
-				ConsoleManager.SetConsoleTitle(consoleTile);
-
-			//See BuildInfoAttribute for more information about this section.
-			object[] attributes = typeof(BuildInfoAttribute).Assembly.GetCustomAttributes(typeof(BuildInfoAttribute), false);
-
-			if (attributes.Length > 0)
-			{
-				var attribute = (BuildInfoAttribute)attributes[0];
-				log.LogMessage(attribute.Info);
-			}
-		}
-	}
-}

+ 47 - 0
BepInEx.Preloader.Core/Logging/ChainloaderLogHelper.cs

@@ -0,0 +1,47 @@
+using System.Diagnostics;
+using System.Linq;
+using BepInEx.Logging;
+
+namespace BepInEx.Preloader.Core.Logging
+{
+	public static class ChainloaderLogHelper
+	{
+		public static void PrintLogInfo(ManualLogSource log)
+		{
+			string consoleTile = $"BepInEx {typeof(Paths).Assembly.GetName().Version} - {Process.GetCurrentProcess().ProcessName}";
+			log.LogMessage(consoleTile);
+
+			if (ConsoleManager.ConsoleActive)
+				ConsoleManager.SetConsoleTitle(consoleTile);
+
+			//See BuildInfoAttribute for more information about this section.
+			object[] attributes = typeof(BuildInfoAttribute).Assembly.GetCustomAttributes(typeof(BuildInfoAttribute), false);
+
+			if (attributes.Length > 0)
+			{
+				var attribute = (BuildInfoAttribute)attributes[0];
+				log.LogMessage(attribute.Info);
+			}
+		}
+
+		public static void RewritePreloaderLogs()
+		{
+			if (PreloaderConsoleListener.LogEvents == null || PreloaderConsoleListener.LogEvents.Count == 0)
+				return;
+
+			// Temporarily disable the console log listener as we replay the preloader logs
+			var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);
+
+			if (logListener != null)
+				Logger.Listeners.Remove(logListener);
+
+			foreach (var preloaderLogEvent in PreloaderConsoleListener.LogEvents)
+			{
+				PreloaderLogger.Log.Log(preloaderLogEvent.Level, $"[{ preloaderLogEvent.Source.SourceName,10}] { preloaderLogEvent.Data}");
+			}
+
+			if (logListener != null)
+				Logger.Listeners.Add(logListener);
+		}
+	}
+}

+ 1 - 1
BepInEx.Preloader.Unity/UnityPreloader.cs

@@ -65,7 +65,7 @@ namespace BepInEx.Preloader.Unity
 				PreloaderLog = new PreloaderConsoleListener(ConfigPreloaderCOutLogging.Value);
 				Logger.Listeners.Add(PreloaderLog);
 
-				BasicLogInfo.PrintLogInfo(Log);
+				ChainloaderLogHelper.PrintLogInfo(Log);
 
 				Log.LogInfo($"Running under Unity v{FileVersionInfo.GetVersionInfo(Paths.ExecutablePath).FileVersion}");
 				Log.LogInfo($"CLR runtime version: {Environment.Version}");

+ 1 - 14
BepInEx.Unity/Bootstrap/UnityChainloader.cs

@@ -84,20 +84,7 @@ namespace BepInEx.Unity.Bootstrap
 			}
 
 
-			// Temporarily disable the console log listener as we replay the preloader logs
-
-			var logListener = Logger.Listeners.FirstOrDefault(logger => logger is ConsoleLogListener);
-
-			if (logListener != null)
-				Logger.Listeners.Remove(logListener);
-
-			foreach (var preloaderLogEvent in PreloaderConsoleListener.LogEvents)
-			{
-				PreloaderLogger.Log.Log(preloaderLogEvent.Level, preloaderLogEvent.Data);
-			}
-
-			if (logListener != null)
-				Logger.Listeners.Add(logListener);
+			ChainloaderLogHelper.RewritePreloaderLogs();
 		}
 
 		public override BaseUnityPlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly)