Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/requestStreaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Aug 14, 2024
2 parents 2af2f46 + 98f22e3 commit 2d8c81f
Show file tree
Hide file tree
Showing 22 changed files with 1,996 additions and 2,241 deletions.
11 changes: 9 additions & 2 deletions Client/core/CCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool

// Grab the command
tagCOMMANDENTRY* pEntry = Get(szCommand);
bool wasHandled = false;
if (pEntry)
{
// If its a core command, or if its enabled
Expand All @@ -133,13 +134,16 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
// Execute it
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
ExecuteHandler(pEntry->pfnCmdFunc, szParameters);

wasHandled = true;
}
}

// Recompose the original command text
std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters : "");

// Is it a cvar? (syntax: cvar[ = value])
if (!wasHandled)
{
// Check to see if '=' exists
unsigned int nOpIndex = val.find('=');
Expand Down Expand Up @@ -187,7 +191,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool

// HACK: if its a 'nick' command, save it here
bool bIsNickCommand = !stricmp(szCommand, "nick");
if (bIsNickCommand && szParameters && !bIsScriptedBind)
if (!wasHandled && bIsNickCommand && szParameters && !bIsScriptedBind)
{
if (CCore::GetSingleton().IsValidNick(szParameters))
{
Expand All @@ -208,10 +212,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
if (m_pfnExecuteHandler)
{
bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind);
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind))
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, wasHandled, bIsScriptedBind, bAllowScriptedBind))
return true;
}

if (wasHandled)
return true;

// Unknown command
val = _("Unknown command or cvar: ") + szCommand;
if (!bIsScriptedBind && !bIsNickCommand && pEntry == nullptr)
Expand Down
8 changes: 2 additions & 6 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,18 +1005,14 @@ void CGameSA::GetShaderReplacementStats(SShaderReplacementStats& outStats)
m_pRenderWare->GetShaderReplacementStats(outStats);
}

void CGameSA::RemoveAllBuildings(bool clearBuildingRemoval)
void CGameSA::RemoveAllBuildings()
{
m_pIplStore->SetDynamicIplStreamingEnabled(false);

m_pPools->GetDummyPool().RemoveAllBuildingLods();
m_pPools->GetBuildingsPool().RemoveAllBuildings();

auto pBuildingRemoval = static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval);
if (clearBuildingRemoval)
{
pBuildingRemoval->ClearRemovedBuildingLists();
}
pBuildingRemoval->DropCaches();

m_isBuildingsRemoved = true;
Expand All @@ -1036,7 +1032,7 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
const bool shouldRemoveBuilding = !m_isBuildingsRemoved;
if (shouldRemoveBuilding)
{
RemoveAllBuildings(false);
RemoveAllBuildings();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class CGameSA : public CGame
PostWeaponFireHandler* m_pPostWeaponFireHandler;
TaskSimpleBeHitHandler* m_pTaskSimpleBeHitHandler;

void RemoveAllBuildings(bool clearBuildingRemoval = true);
void RemoveAllBuildings();
void RestoreGameBuildings();

bool SetBuildingPoolSize(size_t size);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void CClientBuilding::Destroy()
if (!m_pBuilding)
return;

if (m_pHighBuilding)
if (m_pHighBuilding && m_pHighBuilding->IsValid())
{
m_pHighBuilding->GetBuildingEntity()->SetLod(nullptr);
}
Expand Down
8 changes: 3 additions & 5 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5590,7 +5590,7 @@ void CClientGame::ResetMapInfo()
if (pPlayerInfo)
pPlayerInfo->SetCamDrunkLevel(static_cast<byte>(0));

RestreamWorld(true);
RestreamWorld();

ReinitMarkers();
}
Expand Down Expand Up @@ -6813,7 +6813,7 @@ void CClientGame::RestreamModel(unsigned short usModel)
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(usModel);
}

