Skip to content

Commit

Permalink
Add SAMP 0.3.7-R2, R5, DL support
Browse files Browse the repository at this point in the history
  • Loading branch information
Northn committed Jun 12, 2023
1 parent d5e8109 commit dda6bf3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
44 changes: 31 additions & 13 deletions src/libs/samp/samp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ enum SAMPVER {
SAMP_NOT_LOADED,
SAMP_UNKNOWN,
SAMP_037_R1,
SAMP_037_R2,
SAMP_037_R3_1,
SAMP_037_R4_2
SAMP_037_R4_2,
SAMP_037_R5_1,
SAMP_037_DL
};

inline uintptr_t sampGetBase()
Expand All @@ -39,12 +42,21 @@ inline SAMPVER sampGetVersion()
case 0x31DF13:
sampVersion = SAMPVER::SAMP_037_R1;
break;
case 0x3195DD:
sampVersion = SAMPVER::SAMP_037_R2;
break;
case 0xCC4D0:
sampVersion = SAMPVER::SAMP_037_R3_1;
break;
case 0xCBCB0:
sampVersion = SAMPVER::SAMP_037_R4_2;
break;
case 0xCBC90:
sampVersion = SAMPVER::SAMP_037_R5_1;
break;
case 0xFDB60:
sampVersion = SAMPVER::SAMP_037_DL;
break;
default:
sampVersion = SAMPVER::SAMP_UNKNOWN;
#ifdef _DEBUG
Expand All @@ -71,17 +83,23 @@ enum class SampAddresses {

struct SampAddress
{
uintptr_t R1, R3, R4;
uintptr_t R1, R2, R3, R4, R5, DL;

uintptr_t get() {
switch (sampGetVersion())
{
case SAMPVER::SAMP_037_R1:
return R1;
case SAMPVER::SAMP_037_R2:
return R2;
case SAMPVER::SAMP_037_R3_1:
return R3;
case SAMPVER::SAMP_037_R4_2:
return R4;
case SAMPVER::SAMP_037_R5_1:
return R5;
case SAMPVER::SAMP_037_DL:
return DL;
default:
#ifdef _DEBUG
assert(0);
Expand All @@ -93,24 +111,24 @@ struct SampAddress

constexpr SampAddress sampGetAddress(SampAddresses element)
{
#define ENTRY(name, r1, r3, r4) case SampAddresses::name: return {r1, r3, r4};
#define ENTRY(name, r1, r2, r3, r4, r5, dl) case SampAddresses::name: return {r1, r2, r3, r4, r5, dl};
switch (element)
{
ENTRY(CNetGame, 0x21A0F8, 0x26E8DC, 0x26EA0C);
ENTRY(StringWriteEncoder, 0x506B0, 0x53A60, 0x541A0 );
ENTRY(StringReadDecoder, 0x507E0, 0x53B90, 0x542D0 );
ENTRY(CompressorPtr, 0x10D894, 0x121914, 0x121A3C);
ENTRY(HandleRpc, 0x372F0, 0x3A6A0, 0x3ADE0 );
ENTRY(RakClientIntfConstr, 0x33DC0, 0x37170, 0x378B0 );
ENTRY(alloc_packet, 0x347E0, 0x37B90, 0x382D0 );
ENTRY(write_lock, 0x35B10, 0x38EC0, 0x39600 );
ENTRY(write_unlock, 0x35B50, 0x38F00, 0x39640 );
ENTRY(CNetGame, 0x21A0F8, 0x21A100, 0x26E8DC, 0x26EA0C, 0x26EB94, 0x2ACA24);
ENTRY(StringWriteEncoder, 0x506B0, 0x50790, 0x53A60, 0x541A0, 0x541A0, 0x53C60 );
ENTRY(StringReadDecoder, 0x507E0, 0x508C0, 0x53B90, 0x542D0, 0x542D0, 0x53D90 );
ENTRY(CompressorPtr, 0x10D894, 0x10D894, 0x121914, 0x121A3C, 0x121A3C, 0x15FA54);
ENTRY(HandleRpc, 0x372F0, 0x373D0, 0x3A6A0, 0x3ADE0, 0x3ADE0, 0x3A8A0 );
ENTRY(RakClientIntfConstr, 0x33DC0, 0x33F10, 0x37170, 0x378B0, 0x378B0, 0x37370 );
ENTRY(alloc_packet, 0x347E0, 0x348C0, 0x37B90, 0x382D0, 0x382D0, 0x37D90 );
ENTRY(write_lock, 0x35B10, 0x35BF0, 0x38EC0, 0x39600, 0x39600, 0x390C0 );
ENTRY(write_unlock, 0x35B50, 0x35C30, 0x38F00, 0x39640, 0x39640, 0x39100 );
}
#undef ENTRY
#ifdef _DEBUG
assert(0);
#endif
return { 0, 0 };
return { 0, 0, 0, 0, 0, 0 };
}

#define SAMP_OFFSET(name) sampGetAddress(SampAddresses::name).get()
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ void initEnums(sol::state_view& lua)
{ "SAMP_NOT_LOADED", SAMPVER::SAMP_NOT_LOADED },
{ "SAMP_UNKNOWN", SAMPVER::SAMP_UNKNOWN },
{ "SAMP_037_R1", SAMPVER::SAMP_037_R1 },
{ "SAMP_037_R2", SAMPVER::SAMP_037_R2 },
{ "SAMP_037_R3_1", SAMPVER::SAMP_037_R3_1 },
{ "SAMP_037_R4_2", SAMPVER::SAMP_037_R4_2 },
{ "SAMP_037_R5_1", SAMPVER::SAMP_037_R5_1 },
{ "SAMP_037_DL", SAMPVER::SAMP_037_DL },
}
);

Expand Down Expand Up @@ -234,7 +238,7 @@ sol::table open(sol::this_state ts)
gRakLua.initialize();

sol::table module = lua.create_table();
module["VERSION"] = 2.12;
module["VERSION"] = 2.13;
module.set_function("getState", &getState);

module.set_function("registerHandler", &registerHandler);
Expand Down

0 comments on commit dda6bf3

Please sign in to comment.