changing name color

02/07/2021 06:49 sigel123456789#1
iam trying to change the name color but it changes it to the whole server
Code:
#include "namecolors.h"
#include "memhelp.h"

std::vector<tPrefixColorPair> namecolors::m_prefixes;

//-------------------------------------------------------
//You SHOULD only care about updating this offsets if changing client
//cant quarantee anything here
const DWORD dwPrefixJumpbackIfNoPrefix = 0x009CFDDC;
const DWORD dwPrefixJumpbackIfPrefix = 0x009D026C;
const DWORD dwJmxStrCmp = 0x00B44EFC;
const DWORD dwHookAddr = 0x009CFDBE;
//-------------------------------------------------------

DWORD dwPrefixHookCharnameAddr = 0;
DWORD dwNewPrefixCharnameColor = 0;


void namecolors::Initialize()
{
    memhelp::RenderNop((void*)dwHookAddr, 6);
    memhelp::RenderDetour(ASM_JMP, (void*)dwHookAddr, OnCharnamePrefixHook);
}



DWORD namecolors::GetPrefixColor(DWORD charnameAddr)
{
    DWORD res = 0;
    DWORD dwCmpRes = 0;

    for(std::vector<tPrefixColorPair>::iterator iter = m_prefixes.begin(); iter != m_prefixes.end(); iter++)
    {
        std::wstring str = iter->first;

        const wchar_t* curPrefix = str.c_str();
        DWORD len = str.length();

        __asm
        {
        push len;
        push curPrefix;
        push dwPrefixHookCharnameAddr;
        call dwJmxStrCmp;

        add esp, 0xC;

        mov dwCmpRes, eax;
        }

        if(dwCmpRes == 0)
        return iter->second;
        }

        return res;
        }



        void namecolors::OnCharnamePrefix()
        {
            //0 if we dont need to replace anything... see OnCharnamePrefixHook code (je)
            dwNewPrefixCharnameColor = namecolors::GetPrefixColor(dwPrefixHookCharnameAddr);
            //Print debug info here if u wanna
        }

        __declspec(naked) void namecolors::OnCharnamePrefixHook()
        {
            //Emulate
            //EAX = charname (unicode)
            __asm push eax;
            __asm mov dwPrefixHookCharnameAddr, eax;
            __asm pop eax;


            __asm pushad;
            namecolors::OnCharnamePrefix();
            __asm popad;

            __asm cmp dwNewPrefixCharnameColor, 0;
            __asm je no_replace;

            //Update
            __asm push dwNewPrefixCharnameColor;
            __asm mov dwNewPrefixCharnameColor, 0;
            __asm jmp dwPrefixJumpbackIfPrefix;

            no_replace:
            __asm jmp dwPrefixJumpbackIfNoPrefix;
        }



        bool namecolors::PrefixExists(wchar_t* prefix)
        {
            for(std::vector<tPrefixColorPair>::iterator iter = m_prefixes.begin(); iter != m_prefixes.end(); iter++)
            {
                if(wcscmp(iter->first, prefix) == 0)
                    return true;
            }
            return false;
        }


        void namecolors::SetPrefix(wchar_t* prefix, DWORD color)
        {
            if(!namecolors::PrefixExists(prefix))
                m_prefixes.push_back(tPrefixColorPair(prefix, color));
            else
            {
                for(std::vector<tPrefixColorPair>::iterator iter = m_prefixes.begin(); iter != m_prefixes.end(); iter++)
                {
                    if(wcscmp(iter->first, prefix) == 0)
                    {
                        iter->first = prefix;
                        iter->second = color;
                        return;
                    }
                }
            }
        }

        void namecolors::RemovePrefix(wchar_t* prefix)
        {
            if(!PrefixExists(prefix))
                return;


            uint32_t removalAlign = 0;


            for(std::vector<tPrefixColorPair>::iterator iter = m_prefixes.begin(); iter != m_prefixes.end(); iter++)
            {
                if(wcscmp(iter->first, prefix) == 0)
                    break;
                ++removalAlign;
            }

            m_prefixes.erase(m_prefixes.begin() + removalAlign);
        }

Code:
#pragma once
#include "xlib.h"

typedef std::pair<wchar_t*, DWORD> tPrefixColorPair;

class namecolors
{

public:
    static void Initialize();

    static bool PrefixExists(wchar_t* prefix);
    static void SetPrefix(wchar_t* prefix, DWORD color);
    static void RemovePrefix(wchar_t* prefix);



private:
    static std::vector<tPrefixColorPair> m_prefixes;

    //Just for accessibility... clean later
    static void OnCharnamePrefix();
    static void OnCharnamePrefixHook();
    static DWORD GetPrefixColor(DWORD charnameAddr);
};

Code:
    namecolors::SetPrefix(L"sigel", 0xFFFF11FF);