Browse Source

Updated Harmony to Harmony 2

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
d76c6e400a
16 changed files with 235 additions and 294 deletions
  1. +0
    -36
      BSIPA.sln
  2. +1
    -1
      BuildTools
  3. +22
    -1
      IPA.Injector/IPA.Injector.csproj
  4. +0
    -39
      IPA.Injector/PostBuild.msbuild
  5. +1
    -1
      IPA.Loader/IPA.Loader.csproj
  6. +9
    -13
      IPA.Loader/Loader/HarmonyProtector.cs
  7. +201
    -201
      IPA.Loader/Logging/StdoutInterceptor.cs
  8. BIN
      Refs/Unity.TextMeshPro.dll
  9. BIN
      Refs/UnityEngine.AssetBundleModule.dll
  10. BIN
      Refs/UnityEngine.CoreModule.Net4.dll
  11. BIN
      Refs/UnityEngine.Net4.dll
  12. BIN
      Refs/UnityEngine.TextRenderingModule.dll
  13. BIN
      Refs/UnityEngine.UI.dll
  14. BIN
      Refs/UnityEngine.UIModule.dll
  15. BIN
      Refs/UnityEngine.UnityWebRequestModule.Net4.dll
  16. +1
    -2
      Refs/refs.txt

+ 0
- 36
BSIPA.sln View File

