From dbc111c514c00561a2ecf348963f6e110872197c Mon Sep 17 00:00:00 2001 From: Ashley Schmid Date: Sat, 6 Jan 2018 13:44:21 +1100 Subject: [PATCH] Fixed annoying MethodInjector crash --- MethodInjector/Program.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/MethodInjector/Program.cs b/MethodInjector/Program.cs index a2427fc..09ddd87 100644 --- a/MethodInjector/Program.cs +++ b/MethodInjector/Program.cs @@ -14,6 +14,9 @@ class Program // The name of the executable to inject into private static string theExecutable = "TheyAreBillions.exe"; + // The file to log to + private static string logFileName = "MethodInjector_log.txt"; + // A reference to the assembly we are hacking private static Assembly theyAreBillionsAssembly; @@ -82,11 +85,11 @@ static void Main(string[] args) break; case "enabledevtools": - allowFreeBuildings = isEnabled; + enableDevTools = isEnabled; break; case "enableinstantbuild": - allowFreeBuildings = isEnabled; + enableInstantBuild = isEnabled; break; case "allowfreebuildings": @@ -130,7 +133,7 @@ Perform patching ReplaceMethod("ZX.ZXGame", "get_IsDevelopmentVersion", BindingFlags.Static | BindingFlags.Public); ReplaceMethod("ZX.ZXGame", "get_IsBetaPrivateVersion", BindingFlags.Static | BindingFlags.Public); } - ReplaceMethod("ZX.ZXSteam", "ValidateSteamLicense", BindingFlags.Static | BindingFlags.Public); + ReplaceMethod("ZX.ZXSteam", "ValidateSteamLicense", BindingFlags.Static | BindingFlags.Public, true, true); // Instant Build if (enableInstantBuild) @@ -196,7 +199,7 @@ public static FieldInfo GetField(string className, string fieldName, BindingFlag } // Replaces a method with one defined below - public static void ReplaceMethod(string className, string methodName, BindingFlags attr, bool bothWays = true) + public static void ReplaceMethod(string className, string methodName, BindingFlags attr, bool bothWays = true, bool showMessage=true) { // Grab the method we will replace Type theType = theyAreBillionsAssembly.GetType(className); @@ -277,7 +280,10 @@ public static void ReplaceMethod(string className, string methodName, BindingFla } // Log success - LogMessage("Successfully replaced: " + className + " :: " + methodName); + if(showMessage) + { + LogMessage("Successfully replaced: " + className + " :: " + methodName); + } } // Enable cheats @@ -331,9 +337,10 @@ public int get_BuildingTime() return 1; } - private static void LogMessage(string error) + private static void LogMessage(string message) { - System.IO.File.AppendAllText("inject.log", "error: " + error + Environment.NewLine); + Console.WriteLine("MethodInjector: " + message); + System.IO.File.AppendAllText(logFileName, message + Environment.NewLine); } } }