2014-08-03 19:38:53 +06:00
|
|
|
#include "StdAfxSA.h"
|
2014-05-31 00:14:47 +06:00
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
#include <set>
|
2014-08-03 19:38:53 +06:00
|
|
|
#include "VehicleSA.h"
|
|
|
|
#include "TimerSA.h"
|
2014-05-31 00:14:47 +06:00
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
std::set<unsigned int> vecRotorExceptions;
|
|
|
|
|
2014-08-22 04:10:23 +06:00
|
|
|
static void* varVehicleRender = AddressByVersion<void*>(0x6D0E60, 0x6D1680, 0x70C0B0);
|
2014-08-04 18:30:16 +06:00
|
|
|
WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); }
|
2014-08-22 04:10:23 +06:00
|
|
|
static void* varIsLawEnforcementVehicle = AddressByVersion<void*>(0x6D2370, 0x6D2BA0, 0x70D8C0);
|
2014-08-04 18:30:16 +06:00
|
|
|
WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); }
|
2014-05-31 00:14:47 +06:00
|
|
|
|
|
|
|
static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data)
|
|
|
|
{
|
|
|
|
if ( RpAtomicGetFlags(pObject) & rpATOMICRENDER )
|
2014-06-03 06:10:03 +06:00
|
|
|
{
|
2014-05-31 00:14:47 +06:00
|
|
|
*static_cast<RwObject**>(data) = pObject;
|
2014-06-03 06:10:03 +06:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-31 00:14:47 +06:00
|
|
|
return pObject;
|
|
|
|
}
|
|
|
|
|
2014-08-13 02:30:37 +06:00
|
|
|
static RwFrame* GetFrameFromNameCB(RwFrame* pFrame, void* pData)
|
|
|
|
{
|
|
|
|
// Is this a frame we want?
|
|
|
|
std::pair<const char*,RwFrame*>* pFindData = static_cast<std::pair<const char*,RwFrame*>*>(pData);
|
2015-05-06 02:29:15 +05:00
|
|
|
if ( !strcmp(pFindData->first, GetFrameNodeName(pFrame)) )
|
2014-08-13 02:30:37 +06:00
|
|
|
{
|
|
|
|
pFindData->second = pFrame;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try children
|
|
|
|
RwFrameForAllChildren(pFrame, GetFrameFromNameCB, pData);
|
|
|
|
return !pFindData->second ? pFrame : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:27:40 +06:00
|
|
|
static RpMaterial* SetCompAlphaCB(RpMaterial* pMaterial, void* data)
|
|
|
|
{
|
|
|
|
pMaterial->color.alpha = reinterpret_cast<RwUInt8>(data);
|
|
|
|
return pMaterial;
|
|
|
|
}
|
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
void ReadRotorFixExceptions(const wchar_t* pPath)
|
|
|
|
{
|
|
|
|
if ( FILE* hFile = _wfopen(pPath, L"r") )
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
bool bBeganParsing = false;
|
|
|
|
|
|
|
|
while ( fgets(buf, _countof(buf), hFile) )
|
|
|
|
{
|
|
|
|
if ( bBeganParsing )
|
|
|
|
{
|
|
|
|
if ( buf[0] != ';' )
|
|
|
|
{
|
|
|
|
unsigned int nToList = atoi(buf);
|
|
|
|
|
|
|
|
if ( nToList != 0 )
|
|
|
|
vecRotorExceptions.insert(nToList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( strstr(buf, "[RotorFixExceptions]") != nullptr )
|
|
|
|
bBeganParsing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:27:40 +06:00
|
|
|
void CVehicle::SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha)
|
|
|
|
{
|
|
|
|
RpGeometry* pGeometry = RpAtomicGetGeometry(pAtomic);
|
|
|
|
pGeometry->flags |= rpGEOMETRYMODULATEMATERIALCOLOR;
|
|
|
|
|
|
|
|
RpGeometryForAllMaterials(pGeometry, SetCompAlphaCB, reinterpret_cast<void*>(nAlpha));
|
|
|
|
}
|
|
|
|
|
2014-06-23 06:37:03 +06:00
|
|
|
bool CVehicle::CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo)
|
|
|
|
{
|
|
|
|
char PlateText[8];
|
|
|
|
const char* pOverrideText = pModelInfo->GetCustomCarPlateText();
|
|
|
|
|
|
|
|
if ( pOverrideText )
|
|
|
|
strncpy(PlateText, pOverrideText, 8);
|
|
|
|
else
|
|
|
|
CCustomCarPlateMgr::GeneratePlateText(PlateText, 8);
|
|
|
|
|
|
|
|
PlateTexture = CCustomCarPlateMgr::CreatePlateTexture(PlateText, pModelInfo->m_nPlateType);
|
2014-06-23 18:54:36 +06:00
|
|
|
//PlateDesign = pModelInfo->m_nPlateType != -1 ? pModelInfo->m_nPlateType : CCustomCarPlateMgr::GetMapRegionPlateDesign();
|
|
|
|
if ( pModelInfo->m_nPlateType != -1 )
|
|
|
|
PlateDesign = pModelInfo->m_nPlateType;
|
|
|
|
else if ( IsLawEnforcementVehicle() )
|
|
|
|
PlateDesign = CCustomCarPlateMgr::GetMapRegionPlateDesign();
|
|
|
|
else
|
|
|
|
PlateDesign = random(0, 20) == 0 ? random<signed char>(0, 3) : CCustomCarPlateMgr::GetMapRegionPlateDesign();
|
2014-06-23 06:37:03 +06:00
|
|
|
|
|
|
|
assert(PlateDesign >= 0 && PlateDesign < 3);
|
|
|
|
|
|
|
|
pModelInfo->m_plateText[0] = '\0';
|
|
|
|
pModelInfo->m_nPlateType = -1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-23 19:08:48 +06:00
|
|
|
//static RwTexture* pPushedTextures[NUM_MAX_PLATES];
|
2014-06-23 06:37:03 +06:00
|
|
|
|
|
|
|
void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo)
|
|
|
|
{
|
2014-06-30 02:21:18 +06:00
|
|
|
//CCustomCarPlateMgr::SetupPlates(reinterpret_cast<RpClump*>(pModelInfo->pRwObject), PlateTexture, PlateDesign);
|
2014-06-23 06:37:03 +06:00
|
|
|
for ( int i = 0; i < NUM_MAX_PLATES; i++ )
|
|
|
|
{
|
|
|
|
if ( pModelInfo->m_apPlateMaterials[i] )
|
|
|
|
{
|
2014-06-23 19:08:48 +06:00
|
|
|
//RwTexture* pPlateTex = RpMaterialGetTexture(pModelInfo->m_apPlateMaterials[i]);
|
2014-06-23 06:37:03 +06:00
|
|
|
|
2014-06-23 19:08:48 +06:00
|
|
|
//RwTextureAddRef(pPlateTex);
|
|
|
|
//pPushedTextures[i] = pPlateTex;
|
2014-06-23 06:37:03 +06:00
|
|
|
|
|
|
|
RpMaterialSetTexture(pModelInfo->m_apPlateMaterials[i], PlateTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pModelInfo->m_apPlateMaterials[NUM_MAX_PLATES+i] )
|
|
|
|
CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pModelInfo->m_apPlateMaterials[NUM_MAX_PLATES+i], PlateDesign);
|
|
|
|
//RwTexture* pPlatebackTex = RpMaterialGetTexture(pModelInfo->m_apPlateMaterials[4+i]);
|
|
|
|
|
|
|
|
//RwTextureAddRef(pPlatebackTex);
|
|
|
|
//pPushedTextures[4+i] = pPlateTex;
|
|
|
|
|
|
|
|
//RpMaterialSetTexture(pModelInfo->m_apPlateMaterials[i], PlateTexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 19:08:48 +06:00
|
|
|
// This is not needed
|
|
|
|
/*void CVehicle::CustomCarPlate_AfterRenderingStop(CVehicleModelInfo* pModelInfo)
|
2014-06-23 06:37:03 +06:00
|
|
|
{
|
|
|
|
for ( int i = 0; i < NUM_MAX_PLATES; i++ )
|
|
|
|
{
|
|
|
|
if ( pModelInfo->m_apPlateMaterials[i] )
|
|
|
|
{
|
|
|
|
//RwTexture* pPlateTex = RpMaterialGetTexture(pModelInfo->m_apPlateMaterials[i]);
|
|
|
|
|
|
|
|
//RwTextureAddRef(pPlateTex);
|
|
|
|
//pPushedTextures[i] = pPlateTex;
|
|
|
|
|
2014-06-23 19:08:48 +06:00
|
|
|
//RpMaterialSetTexture(pModelInfo->m_apPlateMaterials[i], pPushedTextures[i]);
|
|
|
|
//RwTextureDestroy(pPushedTextures[i]);
|
|
|
|
//pPushedTextures[i] = nullptr;
|
2014-06-23 06:37:03 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 19:08:48 +06:00
|
|
|
}*/
|
2014-06-23 06:37:03 +06:00
|
|
|
|
2014-05-31 00:14:47 +06:00
|
|
|
void CHeli::Render()
|
|
|
|
{
|
|
|
|
double dRotorsSpeed, dMovingRotorSpeed;
|
2015-05-06 02:29:15 +05:00
|
|
|
bool bHasMovingRotor = m_pCarNode[13] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0;
|
|
|
|
bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0;;
|
2014-05-31 00:14:47 +06:00
|
|
|
|
2014-08-03 19:38:53 +06:00
|
|
|
m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000;
|
2014-05-31 00:14:47 +06:00
|
|
|
|
|
|
|
if ( m_fRotorSpeed > 0.0 )
|
|
|
|
dRotorsSpeed = min(1.7 * (1.0/0.22) * m_fRotorSpeed, 1.5);
|
|
|
|
else
|
|
|
|
dRotorsSpeed = 0.0;
|
|
|
|
|
|
|
|
dMovingRotorSpeed = dRotorsSpeed - 0.4;
|
|
|
|
if ( dMovingRotorSpeed < 0.0 )
|
|
|
|
dMovingRotorSpeed = 0.0;
|
|
|
|
|
|
|
|
int nStaticRotorAlpha = static_cast<int>(min((1.5-dRotorsSpeed) * 255.0, 255));
|
|
|
|
int nMovingRotorAlpha = static_cast<int>(min(dMovingRotorSpeed * 175.0, 175));
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
if ( m_pCarNode[12] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[12], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2014-06-03 06:10:03 +06:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingRotor ? nStaticRotorAlpha : 255);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
if ( m_pCarNode[14] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[14], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2014-06-03 06:10:03 +06:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingRotor2 ? nStaticRotorAlpha : 255);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
if ( m_pCarNode[13] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[13], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2015-05-06 02:29:15 +05:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingRotor ? nMovingRotorAlpha : 0);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
if ( m_pCarNode[15] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[15], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2015-05-06 02:29:15 +05:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingRotor2 ? nMovingRotorAlpha : 0);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
CEntity::Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlane::Render()
|
|
|
|
{
|
|
|
|
double dRotorsSpeed, dMovingRotorSpeed;
|
2015-05-06 02:29:15 +05:00
|
|
|
bool bHasMovingProp = m_pCarNode[13] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0;
|
|
|
|
bool bHasMovingProp2 = m_pCarNode[15] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0;
|
2014-05-31 00:14:47 +06:00
|
|
|
|
2014-08-03 19:38:53 +06:00
|
|
|
m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000;
|
2014-05-31 00:14:47 +06:00
|
|
|
|
|
|
|
if ( m_fPropellerSpeed > 0.0 )
|
|
|
|
dRotorsSpeed = min(1.7 * (1.0/0.31) * m_fPropellerSpeed, 1.5);
|
|
|
|
else
|
|
|
|
dRotorsSpeed = 0.0;
|
|
|
|
|
|
|
|
dMovingRotorSpeed = dRotorsSpeed - 0.4;
|
|
|
|
if ( dMovingRotorSpeed < 0.0 )
|
|
|
|
dMovingRotorSpeed = 0.0;
|
|
|
|
|
|
|
|
int nStaticRotorAlpha = static_cast<int>(min((1.5-dRotorsSpeed) * 255.0, 255));
|
|
|
|
int nMovingRotorAlpha = static_cast<int>(min(dMovingRotorSpeed * 175.0, 175));
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
if ( m_pCarNode[12] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[12], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2014-06-04 20:12:53 +06:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingProp ? nStaticRotorAlpha : 255);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
if ( m_pCarNode[14] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[14], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2014-06-04 20:12:53 +06:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingProp2 ? nStaticRotorAlpha : 255);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
if ( m_pCarNode[13] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[13], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2015-05-06 02:29:15 +05:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingProp ? nMovingRotorAlpha : 0);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
2015-05-06 02:29:15 +05:00
|
|
|
if ( m_pCarNode[15] )
|
2014-05-31 00:14:47 +06:00
|
|
|
{
|
|
|
|
RpAtomic* pOutAtomic = nullptr;
|
2014-08-12 02:44:57 +06:00
|
|
|
RwFrameForAllObjects(m_pCarNode[15], GetCurrentAtomicObjectCB, &pOutAtomic);
|
2014-05-31 00:14:47 +06:00
|
|
|
if ( pOutAtomic )
|
2015-05-06 02:29:15 +05:00
|
|
|
SetComponentAtomicAlpha(pOutAtomic, bHasMovingProp2 ? nMovingRotorAlpha : 0);
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
CVehicle::Render();
|
2014-08-12 02:44:57 +06:00
|
|
|
}
|
|
|
|
|
2014-08-13 02:43:17 +06:00
|
|
|
void CPlane::Fix_SilentPatch()
|
|
|
|
{
|
|
|
|
// Reset bouncing panels
|
|
|
|
for ( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
// No reset on Vortex
|
|
|
|
if ( i == 0 && m_nModelIndex == 539 )
|
|
|
|
continue;
|
|
|
|
m_aBouncingPanel[i].m_nNodeIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
void CAutomobile::Fix_SilentPatch()
|
|
|
|
{
|
2014-08-13 02:30:37 +06:00
|
|
|
ResetFrames();
|
|
|
|
|
2014-08-12 02:44:57 +06:00
|
|
|
// Reset bouncing panels
|
|
|
|
for ( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
// Towtruck/Tractor fix
|
2014-08-13 02:43:17 +06:00
|
|
|
if ( i == 0 && ((m_nModelIndex == 525 && m_pCarNode[21]) || (m_nModelIndex == 531 && m_pCarNode[17])) )
|
2014-08-12 02:44:57 +06:00
|
|
|
continue;
|
|
|
|
m_aBouncingPanel[i].m_nNodeIndex = -1;
|
|
|
|
}
|
2014-08-13 02:30:37 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAutomobile::ResetFrames()
|
|
|
|
{
|
|
|
|
RpClump* pOrigClump = reinterpret_cast<RpClump*>(ms_modelInfoPtrs[m_nModelIndex]->pRwObject);
|
|
|
|
if ( pOrigClump )
|
|
|
|
{
|
|
|
|
// Instead of setting frame rotation to (0,0,0) like R* did, obtain the original frame matrix from CBaseNodelInfo clump
|
|
|
|
for ( int i = 8; i < 25; i++ )
|
|
|
|
{
|
|
|
|
if ( m_pCarNode[i] )
|
|
|
|
{
|
|
|
|
// Find a frame in CBaseModelInfo object
|
|
|
|
std::pair<const char*,RwFrame*> FindData = std::make_pair(GetFrameNodeName(m_pCarNode[i]), nullptr);
|
|
|
|
|
|
|
|
RwFrameForAllChildren(RpClumpGetFrame(pOrigClump), GetFrameFromNameCB, &FindData);
|
|
|
|
|
|
|
|
if ( FindData.second )
|
|
|
|
{
|
|
|
|
// Found a frame, reset it
|
|
|
|
*RwFrameGetMatrix(m_pCarNode[i]) = *RwFrameGetMatrix(FindData.second);
|
|
|
|
RwMatrixUpdate(RwFrameGetMatrix(m_pCarNode[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-31 00:14:47 +06:00
|
|
|
}
|