Reloaded-Project / Reloaded.Hooks

Advanced native function hooks for x86, x64. Welcome to the next level!
GNU Lesser General Public License v3.0
213 stars 33 forks source link

Can the following be achieved by Reloaded.Hooks? #17

Closed aybe closed 1 year ago

aybe commented 1 year ago

Here's some context:

I'd like to see if I can write an OpenGL renderer for Destruction Derby S3 ViRGE version.

The game is as follows:

What I'd like to achieve:

Hook onto each exports of both AYAPI.DLL and S3DTKW.DLL so that:

In short, some sort of instrumentation.

In this example, I can see how calls are hooked, the thing I haven't figured out is, how is the call forwarded back to the originally hooked method?

Any clues are welcome, thank you!

Sewer56 commented 1 year ago

Invoke IHook.OriginalFunction as per example in wiki.

Misc Note: Since Graphics APIs are high frequency, consider using Function Pointers for your hooks to reduce overhead. This should reduce transition overhead from native to managed to around ~36 x86 instructions (native to managed) transition into your hook.

Misc Note 2: If absolute performance is a must, the best option is writing a shim in native code for the native graphics API DLLs (like d3d8to9, dxvk do etc,).

aybe commented 1 year ago

Thank you for the tips, they'll come in handy at some point!

I have a small problem, I cannot get the Just-In-Time Debugger window to show up.

Things appear to be working in the console:

[Reloaded] Create Loader | Time: 114ms
[Reloaded] Loaded: reloaded.sharedlib.hooks in 21ms
[Reloaded] Current Process Location: C:\DERBYS3\DD.EXE
[Reloaded] Loaded: DestructionDerbyS3ViRGE in 106ms
[Reloaded] Loading Mods (Total) | Time: 133ms
[Reloaded] Setting Up Hooks (Async) | Time: 253ms
[Reloaded] Total Loader Initialization Time: 422ms

I've reset Visual Studio settings to default, nothing.

Then went to Options, Tools, Debugging, Just-In-Time, found that:.

devenv_z3gRnCRhMS

Restarted as administrator so that I can enable it for everything:

devenv_iBooho3hN6

But still nothing, the JIT Debugger Wizard doesn't want to show up.

Any ideas?

Thank you 😀

Sewer56 commented 1 year ago

Pretty strange and definitively a first I've seen, usually this works out of the box with no configuration required.

I'd usually refer to this MSDN page for guidance regarding this stuff.

You can try setting the defaults I suppose: in

Default value of Debugger is "C:\Windows\system32\vsjitdebugger.exe" -p %ld -e %ld -j 0x%p. Might work if you manually restore it, not sure as I've never ran into this personally before.

aybe commented 1 year ago

I repaired VS, it appeared once for whatever unit tests on some project, I then tried on the project but nothing. 🤬 Been getting all sort of funny stuff lately, e.g. __debugbreak on F12 on a game I'm working on while there's no such code. I think I'm off for a good old reinstallation, hopefully I'll be able to get started hooking by this weekend. Anyway, thanks for your help! 😀