Refactor d3d9 hook module - [merged] #104

Closed
opened 2019-10-06 22:46:21 +03:00 by icex2 · 6 comments
icex2 commented 2019-10-06 22:46:21 +03:00 (Migrated from github.com)

Merges refactor-iidx-d3d9-module -> master

Summary

This PR refactors the d3d9 hook module to enhance maintainability and flexibility (in the future).

Description

It introduces a new base hook/d3d9 module which takes care of infrastructure related setup (IAT patching, handling of d3d9 COM objects) and establishes an IRP handler abstraction layer. The iidxhook-util/d3d9 module implements a IRP handler to dispatch the hooked d3d9 function calls as operations. All previously available features were ported.
Furthermore, up-/downscaling was refactored to work with all IIDX versions now.

In favor of this, the d3d8 module was removed to improve maintainability. With the d3d8to9 wrapper lib, there is no actual value for this anymore. Furthermore, the d3d8to9 lib also solves various odd issues when running d3d8 on newer Windows versions.

Related Issue

Fixes #25

How Has This Been Tested?

  • Add test/d3d9hook to test the hook/d3d9 base module with a basic d3d9 setup and rendering loop
  • Tested with IIDX 9, 11 and 25
_Merges refactor-iidx-d3d9-module -> master_ ## Summary This PR refactors the d3d9 hook module to enhance maintainability and flexibility (in the future). ## Description It introduces a new base hook/d3d9 module which takes care of infrastructure related setup (IAT patching, handling of d3d9 COM objects) and establishes an IRP handler abstraction layer. The iidxhook-util/d3d9 module implements a IRP handler to dispatch the hooked d3d9 function calls as operations. All previously available features were ported. Furthermore, up-/downscaling was refactored to work with all IIDX versions now. In favor of this, the d3d8 module was removed to improve maintainability. With the d3d8to9 wrapper lib, there is no actual value for this anymore. Furthermore, the d3d8to9 lib also solves various odd issues when running d3d8 on newer Windows versions. ## Related Issue Fixes #25 ## How Has This Been Tested? * Add test/d3d9hook to test the hook/d3d9 base module with a basic d3d9 setup and rendering loop * Tested with IIDX 9, 11 and 25
icex2 commented 2019-10-07 06:09:00 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 7, 2019, 05:09

Commented on src/main/iidxhook8/dllmain.c line 73

Moving this here instead of being in DllMain may cause issues.

iirc. the hooks were all initialized there for a reason.

