Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Dec 17, 2024
2 parents b30a4a2 + 6768df5 commit 27b9eae
Show file tree
Hide file tree
Showing 82 changed files with 1,131 additions and 289 deletions.
8 changes: 4 additions & 4 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,10 @@ void CWebView::OnBeforeClose(CefRefPtr<CefBrowser> browser)
// //
// //
////////////////////////////////////////////////////////////////////
bool CWebView::OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& target_url, const CefString& target_frame_name,
CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings, CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access)
bool CWebView::OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int popup_id, const CefString& target_url,
const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture,
const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info, bool* no_javascript_access)
{
// ATTENTION: This method is called on the IO thread

Expand Down
8 changes: 4 additions & 4 deletions Client/cefweb/CWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ class CWebView : public CWebViewInterface,

// CefLifeSpawnHandler methods
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& target_url, const CefString& target_frame_name,
CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings, CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) override;
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int popup_id, const CefString& target_url,
const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture,
const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info, bool* no_javascript_access) override;
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;

// CefJSDialogHandler methods
Expand Down
1 change: 0 additions & 1 deletion Client/core/CConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class CConsole : public CConsoleInterface
bool IsInputActive();
void ActivateInput();

void HandleTextAccepted(bool bHandled);
void GetCommandInfo(const std::string& strIn, std::string& strCmdOut, std::string& strCmdLineOut);

void ResetHistoryChanges();
Expand Down
22 changes: 15 additions & 7 deletions Client/core/CNickGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*****************************************************************************/

#include "StdInc.h"
#include "time.h"
#include <random>

