Skip to content

Commit

Permalink
Fix in-game detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolrog committed May 17, 2021
1 parent a6e964f commit 5125cda
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
26 changes: 6 additions & 20 deletions src/d2dx/D2DXContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,37 +318,23 @@ void D2DXContext::CheckMajorGameState()

_majorGameState = MajorGameState::Menus;

if (_gameHelper->ScreenOpenMode() == 3)
if (_gameHelper->IsInGame())
{
_majorGameState = MajorGameState::InGame;
AttachLateDetours(_gameHelper.get(), this);
}
else
{
for (int32_t i = 0; i < batchCount; ++i)
{
const Batch& batch = _batches.items[i];
const int32_t y0 = _vertices.items[batch.GetStartVertex()].GetY();

if ((GameAddress)batch.GetGameAddress() == GameAddress::DrawFloor)
if (batch.GetHash() == 0x4bea7b80 && y0 >= 550)
{
_majorGameState = MajorGameState::InGame;
AttachLateDetours(_gameHelper.get(), this);
_majorGameState = MajorGameState::TitleScreen;
break;
}
}

if (_majorGameState == MajorGameState::Menus)
{
for (int32_t i = 0; i < batchCount; ++i)
{
const Batch& batch = _batches.items[i];
const int32_t y0 = _vertices.items[batch.GetStartVertex()].GetY();

if (batch.GetHash() == 0x4bea7b80 && y0 >= 550)
{
_majorGameState = MajorGameState::TitleScreen;
break;
}
}
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/d2dx/GameHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,3 +986,24 @@ bool GameHelper::IsGameMenuOpen() const
return false;
}
}

bool GameHelper::IsInGame() const
{
auto playerUnit = GetPlayerUnit();

switch (_version)
{
case GameVersion::Lod109d:
return *((uint32_t*)((uint32_t)_hD2ClientDll + 0x1109FC)) != 0 && playerUnit != 0 && playerUnit->u.v109.path != 0;
case GameVersion::Lod112:
return *((uint32_t*)((uint32_t)_hD2ClientDll + 0x11BCC4)) != 0 && playerUnit != 0 && playerUnit->u.v112.path != 0;
case GameVersion::Lod113c:
return *((uint32_t*)((uint32_t)_hD2ClientDll + 0xF8C9C)) != 0 && playerUnit != 0 && playerUnit->u.v112.path != 0;
case GameVersion::Lod113d:
return *((uint32_t*)((uint32_t)_hD2ClientDll + 0xF79E0)) != 0 && playerUnit != 0 && playerUnit->u.v112.path != 0;
case GameVersion::Lod114d:
return *((uint32_t*)((uint32_t)_hGameExe + 0x3A27C0)) != 0 && playerUnit != 0 && playerUnit->u.v112.path != 0;
default:
return false;
}
}
2 changes: 2 additions & 0 deletions src/d2dx/GameHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace d2dx
virtual int32_t GetCurrentAct() const override;

virtual bool IsGameMenuOpen() const override;

virtual bool IsInGame() const override;

private:
GameVersion GetGameVersion();
Expand Down
2 changes: 2 additions & 0 deletions src/d2dx/IGameHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ namespace d2dx
virtual int32_t GetCurrentAct() const = 0;

virtual bool IsGameMenuOpen() const = 0;

virtual bool IsInGame() const = 0;
};
}
4 changes: 2 additions & 2 deletions src/d2dx/d2dx.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\games\Diablo II\Game.exe</LocalDebuggerCommand>
<LocalDebuggerCommand>C:\games\Diablo II\game.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-3dfx -ns -w -dxtestmop -dxnoclipcursor</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-3dfx -ns -w -dxnoclipcursor</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>C:\games\Diablo II\</LocalDebuggerWorkingDirectory>
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
</PropertyGroup>
Expand Down

0 comments on commit 5125cda

Please sign in to comment.