Skip to content

Commit

Permalink
Add quick fix for bad registry settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolrog committed Apr 5, 2021
1 parent ca58a77 commit 5f9ffd6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/d2dx/GameHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GameHelper::GameHelper() :
_hD2ClientDll(LoadLibraryA("D2Client.dll"))
{
InitializeTextureHashPrefixTable();
FixBadRegistrySettings();
}

GameHelper::~GameHelper()
Expand Down Expand Up @@ -530,3 +531,43 @@ GameVersion GameHelper::GetGameVersion()
return version;
}

void GameHelper::FixBadRegistrySettings()
{
/* It seems like D2DX sometimes causes a bad setting in the registry, probably when touching
the settings in the Video Options menu, and likely due to the modifications done to SD-HD.
While this isn't a fix (and I should fix the problem), at least this will recover the situation
the next time the game is launched. */

HKEY hKey;
LPCTSTR diablo2Key = TEXT("SOFTWARE\\Blizzard Entertainment\\Diablo II");
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, diablo2Key, 0, KEY_READ | KEY_WRITE, &hKey);
assert(openRes == ERROR_SUCCESS);
if (openRes == ERROR_SUCCESS)
{
DWORD type = REG_DWORD;
DWORD size = 4;
DWORD value;
auto queryRes = RegQueryValueExA(hKey, "Light Quality", NULL, &type, (LPBYTE)&value, &size);
assert(queryRes == ERROR_SUCCESS || queryRes == ERROR_MORE_DATA);
if (queryRes == ERROR_SUCCESS && size == 4 && value > 2)
{
value = 2;
RegSetValueExA(hKey, "Light Quality", 0, type, (LPBYTE)&value, size);
}
queryRes = RegQueryValueExA(hKey, "Blended Shadows", NULL, &type, (LPBYTE)&value, &size);
assert(queryRes == ERROR_SUCCESS || queryRes == ERROR_MORE_DATA);
if (queryRes == ERROR_SUCCESS && size == 4 && value > 1)
{
value = 1;
RegSetValueExA(hKey, "Blended Shadows", 0, type, (LPBYTE)&value, size);
}
queryRes = RegQueryValueExA(hKey, "Perspective", NULL, &type, (LPBYTE)&value, &size);
assert(queryRes == ERROR_SUCCESS || queryRes == ERROR_MORE_DATA);
if (queryRes == ERROR_SUCCESS && size == 4 && value > 1)
{
value = 1;
RegSetValueExA(hKey, "Perspective", 0, type, (LPBYTE)&value, size);
}
}
}
1 change: 1 addition & 0 deletions src/d2dx/GameHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace d2dx
void WriteU32(HANDLE module, uint32_t offset, uint32_t value);
GameVersion GetGameVersion();
void InitializeTextureHashPrefixTable();
void FixBadRegistrySettings();

bool _isPd2;
HANDLE _hProcess;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/SlashDiablo-HD
Submodule SlashDiablo-HD updated from 57df0d to 388ea9

0 comments on commit 5f9ffd6

Please sign in to comment.