Changeset 84 for binary-improvements/assembly-patcher/Main.cs
- Timestamp:
- Jul 19, 2014, 12:47:32 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/assembly-patcher/Main.cs
r83 r84 14 14 connectLogPatch (module); 15 15 executionLogPatch( module); 16 publicCommandPermissionsPatch (module); 16 17 module.Write ("Assembly-CSharp.dll"); 17 18 Console.WriteLine ("Done"); 19 } 20 21 private static void publicCommandPermissionsPatch (ModuleDefinition module) 22 { 23 TypeDefinition type = module.GetType ("AdminTools"); 24 25 if (isPatched (type)) { 26 return; 27 } 28 29 markTypePatched (module, type); 30 replaceMethod (type, "GetAllowedCommandsList", true, 1, typeof(AdminToolsStuff).GetMethod ("GetAllowedCommandsList")); 18 31 } 19 32 … … 51 64 52 65 markTypePatched (module, type); 53 replaceMethod (type, ".ctor", 1, typeof(AllocsNetTelnetServer).GetMethod ("init"));54 replaceMethod (type, "Disconnect", 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect"));55 replaceMethod (type, "SetConsole", 1, typeof(AllocsNetTelnetServer).GetMethod ("SetConsole"));56 replaceMethod (type, "WriteToClient", 1, typeof(AllocsNetTelnetServer).GetMethod ("WriteToClient"));66 replaceMethod (type, ".ctor", false, 1, typeof(AllocsNetTelnetServer).GetMethod ("init")); 67 replaceMethod (type, "Disconnect", false, 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect")); 68 replaceMethod (type, "SetConsole", false, 1, typeof(AllocsNetTelnetServer).GetMethod ("SetConsole")); 69 replaceMethod (type, "WriteToClient", false, 1, typeof(AllocsNetTelnetServer).GetMethod ("WriteToClient")); 57 70 } 58 71 … … 92 105 } 93 106 94 private static void replaceMethod (TypeDefinition type, string methodName, int opCount, MethodBase targetMethod)107 private static void replaceMethod (TypeDefinition type, string methodName, bool addThisRef, int opCount, MethodBase targetMethod) 95 108 { 96 109 foreach (MethodDefinition method in type.Methods) { … … 100 113 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); 101 114 var i = 0; 115 if (addThisRef) 116 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, 0)); 102 117 for (int op = 0; op < opCount; op++) { 103 118 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, op + 1));
Note:
See TracChangeset
for help on using the changeset viewer.