Weapons and jetpack render in a shadow now

This commit is contained in:
Silent 2014-08-19 13:16:38 +02:00
parent 77d61dcdd2
commit f73e9cfb07
5 changed files with 121 additions and 10 deletions

View file

@ -1,10 +1,15 @@
#include "StdAfxSA.h" #include "StdAfxSA.h"
#include "GeneralSA.h" #include "GeneralSA.h"
#include "PedSA.h"
// Wrappers // Wrappers
static void* EntityRender = AddressByVersion<void*>(0x534310, 0, 0); static void* EntityRender = AddressByVersion<void*>(0x534310, 0, 0);
WRAPPER void CEntity::Render() { VARJMP(EntityRender); } WRAPPER void CEntity::Render() { VARJMP(EntityRender); }
static void* varInvertRaster = AddressByVersion<void*>(0x705660, 0, 0);
WRAPPER void CShadowCamera::InvertRaster() { VARJMP(varInvertRaster); }
CWeaponInfo* (*CWeaponInfo::GetWeaponInfo)(eWeaponType, signed char) = AddressByVersion<CWeaponInfo*(*)(eWeaponType, signed char)>(0x743C60, 0, 0); CWeaponInfo* (*CWeaponInfo::GetWeaponInfo)(eWeaponType, signed char) = AddressByVersion<CWeaponInfo*(*)(eWeaponType, signed char)>(0x743C60, 0, 0);
static RwTexture*& ms_pRemapTexture = **AddressByVersion<RwTexture***>(0x59F1BD, 0, 0); static RwTexture*& ms_pRemapTexture = **AddressByVersion<RwTexture***>(0x59F1BD, 0, 0);
@ -26,6 +31,24 @@ static void ResetEditableMaterials(std::pair<void*,int>* pData)
*static_cast<int*>(i->first) = i->second; *static_cast<int*>(i->first) = i->second;
} }
RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic, void* pData)
{
UNREFERENCED_PARAMETER(pData);
if ( RpAtomicGetFlags(pAtomic) & rpATOMICRENDER )
{
RpGeometry* pGeometry = RpAtomicGetGeometry(pAtomic);
RwUInt32 geometryFlags = RpGeometryGetFlags(pGeometry);
RpGeometrySetFlags(pGeometry, geometryFlags & ~(rpGEOMETRYTEXTURED|rpGEOMETRYPRELIT|
/*rpGEOMETRYNORMALS|*/rpGEOMETRYLIGHT|rpGEOMETRYMODULATEMATERIALCOLOR|rpGEOMETRYTEXTURED2));
AtomicDefaultRenderCallBack(pAtomic);
RpGeometrySetFlags(pGeometry, geometryFlags);
}
return pAtomic;
}
void CObject::Render() void CObject::Render()
{ {
if ( m_bDoNotRender || !m_pRwObject ) if ( m_bDoNotRender || !m_pRwObject )
@ -53,4 +76,25 @@ void CObject::Render()
if ( bCallRestore ) if ( bCallRestore )
ResetEditableMaterials(materialRestoreData); ResetEditableMaterials(materialRestoreData);
}
RwCamera* CShadowCamera::Update(CEntity* pEntity)
{
RwRGBA ClearColour = { 255, 255, 255, 0 };
RwCameraClear(m_pCamera, &ClearColour, rwCAMERACLEARIMAGE|rwCAMERACLEARZ);
if ( RwCameraBeginUpdate(m_pCamera ) )
{
if ( pEntity )
{
if ( pEntity->nType == 3 )
static_cast<CPed*>(pEntity)->RenderForShadow();
else
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(pEntity->m_pRwObject), ShadowCameraRenderCB, nullptr);
}
InvertRaster();
RwCameraEndUpdate(m_pCamera);
}
return m_pCamera;
} }

View file

@ -549,6 +549,20 @@ public:
static CWeaponInfo* (*GetWeaponInfo)(eWeaponType weaponID, signed char bType); static CWeaponInfo* (*GetWeaponInfo)(eWeaponType weaponID, signed char bType);
}; };
class CShadowCamera
{
public:
RwCamera* m_pCamera;
RwTexture* m_pTexture;
public:
void InvertRaster();
RwCamera* Update(CEntity* pEntity);
};
RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic, void* pData);
static_assert(sizeof(CEntity) == 0x38, "Wrong size: CEntity"); static_assert(sizeof(CEntity) == 0x38, "Wrong size: CEntity");
static_assert(sizeof(CPhysical) == 0x138, "Wrong size: CPhysical"); static_assert(sizeof(CPhysical) == 0x138, "Wrong size: CPhysical");
static_assert(sizeof(CObject) == 0x17C, "Wrong size: CObject"); static_assert(sizeof(CObject) == 0x17C, "Wrong size: CObject");

View file

@ -8,6 +8,12 @@ WRAPPER void CPed::ResetGunFlashAlpha() { VARJMP(varResetGunFlashAlpha); }
static void* varSetGunFlashAlpha = AddressByVersion<void*>(0x5DF400, 0, 0); static void* varSetGunFlashAlpha = AddressByVersion<void*>(0x5DF400, 0, 0);
WRAPPER void CPed::SetGunFlashAlpha(bool bSecondWeapon) { WRAPARG(bSecondWeapon); VARJMP(varSetGunFlashAlpha); } WRAPPER void CPed::SetGunFlashAlpha(bool bSecondWeapon) { WRAPARG(bSecondWeapon); VARJMP(varSetGunFlashAlpha); }
static void* varGetTaskJetPack = AddressByVersion<void*>(0x601110, 0, 0);
WRAPPER CTaskSimpleJetPack* CPedIntelligence::GetTaskJetPack() const { VARJMP(varGetTaskJetPack); }
static void* varRenderJetPack = AddressByVersion<void*>(0x67F6A0, 0, 0);
WRAPPER void CTaskSimpleJetPack::RenderJetPack(CPed* pPed) { WRAPARG(pPed); VARJMP(varRenderJetPack); }
static RwObject* GetFirstObjectCallback(RwObject* pObject, void* pData) static RwObject* GetFirstObjectCallback(RwObject* pObject, void* pData)
{ {
*static_cast<RwObject**>(pData) = pObject; *static_cast<RwObject**>(pData) = pObject;
@ -21,7 +27,7 @@ RwObject* GetFirstObject(RwFrame* pFrame)
return pObject; return pObject;
} }
void CPed::RenderWeapon(bool bMuzzleFlash) void CPed::RenderWeapon(bool bMuzzleFlash, bool bForShadow)
{ {
if ( m_pWeaponObject ) if ( m_pWeaponObject )
{ {
@ -40,10 +46,10 @@ void CPed::RenderWeapon(bool bMuzzleFlash)
} }
RwFrameUpdateObjects(pFrame); RwFrameUpdateObjects(pFrame);
if ( !bMuzzleFlash ) if ( bForShadow )
{ RpClumpForAllAtomics(reinterpret_cast<RpClump*>(m_pWeaponObject), ShadowCameraRenderCB, nullptr);
else if ( !bMuzzleFlash )
RpClumpRender(reinterpret_cast<RpClump*>(m_pWeaponObject)); RpClumpRender(reinterpret_cast<RpClump*>(m_pWeaponObject));
}
else if ( m_pMuzzleFlashFrame ) else if ( m_pMuzzleFlashFrame )
{ {
SetGunFlashAlpha(false); SetGunFlashAlpha(false);
@ -61,10 +67,10 @@ void CPed::RenderWeapon(bool bMuzzleFlash)
RwMatrixTranslate(RwFrameGetMatrix(pFrame), &vecParachuteTranslation, rwCOMBINEPRECONCAT); RwMatrixTranslate(RwFrameGetMatrix(pFrame), &vecParachuteTranslation, rwCOMBINEPRECONCAT);
RwFrameUpdateObjects(pFrame); RwFrameUpdateObjects(pFrame);
if ( !bMuzzleFlash ) if ( bForShadow )
{ RpClumpForAllAtomics(reinterpret_cast<RpClump*>(m_pWeaponObject), ShadowCameraRenderCB, nullptr);
else if ( !bMuzzleFlash )
RpClumpRender(reinterpret_cast<RpClump*>(m_pWeaponObject)); RpClumpRender(reinterpret_cast<RpClump*>(m_pWeaponObject));
}
else if ( m_pMuzzleFlashFrame ) else if ( m_pMuzzleFlashFrame )
{ {
SetGunFlashAlpha(true); SetGunFlashAlpha(true);
@ -74,4 +80,15 @@ void CPed::RenderWeapon(bool bMuzzleFlash)
if ( bMuzzleFlash ) if ( bMuzzleFlash )
ResetGunFlashAlpha(); ResetGunFlashAlpha();
} }
}
void CPed::RenderForShadow()
{
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(m_pRwObject), ShadowCameraRenderCB, nullptr);
RenderWeapon(false, true);
// Render jetpack
auto* pJetPackTask = pPedIntelligence->GetTaskJetPack();
if ( pJetPackTask )
pJetPackTask->RenderJetPack(this);
} }

View file

@ -5,6 +5,19 @@
class CEntryExit; class CEntryExit;
// Stub
class CTaskSimpleJetPack
{
public:
void RenderJetPack(class CPed* pPed);
};
class CPedIntelligence
{
public:
class CTaskSimpleJetPack* GetTaskJetPack() const;
};
class CPedFlags class CPedFlags
{ {
public: public:
@ -297,7 +310,8 @@ public:
void ResetGunFlashAlpha(); void ResetGunFlashAlpha();
void SetGunFlashAlpha(bool bSecondWeapon); void SetGunFlashAlpha(bool bSecondWeapon);
void RenderWeapon(bool bMuzzleFlash); void RenderWeapon(bool bMuzzleFlash, bool bForShadow);
void RenderForShadow();
}; };
static_assert(sizeof(CPed) == 0x79C, "Wrong size: CPed"); static_assert(sizeof(CPed) == 0x79C, "Wrong size: CPed");

View file

@ -51,6 +51,21 @@ WRAPPER RwBool _rpD3D9VertexDeclarationInstColor(RwUInt8 *mem,
RwUInt32 stride) { VARJMP(var_rpD3D9VertexDeclarationInstColor); } RwUInt32 stride) { VARJMP(var_rpD3D9VertexDeclarationInstColor); }
RwCamera* RwCameraBeginUpdate(RwCamera* camera)
{
return camera->beginUpdate(camera);
}
RwCamera* RwCameraEndUpdate(RwCamera* camera)
{
return camera->endUpdate(camera);
}
RwCamera* RwCameraClear(RwCamera* camera, RwRGBA* colour, RwInt32 clearMode)
{
return RWSRCGLOBAL(stdFunc[rwSTANDARDCAMERACLEAR])(camera, colour, clearMode) != FALSE ? camera : NULL;
}
RwFrame* RwFrameForAllChildren(RwFrame* frame, RwFrameCallBack callBack, void* data) RwFrame* RwFrameForAllChildren(RwFrame* frame, RwFrameCallBack callBack, void* data)
{ {
for ( RwFrame* curFrame = frame->child; curFrame; curFrame = curFrame->next ) for ( RwFrame* curFrame = frame->child; curFrame; curFrame = curFrame->next )
@ -452,7 +467,7 @@ void SetRendererForAtomic(RpAtomic* pAtomic)
void RenderWeapon(CPed* pPed) void RenderWeapon(CPed* pPed)
{ {
pPed->RenderWeapon(false); pPed->RenderWeapon(false, false);
ms_weaponPedsForPC.Insert(pPed); ms_weaponPedsForPC.Insert(pPed);
} }
@ -464,7 +479,7 @@ void RenderWeaponPedsForPC()
for ( auto it = ms_weaponPedsForPC.m_lnListHead.m_pNext; it != &ms_weaponPedsForPC.m_lnListTail; it = it->m_pNext ) for ( auto it = ms_weaponPedsForPC.m_lnListHead.m_pNext; it != &ms_weaponPedsForPC.m_lnListTail; it = it->m_pNext )
{ {
it->V()->SetupLighting(); it->V()->SetupLighting();
it->V()->RenderWeapon(true); it->V()->RenderWeapon(true, false);
it->V()->RemoveLighting(); it->V()->RemoveLighting();
} }
} }
@ -1327,6 +1342,13 @@ BOOL InjectDelayedPatches_10()
Nop(0x6D6517, 2); Nop(0x6D6517, 2);
} }
// SSE conflicts
if ( GetModuleHandle("shadows.asi") == nullptr )
{
Patch<DWORD>(0x70665C, 0x52909090);
InjectHook(0x706662, &CShadowCamera::Update);
}
// Bigger streamed entity linked lists // Bigger streamed entity linked lists
// Increase only if they're not increased already // Increase only if they're not increased already
if ( *(DWORD*)0x5B8E55 == 12000 ) if ( *(DWORD*)0x5B8E55 == 12000 )