Changeset 76 for binary-improvements/assembly-patcher
- Timestamp:
- Jul 17, 2014, 1:46:42 AM (10 years ago)
- Location:
- binary-improvements/assembly-patcher
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/assembly-patcher/Main.cs
r75 r76 12 12 ModuleDefinition module = ModuleDefinition.ReadModule ("Assembly-CSharp.dll"); 13 13 telnetPatch (module); 14 connectLogPatch (module);14 connectLogPatch (module); 15 15 module.Write ("Assembly-CSharp.dll"); 16 16 Console.WriteLine ("Done"); … … 26 26 27 27 markTypePatched (module, type); 28 addHook (type, "RequestToSpawnPlayer", true, 5, t ypeof(AllocsRequestToSpawnPlayer).GetMethod ("RequestToSpawnPlayer"));28 addHook (type, "RequestToSpawnPlayer", true, 5, true, typeof(AllocsRequestToSpawnPlayer).GetMethod ("RequestToSpawnPlayer")); 29 29 } 30 30 … … 49 49 } 50 50 51 private static void addHook (TypeDefinition type, string methodName, bool addThisRef, int opCount, MethodBase targetMethod)51 private static void addHook (TypeDefinition type, string methodName, bool addThisRef, int opCount, bool atEnd, MethodBase targetMethod) 52 52 { 53 53 foreach (MethodDefinition method in type.Methods) { … … 56 56 var il = method.Body.GetILProcessor (); 57 57 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); 58 var i = 0; 59 if (addThisRef) 60 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, 0)); 61 for (int op = 0; op < opCount; op++) { 62 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, op + 1)); 58 if (atEnd) { 59 int insBefore = method.Body.Instructions.Count; 60 if (addThisRef) 61 il.Append (il.Create (OpCodes.Ldarg, 0)); 62 for (int op = 0; op < opCount; op++) { 63 il.Append (il.Create (OpCodes.Ldarg, op + 1)); 64 } 65 il.Append (call); 66 il.Remove (method.Body.Instructions [insBefore - 1]); 67 il.Append (il.Create (OpCodes.Ret)); 68 } else { 69 var i = 0; 70 if (addThisRef) 71 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, 0)); 72 for (int op = 0; op < opCount; op++) { 73 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, op + 1)); 74 } 75 il.InsertBefore (method.Body.Instructions [i++], call); 63 76 } 64 il.InsertBefore (method.Body.Instructions [i++], call);65 77 } 66 78 }
Note:
See TracChangeset
for help on using the changeset viewer.