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

[WIP] remove mpq reading/stormlib dependency #105

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 2 additions & 10 deletions BH/BH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include "D2Intercepts.h"
#include "D2Handlers.h"
#include "Modules.h"
#include "MPQReader.h"
#include "MPQInit.h"
#include "TableReader.h"
#include "Task.h"

string BH::path;
Expand Down Expand Up @@ -40,6 +38,7 @@ Patch* patches[] = {
new Patch(Call, D2MULTI, { 0x10781, 0x14A9A }, (int)ChannelWhisper_Interception, 5),
new Patch(Jump, D2MULTI, { 0x108A0, 0x14BE0 }, (int)ChannelChat_Interception, 6),
new Patch(Jump, D2MULTI, { 0x107A0, 0x14850 }, (int)ChannelEmote_Interception, 6),
new Patch(Call, D2COMMON, { 0x66340, 0x0 }, (int)MPQDataLoaded_Interception, 6),
};

Patch* BH::oogDraw = new Patch(Call, D2WIN, { 0x18911, 0xEC61 }, (int)OOGDraw_Interception, 5);
Expand Down Expand Up @@ -83,9 +82,7 @@ DWORD WINAPI LoadMPQData(VOID* lpvoid){
}
}

ReadMPQFiles(patchPath);
InitializeMPQData();
Tables::initTables();

return 0;
}
Expand Down Expand Up @@ -122,12 +119,7 @@ void BH::Initialize()
Task::InitializeThreadPool(2);

// Read the MPQ Data asynchronously
//CreateThread(0, 0, LoadMPQData, 0, 0, 0);
Task::Enqueue([]() -> void {
LoadMPQData(NULL);
moduleManager->MpqLoaded();
});



