Changeset 107 for binary-improvements/assembly-patcher/Main.cs
- Timestamp:
- Jul 26, 2014, 4:41:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/assembly-patcher/Main.cs
r96 r107 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Reflection; 3 4 using Mono.Cecil; … … 14 15 TypeDefinition type = module.GetType ("GameManager"); 15 16 if (isPatched (type)) { 16 Console.WriteLine ("Assembly already patched");17 Console.WriteLine ("Assembly already patched"); 17 18 return; 18 19 } 19 20 markTypePatched (module, type); 20 21 22 consoleOutputPatch (module); 21 23 telnetPatch (module); 22 24 connectLogPatch (module); 23 executionLogPatch (module);24 25 publicCommandPermissionsPatch (module); 25 26 playerDataPatch (module); 27 26 28 module.Write ("Assembly-CSharp.dll"); 27 29 Console.WriteLine ("Done"); 30 31 } 32 33 private static void consoleOutputPatch (ModuleDefinition module) 34 { 35 TypeDefinition type = module.GetType ("ConsoleSdtd"); 36 replaceMethod (type, "ExecuteCmdFromClient", true, 3, typeof(ConsoleOutputSeparator).GetMethod ("C_ExecuteCmdFromClient")); 37 addHook (type, "Run", true, 0, true, typeof(ConsoleOutputSeparator).GetMethod ("C_Run")); 38 replaceMethod (type, "SendResult", true, 1, typeof(ConsoleOutputSeparator).GetMethod ("C_SendResult")); 39 28 40 } 29 41 … … 31 43 { 32 44 TypeDefinition type = module.GetType ("GameManager"); 33 34 45 addHook (type, "SavePlayerData", true, 2, true, typeof(PlayerDataStuff).GetMethod ("GM_SavePlayerData")); 35 addHook (type, "Awake", true, 0, true, typeof(CommandExtensions).GetMethod ("InitCommandExtensions"));46 addHook (type, "Awake", true, 0, true, typeof(CommandExtensions).GetMethod ("InitCommandExtensions")); 36 47 } 37 48 … … 39 50 { 40 51 TypeDefinition type = module.GetType ("AdminTools"); 41 42 52 replaceMethod (type, "GetAllowedCommandsList", true, 1, typeof(AdminToolsStuff).GetMethod ("GetAllowedCommandsList")); 43 53 } … … 46 56 { 47 57 TypeDefinition type = module.GetType ("GameManager"); 48 49 58 addHook (type, "RequestToSpawnPlayer", true, 5, true, typeof(AllocsLogFunctions).GetMethod ("RequestToSpawnPlayer")); 50 }51 52 private static void executionLogPatch (ModuleDefinition module)53 {54 TypeDefinition type = module.GetType ("ConsoleSdtd");55 56 addHook (type, "ExecuteCmdFromClient", true, 3, false, typeof(AllocsLogFunctions).GetMethod ("ExecuteCmdFromClient"));57 59 } 58 60 … … 60 62 { 61 63 TypeDefinition type = module.GetType ("NetTelnetServer"); 62 63 64 replaceMethod (type, ".ctor", false, 1, typeof(AllocsNetTelnetServer).GetMethod ("init")); 64 65 replaceMethod (type, "Disconnect", false, 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect")); … … 76 77 foreach (MethodDefinition method in type.Methods) { 77 78 if (method.Name.Equals (methodName)) { 78 Console.WriteLine ("Patching " + methodName);79 79 var il = method.Body.GetILProcessor (); 80 80 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); … … 98 98 il.InsertBefore (method.Body.Instructions [i++], call); 99 99 } 100 return; 100 101 } 101 102 } 103 Console.WriteLine ("ERROR: Did not find " + type.Name + "." + methodName + "()"); 102 104 } 103 105 … … 106 108 foreach (MethodDefinition method in type.Methods) { 107 109 if (method.Name.Equals (methodName)) { 108 Console.WriteLine ("Patching " + methodName);109 110 var il = method.Body.GetILProcessor (); 110 111 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); … … 117 118 il.InsertBefore (method.Body.Instructions [i++], call); 118 119 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ret)); 120 return; 119 121 } 120 122 } 123 Console.WriteLine ("ERROR: Did not find " + type.Name + "." + methodName + "()"); 121 124 } 122 125 … … 125 128 foreach (FieldDefinition fd in type.Fields) { 126 129 if (fd.Name.Equals ("AllocsPatch")) { 127 Console.WriteLine ("\"" + type.Name + "\" is already patched, skipping");128 130 return true; 129 131 } 130 132 } 131 Console.WriteLine ("Patching \"" + type.Name + "\"");132 133 return false; 133 134 }
Note:
See TracChangeset
for help on using the changeset viewer.