Skip to content

Commit

Permalink
Fixed annoying MethodInjector crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ash47 committed Jan 6, 2018
1 parent edf8fe8 commit dbc111c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions MethodInjector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit dbc111c

Please sign in to comment.