// These words are of a maximum length of 10 characters, capitalized, and stripped of whitespace
const char* const CNickGen::m_szAdjectives[] = {
const char* const szAdjectives[] = {
"Aback", "Abaft", "Abandoned", "Abashed", "Aberrant", "Abhorrent", "Abiding", "Abject", "Ablaze", "Able", "Abnormal",
"Aboard", "Aboriginal", "Abortive", "Abounding", "Abrasive", "Abrupt", "Absent", "Absorbed", "Absorbing", "Abstracted", "Absurd",
"Abundant", "Abusive", "Acceptable", "Accessible", "Accidental", "Accurate", "Acid", "Acidic", "Acoustic", "Acrid", "Actually",
Expand Down Expand Up @@ -109,7 +109,7 @@ const char* const CNickGen::m_szAdjectives[] = {
"Worried", "Worthless", "Wrathful", "Wretched", "Wrong", "Wry",
};

const char* const CNickGen::m_szNouns[] = {
const char* const szNouns[] = {
"Aardvark", "Buffalo", "Alligator", "Ant", "Anteater", "Antelope", "Ape", "Armadillo", "Donkey", "Baboon", "Badger",
"Barracuda", "Bat", "Bear", "Beaver", "Bee", "Bison", "Boar", "Bush", "Butterfly", "Camel", "Calf",
"Cat", "Kitten", "Cattle", "Chamois", "Cheetah", "Chicken", "Chick", "Chimpanzee", "Infant", "Empress", "Troop",
Expand Down Expand Up @@ -196,10 +196,18 @@ const char* const CNickGen::m_szNouns[] = {
"Vampire", "Parasite", "Tramp", "Bum", "Hobo", "Hitchhiker", "Deadbeat", "Acrobat",
};

constexpr auto numAdjectives = std::size(szAdjectives);
constexpr auto numNouns = std::size(szNouns);
constexpr auto maxNum = 100;

SString CNickGen::GetRandomNickname()
{
srand((unsigned int)time(NULL));
int iAdjective = rand() % NICKGEN_NUM_ADJECTIVES;
int iNoun = rand() % NICKGEN_NUM_NOUNS;
return SString("%s%s%i", m_szAdjectives[iAdjective], m_szNouns[iNoun], rand() % 100);
std::random_device rd;
std::mt19937 gen(rd());

std::uniform_int_distribution<int> adjectiveDist(0, numAdjectives - 1);
std::uniform_int_distribution<int> nounDist(0, numNouns - 1);
std::uniform_int_distribution<int> numDist(0, maxNum);

return SString("%s%s%i", szAdjectives[adjectiveDist(gen)], szNouns[nounDist(gen)], numDist(gen));
}
5 changes: 0 additions & 5 deletions Client/core/CNickGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@

#pragma once

#define NICKGEN_NUM_ADJECTIVES 1048
#define NICKGEN_NUM_NOUNS 934

class CNickGen
{
public:
static const char* const m_szAdjectives[NICKGEN_NUM_ADJECTIVES];
static const char* const m_szNouns[NICKGEN_NUM_NOUNS];
static SString GetRandomNickname();
};
12 changes: 11 additions & 1 deletion Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
if (!HasFreeBuildingSlot())
return nullptr;

auto modelInfo = pGame->GetModelInfo(modelId);

// Change the properties group to force dynamic models to be created as buildings instead of dummies
auto prevGroup = modelInfo->GetObjectPropertiesGroup();
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(MODEL_PROPERTIES_GROUP_STATIC);

// Load building
SFileObjectInstance instance;
instance.modelID = modelId;
Expand All @@ -70,9 +77,12 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
pBuilding->m_pLod = nullptr;
pBuilding->m_iplIndex = 0;

// Restore changed properties group
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(prevGroup);

// Always stream model collosion
// TODO We can setup collison bounding box and use GTA streamer for it
auto modelInfo = pGame->GetModelInfo(modelId);
modelInfo->AddColRef();

// Add building in world
Expand Down
28 changes: 28 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,34 @@ void CGameSA::SetRoadSignsTextEnabled(bool isEnabled)
m_isRoadSignsTextEnabled = isEnabled;
}

void CGameSA::SetIgnoreFireStateEnabled(bool isEnabled)
{
if (isEnabled == m_isIgnoreFireStateEnabled)
return;

if (isEnabled)
{
MemSet((void*)0x6511B9, 0x90, 10); // CCarEnterExit::IsVehicleStealable
MemSet((void*)0x643A95, 0x90, 14); // CTaskComplexEnterCar::CreateFirstSubTask
MemSet((void*)0x6900B5, 0x90, 14); // CTaskComplexCopInCar::ControlSubTask
MemSet((void*)0x64F3DB, 0x90, 14); // CCarEnterExit::IsPlayerToQuitCarEnter

MemSet((void*)0x685A7F, 0x90, 14); // CTaskSimplePlayerOnFoot::ProcessPlayerWeapon
}
else
{
// Restore original bytes
MemCpy((void*)0x6511B9, "\x88\x86\x90\x04\x00\x00\x85\xC0\x75\x3E", 10);
MemCpy((void*)0x643A95, "\x8B\x88\x90\x04\x00\x00\x85\xC9\x0F\x85\x99\x01\x00\x00", 14);
MemCpy((void*)0x6900B5, "\x8B\x81\x90\x04\x00\x00\x85\xC0\x0F\x85\x1A\x01\x00\x00", 14);
MemCpy((void*)0x64F3DB, "\x8B\x85\x90\x04\x00\x00\x85\xC0\x0F\x85\x1B\x01\x00\x00", 14);

MemCpy((void*)0x685A7F, "\x8B\x86\x30\x07\x00\x00\x85\xC0\x0F\x85\x1D\x01\x00\x00", 14);
}

m_isIgnoreFireStateEnabled = isEnabled;
}

bool CGameSA::PerformChecks()
{
std::map<std::string, SCheatSA*>::iterator it;
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ class CGameSA : public CGame
bool IsTunnelWeatherBlendEnabled() const noexcept override { return m_isTunnelWeatherBlendEnabled; }
void SetTunnelWeatherBlendEnabled(bool isEnabled) override;

bool IsIgnoreFireStateEnabled() const noexcept override { return m_isIgnoreFireStateEnabled; }
void SetIgnoreFireStateEnabled(bool isEnabled) override;

unsigned long GetMinuteDuration();
void SetMinuteDuration(unsigned long ulTime);
Expand Down Expand Up @@ -378,6 +380,7 @@ class CGameSA : public CGame
bool m_isRoadSignsTextEnabled{true};
bool m_isBuildingsRemoved{false};
bool m_isExtendedWaterCannonsEnabled{false};
bool m_isIgnoreFireStateEnabled{false};

static unsigned int& ClumpOffset;

Expand Down
93 changes: 56 additions & 37 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <game/Common.h>
#include <game/CModelInfo.h>
#include "CRenderWareSA.h"
#include "game/RenderWare.h"

class CPedModelInfoSA;
class CPedModelInfoSAInterface;
Expand Down Expand Up @@ -231,6 +232,11 @@ class CBaseModelInfoSAInterface
// +726 = Word array as referenced in CVehicleModelInfo::GetVehicleUpgrade(int)
// +762 = Array of WORD containing something relative to paintjobs
// +772 = Anim file index

void Shutdown()
{
((void(*)())VFTBL->Shutdown)();
}
};
static_assert(sizeof(CBaseModelInfoSAInterface) == 0x20, "Invalid size for CBaseModelInfoSAInterface");

Expand Down Expand Up @@ -259,53 +265,66 @@ class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface
CTimeInfoSAInterface timeInfo;
};

class CVehicleModelUpgradePosnDesc
{
CVector m_vPosition;
RtQuat m_vRotation;
int m_iParentId;
};

class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change
{
public:
CVector vecDummies[15];
char m_sUpgrade[18];
CVector vecDummies[15];
CVehicleModelUpgradePosnDesc m_sUpgrade[18];
RpAtomic* m_pExtra[6];
std::uint8_t m_numExtras;
std::uint8_t _pad[3];
int m_maskComponentDamagable;
};

class CVehicleModelInfoSAInterface : public CBaseModelInfoSAInterface
class CVehicleModelInfoSAInterface : public CClumpModelInfoSAInterface
{
public:
uint32 pad1; // +32
RpMaterial* pPlateMaterial; // +36
RpMaterial* pPlateMaterial;
char plateText[8];
char pad[2];
std::uint8_t field_30;
std::uint8_t plateType;
char gameName[8];
char pad2[2];
unsigned int uiVehicleType;
std::uint8_t field_3A[2];
std::uint32_t vehicleType;
float fWheelSizeFront;
float fWheelSizeRear;
short sWheelModel;
short sHandlingID;
byte ucNumDoors;
byte ucVehicleList;
byte ucVehicleFlags;
byte ucWheelUpgradeClass;
byte ucTimesUsed;
short sVehFrequency;
unsigned int uiComponentRules;
float fSteeringAngle;
CVehicleModelVisualInfoSAInterface* pVisualInfo; // +92
char pad3[464];
char pDirtMaterial[64]; // *RwMaterial
char pad4[64];
char primColors[8];
char secondColors[8];
char treeColors[8];
char fourColors[8];
unsigned char ucNumOfColorVariations;
unsigned char ucLastColorVariation;
unsigned char ucPrimColor;
unsigned char ucSecColor;
unsigned char ucTertColor;
unsigned char ucQuatColor;
char upgrades[36];
char anRemapTXDs[8];
char pad5[2];
char pAnimBlock[4];
std::int16_t wheelModelID;
std::int16_t handlingID;
std::uint8_t numDoors;
std::uint8_t vehicleClass;
std::uint8_t vehicleFlags;
std::uint8_t wheelUpgradeClass;
std::uint8_t timesUsed;
std::uint8_t field_51;
std::int16_t vehFrequency;
std::uint32_t componentRules;
float bikeSteeringAngle;
CVehicleModelVisualInfoSAInterface* pVisualInfo; // vehicleStruct
std::uint8_t field_60[464];
RpMaterial** m_dirtMaterials;
std::size_t m_numDirtMaterials;
RpMaterial* m_staticDirtMaterials[30];
std::uint8_t primColors[8];
std::uint8_t secondColors[8];
std::uint8_t treeColors[8];
std::uint8_t fourColors[8];
std::uint8_t numOfColorVariations;
std::uint8_t lastColorVariation;
std::uint8_t primColor;
std::uint8_t secColor;
std::uint8_t tertColor;
std::uint8_t quatColor;
std::uint8_t upgrades[36];
std::uint8_t anRemapTXDs[8];
std::uint8_t field_302[2];
void* pAnimBlock; // CAnimBlock*
};

class CModelInfoSA : public CModelInfo
Expand Down Expand Up @@ -466,7 +485,7 @@ class CModelInfoSA : public CModelInfo
// Vehicle towing functions
bool IsTowableBy(CModelInfo* towingModel) override;

bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != 0xffff : false; };
bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != MODEL_PROPERTIES_GROUP_STATIC : false; };