void CClientGame::RestreamWorld(bool removeBigBuildings)
void CClientGame::RestreamWorld()
{
unsigned int numberOfFileIDs = g_pGame->GetCountOfAllFileIDs();

Expand All @@ -6826,9 +6826,7 @@ void CClientGame::RestreamWorld(bool removeBigBuildings)
m_pManager->GetPedManager()->RestreamAllPeds();
m_pManager->GetPickupManager()->RestreamAllPickups();

if (removeBigBuildings)
g_pGame->GetStreaming()->RemoveBigBuildings();

g_pGame->GetStreaming()->RemoveBigBuildings();
g_pGame->GetStreaming()->ReinitStreaming();
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class CClientGame

bool TriggerBrowserRequestResultEvent(const std::unordered_set<SString>& newPages);
void RestreamModel(unsigned short usModel);
void RestreamWorld(bool removeBigBuildings);
void RestreamWorld();
void ReinitMarkers();

void OnWindowFocusChange(bool state);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientIMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool CClientIMG::StreamDisable()

m_pImgManager->UpdateStreamerBufferSize();

g_pClientGame->RestreamWorld(true);
g_pClientGame->RestreamWorld();
return true;
}

Expand Down
16 changes: 2 additions & 14 deletions Client/mods/deathmatch/logic/CScriptFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
DoResourceFileCheck();

// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
// large : >10KB
if (ulSize > 10240)
if (ulSize > 10000)
{
long lCurrentPos = m_pFile->FTell();
m_pFile->FSeek(0, SEEK_END);
Expand All @@ -178,18 +177,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -2;
}

auto bytesRead = m_pFile->FRead(outBuffer.data(), ulSize);

// EOF reached?
// Cant check for error as binary interface
// is pure virtual class with no definitions
// available (CNetServer)
if (m_pFile->FEof())
{
// if so, truncate the data to the amount of bytes read
outBuffer.resize(bytesRead + 1);
}
return bytesRead;
return m_pFile->FRead(outBuffer.data(), ulSize);
}

long CScriptFile::Write(unsigned long ulSize, const char* pData)
Expand Down
7 changes: 1 addition & 6 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,13 +1465,8 @@ bool CStaticFunctionDefinitions::SetElementHealth(CClientEntity& Entity, float f
// Grab the model
CClientPed& Ped = static_cast<CClientPed&>(Entity);

// Limit to max health
float fMaxHealth = Ped.GetMaxHealth();
if (fHealth > fMaxHealth)
fHealth = fMaxHealth;

// Set the new health
Ped.SetHealth(fHealth);
Ped.SetHealth(Clamp(0.0f, fHealth, Ped.GetMaxHealth()));
return true;
break;
}
Expand Down
15 changes: 0 additions & 15 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,11 +1276,6 @@ void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisRe
// No operation on the client
}

std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept
{
return {true, ""};
}

//
// Set error if pThisResource does not have permission to modify every resource in resourceList
//
Expand All @@ -1289,11 +1284,6 @@ void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisR
// No operation on the client
}

std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept
{
return {true, ""};
}

//
// Set error if resource file access is blocked due to reasons
//
Expand All @@ -1302,8 +1292,3 @@ void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pTh
{
// No operation on the client
}

std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly) noexcept
{
return {true, ""};
}
6 changes: 1 addition & 5 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,9 @@ void ReadPregFlags(CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions);
// Resource access helpers
//
void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource);
std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept;
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept;
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
bool* pbReadOnly = nullptr);
std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
bool* pbReadOnly = nullptr) noexcept;

//
// Other misc helpers
Expand Down
15 changes: 6 additions & 9 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,14 @@ int CLuaEngineDefs::EngineGetModelLODDistance(lua_State* luaVM)

int CLuaEngineDefs::EngineSetModelLODDistance(lua_State* luaVM)
{
// bool engineSetModelLODDistance ( int/string modelID, float distance )
// bool engineSetModelLODDistance ( int/string modelID, float distance [, bool extendedLod = false ])
SString strModelId;
float fDistance;
bool extendedLod;
CScriptArgReader argStream(luaVM);
argStream.ReadString(strModelId);
argStream.ReadNumber(fDistance);
argStream.ReadBool(extendedLod, false);

if (!argStream.HasErrors())
{
Expand All @@ -1066,7 +1068,7 @@ int CLuaEngineDefs::EngineSetModelLODDistance(lua_State* luaVM)
CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID);
if (pModelInfo && fDistance > 0.0f)
{
pModelInfo->SetLODDistance(fDistance);
pModelInfo->SetLODDistance(fDistance, extendedLod);
lua_pushboolean(luaVM, true);
return 1;
}
Expand Down Expand Up @@ -2432,14 +2434,9 @@ bool CLuaEngineDefs::EngineResetModelFlags(uint uiModelID)
return false;
}

