From 849722787943f54f1edd9368d557cca383db0ebd Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Tue, 27 Oct 2020 22:02:23 +0300 Subject: [PATCH 1/8] Revert "Revert "Add engineSet/GetModelTime (#752)" (#1588)" This reverts commit 0e03a422a47a211324a7aa4052d684be0d8e2452. --- Client/game_sa/CGameSA.cpp | 5 ++ Client/game_sa/CGameSA.h | 1 + Client/game_sa/CModelInfoSA.cpp | 46 ++++++++++++ Client/game_sa/CModelInfoSA.h | 4 + Client/mods/deathmatch/logic/CClientGame.cpp | 1 + .../logic/luadefs/CLuaEngineDefs.cpp | 74 ++++++++++++++++++- .../deathmatch/logic/luadefs/CLuaEngineDefs.h | 2 + Client/sdk/game/CGame.h | 1 + Client/sdk/game/CModelInfo.h | 2 + Client/sdk/game/RenderWare.h | 7 ++ 10 files changed, 142 insertions(+), 1 deletion(-) diff --git a/Client/game_sa/CGameSA.cpp b/Client/game_sa/CGameSA.cpp index fcf9d7a9200..415367ef98b 100644 --- a/Client/game_sa/CGameSA.cpp +++ b/Client/game_sa/CGameSA.cpp @@ -842,6 +842,11 @@ void CGameSA::ResetModelLodDistances() CModelInfoSA::StaticResetLodDistances(); } +void CGameSA::ResetModelTimes() +{ + CModelInfoSA::StaticResetModelTimes(); +} + void CGameSA::ResetAlphaTransparencies() { CModelInfoSA::StaticResetAlphaTransparencies(); diff --git a/Client/game_sa/CGameSA.h b/Client/game_sa/CGameSA.h index 5c35ab9108d..e43c70a7372 100644 --- a/Client/game_sa/CGameSA.h +++ b/Client/game_sa/CGameSA.h @@ -420,6 +420,7 @@ class CGameSA : public CGame void ResetModelLodDistances(); void ResetAlphaTransparencies(); void DisableVSync(); + void ResetModelTimes(); void OnPedContextChange(CPed* pPedContext); CPed* GetPedContext(); diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 8c79424a7b5..ce055aed413 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -21,6 +21,7 @@ std::map CModelInfo std::map CModelInfoSA::ms_ModelDefaultLodDistanceMap; std::map CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap; std::unordered_map> CModelInfoSA::ms_ModelDefaultDummiesPosition; +std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; std::unordered_map CModelInfoSA::ms_OriginalObjectPropertiesGroups; std::unordered_map> CModelInfoSA::ms_VehicleModelDefaultWheelSizes; @@ -564,6 +565,51 @@ float CModelInfoSA::GetLODDistance() return 0.0f; } +bool CModelInfoSA::SetTime(char cHourOn, char cHourOff) +{ + m_pInterface = ppModelInfo[m_dwModelID]; + if (!m_pInterface) + return false; + + TimeInfo* pTime = ((TimeInfo*(*)(void))m_pInterface->VFTBL->GetTimeInfo)(); + if (!pTime) + return false; + + if (!MapContains(ms_ModelDefaultModelTimeInfo, pTime)) + MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfo(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); + + pTime->m_nTimeOn = cHourOn; + pTime->m_nTimeOff = cHourOff; + return true; +} + +bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) +{ + m_pInterface = ppModelInfo[m_dwModelID]; + if (!m_pInterface) + return false; + + TimeInfo* time = ((TimeInfo*(*)(void))m_pInterface->VFTBL->GetTimeInfo)(); + if (!time) + return false; + + cHourOn = time->m_nTimeOn; + cHourOff = time->m_nTimeOff; + return true; +} + +void CModelInfoSA::StaticResetModelTimes() +{ + // Restore default values + for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) + { + iter->first->m_nTimeOn = iter->second->m_nTimeOn; + iter->first->m_nTimeOff = iter->second->m_nTimeOff; + } + + ms_ModelDefaultModelTimeInfo.clear(); +} + float CModelInfoSA::GetOriginalLODDistance() { // Return default LOD distance value (if doesn't exist, LOD distance hasn't been changed) diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index cef9c36e8a9..3aa515668ca 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -279,6 +279,7 @@ class CModelInfoSA : public CModelInfo static std::map ms_ModelDefaultLodDistanceMap; static std::map ms_ModelDefaultAlphaTransparencyMap; static std::unordered_map> ms_ModelDefaultDummiesPosition; + static std::map ms_ModelDefaultModelTimeInfo; static std::unordered_map ms_OriginalObjectPropertiesGroups; static std::unordered_map> ms_VehicleModelDefaultWheelSizes; bool m_bAddedRefForCollision; @@ -331,6 +332,9 @@ class CModelInfoSA : public CModelInfo void RestreamIPL(); static void StaticFlushPendingRestreamIPL(); static void StaticSetHooks(); + bool GetTime(char& cHourOn, char& cHourOff); + bool SetTime(char cHourOn, char cHourOff); + static void StaticResetModelTimes(); void SetAlphaTransparencyEnabled(BOOL bEnabled); bool IsAlphaTransparencyEnabled(); diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index b58cb2ce188..04a262dd1c5 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -3563,6 +3563,7 @@ void CClientGame::Event_OnIngame() g_pGame->ResetModelLodDistances(); g_pGame->ResetAlphaTransparencies(); + g_pGame->ResetModelTimes(); // Make sure we can access all areas g_pGame->GetStats()->ModifyStat(CITIES_PASSED, 2.0); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 6fab59073d2..dc0f9ec39ef 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -38,6 +38,8 @@ void CLuaEngineDefs::LoadFunctions() {"engineGetModelIDFromName", EngineGetModelIDFromName}, {"engineGetModelTextureNames", EngineGetModelTextureNames}, {"engineGetVisibleTextureNames", EngineGetVisibleTextureNames}, + {"engineSetModelVisibleTime", EngineSetModelVisibleTime}, + {"engineGetModelVisibleTime", EngineGetModelVisibleTime}, {"engineGetModelTextures", EngineGetModelTextures}, {"engineGetSurfaceProperties", EngineGetSurfaceProperties}, {"engineSetSurfaceProperties", EngineSetSurfaceProperties}, @@ -72,6 +74,7 @@ void CLuaEngineDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setAsynchronousLoading", "engineSetAsynchronousLoading"); lua_classfunction(luaVM, "setModelLODDistance", "engineSetModelLODDistance"); lua_classfunction(luaVM, "resetModelLODDistance", "engineResetModelLODDistance"); + lua_classfunction(luaVM, "setModelVisibleTime", "engineSetModelVisibleTime"); lua_classfunction(luaVM, "getVisibleTextureNames", "engineGetVisibleTextureNames"); lua_classfunction(luaVM, "getModelLODDistance", "engineGetModelLODDistance"); @@ -79,6 +82,7 @@ void CLuaEngineDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getModelTextures", "engineGetModelTextures"); lua_classfunction(luaVM, "getModelIDFromName", "engineGetModelIDFromName"); lua_classfunction(luaVM, "getModelNameFromID", "engineGetModelNameFromID"); + lua_classfunction(luaVM, "getModelVisibleTime", "engineGetModelVisibleTime"); lua_classfunction(luaVM, "getModelPhysicalPropertiesGroup", "engineGetModelPhysicalPropertiesGroup"); lua_classfunction(luaVM, "setModelPhysicalPropertiesGroup", "engineSetModelPhysicalPropertiesGroup"); lua_classfunction(luaVM, "restoreModelPhysicalPropertiesGroup", "engineRestoreModelPhysicalPropertiesGroup"); @@ -774,7 +778,7 @@ int CLuaEngineDefs::EngineResetModelLODDistance(lua_State* luaVM) if (argStream.HasErrors()) return luaL_error(luaVM, argStream.GetFullErrorMessage()); - + unsigned short usModelID = CModelNames::ResolveModelID(strModel); CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); if (pModelInfo) @@ -1098,6 +1102,74 @@ int CLuaEngineDefs::EngineGetVisibleTextureNames(lua_State* luaVM) return 1; } +int CLuaEngineDefs::EngineSetModelVisibleTime(lua_State* luaVM) +{ + // bool engineSetModelVisibleTime ( int/string modelID, int hourOn, int hourOff ) + SString strModelId; + char cHourOn,cHourOff; + CScriptArgReader argStream(luaVM); + argStream.ReadString(strModelId); + argStream.ReadNumber(cHourOn); + argStream.ReadNumber(cHourOff); + + if (!argStream.HasErrors()) + { + ushort usModelID = CModelNames::ResolveModelID(strModelId); + CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); + if (pModelInfo) + { + if (cHourOn >= 0 && cHourOn <= 24 && cHourOff >= 0 && cHourOff <= 24) + { + lua_pushboolean(luaVM, pModelInfo->SetTime(cHourOn, cHourOff)); + return 1; + } + } + } + else + luaL_error(luaVM, argStream.GetFullErrorMessage()); + + // Failed + lua_pushboolean(luaVM, false); + return 1; +} + +int CLuaEngineDefs::EngineGetModelVisibleTime(lua_State* luaVM) +{ + // int, int engineGetModelVisibleTime ( int/string modelID ) + SString strModelId; + + CScriptArgReader argStream(luaVM); + argStream.ReadString(strModelId); + + if (!argStream.HasErrors()) + { + ushort usModelID = CModelNames::ResolveModelID(strModelId); + CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); + if (pModelInfo) + { + char cHourOn, cHourOff; + if (pModelInfo->GetTime(cHourOn, cHourOff)) + { + lua_pushnumber(luaVM, cHourOn); + lua_pushnumber(luaVM, cHourOff); + return 2; + } + else // Model is incompatible, don't let confuse user. + { + lua_pushnumber(luaVM, 0); + lua_pushnumber(luaVM, 24); + return 2; + } + } + } + else + luaL_error(luaVM, argStream.GetFullErrorMessage()); + + // Failed + lua_pushboolean(luaVM, false); + return 1; +} + int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) { // table engineGetModelTextures ( string/int modelName/modelID, string/table textureNames ) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h index 02164d02870..c24aafd422a 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h @@ -47,6 +47,8 @@ class CLuaEngineDefs : public CLuaDefs LUA_DECLARE(EngineGetModelIDFromName); LUA_DECLARE(EngineGetModelTextureNames); LUA_DECLARE(EngineGetVisibleTextureNames); + LUA_DECLARE(EngineSetModelVisibleTime); + LUA_DECLARE(EngineGetModelVisibleTime); LUA_DECLARE(EngineGetModelTextures); LUA_DECLARE(EngineSetSurfaceProperties); LUA_DECLARE(EngineGetSurfaceProperties); diff --git a/Client/sdk/game/CGame.h b/Client/sdk/game/CGame.h index 25589c252eb..97420108488 100644 --- a/Client/sdk/game/CGame.h +++ b/Client/sdk/game/CGame.h @@ -239,6 +239,7 @@ class __declspec(novtable) CGame virtual void ResetModelLodDistances() = 0; virtual void ResetAlphaTransparencies() = 0; virtual void DisableVSync() = 0; + virtual void ResetModelTimes() = 0; virtual void OnPedContextChange(CPed* pPedContext) = 0; virtual CPed* GetPedContext() = 0; diff --git a/Client/sdk/game/CModelInfo.h b/Client/sdk/game/CModelInfo.h index 9b8dc4908da..813b30c08b0 100644 --- a/Client/sdk/game/CModelInfo.h +++ b/Client/sdk/game/CModelInfo.h @@ -129,6 +129,8 @@ class CModelInfo virtual float GetOriginalLODDistance() = 0; virtual void SetLODDistance(float fDistance, bool bOverrideMaxDistance = false) = 0; virtual void RestreamIPL() = 0; + virtual bool GetTime(char& hourOn, char& hourOff) = 0; + virtual bool SetTime(char hourOn, char hourOff) = 0; virtual void ModelAddRef(EModelRequestType requestType, const char* szTag /* = NULL*/) = 0; virtual void RemoveRef(bool bRemoveExtraGTARef = false) = 0; diff --git a/Client/sdk/game/RenderWare.h b/Client/sdk/game/RenderWare.h index 9f729510ab6..72e824d0641 100644 --- a/Client/sdk/game/RenderWare.h +++ b/Client/sdk/game/RenderWare.h @@ -479,3 +479,10 @@ struct RwError { int err1, err2; }; + +struct TimeInfo { + TimeInfo(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel) {}; + char m_nTimeOn; + char m_nTimeOff; + short m_wOtherTimeModel; +}; From affb360ea899a9405d09fde6231335a51f9e1a3b Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Tue, 27 Oct 2020 23:41:55 +0300 Subject: [PATCH 2/8] Fix engineSet/GetModelTime don't work in release --- Client/game_sa/CModelInfoSA.cpp | 16 +++++++++------- Client/game_sa/CModelInfoSA.h | 6 ++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index ce055aed413..0e64bfe2031 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -570,11 +570,12 @@ bool CModelInfoSA::SetTime(char cHourOn, char cHourOff) m_pInterface = ppModelInfo[m_dwModelID]; if (!m_pInterface) return false; - - TimeInfo* pTime = ((TimeInfo*(*)(void))m_pInterface->VFTBL->GetTimeInfo)(); - if (!pTime) + + if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; + TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + if (!MapContains(ms_ModelDefaultModelTimeInfo, pTime)) MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfo(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); @@ -589,12 +590,13 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) if (!m_pInterface) return false; - TimeInfo* time = ((TimeInfo*(*)(void))m_pInterface->VFTBL->GetTimeInfo)(); - if (!time) + if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - cHourOn = time->m_nTimeOn; - cHourOff = time->m_nTimeOff; + TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + + cHourOn = pTime->m_nTimeOn; + cHourOff = pTime->m_nTimeOff; return true; } diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index 3aa515668ca..97ee7076075 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -219,6 +219,12 @@ class CBaseModelInfoSAInterface // +772 = Anim file index }; +class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface +{ +public: + TimeInfo timeInfo; +}; + class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change { public: From 7da52731c9b021efdcf7432d862b8ec1b4194fad Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Wed, 28 Oct 2020 00:38:31 +0200 Subject: [PATCH 3/8] Update Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp --- Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index dc0f9ec39ef..9cb74735efe 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -778,7 +778,6 @@ int CLuaEngineDefs::EngineResetModelLODDistance(lua_State* luaVM) if (argStream.HasErrors()) return luaL_error(luaVM, argStream.GetFullErrorMessage()); - unsigned short usModelID = CModelNames::ResolveModelID(strModel); CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); if (pModelInfo) From c081fcf1f1f9c3fc7bb6416c4c1e750ebfaa7050 Mon Sep 17 00:00:00 2001 From: Nikita Obrekht Date: Wed, 28 Oct 2020 01:27:38 +0200 Subject: [PATCH 4/8] Use new parser --- .../logic/luadefs/CLuaEngineDefs.cpp | 76 ++++++------------- .../deathmatch/logic/luadefs/CLuaEngineDefs.h | 5 +- 2 files changed, 25 insertions(+), 56 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 9cb74735efe..d5ce1c1326d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -38,8 +38,8 @@ void CLuaEngineDefs::LoadFunctions() {"engineGetModelIDFromName", EngineGetModelIDFromName}, {"engineGetModelTextureNames", EngineGetModelTextureNames}, {"engineGetVisibleTextureNames", EngineGetVisibleTextureNames}, - {"engineSetModelVisibleTime", EngineSetModelVisibleTime}, - {"engineGetModelVisibleTime", EngineGetModelVisibleTime}, + {"engineSetModelVisibleTime", ArgumentParser}, + {"engineGetModelVisibleTime", ArgumentParser}, {"engineGetModelTextures", EngineGetModelTextures}, {"engineGetSurfaceProperties", EngineGetSurfaceProperties}, {"engineSetSurfaceProperties", EngineSetSurfaceProperties}, @@ -778,6 +778,7 @@ int CLuaEngineDefs::EngineResetModelLODDistance(lua_State* luaVM) if (argStream.HasErrors()) return luaL_error(luaVM, argStream.GetFullErrorMessage()); + unsigned short usModelID = CModelNames::ResolveModelID(strModel); CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); if (pModelInfo) @@ -1101,72 +1102,39 @@ int CLuaEngineDefs::EngineGetVisibleTextureNames(lua_State* luaVM) return 1; } -int CLuaEngineDefs::EngineSetModelVisibleTime(lua_State* luaVM) +bool CLuaEngineDefs::EngineSetModelVisibleTime(std::string strModelId, char cHourOn, char cHourOff) { - // bool engineSetModelVisibleTime ( int/string modelID, int hourOn, int hourOff ) - SString strModelId; - char cHourOn,cHourOff; - CScriptArgReader argStream(luaVM); - argStream.ReadString(strModelId); - argStream.ReadNumber(cHourOn); - argStream.ReadNumber(cHourOff); - - if (!argStream.HasErrors()) + ushort usModelID = CModelNames::ResolveModelID(strModelId); + CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); + if (pModelInfo) { - ushort usModelID = CModelNames::ResolveModelID(strModelId); - CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); - if (pModelInfo) + if (cHourOn >= 0 && cHourOn <= 24 && cHourOff >= 0 && cHourOff <= 24) { - if (cHourOn >= 0 && cHourOn <= 24 && cHourOff >= 0 && cHourOff <= 24) - { - lua_pushboolean(luaVM, pModelInfo->SetTime(cHourOn, cHourOff)); - return 1; - } + return pModelInfo->SetTime(cHourOn, cHourOff); } } - else - luaL_error(luaVM, argStream.GetFullErrorMessage()); - // Failed - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaEngineDefs::EngineGetModelVisibleTime(lua_State* luaVM) +std::variant> CLuaEngineDefs::EngineGetModelVisibleTime(std::string strModelId) { - // int, int engineGetModelVisibleTime ( int/string modelID ) - SString strModelId; - - CScriptArgReader argStream(luaVM); - argStream.ReadString(strModelId); - - if (!argStream.HasErrors()) + ushort usModelID = CModelNames::ResolveModelID(strModelId); + CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); + if (pModelInfo) { - ushort usModelID = CModelNames::ResolveModelID(strModelId); - CModelInfo* pModelInfo = g_pGame->GetModelInfo(usModelID); - if (pModelInfo) + char cHourOn, cHourOff; + if (pModelInfo->GetTime(cHourOn, cHourOff)) { - char cHourOn, cHourOff; - if (pModelInfo->GetTime(cHourOn, cHourOff)) - { - lua_pushnumber(luaVM, cHourOn); - lua_pushnumber(luaVM, cHourOff); - return 2; - } - else // Model is incompatible, don't let confuse user. - { - lua_pushnumber(luaVM, 0); - lua_pushnumber(luaVM, 24); - return 2; - } + return std::tuple(cHourOn, cHourOff); + } + else // Model is incompatible, don't let confuse user. + { + return std::tuple(0, 24); } } - else - luaL_error(luaVM, argStream.GetFullErrorMessage()); - // Failed - lua_pushboolean(luaVM, false); - return 1; + return false; } int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h index c24aafd422a..6b2c872a875 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h @@ -47,8 +47,6 @@ class CLuaEngineDefs : public CLuaDefs LUA_DECLARE(EngineGetModelIDFromName); LUA_DECLARE(EngineGetModelTextureNames); LUA_DECLARE(EngineGetVisibleTextureNames); - LUA_DECLARE(EngineSetModelVisibleTime); - LUA_DECLARE(EngineGetModelVisibleTime); LUA_DECLARE(EngineGetModelTextures); LUA_DECLARE(EngineSetSurfaceProperties); LUA_DECLARE(EngineGetSurfaceProperties); @@ -60,6 +58,9 @@ class CLuaEngineDefs : public CLuaDefs LUA_DECLARE(EngineGetObjectGroupPhysicalProperty) LUA_DECLARE(EngineRestoreObjectGroupPhysicalProperties) static bool CLuaEngineDefs::EngineRestreamWorld(lua_State* const luaVM); + static bool EngineSetModelVisibleTime(std::string strModelId, char cHourOn, char cHourOff); + static std::variant> EngineGetModelVisibleTime(std::string strModelId); + private: static void AddEngineColClass(lua_State* luaVM); static void AddEngineTxdClass(lua_State* luaVM); From f147e4e3a04e9ff3af11d5242392a335304518ec Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Wed, 28 Oct 2020 15:36:20 +0300 Subject: [PATCH 5/8] Moved and renamed TimeInfoSA --- Client/game_sa/CModelInfoSA.cpp | 10 +++++----- Client/game_sa/CModelInfoSA.h | 12 ++++++++++-- Client/sdk/game/RenderWare.h | 7 ------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 0e64bfe2031..18d82a56112 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -21,7 +21,7 @@ std::map CModelInfo std::map CModelInfoSA::ms_ModelDefaultLodDistanceMap; std::map CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap; std::unordered_map> CModelInfoSA::ms_ModelDefaultDummiesPosition; -std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; +std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; std::unordered_map CModelInfoSA::ms_OriginalObjectPropertiesGroups; std::unordered_map> CModelInfoSA::ms_VehicleModelDefaultWheelSizes; @@ -574,10 +574,10 @@ bool CModelInfoSA::SetTime(char cHourOn, char cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + TimeInfoSA* pTime = &static_cast(m_pInterface)->timeInfo; if (!MapContains(ms_ModelDefaultModelTimeInfo, pTime)) - MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfo(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); + MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfoSA(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); pTime->m_nTimeOn = cHourOn; pTime->m_nTimeOff = cHourOff; @@ -593,7 +593,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + TimeInfoSA* pTime = &static_cast(m_pInterface)->timeInfo; cHourOn = pTime->m_nTimeOn; cHourOff = pTime->m_nTimeOff; @@ -603,7 +603,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) void CModelInfoSA::StaticResetModelTimes() { // Restore default values - for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) + for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) { iter->first->m_nTimeOn = iter->second->m_nTimeOn; iter->first->m_nTimeOff = iter->second->m_nTimeOff; diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index 97ee7076075..94a5937f00d 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -219,10 +219,18 @@ class CBaseModelInfoSAInterface // +772 = Anim file index }; +struct TimeInfoSA +{ + TimeInfoSA(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel){}; + char m_nTimeOn; + char m_nTimeOff; + short m_wOtherTimeModel; +}; + class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface { public: - TimeInfo timeInfo; + TimeInfoSA timeInfo; }; class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change @@ -285,7 +293,7 @@ class CModelInfoSA : public CModelInfo static std::map ms_ModelDefaultLodDistanceMap; static std::map ms_ModelDefaultAlphaTransparencyMap; static std::unordered_map> ms_ModelDefaultDummiesPosition; - static std::map ms_ModelDefaultModelTimeInfo; + static std::map ms_ModelDefaultModelTimeInfo; static std::unordered_map ms_OriginalObjectPropertiesGroups; static std::unordered_map> ms_VehicleModelDefaultWheelSizes; bool m_bAddedRefForCollision; diff --git a/Client/sdk/game/RenderWare.h b/Client/sdk/game/RenderWare.h index 72e824d0641..9f729510ab6 100644 --- a/Client/sdk/game/RenderWare.h +++ b/Client/sdk/game/RenderWare.h @@ -479,10 +479,3 @@ struct RwError { int err1, err2; }; - -struct TimeInfo { - TimeInfo(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel) {}; - char m_nTimeOn; - char m_nTimeOff; - short m_wOtherTimeModel; -}; From 7c9e56dac622202876f161da73546fca88568780 Mon Sep 17 00:00:00 2001 From: saml1er Date: Wed, 28 Oct 2020 18:34:21 +0500 Subject: [PATCH 6/8] Revert "Moved and renamed TimeInfoSA" This reverts commit f147e4e3a04e9ff3af11d5242392a335304518ec. --- Client/game_sa/CModelInfoSA.cpp | 10 +++++----- Client/game_sa/CModelInfoSA.h | 12 ++---------- Client/sdk/game/RenderWare.h | 7 +++++++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 18d82a56112..0e64bfe2031 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -21,7 +21,7 @@ std::map CModelInfo std::map CModelInfoSA::ms_ModelDefaultLodDistanceMap; std::map CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap; std::unordered_map> CModelInfoSA::ms_ModelDefaultDummiesPosition; -std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; +std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; std::unordered_map CModelInfoSA::ms_OriginalObjectPropertiesGroups; std::unordered_map> CModelInfoSA::ms_VehicleModelDefaultWheelSizes; @@ -574,10 +574,10 @@ bool CModelInfoSA::SetTime(char cHourOn, char cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfoSA* pTime = &static_cast(m_pInterface)->timeInfo; + TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; if (!MapContains(ms_ModelDefaultModelTimeInfo, pTime)) - MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfoSA(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); + MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfo(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); pTime->m_nTimeOn = cHourOn; pTime->m_nTimeOff = cHourOff; @@ -593,7 +593,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfoSA* pTime = &static_cast(m_pInterface)->timeInfo; + TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; cHourOn = pTime->m_nTimeOn; cHourOff = pTime->m_nTimeOff; @@ -603,7 +603,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) void CModelInfoSA::StaticResetModelTimes() { // Restore default values - for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) + for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) { iter->first->m_nTimeOn = iter->second->m_nTimeOn; iter->first->m_nTimeOff = iter->second->m_nTimeOff; diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index 94a5937f00d..97ee7076075 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -219,18 +219,10 @@ class CBaseModelInfoSAInterface // +772 = Anim file index }; -struct TimeInfoSA -{ - TimeInfoSA(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel){}; - char m_nTimeOn; - char m_nTimeOff; - short m_wOtherTimeModel; -}; - class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface { public: - TimeInfoSA timeInfo; + TimeInfo timeInfo; }; class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change @@ -293,7 +285,7 @@ class CModelInfoSA : public CModelInfo static std::map ms_ModelDefaultLodDistanceMap; static std::map ms_ModelDefaultAlphaTransparencyMap; static std::unordered_map> ms_ModelDefaultDummiesPosition; - static std::map ms_ModelDefaultModelTimeInfo; + static std::map ms_ModelDefaultModelTimeInfo; static std::unordered_map ms_OriginalObjectPropertiesGroups; static std::unordered_map> ms_VehicleModelDefaultWheelSizes; bool m_bAddedRefForCollision; diff --git a/Client/sdk/game/RenderWare.h b/Client/sdk/game/RenderWare.h index 9f729510ab6..72e824d0641 100644 --- a/Client/sdk/game/RenderWare.h +++ b/Client/sdk/game/RenderWare.h @@ -479,3 +479,10 @@ struct RwError { int err1, err2; }; + +struct TimeInfo { + TimeInfo(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel) {}; + char m_nTimeOn; + char m_nTimeOff; + short m_wOtherTimeModel; +}; From d94025937a02c6257a6fc40f53496df4eb233e9f Mon Sep 17 00:00:00 2001 From: saml1er Date: Wed, 28 Oct 2020 18:54:44 +0500 Subject: [PATCH 7/8] code improvements --- Client/game_sa/CModelInfoSA.cpp | 16 +++++++--------- Client/game_sa/CModelInfoSA.h | 12 ++++++++++-- .../deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 1 - Client/sdk/game/RenderWare.h | 7 ------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 0e64bfe2031..6167e14d4ce 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -21,7 +21,7 @@ std::map CModelInfo std::map CModelInfoSA::ms_ModelDefaultLodDistanceMap; std::map CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap; std::unordered_map> CModelInfoSA::ms_ModelDefaultDummiesPosition; -std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; +std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; std::unordered_map CModelInfoSA::ms_OriginalObjectPropertiesGroups; std::unordered_map> CModelInfoSA::ms_VehicleModelDefaultWheelSizes; @@ -574,10 +574,10 @@ bool CModelInfoSA::SetTime(char cHourOn, char cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + CTimeInfoSAInterface* pTime = &static_cast(m_pInterface)->timeInfo; if (!MapContains(ms_ModelDefaultModelTimeInfo, pTime)) - MapSet(ms_ModelDefaultModelTimeInfo, pTime, new TimeInfo(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); + MapSet(ms_ModelDefaultModelTimeInfo, pTime, new CTimeInfoSAInterface(pTime->m_nTimeOn, pTime->m_nTimeOff, pTime->m_wOtherTimeModel)); pTime->m_nTimeOn = cHourOn; pTime->m_nTimeOff = cHourOff; @@ -593,7 +593,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) if (GetModelType() != MODEL_INFO_TYPE_TIME) return false; - TimeInfo* pTime = &static_cast(m_pInterface)->timeInfo; + CTimeInfoSAInterface* pTime = &static_cast(m_pInterface)->timeInfo; cHourOn = pTime->m_nTimeOn; cHourOff = pTime->m_nTimeOff; @@ -602,13 +602,11 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff) void CModelInfoSA::StaticResetModelTimes() { - // Restore default values - for (std::map::const_iterator iter = ms_ModelDefaultModelTimeInfo.begin(); iter != ms_ModelDefaultModelTimeInfo.end(); ++iter) + for (auto const& x : ms_ModelDefaultModelTimeInfo) { - iter->first->m_nTimeOn = iter->second->m_nTimeOn; - iter->first->m_nTimeOff = iter->second->m_nTimeOff; + x.first->m_nTimeOn = x.second->m_nTimeOn; + x.first->m_nTimeOff = x.second->m_nTimeOff; } - ms_ModelDefaultModelTimeInfo.clear(); } diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index 97ee7076075..86df2544c87 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -219,10 +219,18 @@ class CBaseModelInfoSAInterface // +772 = Anim file index }; +struct CTimeInfoSAInterface +{ + CTimeInfoSAInterface(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel){}; + char m_nTimeOn; + char m_nTimeOff; + short m_wOtherTimeModel; +}; + class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface { public: - TimeInfo timeInfo; + CTimeInfoSAInterface timeInfo; }; class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change @@ -285,7 +293,7 @@ class CModelInfoSA : public CModelInfo static std::map ms_ModelDefaultLodDistanceMap; static std::map ms_ModelDefaultAlphaTransparencyMap; static std::unordered_map> ms_ModelDefaultDummiesPosition; - static std::map ms_ModelDefaultModelTimeInfo; + static std::map ms_ModelDefaultModelTimeInfo; static std::unordered_map ms_OriginalObjectPropertiesGroups; static std::unordered_map> ms_VehicleModelDefaultWheelSizes; bool m_bAddedRefForCollision; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index d5ce1c1326d..dcac1ff38fb 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -1113,7 +1113,6 @@ bool CLuaEngineDefs::EngineSetModelVisibleTime(std::string strModelId, char cHou return pModelInfo->SetTime(cHourOn, cHourOff); } } - return false; } diff --git a/Client/sdk/game/RenderWare.h b/Client/sdk/game/RenderWare.h index 72e824d0641..9f729510ab6 100644 --- a/Client/sdk/game/RenderWare.h +++ b/Client/sdk/game/RenderWare.h @@ -479,10 +479,3 @@ struct RwError { int err1, err2; }; - -struct TimeInfo { - TimeInfo(char timeOn, char timeOff, short OtherTimeModel) : m_nTimeOn(timeOn), m_nTimeOff(timeOff), m_wOtherTimeModel(OtherTimeModel) {}; - char m_nTimeOn; - char m_nTimeOff; - short m_wOtherTimeModel; -}; From e7ca90fd230f2d3063a22a912d5b79f81f72bcc1 Mon Sep 17 00:00:00 2001 From: saml1er Date: Wed, 28 Oct 2020 18:56:29 +0500 Subject: [PATCH 8/8] Tweak formatting in CModelInfoSA.cpp --- Client/game_sa/CModelInfoSA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 6167e14d4ce..8a666b1ce61 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -21,7 +21,7 @@ std::map CModelInfo std::map CModelInfoSA::ms_ModelDefaultLodDistanceMap; std::map CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap; std::unordered_map> CModelInfoSA::ms_ModelDefaultDummiesPosition; -std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; +std::map CModelInfoSA::ms_ModelDefaultModelTimeInfo; std::unordered_map CModelInfoSA::ms_OriginalObjectPropertiesGroups; std::unordered_map> CModelInfoSA::ms_VehicleModelDefaultWheelSizes;