Misc fixes

This commit is contained in:
Silent 2016-11-12 18:28:46 +01:00
parent 7e7aaa5db9
commit 6c5a025c60
4 changed files with 62 additions and 53 deletions

View file

@ -1,6 +1,8 @@
#ifndef __GENERAL #ifndef __GENERAL
#define __GENERAL #define __GENERAL
#include <stdint.h>
class CSimpleTransform class CSimpleTransform
{ {
public: public:
@ -11,7 +13,7 @@ public:
class CRGBA class CRGBA
{ {
public: public:
BYTE r, g, b, a; uint8_t r, g, b, a;
inline CRGBA() {} inline CRGBA() {}
@ -19,33 +21,31 @@ public:
: r(in.r), g(in.g), b(in.b), a(in.a) : r(in.r), g(in.g), b(in.b), a(in.a)
{} {}
inline CRGBA(const CRGBA& in, BYTE alpha) inline CRGBA(const CRGBA& in, uint8_t alpha)
: r(in.r), g(in.g), b(in.b), a(alpha) : r(in.r), g(in.g), b(in.b), a(alpha)
{} {}
inline CRGBA(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255) inline CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
: r(red), g(green), b(blue), a(alpha) : r(red), g(green), b(blue), a(alpha)
{} {}
template <typename T> friend CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal)
friend CRGBA Blend(const CRGBA& One, T OneStrength, const CRGBA& Two, T TwoStrength) { double InvBlendVal = 1.0 - BlendVal;
{ T TotalStrength = OneStrength + TwoStrength; return CRGBA( To.r * BlendVal + From.r * InvBlendVal,
return CRGBA( ((One.r * OneStrength) + (Two.r * TwoStrength))/TotalStrength, To.g * BlendVal + From.g * InvBlendVal,
((One.g * OneStrength) + (Two.g * TwoStrength))/TotalStrength, To.b * BlendVal + From.b * InvBlendVal,
((One.b * OneStrength) + (Two.b * TwoStrength))/TotalStrength, To.a * BlendVal + From.a * InvBlendVal); }
((One.a * OneStrength) + (Two.a * TwoStrength))/TotalStrength); }
template <typename T> friend CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal)
friend CRGBA Blend(const CRGBA& One, T OneStrength, const CRGBA& Two, T TwoStrength, const CRGBA& Three, T ThreeStrength) { double InvBlendVal = 1.0 - BlendVal;
{ T TotalStrength = OneStrength + TwoStrength + ThreeStrength; return CRGBA( sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal),
return CRGBA( ((One.r * OneStrength) + (Two.r * TwoStrength) + (Three.r * ThreeStrength))/TotalStrength, sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal),
((One.g * OneStrength) + (Two.g * TwoStrength) + (Three.g * ThreeStrength))/TotalStrength, sqrt((To.b * To.b) * BlendVal + (From.b * From.b) * InvBlendVal),
((One.b * OneStrength) + (Two.b * TwoStrength) + (Three.b * ThreeStrength))/TotalStrength, sqrt((To.a * To.a) * BlendVal + (From.a * From.a) * InvBlendVal)); }
((One.a * OneStrength) + (Two.a * TwoStrength) + (Three.a * ThreeStrength))/TotalStrength); }
// SilentPatch // SilentPatch
CRGBA* BlendGangColour(unsigned char r, unsigned char g, unsigned char b, unsigned char a); CRGBA* BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
}; };
class CRect class CRect

View file