new ScreenInfo();
new Gamefilter();
Expand Down
6 changes: 1 addition & 5 deletions BH/BH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;shlwapi.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;StormLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>kernel32.lib;shlwapi.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
</Link>
Expand Down Expand Up @@ -173,11 +173,9 @@ if defined D2Path (
<ClCompile Include="Modules\Party\Party.cpp" />
<ClCompile Include="Modules\ScreenInfo\ScreenInfo.cpp" />
<ClCompile Include="MPQInit.cpp" />
<ClCompile Include="MPQReader.cpp" />
<ClCompile Include="Mustache.cpp" />
<ClCompile Include="Patch.cpp" />
<ClCompile Include="Modules\StashExport\StashExport.cpp" />
<ClCompile Include="TableReader.cpp" />
<ClCompile Include="Task.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -234,11 +232,9 @@ if defined D2Path (
<ClInclude Include="Modules\Party\Party.h" />
<ClInclude Include="Modules\ScreenInfo\ScreenInfo.h" />
<ClInclude Include="MPQInit.h" />
<ClInclude Include="MPQReader.h" />
<ClInclude Include="Mustache.h" />
<ClInclude Include="Patch.h" />
<ClInclude Include="Modules\StashExport\StashExport.h" />
<ClInclude Include="TableReader.h" />
<ClInclude Include="Task.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
4 changes: 0 additions & 4 deletions BH/BH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
<ClCompile Include="Modules\Party\Party.cpp" />
<ClCompile Include="Modules\ScreenInfo\ScreenInfo.cpp" />
<ClCompile Include="MPQInit.cpp" />
<ClCompile Include="MPQReader.cpp" />
<ClCompile Include="Mustache.cpp" />
<ClCompile Include="Patch.cpp" />
<ClCompile Include="Modules\StashExport\StashExport.cpp" />
<ClCompile Include="TableReader.cpp" />
<ClCompile Include="Task.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -101,11 +99,9 @@
<ClInclude Include="Modules\Party\Party.h" />
<ClInclude Include="Modules\ScreenInfo\ScreenInfo.h" />
<ClInclude Include="MPQInit.h" />
<ClInclude Include="MPQReader.h" />
<ClInclude Include="Mustache.h" />
<ClInclude Include="Patch.h" />
<ClInclude Include="Modules\StashExport\StashExport.h" />
<ClInclude Include="TableReader.h" />
<ClInclude Include="Task.h" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions BH/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,40 @@ enum D2_VideoMode {
VIDEO_MODE_DIRECT3D,
VIDEO_MODE_RAVE
};

enum InventoryTxtRows
{
INV_REC_AMAZON = 0,
INV_REC_SORCERESS,
INV_REC_NECROMANCER,
INV_REC_PALADIN,
INV_REC_BARB,
INV_REC_MONSTER,
INV_REC_TRADE_I,
INV_REC_TRADE_II,
INV_REC_BANK,
INV_REC_CUBE,
INV_REC_GUILD_VAULT,
INV_REC_TROPY_CASE,
INV_REC_BIG_BANK,
INV_REC_HIRELING,
INV_REC_DRUID,
INV_REC_ASSASSIN,
//--Expansion
INV_REC_EXP_AMAZON = 16,
INV_REC_EXP_SORCERESS,
INV_REC_EXP_NECROMANCER,
INV_REC_EXP_PALADIN,
INV_REC_EXP_BARB,
INV_REC_EXP_MONSTER,
INV_REC_EXP_TRADE_I,
INV_REC_EXP_TRADE_II,
INV_REC_EXP_BANK,
INV_REC_EXP_CUBE,
INV_REC_EXP_GUILD_VAULT,
INV_REC_EXP_TROPY_CASE,
INV_REC_EXP_BIG_BANK,
INV_REC_EXP_HIRELING,
INV_REC_EXP_DRUID,
INV_REC_EXP_ASSASSIN
};
105 changes: 75 additions & 30 deletions BH/D2DataTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ struct AutoMagicTxt
struct UniqueItemsTxt
{
WORD _1; //0x00
char szName[34]; //0x02
DWORD dwVersion; //0x24
char szName[32]; //0x02
WORD wTblIndex; //0x22
DWORD wVersion; //0x24
union
{
DWORD dwCode;
Expand All @@ -166,13 +167,14 @@ struct SetItemsTxt
WORD wSetItemId; //0x00
char szName[32]; //0x02
WORD _1; //0x22
DWORD dwTblIndex; //0x24
WORD wTblIndex; //0x24
WORD _2; //0x24
union
{
DWORD dwCode;
char szCode[4];
}; //0x28
DWORD _2; //0x2C
DWORD _3; //0x2C
WORD wLvl; //0x30
WORD wLvlReq; //0x32
DWORD dwRarity; //0x34
Expand All @@ -190,6 +192,22 @@ struct SetItemsTxt
ItemsTxtStat hGreenStats[10]; //0x118
};

struct SetsTxt
{
WORD wSetId; //0x00
WORD wStringId; //0x02
WORD wVersion; //0x04
WORD pad0x06; //0x06
DWORD unk0x08; //0x08
DWORD nSetItems; //0x0C
ItemsTxtStat pBoni2[2]; //0x10
ItemsTxtStat pBoni3[2]; //0x30
ItemsTxtStat pBoni4[2]; //0x50
ItemsTxtStat pBoni5[2]; //0x70
ItemsTxtStat pFBoni[8]; //0x90
SetItemsTxt* pSetItem[6]; //0x110
};

struct RunesTxt
{
char szName[64]; //0x00
Expand Down Expand Up @@ -237,20 +255,7 @@ struct PetTypesTxt
Isn't simpler now?
*/

struct InventoryLayout {
BYTE SlotWidth;
BYTE SlotHeight;
BYTE unk1;
BYTE unk2;
DWORD Left;
DWORD Right;
DWORD Top;
DWORD Bottom;
BYTE SlotPixelWidth;
BYTE SlotPixelHeight;
};
/*
struct InventoryLayout //sizeof 0x14
struct InventoryLayout //sizeof 0x14
{
DWORD dwLeft; //0x00
DWORD dwRight; //0x04
Expand All @@ -272,7 +277,7 @@ struct InventoryLayout {
WORD _align; //0x12
};

struct InventoryTxt //sizeof 0xF0
struct InventoryTxt //sizeof 0xF0
{
InventoryLayout Inventory; //0x00
InventoryLayout Grid; //0x14
Expand All @@ -293,7 +298,7 @@ struct InventoryLayout {
};
InventoryLayout hItem[9];
};
};*/
};

struct BeltBox
{
Expand Down Expand Up @@ -539,6 +544,20 @@ struct ItemStatCostTxt //size 0x144
BYTE _Stuff[230]; //0x5E
};


struct ItemTypesTxt { //size 0xE4
CHAR szCode[0x4]; //0x00
WORD wEquiv[0x2]; //0x04
BYTE bRepair; //0x08
BYTE bBody; //0x09
BYTE bBodyLoc[0x2]; //0x10
WORD wShoots; //0x12
WORD wQuiver; //0x14
BYTE bThrowable; //0x16
//can mostly be inferred from txt file, we dont use any of the other fields though
BYTE _Unk[0xD3]; //0x17
};

struct MissilesTxt
{
DWORD dwId; //0x00
Expand Down Expand Up @@ -1359,6 +1378,32 @@ struct SkillDescTxt
DWORD dwDescCalcB[17]; //0xDC
};

struct TxtLinkNodeStrc
{
char szText[32]; //0x00
int nLinkIndex; //0x20
TxtLinkNodeStrc* pPrevious; //0x24
TxtLinkNodeStrc* pNext; //0x28
};

struct TxtLinkTblStrc
{
union
{
char szCode[4]; //0x00
DWORD dwCode; //0x00
};
int nLinkIndex; //0x04
};

struct TxtLinkStrc
{
DWORD nRecords; //0x00
DWORD nAllocatedCells; //0x04
TxtLinkTblStrc* pTbl; //0x08
TxtLinkNodeStrc* pFirstNode; //0x0C
};

#pragma pack(pop)

struct ItemsTxt //size = 0x1A8, Valid for Weapons, Armors, Misc.txts
Expand All @@ -1371,10 +1416,10 @@ struct ItemsTxt //size = 0x1A8, Valid for Weapons, Armors, Misc.txts
DWORD dwcode; //0x80
char szcode[4]; //0x80
};
DWORD dwnormcode; //0x84
DWORD dwubercode; //0x88
DWORD dwultracode; //0x8C
DWORD dwalternategfx; //0x90
char sznormcode[4]; //0x84
char szubercode[4]; //0x88
char szultracode[4]; //0x8C
char szalternategfx[4]; //0x90
DWORD dwpSpell; //0x94
WORD wstate; //0x98
WORD wcstate1; //0x9A
Expand All @@ -1389,10 +1434,10 @@ struct ItemsTxt //size = 0x1A8, Valid for Weapons, Armors, Misc.txts
WORD bspelldesc; //0xB4
WORD wspelldescstr; //0xB6
DWORD dwspelldesccalc; //0xB8
DWORD dwBetterGem; //0xBC
char szBetterGem[4]; //0xBC
DWORD dwwclass; //0xC0
DWORD dw2handedwclass; //0xC4
DWORD dwTMogType; //0xC8
char szTMogType[4]; //0xC8
DWORD dwminac; //0xCC
DWORD dwmaxac; //0xD0
DWORD dwgamblecost; //0xD4
Expand Down Expand Up @@ -1686,8 +1731,8 @@ struct sgptDataTable {
DWORD dwOverlayRecs; //0xBC0
CharStatsTxt* pCharStatsTxt; //0xBC4
DWORD dwCharsStatsRecs; //0xBC8
ItemStatCostTxt*pItemStatCostTxt;//0xBCC
BYTE* pItemStatCost; //0xBD0
ItemStatCostTxt*pItemStatCostTxt; //0xBCC
TxtLinkStrc* pItemStatCostLink; //0xBD0
DWORD dwItemStatCostRecs; //0xBD4
BYTE* pOpStatNesting; //0xBD8
DWORD dwOpStatNestingRecs; //0xBDC
Expand All @@ -1697,12 +1742,12 @@ struct sgptDataTable {
BYTE* pPetTypes; //0xBEC
DWORD dwPetTypesRecs; //0xBF0
BYTE* pItemsType; //0xBF4
BYTE* pItemsTypeTxt; //0xBF8
ItemTypesTxt* pItemsTypeTxt; //0xBF8
DWORD dwItemsTypeRecs; //0xBFC
DWORD dwItemsTypeNesting; //0xC00
BYTE* pItemsTypeNesting; //0xC04
BYTE* pSets; //0xC08
BYTE* pSetsTxt; //0xC0C
SetsTxt* pSetsTxt; //0xC0C
DWORD dwSetsRecs; //0xC10
BYTE* pSetItems; //0xC14
SetItemsTxt* pSetItemsTxt; //0xC18
Expand Down
11 changes: 11 additions & 0 deletions BH/D2Intercepts.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "D2Handlers.h"
#include "D2Ptrs.h"
#include "MPQInit.h"

VOID __declspec(naked) GameDraw_Interception()
{
Expand Down Expand Up @@ -222,4 +223,14 @@ void __declspec(naked) ChannelEmote_Interception(void)
SkipChat:
ret 8
}
}

void __declspec(naked) MPQDataLoaded_Interception(void)
{
__asm
{
call InitializeMPQData
add esp, 0x10c
ret 0x0c
}
}
3 changes: 2 additions & 1 deletion BH/D2Intercepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ void GameInput_Interception(void);
void ChannelInput_Interception(void);
void ChannelWhisper_Interception(void);
void ChannelChat_Interception(void);
void ChannelEmote_Interception(void);
void ChannelEmote_Interception(void);
void MPQDataLoaded_Interception(void);
6 changes: 6 additions & 0 deletions BH/D2Ptrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ FUNCPTR(D2COMMON, LoadAct, Act* __stdcall, (DWORD ActNumber, DWORD MapId, DWORD
FUNCPTR(D2COMMON, GetLevelText, LevelText * __stdcall, (DWORD levelno), -10014, -10142)
FUNCPTR(D2COMMON, GetObjectText, ObjectTxt * __stdcall, (DWORD objno), -10688, -10319)
FUNCPTR(D2COMMON, GetItemText, ItemText *__stdcall, (DWORD dwItemNo), -10695, -10994)
FUNCPTR(D2COMMON, GetItemsTxt, ItemsTxt* __stdcall, (DWORD dwItemNo), -10695, -10994)

FUNCPTR(D2COMMON, GetLayer, AutomapLayer2* __fastcall, (DWORD dwLevelNo), -10749, -10087)
FUNCPTR(D2COMMON, GetLevel, Level * __fastcall, (ActMisc *pMisc, DWORD dwLevelNo), -10207, -10287)
Expand Down Expand Up @@ -381,6 +382,10 @@ VARPTR(D2COMMON, AutoMagicTxt, AutoMagicTxt*, 0x9FBC8, 0xA4CE4)
VARPTR(D2COMMON, ArmorTxt, ItemsTxt*, 0x9FBA4, 0xA4CC0)
VARPTR(D2COMMON, ArmorTxtRecords, DWORD, 0x9FBA8, 0xA4CC4)

VARPTR(D2COMMON, InventoryTxt, InventoryTxt*, 0x9FA5C, 0xA4CAC)

VARPTR(D2COMMON, ItemsTxtRecords, DWORD, 0x9FB94, 0x0)
Copy link
Author

Choose a reason for hiding this comment

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

TODO: 1.13d



////////////////////////////////////////////////////////////////////////////////////////////////
// D2Common Stubs
Expand Down Expand Up @@ -469,6 +474,7 @@ FUNCPTR(D2CMP, DeleteCellFile, void __stdcall, (CellFile *cellfile), -10106, -10
////////////////////////////////////////////////////////////////////////////////////////////////

FUNCPTR(D2LANG, GetLocaleText, wchar_t* __fastcall, (WORD nLocaleTxtNo), -10003, -10004)
FUNCPTR(D2LANG, GetLocaleTextFromString, wchar_t* __fastcall, (const char* ptString), -10011, -10011)


////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading