Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
changing mouse cursor #464785
03/12/17 15:01
03/12/17 15:01
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Does one of you guys know how to change the cursor image using the windows api?

Note that I'm not talking about 'mouse_map' (which just makes the windows cursor invisible and draws another cursor inside the engine window).

I'd like to change the windows cursor directly to get rid of these 1-2 frames (visual) lag.


POTATO-MAN saves the day! - Random
Re: changing mouse cursor [Re: Kartoffel] #464787
03/12/17 17:49
03/12/17 17:49
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Shouldn't mouse_sync use hardware support and get rid of exactly that lage?

http://www.conitec.net/beta/amouse_sync.htm


Always learn from history, to be sure you make the same mistakes again...
Re: changing mouse cursor [Re: Uhrwerk] #464788
03/12/17 18:46
03/12/17 18:46
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
ShowCursor to show/hide the standard windows cursor
SetCursor to set the cursor
LoadCursor to load a windows standard cursor by name
LoadImage to load a custom image for the cursor

Re: changing mouse cursor [Re: Ch40zzC0d3r] #464789
03/12/17 19:56
03/12/17 19:56
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@Uhrwerk: I tried it before but it doesn't really change anything. Seems like it's output related.

@Ch40zzC0d3r: I just gave it a shot and it's working (kind of). Thanks for the info.. I actually expected it to be trickier than that grin

The only annoying thing is that I have to set the cursor each frame again. I don't think it's supposed to be like that, probably a contradiction with acknex resetting the mouse pointer.
Also using a custom cursor file for some reason doesn't work. Not sure if the file isn't being found or if something else is the problem, but I guess I can figure that out myself.

but thanks again guys laugh


POTATO-MAN saves the day! - Random
Re: changing mouse cursor [Re: Kartoffel] #464790
03/12/17 20:00
03/12/17 20:00
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Check the handle return value and GetLastError, fixing non working windows apis is usually pretty easy and straight forward (atleast in the usermode world and non native apis)

To fix the loop to set the cursor you should just hook the SetCursor API of acknex itself and ignore everything which was not set by you.
You can use a simple detours but the easiest hooking technique would be an IAT hook imo.

Last edited by Ch40zzC0d3r; 03/12/17 20:02.
Re: changing mouse cursor [Re: Ch40zzC0d3r] #464791
03/12/17 20:17
03/12/17 20:17
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Oh wow. I should probably try LoadCursorFromFile instead of LoadCursor which loads it from a resource, duh
problem solved

regarding win-api hooks I'm not sure how that stuff exactly works but for now I'm okay with setting it inside the main while loop


POTATO-MAN saves the day! - Random
Re: changing mouse cursor [Re: Kartoffel] #464792
03/12/17 21:37
03/12/17 21:37
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
edit: well shit. I guess there's no way around using a hook... the cursor sometimes resets after I change it and it begins to flicker back and forth or do other things :S


POTATO-MAN saves the day! - Random
Re: changing mouse cursor [Re: Kartoffel] #464800
03/13/17 20:00
03/13/17 20:00
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
If you need help with it just ask, its pretty easy if you know some assembly

Re: changing mouse cursor [Re: Ch40zzC0d3r] #464801
03/13/17 21:31
03/13/17 21:31
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
So I google'd a bit about windows api hooks and I think I understand the basic principle (at least to some extent). Hooking window messages like key presses seem fairly straight forward to me, but I don't exactly know how hooking specific functions should work.

...soo, yeah, I'd appreciate a little help in case you have time


POTATO-MAN saves the day! - Random
Re: changing mouse cursor [Re: Kartoffel] #464829
03/14/17 09:46
03/14/17 09:46
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
What you found is probably SetWindowsHookEx which ha nothing to do with the hook we need at all. It can set hooks on the WindowMessage handler of a process.

What we need is called a detours (if we use bytepatches to create a hook)
I guess the detours is easier for beginners and since the windows apis are hotpatchable this will work on any OS version too, no need for the IAT hook for now.
So how does it work?

There is a function prologue for windows apis which looks like this:
Code:
74EEEEDA k>  8BFF                             MOV EDI,EDI
74EEEEDC     55                               PUSH EBP
74EEEEDD     8BEC                             MOV EBP,ESP



As you can see this are exactly 5 bytes thanks to the mov edi, edi laugh

So we will place a jmp instruction there (a jmp is also 5 bytes) and copy the bytes to our trampoline which will first execute those 5 overwritten bytes and ten jumps back past the jump (first 5 bytes) to execute the rest of the bytes.

There are alot of hooking libs out there, but you dont need any special stuff. If you still feel like you can use MS Detours for example (x86 version is free), or PolyHook.
Heres a very simple hooking function which works fine for your needs:

Code:
void *CreateDetour(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len + 5);
	DWORD dwBack;

	VirtualProtect(jmp, len+5, PAGE_EXECUTE_READWRITE, &dwBack);
	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	Memcpy(jmp, src, len); 

	jmp += len;
	jmp[0] = 0xE9;
	*(DWORD*)(jmp + 1) = (DWORD)src + len - (DWORD)jmp - 5;

	src[0] = 0xE9;
	*(DWORD*)(src + 1) = (DWORD)dst - (DWORD)src - 5;

	for(int i = 5; i < len; i++)
		src[i] = 0x90;

	VirtualProtect(src, len, dwBack, &dwBack);

	return(jmp - len);
}



And its usage:
Code:
typedef int (WINAPI *tMessageBoxA)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
tMessageBoxA oMessageBoxA;

int WINAPI hkMessageBoxA(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
	return oMessageBoxA(hWnd, lpText, "Hooked :)", uType);
}

...

oMessageBoxA = (tMessageBoxA)CreateDetour((BYTE*)GetProcAddress(GetModuleHandle("user32.dll"), "MessageBoxA")), (BYTE*)hkMessageBoxA, 5);

MessageBoxA(0, "Test", "Test", 0);



The size is always 5 for windows apis because of the mov edi, edi (hotpatchable image)

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1