CLEO Help How does 0AA5 work?

CLEO related
Status
Not open for further replies.

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Hi, i was looking for some info about it in google/sanny builder, but there's nothing specific. Is there anyone who knows what it does exactly and how to manually use it? The goal is to make use of it in another language

http://gtag.gtagaming.com/opcode-database/opcode/0AA5/
Description
0AA5 and similar opcodes have variable number of parameters. This opcode has at least 3 parameters, and also additional ones (passed to the called proc), number and values of which depend on the called procedure. Total number of additional parameters must equal to the parameter num_params. Each passed parameter must be numerical (constant or variable fit), but not string.

Parameters:
1 - address of called proc. It may be the address inside the gta_sa.exe or inside a loaded dll.
2 - number of parameters to pass to the proc.
3 - number of parameters that must be removed from the stack after the proc execution. This value has to be within an interval from zero to num_params. The exact value depends on the calling convention of the procedure. Usually, the exe procedures do not clean the stack themselves, so the pop parameter mostly equals to the num_params (all passed parameters are removed from the stack after the proc execution).

Example 0AA5: call_function 0@ num_params 1 pop 1 params 1@
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
From cleo 4.2a source code.

Code:
asm volatile (
			"loop_0AA5:\n"
			"cmp %2,%3\n"
			"je loop_end_0AA5\n"
			"pushl (%2)\n"
			"addl $4,%2\n"
			"jmp loop_0AA5\n"
			"loop_end_0AA5:\n"
			"call *%0\n"
			"addl %1,%%esp"

From what i understand 0AA5 is used for simple calls(stdcall) but with no returns, altough you can manually pop from the stack 0AA7 does that(returns). Alternatively 0AA6/0AA8 are used for class/structs functions(thiscall).

So basically it pushes arguments on stack then calls the function, i'm pretty every language supports this.
I might be wrong, i don't know much asm.

This is how 0AA5 would look in c++
Code:
__asm{
    push arg1
    push arg2
    ...
    call func
}

or

((int(__stdcall *) (int, int)) (func)) (arg1, arg2);

Paging doctor [member=5679]T3K[/member], maybe he can explain better.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
I tried to use the following code trying to translate "getScreenXYFrom3DCoords" cleo snippet which uses "0AA7: call_function 0x70CE30":
Code:
//at the begining
typedef bool (__cdecl *WorldCoords2ScreenCoords_t)(vector<float> * inPoint, vector<float> * outPoint, float * x, float * y, char, char);
WorldCoords2ScreenCoords_t WorldCoords2ScreenCoords = (WorldCoords2ScreenCoords_t)0x70CE30;



//trying to call the function later somewhere else
vector<float> inPoint(3);
inPoint[0] = 400.0;
inPoint[1] = 1300.0;
inPoint[2] = 10.5;
vector<float> outPoint(3);
float x;
float y;
WorldCoords2ScreenCoords(&inPoint, &outPoint, &x, &y, 1, 1);
niggered from:
http://gtadotnet.googlecode.com/svn/trunk/scripthookv2/GTAScriptHook/LegacyCrap.h
http://gtadotnet.googlecode.com/svn/trunk/scripthookv2/GTAScriptHook/LegacyCrap.cpp


The code crashes but works well with WorldCoords2ScreenCoords() commented out. Does anyone have an idea what could be the problem? The original code from the links above used "CVector" instead of "vector<float>", can it be the reason or is there any more or less obvious mistake?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Probably because of vector, idk.

Code:
struct CVector
{
	float x, y, z;
};

typedef bool(__cdecl *WorldCoords2ScreenCoords_t)(CVector*, CVector*, float *x, float *y, char, char);
WorldCoords2ScreenCoords_t WorldCoords2ScreenCoords = (WorldCoords2ScreenCoords_t)0x70CE30;

CVector inPoint = { 400.0f, 1300.0f, 10.5f }, outPoint;
float x, y;

WorldCoords2ScreenCoords(&inPoint, &outPoint, &x, &y, 1, 1);
 
Status
Not open for further replies.
Top