Jump to content

Adding 5 extra bonuses (6/7 but till 10) causing CClientManager::RESULT_ITEM_LOAD raises error: Cannot access memory at address Dump


Recommended Posts

So I'm trying to add 5 extra bonuses (6/7, but till 10)
But with a catch too
First 3 bonuses should be added from item_attr_rare table, last 2 from item_attr_rare_pvp (so i added a new table, duplicate from item attr rare)

Then I proceeded to increase the item bonus count and limits:

enum EItemMisc
{
	ITEM_NAME_MAX_LEN = 24,
	ITEM_VALUES_MAX_NUM = 6,
	ITEM_SMALL_DESCR_MAX_LEN = 256,
	ITEM_LIMIT_MAX_NUM = 2,
	ITEM_APPLY_MAX_NUM = 3,
	ITEM_SOCKET_MAX_NUM = 3,
	ITEM_MAX_COUNT = 200,

	ITEM_ATTRIBUTE_NORM_NUM = 5,
	ITEM_ATTRIBUTE_RARE_NUM = 3,
#ifdef BETTER_67
	ITEM_ATTRIBUTE_RARE_PVP_NUM = 2,
#endif

	ITEM_ATTRIBUTE_NORM_START = 0,
	ITEM_ATTRIBUTE_NORM_END = ITEM_ATTRIBUTE_NORM_START + ITEM_ATTRIBUTE_NORM_NUM,

	ITEM_ATTRIBUTE_RARE_START = ITEM_ATTRIBUTE_NORM_END,
	ITEM_ATTRIBUTE_RARE_END = ITEM_ATTRIBUTE_RARE_START + ITEM_ATTRIBUTE_RARE_NUM,

#ifdef BETTER_67
	ITEM_ATTRIBUTE_RARE_PVP_START = ITEM_ATTRIBUTE_RARE_END,
#endif

#ifdef BETTER_67
	ITEM_ATTRIBUTE_RARE_PVP_END = ITEM_ATTRIBUTE_RARE_PVP_START + ITEM_ATTRIBUTE_RARE_PVP_NUM,
	ITEM_ATTRIBUTE_MAX_NUM = ITEM_ATTRIBUTE_RARE_PVP_END, // 7
#else
	ITEM_ATTRIBUTE_MAX_NUM = ITEM_ATTRIBUTE_RARE_END, // 7
#endif
	ITEM_ATTRIBUTE_MAX_LEVEL = 5,
	ITEM_AWARD_WHY_MAX_LEN = 50,

	REFINE_MATERIAL_MAX_NUM = 5,

	ITEM_ELK_VNUM = 50026,
};

Created a new vector to store these new bonuses:
 

	std::vector<TItemAttrTable> m_vec_itemRarePvpTable; // New vector to store item_attr_rare_pvp data

And now i read from the db, and for each row create a TItemAttrTable object, which i then add to the above vector:

 

#ifdef BETTER_67
bool CClientManager::InitializeItemRarePvpTable()
{
	char query[4096];
	snprintf(query, sizeof(query),
			 "SELECT apply, apply+0, prob, lv1, lv2, lv3, lv4, lv5, weapon, body, wrist, foots, neck, head, shield, ear "
#ifdef ENABLE_ITEM_ATTR_COSTUME
			 ", costume_body, costume_hair"
#if defined(ENABLE_ITEM_ATTR_COSTUME) && defined(ENABLE_WEAPON_COSTUME_SYSTEM)
			 ", costume_weapon"
#endif
#endif
#ifdef ENABLE_PENDANT_SYSTEM
			 ", pendant"
#endif
#ifdef ENABLE_GLOVE_SYSTEM
			 ", glove"
#endif
			 " FROM item_attr_rare_pvp%s ORDER BY apply",
			 GetTablePostfix());

	auto pkMsg(CDBManager::instance().DirectQuery(query));
	SQLResult *pRes = pkMsg->Get();

	if (!pRes->uiNumRows)
	{
		sys_err("no result from item_attr_rare_pvp");
		return false;
	}

	if (!m_vec_itemRarePvpTable.empty())
	{
		sys_log(0, "RELOAD: item_attr_rare_pvp");
		m_vec_itemRarePvpTable.clear();
	}

	m_vec_itemRarePvpTable.reserve(pRes->uiNumRows);

	MYSQL_ROW data;

	while ((data = mysql_fetch_row(pRes->pSQLResult)))
	{
		TItemAttrTable t{};

		int col = 0;

		strlcpy(t.szApply, data[col++], sizeof(t.szApply));
		str_to_number(t.dwApplyIndex, data[col++]);
		str_to_number(t.dwProb, data[col++]);
		str_to_number(t.lValues[0], data[col++]);
		str_to_number(t.lValues[1], data[col++]);
		str_to_number(t.lValues[2], data[col++]);
		str_to_number(t.lValues[3], data[col++]);
		str_to_number(t.lValues[4], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_WEAPON], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_BODY], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_WRIST], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_FOOTS], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_NECK], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_HEAD], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_SHIELD], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_EAR], data[col++]);
