diff --git a/MethodInjector/Program.cs b/MethodInjector/Program.cs index 7528b5a..777e1b5 100644 --- a/MethodInjector/Program.cs +++ b/MethodInjector/Program.cs @@ -16,10 +16,7 @@ class Program // A reference to the assembly we are hacking private static Assembly theyAreBillionsAssembly; - - // Original methods - private static MethodInfo originalEntity_EventOnUpdate = null; - + // Called when the program is launched static void Main(string[] args) { @@ -64,7 +61,9 @@ Perform patching ReplaceMethod("ZX.ZXGame", "get_IsBetaPrivateVersion", BindingFlags.Static | BindingFlags.Public); // Instant Build - //originalEntity_EventOnUpdate = ReplaceMethod("ZX.Components.CBuildable", "Entity_EventOnUpdate", BindingFlags.NonPublic | BindingFlags.Instance); + ReplaceMethod("ZX.ZXCommandDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance); + ReplaceMethod("ZX.ZXEntityDefaultParams", "get_BuildingTime", BindingFlags.Public | BindingFlags.Instance); + // Get a reference to the Main method MethodInfo main = ZXProgram.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic); @@ -91,22 +90,43 @@ Perform patching } + // Returns a field + public static FieldInfo GetField(string className, string fieldName, BindingFlags attr) + { + // Grab the method we will replace + Type theType = theyAreBillionsAssembly.GetType(className); + if (theType == null) + { + LogMessage("Failed to find class: " + className); + return null; + } + + // Return the field + FieldInfo field = theType.GetField(fieldName, attr); + + if(field == null) + { + LogMessage("Failed to find field: " + className + " :: " + fieldName); + } + return field; + } + // Replaces a method with one defined below - public static MethodInfo ReplaceMethod(string className, string methodName, BindingFlags attr) + public static void ReplaceMethod(string className, string methodName, BindingFlags attr) { // Grab the method we will replace Type theType = theyAreBillionsAssembly.GetType(className); if(theType == null) { LogMessage("Failed to find class: " + className); - return null; + return; } MethodInfo targetMethod = theType.GetMethod(methodName, attr); if(targetMethod == null) { LogMessage("Failed to find method: " + className + " :: " + methodName); - return null; + return; } // Grab the method we will inject @@ -114,7 +134,7 @@ public static MethodInfo ReplaceMethod(string className, string methodName, Bind if (newMethod == null) { LogMessage("Failed to find replacement method: " + className + " :: " + methodName); - return null; + return; } // Prepare methods @@ -148,6 +168,7 @@ public static MethodInfo ReplaceMethod(string className, string methodName, Bind long* inj = (long*)newMethod.MethodHandle.Value.ToPointer() + 1; long* tar = (long*)targetMethod.MethodHandle.Value.ToPointer() + 1; + long tarOriginal = *tar; #if DEBUG //Console.WriteLine("\nVersion x64 Debug\n"); byte* injInst = (byte*)*inj; @@ -161,15 +182,13 @@ public static MethodInfo ReplaceMethod(string className, string methodName, Bind #else //Console.WriteLine("\nVersion x64 Release\n"); *tar = *inj; + *inj = tarOriginal; #endif } } // Log success LogMessage("Successfully replaced: " + className + " :: " + methodName); - - // Sucess - return targetMethod; } // Replacement for can pay resources @@ -203,12 +222,13 @@ public static bool get_IsBetaPrivateVersion() return true; } - // Entity Update replacement - private void Entity_EventOnUpdate() + // The amount of time that things take to build + public int get_BuildingTime() { - + // Lowest possible build time + return 1; } - + private static void LogMessage(string error) { System.IO.File.AppendAllText("inject.log", "error: " + error + Environment.NewLine); diff --git a/README.md b/README.md index 2b330c6..303740f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Tools & Research notes for modding "They Are Billions" - Allow loading of hacked save games -- This simply turns of the save game checksum code that is being used. - Building costs no money -- This removes the cost of buildings, and allows you to build even if you have negative resources. - Enable DEV and PRIVATE modes. + - Instant Build -- Makes buildings build almost instantly ### Cheats - Enable cheats by pressing `control` + `shift` + `H`