bool CLuaEngineDefs::EngineRestreamWorld(lua_State* const luaVM)
bool CLuaEngineDefs::EngineRestreamWorld()
{
bool restreamLODs{};

CScriptArgReader argStream(luaVM);
argStream.ReadBool(restreamLODs, false);

g_pClientGame->RestreamWorld(restreamLODs);
g_pClientGame->RestreamWorld();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CLuaEngineDefs : public CLuaDefs
static bool EngineRestoreTXDImage(uint uiModelID);
static std::vector<std::string_view> EngineImageGetFileList(CClientIMG* pImg);
static std::string EngineImageGetFile(CClientIMG* pImg, std::variant<size_t, std::string_view> file);
static bool EngineRestreamWorld(lua_State* const luaVM);
static bool EngineRestreamWorld();
static bool EngineSetModelVisibleTime(std::string strModelId, char cHourOn, char cHourOff);
static std::variant<bool, CLuaMultiReturn<char, char>> EngineGetModelVisibleTime(std::string strModelId);

Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class __declspec(novtable) CGame
virtual int32_t GetBaseIDforSCM() = 0;
virtual int32_t GetCountOfAllFileIDs() = 0;

virtual void RemoveAllBuildings(bool clearBuildingRemoval = true) = 0;
virtual void RemoveAllBuildings() = 0;
virtual void RestoreGameBuildings() = 0;

virtual bool SetBuildingPoolSize(size_t size) = 0;
Expand Down
13 changes: 2 additions & 11 deletions Server/mods/deathmatch/logic/CScriptFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -1;

// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
// large : >10KB
if (ulSize > 10240)
if (ulSize > 10000)
{
long lCurrentPos = ftell(m_pFile);
fseek(m_pFile, 0, SEEK_END);
Expand All @@ -198,15 +197,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -2;
}

auto bytesRead = fread(outBuffer.data(), 1, ulSize, m_pFile);

// EOF reached or error was thrown?
if (feof(m_pFile) || ferror(m_pFile))
{
// if so, truncate the data to the amount of bytes read
outBuffer.resize(bytesRead + 1);
}
return bytesRead;
return fread(outBuffer.data(), 1, ulSize, m_pFile);
}

long CScriptFile::Write(unsigned long ulSize, const char* pData)
Expand Down
24 changes: 6 additions & 18 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,27 +1654,15 @@ bool CStaticFunctionDefinitions::SetElementHealth(CElement* pElement, float fHea
case CElement::PLAYER:
{
CPed* pPed = static_cast<CPed*>(pElement);
if (pPed->IsSpawned())
{
// Limit their max health to what the stat says
float fMaxHealth = pPed->GetMaxHealth();
if (fHealth > fMaxHealth)
fHealth = fMaxHealth;
if (!pPed->IsSpawned())
return false;

// Do not set the health below zero
if (fHealth < 0.0f)
fHealth = 0.0f;
fHealth = Clamp(0.0f, fHealth, pPed->GetMaxHealth());
pPed->SetHealth(fHealth);

// This makes sure the health is set to what will get reported
unsigned char ucHealth = static_cast<unsigned char>(fHealth * 1.25f);
fHealth = static_cast<float>(ucHealth) / 1.25f;
pPed->SetHealth(fHealth);
if (pPed->IsDead() && fHealth > 0.0f)
pPed->SetIsDead(false);

if (pPed->IsDead() && fHealth > 0.0f)
pPed->SetIsDead(false);
}
else
return false;
break;
}
case CElement::VEHICLE:
Expand Down
Loading

0 comments on commit 2d8c81f

Please sign in to comment.