Skip to content

Commit

Permalink
v0.2.7.1 Update, See CHANGELOG for Full Details
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Aug 30, 2020
1 parent 886210e commit 14a404e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
6. Exposed new Console Output Handle and assign it to Managed Console Class Output. (Credits to knah :D)
7. Added Unity 2019.4.3 Dependencies.
8. Bumped Il2CppAssemblyUnhollower Version.
9. Use a different approach to console cleaning for better interop with other tools. (Credits to knah :D)

---

Expand Down
2 changes: 1 addition & 1 deletion MelonLoader.ModHandler/BuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public static class BuildInfo
public const string Description = "MelonLoader";
public const string Author = "Lava Gang";
public const string Company = "discord.gg/2Wn3N2P";
public const string Version = "0.2.7";
public const string Version = "0.2.7.1";
}
}
23 changes: 23 additions & 0 deletions MelonLoader.Support.Il2Cpp/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Runtime;
using UnhollowerRuntimeLib;
Expand Down Expand Up @@ -30,6 +31,28 @@ private static ISupportModule Initialize()
GetUnityVersionNumbers(out var major, out var minor, out var patch);
UnityVersionHandler.Initialize(major, minor, patch);

// Il2CppSystem.Console.SetOut(new Il2CppSystem.IO.StreamWriter(Il2CppSystem.IO.Stream.Null));
try
{
var il2CppSystemAssembly = Assembly.Load("Il2Cppmscorlib");

var consoleType = il2CppSystemAssembly.GetType("Il2CppSystem.Console");
var streamWriterType = il2CppSystemAssembly.GetType("Il2CppSystem.IO.StreamWriter");
var streamType = il2CppSystemAssembly.GetType("Il2CppSystem.IO.Stream");

var setOutMethod = consoleType.GetMethod("SetOut", BindingFlags.Static | BindingFlags.Public);
var nullStreamField = streamType.GetProperty("Null", BindingFlags.Static | BindingFlags.Public).GetGetMethod();
var streamWriterCtor = streamWriterType.GetConstructor(new[] {streamType});

var nullStream = nullStreamField.Invoke(null, new object[0]);
var steamWriter = streamWriterCtor.Invoke(new[] {nullStream});
setOutMethod.Invoke(null, new[] {steamWriter});
}
catch (Exception ex)
{
MelonLogger.LogError($"Console cleaning failed: {ex}");
}

SetAsLastSiblingDelegateField = IL2CPP.ResolveICall<SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");

ClassInjector.RegisterTypeInIl2Cpp<MelonLoaderComponent>();
Expand Down
11 changes: 5 additions & 6 deletions MelonLoader/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ void Console::Create()
hwndConsole = GetConsoleWindow();
SetTitle(("MelonLoader " + (MelonLoader::DebugMode ? std::string("Debug") : std::string("Normal")) + " Console").c_str());
SetForegroundWindow(hwndConsole);
AlwaysOnTopCheck();
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetStdHandle(STD_OUTPUT_HANDLE, NULL);
AlwaysOnTopCheck();
freopen_s(reinterpret_cast<FILE**>(stdout), "CONOUT$", "w", stdout);
}
else
MessageBox(NULL, ("Failed to Create the " + (MelonLoader::DebugMode ? std::string("Debug") : std::string("Normal")) + " Console!").c_str(), NULL, MB_OK | MB_ICONEXCLAMATION);
// if it returned false, console was already allocated, just grab the handle from it
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
}
}

Expand Down Expand Up @@ -70,7 +69,7 @@ void Console::Write(const char* txt)
ChromiumCheck();
RainbowCheck();
AlwaysOnTopCheck();
WriteConsole(OutputHandle, txt, strlen(txt), NULL, NULL);
std::cout << txt;
ResetColor();
}
};
Expand Down
4 changes: 2 additions & 2 deletions MelonLoader/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class Console
static void Write(std::string txt) { Write(txt.c_str()); }
static void Write(std::string txt, ConsoleColor color) { Write(txt.c_str(), color); }

static void WriteLine(const char* txt) { Write(txt); Write("\n"); }
static void WriteLine(const char* txt, ConsoleColor color) { Write(txt, color); Write("\n"); }
static void WriteLine(const char* txt) { Write(txt); std::cout << std::endl; }
static void WriteLine(const char* txt, ConsoleColor color) { Write(txt, color); std::cout << std::endl; }
static void WriteLine(std::string txt) { WriteLine(txt.c_str()); }
static void WriteLine(std::string txt, ConsoleColor color) { WriteLine(txt.c_str(), color); }
};
2 changes: 1 addition & 1 deletion MelonLoader/DisableAnalytics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ int DisableAnalytics::Hooked_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, vo
Logger::LogError("Exception caught in getaddrinfo! Returning WSATRY_AGAIN");
return WSATRY_AGAIN;
}
}
}

0 comments on commit 14a404e

Please sign in to comment.