Browse Source

Lots of adjustments to work on .NET 3

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
ba38c12394
9 changed files with 56 additions and 12 deletions
  1. +1
    -1
      Doorstop
  2. +15
    -0
      IPA.Injector/Injector.cs
  3. +0
    -2
      IPA.Loader/Config/SelfConfig.cs
  4. +5
    -0
      IPA.Loader/Loader/LibLoader.cs
  5. +9
    -2
      IPA.Loader/Logging/ConsoleWindow.cs
  6. +9
    -1
      IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs
  7. +7
    -1
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  8. +9
    -5
      IPA.Loader/Logging/StdoutInterceptor.cs
  9. +1
    -0
      docs/build.ps1

+ 1
- 1
Doorstop

@ -1 +1 @@
Subproject commit 02647aa40bdde4e5027eb596082a6787497b92e9
Subproject commit bcab2ee05684ad679aa926b4414600f3892657f0

+ 15
- 0
IPA.Injector/Injector.cs View File

@ -16,6 +16,7 @@ using MethodAttributes = Mono.Cecil.MethodAttributes;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
using File = Net3_Proxy.File;
using Directory = Net3_Proxy.Directory;
#endif
@ -29,6 +30,7 @@ namespace IPA.Injector
{
private static Task pluginAsyncLoadTask;
private static Task permissionFixTask;
private static string otherNewtonsoftJson = null;
// ReSharper disable once UnusedParameter.Global
internal static void Main(string[] args)
@ -45,6 +47,16 @@ namespace IPA.Injector
SetupLibraryLoading();
var otherNewtonsoft = Path.Combine(
Directory.EnumerateDirectories(Environment.CurrentDirectory, "*_Data").First(),
"Managed",
"Newtonsoft.Json.dll");
if (File.Exists(otherNewtonsoft))
{ // this game ships its own Newtonsoft; force load ours and flag loading theirs
LibLoader.LoadLibrary(new AssemblyName("Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"));
otherNewtonsoftJson = otherNewtonsoft;
}
EnsureDirectories();
// this is weird, but it prevents Mono from having issues loading the type.
@ -259,6 +271,9 @@ namespace IPA.Injector
if (bootstrapped) return;
bootstrapped = true;
if (otherNewtonsoftJson != null)
Assembly.LoadFrom(otherNewtonsoftJson);
Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
{
var level = UnityLogRedirector.LogTypeToLevel(type);


+ 0
- 2
IPA.Loader/Config/SelfConfig.cs View File

@ -51,7 +51,6 @@ namespace IPA.Config
public bool AutoCheckUpdates = true;
}
[JsonProperty(Required = Required.Always)]
public UpdateObject Updates = new UpdateObject();
public class DebugObject
@ -63,7 +62,6 @@ namespace IPA.Config
public int HideLogThreshold = 512;
}
[JsonProperty(Required = Required.Always)]
public DebugObject Debug = new DebugObject();
[JsonProperty(Required = Required.Default)]


+ 5
- 0
IPA.Loader/Loader/LibLoader.cs View File

@ -49,6 +49,11 @@ namespace IPA.Loader
public static Assembly AssemblyLibLoader(object source, ResolveEventArgs e)
{
var asmName = new AssemblyName(e.Name);
return LoadLibrary(asmName);
}
internal static Assembly LoadLibrary(AssemblyName asmName)
{
Log(Logger.Level.Debug, $"Resolving library {asmName}");
SetupAssemblyFilenames();


+ 9
- 2
IPA.Loader/Logging/ConsoleWindow.cs View File

@ -91,7 +91,14 @@ namespace IPA.Logging
if (!file.IsInvalid)
{
handle = file;
#if NET4
var fs = new FileStream(file, dotNetFileAccess);
#elif NET3
#pragma warning disable CS0618
// this is marked obsolete, and shouldn't need to be used, but the constructor used in .NET 4 doesn't exist in Unity's mscorlib.dll
var fs = new FileStream(file.DangerousGetHandle(), dotNetFileAccess);
#pragma warning restore
#endif
return fs;
}
@ -99,7 +106,7 @@ namespace IPA.Logging
return null;
}
#region Win API Functions and Constants
#region Win API Functions and Constants
[DllImport("kernel32.dll",
EntryPoint = "AllocConsole",
SetLastError = true,
@ -150,6 +157,6 @@ namespace IPA.Logging
private const uint AttachParent = 0xFFFFFFFF;
#endregion
#endregion
}
}

