MafiaHub / MafiaMP

Multiplayer experience for Mafia: Definitive Edition
https://mafiahub.dev
Other
39 stars 5 forks source link

Research: trigger player death #52

Open zpl-zak opened 8 months ago

zpl-zak commented 8 months ago

Description

We have identified an issue where it is impossible to programmatically trigger a player's death by directly setting the health value to 0. This requires investigation to understand the underlying cause and to identify if there is an existing function within the game's SDK that would allow us to achieve this functionality appropriately.

Tasks

Scope

This issue is restricted to the client side.

See https://github.com/MafiaHub/MafiaMP/pull/47#discussion_r1450846934 for details.

Segfaultd commented 7 months ago

There is a I_Human2::Kill method. Parameters to research

Deewarz commented 7 months ago

Interesting because C_HumanScript::SetHealth should call I_Human2::Kill if health is <= 0.0

void __fastcall C_HumanScript::SetHealth(__int64 *a1, float a2)
{
  __int64 v2; // rcx
  __int64 Game; // rax
  __int64 v4; // rax
  __int64 HealthSystem; // rax
  __int64 HealthBar; // rax

  v2 = *a1;
  if ( *(_BYTE *)(v2 + 24) == 9 )
  {
    Game = GetGame();
    v4 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)Game + 144i64))(Game);
    HealthSystem = C_Player2::GetHealthSystem(v4);
    HealthBar = mafia::health_system::C_HealthSystem::GetHealthBar(HealthSystem);
    sub_142BF4650(HealthBar);
  }
  else if ( (*(_BYTE *)(v2 + 28) & 1) != 0 )
  {
    if ( a2 <= 0.0 )
      I_Human2::Kill(v2, 9, 0, (__int64)ue::sys::math::ZeroVector);
    else
      I_Human2::SetHealth(v2, a2);
  }
}

Do we have an idea of what is v2 + 24 in if ( *(_BYTE *)(v2 + 24) == 9 )?