Once again cleaned up FLA integration

This commit is contained in:
Silent 2017-09-09 20:46:10 +02:00
parent 5050c6510e
commit df32c8ab6a
4 changed files with 40 additions and 38 deletions

View file

@ -3,21 +3,21 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
int32_t (*FLAUtils::GetExtendedID8Func)(const void* ptr) = FLAUtils::GetExtendedID8_Stock;
int32_t (*FLAUtils::GetExtendedID16Func)(const void* ptr) = FLAUtils::GetExtendedID16_Stock;
int32_t (*FLAUtils::GetExtendedID8Func)(const uint8_t* ptr) = FLAUtils::GetExtendedID8_Stock;
int32_t (*FLAUtils::GetExtendedID16Func)(const uint16_t* ptr) = FLAUtils::GetExtendedID16_Stock;
void FLAUtils::Init()
{
HMODULE hFLA = GetModuleHandle(TEXT("$fastman92limitAdjuster.asi"));
const HMODULE hFLA = GetModuleHandle(TEXT("$fastman92limitAdjuster.asi"));
if ( hFLA != nullptr )
{
auto function8 = reinterpret_cast<decltype(GetExtendedID8Func)>(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" ));
const auto function8 = reinterpret_cast<decltype(GetExtendedID8Func)>(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" ));
if ( function8 != nullptr )
{
GetExtendedID8Func = function8;
}
auto function16 = reinterpret_cast<decltype(GetExtendedID16Func)>(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" ));
const auto function16 = reinterpret_cast<decltype(GetExtendedID16Func)>(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" ));
if ( function16 != nullptr )
{
GetExtendedID16Func = function16;

View file

@ -7,6 +7,12 @@ class FLAUtils
public:
class int8
{
public:
inline int32_t Get() const
{
return GetExtendedID8Func( &value );
}
private:
int8() = delete;
int8& operator =( const int8& ) = delete;
@ -16,6 +22,12 @@ public:
class int16
{
public:
inline int32_t Get() const
{
return GetExtendedID16Func( &value );
}
private:
int16() = delete;
int16& operator =( const int16& ) = delete;
@ -23,37 +35,27 @@ public:
uint16_t value;
};
static_assert( sizeof(int8) == sizeof(uint8_t) );
static_assert( sizeof(int16) == sizeof(uint16_t) );
static int32_t GetExtendedID(const int8* ptr)
{
return GetExtendedID8Func(ptr);
}
static int32_t GetExtendedID(const int16* ptr)
{
return GetExtendedID16Func(ptr);
}
static void Init();
private:
static constexpr int32_t MAX_UINT8_ID = 0xFF;
static constexpr int32_t MAX_UINT16_ID = 0xFFFD;
static int32_t GetExtendedID8_Stock(const void* ptr)
static int32_t GetExtendedID8_Stock(const uint8_t* ptr)
{
uint8_t uID = *static_cast<const uint8_t*>(ptr);
const uint8_t uID = *ptr;
return uID == MAX_UINT8_ID ? -1 : uID;
}
static int32_t GetExtendedID16_Stock(const void* ptr)
static int32_t GetExtendedID16_Stock(const uint16_t* ptr)
{
uint16_t uID = *static_cast<const uint16_t*>(ptr);
return uID > MAX_UINT16_ID ? *static_cast<const int16_t*>(ptr) : uID;
const uint16_t uID = *ptr;
return uID > MAX_UINT16_ID ? *reinterpret_cast<const int16_t*>(ptr) : uID;
}
static int32_t (*GetExtendedID8Func)(const void* ptr);
static int32_t (*GetExtendedID16Func)(const void* ptr);
static int32_t (*GetExtendedID8Func)(const uint8_t* ptr);
static int32_t (*GetExtendedID16Func)(const uint16_t* ptr);
static_assert( sizeof(int8) == sizeof(uint8_t) );
static_assert( sizeof(int16) == sizeof(uint16_t) );
};

View file

@ -56,15 +56,15 @@ void CObject::Render()
bool bCallRestore;
std::pair<void*,int> materialRestoreData[16];
const int32_t carPartModelIndex = FLAUtils::GetExtendedID( &m_wCarPartModelIndex );
const int32_t carPartModelIndex = m_wCarPartModelIndex.Get();
if ( carPartModelIndex != -1 && m_objectCreatedBy == TEMP_OBJECT && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC )
{
auto* pData = materialRestoreData;
ms_pRemapTexture = m_pPaintjobTex;
static_cast<CVehicleModelInfo*>(ms_modelInfoPtrs[ carPartModelIndex ])->SetVehicleColour( FLAUtils::GetExtendedID( &m_nCarColor[0] ),
FLAUtils::GetExtendedID( &m_nCarColor[1] ), FLAUtils::GetExtendedID( &m_nCarColor[2] ), FLAUtils::GetExtendedID( &m_nCarColor[3] ) );
static_cast<CVehicleModelInfo*>(ms_modelInfoPtrs[ carPartModelIndex ])->SetVehicleColour( m_nCarColor[0].Get(),
m_nCarColor[1].Get(), m_nCarColor[2].Get(), m_nCarColor[3].Get() );
SetEditableMaterialsCB(reinterpret_cast<RpAtomic*>(m_pRwObject), &pData);
pData->first = nullptr;

View file

@ -172,7 +172,7 @@ void CVehicle::SetComponentRotation( RwFrame* component, eRotAxis axis, float an
void CHeli::Render()
{
double dRotorsSpeed, dMovingRotorSpeed;
bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) );
bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() );
bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors;
bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors;
@ -224,7 +224,7 @@ void CHeli::Render()
void CPlane::Render()
{
double dRotorsSpeed, dMovingRotorSpeed;
bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) );
bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() );
bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors;
bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors;
@ -277,8 +277,7 @@ void CPlane::Fix_SilentPatch()
{
// Reset bouncing panels
// No reset on Vortex
const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex );
for ( ptrdiff_t i = extID == 539 ? 1 : 0; i < 3; i++ )
for ( ptrdiff_t i = m_nModelIndex.Get() == 539 ? 1 : 0; i < 3; i++ )
{
m_aBouncingPanel[i].m_nNodeIndex = -1;
}
@ -291,17 +290,18 @@ void CAutomobile::PreRender()
(this->*(orgPreRender))();
if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 603 )
const int32_t extID = m_nModelIndex.Get();
if ( extID == 603 )
{
ProcessPhoenixBlower( 603 );
ProcessPhoenixBlower( extID );
}
if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 574 )
if ( extID == 574 )
{
ProcessSweeper();
}
if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 582 )
if ( extID == 582 )
{
ProcessNewsvan();
}
@ -312,7 +312,7 @@ void CAutomobile::Fix_SilentPatch()
ResetFrames();
// Reset bouncing panels
const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex );
const int32_t extID = m_nModelIndex.Get();
for ( ptrdiff_t i = (extID == 525 && m_pCarNode[21]) || (extID == 531 && m_pCarNode[17]) ? 1 : 0; i < 3; i++ )
{
// Towtruck/Tractor fix
@ -322,7 +322,7 @@ void CAutomobile::Fix_SilentPatch()
void CAutomobile::ResetFrames()
{
RpClump* pOrigClump = reinterpret_cast<RpClump*>(ms_modelInfoPtrs[ FLAUtils::GetExtendedID( &m_nModelIndex ) ]->pRwObject);
RpClump* pOrigClump = reinterpret_cast<RpClump*>(ms_modelInfoPtrs[ m_nModelIndex.Get() ]->pRwObject);
if ( pOrigClump != nullptr )
{
// Instead of setting frame rotation to (0,0,0) like R* did, obtain the original frame matrix from CBaseNodelInfo clump