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

Add new function isPlayerCrosshairVisible #3720

Merged
Merged
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
39 changes: 39 additions & 0 deletions Client/game_sa/CHudSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include "StdInc.h"
#include "CHudSA.h"
#include "CGameSA.h"
#include "CCameraSA.h"

extern CGameSA* pGame;

char szVehicleName[50] = {'\0'};
char szZoneName[50] = {'\0'};
Expand Down Expand Up @@ -171,3 +175,38 @@ void CHudSA::ResetComponentAdjustment()
MemPut<float>(m_pfCameraCrosshairScale, 192.0f);
m_fSniperCrosshairScale = 210.0f;
}

bool CHudSA::IsCrosshairVisible()
FileEX marked this conversation as resolved.
Show resolved Hide resolved
{
if (!IsComponentVisible(HUD_CROSSHAIR))
return false;

CCamera* camera = pGame->GetCamera();
eCamMode cameraViewMode = static_cast<eCamMode>(camera->GetCam(camera->GetActiveCam())->GetMode());

switch (cameraViewMode)
{
case MODE_SNIPER_RUNABOUT:
case MODE_ROCKETLAUNCHER_RUNABOUT:
case MODE_ROCKETLAUNCHER_RUNABOUT_HS:
case MODE_M16_1STPERSON_RUNABOUT:
case MODE_1STPERSON_RUNABOUT:
case MODE_AIMWEAPON:
case MODE_AIMWEAPON_ATTACHED:
case MODE_AIMWEAPON_FROMCAR:
case MODE_M16_1STPERSON:
case MODE_HELICANNON_1STPERSON:
case MODE_SNIPER:
case MODE_ROCKETLAUNCHER:
case MODE_ROCKETLAUNCHER_HS:
case MODE_AIMING:
case MODE_CAMERA:
return true;
default:
break;
}

// Check CTheScripts::bDrawCrossHair
std::uint8_t crossHairType = *reinterpret_cast<std::uint8_t*>(VAR_CTheScripts_bDrawCrossHair);
return crossHairType > 0;
}
3 changes: 3 additions & 0 deletions Client/game_sa/CHudSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#define CODE_ShowMoney 0x58F47D

#define VAR_CTheScripts_bDrawCrossHair 0xA44490

struct SHudComponent
{
bool bIsPartOfAll;
Expand All @@ -59,6 +61,7 @@ class CHudSA : public CHud
bool IsComponentVisible(eHudComponent component);
void AdjustComponents(float fAspectRatio);
void ResetComponentAdjustment();
bool IsCrosshairVisible();

protected:
void InitComponentList();
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"getPlayerMoney", GetPlayerMoney},
{"getPlayerWantedLevel", GetPlayerWantedLevel},
{"getPlayerScriptDebugLevel", ArgumentParser<GetPlayerScriptDebugLevel>},
{"isPlayerCrosshairVisible", ArgumentParser<IsPlayerCrosshairVisible>},

// Player set funcs
{"showPlayerHudComponent", ShowPlayerHudComponent},
Expand Down Expand Up @@ -91,13 +92,15 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getScriptDebugLevel", "getPlayerScriptDebugLevel");

lua_classfunction(luaVM, "isNametagShowing", "isPlayerNametagShowing");
lua_classfunction(luaVM, "isCrosshairVisible", "isPlayerCrosshairVisible");

lua_classvariable(luaVM, "ping", NULL, "getPlayerPing");
lua_classvariable(luaVM, "name", NULL, "getPlayerName");
lua_classvariable(luaVM, "team", NULL, "getPlayerTeam");
lua_classvariable(luaVM, "scriptDebugLevel", nullptr, "getPlayerScriptDebugLevel");
lua_classvariable(luaVM, "nametagText", "setPlayerNametagText", "getPlayerNametagText");
lua_classvariable(luaVM, "nametagShowing", "setPlayerNametagShowing", "isPlayerNametagShowing");
lua_classvariable(luaVM, "crosshairVisible", nullptr, "isPlayerCrosshairVisible");

lua_registerclass(luaVM, "Player", "Ped");
}
Expand Down Expand Up @@ -636,3 +639,8 @@ unsigned char CLuaPlayerDefs::GetPlayerMapOpacity()
int iMapOpacity = g_pCore->GetCVars()->GetValue<int>("mapalpha");
return static_cast<unsigned char>(Clamp(0, iMapOpacity, 255));
}

bool CLuaPlayerDefs::IsPlayerCrosshairVisible()
FileEX marked this conversation as resolved.
Show resolved Hide resolved
{
return g_pGame->GetHud()->IsCrosshairVisible();
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerMoney);
LUA_DECLARE(GetPlayerWantedLevel);
static std::uint8_t GetPlayerScriptDebugLevel() noexcept;
static bool IsPlayerCrosshairVisible();

// Player set
LUA_DECLARE(ShowPlayerHudComponent);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ class CHud
virtual bool IsComponentVisible(eHudComponent component) = 0;
virtual void AdjustComponents(float fAspectRatio) = 0;
virtual void ResetComponentAdjustment() = 0;
virtual bool IsCrosshairVisible() = 0;
};
Loading