#ifdef ENABLE_ITEM_ATTR_COSTUME
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_BODY], data[col++]);
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_HAIR], data[col++]);
#if defined(ENABLE_ITEM_ATTR_COSTUME) && defined(ENABLE_WEAPON_COSTUME_SYSTEM)
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_WEAPON], data[col++]);
#endif
#endif
#ifdef ENABLE_PENDANT_SYSTEM
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_PENDANT], data[col++]);
#endif
#ifdef ENABLE_GLOVE_SYSTEM
		str_to_number(t.bMaxLevelBySet[ATTRIBUTE_SET_GLOVE], data[col++]);
#endif

		sys_log(0, "ITEM_RARE_PVP: %-20s %4lu { %3d %3d %3d %3d %3d } { %d %d %d %d %d %d %d"
#ifdef ENABLE_ITEM_ATTR_COSTUME
				   " %d %d"
#if defined(ENABLE_ITEM_ATTR_COSTUME) && defined(ENABLE_WEAPON_COSTUME_SYSTEM)
				   " %d"
#endif
#endif
#ifdef ENABLE_PENDANT_SYSTEM
				   " %d"
#endif
#ifdef ENABLE_GLOVE_SYSTEM
				   " %d"
#endif
				   " }",
				t.szApply,
				t.dwProb,
				t.lValues[0],
				t.lValues[1],
				t.lValues[2],
				t.lValues[3],
				t.lValues[4],
				t.bMaxLevelBySet[ATTRIBUTE_SET_WEAPON],
				t.bMaxLevelBySet[ATTRIBUTE_SET_BODY],
				t.bMaxLevelBySet[ATTRIBUTE_SET_WRIST],
				t.bMaxLevelBySet[ATTRIBUTE_SET_FOOTS],
				t.bMaxLevelBySet[ATTRIBUTE_SET_NECK],
				t.bMaxLevelBySet[ATTRIBUTE_SET_HEAD],
				t.bMaxLevelBySet[ATTRIBUTE_SET_SHIELD],
				t.bMaxLevelBySet[ATTRIBUTE_SET_EAR]
#ifdef ENABLE_ITEM_ATTR_COSTUME
				,
				t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_BODY], t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_HAIR]
#if defined(ENABLE_ITEM_ATTR_COSTUME) && defined(ENABLE_WEAPON_COSTUME_SYSTEM)
				,
				t.bMaxLevelBySet[ATTRIBUTE_SET_COSTUME_WEAPON]
#endif
#endif
#ifdef ENABLE_PENDANT_SYSTEM
				,
				t.bMaxLevelBySet[ATTRIBUTE_SET_PENDANT]
#endif
#ifdef ENABLE_GLOVE_SYSTEM
				,
				t.bMaxLevelBySet[ATTRIBUTE_SET_GLOVE]
#endif
		);

		m_vec_itemRarePvpTable.emplace_back(t);
	}

	return true;
}
#endif // BETTER_67

Initialization seem to pass all ok
 

#ifdef BETTER_67
	// Initialize the new table
	if (!InitializeItemRarePvpTable())
	{
		sys_err("InitializeItemRarePvpTable FAILED");
		return false;
	}
	else
	{
		sys_err("Succesfully initialized ItemRarePvpTable");
	}
#endif

The syserr log is temporary, just so I am convinced it worked, or atleast returned true, which it does

But the problem is, now it seems that it fails to load items, db core dump, displayed using bt only:
 

(gdb)
#0  thr_kill () at thr_kill.S:4
#1  0x20a1fa8b in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52
#2  0x20ac9beb in abort () at /usr/src/lib/libc/stdlib/abort.c:67
#3  0x0042ab87 in emergency_sig (sig=11) at Main.cpp:53
#4  0x209760b9 in handle_signal (actp=<optimized out>, sig=<optimized out>, info=0xffffd1c0, ucp=0xffffcf00) at /usr/src/lib/libthr/thread/thr_sig.c:303
#5  0x20975660 in thr_sighandler (sig=11, info=0xffffd1c0, _ucp=0xffffcf00) at /usr/src/lib/libthr/thread/thr_sig.c:246
#6  <signal handler called>
#7  0x004428c4 in str_to_number (out=@0x2299a531: 0, in=0x30323033 <error: Cannot access memory at address 0x30323033>) at ./../../common/utils.h:48
#8  CreateItemTableFromRes (res=0x22fa7240, pVec=0x4ab978 <CClientManager::RESULT_ITEM_LOAD(CPeer*, st_mysql_res*, unsigned int, unsigned int)::s_items>, dwPID=17)
    at ClientManagerPlayer.cpp:64
