Jump to content

Extend Stack Items


Recommended Posts

  • Premium

M2 Download Center

This is the hidden content, please
( Internal )

Hi there Devs,

I successfully extended the maximum number of items in a stack, so I'd like to share it. Originally the type of the "count" variables are "BYTE", so the maximum number only 255. I changed this to "WORD" (unsigned short), so now its about 60k.

client

packet.h

Search for this: typedef struct command_item_drop2
then replace this in the struct:

BYTE        count;

to this:

WORD        count;

Then search for this: typedef struct command_item_move
then replace this in the struct:

BYTE num;

To this:

WORD num;

Search for this: typedef struct SShopItemTable
then replace this in the struct:

BYTE		count;

to this:

WORD		count;

Search for this: typedef struct packet_set_item2
then replace this in the struct:

BYTE		count;

to this:

WORD		count;

Then search for this: typedef struct packet_update_item
then replace this in the struct:

BYTE		count;

to this:

WORD		count;


Then search for this: typedef struct SEquipmentItemSet
replace this:

BYTE    count;

to this:

WORD    count;


PythonNetworkPhaseGame.cpp->RecvExchangePacket function

Replace this:

CPythonExchange::Instance().SetItemToSelf(iSlotIndex, exchange_packet.arg1, (BYTE) exchange_packet.arg3);

To this:

CPythonExchange::Instance().SetItemToSelf(iSlotIndex, exchange_packet.arg1, (WORD) exchange_packet.arg3);

and this:

CPythonExchange::Instance().SetItemToTarget(iSlotIndex, exchange_packet.arg1, (BYTE) exchange_packet.arg3);

to this:

CPythonExchange::Instance().SetItemToTarget(iSlotIndex, exchange_packet.arg1, (WORD) exchange_packet.arg3);


pythonexchange.cpp:

Replace this:

BYTE CPythonExchange::GetItemCountFromTarget(BYTE pos)

With this:

WORD CPythonExchange::GetItemCountFromTarget(BYTE pos)

Then this:

BYTE CPythonExchange::GetItemCountFromSelf(BYTE pos)

With this:

WORD CPythonExchange::GetItemCountFromSelf(BYTE pos)

And this:

void CPythonExchange::SetItemToTarget(DWORD pos, DWORD vnum, BYTE count)

With this:

void CPythonExchange::SetItemToTarget(DWORD pos, DWORD vnum, WORD count)

And then this:

void CPythonExchange::SetItemToSelf(DWORD pos, DWORD vnum, BYTE count)

With this:

void CPythonExchange::SetItemToSelf(DWORD pos, DWORD vnum, WORD count)


pythonexchange.h

Replace this ones:

		BYTE			GetItemCountFromTarget(BYTE pos);
		BYTE			GetItemCountFromSelf(BYTE pos);
		
		void			SetItemToTarget(DWORD pos, DWORD vnum, BYTE count);
		void			SetItemToSelf(DWORD pos, DWORD vnum, BYTE count);
		
		BYTE					item_count[EXCHANGE_ITEM_MAX_NUM];

To this:

		WORD			GetItemCountFromTarget(BYTE pos);
		WORD			GetItemCountFromSelf(BYTE pos);
		
		void			SetItemToTarget(DWORD pos, DWORD vnum, WORD count);
		void			SetItemToSelf(DWORD pos, DWORD vnum, WORD count);
		
		WORD					item_count[EXCHANGE_ITEM_MAX_NUM];


PythonNetworkStreamPhaseGameItem.cpp

Replace the whole function:

bool CPythonNetworkStream::SendShopSellPacketNew

With this:

typedef struct fckOFF
{
	BYTE		bySlot;
	WORD		byCount;
} TfckOFF;

bool CPythonNetworkStream::SendShopSellPacketNew(BYTE bySlot, WORD byCount)
{
	if (!__CanActMainInstance())
		return true;

	TPacketCGShop PacketShop;
	PacketShop.header = HEADER_CG_SHOP;
	PacketShop.subheader = SHOP_SUBHEADER_CG_SELL2;
	TfckOFF second;
	second.byCount = byCount;
	second.bySlot = bySlot;

	if (!Send(sizeof(TPacketCGShop), &PacketShop))
	{
		Tracef("SendShopSellPacket Error\n");
		return false;
	}
	if (!Send(sizeof(TfckOFF), &second))
	{
		Tracef("SendShopAddSellPacket Error\n");
		return false;
	}
	/*if (!Send(sizeof(WORD), &byCount))
	{
		Tracef("SendShopAddSellPacket Error\n");
		return false;
	}*/

	Tracef(" SendShopSellPacketNew(bySlot=%d, byCount=%u)\n", bySlot, byCount);

	return SendSequence();
}

