Register for your free account! | Forgot your password?

You last visited: Today at 19:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



changing name color

Discussion on changing name color within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
sigel123456789's Avatar
 
elite*gold: 0
Join Date: Sep 2015
Posts: 327
Received Thanks: 55
changing name color

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);
sigel123456789 is offline  
Reply


Similar Threads Similar Threads
Help with color name / color global / counter fortress
01/10/2021 - SRO PServer Questions & Answers - 1 Replies
#closed
changing chat text color ?
07/31/2012 - Silkroad Online - 5 Replies
is it possible to change chat text color ? i tried to search but i didn't find anything.
[Guide] Just changing the drops of VIP maps without changing of its place
10/08/2010 - EO PServer Guides & Releases - 2 Replies
in revo's DB when u add the VIP tele it apears on the old market .. some ppl dont know how to change its place thats why i made this query for them delete from cq_generator where id >= 0113 and id <= 0128; INSERT INTO `cq_generator` VALUES ('0113', '8900', '0062', '0033', '0001', '0001', '0001', '0025', '0001', '0110', '0000', '0000', '0000', '0000', '0000'); INSERT INTO `cq_generator` VALUES ('0114', '8900', '0072', '0037', '0001', '0001', '0001', '0025', '0001', '0110', '0000',...



All times are GMT +1. The time now is 19:56.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.