@ -1,5 +1,6 @@
#include "StdAfxSA.h" #include "StdAfxSA.h"
#include <limits> #include <limits>
#include <algorithm>
#include "ScriptSA.h" #include "ScriptSA.h"
#include "GeneralSA.h" #include "GeneralSA.h"
@ -69,7 +70,7 @@ RwFrame* RwFrameForAllChildren(RwFrame* frame, RwFrameCallBack callBack, void* d
{ {
for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next ) for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next )
{ {
if ( !callBack(curFrame, data) ) if ( callBack(curFrame, data) == NULL )
break; break;
} }
return frame; return frame;
@ -79,7 +80,7 @@ RwFrame* RwFrameForAllObjects(RwFrame* frame, RwObjectCallBack callBack, void* d
{ {
for ( RwLLLink* link = rwLinkListGetFirstLLLink(&frame->objectList); link != rwLinkListGetTerminator(&frame->objectList); link = rwLLLinkGetNext(link) ) for ( RwLLLink* link = rwLinkListGetFirstLLLink(&frame->objectList); link != rwLinkListGetTerminator(&frame->objectList); link = rwLLLinkGetNext(link) )
{ {
if ( !callBack(&rwLLLinkGetData(link, RwObjectHasFrame, lFrame)->object, data) ) if ( callBack(&rwLLLinkGetData(link, RwObjectHasFrame, lFrame)->object, data) == NULL )
break; break;
} }
@ -131,7 +132,7 @@ RpClump* RpClumpForAllAtomics(RpClump* clump, RpAtomicCallBack callback, void* p
{ {
for ( RwLLLink* link = rwLinkListGetFirstLLLink(&clump->atomicList); link != rwLinkListGetTerminator(&clump->atomicList); link = rwLLLinkGetNext(link) ) for ( RwLLLink* link = rwLinkListGetFirstLLLink(&clump->atomicList); link != rwLinkListGetTerminator(&clump->atomicList); link = rwLLLinkGetNext(link) )
{ {
if ( !callback(rwLLLinkGetData(link, RpAtomic, inClumpLink), pData) ) if ( callback(rwLLLinkGetData(link, RpAtomic, inClumpLink), pData) == NULL )
break; break;
} }
return clump; return clump;
@ -148,7 +149,7 @@ RpClump* RpClumpRender(RpClump* clump)
{ {
// Not sure why they need this // Not sure why they need this
RwFrameGetLTM(RpAtomicGetFrame(curAtomic)); RwFrameGetLTM(RpAtomicGetFrame(curAtomic));
if ( !RpAtomicRender(curAtomic) ) if ( RpAtomicRender(curAtomic) == NULL )
retClump = NULL; retClump = NULL;
} }
} }
@ -159,7 +160,7 @@ RpGeometry* RpGeometryForAllMaterials(RpGeometry* geometry, RpMaterialCallBack f
{ {
for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ ) for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ )
{ {
if ( !fpCallBack(geometry->matList.materials[i], pData) ) if ( fpCallBack(geometry->matList.materials[i], pData) == NULL )
break; break;
} }
return geometry; return geometry;
@ -306,13 +307,13 @@ RpAtomic* TwoPassAlphaRender_aap(RpAtomic* atomic)
atomic = AtomicDefaultRenderCallBack(atomic); atomic = AtomicDefaultRenderCallBack(atomic);
if ( atomic ) if ( atomic != nullptr )
{ {
// 2nd pass // 2nd pass
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast<void*>(rwALPHATESTFUNCTIONLESS)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast<void*>(rwALPHATESTFUNCTIONLESS));
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
AtomicDefaultRenderCallBack(atomic); atomic = AtomicDefaultRenderCallBack(atomic);
} }
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
@ -345,14 +346,14 @@ RpAtomic* TwoPassAlphaRender_Silent(RpAtomic* atomic)
atomic = AtomicDefaultRenderCallBack(atomic); atomic = AtomicDefaultRenderCallBack(atomic);
if ( atomic ) if ( atomic != nullptr )
{ {
// 2nd pass // 2nd pass
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE)); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast<void*>(rwALPHATESTFUNCTIONLESS)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast<void*>(rwALPHATESTFUNCTIONLESS));
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
AtomicDefaultRenderCallBack(atomic); atomic = AtomicDefaultRenderCallBack(atomic);
} }
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
@ -630,9 +631,8 @@ bool GetCurrentZoneLockedOrUnlocked(float fPosX, float fPosY)
// By NTAuthority // By NTAuthority
void DrawMoonWithPhases(int moonColor, float* screenPos, float sizeX, float sizeY) void DrawMoonWithPhases(int moonColor, float* screenPos, float sizeX, float sizeY)
{ {
if ( !gpMoonMask ) if ( gpMoonMask == nullptr )
{ {
if ( GetFileAttributes("lunar.png") != INVALID_FILE_ATTRIBUTES ) if ( GetFileAttributes("lunar.png") != INVALID_FILE_ATTRIBUTES )
{ {
// load from file // load from file
@ -692,9 +692,10 @@ void DrawMoonWithPhases(int moonColor, float* screenPos, float sizeX, float size
//D3DPERF_EndEvent(); //D3DPERF_EndEvent();
} }
CRGBA* CRGBA::BlendGangColour(unsigned char r, unsigned char g, unsigned char b, unsigned char a) CRGBA* CRGBA::BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{ {
*this = Blend(CRGBA(r, g, b), pCurrZoneInfo->ZoneColour.a, HudColour[3], static_cast<BYTE>(255-pCurrZoneInfo->ZoneColour.a)); double colourIntensity = static_cast<double>(pCurrZoneInfo->ZoneColour.a) / 255.0;
*this = BlendSqr(CRGBA(r, g, b), HudColour[3], colourIntensity);
this->a = a; this->a = a;
return this; return this;
@ -702,7 +703,7 @@ CRGBA* CRGBA::BlendGangColour(unsigned char r, unsigned char g, unsigned char b,
void SunAndMoonFarClip() void SunAndMoonFarClip()
{ {
fSunFarClip = min(1500.0f, fFarClipZ); fSunFarClip = std::min(1500.0f, fFarClipZ);
DoSunAndMoon(); DoSunAndMoon();
} }

View file

@ -8,6 +8,7 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#define NOMINMAX
#define WINVER 0x0502 #define WINVER 0x0502
#define _WIN32_WINNT 0x0502 #define _WIN32_WINNT 0x0502
@ -50,12 +51,6 @@ extern RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*);
extern unsigned char& nGameClockDays; extern unsigned char& nGameClockDays;
extern unsigned char& nGameClockMonths; extern unsigned char& nGameClockMonths;
template<typename T>
inline T random(T a, T b)
{
return a + static_cast<T>(rand() * (1.0f/(RAND_MAX+1)) * (b - a));
}
#define DISABLE_FLA_DONATION_WINDOW 0 #define DISABLE_FLA_DONATION_WINDOW 0
//#define HIDE_MATERIAL //#define HIDE_MATERIAL

View file

@ -1,16 +1,27 @@
#include "StdAfxSA.h" #include "StdAfxSA.h"
#include <set> #include <algorithm>
#include <vector>
#include "VehicleSA.h" #include "VehicleSA.h"
#include "TimerSA.h" #include "TimerSA.h"
std::set<unsigned int> vecRotorExceptions; std::vector<unsigned int> vecRotorExceptions;
static bool ShouldIgnoreRotor( unsigned int id )
{
return std::find( vecRotorExceptions.begin(), vecRotorExceptions.end(), id ) != vecRotorExceptions.end();
}
static void* varVehicleRender = AddressByVersion<void*>(0x6D0E60, 0x6D1680, 0x70C0B0); static void* varVehicleRender = AddressByVersion<void*>(0x6D0E60, 0x6D1680, 0x70C0B0);
WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); } WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); }
static void* varIsLawEnforcementVehicle = AddressByVersion<void*>(0x6D2370, 0x6D2BA0, 0x70D8C0); static void* varIsLawEnforcementVehicle = AddressByVersion<void*>(0x6D2370, 0x6D2BA0, 0x70D8C0);
WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); } WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); }
static int32_t random(int32_t from, int32_t to)
{
return from + ( rand() % (to-from) );
}
static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data) static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data)
{ {
if ( RpAtomicGetFlags(pObject) & rpATOMICRENDER ) if ( RpAtomicGetFlags(pObject) & rpATOMICRENDER )
@ -62,7 +73,7 @@ void ReadRotorFixExceptions(const wchar_t* pPath)
unsigned int toList = _wtoi( fileID ); unsigned int toList = _wtoi( fileID );
if ( toList != 0 ) if ( toList != 0 )
vecRotorExceptions.insert( toList ); vecRotorExceptions.push_back( toList );
} }
delete[] buf; delete[] buf;
@ -93,7 +104,7 @@ bool CVehicle::CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo)
else if ( IsLawEnforcementVehicle() ) else if ( IsLawEnforcementVehicle() )
PlateDesign = CCustomCarPlateMgr::GetMapRegionPlateDesign(); PlateDesign = CCustomCarPlateMgr::GetMapRegionPlateDesign();
else else
PlateDesign = random(0, 20) == 0 ? random<signed char>(0, 3) : CCustomCarPlateMgr::GetMapRegionPlateDesign(); PlateDesign = random(0, 20) == 0 ? random(0, 3) : CCustomCarPlateMgr::GetMapRegionPlateDesign();
assert(PlateDesign >= 0 && PlateDesign < 3); assert(PlateDesign >= 0 && PlateDesign < 3);
@ -154,13 +165,14 @@ void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo
void CHeli::Render() void CHeli::Render()
{ {
double dRotorsSpeed, dMovingRotorSpeed; double dRotorsSpeed, dMovingRotorSpeed;
bool bHasMovingRotor = m_pCarNode[13] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0; bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex );
bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0;; bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors;
bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors;
m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000;
if ( m_fRotorSpeed > 0.0 ) if ( m_fRotorSpeed > 0.0 )
dRotorsSpeed = min(1.7 * (1.0/0.22) * m_fRotorSpeed, 1.5); dRotorsSpeed = std::min(1.7 * (1.0/0.22) * m_fRotorSpeed, 1.5);
else else
dRotorsSpeed = 0.0; dRotorsSpeed = 0.0;
@ -168,8 +180,8 @@ void CHeli::Render()
if ( dMovingRotorSpeed < 0.0 ) if ( dMovingRotorSpeed < 0.0 )
dMovingRotorSpeed = 0.0; dMovingRotorSpeed = 0.0;
int nStaticRotorAlpha = static_cast<int>(min((1.5-dRotorsSpeed) * 255.0, 255)); int nStaticRotorAlpha = static_cast<int>(std::min((1.5-dRotorsSpeed) * 255.0, 255.0));
int nMovingRotorAlpha = static_cast<int>(min(dMovingRotorSpeed * 175.0, 175)); int nMovingRotorAlpha = static_cast<int>(std::min(dMovingRotorSpeed * 175.0, 175.0));
if ( m_pCarNode[12] ) if ( m_pCarNode[12] )
{ {
@ -209,13 +221,14 @@ void CHeli::Render()
void CPlane::Render() void CPlane::Render()
{ {
double dRotorsSpeed, dMovingRotorSpeed; double dRotorsSpeed, dMovingRotorSpeed;
bool bHasMovingProp = m_pCarNode[13] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0; bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex );
bool bHasMovingProp2 = m_pCarNode[15] != nullptr && vecRotorExceptions.count(m_nModelIndex) == 0; bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors;
bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors;
m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000; m_nTimeTillWeNeedThisCar = CTimer::m_snTimeInMilliseconds + 3000;
if ( m_fPropellerSpeed > 0.0 ) if ( m_fPropellerSpeed > 0.0 )
dRotorsSpeed = min(1.7 * (1.0/0.31) * m_fPropellerSpeed, 1.5); dRotorsSpeed = std::min(1.7 * (1.0/0.31) * m_fPropellerSpeed, 1.5);
else else
dRotorsSpeed = 0.0; dRotorsSpeed = 0.0;
@ -223,8 +236,8 @@ void CPlane::Render()
if ( dMovingRotorSpeed < 0.0 ) if ( dMovingRotorSpeed < 0.0 )
dMovingRotorSpeed = 0.0; dMovingRotorSpeed = 0.0;
int nStaticRotorAlpha = static_cast<int>(min((1.5-dRotorsSpeed) * 255.0, 255)); int nStaticRotorAlpha = static_cast<int>(std::min((1.5-dRotorsSpeed) * 255.0, 255.0));
int nMovingRotorAlpha = static_cast<int>(min(dMovingRotorSpeed * 175.0, 175)); int nMovingRotorAlpha = static_cast<int>(std::min(dMovingRotorSpeed * 175.0, 175.0));
if ( m_pCarNode[12] ) if ( m_pCarNode[12] )
{ {