Example #1
0
 protected void SetWindow(IntPtr hwnd)
 {
     Hwnd = hwnd;
     // Hook WndProc
     old_wndproc       = NativeAPI.GetWindowLong(Hwnd, NativeAPI.GWL_WNDPROC);
     wnd_proc_delegate = new NativeAPI.WndProcDelegate(WndProcDetour);
     NativeAPI.SetWindowLong(Hwnd, NativeAPI.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(wnd_proc_delegate));
 }
Example #2
0
        int D3D9CreateDeviceDetour(IntPtr instance, uint adapter, uint deviceType, IntPtr focusWindow, uint behaviorFlags, ref NativeAPI.PresentParameters presentationParameters, out IntPtr returnedDeviceInterface)
        {
            // Invoke original create device function and retrieve the created device
            var result = Direct3D9CreateDevice(instance, adapter, deviceType, focusWindow, behaviorFlags, ref presentationParameters, out returnedDeviceInterface);
            Direct3DDevice9 = returnedDeviceInterface;
            Hwnd = focusWindow;
            if (hook_end_scene == null) {
                // Hook WndProc
                old_wndproc = NativeAPI.GetWindowLong(focusWindow, NativeAPI.GWL_WNDPROC);
                wnd_proc_delegate = new NativeAPI.WndProcDelegate(WndProcDetour);
                NativeAPI.SetWindowLong(focusWindow, NativeAPI.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(wnd_proc_delegate));

                // Hook EndScene
                var end_scene_pointer = Misc.GetVTableFunction(Direct3DDevice9, NativeAPI.EndSceneOffset);
                EndScene = Misc.GetDelegate<NativeAPI.Direct3D9EndScene>(end_scene_pointer);
                hook_end_scene = LocalHook.Create(end_scene_pointer, new NativeAPI.Direct3D9EndScene(EndSceneCallback), this);
                hook_end_scene.ThreadACL.SetExclusiveACL(new Int32[] { });
            }

            if (hook_reset == null) {
                // Hook Reset
                var reset_pointer = Misc.GetVTableFunction(Direct3DDevice9, NativeAPI.ResetOffset);
                Reset = Misc.GetDelegate<NativeAPI.Direct3D9ResetDelegate>(reset_pointer);
                hook_reset = LocalHook.Create(reset_pointer, new NativeAPI.Direct3D9ResetDelegate(D3D9ResetDetour), this);
                hook_reset.ThreadACL.SetExclusiveACL(new Int32[] { });
            }

            try {
                if (OnCreateDevice != null)
                    OnCreateDevice();
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
            return result;
        }