private:
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CPlayerPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CPlayerInfoSA.h"
#include "CPlayerPedSA.h"
#include "CWorldSA.h"
#include "CProjectileInfoSA.h"

extern CCoreInterface* g_pCore;
extern CGameSA* pGame;
Expand Down Expand Up @@ -137,6 +138,7 @@ CPlayerPedSA::~CPlayerPedSA()
if ((DWORD)GetInterface()->vtbl != VTBL_CPlaceable)
{
CWorldSA* world = (CWorldSA*)pGame->GetWorld();
pGame->GetProjectileInfo()->RemoveEntityReferences(this);
world->Remove(m_pInterface, CPlayerPed_Destructor);

DWORD dwThis = (DWORD)m_pInterface;
Expand Down
15 changes: 15 additions & 0 deletions Client/game_sa/CProjectileInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,18 @@ DWORD CProjectileInfoSA::GetCounter()
{
return internalInterface->dwCounter - pGame->GetSystemTime();
}

void CProjectileInfoSA::RemoveEntityReferences(CEntity* entity)
{
const CEntitySAInterface* entityInterface = entity->GetInterface();
for (int i = 0; i < PROJECTILE_INFO_COUNT; i++)
{
auto projectileInterface = projectileInfo[i]->internalInterface;

if (projectileInterface->pEntProjectileOwner == entityInterface)
projectileInterface->pEntProjectileOwner = nullptr;

if (projectileInterface->pEntProjectileTarget == entityInterface)
projectileInterface->pEntProjectileTarget = nullptr;
}
}
4 changes: 3 additions & 1 deletion Client/game_sa/CProjectileInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CProjectileInfoSAInterface
};
// #pragma pack(pop)

class CProjectileInfoSA : public CProjectileInfo
// TODO extract manager class
class CProjectileInfoSA final : public CProjectileInfo
{
private:
CProjectileInfoSA* projectileInfo[PROJECTILE_INFO_COUNT];
Expand All @@ -65,6 +66,7 @@ class CProjectileInfoSA : public CProjectileInfo
CProjectileInfo* GetProjectileInfo(DWORD dwIndex);
bool AddProjectile(CEntity* creator, eWeaponType eWeapon, CVector vecOrigin, float fForce, CVector* target, CEntity* targetEntity);
CProjectile* GetProjectile(void* projectilePointer);
void RemoveEntityReferences(CEntity* entity);

CEntity* GetTarget();
void SetTarget(CEntity* pEntity);
Expand Down
14 changes: 14 additions & 0 deletions Client/game_sa/CSettingsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ void CSettingsSA::SetDynamicPedShadowsEnabled(bool bEnable)
m_bDynamicPedShadowsEnabled = bEnable;
}

bool CSettingsSA::IsDynamicPedShadowsEnabledByVideoSetting() const noexcept
{
bool pedDynamicShadows;
g_pCore->GetCVars()->Get("dynamic_ped_shadows", pedDynamicShadows);
return pedDynamicShadows;
}

bool CSettingsSA::ResetDynamicPedShadows() noexcept
{
pGame->GetSettings()->SetDynamicPedShadowsEnabled(pGame->GetSettings()->IsDynamicPedShadowsEnabledByVideoSetting());
return true;
}


//
// Volumetric shadow hooks
//
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CSettingsSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class CSettingsSA : public CGameSettings

bool IsDynamicPedShadowsEnabled();
void SetDynamicPedShadowsEnabled(bool bEnable);
bool IsDynamicPedShadowsEnabledByVideoSetting() const noexcept;
bool ResetDynamicPedShadows() noexcept;

float GetAspectRatioValue();
eAspectRatio GetAspectRatio();
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ CVehicleSA::~CVehicleSA()
}

CWorldSA* pWorld = (CWorldSA*)pGame->GetWorld();
pGame->GetProjectileInfo()->RemoveEntityReferences(this);
pWorld->Remove(m_pInterface, CVehicle_Destructor);
pWorld->RemoveReferencesToDeletedObject(m_pInterface);

Expand Down
Loading

0 comments on commit 27b9eae

Please sign in to comment.