Implementing Player Name Color Change on Client Side

arwekaj09

Member
Joined
Feb 8, 2024
Messages
5
Hello everyone,

First and foremost, I want to express my gratitude for this wonderful forum where we can share knowledge and seek assistance from fellow enthusiasts.

I have a question regarding implementing a feature on the client side of my project, and I'm hoping someone here might be able to offer some guidance.

I'm looking to modify the color of player names based on specific text contained within them. For instance, if a player's name includes "Shaiya," I want their name to appear in green. Similarly, if the name contains "Test," it should be displayed in orange.

I am particularly interested in achieving this on the client side only. I understand that altering the appearance of player names dynamically can enhance the user experience and add a layer of customization.

PS: I am using Essential files
 
my answer requires this project.


i set the detour here because it won't interfere with party, admin, or enemy name colors.

C++:
void hook::name_color()
{
    // user name color
    util::detour((void*)0x45381B, naked_0x45381B, 6);
}

the function return value (eax) should be copied to ebp (the argb value), unless the return value is null. i don't think you need to save/restore registers in this case. use your own judgement and edit the asm as needed.

C++:
unsigned u0x453821 = 0x453821;
void __declspec(naked) naked_0x45381B()
{
    __asm
    {
        push esi // user
        call func
        add esp,0x4
        test eax,eax

        je original
        mov ebp,eax

        original:
        cmp dword ptr ds:[0x22AA7F8],ebx
        jmp u0x453821
    }
}

i would use a map (aka dictionary) to store the text and colors. the function explains itself well enough. i'm not sure if case sensitivity matters to you. use google if it does. :p

C++:
#include <map>
#include <string>

#include <include/main.h>
#include <include/util.h>
#include <include/shaiya/include/CCharacter.h>
using namespace shaiya;

using Color = unsigned int;

const std::map<std::string, Color> text_to_color
{
    { "Shaiya", 0xFF00FF40 },
    { "Test", 0xFFFF8000 }
};

Color func(CCharacter* user)
{
    if (!user)
        return 0;

    std::string charName(user->charName.data());

    for (const auto& [text, color] : text_to_color)
        if (charName.contains(text))
            return color;

    return 0;
}
 
Back
Top