Then replace this:

bool CPythonNetworkStream::SendItemMovePacket(TItemPos pos, TItemPos change_pos, BYTE num)
bool CPythonNetworkStream::SendSafeBoxItemMovePacket(BYTE bySourcePos, BYTE byTargetPos, BYTE byCount)

To this:

bool CPythonNetworkStream::SendItemMovePacket(TItemPos pos, TItemPos change_pos, WORD num)
bool CPythonNetworkStream::SendSafeBoxItemMovePacket(BYTE bySourcePos, BYTE byTargetPos, WORD byCount)


pythonplayermodule.cpp

Replace the whole function:

PyObject * playerSetItemCount(PyObject* poSelf, PyObject* poArgs)

With this:

PyObject * playerSetItemCount(PyObject* poSelf, PyObject* poArgs)
{
	switch (PyTuple_Size(poArgs))
	{
	case 2:
		{
			int iSlotIndex;
			if (!PyTuple_GetInteger(poArgs, 0, &iSlotIndex))
				return Py_BuildException();

			WORD wCount;
			if (!PyTuple_GetInteger(poArgs, 1, &wCount))
				return Py_BuildException();

			if (0 == wCount)
				return Py_BuildException();

			CPythonPlayer::Instance().SetItemCount(TItemPos (INVENTORY, iSlotIndex), wCount);
			return Py_BuildNone();
		}
	case 3:
		{
			TItemPos Cell;
			if (!PyTuple_GetByte(poArgs, 0, &Cell.window_type))
				return Py_BuildException();

			if (!PyTuple_GetInteger(poArgs, 1, &Cell.cell))
				return Py_BuildException();

			WORD wCount;
			if (!PyTuple_GetInteger(poArgs, 2, &wCount))
				return Py_BuildException();

			CPythonPlayer::Instance().SetItemCount(Cell, wCount);

			return Py_BuildNone();
		}
	default:
		return Py_BuildException();

	}
}

PythonNetworkStreamModule.cpp

Replace the following function:

PyObject* netSendItemMovePacket(PyObject* poSelf, PyObject* poArgs)

With this:

PyObject* netSendItemMovePacket(PyObject* poSelf, PyObject* poArgs)
{
	TItemPos Cell;
	TItemPos ChangeCell;
	int num;

	switch (PyTuple_Size(poArgs))
	{
	case 3:
		if (!PyTuple_GetInteger(poArgs, 0, &Cell.cell))
			return Py_BuildException();
		if (!PyTuple_GetInteger(poArgs, 1, &ChangeCell.cell))
			return Py_BuildException();
		if (!PyTuple_GetInteger(poArgs, 2, &num))
			return Py_BuildException();
		break;
	case 5:
		{
			if (!PyTuple_GetByte(poArgs, 0, &Cell.window_type))
				return Py_BuildException();
			if (!PyTuple_GetInteger(poArgs, 1, &Cell.cell))
				return Py_BuildException();
			if (!PyTuple_GetByte(poArgs, 2, &ChangeCell.window_type))
				return Py_BuildException();
			if (!PyTuple_GetInteger(poArgs, 3, &ChangeCell.cell))
				return Py_BuildException();
			if (!PyTuple_GetInteger(poArgs, 4, &num))
				return Py_BuildException();
		}
		break;
	default:
		return Py_BuildException();
	}

	CPythonNetworkStream& rkNetStream=CPythonNetworkStream::Instance();
	rkNetStream.SendItemMovePacket(Cell, ChangeCell, (WORD) num);//ez a sor az
	return Py_BuildNone();
}

GameType.h

Search for this: typedef struct packet_item
Then replace this:

BYTE        count;

With this:

WORD        count;

Search for this: typedef struct packet_shop_item
And edit this:

BYTE        count;

to this:

WORD        count;

AbstractPlayer.h

Replace this:

virtual void	SetItemCount(TItemPos itemPos, BYTE byCount) = 0;

With this:

virtual void	SetItemCount(TItemPos itemPos, WORD byCount) = 0;

PythonPlayer.cpp

Replace this:

void CPythonPlayer::SetItemCount(TItemPos Cell, BYTE byCount)

With this:

void CPythonPlayer::SetItemCount(TItemPos Cell, WORD byCount)

PythonPlayer.h

Replace this:

void	SetItemCount(TItemPos Cell, BYTE byCount);

With this:

void	SetItemCount(TItemPos Cell, WORD byCount);

PythonNetworkStream.h

And this:

bool SendSafeBoxItemMovePacket(BYTE bySourcePos, BYTE byTargetPos, BYTE byCount);
bool SendShopSellPacketNew(BYTE bySlot, BYTE byCount);
bool SendItemMovePacket(TItemPos pos, TItemPos change_pos, BYTE num);

With this:

bool SendSafeBoxItemMovePacket(BYTE bySourcePos, BYTE byTargetPos, WORD byCount);
bool SendShopSellPacketNew(BYTE bySlot, WORD byCount);
bool SendItemMovePacket(TItemPos pos, TItemPos change_pos, WORD num);

Now we are done with the client, you can build it now.

 

server

common/tables.h

Search this: typedef struct SShopItemTable
Then replace this:

BYTE		count;

To this:

WORD		count;

packet.h

Search for this: typedef struct command_item_drop2
Then edit this:

BYTE	count;

To this:

WORD	count;

Then search this:: typedef struct command_item_move
Replace this:

BYTE	count;

With this:

WORD	count;

Then search this: typedef struct packet_item_set
Replace this:

BYTE	count;

To this:

WORD	count;

Search this: typedef struct packet_item_update
Replace this:

BYTE	count;

To this:

WORD	count;

Search this: struct packet_shop_item
Replace this:

BYTE        count;

To this:

WORD        count;

Search this: typedef struct pakcet_view_equip
Then replace this:

BYTE	count;

To this:

WORD	count;


input_main.cpp

Replace this whole function:

int CInputMain::Shop(LPCHARACTER ch, const char * data, size_t uiBytes)

With this:

typedef struct fckOFF
{
	BYTE		bySlot;
	WORD		byCount;
} TfckOFF;

int CInputMain::Shop(LPCHARACTER ch, const char * data, size_t uiBytes)
{
	TPacketCGShop * p = (TPacketCGShop *) data;

	if (uiBytes < sizeof(TPacketCGShop))
		return -1;

	if (test_server)
		sys_log(0, "CInputMain::Shop() ==> SubHeader %d", p->subheader);

	const char * c_pData = data + sizeof(TPacketCGShop);
	uiBytes -= sizeof(TPacketCGShop);

	switch (p->subheader)
	{
		case SHOP_SUBHEADER_CG_END:
			sys_log(1, "INPUT: %s SHOP: END", ch->GetName());
			CShopManager::instance().StopShopping(ch);
			return 0;

		case SHOP_SUBHEADER_CG_BUY:
			{
				if (uiBytes < sizeof(BYTE) + sizeof(BYTE))
					return -1;

				BYTE bPos = *(c_pData + 1);
				sys_log(1, "INPUT: %s SHOP: BUY %d", ch->GetName(), bPos);
				CShopManager::instance().Buy(ch, bPos);
				return (sizeof(BYTE) + sizeof(BYTE));
			}

		case SHOP_SUBHEADER_CG_SELL:
			{
				if (uiBytes < sizeof(BYTE))
					return -1;

				BYTE pos = *c_pData;

				sys_log(0, "INPUT: %s SHOP: SELL", ch->GetName());
				CShopManager::instance().Sell(ch, pos);
				return sizeof(BYTE);
			}

		case SHOP_SUBHEADER_CG_SELL2:
			{
				if (uiBytes < sizeof(TfckOFF))
					return -1;
				TfckOFF*p2 = (TfckOFF*)c_pData;
				/*BYTE pos = *(c_pData++);
				WORD count = *(c_pData);*/

				sys_log(0, "INPUT: %s SHOP: SELL2", ch->GetName());
				CShopManager::instance().Sell(ch, p2->bySlot, p2->byCount);
				return sizeof(TfckOFF);
			}

		default:
			sys_err("CInputMain::Shop : Unknown subheader %d : %s", p->subheader, ch->GetName());
			break;
	}

	return 0;
}


