Skip to content

Instantly share code, notes, and snippets.

@indirivacua
Created February 17, 2019 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indirivacua/c50b58fd2c9de5174419cfca9fc33d26 to your computer and use it in GitHub Desktop.
Save indirivacua/c50b58fd2c9de5174419cfca9fc33d26 to your computer and use it in GitHub Desktop.
CLEO for Open/Close Car Window in GTA SA
{
https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CAutomobile.h
https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/rw/rwcore.h -> RwFrame & RwMatrix (RwMatrixTag)
https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CEntity.h
}
{$CLEO}
0000:
thread 'WINDOW'
const
ACTOR_CAR = 0@
PREV_ACTOR_CAR = 1@
CAR_STRUCT = 2@
RPCLUMP = 3@
RWFRAME_WIN_DOOR_LF_DUMMY = 4@
RWFRAME_DOOR_LF_DUMMY = 5@
X = 6@
Y = 7@
Z = 8@
MAX_Z = 9@
MIN_Z = 10@
isPlayerHasEnteredACar = 30@
isFirstTimeEnteringThatCar = 31@
_ZN15CClumpModelInfo16GetFrameFromNameEP7RpClumpPc = 0x004C5400 //RwFrame *__cdecl CClumpModelInfo__GetFrameFromName(RpClump *clump, char *name)
_memcpy_0 = 0x008266F0 //void *__cdecl memcpy_0(void *, const void *, size_t)
end
var
ACTOR_CAR : Int
PREV_ACTOR_CAR : Int
Z : Float
MAX_Z : Float
MIN_Z : Float
end
isPlayerHasEnteredACar = false
while true
wait 0
if or
Actor.Driving($PLAYER_ACTOR)
isPlayerHasEnteredACar == true
then
if Actor.Driving($PLAYER_ACTOR)
then
isPlayerHasEnteredACar = true
ACTOR_CAR = Actor.CurrentCar($PLAYER_ACTOR) //If player changes car, the var ACTOR_CAR must get the new car reference
if ACTOR_CAR <> PREV_ACTOR_CAR
then
isFirstTimeEnteringThatCar = true
end
PREV_ACTOR_CAR = ACTOR_CAR
end
0A97: CAR_STRUCT = car ACTOR_CAR struct //CAutomobile
CAR_STRUCT += 0x18
0A8D: RPCLUMP = read_memory CAR_STRUCT size 4 virtual_protect 0 /*CAutomobile.vehicle<CVehicle>.physical<CPhysical>.entity<CEntity>.object<ClumpAtomicUnion> -> union {
struct RwObject *m_pRwObject;
struct RpClump *m_pRwClump;
struct RpAtomic *m_pRwAtomic;
}*/
0AA7: call_function_return _ZN15CClumpModelInfo16GetFrameFromNameEP7RpClumpPc num_params 2 pop 2 _name "WIN_DOOR_LF_DUMMY" _clump RPCLUMP store_to RWFRAME_WIN_DOOR_LF_DUMMY
if
RWFRAME_WIN_DOOR_LF_DUMMY > 0 //Only if the car have that dummy ("only if the car is adapted...")
then
0AA7: call_function_return _ZN15CClumpModelInfo16GetFrameFromNameEP7RpClumpPc num_params 2 pop 2 _name "DOOR_LF_DUMMY" _clump RPCLUMP store_to RWFRAME_DOOR_LF_DUMMY
//ROTATE
RWFRAME_DOOR_LF_DUMMY += 0x10 //RwFrame.modelling<RwMatrixTag> (local to object)
RWFRAME_DOOR_LF_DUMMY += 0x0 //RwMatrixTag.right<RwV3D> (angle)
RWFRAME_WIN_DOOR_LF_DUMMY += 0x10 //RwFrame.modelling<RwMatrixTag> (local to object)
RWFRAME_WIN_DOOR_LF_DUMMY += 0x0 //RwMatrixTag.right<RwV3D> (angle)
0AA5: call_function _memcpy_0 num_params 3 pop 3 params _size 0x0C _sourceData RWFRAME_DOOR_LF_DUMMY _copyTo RWFRAME_WIN_DOOR_LF_DUMMY
RWFRAME_DOOR_LF_DUMMY -= 0x10
RWFRAME_WIN_DOOR_LF_DUMMY -= 0x10
RWFRAME_DOOR_LF_DUMMY += 0x10 //RwFrame.modelling<RwMatrixTag> (local to object)
RWFRAME_DOOR_LF_DUMMY += 0x10 //RwMatrixTag.top<RwV3D> (angle)
RWFRAME_WIN_DOOR_LF_DUMMY += 0x10 //RwFrame.modelling<RwMatrixTag> (local to object)
RWFRAME_WIN_DOOR_LF_DUMMY += 0x10 //RwMatrixTag.top<RwV3D> (angle)
0AA5: call_function _memcpy_0 num_params 3 pop 3 params _size 0x0C _sourceData RWFRAME_DOOR_LF_DUMMY _copyTo RWFRAME_WIN_DOOR_LF_DUMMY
//MOVE
RWFRAME_WIN_DOOR_LF_DUMMY -= 0x10
RWFRAME_WIN_DOOR_LF_DUMMY -= 0x10
RWFRAME_WIN_DOOR_LF_DUMMY += 0x10 //RwFrame.modelling<RwMatrixTag>
RWFRAME_WIN_DOOR_LF_DUMMY += 0x30 //RwMatrixTag.pos<RwV3D>
0A8D: X = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0 //RwFrame.modelling<RwMatrixTag>.pos<RwV3D>.x
RWFRAME_WIN_DOOR_LF_DUMMY += 4
0A8D: Y = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0
RWFRAME_WIN_DOOR_LF_DUMMY += 4
0A8D: Z = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0
if isFirstTimeEnteringThatCar == true
then
MAX_Z = Z
MIN_Z = MAX_Z
MIN_Z -= 0.5
isFirstTimeEnteringThatCar = false
end
if Actor.Driving($PLAYER_ACTOR)
then
gosub @MoveWithKeyboard
end
0A8C: write_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 value Z virtual_protect 0
/*
//DEBUG
0AD1: show_formatted_text_highpriority "x=%.3f ; y=%.3f ; z=~r~%.3f" time 1000 X Y Z
RWFRAME_WIN_DOOR_LF_DUMMY -= 0x10
RWFRAME_WIN_DOOR_LF_DUMMY -= 0x30
RWFRAME_WIN_DOOR_LF_DUMMY -= 4
RWFRAME_WIN_DOOR_LF_DUMMY -= 4
RWFRAME_WIN_DOOR_LF_DUMMY += 0x50 //RwFrame.ltm<RwMatrixTag> (local to world)
RWFRAME_WIN_DOOR_LF_DUMMY += 0x30 //RwMatrixTag.pos<RwV3D>
0A8D: X = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0 //RwFrame.ltm<RwMatrixTag>.pos<RwV3D>.x
RWFRAME_WIN_DOOR_LF_DUMMY += 4
0A8D: Y = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0
RWFRAME_WIN_DOOR_LF_DUMMY += 4
0A8D: Z = read_memory RWFRAME_WIN_DOOR_LF_DUMMY size 4 virtual_protect 0
024F: create_corona_with_radius 1.0 type 0 lensflares 0 with_color 255 0 0 at X Y Z
*/
end
end
end
:MoveWithKeyboard
if and
0AB0: key_pressed 0x6B //+
Z <= MAX_Z
then
0079: Z += frame_delta_time * 0.01
else
if and
0AB0: key_pressed 0x6D //-
Z >= MIN_Z
then
007F: Z -= frame_delta_time * 0.01
end
end
return
/*
// module:
void __thiscall CMatrix::SetRotateZOnly(CMatrix *this, float a2)
{
long double v2; // st6
long double v3; // st5
this->right.z = 0.0;
this->top.z = 0.0;
this->at.x = 0.0;
this->at.y = 0.0;
this->at.z = 1.0;
v2 = sin(a2);
v3 = cos(a2);
this->right.x = *(float *)&v3;
this->right.y = v2; //Angles are saved in RwFrame.modelling<RwMatrixTag>.right<RwV3D>
this->top.x = -v2; //Angles are saved in RwFrame.modelling<RwMatrixTag>.top<RwV3D>
this->top.y = *(float *)&v3;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment