Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hijack.hijack(typeof(Game1).GetMethod("setGraphicsForSeason", BindingFlags.Static | BindingFlags.Public),
- typeof(NewGame1).GetMethod("setGraphicsForSeason", BindingFlags.Static | BindingFlags.Public));
- public static void hijack( MethodInfo target, MethodInfo replaceWith )
- {
- // I had some verification stuff here, but it handle everything correctly
- Log.debug("Hijacking method \"" + target + "\", replacing with \"" + replaceWith + "\".");
- RuntimeHelpers.PrepareMethod(target.MethodHandle);
- RuntimeHelpers.PrepareMethod(replaceWith.MethodHandle);
- if (target.IsVirtual)
- {/*
- // http://stackoverflow.com/a/38783635
- unsafe
- {
- UI
- }*/
- }
- //else
- {
- // http://stackoverflow.com/a/36415711
- unsafe
- {
- int insOffset = 1;
- if (IntPtr.Size == 4)
- {
- insOffset = 2;
- }
- Log.trace("Offset: " + insOffset);
- int* ttar = (int*)target.MethodHandle.Value.ToPointer() + insOffset;
- int* rtar = (int*)replaceWith.MethodHandle.Value.ToPointer() + insOffset;
- if (Debugger.IsAttached)
- {
- Log.trace("Debugger is attached.");
- byte* tinsn = (byte*)(*ttar);
- byte* rinsn = (byte*)(*rtar);
- int* tsrc = (int*)(tinsn + 1);
- int* rsrc = (int*)(rinsn + 1);
- Log.trace("Data (1): " + new IntPtr(ttar) + "=" + (ttar == null ? 0 : (*ttar)) + " " + new IntPtr(rtar) + "=" + (rtar == null ? 0 : (*rtar)));
- Log.trace("Data (2): " + new IntPtr(tinsn) + "=" + (tinsn == null ? 0 : (*tinsn)) + " " + new IntPtr(rinsn) + "=" + (rinsn == null ? 0 : (*rinsn)));
- Log.trace("Data (3): " + new IntPtr(tsrc) + "=" + (tinsn == null ? 1 : (*tsrc)) + " " + new IntPtr(rsrc) + "=" + (rinsn == null ? 1 : (*rsrc)));
- (*tsrc) = (((int)rinsn + 5) + (*rsrc)) - ((int)tinsn + 5);
- }
- else
- {
- Log.trace("Debugger is not attached.");
- Log.trace("Data: " + new IntPtr(ttar) + "=" + (*ttar) + " " + new IntPtr(rtar) + "=" + (*rtar));
- (*ttar) = (*rtar);
- }
- }
- }
- Log.trace("Done");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement