Help Changing SA-MP name-tag colors

Bear

New member
Joined
Jul 19, 2023
Messages
3
Reaction score
0
I develop Lua mods for SA-MP but I'm unfamiliar with memory hacking. Someone with color blindness has asked me for a mod to automatically change specific name-tag colors to other ones. Since there's no function to change name-tag colors in the Moonloader API, I'm assuming that memory hacking is involved.

I found [LUA] Color Names but it turned out to be closed-source and lacking the functionality I needed. I messaged the developer and haven't received a reply despite their continual activity.

I just need the code to change the name-tag color of a player, given their SA-MP ID. I can code the rest of the logic myself.
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
I develop Lua mods for SA-MP but I'm unfamiliar with memory hacking. Someone with color blindness has asked me for a mod to automatically change specific name-tag colors to other ones. Since there's no function to change name-tag colors in the Moonloader API, I'm assuming that memory hacking is involved.

I found [LUA] Color Names but it turned out to be closed-source and lacking the functionality I needed. I messaged the developer and haven't received a reply despite their continual activity.

I just need the code to change the name-tag color of a player, given their SA-MP ID. I can code the rest of the logic myself.
You looking for specific samp version or for all together?
 
Joined
Jul 30, 2023
Messages
5
Reaction score
4
Salutations, niggas.

I am GUWOP himself, and I come here, from trapping, here to present a way which doesn't require changing player color.

The way we will do this, is simply hook into the function which is responsible for drawing text onto screen, then find out the return addresses that we care about, so that we can manipulate the color ONLY for nametags.

Below, I attach the code which achieves the behavior we just described.
Code:
typedef uint32_t SampARGB_t;
static constexpr DWORD g_nameTagRetaddrs[] = { 0x6b637 };
typedef int(__stdcall* DrawToScreenFn_t)(int, int, const char*, int, int, int, int);
static DrawToScreenFn_t g_ogDrawToScreen = nullptr;
static int __stdcall DrawToScreenHook(int a1, int a2, const char* str, int a4, int a5, int a6, SampARGB_t color)
{
    if (str && *str)
        LOG(str << L' ' << std::hex << (DWORD)(_ReturnAddress()) << L'\n');

    if (IS_RETADDR_INSIDE(g_nameTagRetaddrs))
        color = (0xff << 24) | GetTickCount() & 0xffffff;

    Hook::Remove(DrawToScreenHook);
    int r = g_ogDrawToScreen(a1, a2, str, a4, a5, a6, color);
    Hook::Reinstall(DrawToScreenHook);

    return r;
}

Code:
static constexpr DWORD g_fnDrawToScreen = 0x73BE0;

Code:
    Hook::Install((void*)((DWORD)(g_data.GetSampDll()) + g_fnDrawToScreen), DrawToScreenHook, (void**)&g_ogDrawToScreen);

Offsets above are for SA:MP 0.3.7-R5 (MD5 5BA5F0BE7AF99DFD03FB39E88A970A2B), but I hope such is not an issue.

Using the method I described, you can also modify the text outline color, but that is an exercise for the reader.

A presentation:

Kind regards, and I fucking hate romanians.
SCOOCHIE!
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
Salutations, niggas.

I am GUWOP himself, and I come here, from trapping, here to present a way which doesn't require changing player color.

The way we will do this, is simply hook into the function which is responsible for drawing text onto screen, then find out the return addresses that we care about, so that we can manipulate the color ONLY for nametags.

Below, I attach the code which achieves the behavior we just described.
Code:
typedef uint32_t SampARGB_t;
static constexpr DWORD g_nameTagRetaddrs[] = { 0x6b637 };
typedef int(__stdcall* DrawToScreenFn_t)(int, int, const char*, int, int, int, int);
static DrawToScreenFn_t g_ogDrawToScreen = nullptr;
static int __stdcall DrawToScreenHook(int a1, int a2, const char* str, int a4, int a5, int a6, SampARGB_t color)
{
    if (str && *str)
        LOG(str << L' ' << std::hex << (DWORD)(_ReturnAddress()) << L'\n');

    if (IS_RETADDR_INSIDE(g_nameTagRetaddrs))
        color = (0xff << 24) | GetTickCount() & 0xffffff;

    Hook::Remove(DrawToScreenHook);
    int r = g_ogDrawToScreen(a1, a2, str, a4, a5, a6, color);
    Hook::Reinstall(DrawToScreenHook);

    return r;
}

Code:
static constexpr DWORD g_fnDrawToScreen = 0x73BE0;

Code:
    Hook::Install((void*)((DWORD)(g_data.GetSampDll()) + g_fnDrawToScreen), DrawToScreenHook, (void**)&g_ogDrawToScreen);

Offsets above are for SA:MP 0.3.7-R5 (MD5 5BA5F0BE7AF99DFD03FB39E88A970A2B), but I hope such is not an issue.

Using the method I described, you can also modify the text outline color, but that is an exercise for the reader.

A presentation:

Kind regards, and I fucking hate romanians.
SCOOCHIE!
Nice, Great work, Well done !
Btw, do you know something about drawing lines directly from samp memories without using D3D9 rendering?

Regards,
Parazitas.
 

Bear

New member
Joined
Jul 19, 2023
Messages
3
Reaction score
0
Thanks for the responses, everyone.

For the player colors in R1, this is the code that worked:
Code:
local colorPtr = samp_base + 0x216379 + (playerId * 4)
The address offset that worked for me was 0x216379, not 0x216378.

@GucciManeLaFlare, thanks a lot for the response. I'm sorry that I worded my question incorrectly. I wanted to change player color altogether, not just for the nametags. I hope it helps someone, though.

I'd also like to solve the problem for 0.3.7 R3-1, as that's the only other samp version that sampfuncs is available for (here). It's also what I use personally. I've tried finding the address offset myself in R3-1 but I've failed.
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,103
Solutions
5
Reaction score
882
Location
Lithuania
Thanks for the responses, everyone.

For the player colors in R1, this is the code that worked:
Code:
local colorPtr = samp_base + 0x216379 + (playerId * 4)
The address offset that worked for me was 0x216379, not 0x216378.

@GucciManeLaFlare, thanks a lot for the response. I'm sorry that I worded my question incorrectly. I wanted to change player color altogether, not just for the nametags. I hope it helps someone, though.

I'd also like to solve the problem for 0.3.7 R3-1, as that's the only other samp version that sampfuncs is available for (here). It's also what I use personally. I've tried finding the address offset myself in R3-1 but I've failed.
It's actually simple to find memories, i will drop for all existing samp versions when i run my pc.
 
Top