Replace Part of an string

01/05/2016 22:35 raventh1984#1
Hi elitepvpers,

I am working on reducing some file sizes so i removed all II_PART_F etc
and altered mdldyna.inc

however in Spec_Item it will load only the Male Icons.

Now what i have in mind is to make an function to replace the male icon with female if you are an female char.

For the first test i have left the sex of the char out.

Code:
void CItemBase::SetTexture()
{
#ifdef __CLIENT
	ItemProp* pProp = GetProp();
	if (!pProp)
	{
		LPCTSTR szErr = Error("CItemBase::SetTexture GetProp() NULL Return %d", m_dwItemId);
		ADDERRORMSG(szErr);
	}


	//if(g_pPlayer->GetSex() == SEX_FEMALE)
	//{
		switch (pProp->dwItemKind3)
		{
		case IK3_HELMET:
		case IK3_SUIT:
		case IK3_GAUNTLET:
		case IK3_BOOTS:
		//	std::string strIcon = pProp->szIcon;
		//	size_t f = strIcon.find("Itm_m");
		//	strIcon.replace(f, std::string("Itm_m").length(), "Itm_f");
		//	m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, _T("strIcon")), 0xffff00ff);
		//	break;
			std::string strIcon = pProp->szIcon;
			ReplaceStringInPlace(strIcon, "Itm_m", "Itm_f");
			m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
			break;
		}
	//}
	
	//m_pTexture = CWndBase::m_textureMng.AddTexture( g_Neuz.m_pd3dDevice, MakePath( DIR_ITEM, strIcon ), 0xffff00ff );

#endif
}
I know its an mess but i am still testing

Now take an look into this line
Code:
m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
Its located underneath ReplaceStringInPlace

Now its giving me an error
No instance of overloaded function "MakePath" matches the arguments list argument types are (const char[6], std::string)

But is strIcon not an string? even it an part of the string is getting replaced?

With kind regards
01/05/2016 23:16 alfredico#2
You are converting std::string to CString.

CString strIcon;
strIcon.Replace("Itm_m", "Itm_f");
01/05/2016 23:27 raventh1984#3
does strIcon.replace replaces an part of the string? so it looks for that part in lets say

itm_mVag01Upper.dds?

Lol Nevermind ofcourse it does. Pfffff i was overthinking at at this point.

Thank you Alfredico.

Edit2:
Next problem is if i put if(g_pPlayer->GetSex() == SEX_FEMALE) rest of the code
It crashes on BYTE GetSex() inside Mover.h

