Doubt you guys can help me...

Results 1 to 7 of 7
  1. #1
    Mako is insane. ThePhailure772 is offline
    MemberRank
    Sep 2007 Join Date
    1,115Posts

    Doubt you guys can help me...

    So, I'm currently working on my emulator. On the Match.ResponseCharItemList packet, the client is acting like I'm sending only the inventory. It's saying I have /nothing/ equipped, except when I'm at character select screen. That works fine.. Here's the code:

    Item Structure:
    Code:
        public class Item
        {
            public Int32 nItemCID = 0;
            public Int32 nItemID = 0;
            public Int32 nRentHour = 0;
            public Int32 nPrice = 0;
            public byte nSex = 0;
            public byte nLevel = 0;
        }
    Code:
            public static void ResponseCharItemList(Client client, Packet packet)
            {
                MUID uidChar = new MUID();
                
                if (!packet.Read(ref uidChar))
                {
                    Log.Write("ResponseCharItemList", "Invalid Packet.");
                    client.Disconnect();
                    return;
                }
    
                packet = new Packet(Operation.MatchResponseCharacterItemList, PacketVersion.Decrypted, client.m_bPacketCount);
                packet.Write(client.CharInfo.nBP);
    
                packet.Write(8, 12);
                foreach (UInt64 nItem in client.CharInfo.nEquippedItems)
                {
                    Log.Write("ResponseCharItemList", "Found Equipped Item: {0}", nItem);
                    packet.Write(nItem);
                }
    
                
                packet.Write(16, client.CharInfo.nItems.Count);
                foreach (Item item in client.CharInfo.nItems)
                {
                    packet.Write((Int32)0);
                    packet.Write(item.nItemCID);
                    packet.Write(item.nItemID);
                    packet.Write(item.nRentHour);
                    Log.Write("ResponseCharItems", "Found Inventory Item: {0}", item.nItemID); 
                }
                
                packet.Finalize(client.m_bCrypt);
                client.Send(packet.getPacket());
            }
    Console output:
    Code:
    [8/16/2009 3:08:37 PM] | Recieve | Recieved Packet: MatchRequestCharacterItemList
    [8/16/2009 3:08:37 PM] | Recieve | Recieved Packet: 1422
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 520501
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 521501
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 522501
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 523501
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 524501
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 0
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 0
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 1
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 454
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 455
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 0
    [8/16/2009 3:08:37 PM] | ResponseCharItemList | Found Equipped Item: 0
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 1
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 24502
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 3
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 1
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 7
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 2
    [8/16/2009 3:08:37 PM] | ResponseCharItems | Found Inventory Item: 265
    Last edited by ThePhailure772; 16-08-09 at 09:14 PM.


  2. #2
    Proficient Member -Lambda- is offline
    MemberRank
    Jan 2007 Join Date
    SpainLocation
    157Posts

    Re: Doubt you guys can help me...

    I think is something wrong with the Blob Arrays

    Here is my item listing function, it works perfectly.

    Code:
    bool MMatchServer::ResponseCharacterItemList( MUID& uidPlayer )
    {
        MMatchObject* pMatchObject = GetObject( uidPlayer );
    
        if( pMatchObject && pMatchObject->m_pCharInfo )
        {
            if( !m_MatchDBMgr.GetCharItemInfo( pMatchObject->m_pCharInfo ) )
            {
                MLog( "DB Query(ResponseCharacterItemList > GetCharItemInfo) Failed" );
                return false;
            }
    
            MCommand* pCmd = CreateCommand( MATCH_RESPONSECHARACTERITEMLIST, uidPlayer );
    
            if( pCmd )
            {
                pCmd->AddParameter( new MCommandParameterUInt( pMatchObject->m_pCharInfo->m_nBP ) );
    
                void* pArray = MMakeBlobArray( sizeof( MTD_ItemNode ), 12 );
    
                for( int i = 0; i != 12; i++ )
                {
                    MTD_ItemNode Item;
                    MMatchItem* pItem = pMatchObject->m_pCharInfo->m_EquipedItem.GetItem( (MMatchCharItemParts)i );
    
                    if( pItem )
                    {
                        Item.nItemID = pItem->m_pDesc->m_nID;
                        Item.uidItem = pItem->m_uidItem;
                    }else{
                        Item.nItemID = 0;
                        Item.uidItem = MUID( 0, 0 );
                    }
    
                    memcpy( MGetBlobArrayElement( pArray, i ), &Item, sizeof( MTD_ItemNode ) );
                }
    
                pCmd->AddParameter( new MCommandParameterBlob( pArray, MGetBlobArraySize( pArray ) ) );
    
                MEraseBlobArray( pArray );
    
                pArray = MMakeBlobArray( sizeof( MTD_ItemNode ), pMatchObject->m_pCharInfo->m_ItemList.size() );
    
                map<MUID, MMatchItem*>::iterator it = pMatchObject->m_pCharInfo->m_ItemList.begin();
    
                for( int i = 0; it != pMatchObject->m_pCharInfo->m_ItemList.end(); it++, i++ )
                {
                    MMatchItem* pItem = (*it).second;
    
                    if( !pItem )
                        continue;
    
                    MTD_ItemNode Item;
    
                    Item.nItemID = pItem->m_pDesc->m_nID;
                    Item.uidItem = pItem->m_uidItem;
    
                    memcpy( MGetBlobArrayElement( pArray, i ), &Item, sizeof( MTD_ItemNode ) );
                }
    
                pCmd->AddParameter( new MCommandParameterBlob( pArray, MGetBlobArraySize( pArray ) ) );
    
                MEraseBlobArray( pArray );
    
                RouteToListener( pMatchObject, pCmd );
    
                return true;
            }
        }
    
        return false;
    }
    Also remember that the blob arrays are 8 bytes lenght, the first 4 bytes is the element size and the last 4 bytes the element count.

    Code:
    void* MMakeBlobArray( int nOneBlobSize, int nBlobCount )
    {
    	unsigned char* pArray = new unsigned char[ nOneBlobSize * nBlobCount + 8 ];
    
    	*(int*)( pArray )			= nOneBlobSize;
    	*(int*)( pArray + 4 )		= nBlobCount;
    
    	return pArray;
    }
    
    void* MGetBlobArrayElement( void* pBlob, int nIndex )
    {
    	if( nIndex < 0 || nIndex > *(int*)( (unsigned char*)pBlob + 4 ) )
    		return NULL;
    
    	return (unsigned char*)pBlob + nIndex * *(int*)( pBlob ) + 8;
    }
    
    int MGetBlobArraySize( void* pBlob )
    {
    	return *(int*)(unsigned char*)pBlob * *(int*)( (unsigned char*)pBlob + 4 ) + 8;
    }
    
    int MGetBlobArrayCount( void* pBlob )
    {
    	return *(int*)( (unsigned char*)pBlob + 4 ); 
    }
    
    void MEraseBlobArray( void* pBlob )
    {
    	delete [] pBlob;
    }
    Last edited by -Lambda-; 16-08-09 at 09:20 PM.

  3. #3
    Mako is insane. ThePhailure772 is offline
    MemberRank
    Sep 2007 Join Date
    1,115Posts

    Re: Doubt you guys can help me...

    Code:
            public void Write(int pSize, int pCount)
            {
                int size = 8 + (pSize * pCount);
                Write(size);
                Write(pSize);
                Write(pCount);
                Increase(pSize * pCount);
            }
    Blobs are correct, I've already tested that.

    Packet:
    [code]
    64 00 F7 00 7D 0A F1 00 1E 07 09 00 00 00 00 68 d.
    Last edited by ThePhailure772; 16-08-09 at 09:23 PM.

  4. #4
    Proficient Member -Lambda- is offline
    MemberRank
    Jan 2007 Join Date
    SpainLocation
    157Posts

    Re: Doubt you guys can help me...

    Quote Originally Posted by Theoretical View Post
    Code:
            public void Write(int pSize, int pCount)
            {
                int size = 8 + (pSize * pCount);
                Write(size);
                Write(pSize);
                Write(pCount);
                Increase(pSize * pCount);
            }
    Blobs are correct, I've already tested that.

    Didn't know that the Write function does the blob handling.

    Btw, how C# handles the structure packing? is 1 byte aligned, 4 bytes...

  5. #5
    much coder t0p lel Team Zebra is offline
    MemberRank
    Mar 2009 Join Date
    234Posts

    Re: Doubt you guys can help me...

    He just overloaded the Write function to handle the data according to its type.

  6. #6
    Mako is insane. ThePhailure772 is offline
    MemberRank
    Sep 2007 Join Date
    1,115Posts

    Re: Doubt you guys can help me...

    Quote Originally Posted by -Lambda- View Post
    Didn't know that the Write function does the blob handling.

    Btw, how C# handles the structure packing? is 1 byte aligned, 4 bytes...
    I haven't had any issues with structure packing because I mainly write the paramaters on my own.

  7. #7
    Proficient Member -Lambda- is offline
    MemberRank
    Jan 2007 Join Date
    SpainLocation
    157Posts

    Re: Doubt you guys can help me...

    Quote Originally Posted by Team Zebra View Post
    He just overloaded the Write function to handle the data according to its type.
    Yes, i know but i didn't know that the overload exists, this is because i have doubt about the blob thing.

    Also, no idea because is not showing the equiped items, right now i haven't sleep for like 20h so dont expect awesome responses XD



Advertisement