Skip to content

Commit 804bf12

Browse files
committedNov 23, 2020
64-bit fixes, and fixing new delegate dispatch system.
1 parent ee5a6d8 commit 804bf12

17 files changed

+120
-38
lines changed
 

‎CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ if(BUILD_GAME)
5050
set(LIBRARY_SRC ${SDL_SRC} ${ADPCM_SRC} ${HUFFMAN_SRC} ${PKWARE_SRC} ${GLEW_SRC})
5151

5252
set(ENGINE_SRC ${ENGINE_SRC} ${SHARED_SRC} ${LIBRARY_SRC})
53-
set(SDL2_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Libraries/sdl/x86")
53+
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
54+
set(SDL2_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Libraries/sdl/x86")
55+
else()
56+
set(SDL2_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Libraries/sdl/x64")
57+
endif()
5458
set(SDL2_LIBRARIES "${SDL2_LIBRARY_DIR}/SDL2.lib" "${SDL2_LIBRARY_DIR}/SDL2main.lib"
5559
"${SDL2_LIBRARY_DIR}/SDL2main.lib" "${SDL2_LIBRARY_DIR}/SDL2test.lib"
5660
"${SDL2_LIBRARY_DIR}/SDL2_net.lib" "${SDL2_LIBRARY_DIR}/SDL2_mixer.lib"

‎Engine/Diablo2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct D2CmdArgStrc
2222
char szKeyName[16]; // +10
2323
char szCmdName[16]; // +20
2424
DWORD dwType; // +30 ( 0 use GetProfInt - write bool, 1 DWORD , 2 string, 3 BYTE, 4 WORD)
25-
int nOffset; // +34
25+
DWORD nOffset; // +34
2626
DWORD dwDefault; // +38
2727
}; // +3C
2828

‎Engine/INI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace INI
152152
{
153153
case CMD_BOOLEAN:
154154
#ifdef _WIN32
155-
pField->fieldValues.bValue = *(bool*)((DWORD)pData + pCurrent->nOffset);
155+
pField->fieldValues.bValue = *(bool*)((BYTE*)pData + pCurrent->nOffset);
156156
#else
157157
pField->fieldValues.bValue = *(bool*)(pData + pCurrent->nOffset);
158158
#endif
@@ -168,7 +168,7 @@ namespace INI
168168
case CMD_WORD:
169169
case CMD_DWORD:
170170
#ifdef _WIN32
171-
pField->fieldValues.nValue = *(int*)((DWORD)pData + pCurrent->nOffset);
171+
pField->fieldValues.nValue = *(int*)((BYTE*)pData + pCurrent->nOffset);
172172
#else
173173
pField->fieldValues.nValue = *(int*)(pData + pCurrent->nOffset);
174174
#endif
@@ -181,7 +181,7 @@ namespace INI
181181

182182
case CMD_STRING:
183183
#ifdef _WIN32
184-
D2Lib::strncpyz(pField->fieldValues.szValue, (char*)((DWORD)pData + pCurrent->nOffset), INI_MAX_STRINGLEN);
184+
D2Lib::strncpyz(pField->fieldValues.szValue, (char*)((BYTE*)pData + pCurrent->nOffset), INI_MAX_STRINGLEN);
185185
#else
186186
D2Lib::strncpyz(pField->fieldValues.szValue, (char*)(pData + pCurrent->nOffset), INI_MAX_STRINGLEN);
187187
#endif

‎Engine/Platform_Windows.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ namespace Sys
308308
Log_ErrorAssertReturn(bModuleFound, nullptr);
309309

310310
gModules[nModule].dwModule = LoadLibrary(szModulePath);
311+
DWORD error = GetLastError();
311312
Log_ErrorAssertReturn(gModules[nModule].dwModule != 0, nullptr);
312313

313314
GetAPIType ModuleAPI;

‎Modcode/Client/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ add_library(D2Client SHARED
1515
"${D2CLIENT_FILES}"
1616
"${SHARED_SRC}"
1717
)
18-
set_target_properties(D2Client PROPERTIES OUTPUT_NAME D2Client)
18+
set_target_properties(D2Client
19+
PROPERTIES
20+
OUTPUT_NAME D2Client
21+
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug"
22+
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug"
23+
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug"
24+
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release"
25+
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release"
26+
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release"
27+
)
1928
set_target_properties(D2Client PROPERTIES LINKER_LANGUAGE CXX)
2029

2130
target_link_libraries(D2Client ${STATIC_LIBRARIES} D2Common)

‎Modcode/Client/UI/D2Menu.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ void D2Menu::HidePanel(D2Panel* pPanel)
120120
pCurrent = pCurrent->m_pNextVisible;
121121
}
122122

123+
if (pLast == nullptr)
124+
{
125+
return;
126+
}
127+
128+
if (pCurrent == nullptr)
129+
{
130+
pLast->m_pNextVisible = nullptr;
131+
return;
132+
}
133+
123134
pLast->m_pNextVisible = pCurrent->m_pNextVisible;
124135
}
125136

‎Modcode/Client/UI/Menus/CharCreate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void CharCreateData::OnCharacterSteppedBack(class IRenderObject* caller, void* e
6161
*/
6262
namespace D2Menus
6363
{
64-
CharCreate::CharCreate(bool bFromCharSelect)
64+
CharCreate::CharCreate(bool bFromCharSelect) : D2Menu()
6565
{
6666
engine->renderer->SetGlobalPalette(PAL_FECHAR);
6767
backgroundTexture = engine->renderer->AllocateObject(0);

‎Modcode/Client/UI/Menus/CharSelect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace D2Menus
99
/*
1010
* Creates the CharSelect menu.
1111
*/
12-
CharSelect::CharSelect(char** pszSavePaths, int nNumFiles)
12+
CharSelect::CharSelect(char** pszSavePaths, int nNumFiles) : D2Menu()
1313
{
1414
bool bPreloadedSave = (pszSavePaths != nullptr);
1515
D2SaveHeader header{ 0 };

‎Modcode/Client/UI/Menus/Main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace D2Menus
88
*/
99
Main::Main() : D2Menu()
1010
{
11+
m_visiblePanels = nullptr;
12+
1113
IGraphicsReference* flameTexLeft = engine->graphics->CreateReference(
1214
"data\\global\\ui\\FrontEnd\\D2LogoFireLeft.dc6",
1315
UsagePolicy_Permanent
@@ -69,7 +71,14 @@ namespace D2Menus
6971
Main::~Main()
7072
{
7173
// We don't kill the game select background, because we might need it again later
74+
engine->renderer->Remove(backgroundObject);
75+
engine->renderer->Remove(flameLeft);
76+
engine->renderer->Remove(flameRight);
77+
engine->renderer->Remove(blackLeft);
78+
engine->renderer->Remove(blackRight);
7279
delete pMainPanel;
80+
pMainPanel = nullptr;
81+
m_visiblePanels = nullptr;
7382
}
7483

7584
/*

‎Modcode/Client/UI/Menus/Trademark.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace D2Menus
7373
trademark->SetTextColor(TextColor_Gold);
7474
allRightsReserved->SetTextColor(TextColor_Gold);
7575

76-
m_dwTimeRemaining = 10000;
76+
m_timeRemaining = 10000;
7777
}
7878

7979
/*
@@ -100,8 +100,8 @@ namespace D2Menus
100100
{
101101
D2Menu::Tick(dwDeltaMs);
102102

103-
m_dwTimeRemaining -= dwDeltaMs;
104-
if (m_dwTimeRemaining <= 0)
103+
m_timeRemaining -= dwDeltaMs;
104+
if (m_timeRemaining <= 0)
105105
{
106106
delete cl.pActiveMenu;
107107
cl.pActiveMenu = new Main();
@@ -130,7 +130,7 @@ namespace D2Menus
130130
bool Trademark::HandleMouseClicked(DWORD dwX, DWORD dwY)
131131
{
132132
// if mouse is clicked, go to main menu
133-
m_dwTimeRemaining = 0;
133+
m_timeRemaining = 0;
134134
return true;
135135
}
136136
}

‎Modcode/Client/UI/Menus/Trademark.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace D2Menus
88
private:
99
char16_t* szCopyrightText;
1010
char16_t* szAllRightsReservedText;
11-
DWORD m_dwTimeRemaining;
11+
int m_timeRemaining;
1212

1313
IRenderObject* backgroundObject;
1414
IRenderObject* flameLeft;

‎Modcode/Client/UI/Panels/CharCreate.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ namespace D2Panels
2828
pCancelButton->AttachIdentifier("cc_cancel");
2929
pOKButton->AttachIdentifier("cc_ok");
3030

31+
pCancelButton->AddEventListener(Clicked, [] {
32+
delete cl.pActiveMenu;
33+
cl.pActiveMenu = new D2Menus::CharSelect();
34+
});
35+
3136
pOKButton->Disable();
3237
}
3338

‎Modcode/Client/UI/Panels/CharSelect.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ namespace D2Panels
4545
okButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_OK));
4646
exitButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_EXIT));
4747

48+
exitButton->AddEventListener(Clicked, [] {
49+
delete cl.pActiveMenu;
50+
cl.pActiveMenu = new D2Menus::Main();
51+
});
4852

4953
characterDisplayName->AttachFontResource(cl.font42);
5054
}

‎Modcode/Client/UI/Panels/Debug.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Debug.hpp"
22
#include "../D2Menu.hpp"
3+
#include "../Menus/Main.hpp"
34

45
#define MAIN_BUTTON_DC6 "data\\global\\ui\\FrontEnd\\3WideButtonBlank.dc6"
56

@@ -17,8 +18,7 @@ namespace D2Panels
1718
m_exitButton->AttachText(u"EXIT");
1819
m_exitButton->AddEventListener(Clicked, [] {
1920
delete cl.pActiveMenu;
20-
D2Client_GoToContextMenu();
21-
return;
21+
cl.pActiveMenu = new D2Menus::Main();
2222
});
2323
}
2424

‎Modcode/Client/UI/Panels/Main.cpp

+44-21
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#define SMALL_BUTTON_DC6 "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6"
1919
#define THIN_BUTTON_DC6 "data\\global\\ui\\FrontEnd\\NarrowButtonBlank.dc6"
2020

21+
/** Tries to advance to the character select screen.
22+
* If there's no save files present, it advances to the character creation screen instead.
23+
*/
24+
void D2Client_AdvanceToCharSelect()
25+
{
26+
27+
}
28+
2129
namespace D2Panels
2230
{
2331
/*
@@ -59,6 +67,42 @@ namespace D2Panels
5967
m_cinematicsButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_CINEMATICS));
6068
m_exitButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_EXIT));
6169

70+
m_singleplayerButton->AddEventListener(Clicked, [] {
71+
cl.szCurrentIPDestination[0] = '\0'; // set IP to blank
72+
engine->NET_SetPlayerCount(1);
73+
cl.charSelectContext = CSC_SINGLEPLAYER;
74+
75+
int nNumFiles = 0;
76+
char** szFileList = engine->FS_ListFilesInDirectory("Save", "*.d2s", &nNumFiles);
77+
78+
delete cl.pActiveMenu;
79+
if (nNumFiles <= 0)
80+
{
81+
cl.pActiveMenu = new D2Menus::CharCreate();
82+
}
83+
else
84+
{
85+
cl.pActiveMenu = new D2Menus::CharSelect(szFileList, nNumFiles);
86+
engine->FS_FreeFileList(szFileList, nNumFiles);
87+
}
88+
});
89+
90+
m_multiplayerButton->AddEventListener(Clicked, [] {
91+
delete cl.pActiveMenu;
92+
cl.pActiveMenu = new D2Menus::OtherMultiplayer();
93+
});
94+
95+
m_exitButton->AddEventListener(Clicked, [] {
96+
cl.bKillGame = true;
97+
});
98+
99+
#ifdef _DEBUG
100+
m_debugMapButton->AddEventListener(Clicked, [] {
101+
delete cl.pActiveMenu;
102+
cl.pActiveMenu = new D2Menus::Debug();
103+
});
104+
#endif
105+
62106
// Disable the battle.net button and the gateway button.
63107
// Closed Battle.net is not allowed in OpenD2.
64108
m_battleNetButton->Disable();
@@ -86,25 +130,4 @@ namespace D2Panels
86130
{
87131
DrawAllWidgets();
88132
}
89-
90-
/*
91-
* Tries to advance to the character select screen.
92-
* If there's no save files present, it advances to the character creation screen instead.
93-
*/
94-
void D2Client_AdvanceToCharSelect()
95-
{
96-
int nNumFiles = 0;
97-
char** szFileList = engine->FS_ListFilesInDirectory("Save", "*.d2s", &nNumFiles);
98-
99-
delete cl.pActiveMenu;
100-
if (nNumFiles <= 0)
101-
{
102-
cl.pActiveMenu = new D2Menus::CharCreate();
103-
}
104-
else
105-
{
106-
cl.pActiveMenu = new D2Menus::CharSelect(szFileList, nNumFiles);
107-
engine->FS_FreeFileList(szFileList, nNumFiles);
108-
}
109-
}
110133
}

‎Modcode/Client/UI/Panels/OtherMultiplayer.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ namespace D2Panels
3232
m_openBattleNetButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_OPENBNET));
3333
m_TCPIPButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_TCPIP));
3434
m_cancelButton->AttachText(engine->TBL_FindStringFromIndex(TBLTEXT_CANCEL));
35+
36+
m_TCPIPButton->AddEventListener(Clicked, [] {
37+
delete cl.pActiveMenu;
38+
cl.pActiveMenu = new D2Menus::TCPIP();
39+
});
40+
m_cancelButton->AddEventListener(Clicked, [] {
41+
delete cl.pActiveMenu;
42+
cl.pActiveMenu = new D2Menus::Main();
43+
});
3544
}
3645

3746
/*

‎Shared/D2Shared.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,18 @@ class UnorderedDelegateList
964964

965965
void Dispatch(Args... args)
966966
{
967+
// TODO: find a workaround for this.
968+
// Basically if we fire off a delegate that alters its containing object = this goes boom!
969+
void (*bindList[MAX_BOUND_TO_DELEGATELIST])(Args...);
967970
for (int i = 0; i < MAX_BOUND_TO_DELEGATELIST; i++)
968971
{
969-
if (m_bound[i] != nullptr)
972+
bindList[i] = m_bound[i];
973+
}
974+
for (int i = 0; i < MAX_BOUND_TO_DELEGATELIST; i++)
975+
{
976+
if (bindList[i] != nullptr)
970977
{
971-
m_bound[i](args...);
978+
bindList[i](args...);
972979
}
973980
}
974981
}

0 commit comments

Comments
 (0)
Please sign in to comment.