i also have tryd
CMover* pMover;
if(pMover->GetSex() but the result is the same.


("You never are to old to learn haha")
01/06/2016 00:12 alfredico#4
g_pPlayer is null?
01/06/2016 00:22 raventh1984#5
I have tested it and indeed g_pPlayer is null.

i thought that if you logged in that g_pPlayer will had an value.
Seems i still have an lot to learn.

EDIT:

So if(g_pPlayer->GetSex() != NULL)
{
rest of the code

why is g_pPlayer null? Could you explain it? how this is happening so i can understand what to do?
01/06/2016 00:47 alfredico#6
CItemBase class is just for items.

I don't know what are you trying to do. Oh and g_pPlayer is CMover class, so it doesn't matter if you do CMover* pMover or CMover* g_pPlayer, would still return null.
01/06/2016 07:13 raventh1984#7
I removed all double lines from Spec_Item

So II_ARM_M_STORMB_HELMET_SET_KAL and II_ARM_F_STORMB_HELMET_SET_KAL

is now just II_ARM_STORMB_HELMET_SET_KAL.

So now i need to have an check otherwise it will load only the szIcons from the male char. instead of female if the char is female.
01/06/2016 10:03 alfredico#8
CMover* pMover = g_pPlayer;

CMover* pMover = CMover::GetActiveMover();

CObj* pObj;
CMover* pMover = (CMover*)pObj;

Or g_Neuz.m_apPlayer


Try and maybe there is one which works.
01/06/2016 11:11 raventh1984#9
Only g_Neuz.m_apPlayer is working
I did it like so for testing

Code:
if (g_Neuz.m_apPlayer != NULL)
	{
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
Its showing the icon now. So thank you for that.
Now i need to figure out how to set the Sex of the char

i have it now like this
Code:
for (int i = 0; i < 3; i++)
	{
		if (g_Neuz.m_apPlayer[i] != NULL)
		{
			if (g_Neuz.m_apPlayer[i]->GetSex() == SEX_FEMALE)
			{
				m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
			}
			else
			{

			}
		}
	}
But its showing the icons for both Female as Male.
And if i read it correct its saying if GetSex == Female then only show the icons.

Thank you for the help so far
01/06/2016 18:05 alfredico#10
That's because you are loading textures for all characters you have created. The i should be replaced by the character slot.

You only need this, the rest is not needed.
if (g_Neuz.m_apPlayer[slot]->GetSex() == SEX_FEMALE)
01/06/2016 18:59 raventh1984#11
Well i have tried that one before.

Result is this

Code:
if (g_Neuz.m_apPlayer[1]->GetSex() == SEX_FEMALE)
	{
		strIcon.Replace("Itm_m", "Itm_f");
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
	else
	{
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
[1] is the slot of the character
So what it does now is checking if slot 1 is an female if so then replace the string.
However my male char is char slot 0 and you guessed it its also female icons.

If i change the [1] to [0] then all icons are male since char slot 0 is an male char.

So i need to check witch char is loaded and get the sex from that one.


Is it possible to include WndSelectChar inside item.cpp and work with that class to?
01/06/2016 19:08 alfredico#12
Correct. I would take m_nSlot from CDPLoginClient.
#include "DPLoginClient.h"
extern CDPLoginClient g_dpLoginClient;
if (g_Neuz.m_apPlayer[g_dpLoginClient.m_nSlot]->GetSex() == SEX_FEMALE)

And tbh, I think there could be a cleaner way to do all this.
01/06/2016 19:32 raventh1984#13
Thank you that worked.

i really can't say about an cleaner way. Except to add them to Spec_Item again.
This is an quick solution atm.

before i added the above code i had this

Code:
CWndSelectChar* SelectChar;
	if (SelectChar->m_nSelectCharacter == 0 && g_Neuz.m_apPlayer[0]->GetSex() == SEX_FEMALE)
	{
		strIcon.Replace("Itm_m", "Itm_f");
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
	else if (SelectChar->m_nSelectCharacter == 0 && g_Neuz.m_apPlayer[0]->GetSex() == SEX_MALE)
	{
		//strIcon.Replace("Itm_m", "Itm_f");
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
	
	if (SelectChar->m_nSelectCharacter == 1 && g_Neuz.m_apPlayer[1]->GetSex() == SEX_FEMALE)
	{
		strIcon.Replace("Itm_m", "Itm_f");
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
	else if (SelectChar->m_nSelectCharacter == 1 && g_Neuz.m_apPlayer[1]->GetSex() == SEX_MALE)
	{
		//strIcon.Replace("Itm_m", "Itm_f");
		m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
	}
That worked to but your solution is cleaner.

Thank you for your big help in this
01/10/2016 18:20 KazumiTanuki#14
Quote:
Originally Posted by raventh1984 View Post
does strIcon.replace replaces an part of the string? so it looks for that part in lets say

itm_mVag01Upper.dds?

Lol Nevermind ofcourse it does. Pfffff i was overthinking at at this point.

Thank you Alfredico.

Edit2:
Next problem is if i put if(g_pPlayer->GetSex() == SEX_FEMALE) rest of the code
It crashes on BYTE GetSex() inside Mover.h

i also have tryd
CMover* pMover;
if(pMover->GetSex() but the result is the same.


("You never are to old to learn haha")

replace the string with a loop
01/10/2016 21:49 raventh1984#15
It's already solved.
It still was crashing so i removed to code and altered it inside WndItemCtrl.cpp
Code:
ItemProp* pItemProp = pItemElem->GetProp();
			CString strIcon = pItemProp->szIcon;
			switch (pItemProp->dwItemKind3)
			{
			case IK3_HELMET:
			case IK3_SUIT:
			case IK3_GAUNTLET:
			case IK3_BOOTS:
				switch (g_pPlayer->GetSex())
				{
				case SEX_MALE:
					m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
					m_pTexture->Render(p2DRender, CPoint(x, y), nalpha);
					break;
				case SEX_FEMALE:
					strIcon.Replace("Itm_m", "Itm_f");
					m_pTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, strIcon), 0xffff00ff);
					m_pTexture->Render(p2DRender, CPoint(x, y), nalpha);
					break;
				}
				break;
			default:
				pItemElem->GetTexture()->Render(p2DRender, CPoint(x, y), nalpha);
				break;
			}