Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/allow_bigger_lod_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Aug 14, 2024
2 parents 9548ebe + 612f9a6 commit de2caaa
Show file tree
Hide file tree
Showing 75 changed files with 3,068 additions and 2,271 deletions.
13 changes: 10 additions & 3 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,14 +134,16 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
// Execute it
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
ExecuteHandler(pEntry->pfnCmdFunc, szParameters);
return true;

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 @@ -188,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 +211,14 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
// Try to execute the handler
if (m_pfnExecuteHandler)
{
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind))
bool bAllowScriptedBind = (!pEntry || pEntry->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
22 changes: 11 additions & 11 deletions Client/game_sa/CCameraSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ float CCameraSA::GetShakeForce()

void CCameraSA::ShakeCamera(float radius, float x, float y, float z) noexcept
{
DWORD dwFunc = FUNC_ShakeCam;
CCameraSAInterface* cameraInterface = GetInterface();
_asm
{
mov ecx, cameraInterface
push z
push y
push x
push radius
call dwFunc
}
static CCameraSAInterface* cameraInterface = GetInterface();
if (radius <= 0.0f)
return ResetShakeCamera();

using ShakeCamera_t = void(__thiscall*)(CCameraSAInterface*, float radius, float x, float y, float z);
((ShakeCamera_t)FUNC_ShakeCam)(cameraInterface, radius, x, y, z);
}

void CCameraSA::ResetShakeCamera() noexcept
{
GetInterface()->m_fCamShakeForce = 0.0f;
}
1 change: 1 addition & 0 deletions Client/game_sa/CCameraSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,5 @@ class CCameraSA : public CCamera
float GetShakeForce();

void ShakeCamera(float radius, float x, float y, float z) noexcept override;
void ResetShakeCamera() noexcept override;
};
13 changes: 13 additions & 0 deletions Client/game_sa/CCarEnterExitSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ bool CCarEnterExitSA::GetNearestCarPassengerDoor(CPed* pPed, CVehicle* pVehicle,
return bReturn;
}

void CCarEnterExitSA::GetPositionToOpenCarDoor(CVector& position, CVehicle* vehicle, std::uint32_t door) const noexcept
{
CVehicleSA* vehicleSA = dynamic_cast<CVehicleSA*>(vehicle);

if (!vehicleSA)
return;

CVehicleSAInterface* vehicleInterface = vehicleSA->GetVehicleInterface();

auto CCarEnterExit_GetPositionToOpenCarDoor = (void(__cdecl*)(CVector&, CVehicleSAInterface*, int))FUNC_GetPositionToOpenCarDoor;
CCarEnterExit_GetPositionToOpenCarDoor(position, vehicleInterface, door);
}

int CCarEnterExitSA::ComputeTargetDoorToExit(CPed* pPed, CVehicle* pVehicle)
{
DWORD dwFunc = FUNC_ComputeTargetDoorToExit;
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CCarEnterExitSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#define FUNC_GetNearestCarPassengerDoor 0x650BB0
#define FUNC_ComputeTargetDoorToExit 0x64F110
#define FUNC_IsRoomForPedToLeaveCar 0x6504C0
#define FUNC_GetPositionToOpenCarDoor 0x64E740

class CCarEnterExitSA : public CCarEnterExit
{
public:
bool GetNearestCarDoor(CPed* pPed, CVehicle* pVehicle, CVector* pVector, int* pDoor);
bool GetNearestCarPassengerDoor(CPed* pPed, CVehicle* pVehicle, CVector* pVector, int* pDoor, bool bUnknown, bool bUnknown2, bool bCheckIfRoomToGetIn);
void GetPositionToOpenCarDoor(CVector& position, CVehicle* vehicle, std::uint32_t door) const noexcept;
int ComputeTargetDoorToExit(CPed* pPed, CVehicle* pVehicle);
bool IsRoomForPedToLeaveCar(CVehicle* pVehicle, int iDoor, CVector* pUnknown = 0);
};
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
14 changes: 11 additions & 3 deletions Client/mods/deathmatch/ClientCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using std::vector;

extern CClientGame* g_pClientGame;

bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind)
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind, bool bAllowScriptedBind)
{
// Has the core already handled this command?
if (!bHandled)
Expand Down Expand Up @@ -95,8 +95,16 @@ bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHand
}
else
{
// Call our comand-handlers for core-executed commands too
g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommand, szArguments);
// Call the onClientCoreCommand event
CLuaArguments Arguments;
Arguments.PushString(szCommand);

auto pLocalPlayer = g_pClientGame->GetLocalPlayer();
pLocalPlayer->CallEvent("onClientCoreCommand", Arguments, true);

// Call our comand-handlers for core-executed commands too, if allowed
if (bAllowScriptedBind)
g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommand, szArguments);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/ClientCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#pragma once

bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind);
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind, bool bAllowScriptedBind);