+ 9
- 1
IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs View File

@ -19,7 +19,9 @@ namespace IPA.Logging.Printers
/// The color to print messages as.
/// </summary>
/// <value>the color to print this message as</value>
public ConsoleColor Color { get; set; } = Console.ForegroundColor;
// Initializer calls this function because Unity's .NET 3.5 doesn't have the color properties on Console
// TODO: move this garbo out to Net3_Proxy
public ConsoleColor Color { get; set; } = GetConsoleColor(WinConsole.OutHandle);
/// <summary>
/// Prints an entry to the console window.
@ -71,6 +73,12 @@ namespace IPA.Logging.Printers
return (short)(attr | (int)color);
}
private static ConsoleColor GetConsoleColor(IntPtr handle)
{
GetConsoleScreenBufferInfo(handle, out var info);
return (ConsoleColor)(info.Attribute & 15);
}
// ReSharper disable NotAccessedField.Local
#pragma warning disable 649


+ 7
- 1
IPA.Loader/Logging/Printers/GZFilePrinter.cs View File

@ -23,7 +23,13 @@ namespace IPA.Logging.Printers
IntPtr lpSecurityAttributes
);
internal static Regex removeControlCodes = new Regex("\x1b\\[\\d+m", RegexOptions.Compiled);
#if NET4
private const RegexOptions reOptions = RegexOptions.Compiled;
#elif NET3 // Needed because Compiled doesn't exist in Unity's .NET 3 runtime
private const RegexOptions reOptions = RegexOptions.None;
#endif
internal static Regex removeControlCodes = new Regex("\x1b\\[\\d+m", reOptions);
private FileInfo fileInfo;


+ 9
- 5
IPA.Loader/Logging/StdoutInterceptor.cs View File

@ -121,12 +121,16 @@ namespace IPA.Logging
var console = typeof(Console);
var resetColor = console.GetMethod("ResetColor");
var foregroundProperty = console.GetProperty("ForegroundColor");
var setFg = foregroundProperty.GetSetMethod();
var getFg = foregroundProperty.GetGetMethod();
var setFg = foregroundProperty?.GetSetMethod();
var getFg = foregroundProperty?.GetGetMethod();
harmony.Patch(resetColor, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchResetColor"));
harmony.Patch(setFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchSetForegroundColor"));
harmony.Patch(getFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchGetForegroundColor"));
if (resetColor != null)
harmony.Patch(resetColor, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchResetColor"));
if (foregroundProperty != null)
{
harmony.Patch(setFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchSetForegroundColor"));
harmony.Patch(getFg, transpiler: new HarmonyMethod(typeof(ConsoleHarmonyPatches), "PatchGetForegroundColor"));
}
}
public static ConsoleColor GetColor() => stdoutInterceptor.currentColor;


+ 1
- 0
docs/build.ps1 View File

@ -55,6 +55,7 @@ if ((Test-Path $newtonsoftLoc -PathType Leaf) -and (Test-Path $selfConfigLoc -Pa
# Generate schema
$schemagen = New-Object -TypeName Newtonsoft.Json.Schema.Generation.JSchemaGenerator
$schemagen.DefaultRequired = [Newtonsoft.Json.Required]::Always
$schema = $schemagen.Generate([IPA.Config.SelfConfig])
$schema.ToString() | Out-File "other_api/config/_schema.json"


Loading…
Cancel
Save