shop_manager.cpp

Replace this:

void CShopManager::Sell(LPCHARACTER ch, BYTE bCell, BYTE bCount)

To this:

void CShopManager::Sell(LPCHARACTER ch, BYTE bCell, WORD bCount)
 
shop.h

Search this: typedef struct shop_item

Replace this:

BYTE	count;

To this:

WORD	count;

shop_manager.h

Replace this:

void	Sell(LPCHARACTER ch, BYTE bCell, BYTE bCount=0);

To this:

void	Sell(LPCHARACTER ch, BYTE bCell, WORD bCount=0);

char_item.cpp

Replace this:

bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)

To this:

bool CHARACTER::DropItem(TItemPos Cell, WORD bCount)

Then replace this:

bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)

To this:

bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, WORD count)

And replace this in this function:

count = MIN(200 - item2->GetCount(), count);

To this:

count = MIN(ITEM_MAX_COUNT - item2->GetCount(), count);

Then replace this:

LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bMsg)

To this:

LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, WORD bCount, int iRarePct, bool bMsg)

And replace this in this function:

BYTE bCount2 = MIN(200 - item->GetCount(), bCount);

To this:

WORD bCount2 = MIN(ITEM_MAX_COUNT - item->GetCount(), bCount);

And replace this inside the PickupItem function:

BYTE bCount = item->GetCount();

To this:

WORD bCount = item->GetCount();

And this (still inside this function):

BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);

To this:

WORD bCount2 = MIN(ITEM_MAX_COUNT - item2->GetCount(), bCount);


item.cpp->DWORD CItem::GetCount()

Replace this:

return MIN(m_dwCount, 200);

To this:

return MIN(m_dwCount, ITEM_MAX_COUNT);


safebox.cpp

Replace this:

bool CSafebox::MoveItem(BYTE bCell, BYTE bDestCell, BYTE count)

To this:

bool CSafebox::MoveItem(BYTE bCell, BYTE bDestCell, WORD count)

Then replace this inside this function:

count = MIN(200 - item2->GetCount(), count);

To this:

count = MIN(ITEM_MAX_COUNT - item2->GetCount(), count);

common/item_lenght.h

Here you can set the maximum number in a stack. Change this as big as you want (between 0 and ~60k)

ITEM_MAX_COUNT				= 200,

(I changed this to 300, just for the test)

char.h

Replace this:

bool			DropItem(TItemPos Cell,  BYTE bCount=0);
bool			MoveItem(TItemPos pos, TItemPos change_pos, BYTE num);
LPITEM			AutoGiveItem(DWORD dwItemVnum, BYTE bCount=1, int iRarePct = -1, bool bMsg = true);

To this:

bool			DropItem(TItemPos Cell,  WORD bCount=0);
bool			MoveItem(TItemPos pos, TItemPos change_pos, WORD num);
LPITEM			AutoGiveItem(DWORD dwItemVnum, WORD bCount=1, int iRarePct = -1, bool bMsg = true);


safebox.h

Replace this:

bool		MoveItem(BYTE bCell, BYTE bDestCell, BYTE count);

To this:

bool		MoveItem(BYTE bCell, BYTE bDestCell, WORD count);

oxevent.cpp

Replace this:

bool COXEventManager::GiveItemToAttender(DWORD dwItemVnum, BYTE count)

To this:

bool COXEventManager::GiveItemToAttender(DWORD dwItemVnum, WORD count)

oxevent.h

Replace this:

bool GiveItemToAttender(DWORD dwItemVnum, BYTE count);

With this:

bool GiveItemToAttender(DWORD dwItemVnum, WORD count);

Now we are done with the server, don't foget to build the db and the gamefile too!


database

We have to do 2 more things:

  • Go to the player database, right click on the item table -> desing table, then edit the count column's type from tinyint to smallint and the lenght from 3 to 4.
  • shop_item table->desing table: edit the count column's type from tinyint to smallint

And we are done ;) I also captured the  "progress" like in my "Expand maximum level" topic, its about 40 minutes long again, its not necessary at all to watch it, but if you are interested about the progress, or you just bored and have 40-50 minute freetime, watch it, if you want ;)

Special thanks to TheSLZ for testing the edits.
If you have any problem/remark/question, or you've just found a bug, feel free to tell/ask it here or in PM.

Have a nice day,
~masodikbela

  • Metin2 Dev 135
  • kekw 2
  • Dislove 1
  • Not Good 1
  • Sad 1
  • Cry 1
  • Think 1
  • Confused 2
  • Good 42
  • Love 2
  • Love 124

The one and only UI programming guideline

Link to comment
Share on other sites

  • Premium

Thanks, I love it! ;)

Buuut, what is that TfckOFF?:D

:D I've got a big problem with the "sell packet", (you can see it in the video, about a quarter of this about this problem -.-) And after one hour trying I realized that I should use "struct", so it got this nice name :D

  • Metin2 Dev 1
  • Love 1

The one and only UI programming guideline

Link to comment
Share on other sites

  • Honorable Member

Hmm, I can't watch the video because of my mobile-internet is limited.

But I will test with this:

		case SHOP_SUBHEADER_CG_SELL2:
			{
				if (uiBytes < sizeof(WORD) + sizeof(WORD) + sizeof(BYTE))
					return -1;

				//WORD wPos = *(c_pData);
				const WORD wPos = *reinterpret_cast<const WORD*>(c_pData);//c_pData[0:sizeof(WORD)]
				const WORD wCount = *(c_pData + sizeof(WORD));//c_pData[sizeof(WORD):(2*sizeof(WORD))]
				const BYTE bType = *(c_pData + sizeof(WORD) + sizeof(WORD));//c_pData[(2*sizeof(WORD)):]

				sys_log(0, "INPUT: %s SHOP: SELL2", ch->GetName());
				sys_log(0, "   wPos: %d, wCount: %d, bType: %d", wPos, wCount, bType);
				CShopManager::instance().Sell(ch, wPos, wCount, bType);
				return sizeof(WORD) + sizeof(WORD) + sizeof(BYTE);
			}

Because I implemented the items selling from the DS-Inventory.

  • Metin2 Dev 2
Link to comment
Share on other sites

  • Premium

Well, now I see that my problem was that I just changed the variable type, and I didn't add the size of the word to the "c_pData", so it copied only the size of a "byte", so I couldn't sell more than 255 items in a stack, and if I wanted to, I've got "overflow". Finally, the "struct" solved this problem, but now I know this way too ^^

The one and only UI programming guideline

Link to comment
Share on other sites

  • Premium

What kind of window is this? Maybe its possible, that you have different systems/features than me.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1

The one and only UI programming guideline

Link to comment
Share on other sites

This one is not about stack problem. I have before same one but I don't remember what was it:/ What do you changed last time? Probably problem is about more slots in shops :) Regards. Check again if you do corectly all files...

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • 3 weeks later...
  • Premium
On 11/8/2015 at 8:48 PM, Kamylek said:

.gif

 

With shops everything is okey...

I still don't know what kind of window is that. Its possible, that windows in connection with belt system/dragon soul system won't work properly, because I not use any of them, so I didn't tested them.

  • Metin2 Dev 2

The one and only UI programming guideline

Link to comment
Share on other sites

On 11/8/2015 at 8:56 PM, masodikbela said:
On 11/8/2015 at 8:48 PM, Kamylek said:

.gif

 

With shops everything is okey...

I still don't know what kind of window is that. Its possible, that windows in connection with belt system/dragon soul system won't work properly, because I not use any of them, so I didn't tested them.

Every shop(not player shop) i open looks like on ss

  • Metin2 Dev 1
  • Lmao 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...
  • Management

Hello,

When I buy something from a shop, I just have packs 50, but when I click to buy the client blocks and or close or goes back to the login part, when I login in again 1074 itens on my inventory...

How do I resolve this?

Thanks

Kind regards,

charparodar

EDIT: #RemoveThisPost

#ProblemSolved

I was missing just 1 part <.<

Edited by charparodar
Problem Solved
  • Metin2 Dev 1
  • Think 1
  • Lmao 1

raw

raw

Link to comment
Share on other sites

  • 7 months later...
  • 3 months later...

Announcements



×
×
  • 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.