Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More drive-by cleanup #122

Merged
merged 9 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions source/D2CommonDefinitions/include/D2Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ enum D2C_Acts

#endif // CONSTANTS_LEVELS



enum D2C_ClientStates
{
CLTSTATE_CONNECTED = 4
};

enum D2SaveCharType
{
CHARTYPE_HARDCORE = 0x24,
Expand Down
37 changes: 23 additions & 14 deletions source/D2CommonDefinitions/include/D2PacketDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,21 @@ struct D2GSPacketClt31 //size of 0x09
int32_t unk0x01[2]; //0x01
};

enum D2TransactionMode : uint32_t {
TRANSACTIONMODE_BUY = 0,
TRANSACTIONMODE_GAMBLE = 2,
TRANSACTIONMODE_FILL = 0x80000000
};
AudriusButkevicius marked this conversation as resolved.
Show resolved Hide resolved

struct D2GSPacketClt32 //size of 0x11
{
uint8_t nHeader; //0x00
int32_t unk0x01; //0x01
int32_t unk0x05; //0x05
uint16_t unk0x09; //0x09
uint16_t unk0x0B; //0x0B
int32_t unk0x0D; //0x0D
uint8_t nHeader; //0x00
int32_t dwUnitGUID; //0x01
AudriusButkevicius marked this conversation as resolved.
Show resolved Hide resolved
int32_t dwItemGUID; //0x05
D2TransactionMode dwTransactionMode; //0x09
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given:

return D2GAME_NPC_BuyItemHandler_6FCC92A0(pGame, pUnit, *(int32_t*)((char*)pPacket + 1), *(int32_t*)((char*)pPacket + 5), (*(int32_t*)((char*)pPacket + 9) & INT_MAX) >> 16, *(int32_t*)((char*)pPacket + 9), *(int32_t*)((char*)pPacket + 13), *(int32_t*)((char*)pPacket + 9) & 0x80000000);

This field is a bit more interesting, as sometimes it reads just the top bit, sometimes, the 15 upper bits minus the top one, sometimes the whole thing, however I think making struct/union/bitstruct for this might be annoying.

Copy link
Member

@Lectem Lectem Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to have a union or at least helper functions in this case. After a quick look I think those 4 bytes pack the following information:

  • Transaction type bits 0 - 15 (enum should be in D2Common, as it must be used in ITEMS_CalculateTransactionCost)
  • Something related to max cost for item transaction ? Seems to mostly be used with value of 0. ItemMode, but should always be 0? bits 16-30
  • Fill item (book, pots, scrolls...) bit 31

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transaction types are:

  • 0 buy
  • 1 sell
  • 2 gamble
  • 3 repair

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that is correct, as its a buy packet, so sell doesn't make sense. I also assumed there is a separate repair packet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to be fair, values 1 and 3 are unused, but the field is converted and used as transaction type, which may hold any of the 4 values mentioned above.
I suppose we could have a specific enum for the packet, then cast to the real transaction type enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the issue of the packing, I just checked and it's packed because they use the same function for all packets of size 0x11 (D2Client.0x6FAADAA0) which takes 4 DWORD params.

For reference here is how it is computed:

        nPackedTransationInfo = (unsigned __int16)nItemAnimMode << 16;
        if ( gbVendorGamble_6FBB5D7C )
            nPackedTransationInfo |= 2u;
        if ( (nKeys & 4) != 0 )                 // is Shift held
        {
            nClassId = pItem ? pItem->dwClassId : -1;
            pItemRecord = D2COMMON_10600_GetItemTxtRecord(nClassId);
            if ( pItemRecord )
            {
                if ( pItemRecord->nMultibuy )
                    nPackedTransationInfo |= 0x80000000;
            }
        }
        D2CLIENT_PACKETS_SendPacketSize17_6FAADAA0(
            0x32,
            gnActiveNpcGUID_6FBB5CF5,
            dword_13E25BD5,
            nPackedTransationInfo,
            a5);

int32_t dwCost; //0x0D
};
static_assert(sizeof(D2GSPacketClt32) == 0x11, "size mismatch");

