Mostly ready for multiple EXEs compatibility

TODO: RW calls
This commit is contained in:
Silent 2014-08-04 14:30:16 +02:00
parent b80846091f
commit abb1db6b44
10 changed files with 49 additions and 31 deletions

View file

@ -128,9 +128,6 @@ public:
class CAEWaveDecoder : public CAEStreamingDecoder class CAEWaveDecoder : public CAEStreamingDecoder
{ {
private: private:
unsigned short nNumChannels;
unsigned short nBitRate;
unsigned int nSampleRate;
unsigned int nDataSize; unsigned int nDataSize;
unsigned int nOffsetToData; unsigned int nOffsetToData;
//bool bInitialised; //bool bInitialised;

View file

@ -2,18 +2,13 @@
#include "GeneralSA.h" #include "GeneralSA.h"
// Wrappers // Wrappers
WRAPPER bool CalcScreenCoors(const CVector& vecIn, CVector* vecOut) { WRAPARG(vecIn); WRAPARG(vecOut); EAXJMP(0x71DAB0); } static void* EntityRender = AddressByVersion<void*>(0x534310, 0, 0);
WRAPPER void LoadingScreenLoadingFile(const char* pText) { WRAPARG(pText); EAXJMP(0x5B3680); } WRAPPER void CEntity::Render() { VARJMP(EntityRender); }
WRAPPER void CEntity::UpdateRW() { EAXJMP(0x446F90); } static RwTexture*& ms_pRemapTexture = **AddressByVersion<RwTexture***>(0x59F1BD, 0, 0);
WRAPPER void CEntity::RegisterReference(CEntity** pAddress) { WRAPARG(pAddress); EAXJMP(0x571B70); } static unsigned char* ms_currentCol = *AddressByVersion<unsigned char**>(0x4C84C8, 0, 0);
WRAPPER void CEntity::CleanUpOldReference(CEntity** pAddress) { WRAPARG(pAddress); EAXJMP(0x571A00); }
WRAPPER void CEntity::Render() { EAXJMP(0x534310); }
static RwTexture*& ms_pRemapTexture = *(RwTexture**)0xB4E47C; auto SetEditableMaterialsCB = AddressByVersion<RpAtomic*(*)(RpAtomic*,void*)>(0x4C83E0, 0, 0);
static unsigned char* ms_currentCol = *(unsigned char**)0x4C84C8;
WRAPPER RpAtomic* SetEditableMaterialsCB(RpAtomic* pMaterial, void* pData) { WRAPARG(pMaterial); WRAPARG(pData); EAXJMP(0x4C83E0); }
static void SetVehicleColour(unsigned char primaryColour, unsigned char secondaryColour, unsigned char tertiaryColour, unsigned char quaternaryColour) static void SetVehicleColour(unsigned char primaryColour, unsigned char secondaryColour, unsigned char tertiaryColour, unsigned char quaternaryColour)
{ {

View file

@ -1,12 +1,13 @@
#include "StdAfxSA.h" #include "StdAfxSA.h"
#include "ModelInfoSA.h" #include "ModelInfoSA.h"
WRAPPER void CBaseModelInfo::Shutdown() { EAXJMP(0x4C4D50); } static void* BaseModelInfoShutdown = AddressByVersion<void*>(0x4C4D50, 0, 0);
WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); }
WRAPPER RwTexture* CCustomCarPlateMgr::CreatePlateTexture(const char* pText, signed char nDesign) { EAXJMP(0x6FDEA0); } RwTexture* (*CCustomCarPlateMgr::CreatePlateTexture)(const char* pText, signed char nDesign) = AddressByVersion<RwTexture*(*)(const char*,signed char)>(0x6FDEA0, 0, 0);
WRAPPER bool CCustomCarPlateMgr::GeneratePlateText(char* pBuf, int nLen) { EAXJMP(0x6FD5B0); } bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen) = AddressByVersion<bool(*)(char*,int)>(0x6FD5B0, 0, 0);
WRAPPER signed char CCustomCarPlateMgr::GetMapRegionPlateDesign() { EAXJMP(0x6FD7A0); } signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion<signed char(*)()>(0x6FD7A0, 0, 0);
WRAPPER void CCustomCarPlateMgr::SetupMaterialPlatebackTexture(RpMaterial* pMaterial, signed char nDesign) { EAXJMP(0x6FDE50); } void (*CCustomCarPlateMgr::SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign) = AddressByVersion<void(*)(RpMaterial*,signed char)>(0x6FDE50, 0, 0);
void CVehicleModelInfo::Shutdown() void CVehicleModelInfo::Shutdown()
{ {

View file

@ -292,10 +292,10 @@ private:
//static signed char m_nCurPlateDesign; //static signed char m_nCurPlateDesign;
public: public:
static RwTexture* CreatePlateTexture(const char* pText, signed char nDesign); static RwTexture* (*CreatePlateTexture)(const char* pText, signed char nDesign);
static bool GeneratePlateText(char* pBuf, int nLen); static bool (*GeneratePlateText)(char* pBuf, int nLen);
static signed char GetMapRegionPlateDesign(); static signed char (*GetMapRegionPlateDesign)();
static void SetupMaterialPlatebackTexture(RpMaterial* pMaterial, signed char nDesign); static void (*SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign);
static void SetupClump(RpClump* pClump, RpMaterial** pMatsArray); static void SetupClump(RpClump* pClump, RpMaterial** pMatsArray);
static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign); static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign);

View file

@ -24,10 +24,11 @@ RwTexture* CPNGFile::ReadFromFile(const char* pFileName)
RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen) RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen)
{ {
static BYTE* pMem = AddressByVersion<BYTE*>(0x7CF9CA, 0, 0);
RwTexture* pTexture = nullptr; RwTexture* pTexture = nullptr;
// TOOO: EXEs // TOOO: EXEs
MemoryVP::Patch<BYTE>(0x7CF9CA, rwSTREAMMEMORY); MemoryVP::Patch<BYTE>(pMem, rwSTREAMMEMORY);
RwMemory PNGMemory; RwMemory PNGMemory;
PNGMemory.start = const_cast<RwUInt8*>(static_cast<const RwUInt8*>(pMemory)); PNGMemory.start = const_cast<RwUInt8*>(static_cast<const RwUInt8*>(pMemory));
@ -48,7 +49,7 @@ RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen)
RwImageDestroy(pImage); RwImageDestroy(pImage);
} }
MemoryVP::Patch<BYTE>(0x7CF9CA, rwSTREAMFILENAME); MemoryVP::Patch<BYTE>(pMem, rwSTREAMFILENAME);
return pTexture; return pTexture;
} }

