Guest User

Micah

a guest
Feb 13th, 2009
1,483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WiimoteVision
  4. {
  5.     public class Injected : EasyHook.IEntryPoint
  6.     {
  7.         private EasyHook.LocalHook Direct3DCreate9Hook;
  8.         private MyDirect3D9.IDirect3D9 IDirect3D9;
  9.        
  10.         public Injected(EasyHook.RemoteHooking.IContext Context)
  11.         {
  12.            
  13.         }
  14.        
  15.         public unsafe void Run(EasyHook.RemoteHooking.IContext Context)
  16.         {
  17.             // Install the DirectX hook.
  18.             try
  19.             {
  20.                 Direct3DCreate9Hook = EasyHook.LocalHook.Create(
  21.                         EasyHook.LocalHook.GetProcAddress("D3D9.DLL", "Direct3DCreate9"),
  22.                         new Direct3DCreate9Delegate(MyDirect3DCreate9),
  23.                         this);
  24.                
  25.                 Direct3DCreate9Hook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
  26.             }
  27.             catch (Exception Exception)
  28.             {
  29.                 return;
  30.             }
  31.            
  32.             EasyHook.RemoteHooking.WakeUpProcess();
  33.            
  34.             while (true)
  35.             {
  36.                 System.Threading.Thread.Sleep(500);
  37.             }
  38.         }
  39.        
  40.         // This is the wrapping that let's us give Win32 a delegate instead of a function pointer.
  41.         [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Winapi, SetLastError = true)]
  42.         private unsafe delegate Win32.D3D9.IDirect3D9* Direct3DCreate9Delegate(ushort SdkVersion);
  43.        
  44.         // This is our fake version of Direct3DCreate9.  We call the real one but this let's us grab the IDirect3D pointer.
  45.         private static unsafe Win32.D3D9.IDirect3D9* MyDirect3DCreate9(ushort SdkVersion)
  46.         {
  47.             // Since this function is static we need to get a reference to "this".
  48.             Injected This = (Injected)EasyHook.HookRuntimeInfo.Callback;
  49.            
  50.             // Create one of our custom IDirect3D9 objects (which insantiates a real one and passes most calls through to it).
  51.             This.IDirect3D9 = new MyDirect3D9.IDirect3D9(SdkVersion);
  52.            
  53.             // Return the IDirect3D9 pointer.
  54.             return This.IDirect3D9.NativeIDirect3D9;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment