From 36416b230951e7da2b65c4447f72622939fbfb38 Mon Sep 17 00:00:00 2001 From: G-Moris Date: Mon, 23 Dec 2024 18:11:21 +0300 Subject: [PATCH] Other fixes for #3848 (#3900) * Update * Update 2 * Update 3 --------- Co-authored-by: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> --- Client/game_sa/CGameSA.cpp | 337 ++++++++------- Client/game_sa/CHandlingEntrySA.cpp | 16 +- .../logic/luadefs/CLuaVehicleDefs.cpp | 398 +++++++++--------- Server/mods/deathmatch/logic/CGame.cpp | 2 +- Server/mods/deathmatch/logic/CGame.h | 4 +- .../logic/CStaticFunctionDefinitions.cpp | 54 +-- Server/mods/deathmatch/logic/CVehicle.cpp | 2 +- .../deathmatch/logic/luadefs/CLuaDefs.cpp | 4 +- .../mods/deathmatch/logic/luadefs/CLuaDefs.h | 2 +- .../logic/luadefs/CLuaHandlingDefs.cpp | 231 +++++----- 10 files changed, 543 insertions(+), 507 deletions(-) diff --git a/Client/game_sa/CGameSA.cpp b/Client/game_sa/CGameSA.cpp index dffc159313..c3eafa78d6 100644 --- a/Client/game_sa/CGameSA.cpp +++ b/Client/game_sa/CGameSA.cpp @@ -71,177 +71,202 @@ unsigned int OBJECTDYNAMICINFO_MAX = *(uint32_t*)0x59FB4C != 0x90909090 ? *(uint */ CGameSA::CGameSA() { - pGame = this; + try + { + pGame = this; - // Find the game version and initialize m_eGameVersion so GetGameVersion() will return the correct value - FindGameVersion(); + // Find the game version and initialize m_eGameVersion so GetGameVersion() will return the correct value + FindGameVersion(); - m_bAsyncScriptEnabled = false; - m_bAsyncScriptForced = false; - m_bASyncLoadingSuspended = false; - m_iCheckStatus = 0; + m_bAsyncScriptEnabled = false; + m_bAsyncScriptForced = false; + m_bASyncLoadingSuspended = false; + m_iCheckStatus = 0; - const unsigned int modelInfoMax = GetCountOfAllFileIDs(); - ModelInfo = new CModelInfoSA[modelInfoMax]; - ObjectGroupsInfo = new CObjectGroupPhysicalPropertiesSA[OBJECTDYNAMICINFO_MAX]; + const unsigned int modelInfoMax = GetCountOfAllFileIDs(); + ModelInfo = new CModelInfoSA[modelInfoMax]; + ObjectGroupsInfo = new CObjectGroupPhysicalPropertiesSA[OBJECTDYNAMICINFO_MAX]; - SetInitialVirtualProtect(); + SetInitialVirtualProtect(); - // Set the model ids for all the CModelInfoSA instances - for (unsigned int i = 0; i < modelInfoMax; i++) - { - ModelInfo[i].SetModelID(i); - } + // Set the model ids for all the CModelInfoSA instances + for (unsigned int i = 0; i < modelInfoMax; i++) + { + ModelInfo[i].SetModelID(i); + } - // Prepare all object dynamic infos for CObjectGroupPhysicalPropertiesSA instances - for (unsigned int i = 0; i < OBJECTDYNAMICINFO_MAX; i++) - { - ObjectGroupsInfo[i].SetGroup(i); - } + // Prepare all object dynamic infos for CObjectGroupPhysicalPropertiesSA instances + for (unsigned int i = 0; i < OBJECTDYNAMICINFO_MAX; i++) + { + ObjectGroupsInfo[i].SetGroup(i); + } - m_pAudioEngine = new CAudioEngineSA((CAudioEngineSAInterface*)CLASS_CAudioEngine); - m_pAEAudioHardware = new CAEAudioHardwareSA((CAEAudioHardwareSAInterface*)CLASS_CAEAudioHardware); - m_pAESoundManager = new CAESoundManagerSA((CAESoundManagerSAInterface*)CLASS_CAESoundManager); - m_pAudioContainer = new CAudioContainerSA(); - m_pWorld = new CWorldSA(); - m_Pools = std::make_unique(); - m_pClock = new CClockSA(); - m_pRadar = new CRadarSA(); - m_pCamera = new CCameraSA((CCameraSAInterface*)CLASS_CCamera); - m_pCoronas = new CCoronasSA(); - m_pCheckpoints = new CCheckpointsSA(); - m_pPickups = new CPickupsSA(); - m_pExplosionManager = new CExplosionManagerSA(); - m_pHud = new CHudSA(); - m_pFireManager = new CFireManagerSA(); - m_p3DMarkers = new C3DMarkersSA(); - m_pPad = new CPadSA((CPadSAInterface*)CLASS_CPad); - m_pCAERadioTrackManager = new CAERadioTrackManagerSA(); - m_pWeather = new CWeatherSA(); - m_pStats = new CStatsSA(); - m_pTaskManagementSystem = new CTaskManagementSystemSA(); - m_pSettings = new CSettingsSA(); - m_pCarEnterExit = new CCarEnterExitSA(); - m_pControllerConfigManager = new CControllerConfigManagerSA(); - m_pProjectileInfo = new CProjectileInfoSA(); - m_pRenderWare = new CRenderWareSA(); - m_HandlingManager = std::make_unique(); - m_pEventList = new CEventListSA(); - m_pGarages = new CGaragesSA((CGaragesSAInterface*)CLASS_CGarages); - m_pTasks = new CTasksSA((CTaskManagementSystemSA*)m_pTaskManagementSystem); - m_pAnimManager = new CAnimManagerSA; - m_pStreaming = new CStreamingSA; - m_pVisibilityPlugins = new CVisibilityPluginsSA; - m_pKeyGen = new CKeyGenSA; - m_pRopes = new CRopesSA; - m_pFx = new CFxSA((CFxSAInterface*)CLASS_CFx); - m_pFxManager = new CFxManagerSA((CFxManagerSAInterface*)CLASS_CFxManager); - m_pWaterManager = new CWaterManagerSA(); - m_pWeaponStatsManager = new CWeaponStatManagerSA(); - m_pPointLights = new CPointLightsSA(); - m_collisionStore = new CColStoreSA(); - m_pIplStore = new CIplStoreSA(); - m_pCoverManager = new CCoverManagerSA(); - m_pPlantManager = new CPlantManagerSA(); - m_pBuildingRemoval = new CBuildingRemovalSA(); - - m_pRenderer = std::make_unique(); - - // Normal weapon types (WEAPONSKILL_STD) - for (int i = 0; i < NUM_WeaponInfosStdSkill; i++) - { - eWeaponType weaponType = (eWeaponType)(WEAPONTYPE_PISTOL + i); - WeaponInfos[i] = new CWeaponInfoSA((CWeaponInfoSAInterface*)(ARRAY_WeaponInfo + i * CLASSSIZE_WeaponInfo), weaponType); - m_pWeaponStatsManager->CreateWeaponStat(WeaponInfos[i], (eWeaponType)(weaponType - WEAPONTYPE_PISTOL), WEAPONSKILL_STD); - } + m_pAudioEngine = new CAudioEngineSA((CAudioEngineSAInterface*)CLASS_CAudioEngine); + m_pAEAudioHardware = new CAEAudioHardwareSA((CAEAudioHardwareSAInterface*)CLASS_CAEAudioHardware); + m_pAESoundManager = new CAESoundManagerSA((CAESoundManagerSAInterface*)CLASS_CAESoundManager); + m_pAudioContainer = new CAudioContainerSA(); + m_pWorld = new CWorldSA(); + m_Pools = std::make_unique(); + m_pClock = new CClockSA(); + m_pRadar = new CRadarSA(); + m_pCamera = new CCameraSA((CCameraSAInterface*)CLASS_CCamera); + m_pCoronas = new CCoronasSA(); + m_pCheckpoints = new CCheckpointsSA(); + m_pPickups = new CPickupsSA(); + m_pExplosionManager = new CExplosionManagerSA(); + m_pHud = new CHudSA(); + m_pFireManager = new CFireManagerSA(); + m_p3DMarkers = new C3DMarkersSA(); + m_pPad = new CPadSA((CPadSAInterface*)CLASS_CPad); + m_pCAERadioTrackManager = new CAERadioTrackManagerSA(); + m_pWeather = new CWeatherSA(); + m_pStats = new CStatsSA(); + m_pTaskManagementSystem = new CTaskManagementSystemSA(); + m_pSettings = new CSettingsSA(); + m_pCarEnterExit = new CCarEnterExitSA(); + m_pControllerConfigManager = new CControllerConfigManagerSA(); + m_pProjectileInfo = new CProjectileInfoSA(); + m_pRenderWare = new CRenderWareSA(); + m_HandlingManager = std::make_unique(); + m_pEventList = new CEventListSA(); + m_pGarages = new CGaragesSA((CGaragesSAInterface*)CLASS_CGarages); + m_pTasks = new CTasksSA((CTaskManagementSystemSA*)m_pTaskManagementSystem); + m_pAnimManager = new CAnimManagerSA; + m_pStreaming = new CStreamingSA; + m_pVisibilityPlugins = new CVisibilityPluginsSA; + m_pKeyGen = new CKeyGenSA; + m_pRopes = new CRopesSA; + m_pFx = new CFxSA((CFxSAInterface*)CLASS_CFx); + m_pFxManager = new CFxManagerSA((CFxManagerSAInterface*)CLASS_CFxManager); + m_pWaterManager = new CWaterManagerSA(); + m_pWeaponStatsManager = new CWeaponStatManagerSA(); + m_pPointLights = new CPointLightsSA(); + m_collisionStore = new CColStoreSA(); + m_pIplStore = new CIplStoreSA(); + m_pCoverManager = new CCoverManagerSA(); + m_pPlantManager = new CPlantManagerSA(); + m_pBuildingRemoval = new CBuildingRemovalSA(); + + m_pRenderer = std::make_unique(); + + // Normal weapon types (WEAPONSKILL_STD) + for (int i = 0; i < NUM_WeaponInfosStdSkill; i++) + { + eWeaponType weaponType = (eWeaponType)(WEAPONTYPE_PISTOL + i); + WeaponInfos[i] = new CWeaponInfoSA((CWeaponInfoSAInterface*)(ARRAY_WeaponInfo + i * CLASSSIZE_WeaponInfo), weaponType); + m_pWeaponStatsManager->CreateWeaponStat(WeaponInfos[i], (eWeaponType)(weaponType - WEAPONTYPE_PISTOL), WEAPONSKILL_STD); + } - // Extra weapon types for skills (WEAPONSKILL_POOR,WEAPONSKILL_PRO,WEAPONSKILL_SPECIAL) - int index; - eWeaponSkill weaponSkill = eWeaponSkill::WEAPONSKILL_POOR; - for (int skill = 0; skill < 3; skill++) - { - // STD is created first, then it creates "extra weapon types" (poor, pro, special?) but in the enum 1 = STD which meant the STD weapon skill contained - // pro info - if (skill >= 1) + // Extra weapon types for skills (WEAPONSKILL_POOR,WEAPONSKILL_PRO,WEAPONSKILL_SPECIAL) + int index; + eWeaponSkill weaponSkill = eWeaponSkill::WEAPONSKILL_POOR; + for (int skill = 0; skill < 3; skill++) { - if (skill == 1) + // STD is created first, then it creates "extra weapon types" (poor, pro, special?) but in the enum 1 = STD which meant the STD weapon skill + // contained pro info + if (skill >= 1) { - weaponSkill = eWeaponSkill::WEAPONSKILL_PRO; + if (skill == 1) + { + weaponSkill = eWeaponSkill::WEAPONSKILL_PRO; + } + if (skill == 2) + { + weaponSkill = eWeaponSkill::WEAPONSKILL_SPECIAL; + } } - if (skill == 2) + for (int i = 0; i < NUM_WeaponInfosOtherSkill; i++) { - weaponSkill = eWeaponSkill::WEAPONSKILL_SPECIAL; + eWeaponType weaponType = (eWeaponType)(WEAPONTYPE_PISTOL + i); + index = NUM_WeaponInfosStdSkill + skill * NUM_WeaponInfosOtherSkill + i; + WeaponInfos[index] = new CWeaponInfoSA((CWeaponInfoSAInterface*)(ARRAY_WeaponInfo + index * CLASSSIZE_WeaponInfo), weaponType); + m_pWeaponStatsManager->CreateWeaponStat(WeaponInfos[index], weaponType, weaponSkill); } } - for (int i = 0; i < NUM_WeaponInfosOtherSkill; i++) - { - eWeaponType weaponType = (eWeaponType)(WEAPONTYPE_PISTOL + i); - index = NUM_WeaponInfosStdSkill + skill * NUM_WeaponInfosOtherSkill + i; - WeaponInfos[index] = new CWeaponInfoSA((CWeaponInfoSAInterface*)(ARRAY_WeaponInfo + index * CLASSSIZE_WeaponInfo), weaponType); - m_pWeaponStatsManager->CreateWeaponStat(WeaponInfos[index], weaponType, weaponSkill); - } - } - m_pPlayerInfo = new CPlayerInfoSA((CPlayerInfoSAInterface*)CLASS_CPlayerInfo); - - // Init cheat name => address map - m_Cheats[CHEAT_HOVERINGCARS] = new SCheatSA((BYTE*)VAR_HoveringCarsEnabled); - m_Cheats[CHEAT_FLYINGCARS] = new SCheatSA((BYTE*)VAR_FlyingCarsEnabled); - m_Cheats[CHEAT_EXTRABUNNYHOP] = new SCheatSA((BYTE*)VAR_ExtraBunnyhopEnabled); - m_Cheats[CHEAT_EXTRAJUMP] = new SCheatSA((BYTE*)VAR_ExtraJumpEnabled); - - // New cheats for Anticheat - m_Cheats[CHEAT_TANKMODE] = new SCheatSA((BYTE*)VAR_TankModeEnabled, false); - m_Cheats[CHEAT_NORELOAD] = new SCheatSA((BYTE*)VAR_NoReloadEnabled, false); - m_Cheats[CHEAT_PERFECTHANDLING] = new SCheatSA((BYTE*)VAR_PerfectHandling, false); - m_Cheats[CHEAT_ALLCARSHAVENITRO] = new SCheatSA((BYTE*)VAR_AllCarsHaveNitro, false); - m_Cheats[CHEAT_BOATSCANFLY] = new SCheatSA((BYTE*)VAR_BoatsCanFly, false); - m_Cheats[CHEAT_INFINITEOXYGEN] = new SCheatSA((BYTE*)VAR_InfiniteOxygen, false); - m_Cheats[CHEAT_WALKUNDERWATER] = new SCheatSA((BYTE*)VAR_WalkUnderwater, false); - m_Cheats[CHEAT_FASTERCLOCK] = new SCheatSA((BYTE*)VAR_FasterClock, false); - m_Cheats[CHEAT_FASTERGAMEPLAY] = new SCheatSA((BYTE*)VAR_FasterGameplay, false); - m_Cheats[CHEAT_SLOWERGAMEPLAY] = new SCheatSA((BYTE*)VAR_SlowerGameplay, false); - m_Cheats[CHEAT_ALWAYSMIDNIGHT] = new SCheatSA((BYTE*)VAR_AlwaysMidnight, false); - m_Cheats[CHEAT_FULLWEAPONAIMING] = new SCheatSA((BYTE*)VAR_FullWeaponAiming, false); - m_Cheats[CHEAT_INFINITEHEALTH] = new SCheatSA((BYTE*)VAR_InfiniteHealth, false); - m_Cheats[CHEAT_NEVERWANTED] = new SCheatSA((BYTE*)VAR_NeverWanted, false); - m_Cheats[CHEAT_HEALTARMORMONEY] = new SCheatSA((BYTE*)VAR_HealthArmorMoney, false); - - // Change pool sizes here - m_Pools->SetPoolCapacity(TASK_POOL, 5000); // Default is 500 - m_Pools->SetPoolCapacity(OBJECT_POOL, MAX_OBJECTS); // Default is 350 - m_Pools->SetPoolCapacity(EVENT_POOL, 5000); // Default is 200 - m_Pools->SetPoolCapacity(COL_MODEL_POOL, 12000); // Default is 10150 - m_Pools->SetPoolCapacity(ENV_MAP_MATERIAL_POOL, 16000); // Default is 4096 - m_Pools->SetPoolCapacity(ENV_MAP_ATOMIC_POOL, 4000); // Default is 1024 - m_Pools->SetPoolCapacity(SPEC_MAP_MATERIAL_POOL, 16000); // Default is 4096 - m_Pools->SetPoolCapacity(ENTRY_INFO_NODE_POOL, MAX_ENTRY_INFO_NODES); // Default is 500 - m_Pools->SetPoolCapacity(POINTER_SINGLE_LINK_POOL, MAX_POINTER_SINGLE_LINKS); // Default is 70000 - m_Pools->SetPoolCapacity(POINTER_DOUBLE_LINK_POOL, MAX_POINTER_DOUBLE_LINKS); // Default is 3200 - dassert(m_Pools->GetPoolCapacity(POINTER_SINGLE_LINK_POOL) == MAX_POINTER_SINGLE_LINKS); - - // Increase streaming object instances list size - MemPut(0x05B8E55, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 - MemPut(0x05B8EB0, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 - - // Increase matrix array size - MemPut(0x054F3A1, MAX_OBJECTS * 3); // Default is 900 - - CEntitySAInterface::StaticSetHooks(); - CPhysicalSAInterface::StaticSetHooks(); - CObjectSA::StaticSetHooks(); - CModelInfoSA::StaticSetHooks(); - CPlayerPedSA::StaticSetHooks(); - CRenderWareSA::StaticSetHooks(); - CRenderWareSA::StaticSetClothesReplacingHooks(); - CTasksSA::StaticSetHooks(); - CPedSA::StaticSetHooks(); - CSettingsSA::StaticSetHooks(); - CFxSystemSA::StaticSetHooks(); - CFileLoaderSA::StaticSetHooks(); - D3DResourceSystemSA::StaticSetHooks(); - CVehicleSA::StaticSetHooks(); - CCheckpointSA::StaticSetHooks(); + m_pPlayerInfo = new CPlayerInfoSA((CPlayerInfoSAInterface*)CLASS_CPlayerInfo); + + // Init cheat name => address map + m_Cheats[CHEAT_HOVERINGCARS] = new SCheatSA((BYTE*)VAR_HoveringCarsEnabled); + m_Cheats[CHEAT_FLYINGCARS] = new SCheatSA((BYTE*)VAR_FlyingCarsEnabled); + m_Cheats[CHEAT_EXTRABUNNYHOP] = new SCheatSA((BYTE*)VAR_ExtraBunnyhopEnabled); + m_Cheats[CHEAT_EXTRAJUMP] = new SCheatSA((BYTE*)VAR_ExtraJumpEnabled); + + // New cheats for Anticheat + m_Cheats[CHEAT_TANKMODE] = new SCheatSA((BYTE*)VAR_TankModeEnabled, false); + m_Cheats[CHEAT_NORELOAD] = new SCheatSA((BYTE*)VAR_NoReloadEnabled, false); + m_Cheats[CHEAT_PERFECTHANDLING] = new SCheatSA((BYTE*)VAR_PerfectHandling, false); + m_Cheats[CHEAT_ALLCARSHAVENITRO] = new SCheatSA((BYTE*)VAR_AllCarsHaveNitro, false); + m_Cheats[CHEAT_BOATSCANFLY] = new SCheatSA((BYTE*)VAR_BoatsCanFly, false); + m_Cheats[CHEAT_INFINITEOXYGEN] = new SCheatSA((BYTE*)VAR_InfiniteOxygen, false); + m_Cheats[CHEAT_WALKUNDERWATER] = new SCheatSA((BYTE*)VAR_WalkUnderwater, false); + m_Cheats[CHEAT_FASTERCLOCK] = new SCheatSA((BYTE*)VAR_FasterClock, false); + m_Cheats[CHEAT_FASTERGAMEPLAY] = new SCheatSA((BYTE*)VAR_FasterGameplay, false); + m_Cheats[CHEAT_SLOWERGAMEPLAY] = new SCheatSA((BYTE*)VAR_SlowerGameplay, false); + m_Cheats[CHEAT_ALWAYSMIDNIGHT] = new SCheatSA((BYTE*)VAR_AlwaysMidnight, false); + m_Cheats[CHEAT_FULLWEAPONAIMING] = new SCheatSA((BYTE*)VAR_FullWeaponAiming, false); + m_Cheats[CHEAT_INFINITEHEALTH] = new SCheatSA((BYTE*)VAR_InfiniteHealth, false); + m_Cheats[CHEAT_NEVERWANTED] = new SCheatSA((BYTE*)VAR_NeverWanted, false); + m_Cheats[CHEAT_HEALTARMORMONEY] = new SCheatSA((BYTE*)VAR_HealthArmorMoney, false); + + // Change pool sizes here + m_Pools->SetPoolCapacity(TASK_POOL, 5000); // Default is 500 + m_Pools->SetPoolCapacity(OBJECT_POOL, MAX_OBJECTS); // Default is 350 + m_Pools->SetPoolCapacity(EVENT_POOL, 5000); // Default is 200 + m_Pools->SetPoolCapacity(COL_MODEL_POOL, 12000); // Default is 10150 + m_Pools->SetPoolCapacity(ENV_MAP_MATERIAL_POOL, 16000); // Default is 4096 + m_Pools->SetPoolCapacity(ENV_MAP_ATOMIC_POOL, 4000); // Default is 1024 + m_Pools->SetPoolCapacity(SPEC_MAP_MATERIAL_POOL, 16000); // Default is 4096 + m_Pools->SetPoolCapacity(ENTRY_INFO_NODE_POOL, MAX_ENTRY_INFO_NODES); // Default is 500 + m_Pools->SetPoolCapacity(POINTER_SINGLE_LINK_POOL, MAX_POINTER_SINGLE_LINKS); // Default is 70000 + m_Pools->SetPoolCapacity(POINTER_DOUBLE_LINK_POOL, MAX_POINTER_DOUBLE_LINKS); // Default is 3200 + dassert(m_Pools->GetPoolCapacity(POINTER_SINGLE_LINK_POOL) == MAX_POINTER_SINGLE_LINKS); + + // Increase streaming object instances list size + MemPut(0x05B8E55, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 + MemPut(0x05B8EB0, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 + + // Increase matrix array size + MemPut(0x054F3A1, MAX_OBJECTS * 3); // Default is 900 + + CEntitySAInterface::StaticSetHooks(); + CPhysicalSAInterface::StaticSetHooks(); + CObjectSA::StaticSetHooks(); + CModelInfoSA::StaticSetHooks(); + CPlayerPedSA::StaticSetHooks(); + CRenderWareSA::StaticSetHooks(); + CRenderWareSA::StaticSetClothesReplacingHooks(); + CTasksSA::StaticSetHooks(); + CPedSA::StaticSetHooks(); + CSettingsSA::StaticSetHooks(); + CFxSystemSA::StaticSetHooks(); + CFileLoaderSA::StaticSetHooks(); + D3DResourceSystemSA::StaticSetHooks(); + CVehicleSA::StaticSetHooks(); + CCheckpointSA::StaticSetHooks(); + } + catch (const std::bad_alloc& e) + { + std::string error = _("Failed initialization game_sa"); + error += "\n"; + error += _("Memory allocations failed"); + error += ": "; + error += e.what(); + + MessageBoxUTF8(nullptr, error.c_str(), _("Error"), MB_ICONERROR | MB_OK); + ExitProcess(EXIT_FAILURE); + } + catch (const std::exception& e) + { + std::string error = _("Failed initialization game_sa"); + error += "\n"; + error += _("Information"); + error += ": "; + error += e.what(); + + MessageBoxUTF8(nullptr, error, _("Error"), MB_ICONERROR | MB_OK); + ExitProcess(EXIT_FAILURE); + } } CGameSA::~CGameSA() diff --git a/Client/game_sa/CHandlingEntrySA.cpp b/Client/game_sa/CHandlingEntrySA.cpp index 3cc2987f82..3e38045dda 100644 --- a/Client/game_sa/CHandlingEntrySA.cpp +++ b/Client/game_sa/CHandlingEntrySA.cpp @@ -21,7 +21,7 @@ CHandlingEntrySA::CHandlingEntrySA() // Create a new interface and zero it if (m_HandlingSA = std::make_unique()) { - MemSet(m_HandlingSA.get(), 0, sizeof(tHandlingDataSA)); + MemSetFast(m_HandlingSA.get(), 0, sizeof(tHandlingDataSA)); } } @@ -31,7 +31,7 @@ CHandlingEntrySA::CHandlingEntrySA(const tHandlingDataSA* const pOriginal) m_HandlingSA = nullptr; if (pOriginal) { - MemCpy(&m_Handling, pOriginal, sizeof(tHandlingDataSA)); + MemCpyFast(&m_Handling, pOriginal, sizeof(tHandlingDataSA)); } } @@ -52,15 +52,9 @@ void CHandlingEntrySA::Recalculate() noexcept if (!m_HandlingSA) return; - try - { - // Copy our stored field to GTA's - MemCpy(m_HandlingSA.get(), &m_Handling, sizeof(m_Handling)); - ((void(_stdcall*)(tHandlingDataSA*))FUNC_HandlingDataMgr_ConvertDataToGameUnits)(m_HandlingSA.get()); - } - catch (...) - { - } + // Copy our stored field to GTA's + MemCpyFast(m_HandlingSA.get(), &m_Handling, sizeof(m_Handling)); + ((void(_stdcall*)(tHandlingDataSA*))FUNC_HandlingDataMgr_ConvertDataToGameUnits)(m_HandlingSA.get()); } void CHandlingEntrySA::SetSuspensionForceLevel(float fForce) noexcept diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 0f9fcba457..551bfb222d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -13,6 +13,7 @@ #include #include #include "lua/CLuaFunctionParser.h" +#include void CLuaVehicleDefs::LoadFunctions() { @@ -2657,7 +2658,7 @@ int CLuaVehicleDefs::SetVehicleHandling(lua_State* luaVM) int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM) { // table getVehicleHandling ( element theVehicle, [ string property ] ) - CClientVehicle* pVehicle = NULL; + CClientVehicle* pVehicle = nullptr; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pVehicle); @@ -2668,50 +2669,55 @@ int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM) SString strProperty; argStream.ReadString(strProperty); + bool bResult = true; eHandlingProperty eProperty = g_pGame->GetHandlingManager()->GetPropertyEnumFromName(strProperty); - if (eProperty == HANDLING_MAX) - { - argStream.SetCustomError("Invalid property"); - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; - } - - float fValue = 0.0f; - CVector vecValue = CVector(0.0f, 0.0f, 0.0f); - SString strValue = ""; - unsigned int uiValue = 0; - unsigned char ucValue = 0; - if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue)) - { - lua_pushnumber(luaVM, fValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue)) - { - lua_pushnumber(luaVM, uiValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue)) - { - lua_pushnumber(luaVM, ucValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue)) + if (eProperty != HANDLING_MAX) { - lua_pushstring(luaVM, strValue); + float fValue = 0.0f; + CVector vecValue = CVector(0.0f, 0.0f, 0.0f); + SString strValue = ""; + unsigned int uiValue = 0; + unsigned char ucValue = 0; + if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue)) + { + lua_pushnumber(luaVM, fValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue)) + { + lua_pushnumber(luaVM, uiValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue)) + { + lua_pushnumber(luaVM, ucValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue)) + { + lua_pushstring(luaVM, strValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue)) + { + lua_createtable(luaVM, 3, 0); + lua_pushnumber(luaVM, 1); + lua_pushnumber(luaVM, vecValue.fX); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 2); + lua_pushnumber(luaVM, vecValue.fY); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 3); + lua_pushnumber(luaVM, vecValue.fZ); + lua_settable(luaVM, -3); + } + else + { + bResult = false; + } } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue)) + else { - lua_createtable(luaVM, 3, 0); - lua_pushnumber(luaVM, 1); - lua_pushnumber(luaVM, vecValue.fX); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 2); - lua_pushnumber(luaVM, vecValue.fY); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 3); - lua_pushnumber(luaVM, vecValue.fZ); - lua_settable(luaVM, -3); + bResult = false; } - else + + if (!bResult) { argStream.SetCustomError("Invalid property"); m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); @@ -2719,149 +2725,157 @@ int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM) } return 1; } - CHandlingEntry* pEntry = pVehicle->GetHandlingData(); - lua_newtable(luaVM); + if (const auto* const entry = pVehicle->GetHandlingData()) + { + lua_newtable(luaVM); - lua_pushnumber(luaVM, pEntry->GetMass()); - lua_setfield(luaVM, -2, "mass"); - - lua_pushnumber(luaVM, pEntry->GetTurnMass()); - lua_setfield(luaVM, -2, "turnMass"); - - lua_pushnumber(luaVM, pEntry->GetDragCoeff()); - lua_setfield(luaVM, -2, "dragCoeff"); - - lua_createtable(luaVM, 3, 0); - CVector vecCenter = pEntry->GetCenterOfMass(); - lua_pushnumber(luaVM, 1); - lua_pushnumber(luaVM, vecCenter.fX); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 2); - lua_pushnumber(luaVM, vecCenter.fY); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 3); - lua_pushnumber(luaVM, vecCenter.fZ); - lua_settable(luaVM, -3); - lua_setfield(luaVM, -2, "centerOfMass"); - - lua_pushnumber(luaVM, pEntry->GetPercentSubmerged()); - lua_setfield(luaVM, -2, "percentSubmerged"); - - lua_pushnumber(luaVM, pEntry->GetTractionMultiplier()); - lua_setfield(luaVM, -2, "tractionMultiplier"); - - CHandlingEntry::eDriveType eDriveType = pEntry->GetCarDriveType(); - if (eDriveType == CHandlingEntry::FWD) - lua_pushstring(luaVM, "fwd"); - else if (eDriveType == CHandlingEntry::RWD) - lua_pushstring(luaVM, "rwd"); - else if (eDriveType == CHandlingEntry::FOURWHEEL) - lua_pushstring(luaVM, "awd"); - else // What the ... (yeah, security) - lua_pushnil(luaVM); - lua_setfield(luaVM, -2, "driveType"); - CHandlingEntry::eEngineType eEngineType = pEntry->GetCarEngineType(); - if (eEngineType == CHandlingEntry::PETROL) - lua_pushstring(luaVM, "petrol"); - else if (eEngineType == CHandlingEntry::DIESEL) - lua_pushstring(luaVM, "diesel"); - else if (eEngineType == CHandlingEntry::ELECTRIC) - lua_pushstring(luaVM, "electric"); - else - lua_pushnil(luaVM); - lua_setfield(luaVM, -2, "engineType"); + lua_pushnumber(luaVM, entry->GetMass()); + lua_setfield(luaVM, -2, "mass"); + + lua_pushnumber(luaVM, entry->GetTurnMass()); + lua_setfield(luaVM, -2, "turnMass"); + + lua_pushnumber(luaVM, entry->GetDragCoeff()); + lua_setfield(luaVM, -2, "dragCoeff"); + + lua_createtable(luaVM, 3, 0); + CVector vecCenter = entry->GetCenterOfMass(); + lua_pushnumber(luaVM, 1); + lua_pushnumber(luaVM, vecCenter.fX); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 2); + lua_pushnumber(luaVM, vecCenter.fY); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 3); + lua_pushnumber(luaVM, vecCenter.fZ); + lua_settable(luaVM, -3); + lua_setfield(luaVM, -2, "centerOfMass"); + + lua_pushnumber(luaVM, entry->GetPercentSubmerged()); + lua_setfield(luaVM, -2, "percentSubmerged"); + + lua_pushnumber(luaVM, entry->GetTractionMultiplier()); + lua_setfield(luaVM, -2, "tractionMultiplier"); + + CHandlingEntry::eDriveType eDriveType = entry->GetCarDriveType(); + if (eDriveType == CHandlingEntry::FWD) + lua_pushstring(luaVM, "fwd"); + else if (eDriveType == CHandlingEntry::RWD) + lua_pushstring(luaVM, "rwd"); + else if (eDriveType == CHandlingEntry::FOURWHEEL) + lua_pushstring(luaVM, "awd"); + else // What the ... (yeah, security) + lua_pushnil(luaVM); + lua_setfield(luaVM, -2, "driveType"); + CHandlingEntry::eEngineType eEngineType = entry->GetCarEngineType(); + if (eEngineType == CHandlingEntry::PETROL) + lua_pushstring(luaVM, "petrol"); + else if (eEngineType == CHandlingEntry::DIESEL) + lua_pushstring(luaVM, "diesel"); + else if (eEngineType == CHandlingEntry::ELECTRIC) + lua_pushstring(luaVM, "electric"); + else + lua_pushnil(luaVM); + lua_setfield(luaVM, -2, "engineType"); - lua_pushnumber(luaVM, pEntry->GetNumberOfGears()); - lua_setfield(luaVM, -2, "numberOfGears"); + lua_pushnumber(luaVM, entry->GetNumberOfGears()); + lua_setfield(luaVM, -2, "numberOfGears"); - lua_pushnumber(luaVM, pEntry->GetEngineAcceleration()); - lua_setfield(luaVM, -2, "engineAcceleration"); + lua_pushnumber(luaVM, entry->GetEngineAcceleration()); + lua_setfield(luaVM, -2, "engineAcceleration"); - lua_pushnumber(luaVM, pEntry->GetEngineInertia()); - lua_setfield(luaVM, -2, "engineInertia"); + lua_pushnumber(luaVM, entry->GetEngineInertia()); + lua_setfield(luaVM, -2, "engineInertia"); - lua_pushnumber(luaVM, pEntry->GetMaxVelocity()); - lua_setfield(luaVM, -2, "maxVelocity"); + lua_pushnumber(luaVM, entry->GetMaxVelocity()); + lua_setfield(luaVM, -2, "maxVelocity"); - lua_pushnumber(luaVM, pEntry->GetBrakeDeceleration()); - lua_setfield(luaVM, -2, "brakeDeceleration"); + lua_pushnumber(luaVM, entry->GetBrakeDeceleration()); + lua_setfield(luaVM, -2, "brakeDeceleration"); - lua_pushnumber(luaVM, pEntry->GetBrakeBias()); - lua_setfield(luaVM, -2, "brakeBias"); + lua_pushnumber(luaVM, entry->GetBrakeBias()); + lua_setfield(luaVM, -2, "brakeBias"); - lua_pushboolean(luaVM, pEntry->GetABS()); - lua_setfield(luaVM, -2, "ABS"); + lua_pushboolean(luaVM, entry->GetABS()); + lua_setfield(luaVM, -2, "ABS"); - lua_pushnumber(luaVM, pEntry->GetSteeringLock()); - lua_setfield(luaVM, -2, "steeringLock"); + lua_pushnumber(luaVM, entry->GetSteeringLock()); + lua_setfield(luaVM, -2, "steeringLock"); - lua_pushnumber(luaVM, pEntry->GetTractionLoss()); - lua_setfield(luaVM, -2, "tractionLoss"); + lua_pushnumber(luaVM, entry->GetTractionLoss()); + lua_setfield(luaVM, -2, "tractionLoss"); - lua_pushnumber(luaVM, pEntry->GetTractionBias()); - lua_setfield(luaVM, -2, "tractionBias"); + lua_pushnumber(luaVM, entry->GetTractionBias()); + lua_setfield(luaVM, -2, "tractionBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionForceLevel()); - lua_setfield(luaVM, -2, "suspensionForceLevel"); + lua_pushnumber(luaVM, entry->GetSuspensionForceLevel()); + lua_setfield(luaVM, -2, "suspensionForceLevel"); - lua_pushnumber(luaVM, pEntry->GetSuspensionDamping()); - lua_setfield(luaVM, -2, "suspensionDamping"); + lua_pushnumber(luaVM, entry->GetSuspensionDamping()); + lua_setfield(luaVM, -2, "suspensionDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionHighSpeedDamping()); - lua_setfield(luaVM, -2, "suspensionHighSpeedDamping"); + lua_pushnumber(luaVM, entry->GetSuspensionHighSpeedDamping()); + lua_setfield(luaVM, -2, "suspensionHighSpeedDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionUpperLimit()); - lua_setfield(luaVM, -2, "suspensionUpperLimit"); + lua_pushnumber(luaVM, entry->GetSuspensionUpperLimit()); + lua_setfield(luaVM, -2, "suspensionUpperLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionLowerLimit()); - lua_setfield(luaVM, -2, "suspensionLowerLimit"); + lua_pushnumber(luaVM, entry->GetSuspensionLowerLimit()); + lua_setfield(luaVM, -2, "suspensionLowerLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionFrontRearBias()); - lua_setfield(luaVM, -2, "suspensionFrontRearBias"); + lua_pushnumber(luaVM, entry->GetSuspensionFrontRearBias()); + lua_setfield(luaVM, -2, "suspensionFrontRearBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionAntiDiveMultiplier()); - lua_setfield(luaVM, -2, "suspensionAntiDiveMultiplier"); + lua_pushnumber(luaVM, entry->GetSuspensionAntiDiveMultiplier()); + lua_setfield(luaVM, -2, "suspensionAntiDiveMultiplier"); - lua_pushnumber(luaVM, pEntry->GetCollisionDamageMultiplier()); - lua_setfield(luaVM, -2, "collisionDamageMultiplier"); + lua_pushnumber(luaVM, entry->GetCollisionDamageMultiplier()); + lua_setfield(luaVM, -2, "collisionDamageMultiplier"); - lua_pushnumber(luaVM, pEntry->GetSeatOffsetDistance()); - lua_setfield(luaVM, -2, "seatOffsetDistance"); + lua_pushnumber(luaVM, entry->GetSeatOffsetDistance()); + lua_setfield(luaVM, -2, "seatOffsetDistance"); - lua_pushnumber(luaVM, pEntry->GetHandlingFlags()); - lua_setfield(luaVM, -2, "handlingFlags"); + lua_pushnumber(luaVM, entry->GetHandlingFlags()); + lua_setfield(luaVM, -2, "handlingFlags"); - lua_pushnumber(luaVM, pEntry->GetModelFlags()); - lua_setfield(luaVM, -2, "modelFlags"); + lua_pushnumber(luaVM, entry->GetModelFlags()); + lua_setfield(luaVM, -2, "modelFlags"); - lua_pushnumber(luaVM, pEntry->GetMonetary()); - lua_setfield(luaVM, -2, "monetary"); + lua_pushnumber(luaVM, entry->GetMonetary()); + lua_setfield(luaVM, -2, "monetary"); - CHandlingEntry::eLightType eHeadType = pEntry->GetHeadLight(); - if (eHeadType == CHandlingEntry::LONG) - lua_pushstring(luaVM, "long"); - else if (eHeadType == CHandlingEntry::SMALL) - lua_pushstring(luaVM, "small"); - else if (eHeadType == CHandlingEntry::BIG) - lua_pushstring(luaVM, "big"); - else - lua_pushnil(luaVM); - lua_setfield(luaVM, -2, "headLight"); - - CHandlingEntry::eLightType eTailType = pEntry->GetTailLight(); - if (eTailType == CHandlingEntry::LONG) - lua_pushstring(luaVM, "long"); - else if (eTailType == CHandlingEntry::SMALL) - lua_pushstring(luaVM, "small"); - else if (eTailType == CHandlingEntry::BIG) - lua_pushstring(luaVM, "big"); - else - lua_pushnil(luaVM); - lua_setfield(luaVM, -2, "tailLight"); + CHandlingEntry::eLightType eHeadType = entry->GetHeadLight(); + if (eHeadType == CHandlingEntry::LONG) + lua_pushstring(luaVM, "long"); + else if (eHeadType == CHandlingEntry::SMALL) + lua_pushstring(luaVM, "small"); + else if (eHeadType == CHandlingEntry::BIG) + lua_pushstring(luaVM, "big"); + else + lua_pushnil(luaVM); + lua_setfield(luaVM, -2, "headLight"); + + CHandlingEntry::eLightType eTailType = entry->GetTailLight(); + if (eTailType == CHandlingEntry::LONG) + lua_pushstring(luaVM, "long"); + else if (eTailType == CHandlingEntry::SMALL) + lua_pushstring(luaVM, "small"); + else if (eTailType == CHandlingEntry::BIG) + lua_pushstring(luaVM, "big"); + else + lua_pushnil(luaVM); + lua_setfield(luaVM, -2, "tailLight"); - lua_pushnumber(luaVM, pEntry->GetAnimGroup()); - lua_setfield(luaVM, -2, "animGroup"); + lua_pushnumber(luaVM, entry->GetAnimGroup()); + lua_setfield(luaVM, -2, "animGroup"); + } + else + { + argStream.SetCustomError("Invalid handling data"); + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM, false); + } return 1; } else @@ -2880,19 +2894,19 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) if (!argStream.HasErrors()) { - if (uiModel) + if (CClientVehicleManager::IsValidModel(uiModel)) { - if (const CHandlingEntry* pEntry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(uiModel)) + if (const auto* const entry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(uiModel)) { lua_newtable(luaVM); - lua_pushnumber(luaVM, pEntry->GetMass()); + lua_pushnumber(luaVM, entry->GetMass()); lua_setfield(luaVM, -2, "mass"); - lua_pushnumber(luaVM, pEntry->GetTurnMass()); + lua_pushnumber(luaVM, entry->GetTurnMass()); lua_setfield(luaVM, -2, "turnMass"); - lua_pushnumber(luaVM, pEntry->GetDragCoeff()); + lua_pushnumber(luaVM, entry->GetDragCoeff()); lua_setfield(luaVM, -2, "dragCoeff"); lua_createtable(luaVM, 3, 0); - CVector vecCenter = pEntry->GetCenterOfMass(); + CVector vecCenter = entry->GetCenterOfMass(); lua_pushnumber(luaVM, 1); lua_pushnumber(luaVM, vecCenter.fX); lua_settable(luaVM, -3); @@ -2903,11 +2917,11 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) lua_pushnumber(luaVM, vecCenter.fZ); lua_settable(luaVM, -3); lua_setfield(luaVM, -2, "centerOfMass"); - lua_pushnumber(luaVM, pEntry->GetPercentSubmerged()); + lua_pushnumber(luaVM, entry->GetPercentSubmerged()); lua_setfield(luaVM, -2, "percentSubmerged"); - lua_pushnumber(luaVM, pEntry->GetTractionMultiplier()); + lua_pushnumber(luaVM, entry->GetTractionMultiplier()); lua_setfield(luaVM, -2, "tractionMultiplier"); - CHandlingEntry::eDriveType eDriveType = pEntry->GetCarDriveType(); + CHandlingEntry::eDriveType eDriveType = entry->GetCarDriveType(); if (eDriveType == CHandlingEntry::FWD) lua_pushstring(luaVM, "fwd"); else if (eDriveType == CHandlingEntry::RWD) @@ -2917,7 +2931,7 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) else // What the ... (yeah, security) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "driveType"); - CHandlingEntry::eEngineType eEngineType = pEntry->GetCarEngineType(); + CHandlingEntry::eEngineType eEngineType = entry->GetCarEngineType(); if (eEngineType == CHandlingEntry::PETROL) lua_pushstring(luaVM, "petrol"); else if (eEngineType == CHandlingEntry::DIESEL) @@ -2927,51 +2941,51 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "engineType"); - lua_pushnumber(luaVM, pEntry->GetNumberOfGears()); + lua_pushnumber(luaVM, entry->GetNumberOfGears()); lua_setfield(luaVM, -2, "numberOfGears"); - lua_pushnumber(luaVM, pEntry->GetEngineAcceleration()); + lua_pushnumber(luaVM, entry->GetEngineAcceleration()); lua_setfield(luaVM, -2, "engineAcceleration"); - lua_pushnumber(luaVM, pEntry->GetEngineInertia()); + lua_pushnumber(luaVM, entry->GetEngineInertia()); lua_setfield(luaVM, -2, "engineInertia"); - lua_pushnumber(luaVM, pEntry->GetMaxVelocity()); + lua_pushnumber(luaVM, entry->GetMaxVelocity()); lua_setfield(luaVM, -2, "maxVelocity"); - lua_pushnumber(luaVM, pEntry->GetBrakeDeceleration()); + lua_pushnumber(luaVM, entry->GetBrakeDeceleration()); lua_setfield(luaVM, -2, "brakeDeceleration"); - lua_pushnumber(luaVM, pEntry->GetBrakeBias()); + lua_pushnumber(luaVM, entry->GetBrakeBias()); lua_setfield(luaVM, -2, "brakeBias"); - lua_pushboolean(luaVM, pEntry->GetABS()); + lua_pushboolean(luaVM, entry->GetABS()); lua_setfield(luaVM, -2, "ABS"); - lua_pushnumber(luaVM, pEntry->GetSteeringLock()); + lua_pushnumber(luaVM, entry->GetSteeringLock()); lua_setfield(luaVM, -2, "steeringLock"); - lua_pushnumber(luaVM, pEntry->GetTractionLoss()); + lua_pushnumber(luaVM, entry->GetTractionLoss()); lua_setfield(luaVM, -2, "tractionLoss"); - lua_pushnumber(luaVM, pEntry->GetTractionBias()); + lua_pushnumber(luaVM, entry->GetTractionBias()); lua_setfield(luaVM, -2, "tractionBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionForceLevel()); + lua_pushnumber(luaVM, entry->GetSuspensionForceLevel()); lua_setfield(luaVM, -2, "suspensionForceLevel"); - lua_pushnumber(luaVM, pEntry->GetSuspensionDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionDamping()); lua_setfield(luaVM, -2, "suspensionDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionHighSpeedDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionHighSpeedDamping()); lua_setfield(luaVM, -2, "suspensionHighSpeedDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionUpperLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionUpperLimit()); lua_setfield(luaVM, -2, "suspensionUpperLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionLowerLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionLowerLimit()); lua_setfield(luaVM, -2, "suspensionLowerLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionFrontRearBias()); + lua_pushnumber(luaVM, entry->GetSuspensionFrontRearBias()); lua_setfield(luaVM, -2, "suspensionFrontRearBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionAntiDiveMultiplier()); + lua_pushnumber(luaVM, entry->GetSuspensionAntiDiveMultiplier()); lua_setfield(luaVM, -2, "suspensionAntiDiveMultiplier"); - lua_pushnumber(luaVM, pEntry->GetCollisionDamageMultiplier()); + lua_pushnumber(luaVM, entry->GetCollisionDamageMultiplier()); lua_setfield(luaVM, -2, "collisionDamageMultiplier"); - lua_pushnumber(luaVM, pEntry->GetSeatOffsetDistance()); + lua_pushnumber(luaVM, entry->GetSeatOffsetDistance()); lua_setfield(luaVM, -2, "seatOffsetDistance"); - lua_pushnumber(luaVM, pEntry->GetHandlingFlags()); + lua_pushnumber(luaVM, entry->GetHandlingFlags()); lua_setfield(luaVM, -2, "handlingFlags"); - lua_pushnumber(luaVM, pEntry->GetModelFlags()); + lua_pushnumber(luaVM, entry->GetModelFlags()); lua_setfield(luaVM, -2, "modelFlags"); - lua_pushnumber(luaVM, pEntry->GetMonetary()); + lua_pushnumber(luaVM, entry->GetMonetary()); lua_setfield(luaVM, -2, "monetary"); - CHandlingEntry::eLightType eHeadType = pEntry->GetHeadLight(); + CHandlingEntry::eLightType eHeadType = entry->GetHeadLight(); if (eHeadType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eHeadType == CHandlingEntry::SMALL) @@ -2981,7 +2995,7 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "headLight"); - CHandlingEntry::eLightType eTailType = pEntry->GetTailLight(); + CHandlingEntry::eLightType eTailType = entry->GetTailLight(); if (eTailType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eTailType == CHandlingEntry::SMALL) @@ -2991,7 +3005,7 @@ int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "tailLight"); - lua_pushnumber(luaVM, pEntry->GetAnimGroup()); + lua_pushnumber(luaVM, entry->GetAnimGroup()); lua_setfield(luaVM, -2, "animGroup"); return 1; } diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index ec09e810ae..1bcdf5ce66 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -595,7 +595,7 @@ bool CGame::Start(int iArgumentCount, char* szArguments[]) m_pPlayerManager = new CPlayerManager; m_pRadarAreaManager = new CRadarAreaManager; m_pMarkerManager = new CMarkerManager(m_pColManager); - m_HandlingManager = std::make_shared(); + m_HandlingManager = std::make_unique(); m_pVehicleManager = new CVehicleManager; m_pPacketTranslator = new CPacketTranslator(m_pPlayerManager); m_pBanManager = new CBanManager; diff --git a/Server/mods/deathmatch/logic/CGame.h b/Server/mods/deathmatch/logic/CGame.h index c68cc7dbff..c4344a8180 100644 --- a/Server/mods/deathmatch/logic/CGame.h +++ b/Server/mods/deathmatch/logic/CGame.h @@ -216,7 +216,7 @@ class CGame bool IsFinished() { return m_bIsFinished; }; CMainConfig* GetConfig() { return m_pMainConfig; } - std::shared_ptr GetHandlingManager() { return m_HandlingManager; } + CHandlingManager* GetHandlingManager() const noexcept { return m_HandlingManager.get(); } CMapManager* GetMapManager() { return m_pMapManager; } CPlayerManager* GetPlayerManager() { return m_pPlayerManager; } CObjectManager* GetObjectManager() { return m_pObjectManager; } @@ -571,7 +571,7 @@ class CGame CSettings* m_pSettings; CZoneNames* m_pZoneNames; ASE* m_pASE; - std::shared_ptr m_HandlingManager; + std::unique_ptr m_HandlingManager; CRPCFunctions* m_pRPCFunctions; CLanBroadcast* m_pLanBroadcast; CWaterManager* m_pWaterManager; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index a21f9ad706..6e1c06d124 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -100,7 +100,7 @@ static CBanManager* m_pBanManager; static CPedManager* m_pPedManager; static CWaterManager* m_pWaterManager; static CCustomWeaponManager* m_pCustomWeaponManager; -static std::shared_ptr m_HandlingManager; +static CHandlingManager* m_pHandlingManager; // Used to run a function on all the children of the elements too #define RUN_CHILDREN(func) \ @@ -135,7 +135,7 @@ CStaticFunctionDefinitions::CStaticFunctionDefinitions(CGame* pGame) m_pPedManager = pGame->GetPedManager(); m_pWaterManager = pGame->GetWaterManager(); m_pCustomWeaponManager = pGame->GetCustomWeaponManager(); - m_HandlingManager = pGame->GetHandlingManager(); + m_pHandlingManager = pGame->GetHandlingManager(); } CStaticFunctionDefinitions::~CStaticFunctionDefinitions() @@ -5492,11 +5492,11 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling const CHandlingEntry* pEntry = nullptr; if (bOriginal) { - pEntry = m_HandlingManager->GetOriginalHandlingData(model); + pEntry = m_pHandlingManager->GetOriginalHandlingData(model); } else { - pEntry = m_HandlingManager->GetModelHandlingData(model); + pEntry = m_pHandlingManager->GetModelHandlingData(model); } if (!pEntry) @@ -5516,11 +5516,11 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling const CHandlingEntry* pEntry = nullptr; if (bOriginal) { - pEntry = m_HandlingManager->GetOriginalHandlingData(model); + pEntry = m_pHandlingManager->GetOriginalHandlingData(model); } else { - pEntry = m_HandlingManager->GetModelHandlingData(model); + pEntry = m_pHandlingManager->GetModelHandlingData(model); } if (!pEntry) @@ -5534,11 +5534,11 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling const CHandlingEntry* pEntry = nullptr; if (bOriginal) { - pEntry = m_HandlingManager->GetOriginalHandlingData(model); + pEntry = m_pHandlingManager->GetOriginalHandlingData(model); } else { - pEntry = m_HandlingManager->GetModelHandlingData(model); + pEntry = m_pHandlingManager->GetModelHandlingData(model); } if (!pEntry) @@ -5552,11 +5552,11 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling const CHandlingEntry* pEntry = nullptr; if (bOriginal) { - pEntry = m_HandlingManager->GetOriginalHandlingData(model); + pEntry = m_pHandlingManager->GetOriginalHandlingData(model); } else { - pEntry = m_HandlingManager->GetModelHandlingData(model); + pEntry = m_pHandlingManager->GetModelHandlingData(model); } if (!pEntry) @@ -5570,11 +5570,11 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling const CHandlingEntry* pEntry = nullptr; if (bOriginal) { - pEntry = m_HandlingManager->GetOriginalHandlingData(model); + pEntry = m_pHandlingManager->GetOriginalHandlingData(model); } else { - pEntry = m_HandlingManager->GetModelHandlingData(model); + pEntry = m_pHandlingManager->GetModelHandlingData(model); } if (!pEntry) @@ -5585,66 +5585,66 @@ bool CStaticFunctionDefinitions::GetModelHandling(std::uint32_t model, eHandling bool CStaticFunctionDefinitions::SetModelHandling(std::uint32_t model, eHandlingProperty eProperty, float fValue) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; if (!SetEntryHandling(pEntry, eProperty, fValue)) return false; - m_HandlingManager->SetModelHandlingHasChanged(model, true); + m_pHandlingManager->SetModelHandlingHasChanged(model, true); return true; } bool CStaticFunctionDefinitions::SetModelHandling(std::uint32_t model, eHandlingProperty eProperty, CVector vecValue) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; if (!SetEntryHandling(pEntry, eProperty, vecValue)) return false; - m_HandlingManager->SetModelHandlingHasChanged(model, true); + m_pHandlingManager->SetModelHandlingHasChanged(model, true); return true; } bool CStaticFunctionDefinitions::SetModelHandling(std::uint32_t model, eHandlingProperty eProperty, std::string strValue) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; if (!SetEntryHandling(pEntry, eProperty, strValue)) return false; - m_HandlingManager->SetModelHandlingHasChanged(model, true); + m_pHandlingManager->SetModelHandlingHasChanged(model, true); return true; } bool CStaticFunctionDefinitions::SetModelHandling(std::uint32_t model, eHandlingProperty eProperty, unsigned char ucValue) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; if (!SetEntryHandling(pEntry, eProperty, ucValue)) return false; - m_HandlingManager->SetModelHandlingHasChanged(model, true); + m_pHandlingManager->SetModelHandlingHasChanged(model, true); return true; } bool CStaticFunctionDefinitions::SetModelHandling(std::uint32_t model, eHandlingProperty eProperty, unsigned int uiValue) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; if (!SetEntryHandling(pEntry, eProperty, uiValue)) return false; - m_HandlingManager->SetModelHandlingHasChanged(model, true); + m_pHandlingManager->SetModelHandlingHasChanged(model, true); return true; } @@ -7406,7 +7406,7 @@ bool CStaticFunctionDefinitions::ResetVehicleHandling(CVehicle* pVehicle, bool b if (bUseOriginal) { - pNewEntry = m_HandlingManager->GetOriginalHandlingData(model); + pNewEntry = m_pHandlingManager->GetOriginalHandlingData(model); if (!pNewEntry) return false; @@ -7414,7 +7414,7 @@ bool CStaticFunctionDefinitions::ResetVehicleHandling(CVehicle* pVehicle, bool b } else { - pNewEntry = m_HandlingManager->GetModelHandlingData(model); + pNewEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pNewEntry) return false; @@ -7552,11 +7552,11 @@ bool CStaticFunctionDefinitions::ResetVehicleHandlingProperty(CVehicle* pVehicle bool CStaticFunctionDefinitions::ResetModelHandling(std::uint32_t model) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); if (!pEntry) return false; - const CHandlingEntry* pHandlingEntry = m_HandlingManager->GetOriginalHandlingData(model); + const CHandlingEntry* pHandlingEntry = m_pHandlingManager->GetOriginalHandlingData(model); if (!pHandlingEntry) return false; @@ -7566,7 +7566,7 @@ bool CStaticFunctionDefinitions::ResetModelHandling(std::uint32_t model) bool CStaticFunctionDefinitions::ResetModelHandlingProperty(std::uint32_t model, eHandlingProperty eProperty) { - CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); + CHandlingEntry* pEntry = m_pHandlingManager->GetModelHandlingData(model); float fValue; CVector vecValue; diff --git a/Server/mods/deathmatch/logic/CVehicle.cpp b/Server/mods/deathmatch/logic/CVehicle.cpp index 503bed059c..ff85b48823 100644 --- a/Server/mods/deathmatch/logic/CVehicle.cpp +++ b/Server/mods/deathmatch/logic/CVehicle.cpp @@ -850,7 +850,7 @@ void CVehicle::GetInitialDoorStates(SFixedArray& ucOut void CVehicle::GenerateHandlingData() noexcept { - const auto handlingManager = g_pGame->GetHandlingManager(); + const auto* handlingManager = g_pGame->GetHandlingManager(); // Make a new CHandlingEntry if (!m_HandlingEntry) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp index a5c2a95a7b..6afc751f67 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp @@ -40,7 +40,7 @@ namespace CElementDeleter* CLuaDefs::m_pElementDeleter = NULL; CBlipManager* CLuaDefs::m_pBlipManager = NULL; -std::shared_ptr CLuaDefs::m_HandlingManager = nullptr; +CHandlingManager* CLuaDefs::m_pHandlingManager = nullptr; CLuaManager* CLuaDefs::m_pLuaManager = NULL; CMarkerManager* CLuaDefs::m_pMarkerManager = NULL; CObjectManager* CLuaDefs::m_pObjectManager = NULL; @@ -63,7 +63,7 @@ void CLuaDefs::Initialize(CGame* pGame) m_pRootElement = pGame->GetMapManager()->GetRootElement(); m_pElementDeleter = pGame->GetElementDeleter(); m_pBlipManager = pGame->GetBlipManager(); - m_HandlingManager = pGame->GetHandlingManager(); + m_pHandlingManager = pGame->GetHandlingManager(); m_pLuaManager = pGame->GetLuaManager(); m_pMarkerManager = pGame->GetMarkerManager(); m_pObjectManager = pGame->GetObjectManager(); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.h index 45653f84ed..2bde93fb0e 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.h @@ -68,7 +68,7 @@ class CLuaDefs protected: static CElementDeleter* m_pElementDeleter; static CBlipManager* m_pBlipManager; - static std::shared_ptr m_HandlingManager; + static CHandlingManager* m_pHandlingManager; static CLuaManager* m_pLuaManager; static CMarkerManager* m_pMarkerManager; static CObjectManager* m_pObjectManager; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp index 9b449a640e..6e5c5bd92a 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp @@ -47,7 +47,7 @@ int CLuaHandlingDefs::SetVehicleHandling(lua_State* luaVM) SString strProperty; argStream.ReadString(strProperty); - eHandlingProperty eProperty = m_HandlingManager->GetPropertyEnumFromName(strProperty); + eHandlingProperty eProperty = m_pHandlingManager->GetPropertyEnumFromName(strProperty); if (eProperty) { if (argStream.NextIsNil()) @@ -229,7 +229,7 @@ int CLuaHandlingDefs::SetModelHandling(lua_State* luaVM) if (!argStream.HasErrors()) { - eHandlingProperty eProperty = m_HandlingManager->GetPropertyEnumFromName(strProperty); + eHandlingProperty eProperty = m_pHandlingManager->GetPropertyEnumFromName(strProperty); if (eProperty) { if (argStream.NextIsNil()) @@ -402,50 +402,55 @@ int CLuaHandlingDefs::GetVehicleHandling(lua_State* luaVM) SString strProperty; argStream.ReadString(strProperty); - eHandlingProperty eProperty = m_HandlingManager->GetPropertyEnumFromName(strProperty); - if (eProperty == HANDLING_MAX) + bool bResult = true; + eHandlingProperty eProperty = m_pHandlingManager->GetPropertyEnumFromName(strProperty); + if (eProperty != HANDLING_MAX) { - argStream.SetCustomError("Invalid property"); - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; - } - - float fValue = 0.0f; - CVector vecValue = CVector(0.0f, 0.0f, 0.0f); - SString strValue = ""; - unsigned int uiValue = 0; - unsigned char ucValue = 0; - if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue)) - { - lua_pushnumber(luaVM, fValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue)) - { - lua_pushnumber(luaVM, uiValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue)) - { - lua_pushnumber(luaVM, ucValue); - } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue)) - { - lua_pushstring(luaVM, strValue); + float fValue = 0.0f; + CVector vecValue = CVector(0.0f, 0.0f, 0.0f); + SString strValue = ""; + unsigned int uiValue = 0; + unsigned char ucValue = 0; + if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue)) + { + lua_pushnumber(luaVM, fValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue)) + { + lua_pushnumber(luaVM, uiValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue)) + { + lua_pushnumber(luaVM, ucValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue)) + { + lua_pushstring(luaVM, strValue); + } + else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue)) + { + lua_createtable(luaVM, 3, 0); + lua_pushnumber(luaVM, 1); + lua_pushnumber(luaVM, vecValue.fX); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 2); + lua_pushnumber(luaVM, vecValue.fY); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 3); + lua_pushnumber(luaVM, vecValue.fZ); + lua_settable(luaVM, -3); + } + else + { + bResult = false; + } } - else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue)) + else { - lua_createtable(luaVM, 3, 0); - lua_pushnumber(luaVM, 1); - lua_pushnumber(luaVM, vecValue.fX); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 2); - lua_pushnumber(luaVM, vecValue.fY); - lua_settable(luaVM, -3); - lua_pushnumber(luaVM, 3); - lua_pushnumber(luaVM, vecValue.fZ); - lua_settable(luaVM, -3); + bResult = false; } - else + + if (!bResult) { argStream.SetCustomError("Invalid property"); m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); @@ -617,24 +622,23 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) if (!argStream.HasErrors()) { - if (model) + if (CVehicleManager::IsValidModel(model)) { - const CHandlingEntry* pEntry = m_HandlingManager->GetModelHandlingData(model); - if (pEntry) + if (const auto* const entry = m_pHandlingManager->GetModelHandlingData(model)) { lua_newtable(luaVM); - lua_pushnumber(luaVM, pEntry->GetMass()); + lua_pushnumber(luaVM, entry->GetMass()); lua_setfield(luaVM, -2, "mass"); - lua_pushnumber(luaVM, pEntry->GetTurnMass()); + lua_pushnumber(luaVM, entry->GetTurnMass()); lua_setfield(luaVM, -2, "turnMass"); - lua_pushnumber(luaVM, pEntry->GetDragCoeff()); + lua_pushnumber(luaVM, entry->GetDragCoeff()); lua_setfield(luaVM, -2, "dragCoeff"); lua_createtable(luaVM, 3, 0); - CVector vecCenter = pEntry->GetCenterOfMass(); + CVector vecCenter = entry->GetCenterOfMass(); lua_pushnumber(luaVM, 1); lua_pushnumber(luaVM, vecCenter.fX); lua_settable(luaVM, -3); @@ -646,13 +650,13 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) lua_settable(luaVM, -3); lua_setfield(luaVM, -2, "centerOfMass"); - lua_pushnumber(luaVM, pEntry->GetPercentSubmerged()); + lua_pushnumber(luaVM, entry->GetPercentSubmerged()); lua_setfield(luaVM, -2, "percentSubmerged"); - lua_pushnumber(luaVM, pEntry->GetTractionMultiplier()); + lua_pushnumber(luaVM, entry->GetTractionMultiplier()); lua_setfield(luaVM, -2, "tractionMultiplier"); - CHandlingEntry::eDriveType eDriveType = pEntry->GetCarDriveType(); + CHandlingEntry::eDriveType eDriveType = entry->GetCarDriveType(); if (eDriveType == CHandlingEntry::FWD) lua_pushstring(luaVM, "fwd"); else if (eDriveType == CHandlingEntry::RWD) @@ -663,7 +667,7 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "driveType"); - CHandlingEntry::eEngineType eEngineType = pEntry->GetCarEngineType(); + CHandlingEntry::eEngineType eEngineType = entry->GetCarEngineType(); if (eEngineType == CHandlingEntry::PETROL) lua_pushstring(luaVM, "petrol"); else if (eEngineType == CHandlingEntry::DIESEL) @@ -674,73 +678,73 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "engineType"); - lua_pushnumber(luaVM, pEntry->GetNumberOfGears()); + lua_pushnumber(luaVM, entry->GetNumberOfGears()); lua_setfield(luaVM, -2, "numberOfGears"); - lua_pushnumber(luaVM, pEntry->GetEngineAcceleration()); + lua_pushnumber(luaVM, entry->GetEngineAcceleration()); lua_setfield(luaVM, -2, "engineAcceleration"); - lua_pushnumber(luaVM, pEntry->GetEngineInertia()); + lua_pushnumber(luaVM, entry->GetEngineInertia()); lua_setfield(luaVM, -2, "engineInertia"); - lua_pushnumber(luaVM, pEntry->GetMaxVelocity()); + lua_pushnumber(luaVM, entry->GetMaxVelocity()); lua_setfield(luaVM, -2, "maxVelocity"); - lua_pushnumber(luaVM, pEntry->GetBrakeDeceleration()); + lua_pushnumber(luaVM, entry->GetBrakeDeceleration()); lua_setfield(luaVM, -2, "brakeDeceleration"); - lua_pushnumber(luaVM, pEntry->GetBrakeBias()); + lua_pushnumber(luaVM, entry->GetBrakeBias()); lua_setfield(luaVM, -2, "brakeBias"); - lua_pushboolean(luaVM, pEntry->GetABS()); + lua_pushboolean(luaVM, entry->GetABS()); lua_setfield(luaVM, -2, "ABS"); - lua_pushnumber(luaVM, pEntry->GetSteeringLock()); + lua_pushnumber(luaVM, entry->GetSteeringLock()); lua_setfield(luaVM, -2, "steeringLock"); - lua_pushnumber(luaVM, pEntry->GetTractionLoss()); + lua_pushnumber(luaVM, entry->GetTractionLoss()); lua_setfield(luaVM, -2, "tractionLoss"); - lua_pushnumber(luaVM, pEntry->GetTractionBias()); + lua_pushnumber(luaVM, entry->GetTractionBias()); lua_setfield(luaVM, -2, "tractionBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionForceLevel()); + lua_pushnumber(luaVM, entry->GetSuspensionForceLevel()); lua_setfield(luaVM, -2, "suspensionForceLevel"); - lua_pushnumber(luaVM, pEntry->GetSuspensionDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionDamping()); lua_setfield(luaVM, -2, "suspensionDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionHighSpeedDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionHighSpeedDamping()); lua_setfield(luaVM, -2, "suspensionHighSpeedDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionUpperLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionUpperLimit()); lua_setfield(luaVM, -2, "suspensionUpperLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionLowerLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionLowerLimit()); lua_setfield(luaVM, -2, "suspensionLowerLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionFrontRearBias()); + lua_pushnumber(luaVM, entry->GetSuspensionFrontRearBias()); lua_setfield(luaVM, -2, "suspensionFrontRearBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionAntiDiveMultiplier()); + lua_pushnumber(luaVM, entry->GetSuspensionAntiDiveMultiplier()); lua_setfield(luaVM, -2, "suspensionAntiDiveMultiplier"); - lua_pushnumber(luaVM, pEntry->GetCollisionDamageMultiplier()); + lua_pushnumber(luaVM, entry->GetCollisionDamageMultiplier()); lua_setfield(luaVM, -2, "collisionDamageMultiplier"); - lua_pushnumber(luaVM, pEntry->GetSeatOffsetDistance()); + lua_pushnumber(luaVM, entry->GetSeatOffsetDistance()); lua_setfield(luaVM, -2, "seatOffsetDistance"); - lua_pushnumber(luaVM, pEntry->GetHandlingFlags()); + lua_pushnumber(luaVM, entry->GetHandlingFlags()); lua_setfield(luaVM, -2, "handlingFlags"); - lua_pushnumber(luaVM, pEntry->GetModelFlags()); + lua_pushnumber(luaVM, entry->GetModelFlags()); lua_setfield(luaVM, -2, "modelFlags"); - lua_pushnumber(luaVM, pEntry->GetMonetary()); + lua_pushnumber(luaVM, entry->GetMonetary()); lua_setfield(luaVM, -2, "monetary"); - CHandlingEntry::eLightType eHeadType = pEntry->GetHeadLight(); + CHandlingEntry::eLightType eHeadType = entry->GetHeadLight(); if (eHeadType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eHeadType == CHandlingEntry::SMALL) @@ -751,7 +755,7 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "headLight"); - CHandlingEntry::eLightType eTailType = pEntry->GetTailLight(); + CHandlingEntry::eLightType eTailType = entry->GetTailLight(); if (eTailType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eTailType == CHandlingEntry::SMALL) @@ -762,7 +766,7 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "tailLight"); - lua_pushnumber(luaVM, pEntry->GetAnimGroup()); + lua_pushnumber(luaVM, entry->GetAnimGroup()); lua_setfield(luaVM, -2, "animGroup"); return 1; @@ -789,20 +793,19 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) if (!argStream.HasErrors()) { - if (model) + if (CVehicleManager::IsValidModel(model)) { - const CHandlingEntry* pEntry = m_HandlingManager->GetOriginalHandlingData(model); - if (pEntry) + if (const auto* const entry = m_pHandlingManager->GetOriginalHandlingData(model)) { lua_newtable(luaVM); - lua_pushnumber(luaVM, pEntry->GetMass()); + lua_pushnumber(luaVM, entry->GetMass()); lua_setfield(luaVM, -2, "mass"); - lua_pushnumber(luaVM, pEntry->GetTurnMass()); + lua_pushnumber(luaVM, entry->GetTurnMass()); lua_setfield(luaVM, -2, "turnMass"); - lua_pushnumber(luaVM, pEntry->GetDragCoeff()); + lua_pushnumber(luaVM, entry->GetDragCoeff()); lua_setfield(luaVM, -2, "dragCoeff"); lua_createtable(luaVM, 3, 0); - CVector vecCenter = pEntry->GetCenterOfMass(); + CVector vecCenter = entry->GetCenterOfMass(); lua_pushnumber(luaVM, 1); lua_pushnumber(luaVM, vecCenter.fX); lua_settable(luaVM, -3); @@ -813,11 +816,11 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) lua_pushnumber(luaVM, vecCenter.fZ); lua_settable(luaVM, -3); lua_setfield(luaVM, -2, "centerOfMass"); - lua_pushnumber(luaVM, pEntry->GetPercentSubmerged()); + lua_pushnumber(luaVM, entry->GetPercentSubmerged()); lua_setfield(luaVM, -2, "percentSubmerged"); - lua_pushnumber(luaVM, pEntry->GetTractionMultiplier()); + lua_pushnumber(luaVM, entry->GetTractionMultiplier()); lua_setfield(luaVM, -2, "tractionMultiplier"); - CHandlingEntry::eDriveType eDriveType = pEntry->GetCarDriveType(); + CHandlingEntry::eDriveType eDriveType = entry->GetCarDriveType(); if (eDriveType == CHandlingEntry::FWD) lua_pushstring(luaVM, "fwd"); else if (eDriveType == CHandlingEntry::RWD) @@ -827,7 +830,7 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) else // What the ... (yeah, security) lua_pushnil(luaVM); lua_setfield(luaVM, -2, "driveType"); - CHandlingEntry::eEngineType eEngineType = pEntry->GetCarEngineType(); + CHandlingEntry::eEngineType eEngineType = entry->GetCarEngineType(); if (eEngineType == CHandlingEntry::PETROL) lua_pushstring(luaVM, "petrol"); else if (eEngineType == CHandlingEntry::DIESEL) @@ -837,51 +840,51 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "engineType"); - lua_pushnumber(luaVM, pEntry->GetNumberOfGears()); + lua_pushnumber(luaVM, entry->GetNumberOfGears()); lua_setfield(luaVM, -2, "numberOfGears"); - lua_pushnumber(luaVM, pEntry->GetEngineAcceleration()); + lua_pushnumber(luaVM, entry->GetEngineAcceleration()); lua_setfield(luaVM, -2, "engineAcceleration"); - lua_pushnumber(luaVM, pEntry->GetEngineInertia()); + lua_pushnumber(luaVM, entry->GetEngineInertia()); lua_setfield(luaVM, -2, "engineInertia"); - lua_pushnumber(luaVM, pEntry->GetMaxVelocity()); + lua_pushnumber(luaVM, entry->GetMaxVelocity()); lua_setfield(luaVM, -2, "maxVelocity"); - lua_pushnumber(luaVM, pEntry->GetBrakeDeceleration()); + lua_pushnumber(luaVM, entry->GetBrakeDeceleration()); lua_setfield(luaVM, -2, "brakeDeceleration"); - lua_pushnumber(luaVM, pEntry->GetBrakeBias()); + lua_pushnumber(luaVM, entry->GetBrakeBias()); lua_setfield(luaVM, -2, "brakeBias"); - lua_pushboolean(luaVM, pEntry->GetABS()); + lua_pushboolean(luaVM, entry->GetABS()); lua_setfield(luaVM, -2, "ABS"); - lua_pushnumber(luaVM, pEntry->GetSteeringLock()); + lua_pushnumber(luaVM, entry->GetSteeringLock()); lua_setfield(luaVM, -2, "steeringLock"); - lua_pushnumber(luaVM, pEntry->GetTractionLoss()); + lua_pushnumber(luaVM, entry->GetTractionLoss()); lua_setfield(luaVM, -2, "tractionLoss"); - lua_pushnumber(luaVM, pEntry->GetTractionBias()); + lua_pushnumber(luaVM, entry->GetTractionBias()); lua_setfield(luaVM, -2, "tractionBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionForceLevel()); + lua_pushnumber(luaVM, entry->GetSuspensionForceLevel()); lua_setfield(luaVM, -2, "suspensionForceLevel"); - lua_pushnumber(luaVM, pEntry->GetSuspensionDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionDamping()); lua_setfield(luaVM, -2, "suspensionDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionHighSpeedDamping()); + lua_pushnumber(luaVM, entry->GetSuspensionHighSpeedDamping()); lua_setfield(luaVM, -2, "suspensionHighSpeedDamping"); - lua_pushnumber(luaVM, pEntry->GetSuspensionUpperLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionUpperLimit()); lua_setfield(luaVM, -2, "suspensionUpperLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionLowerLimit()); + lua_pushnumber(luaVM, entry->GetSuspensionLowerLimit()); lua_setfield(luaVM, -2, "suspensionLowerLimit"); - lua_pushnumber(luaVM, pEntry->GetSuspensionFrontRearBias()); + lua_pushnumber(luaVM, entry->GetSuspensionFrontRearBias()); lua_setfield(luaVM, -2, "suspensionFrontRearBias"); - lua_pushnumber(luaVM, pEntry->GetSuspensionAntiDiveMultiplier()); + lua_pushnumber(luaVM, entry->GetSuspensionAntiDiveMultiplier()); lua_setfield(luaVM, -2, "suspensionAntiDiveMultiplier"); - lua_pushnumber(luaVM, pEntry->GetCollisionDamageMultiplier()); + lua_pushnumber(luaVM, entry->GetCollisionDamageMultiplier()); lua_setfield(luaVM, -2, "collisionDamageMultiplier"); - lua_pushnumber(luaVM, pEntry->GetSeatOffsetDistance()); + lua_pushnumber(luaVM, entry->GetSeatOffsetDistance()); lua_setfield(luaVM, -2, "seatOffsetDistance"); - lua_pushnumber(luaVM, pEntry->GetHandlingFlags()); + lua_pushnumber(luaVM, entry->GetHandlingFlags()); lua_setfield(luaVM, -2, "handlingFlags"); - lua_pushnumber(luaVM, pEntry->GetModelFlags()); + lua_pushnumber(luaVM, entry->GetModelFlags()); lua_setfield(luaVM, -2, "modelFlags"); - lua_pushnumber(luaVM, pEntry->GetMonetary()); + lua_pushnumber(luaVM, entry->GetMonetary()); lua_setfield(luaVM, -2, "monetary"); - CHandlingEntry::eLightType eHeadType = pEntry->GetHeadLight(); + CHandlingEntry::eLightType eHeadType = entry->GetHeadLight(); if (eHeadType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eHeadType == CHandlingEntry::SMALL) @@ -891,7 +894,7 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "headLight"); - CHandlingEntry::eLightType eTailType = pEntry->GetTailLight(); + CHandlingEntry::eLightType eTailType = entry->GetTailLight(); if (eTailType == CHandlingEntry::LONG) lua_pushstring(luaVM, "long"); else if (eTailType == CHandlingEntry::SMALL) @@ -901,7 +904,7 @@ int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) else lua_pushnil(luaVM); lua_setfield(luaVM, -2, "tailLight"); - lua_pushnumber(luaVM, pEntry->GetAnimGroup()); + lua_pushnumber(luaVM, entry->GetAnimGroup()); lua_setfield(luaVM, -2, "animGroup"); return 1; }