#9  0x00444177 in CClientManager::RESULT_ITEM_LOAD (this=0xffffd410, peer=0x20bef600, pRes=0x22fa7240, dwHandle=4, dwPID=17) at ClientManagerPlayer.cpp:692
#10 0x00443f4c in CClientManager::RESULT_COMPOSITE_PLAYER (this=0xffffd410, peer=0x20bef600, pMsg=0x20bc4570, dwQID=1) at ClientManagerPlayer.cpp:587
#11 0x00431e4e in CClientManager::AnalyzeQueryResult (this=0xffffd410, msg=0x20bc4570) at ClientManager.cpp:2887
#12 0x004318b0 in CClientManager::MainLoop (this=0xffffd410) at ClientManager.cpp:314
#13 0x0042ac99 in main () at Main.cpp:84

I changed nothing in `RESULT_ITEM_LOAD` or any other place, double checked in git pr view, no accidents there neither, I assume changing the bonus range has other several cascading effects and necessary changes?

If so, could anybody point me in the right direction?

Update, here, fixed the core crash, but I guess something didn't go as planned, altered item table, added the other columns for the new attrs, but somewhere i fucked up bcs now, inventory dosen't work, items are duplicated and alot of other things broke

For cache i changed the fush method a bit

 

void CItemCache::OnFlush()
{
	if (m_data.vnum == 0)
	{
		char szQuery[QUERY_MAX_LEN];
		snprintf(szQuery, sizeof(szQuery), "DELETE FROM item%s WHERE id=%u", GetTablePostfix(), m_data.id);
		CDBManager::instance().ReturnQuery(szQuery, QID_ITEM_DESTROY, 0, NULL);

		if (g_test_server)
			sys_log(0, "ItemCache::Flush : DELETE %u %s", m_data.id, szQuery);
	}
	else
	{
		TPlayerItem *p = &m_data;
		const auto setQuery = fmt::format(FMT_COMPILE("id={}, owner_id={}, `window`={}, pos={}, count={}, vnum={}, socket0={}, socket1={}, socket2={}, "
													  "attrtype0={}, attrvalue0={}, "
													  "attrtype1={}, attrvalue1={}, "
													  "attrtype2={}, attrvalue2={}, "
													  "attrtype3={}, attrvalue3={}, "
													  "attrtype4={}, attrvalue4={}, "
													  "attrtype5={}, attrvalue5={}, "
													  "attrtype6={}, attrvalue6={} "
#ifdef BETTER_67
													  ", attrtype7={}, attrvalue7={}, "
													  "attrtype8={}, attrvalue8={}, "
													  "attrtype9={}, attrvalue9={} "
#endif
													  ),
										  p->id,
										  p->owner,
										  p->window,
										  p->pos,
										  p->count,
										  p->vnum,
										  p->alSockets[0],
										  p->alSockets[1],
										  p->alSockets[2],
										  p->aAttr[0].bType, p->aAttr[0].sValue,
										  p->aAttr[1].bType, p->aAttr[1].sValue,
										  p->aAttr[2].bType, p->aAttr[2].sValue,
										  p->aAttr[3].bType, p->aAttr[3].sValue,
										  p->aAttr[4].bType, p->aAttr[4].sValue,
										  p->aAttr[5].bType, p->aAttr[5].sValue,
										  p->aAttr[6].bType, p->aAttr[6].sValue
#ifdef BETTER_67
										  ,
										  p->aAttr[7].bType, p->aAttr[7].sValue,
										  p->aAttr[8].bType, p->aAttr[8].sValue,
										  p->aAttr[9].bType, p->aAttr[9].sValue
#endif
		); // @fixme205

		const auto itemQuery = fmt::format(FMT_COMPILE("INSERT INTO item{} SET {} ON DUPLICATE KEY UPDATE {}"),
										   GetTablePostfix(), setQuery, setQuery);

		if (g_test_server)
			sys_log(0, "ItemCache::Flush :REPLACE  (%s)", itemQuery.c_str());

		CDBManager::instance().ReturnQuery(itemQuery.c_str(), QID_ITEM_SAVE, 0, NULL);

		++g_item_count;
	}

	m_bNeedQuery = false;
}

Is there any other place i gotta change caching?

What basically happens now, client seems to not understand anything anymore, chat dosent work after the things start bugging out But hopefully i think i understand i m missing something on client side too bcs there are some chat packets that are being raised after moving items around in the inv

0528 13:29:18383 :: Unprocessed packet header 137, state Game 0528 13:29:19900 :: Unprocessed packet header 73, state Game 0528 13:29:24570 :: Unknown packet header: 102, last: 61 124

https://giphy.com/gifs/r4qrhqbxdqVwnrLrKW

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

update 999, seems like after adding 3 bonuses on an item it is succesfuly inserted into the db, but client instantly crashes with no syserr when a item with the 3rd bonus is present on the char

Do you guys have any advice on where I should add them on client side to be visible?

I m expecting some range on python side or something like that but not sure where

Fixed the unprocessed packets too, seems like having null attrs in db is not ok

fixed the client problem too, had to increase ITEM_ATTRIBUTE_SLOT_RARE_NUM on client side

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.