struct D2GSPacketClt33 //size of 0x11
{
Expand Down Expand Up @@ -383,8 +389,8 @@ struct D2GSPacketClt44 //size of 0x11
struct D2GSPacketClt45 //size of 0x09
{
uint8_t nHeader; //0x00
int32_t unk0x01; //0x01
int32_t unk0x05; //0x05
int32_t nPortalGUID; //0x01
int32_t nLevelId; //0x05
};

//TODO: 0x46 - 0x48
Expand All @@ -393,7 +399,7 @@ struct D2GSPacketClt49 //size of 0x09
{
uint8_t nHeader; //0x00
int32_t nWaypointGUID; //0x01
int32_t unk0x05; //0x05
int32_t nLevelId; //0x05
};

//TODO: 0x4A - 0x4E
Expand Down Expand Up @@ -433,7 +439,10 @@ struct D2GSPacketClt58 //size of 0x03
struct D2GSPacketClt59 //size of 0x11
{
uint8_t nHeader; //0x00
int32_t unk0x01[4]; //0x01
uint32_t nUnitType; //0x01
uint32_t dwUnitGUID; //0x05
uint32_t dwTargetX; //0x09
uint32_t dwTargetY; //0x0D
};

//TODO: 0x5A - 0x5C
Expand All @@ -450,7 +459,7 @@ struct D2GSPacketClt5E //size of 0x06
{
uint8_t nHeader; //0x00
uint8_t nType; //0x01
int32_t unk0x02; //0x02
int32_t dwPlayerGUID; //0x02
};

struct D2GSPacketClt5F
Expand Down Expand Up @@ -484,10 +493,10 @@ struct D2GSPacketClt66 //size of 0x2E
{
uint8_t nHeader; //0x00
char szGameName[16]; //0x01
uint8_t bSkipVerification; //0x11
uint8_t nGameType; //0x11
uint8_t nPlayerClass; //0x12
int8_t unk0x13; //0x13
int8_t unk0x14; //0x14
int8_t nTemplate; //0x13
int8_t nDifficulty ; //0x14
char szClientName[16]; //0x15
int16_t unk0x25; //0x25
uint32_t nGameFlags; //0x27
Expand Down
2 changes: 1 addition & 1 deletion source/D2Game/src/GAME/CCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void __fastcall CCMD_ProcessClientSystemMessage(void* pData, int32_t nSize)
D2GSPacketClt66* pPacket66 = (D2GSPacketClt66*)pPacket;
if (GAME_VerifyCreateNewGame(nClientId, pPacket66))
{
GAME_SendGameInit(nClientId, pPacket66->szGameName, pPacket66->bSkipVerification, pPacket66->nPlayerClass, pPacket66->szClientName, pPacket66->unk0x25, pPacket66->nGameFlags, pPacket66->unk0x13, pPacket66->unk0x2B, pPacket66->unk0x2C, pPacket66->unk0x14, pPacket66->nLocale, 0, 0);
GAME_SendGameInit(nClientId, pPacket66->szGameName, pPacket66->nGameType, pPacket66->nPlayerClass, pPacket66->szClientName, pPacket66->unk0x25, pPacket66->nGameFlags, pPacket66->nTemplate, pPacket66->unk0x2B, pPacket66->unk0x2C, pPacket66->nDifficulty, pPacket66->nLocale, 0, 0);
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions source/D2Game/src/GAME/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void __fastcall GAME_ResolveGameNameConflict(D2GameStrc* pGameToSanitize, char*
//D2Game.0x6FC35CB0
int32_t __fastcall GAME_VerifyCreateNewGame(int32_t nClientId, D2GSPacketClt66* pPacket)
{
if (gpD2ServerCallbackFunctions_6FD45830 && pPacket->bSkipVerification)
if (gpD2ServerCallbackFunctions_6FD45830 && pPacket->nGameType)
{
return 0;
}
Expand Down Expand Up @@ -1386,7 +1386,7 @@ void __fastcall GAME_DisconnectClient(D2GameStrc* pGame, D2ClientStrc* pClient,
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nType = nEventType;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;
packet5A.dwParam = 0;
CLIENTS_CopyAccountNameToBuffer(pClient, &packet5A.szText[16]);
packet5A.szText[31] = '\0';
Expand Down Expand Up @@ -1508,7 +1508,7 @@ void __stdcall D2Game_10024_RemoveClientFromGame(int32_t nClientId)
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_DISCONNECT;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;
packet5A.dwParam = 0;
packet5A.szText[16] = 0;
SStrCopy(packet5A.szText, CLIENTS_GetName(pClient), 16u);
Expand Down Expand Up @@ -1705,7 +1705,7 @@ void __fastcall GAME_EndGame(int32_t nClientId, int32_t a2)
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_PLAYERLEFT;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;
packet5A.dwParam = 0;
CLIENTS_CopyAccountNameToBuffer(pClient, &packet5A.szText[16]);
packet5A.szText[31] = '\0';
Expand Down Expand Up @@ -2254,7 +2254,7 @@ void __fastcall D2GAME_UpdateAllClients_6FC389C0(D2GameStrc* pGame)
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5A;
packet5A.nType = EVENTTYPE_PLAYERJOIN;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;
packet5A.dwParam = 0;
packet5A.szText[16] = '\0';

Expand Down Expand Up @@ -3649,7 +3649,7 @@ void __stdcall D2Game_10021(int32_t a1, int32_t nPacketParam, const char* szMess
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_REALMGOINGDOWN;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;
packet5A.dwParam = nPacketParam;
packet5A.szText[16] = 0;
sub_6FC84D40(pGame, &packet5A);
Expand Down
28 changes: 15 additions & 13 deletions source/D2Game/src/PLAYER/PlrMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ int32_t __fastcall sub_6FC83340(D2GameStrc* pGame, D2UnitStrc* pUnit, D2SkillStr
{
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nColor = 1;
packet5A.nColor = STRCOLOR_RED;
packet5A.dwParam = 0;
packet5A.nType = EVENTTYPE_CANTDOTHAT;
D2GAME_PACKETS_SendPacket0x5A_6FC3DEC0(SUNIT_GetClientFromPlayer(pUnit, __FILE__, __LINE__), &packet5A);
Expand Down Expand Up @@ -1714,7 +1714,7 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x15_HandleChatMessage_6FC84950(D2Ga

packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_NOTLISTENINGTOYOU;
packet5A.nColor = 0;
packet5A.nColor = STRCOLOR_WHITE;
packet5A.dwParam = 0;
SStrCopy(packet5A.szText, packet15.szName, INT_MAX);
packet5A.szText[15] = 0;
Expand All @@ -1728,7 +1728,7 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x15_HandleChatMessage_6FC84950(D2Ga

packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_NOTINGAME;
packet5A.nColor = 0;
packet5A.nColor = STRCOLOR_WHITE;
packet5A.dwParam = 0;
SStrCopy(packet5A.szText, packet15.szName, INT_MAX);
packet5A.szText[15] = 0;
Expand Down Expand Up @@ -1964,7 +1964,7 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x19_RemoveItemFromBuffer_6FC850C0(D
{
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5A;
packet5A.nColor = 1;
packet5A.nColor = STRCOLOR_RED;
packet5A.dwParam = 0;
packet5A.nType = EVENTTYPE_CANTDOTHAT;
D2GAME_PACKETS_SendPacket0x5A_6FC3DEC0(SUNIT_GetClientFromPlayer(pUnit, __FILE__, __LINE__), &packet5A);
Expand Down Expand Up @@ -3272,8 +3272,10 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x45_ChangeTpLocation_6FC87930(D2Gam
return 3;
}

const int32_t nPortalGUID = *(int32_t*)((char*)pPacket + 1);
const uint16_t nLevelId = *(uint16_t*)((char*)pPacket + 5);
D2GSPacketClt45* pPacket45 = (D2GSPacketClt45*)pPacket;

const int32_t nPortalGUID = pPacket45->nPortalGUID;
const uint16_t nLevelId = pPacket45->nLevelId;
D2UnitStrc* pPortal = SUNIT_GetServerUnit(pGame, UNIT_OBJECT, nPortalGUID);
if (pPortal)
{
Expand Down Expand Up @@ -3432,13 +3434,13 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x49_TakeOrCloseWp_6FC87E60(D2GameSt
return 1;
}

if (!pPacket49->unk0x05)
if (!pPacket49->nLevelId)
{
D2GAME_WAYPOINT_Unk_6FC79600(pGame, pUnit, pPacket49->nWaypointGUID, pPacket49->unk0x05);
D2GAME_WAYPOINT_Unk_6FC79600(pGame, pUnit, pPacket49->nWaypointGUID, pPacket49->nLevelId);
return 0;
}

if (pPacket49->unk0x05 >= sgptDataTables->nLevelsTxtRecordCount)
if (pPacket49->nLevelId >= sgptDataTables->nLevelsTxtRecordCount)
{
nResult = 3;
}
Expand All @@ -3449,15 +3451,15 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x49_TakeOrCloseWp_6FC87E60(D2GameSt
D2_ASSERT(pPlayerData);

int16_t nWaypointNo = 0;
if (!WAYPOINTS_GetWaypointNoFromLevelId(pPacket49->unk0x05, &nWaypointNo))
if (!WAYPOINTS_GetWaypointNoFromLevelId(pPacket49->nLevelId, &nWaypointNo))
{
nResult = 3;
}
else
{
if (WAYPOINTS_IsActivated(pPlayerData->pWaypointData[pGame->nDifficulty], nWaypointNo))
{
D2GAME_WAYPOINT_Unk_6FC79600(pGame, pUnit, pPacket49->nWaypointGUID, pPacket49->unk0x05);
D2GAME_WAYPOINT_Unk_6FC79600(pGame, pUnit, pPacket49->nWaypointGUID, pPacket49->nLevelId);
return 0;
}

Expand Down Expand Up @@ -4123,7 +4125,7 @@ int32_t __fastcall D2GAME_PACKETCALLBACK_Rcv0x63_ShiftLeftClickItemToBelt_6FC88F
{
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nColor = 1;
packet5A.nColor = STRCOLOR_RED;
packet5A.dwParam = 0;
packet5A.nType = EVENTTYPE_CANTDOTHAT;
D2GAME_PACKETS_SendPacket0x5A_6FC3DEC0(SUNIT_GetClientFromPlayer(pUnit, __FILE__, __LINE__), &packet5A);
Expand Down Expand Up @@ -4367,7 +4369,7 @@ void __fastcall D2GAME_PLRMSG_Last_6FC89450(D2GameStrc* pGame, D2UnitStrc* pAtta
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5Au;
packet5A.nType = EVENTTYPE_SLAIN_BY;
packet5A.nColor = 4;
packet5A.nColor = STRCOLOR_DARK_GOLD;

if (pPlayer)
{
Expand Down
2 changes: 1 addition & 1 deletion source/D2Game/src/PLAYER/PlrTrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ void __fastcall PLRTRADE_SendEventPacketToPlayer(D2UnitStrc* pPlayer, D2C_SRV2CL
D2GSPacketSrv5A packet5A = {};
packet5A.nHeader = 0x5A;
packet5A.nType = nType;
packet5A.nColor = 0;
packet5A.nColor = STRCOLOR_WHITE;
packet5A.dwParam = 0;

if (szSource)
Expand Down