void COMMAND_Help(const char* szCmdLine);
void COMMAND_Disconnect(const char* szCmdLine);
Expand Down
4 changes: 3 additions & 1 deletion Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
m_pLowBuilding(nullptr)
{
m_pManager = pManager;
m_pModelInfo = g_pGame->GetModelInfo(usModelId);
SetTypeName("building");
m_pBuildingManager->AddToList(this);
Create();
Expand Down Expand Up @@ -99,6 +100,7 @@ void CClientBuilding::SetModel(uint16_t model)
if (CClientBuildingManager::IsValidModel(model))
{
m_usModelId = model;
m_pModelInfo = g_pGame->GetModelInfo(model);
Recreate();
}
}
Expand Down Expand Up @@ -143,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
33 changes: 31 additions & 2 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,38 @@ void CClientBuildingManager::DestroyAllForABit()

void CClientBuildingManager::RestoreDestroyed()
{
for (CClientBuilding* building : GetBuildings())
bool hasInvalidLods = true;
while (hasInvalidLods)
{
building->Create();
hasInvalidLods = false;
for (CClientBuilding* building : GetBuildings())
{
const CClientBuilding* highLodBuilding = building->GetHighLodBuilding();
if (highLodBuilding && !highLodBuilding->IsValid())
{
hasInvalidLods = true;
}
else
{
CModelInfo* modelInfo = building->GetModelInfo();
const uint16_t physicalGroup = modelInfo->GetObjectPropertiesGroup();

if (physicalGroup == -1)
{
building->Create();
}
else
{
// GTA creates dynamic models as dummies.
// It's possible that the physical group was changes after
// creating a new building. We can avoid crashes in this case.
modelInfo->SetObjectPropertiesGroup(-1);
building->Create();
modelInfo->SetObjectPropertiesGroup(physicalGroup);
}

}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,8 @@ void CClientCamera::ShakeCamera(float radius, float x, float y, float z) noexcep
{
m_pCamera->ShakeCamera(radius, x, y, z);
}

void CClientCamera::ResetShakeCamera() noexcept
{
m_pCamera->ResetShakeCamera();
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CClientCamera final : public CClientEntity
void Reset();

void ShakeCamera(float radius, float x, float y, float z) noexcept;
void ResetShakeCamera() noexcept;

void SetCameraVehicleViewMode(eVehicleCamMode eMode);
void SetCameraPedViewMode(ePedCamMode eMode);
Expand Down
9 changes: 4 additions & 5 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,7 @@ void CClientGame::AddBuiltInEvents()

// Console events
m_Events.AddEvent("onClientConsole", "text", NULL, false);
m_Events.AddEvent("onClientCoreCommand", "command", NULL, false);

// Chat events
m_Events.AddEvent("onClientChatMessage", "text, r, g, b, messageType", NULL, false);
Expand Down Expand Up @@ -5589,7 +5590,7 @@ void CClientGame::ResetMapInfo()
if (pPlayerInfo)
pPlayerInfo->SetCamDrunkLevel(static_cast<byte>(0));

RestreamWorld(true);
RestreamWorld();

ReinitMarkers();
}
Expand Down Expand Up @@ -6812,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 @@ -6825,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
15 changes: 15 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <game/CBikeHandlingEntry.h>
#include <game/CBoat.h>
#include <game/CBoatHandlingEntry.h>
#include <game/CCarEnterExit.h>
#include <game/CDoor.h>
#include <game/CFlyingHandlingEntry.h>
#include <game/CHandlingEntry.h>
Expand Down Expand Up @@ -5031,3 +5032,17 @@ void CClientVehicle::ResetWheelScale()

m_bWheelScaleChanged = false;
}

CVector CClientVehicle::GetEntryPoint(std::uint32_t entryPointIndex)
{
static const uint32_t lookup[4] = {10, 8, 11, 9};
assert(entryPointIndex < 4);
const std::uint32_t saDoorIndex = lookup[entryPointIndex];

CVector entryPoint;
CVehicle* gameVehicle = GetGameVehicle();

g_pGame->GetCarEnterExit()->GetPositionToOpenCarDoor(entryPoint, gameVehicle, saDoorIndex);

return entryPoint;
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ class CClientVehicle : public CClientStreamElement
bool SetDummyPosition(eVehicleDummies dummy, const CVector& position);
bool ResetDummyPositions();

CVector GetEntryPoint(std::uint32_t entryPointIndex);

protected:
void ConvertComponentRotationBase(const SString& vehicleComponent, CVector& vecInOutRotation, EComponentBaseType inputBase, EComponentBaseType outputBase);
void ConvertComponentPositionBase(const SString& vehicleComponent, CVector& vecInOutPosition, EComponentBaseType inputBase, EComponentBaseType outputBase);
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
Loading

0 comments on commit de2caaa

Please sign in to comment.