Page 1 of 1

[CLOSED] Cheat Engine {$CCODE} imports

Posted: Wed Aug 21, 2024 12:23 pm
by Horse4Horse
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: Select all

{$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: Select all

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

Code: Select all

extern __declspec(dllimport) SHORT __stdcall GetKeyState();
It still called win32kbase.
As an example, this is the previous cheat I made for the game "Exanima" x64 version:
[Link]

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?

Re: Cheat Engine {$CCODE} imports

Posted: Wed Aug 21, 2024 5:18 pm
by Horse4Horse
Answer from the Dark Byte himself:
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
But because I never specified memset myself in the code and compiler did it, so I just redefined it to:

Code: Select all

registerSymbol('memset', getAddress('ucrtbase.memset'))