AhkHook: API hooking with autohotkey

Post your working scripts, libraries and tools for AHK v1.1 and older
TheDimensioner
Posts: 3
Joined: 12 Mar 2017, 23:15

Re: AHK Injector: DirectX hooking with autohotkey

21 Mar 2017, 21:43

Hello, sorry for double posting, but I was able to make Resident Evil work and with AHK Injector, which I have to say, works amazingly. I simply updated my codec pack and media player (MPC-HC), and well, opening a video file in the background and setting a resolution of 1280x960 makes the game run at a smooth 30 FPS at every gameplay instance, although it does slowdown with more than two 3D models on the screen at the same time. There's also the inventory issue, which is reeealy slow (like with Resident Evil 2), but since RE1 (US/EU/ASIA) has no hardware mode that allows a windowed mode (besides "novideo", which sucks), I can't test if it can be fixed like with RE2, but that issue is minor. I was able to beat both Chris' and Jill's campaign, and finally got to use the famous machine guns exclusive to the PC version. Overall I can say I had the best experience playing this game on any platform.

AHK Injector enhanced that experience, by the use of a higher resolution, and basically by patching it. Better color, and also framerates, are the best way to play Resident Evil. Only thing missing, would be a way to disable the filter on the 3D models (like in RE2 as well), and a mod to enhance the music, or swap the files with PSX ones. I perceived that the voice files are already of a higher quality than PSX (at least audibly), so they're good. Additionally, video files are... bad XD. 10FPS is not good, but I guess there's also a way to get them from PSX, I just don't know how...

Oh, something I forgot, I don't know if it actually made a difference, but changing the framerate setting also helped maintaining the game smooth. I've set it to 59.94, and although it maintains 30 FPS (20~25 in inventory and menus), it doesn't break cutscenes. The default 40.0 does however, not often though (more often in the infamous Barry/Jill scene in the beginning). I've also put 120 for the mentioned 240p mode in the previous post (because that's what a 31khz monitor need to support it), and it makes the game slightly faster, which also breaks cutscenes. But again, overall, using this fix is better than what I had before, which was never being able to play on PC (aside from emulators). So thank you @Peixoto, for providing us with this amazing software!
Peixoto
Posts: 24
Joined: 18 Aug 2015, 11:20

Re: AHK Injector: DirectX hooking with autohotkey

21 Mar 2017, 22:15

TheDimensioner wrote:Hello, sorry for double posting, but I was able to make Resident Evil work and with AHK Injector, which I have to say, works amazingly. I simply updated my codec pack and media player (MPC-HC), and well, opening a video file in the background and setting a resolution of 1280x960 makes the game run at a smooth 30 FPS at every gameplay instance, although it does slowdown with more than two 3D models on the screen at the same time. There's also the inventory issue, which is reeealy slow (like with Resident Evil 2), but since RE1 (US/EU/ASIA) has no hardware mode that allows a windowed mode (besides "novideo", which sucks), I can't test if it can be fixed like with RE2, but that issue is minor. I was able to beat both Chris' and Jill's campaign, and finally got to use the famous machine guns exclusive to the PC version. Overall I can say I had the best experience playing this game on any platform.

AHK Injector enhanced that experience, by the use of a higher resolution, and basically by patching it. Better color, and also framerates, are the best way to play Resident Evil. Only thing missing, would be a way to disable the filter on the 3D models (like in RE2 as well), and a mod to enhance the music, or swap the files with PSX ones. I perceived that the voice files are already of a higher quality than PSX (at least audibly), so they're good. Additionally, video files are... bad XD. 10FPS is not good, but I guess there's also a way to get them from PSX, I just don't know how...

Oh, something I forgot, I don't know if it actually made a difference, but changing the framerate setting also helped maintaining the game smooth. I've set it to 59.94, and although it maintains 30 FPS (20~25 in inventory and menus), it doesn't break cutscenes. The default 40.0 does however, not often though (more often in the infamous Barry/Jill scene in the beginning). I've also put 120 for the mentioned 240p mode in the previous post (because that's what a 31khz monitor need to support it), and it makes the game slightly faster, which also breaks cutscenes. But again, overall, using this fix is better than what I had before, which was never being able to play on PC (aside from emulators). So thank you @Peixoto, for providing us with this amazing software!
About your speed issues, i can only recommend you to uninstall all previous tricks. My patch should be able to solve all speed problems, including the slow inventory in RE 2. It's quite surprising to me that the inventory in RE 1 is slow. The slow inventory in RE2 has a very simple reason: the game locks the backbuffer to render the health Display, and today's cards don't like this. That doesn't happens in RE 1, which renders everything using Direct3D.

You could also try to set the frame time to a very slow value n RE 1 and leave the game speed at the default (1) for RE 2 and then use
this: https://sourceforge.net/projects/dxwnd/ to limit the frame rate

A sound mod should be possible. I will release a program update soon, there will be a hint in the new documentation on how to request new mods and new features
TheDimensioner
Posts: 3
Joined: 12 Mar 2017, 23:15

Re: AHK Injector: DirectX hooking with autohotkey

21 Mar 2017, 23:15

Thank you for replying, Peixoto. I have to say that I'm not using any other "trick" (ddraw, wrapper, configurator, CPU clock limiter, or whatever else), only AHK Injector and a clean disc rip. But as I mentioned on the previous post, and on this one, it only becomes playable with a media player paused in the background. I've put my system specs in that post (page 2), and you can see that my GPU is old, although still way ahead of what this game needed.

I've tried AHK Injector with the 1.0c patch (as recommended) the first time, and I still had issues. Without the patch, at 1280x960 (my desktop's resolution is 1440x1080, custom made by me by the way, but the GPU driver "don't want other programs to know", since it rarely shows up in other games or emulators resolution list), close to 60 FPS in RE.bat, and the media player in the background, is the only way it works "ok". I forgot to mention that door animations are also slow (in RE2 as well, but that is only still fixed with windowed).

It was always weird to make any Resident Evil game run on this computer, and I have to say it got even weirder with Windows 8.1. Since I refuse to upgrade to 10, or go back to 7 for only some games, I'm just glad I was able to finish my favorite classic franchise with their best versions. I will look forward to the new AHK Injector version.
TheDrifter363
Posts: 2
Joined: 30 Mar 2017, 15:02

Re: AhkHook: API hooking with autohotkey

30 Mar 2017, 15:13

Hi Peixoto,

I have a question about your game patches. So I was trying it out with Resident Evil 2 and while it does work great, I noticed that load game issue you were talking about. Is there no way to fix that currently? It does get annoying deciding between the fmvs or the ability to load your game. Especially because I transferred the sourcnext fmvs to the platinum version of the game. Those are some high quality fmvs. I would hate to have to not use them.

Also, on the topic of Resident Evil 3. You mentioned using that one mod, the restoration mod, with your patch. However, upon installing that mod, I didn't need to do anything extra. It already had xinput support, 32 bit colorspace, etc. What does your patch do extra that the mod hasn't already done? Also how would that mod be installed along with your patch? You mentioned creating a mod folder under Documents, but that mod comes with a setup.exe. Would we have to extract the mod files, if that's even possible? Oh, almost forgot! Your patch also enables windows 98 compatibility with this game, but I didn't see any need for it, as the mod doesn't seem to required compatibility mode at all. I know some of these old games required administrator access because they store their settings in the registry, at least that's how I make sense of it. But Resident Evil 3, doesn't seem to store anything in the registry, besides its name and a version 1.0 folder. It's really weird. Both Resident Evil 2 and Dino Crisis appear to store their settings and maybe unlockables in the registry.

For Dino Crisis 2, how would one go about creating a patch for that game. Mainly I wanted to disable the built in controller detection as it was detecting my xinput controller and not giving me any way to rebind controls. Also the widescreen resolution stretches out the aspect ratio which is rather annoying.

I also tried your patch out with Dino Crisis. Currently I can't think of anything I want to let you know about that besides that it works great. Oh, almost forgot too! I noticed you didn't have any compatibility options with this game. Now while it does work great, would it have any effect on the game being able to update values in the registry, since it's not running as administrator? Wait....disregard. I just noticed upon launching your game, I grant administrator access to it and any of its sub processes. Lol.

If it helps, I'm running Windows 10 64 bit.

Any help would be appreciated! Thanks!
Peixoto
Posts: 24
Joined: 18 Aug 2015, 11:20

Re: AhkHook: API hooking with autohotkey

30 Mar 2017, 21:38

TheDrifter363 wrote:Hi Peixoto,

I have a question about your game patches...
Peixoto in the 1st post wrote:If you came looking for the game patches have created with the program, go here:
http://www.vogons.org/viewtopic.php?f=24&t=53121

OK ? I will e glad to answer
Last edited by Peixoto on 01 Apr 2017, 22:29, edited 1 time in total.
TheDrifter363
Posts: 2
Joined: 30 Mar 2017, 15:02

Re: AhkHook: API hooking with autohotkey

30 Mar 2017, 23:01

Understood Peixoto. Thanks. I'll post on the other board.
whynotregister
Posts: 147
Joined: 05 Nov 2016, 22:42

Re: AhkHook: API hooking with autohotkey

01 Sep 2017, 15:48

How do I detect when a process LoadLibraryA api is used?

Can I see the example code in this regard?
Peixoto
Posts: 24
Joined: 18 Aug 2015, 11:20

Re: AhkHook: API hooking with autohotkey

05 Sep 2017, 20:10

whynotregister wrote:How do I detect when a process LoadLibraryA api is used?

Can I see the example code in this regard?
something like this(untested):

Code: Select all

global LoadLibraryA_hook := new Hook("LoadLibraryA", "Kernel32.dll", "LoadLibraryA")

LoadLibraryA(dll_name)
{
	dll := strget(dll_name+0, "CP0")
	msgbox % "Loading :" dll
        return dllcall(LoadLibraryA_hook.Trampoline, uint, dll_name)
}
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: AhkHook: API hooking with autohotkey

01 Jul 2018, 07:31

Peixoto wrote:If you came looking for the game patches have created with the program, go here:
http://www.vogons.org/viewtopic.php?f=24&t=53121

If you are interested in writing API hooks with autohotkey, download AhkHook from here:
https://github.com/Daniel-Lobo/AhkHook and ask questions in this topic

AhkHook sample:

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%  
#SingleInstance Ignore

if ! A_isdll
{
	target=%1%
	if not target 
	{
		msgbox, 16, , Drag and drop the taget application over the script !
		ExitApp
	}
	
	run ..\ahkhook.exe -t "%target%" -s "%A_scriptfullpath%" -a """"commandline argument with quotes"""" -e "settings test", , ,ProcessID	
	return
}


envget, my_settings, remote_settings
msgbox % "Testing the ""-e"" command, the string passed was: """ my_settings """"
global msgbox_hook := new Hook("MessageBoxW", "User32.dll", "MessageBoxW")

MessageBoxW(p1, p2, p3, p4)
{
	r := dllcall(msgbox_hook.Trampoline, uint, p1, uint, p2, str, "This Messagebox was hooked", uint, p4)	
	/* Unhook a function just by deleting the hook object. You will note that in the supplyed MesageBox test propgram, 
	 * only the first message box is hooked
	 */
	msgbox_hook := ""
	return r
}

Is there an example of this script where it is used to get information from character Data structures in games, like Call of Duty or Fortnite?
I guess what I'm asking is a rough example of how the message box would show character ammo, coordinates, etc. Or is this script intended for that?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: AhkHook: API hooking with autohotkey

04 Feb 2019, 19:27

Peixoto, I have written code for getting address of directx EndScene method.
How can I inject this code and make hook in running application with Your library?

Code: Select all

d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(1, D3DPRESENT_PARAMETERS, 0)   ; BackBufferWidth
NumPut(1, D3DPRESENT_PARAMETERS, 4)   ; BackBufferHeight
NumPut(1, D3DPRESENT_PARAMETERS, 24)   ; D3DSWAPEFFECT_DISCARD
NumPut(1, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)   ; Windowed
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_HARDWARE_VERTEXPROCESSING := 0x00000040, &D3DPRESENT_PARAMETERS, device)
EndScene := NumGet(NumGet(device+0)+42*A_PtrSize) 
Release(device)
Release(d3d)

; hook code


Direct3DCreate9(SDKVersion)
{
   if !DllCall("GetModuleHandle","str","d3d9", "PTR")
   {
      MsgBox, 16, Error, d3d9 failed.
      ExitApp
   }
   return DllCall("d3d9\Direct3DCreate9", "uint", SDKVersion)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),"ptr",this,"uint",Adapter,"uint",DeviceType,"ptr",hFocusWindow,"uint",BehaviorFlags,"ptr",pPresentationParameters,"ptr*",ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

Release(this)
{
   return DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), "ptr", this)
}

_Error(val)
{
   msgbox % val
   ExitApp
}
gameraider
Posts: 1
Joined: 01 Jun 2019, 23:13

Re: AhkHook: API hooking with autohotkey

01 Jun 2019, 23:22

hi there,could u plz send ur newest Peixoto's patches for a few old games to my email:[email protected] ? ,for some reason, i cannot download it from your shared onedrive,thanks.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AhkHook: API hooking with autohotkey

07 Jun 2021, 18:38

malcev wrote:
04 Feb 2019, 19:27
Peixoto, I have written code for getting address of directx EndScene method.
How can I inject this code and make hook in running application with Your library?
edit the constructor to not call GetProcAddress when an integer(address) is passed in?
also, @Peixoto dll source would be kinda nice
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: AhkHook: API hooking with autohotkey

08 Jun 2021, 01:36

I asked author about it and he answered:
Actually my API doesn't includes any means to hook com methods, i will include it soon.
Finally I used MinHook library:
https://www.autohotkey.com/boards/viewtopic.php?p=294758#p294758
BTW
FW1FontWrapper.dll does not work properly with unity engine games running in full-screen mode.
I was wrong about it, because tested unity engine games used fake full-screen mode.
I detected it with creating window with undocumented CreateWindowInBand and ZBID_UIACCESS and my window was on top of full-screen unity engine game.
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75695
Also I have searched how to call SetWindowBand without injecting and hooking, but it seems that nobody knows it.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: charlie89, gwarble, pekoe, Spikea and 137 guests