View file

@ -77,6 +77,9 @@ CZoneInfo*& pCurrZoneInfo = **AddressByVersion<CZoneInfo***>(0x58ADB1, 0, 0);
CRGBA* HudColour = *AddressByVersion<CRGBA**>(0x58ADF6, 0, 0); CRGBA* HudColour = *AddressByVersion<CRGBA**>(0x58ADF6, 0, 0);
unsigned char* ZonesVisited = *AddressByVersion<unsigned char**>(0x57216A, 0, 0) - 9; unsigned char* ZonesVisited = *AddressByVersion<unsigned char**>(0x57216A, 0, 0) - 9;
float& m_fDNBalanceParam = **AddressByVersion<float**>(0x4A9062, 0, 0);
RpLight*& pAmbient = **AddressByVersion<RpLight***>(0x5BA53A, 0, 0);
CLinkListSA<CEntity*>& ms_weaponPedsForPC = **AddressByVersion<CLinkListSA<CEntity*>**>(0x53EACA, 0, 0); CLinkListSA<CEntity*>& ms_weaponPedsForPC = **AddressByVersion<CLinkListSA<CEntity*>**>(0x53EACA, 0, 0);
CLinkListSA<AlphaObjectInfo>& m_alphaList = **AddressByVersion<CLinkListSA<AlphaObjectInfo>**>(0x733A4D, 0, 0); CLinkListSA<AlphaObjectInfo>& m_alphaList = **AddressByVersion<CLinkListSA<AlphaObjectInfo>**>(0x733A4D, 0, 0);
@ -537,10 +540,9 @@ void SetShader(RxD3D9InstanceData* pInstData)
{ {
if ( bRenderNVC ) if ( bRenderNVC )
{ {
// TODO: Daynight balance var
D3DMATRIX outMat; D3DMATRIX outMat;
float fEnvVars[2] = { *(float*)0x8D12C0, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; float fEnvVars[2] = { m_fDNBalanceParam, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) };
RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8); RwRGBAReal* AmbientLight = RpLightGetColor(pAmbient);
// Normalise the balance // Normalise the balance
if ( fEnvVars[0] < 0.0f ) if ( fEnvVars[0] < 0.0f )
@ -551,6 +553,7 @@ void SetShader(RxD3D9InstanceData* pInstData)
RwD3D9SetVertexShader(pNVCShader); RwD3D9SetVertexShader(pNVCShader);
_rwD3D9VSSetActiveWorldMatrix(RwFrameGetLTM(RpAtomicGetFrame(pRenderedAtomic))); _rwD3D9VSSetActiveWorldMatrix(RwFrameGetLTM(RpAtomicGetFrame(pRenderedAtomic)));
//_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic)));
_rwD3D9VSGetComposedTransformMatrix(&outMat); _rwD3D9VSGetComposedTransformMatrix(&outMat);
RwD3D9SetVertexShaderConstant(0, &outMat, 4); RwD3D9SetVertexShaderConstant(0, &outMat, 4);
@ -1307,6 +1310,7 @@ __forceinline void Patch_SA_10()
// PS2 SUN!!!!!!!!!!!!!!!!! // PS2 SUN!!!!!!!!!!!!!!!!!
static const float fSunMult = (1050.0f * 0.95f) / 1500.0f; static const float fSunMult = (1050.0f * 0.95f) / 1500.0f;
// TODO: Use min()
Nop(0x6FB17C, 3); Nop(0x6FB17C, 3);
Patch<const void*>(0x6FC5B0, &fSunMult); Patch<const void*>(0x6FC5B0, &fSunMult);
//Patch<WORD>(0x6FB172, 0x0BEB); //Patch<WORD>(0x6FB172, 0x0BEB);

View file

@ -2,6 +2,7 @@
#pragma warning(disable:4401) // member is bit field #pragma warning(disable:4401) // member is bit field
#pragma warning(disable:4733) // handler not registered as safe handler #pragma warning(disable:4733) // handler not registered as safe handler
#pragma warning(disable:4725) // instruction may be inaccurate on some Pentiums #pragma warning(disable:4725) // instruction may be inaccurate on some Pentiums
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS

View file

@ -3,9 +3,12 @@
#include "VehicleSA.h" #include "VehicleSA.h"
#include "TimerSA.h" #include "TimerSA.h"
WRAPPER void CVehicle::SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha) { WRAPARG(pAtomic); WRAPARG(nAlpha); EAXJMP(0x6D2960); } void (*CVehicle::SetComponentAtomicAlpha)(RpAtomic* pAtomic, int nAlpha) = AddressByVersion<void(*)(RpAtomic*,int)>(0x6D2960, 0, 0);
WRAPPER void CVehicle::Render() { EAXJMP(0x6D0E60); }
WRAPPER bool CVehicle::IsLawEnforcementVehicle() { EAXJMP(0x6D2370); } static void* varVehicleRender = AddressByVersion<void*>(0x6D0E60, 0, 0);
WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); }
static void* varIsLawEnforcementVehicle = AddressByVersion<void*>(0x6D2370, 0, 0);
WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); }
static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data) static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data)
{ {

View file

@ -115,7 +115,7 @@ public:
bool IsLawEnforcementVehicle(); bool IsLawEnforcementVehicle();
static void SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha); static void (*SetComponentAtomicAlpha)(RpAtomic* pAtomic, int nAlpha);
}; };
class NOVMT CAutomobile : public CVehicle class NOVMT CAutomobile : public CVehicle

View file

@ -29,6 +29,12 @@ inline bool* GetEuropean()
return &bEuropean; return &bEuropean;
} }
inline void* GetDummy()
{
static DWORD dwDummy;
return &dwDummy;
}
// This function initially detects SA version then chooses the address basing on game version // This function initially detects SA version then chooses the address basing on game version
template<typename T> template<typename T>
inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
@ -64,10 +70,16 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
*bEuropean = false; *bEuropean = false;
} }
} }
switch ( *bVer ) switch ( *bVer )
{ {
case 1: case 1:
assert(address11); assert(address11);
// Safety measures - if null, return dummy var pointer to prevent a crash
if ( !address11 )
return (T)GetDummy();
// Adjust to EU if needed // Adjust to EU if needed
if ( *bEuropean && address11 > 0x746FA0 ) if ( *bEuropean && address11 > 0x746FA0 )
{ {
@ -79,6 +91,10 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
return (T)address11; return (T)address11;
case 2: case 2:
assert(addressSteam); assert(addressSteam);
// Safety measures - if null, return dummy var pointer to prevent a crash
if ( !addressSteam )
return (T)GetDummy();
return (T)addressSteam; return (T)addressSteam;
default: default:
assert(address10); assert(address10);