@ -6,7 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA", "IPA\IPA.csproj", "{14092533-98BB-40A4-9AFC-27BB75672A70}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA", "IPA\IPA.csproj", "{14092533-98BB-40A4-9AFC-27BB75672A70}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {5F33B310-DC8D-4C0D-877E-BAC3908DE10F} {5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {5F33B310-DC8D-4C0D-877E-BAC3908DE10F}
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A} = {E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}
{2A1AF16B-27F1-46E0-9A95-181516BC1CB7} = {2A1AF16B-27F1-46E0-9A95-181516BC1CB7} {2A1AF16B-27F1-46E0-9A95-181516BC1CB7} = {2A1AF16B-27F1-46E0-9A95-181516BC1CB7}
EndProjectSection EndProjectSection
EndProject EndProject
@ -35,8 +34,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollectDependencies", "BuildTools\CollectDependencies\CollectDependencies.csproj", "{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollectDependencies", "BuildTools\CollectDependencies\CollectDependencies.csproj", "{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyRenameStep", "BuildTools\AssemblyRenameStep\AssemblyRenameStep.csproj", "{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSIPA-ModList", "BSIPA-ModList\BSIPA-ModList.csproj", "{23AB2621-A05C-4377-8418-85E6012C0BBE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSIPA-ModList", "BSIPA-ModList\BSIPA-ModList.csproj", "{23AB2621-A05C-4377-8418-85E6012C0BBE}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {5F33B310-DC8D-4C0D-877E-BAC3908DE10F} {5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {5F33B310-DC8D-4C0D-877E-BAC3908DE10F}
@ -223,38 +220,6 @@ Global
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net3.Build.0 = Debug|Any CPU {5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net3.Build.0 = Debug|Any CPU
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net4.ActiveCfg = Debug|Any CPU {5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net4.ActiveCfg = Debug|Any CPU
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net4.Build.0 = Debug|Any CPU {5F33B310-DC8D-4C0D-877E-BAC3908DE10F}.Verbose|x86-Net4.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x64-Net3.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x64-Net3.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x64-Net4.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x64-Net4.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x86-Net3.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x86-Net3.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x86-Net4.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Debug|x86-Net4.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x64-Net3.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x64-Net3.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x64-Net4.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x64-Net4.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x86-Net3.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x86-Net3.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x86-Net4.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Release|x86-Net4.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x64-Net3.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x64-Net3.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x64-Net4.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x64-Net4.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x86-Net3.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x86-Net3.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x86-Net4.ActiveCfg = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose_Release|x86-Net4.Build.0 = Release|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x64-Net3.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x64-Net3.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x64-Net4.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x64-Net4.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x86-Net3.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x86-Net3.Build.0 = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x86-Net4.ActiveCfg = Debug|Any CPU
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A}.Verbose|x86-Net4.Build.0 = Debug|Any CPU
{23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net3.ActiveCfg = Debug|Any CPU {23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net3.ActiveCfg = Debug|Any CPU
{23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net4.ActiveCfg = Debug|Any CPU {23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net4.ActiveCfg = Debug|Any CPU
{23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net4.Build.0 = Debug|Any CPU {23AB2621-A05C-4377-8418-85E6012C0BBE}.Debug|x64-Net4.Build.0 = Debug|Any CPU
@ -336,7 +301,6 @@ Global
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {C79C2C3A-A7FC-40D6-A5CC-9752A661AFA9} {5F33B310-DC8D-4C0D-877E-BAC3908DE10F} = {C79C2C3A-A7FC-40D6-A5CC-9752A661AFA9}
{E2CCDD2F-1D4F-4B06-9CD4-E0D2B9AE543A} = {C79C2C3A-A7FC-40D6-A5CC-9752A661AFA9}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7380FAB-02D6-4A2A-B428-B4BFCFE3A054} SolutionGuid = {C7380FAB-02D6-4A2A-B428-B4BFCFE3A054}


+ 1
- 1
BuildTools

@ -1 +1 @@
Subproject commit 07379607d40ac4acf5932819a935a333548f214e
Subproject commit 41c3a12d56de96a3495893d1fea4a485a98c67af

+ 22
- 1
IPA.Injector/IPA.Injector.csproj View File

@ -125,6 +125,27 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild"> <Target Name="AfterBuild">
<Exec Command="&quot;$(MSBuildBinPath)\MSBuild.exe&quot; &quot;$(MSBuildProjectDirectory)\PostBuild.msbuild&quot; /property:OPath=$(OutputPath) /property:Configuration=$(Configuration) /property:SolDir=$(SolutionDir)" />
<Message Text="Relocating" Importance="normal" />
<ItemGroup>
<SystemFiles Include="$(OutputPath)IPA.Injector.*" />
<SystemFiles Include="$(OutputPath)IPA.Loader.*" />
<SystemFiles Include="$(OutputPath)AsyncBridge.*" />
<SystemFiles Include="$(OutputPath)System.*" />
<SystemFiles Include="$(OutputPath)Portable.System.*" />
<SystemFiles Include="$(OutputPath)Net3-Proxy.*" />
<SystemFiles Include="$(OutputPath)Libraries\Mono\**\*" />
<OldLibFiles Include="$(OutputPath)Libs\**\*" />
</ItemGroup>
<Move SourceFiles="@(SystemFiles)" DestinationFolder="$(OutputPath)Data\Managed" />
<RemoveDir Directories="$(OutputPath)Libraries\Mono" />
<Delete Files="@(OldLibFiles)" />
<RemoveDir Directories="$(OutputPath)Libs" />
<ItemGroup>
<LibFiles Include="$(OutputPath)**\*" Exclude="$(OutputPath)Data\**\*;$(OutputPath)Libs\**\*" />
</ItemGroup>
<Move SourceFiles="@(LibFiles)" DestinationFolder="$(OutputPath)Libs\" />
<RemoveDir Directories="$(OutputPath)Libraries\Included" />
<RemoveDir Directories="$(OutputPath)Libraries" />
</Target> </Target>
</Project> </Project>

+ 0
- 39
IPA.Injector/PostBuild.msbuild View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="PostBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<OPath></OPath>
<SolDir></SolDir>
</PropertyGroup>
<UsingTask TaskName="AssemblyRename" AssemblyFile="$(SolDir)BuildTools\AssemblyRenameStep\bin\$(Configuration)\AssemblyRenameStep.dll" />
<Target Name="PostBuild">
<Message Text="Relocating" Importance="normal" />
<ItemGroup>
<SystemFiles Include="$(OPath)IPA.Injector.*" />
<SystemFiles Include="$(OPath)IPA.Loader.*" />
<SystemFiles Include="$(OPath)AsyncBridge.*" />
<SystemFiles Include="$(OPath)System.*" />
<SystemFiles Include="$(OPath)Portable.System.*" />
<SystemFiles Include="$(OPath)Net3-Proxy.*" />
<SystemFiles Include="$(OPath)Libraries\Mono\**\*" />
<OldLibFiles Include="$(OPath)Libs\**\*" />
</ItemGroup>
<Move SourceFiles="@(SystemFiles)" DestinationFolder="$(OPath)Data\Managed" />
<RemoveDir Directories="$(OPath)Libraries\Mono" />
<Delete Files="@(OldLibFiles)" />
<RemoveDir Directories="$(OPath)Libs" />
<ItemGroup>
<LibFiles Include="$(OPath)**\*" Exclude="$(OPath)Data\**\*;$(OPath)Libs\**\*" />
</ItemGroup>
<Move SourceFiles="@(LibFiles)" DestinationFolder="$(OPath)Libs\" />
<RemoveDir Directories="$(OPath)Libraries\Included" />
<RemoveDir Directories="$(OPath)Libraries" />
<ItemGroup>
<ToRename Include="$(OPath)Libs\**\*.dll" />
</ItemGroup>
<!--<AssemblyRename Assemblies="@(ToRename)" />-->
</Target>
</Project>

+ 1
- 1
IPA.Loader/IPA.Loader.csproj View File

@ -170,7 +170,7 @@
<Version>1.9.1.8</Version> <Version>1.9.1.8</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Lib.Harmony"> <PackageReference Include="Lib.Harmony">
<Version>1.2.0.1</Version>
<Version>2.0.0.7</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Mono.Cecil"> <PackageReference Include="Mono.Cecil">
<Version>0.10.4</Version> <Version>0.10.4</Version>


+ 9
- 13
IPA.Loader/Loader/HarmonyProtector.cs View File

@ -1,4 +1,4 @@
using Harmony;
using HarmonyLib;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
@ -11,19 +11,19 @@ namespace IPA.Loader
internal static class HarmonyProtector internal static class HarmonyProtector
{ {
private static HarmonyInstance instance;
private static Harmony instance;
private static Assembly selfAssem; private static Assembly selfAssem;
private static Assembly harmonyAssem; private static Assembly harmonyAssem;
public static void Protect(HarmonyInstance inst = null)
public static void Protect(Harmony inst = null)
{ {
selfAssem = Assembly.GetExecutingAssembly(); selfAssem = Assembly.GetExecutingAssembly();
harmonyAssem = typeof(HarmonyInstance).Assembly;
harmonyAssem = typeof(Harmony).Assembly;
if (inst == null) if (inst == null)
{ {
if (instance == null) if (instance == null)
instance = HarmonyInstance.Create("BSIPA Safeguard");
instance = new Harmony("BSIPA Safeguard");
inst = instance; inst = instance;
} }
@ -34,16 +34,12 @@ namespace IPA.Loader
inst.Patch(target, new HarmonyMethod(patch)); inst.Patch(target, new HarmonyMethod(patch));
} }
private static void PatchProcessor_Patch_Prefix(ref List<MethodBase> ___originals)
private static bool PatchProcessor_Patch_Prefix(MethodBase ___original, out MethodInfo __result)
{ {
for (int i = 0; i < ___originals.Count; i++)
{
var mi = ___originals[i];
var asm = mi.DeclaringType.Assembly;
var asm = ___original.DeclaringType.Assembly;
if (asm.Equals(selfAssem) || asm.Equals(harmonyAssem))
___originals.RemoveAt(i--);
}
__result = ___original as MethodInfo;
return !(asm.Equals(selfAssem) || asm.Equals(harmonyAssem));
} }
} }
} }

+ 201
- 201
IPA.Loader/Logging/StdoutInterceptor.cs View File

@ -1,201 +1,201 @@
using Harmony;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection.Emit;
using System.Text;
namespace IPA.Logging
{
internal class StdoutInterceptor : TextWriter
{
public override Encoding Encoding => Encoding.Default;
private bool isStdErr;
public override void Write(char value)
{
Write(value.ToString());
}
private string lineBuffer = "";
private object bufferLock = new object();
public override void Write(string value)
{
lock (bufferLock)
{ // avoid threading issues
lineBuffer += value;
var parts = lineBuffer.Split(new[] { Environment.NewLine, "\n", "\r" }, StringSplitOptions.None);
for (int i = 0; i < parts.Length; i++)
{
if (i + 1 == parts.Length) // last element
lineBuffer = parts[i];
else
{
var str = parts[i];
if (string.IsNullOrEmpty(str)) continue;
if (!isStdErr && WinConsole.IsInitialized)
str = ConsoleColorToForegroundSet(currentColor) + str;
if (isStdErr)
Logger.stdout.Error(str);
else
Logger.stdout.Info(str);
}
}
}
}
private const ConsoleColor defaultColor = ConsoleColor.Gray;
private ConsoleColor currentColor = defaultColor;
private static string ConsoleColorToForegroundSet(ConsoleColor col)
{
if (!WinConsole.UseVTEscapes) return "";
string code = "0"; // reset
switch (col)
{
case ConsoleColor.Black:
code = "30";
break;
case ConsoleColor.DarkBlue:
code = "34";
break;
case ConsoleColor.DarkGreen:
code = "32";
break;
case ConsoleColor.DarkCyan:
code = "36";
break;
case ConsoleColor.DarkRed:
code = "31";
break;
case ConsoleColor.DarkMagenta:
code = "35";
break;
case ConsoleColor.DarkYellow:
code = "33";
break;
case ConsoleColor.Gray:
code = "37";
break;
case ConsoleColor.DarkGray:
code = "90"; // literally bright black
break;
case ConsoleColor.Blue:
code = "94";
break;
case ConsoleColor.Green:
code = "92";
break;
case ConsoleColor.Cyan:
code = "96";
break;
case ConsoleColor.Red:
code = "91";
break;
case ConsoleColor.Magenta:
code = "95";
break;
case ConsoleColor.Yellow:
code = "93";
break;
case ConsoleColor.White:
code = "97";
break;
}
return "\x1b[" + code + "m";
}
private static StdoutInterceptor stdoutInterceptor;
private static StdoutInterceptor stderrInterceptor;
private static class ConsoleHarmonyPatches
{
public static void Patch(HarmonyInstance harmony)
{
var console = typeof(Console);
var resetColor = console.GetMethod("ResetColor");
var foregroundProperty = console.GetProperty("ForegroundColor");
var setFg = foregroundProperty?.GetSetMethod();
var getFg = foregroundProperty?.GetGetMethod();
if (resetColor != null)
harmony.Patch(resetColor, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchResetColor)));
if (foregroundProperty != null)
{
harmony.Patch(setFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchSetForegroundColor)));
harmony.Patch(getFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchGetForegroundColor)));
}
}
public static ConsoleColor GetColor() => stdoutInterceptor.currentColor;
public static void SetColor(ConsoleColor col) => stdoutInterceptor.currentColor = col;
public static void ResetColor() => stdoutInterceptor.currentColor = defaultColor;
public static IEnumerable<CodeInstruction> PatchGetForegroundColor(IEnumerable<CodeInstruction> _)
{
var getColorM = typeof(ConsoleHarmonyPatches).GetMethod("GetColor");
return new[] {
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, getColorM),
new CodeInstruction(OpCodes.Ret)
};
}
public static IEnumerable<CodeInstruction> PatchSetForegroundColor(IEnumerable<CodeInstruction> _)
{
var setColorM = typeof(ConsoleHarmonyPatches).GetMethod("SetColor");
return new[] {
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, setColorM),
new CodeInstruction(OpCodes.Ret)
};
}
public static IEnumerable<CodeInstruction> PatchResetColor(IEnumerable<CodeInstruction> _)
{
var resetColor = typeof(ConsoleHarmonyPatches).GetMethod("ResetColor");
return new[] {
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, resetColor),
new CodeInstruction(OpCodes.Ret)
};
}
}
private static HarmonyInstance harmony;
private static bool usingInterceptor = false;
public static void Intercept()
{
if (!usingInterceptor)
{
usingInterceptor = true;
if (harmony == null)
harmony = HarmonyInstance.Create("BSIPA Console Redirector Patcher");
if (stdoutInterceptor == null)
stdoutInterceptor = new StdoutInterceptor();
if (stderrInterceptor == null)
stderrInterceptor = new StdoutInterceptor() { isStdErr = true };
RedirectConsole();
ConsoleHarmonyPatches.Patch(harmony);
}
}
public static void RedirectConsole()
{
if (usingInterceptor)
{
Console.SetOut(stdoutInterceptor);
Console.SetError(stderrInterceptor);
}
}
}
}
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection.Emit;
using System.Text;
namespace IPA.Logging
{
internal class StdoutInterceptor : TextWriter
{
public override Encoding Encoding => Encoding.Default;
private bool isStdErr;
public override void Write(char value)
{
Write(value.ToString());
}
private string lineBuffer = "";
private object bufferLock = new object();
public override void Write(string value)
{
lock (bufferLock)
{ // avoid threading issues
lineBuffer += value;
var parts = lineBuffer.Split(new[] { Environment.NewLine, "\n", "\r" }, StringSplitOptions.None);
for (int i = 0; i < parts.Length; i++)
{
if (i + 1 == parts.Length) // last element
lineBuffer = parts[i];
else
{
var str = parts[i];
if (string.IsNullOrEmpty(str)) continue;
if (!isStdErr && WinConsole.IsInitialized)
str = ConsoleColorToForegroundSet(currentColor) + str;
if (isStdErr)
Logger.stdout.Error(str);
else
Logger.stdout.Info(str);
}
}
}
}
private const ConsoleColor defaultColor = ConsoleColor.Gray;
private ConsoleColor currentColor = defaultColor;
private static string ConsoleColorToForegroundSet(ConsoleColor col)
{
if (!WinConsole.UseVTEscapes) return "";
string code = "0"; // reset
switch (col)
{
case ConsoleColor.Black:
code = "30";
break;
case ConsoleColor.DarkBlue:
code = "34";
break;
case ConsoleColor.DarkGreen:
code = "32";
break;
case ConsoleColor.DarkCyan:
code = "36";
break;
case ConsoleColor.DarkRed:
code = "31";
break;
case ConsoleColor.DarkMagenta:
code = "35";
break;
case ConsoleColor.DarkYellow:
code = "33";
break;
case ConsoleColor.Gray:
code = "37";
break;
case ConsoleColor.DarkGray:
code = "90"; // literally bright black
break;
case ConsoleColor.Blue:
code = "94";
break;
case ConsoleColor.Green:
code = "92";
break;
case ConsoleColor.Cyan:
code = "96";
break;
case ConsoleColor.Red:
code = "91";
break;
case ConsoleColor.Magenta:
code = "95";
break;
case ConsoleColor.Yellow:
code = "93";
break;
case ConsoleColor.White:
code = "97";
break;
}
return "\x1b[" + code + "m";
}
private static StdoutInterceptor stdoutInterceptor;
private static StdoutInterceptor stderrInterceptor;
private static class ConsoleHarmonyPatches
{
public static void Patch(Harmony harmony)
{
var console = typeof(Console);
var resetColor = console.GetMethod("ResetColor");
var foregroundProperty = console.GetProperty("ForegroundColor");
var setFg = foregroundProperty?.GetSetMethod();
var getFg = foregroundProperty?.GetGetMethod();
if (resetColor != null)
harmony.Patch(resetColor, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchResetColor)));
if (foregroundProperty != null)
{
harmony.Patch(setFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchSetForegroundColor)));
harmony.Patch(getFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), nameof(PatchGetForegroundColor)));
}
}
public static ConsoleColor GetColor() => stdoutInterceptor.currentColor;
public static void SetColor(ConsoleColor col) => stdoutInterceptor.currentColor = col;
public static void ResetColor() => stdoutInterceptor.currentColor = defaultColor;
public static IEnumerable<CodeInstruction> PatchGetForegroundColor(IEnumerable<CodeInstruction> _)
{
var getColorM = typeof(ConsoleHarmonyPatches).GetMethod("GetColor");
return new[] {
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, getColorM),
new CodeInstruction(OpCodes.Ret)
};
}
public static IEnumerable<CodeInstruction> PatchSetForegroundColor(IEnumerable<CodeInstruction> _)
{
var setColorM = typeof(ConsoleHarmonyPatches).GetMethod("SetColor");
return new[] {
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, setColorM),
new CodeInstruction(OpCodes.Ret)
};
}
public static IEnumerable<CodeInstruction> PatchResetColor(IEnumerable<CodeInstruction> _)
{
var resetColor = typeof(ConsoleHarmonyPatches).GetMethod("ResetColor");
return new[] {
new CodeInstruction(OpCodes.Tailcall),
new CodeInstruction(OpCodes.Call, resetColor),
new CodeInstruction(OpCodes.Ret)
};
}
}
private static Harmony harmony;
private static bool usingInterceptor = false;
public static void Intercept()
{
if (!usingInterceptor)
{
usingInterceptor = true;
if (harmony == null)
harmony = new Harmony("BSIPA Console Redirector Patcher");
if (stdoutInterceptor == null)
stdoutInterceptor = new StdoutInterceptor();
if (stderrInterceptor == null)
stderrInterceptor = new StdoutInterceptor() { isStdErr = true };
RedirectConsole();
ConsoleHarmonyPatches.Patch(harmony);
}
}
public static void RedirectConsole()
{
if (usingInterceptor)
{
Console.SetOut(stdoutInterceptor);
Console.SetError(stderrInterceptor);
}
}
}
}

BIN
Refs/Unity.TextMeshPro.dll View File


BIN
Refs/UnityEngine.AssetBundleModule.dll View File


BIN
Refs/UnityEngine.CoreModule.Net4.dll View File


BIN
Refs/UnityEngine.Net4.dll View File


BIN
Refs/UnityEngine.TextRenderingModule.dll View File


BIN
Refs/UnityEngine.UI.dll View File


BIN
Refs/UnityEngine.UIModule.dll View File


BIN
Refs/UnityEngine.UnityWebRequestModule.Net4.dll View File


+ 1
- 2
Refs/refs.txt View File

@ -15,8 +15,7 @@
::from ./bsinstalldir.txt ::from ./bsinstalldir.txt
"Beat Saber_Data/ "Beat Saber_Data/
""Managed/ ""Managed/
"""Assembly-CSharp.dll?virt
"""MainAssembly.dll?virt
"""Main.dll?virt
"""Unity.TextMeshPro.dll """Unity.TextMeshPro.dll
"""UnityEngine. """UnityEngine.
""""TextRenderingModule. """"TextRenderingModule.


Loading…
Cancel
Save