In GitLab by @xyen on Oct 7, 2019, 05:09 Commented on [src/main/iidxhook8/dllmain.c line 73](https://github.com/djhackersdev/bemanitools/compare/3436838b8517f042e9874b17c876061e75101873..b83033587fb470a0b7899a7b307b259c433f8e34#diff-2652fef86a3a811b7b9013de2364403dR73) Moving this here instead of being in DllMain may cause issues. iirc. the hooks were all initialized there for a reason.
icex2 commented 2019-10-07 19:01:53 +03:00 (Migrated from github.com)

I am not entirely sure but to the best of my recollection, this was depending on libraries and functions you were IAT hooking. Some of them might already get executed before the main hook function which does all the config reading and configuring the hooks. This could mean that you missed detouring a call that might have been important...or not.

For the ezusb hooks, we must delay the iohooking to allow implementations of iidxio, e.g. iidxio-ezusb and iidxio-ezusb2, to setup real devices without getting in conflict with the hooks that want to detour these calls:

    /* Set up IO emulation hooks _after_ IO API setup to allow
       API implementations with real IO devices */
    iohook_init(iidxhook_handlers, lengthof(iidxhook_handlers));

Back to the d3d9 hooking: The iohook implementations execute the hook_d3d9_init still before any gfx context is created. Either when OpenProcess for older IIDX games is called which happens very early after main is called or in my_dll_entry_init which is still before the entry point of the dlls is called on newer versions.

I am not entirely sure but to the best of my recollection, this was depending on libraries and functions you were IAT hooking. Some of them might already get executed before the main hook function which does all the config reading and configuring the hooks. This could mean that you missed detouring a call that might have been important...or not. For the ezusb hooks, we must delay the iohooking to allow implementations of iidxio, e.g. iidxio-ezusb and iidxio-ezusb2, to setup real devices without getting in conflict with the hooks that want to detour these calls: ``` /* Set up IO emulation hooks _after_ IO API setup to allow API implementations with real IO devices */ iohook_init(iidxhook_handlers, lengthof(iidxhook_handlers)); ``` Back to the d3d9 hooking: The iohook implementations execute the hook_d3d9_init still before any gfx context is created. Either when OpenProcess for older IIDX games is called which happens very early after main is called or in my_dll_entry_init which is still before the entry point of the dlls is called on newer versions.
icex2 commented 2019-10-07 19:03:41 +03:00 (Migrated from github.com)

resolved all threads

resolved all threads
icex2 commented 2019-10-07 19:04:15 +03:00 (Migrated from github.com)

@willxinc approved of this via PM.

@willxinc approved of this via PM.
icex2 commented 2019-10-07 19:04:30 +03:00 (Migrated from github.com)

added 23 commits

  • bbdb6890...3436838b - 5 commits from branch master
  • 60050d0d - hook: Add d3d9 hook module
  • d169ee84 - test/hook: Add tests for d3d9 hook module
  • c5d39d82 - iidxhook-util: Major refactoring of d3d9 module
  • 77906205 - test/check: Add check_failed func
  • 3e603002 - iidxhook-util: Adapt enum name of upscaling filter names
  • e0d7596f - iidxhook1: Refactor to use new d3d9 module
  • f201bff9 - iidxhook2: Refactor to use new d3d9 module
  • 53d61dcb - iidxhook3: Refactor to use new d3d9 module
  • 5183547b - iidxhook4: Refactor to use new d3d9 module
  • a626e9e6 - iidxhook5: Refactor to use new d3d9 module
  • b1871a47 - iidxhook6: Refactor to use new d3d9 module
  • f4c0810e - iidxhook7: Refactor to use new d3d9 module
  • d9cc873e - iidxhook8: Refactor to use new d3d9 module
  • a10132f6 - dist/iidx: Fix default values for override window size
  • 8c998f64 - Add inject.exe to test package
  • d64f8b2d - iidxhook-util: Remove d3d8 module
  • ff6bad24 - iidxhook1/2 config: Remove deprecated use_d3d9_hooks param
  • b8303358 - doc/iidxhook: Update doc for iidxhook1/2

Compare with previous version

added 23 commits <ul><li>bbdb6890...3436838b - 5 commits from branch <code>master</code></li><li>60050d0d - hook: Add d3d9 hook module</li><li>d169ee84 - test/hook: Add tests for d3d9 hook module</li><li>c5d39d82 - iidxhook-util: Major refactoring of d3d9 module</li><li>77906205 - test/check: Add check_failed func</li><li>3e603002 - iidxhook-util: Adapt enum name of upscaling filter names</li><li>e0d7596f - iidxhook1: Refactor to use new d3d9 module</li><li>f201bff9 - iidxhook2: Refactor to use new d3d9 module</li><li>53d61dcb - iidxhook3: Refactor to use new d3d9 module</li><li>5183547b - iidxhook4: Refactor to use new d3d9 module</li><li>a626e9e6 - iidxhook5: Refactor to use new d3d9 module</li><li>b1871a47 - iidxhook6: Refactor to use new d3d9 module</li><li>f4c0810e - iidxhook7: Refactor to use new d3d9 module</li><li>d9cc873e - iidxhook8: Refactor to use new d3d9 module</li><li>a10132f6 - dist/iidx: Fix default values for override window size</li><li>8c998f64 - Add inject.exe to test package</li><li>d64f8b2d - iidxhook-util: Remove d3d8 module</li><li>ff6bad24 - iidxhook1/2 config: Remove deprecated use_d3d9_hooks param</li><li>b8303358 - doc/iidxhook: Update doc for iidxhook1/2</li></ul> [Compare with previous version](/djhackers/bemanitools/merge_requests/3/diffs?diff_id=1045&start_sha=bbdb68909a6ab79a0cb3603090d990307a34de56)
icex2 commented 2019-10-07 19:07:18 +03:00 (Migrated from github.com)

merged

merged
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/djhackersdev_bemanitools#104