Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Cheat Engine {$CCODE} imports

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Horse4Horse
Newbie cheater
Reputation: 1

Joined: 17 May 2015
Posts: 22

PostPosted: Wed Aug 21, 2024 6:16 am    Post subject: Cheat Engine {$CCODE} imports Reply with quote

I'm making a simple C section for matrix multiplications for object rotation in 3d. It works in lua as a PoC.
The problem is, what I'm already encountered every time I worked with C code sections in CE - for some reason CE prefers to use "ntoskrnl' over "ucrtbase" for functions like "memset", "memove", etc.
I already had to deal with it in the pervious cheat in this way:
Code:
{$c}
#define NO_OLDNAMES
#include <windows.h>

typedef HWND(WINAPI *GETFOREGROUNDWINDOW)(void);
GETFOREGROUNDWINDOW pfnGetForegroundWindow;
{$asm}

{$ccode}
HMODULE hModuleUser32 = LoadLibrary("User32.dll");
pfnGetForegroundWindow = (GETFOREGROUNDWINDOW)GetProcAddress(hModuleUser32, "GetForegroundWindow");
{$asm}

So it won't compile to call "win32kbase.GetForegroundWindow".

I also tried:
Code:
extern __declspec(dllimport) HWND __stdcall GetForegroundWindow();

And it worked, but when I tried the same thing with:
Code:
extern __declspec(dllimport) SHORT __stdcall GetKeyState();

It still called win32kbase.

And now, when I'm dealing with matrixes, compiler automatically uses memset's and memmove's and I can't control where it gets them from.
So the main question is - how to deal with imports in a proper way?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 464

Joined: 09 May 2003
Posts: 25485
Location: The netherlands

PostPosted: Wed Aug 21, 2024 10:00 am    Post subject: Reply with quote

registersymbol the correct symbol with a different name first (different script, or lua block)

e.g registerSymbol('ucrtbase_memset', getAddress('ucrtbase.memset'))

and then in your ccode you can call ucrtbase_memset

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Horse4Horse
Newbie cheater
Reputation: 1

Joined: 17 May 2015
Posts: 22

PostPosted: Wed Aug 21, 2024 11:14 am    Post subject: Reply with quote

Dark Byte wrote:
registersymbol the correct symbol with a different name first (different script, or lua block)

e.g registerSymbol('ucrtbase_memset', getAddress('ucrtbase.memset'))

and then in your ccode you can call ucrtbase_memset


Many thanks, Dark Byte, you are genius. It is such a simple solution but it never came to me.

Eeyup, I'm already using script on a higher call level to start a C code injection. So I ended up redefining to:
Code:
registerSymbol('memset', getAddress('ucrtbase.memset'))

Because I never specified memset myself in the code, compiler did it. And now it points to the right function.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites