implemented CCutsceneHead and dependencies

This commit is contained in:
aap 2019-06-12 20:07:37 +02:00
parent cb5ec27747
commit a9517c01af
21 changed files with 374 additions and 20 deletions

View File

@ -4,3 +4,4 @@
bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5; bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5;
bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F; bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F;
CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88;

View File

@ -1,10 +1,14 @@
#pragma once #pragma once
class CDirectory;
class CCutsceneMgr class CCutsceneMgr
{ {
static bool &ms_running; static bool &ms_running;
static bool &ms_cutsceneProcessing; static bool &ms_cutsceneProcessing;
public: public:
static CDirectory *&ms_pCutsceneDir;
static bool IsRunning(void) { return ms_running; } static bool IsRunning(void) { return ms_running; }
static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; } static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; }
}; };

5
src/Radar.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "common.h"
#include "patcher.h"
#include "Radar.h"
WRAPPER void CRadar::ClearBlipForEntity(eBlipType type, int32 id) { EAXJMP(0x4A56C0); }

17
src/Radar.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
enum eBlipType
{
BLIP_NONE,
BLIP_CAR,
BLIP_CHAR,
BLIP_OBJECT,
BLIP_COORD,
BLIP_CONTACT_POINT
};
class CRadar
{
public:
static void ClearBlipForEntity(eBlipType type, int32 id);
};

View File

@ -29,6 +29,23 @@ DefinedState(void)
RwD3D8SetRenderState(D3DRS_ALPHAREF, 2); RwD3D8SetRenderState(D3DRS_ALPHAREF, 2);
} }
RwFrame*
GetFirstFrameCallback(RwFrame *child, void *data)
{
*(RwFrame**)data = child;
return nil;
}
RwFrame*
GetFirstChild(RwFrame *frame)
{
RwFrame *child;
child = nil;
RwFrameForAllChildren(frame, GetFirstFrameCallback, &child);
return child;
}
RwObject* RwObject*
GetFirstObjectCallback(RwObject *object, void *data) GetFirstObjectCallback(RwObject *object, void *data)
{ {
@ -46,6 +63,23 @@ GetFirstObject(RwFrame *frame)
return obj; return obj;
} }
RpAtomic*
GetFirstAtomicCallback(RpAtomic *atm, void *data)
{
*(RpAtomic**)data = atm;
return nil;
}
RpAtomic*
GetFirstAtomic(RpClump *clump)
{
RpAtomic *atm;
atm = nil;
RpClumpForAllAtomics(clump, GetFirstAtomicCallback, &atm);
return atm;
}
void void
CameraSize(RwCamera * camera, RwRect * rect, CameraSize(RwCamera * camera, RwRect * rect,
RwReal viewWindow, RwReal aspectRatio) RwReal viewWindow, RwReal aspectRatio)

View File

@ -1,13 +1,15 @@
#pragma once #pragma once
void DefinedState(void); void DefinedState(void);
RwFrame *GetFirstChild(RwFrame *frame);
RwObject *GetFirstObject(RwFrame *frame); RwObject *GetFirstObject(RwFrame *frame);
RpAtomic *GetFirstAtomic(RpClump *clump);
extern void CameraSize(RwCamera *camera, void CameraSize(RwCamera *camera,
RwRect *rect, RwRect *rect,
RwReal viewWindow, RwReal viewWindow,
RwReal aspectRatio); RwReal aspectRatio);
extern void CameraDestroy(RwCamera *camera); void CameraDestroy(RwCamera *camera);
extern RwCamera *CameraCreate(RwInt32 width, RwCamera *CameraCreate(RwInt32 width,
RwInt32 height, RwInt32 height,
RwBool zBuffer); RwBool zBuffer);

View File

@ -8,3 +8,21 @@ CStreamingInfo *CStreaming::ms_aInfoForModel = (CStreamingInfo*)0x6C7088;
WRAPPER void CStreaming::RemoveModel(int32 id) { EAXJMP(0x408830); } WRAPPER void CStreaming::RemoveModel(int32 id) { EAXJMP(0x408830); }
WRAPPER void CStreaming::RequestModel(int32 model, int32 flags) { EAXJMP(0x407EA0); } WRAPPER void CStreaming::RequestModel(int32 model, int32 flags) { EAXJMP(0x407EA0); }
WRAPPER void CStreaming::MakeSpaceFor(int32 size) { EAXJMP(0x409B70); }
void
CStreaming::ImGonnaUseStreamingMemory(void)
{
}
void
CStreaming::IHaveUsedStreamingMemory(void)
{
UpdateMemoryUsed();
}
void
CStreaming::UpdateMemoryUsed(void)
{
}

View File

@ -51,4 +51,8 @@ public:
static void RemoveModel(int32 id); static void RemoveModel(int32 id);
static void RequestModel(int32 model, int32 flags); static void RequestModel(int32 model, int32 flags);
static void MakeSpaceFor(int32 size);
static void ImGonnaUseStreamingMemory(void);
static void IHaveUsedStreamingMemory(void);
static void UpdateMemoryUsed(void);
}; };

View File

@ -14,6 +14,7 @@ class CTimer
static bool &m_CodePause; static bool &m_CodePause;
public: public:
static float GetTimeStep(void) { return ms_fTimeStep; } static float GetTimeStep(void) { return ms_fTimeStep; }
static float GetTimeStepNonClipped(void) { return ms_fTimeStepNonClipped; }
static void SetTimeStep(float ts) { ms_fTimeStep = ts; } static void SetTimeStep(float ts) { ms_fTimeStep = ts; }
static uint32 GetFrameCounter(void) { return m_FrameCounter; } static uint32 GetFrameCounter(void) { return m_FrameCounter; }
static uint32 GetTimeInMilliseconds(void) { return m_snTimeInMilliseconds; } static uint32 GetTimeInMilliseconds(void) { return m_snTimeInMilliseconds; }

View File

@ -135,6 +135,7 @@ int myrand(void);
void mysrand(unsigned int seed); void mysrand(unsigned int seed);
extern uint8 work_buff[55000]; extern uint8 work_buff[55000];
extern char gString[256];
void re3_debug(char *format, ...); void re3_debug(char *format, ...);
void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...); void re3_trace(const char *filename, unsigned int lineno, const char *func, char *format, ...);

View File

@ -1,2 +1,117 @@
#include "common.h" #include "common.h"
#include <rpskin.h>
#include "patcher.h"
#include "RwHelper.h"
#include "RpAnimBlend.h"
#include "AnimBlendClumpData.h"
#include "Directory.h"
#include "CutsceneMgr.h"
#include "Streaming.h"
#include "CutsceneHead.h" #include "CutsceneHead.h"
CCutsceneHead::CCutsceneHead(CObject *obj)
{
RpAtomic *atm;
assert(RwObjectGetType(obj->m_rwObject) == rpCLUMP);
m_pHeadNode = RpAnimBlendClumpFindFrame((RpClump*)obj->m_rwObject, "Shead")->frame;
atm = (RpAtomic*)GetFirstObject(m_pHeadNode);
if(atm){
assert(RwObjectGetType(atm) == rpATOMIC);
RpAtomicSetFlags(atm, RpAtomicGetFlags(atm) & ~rpATOMICRENDER);
}
}
void
CCutsceneHead::CreateRwObject(void)
{
RpAtomic *atm;
CEntity::CreateRwObject();
assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject);
RpSkinAtomicSetHAnimHierarchy(atm, RpHAnimFrameGetHierarchy(GetFirstChild(RpClumpGetFrame((RpClump*)m_rwObject))));
}
void
CCutsceneHead::DeleteRwObject(void)
{
CEntity::DeleteRwObject();
}
void
CCutsceneHead::ProcessControl(void)
{
RpAtomic *atm;
RpHAnimHierarchy *hier;
CPhysical::ProcessControl();
m_matrix.SetRotateY(PI/2);
m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix;
UpdateRwFrame();
assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject);
hier = RpSkinAtomicGetHAnimHierarchy(atm);
RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClipped()/50.0f);
}
void
CCutsceneHead::Render(void)
{
RpAtomic *atm;
m_matrix.SetRotateY(PI/2);
m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix;
UpdateRwFrame();
assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject);
RpHAnimHierarchyUpdateMatrices(RpSkinAtomicGetHAnimHierarchy(atm));
CObject::Render();
}
void
CCutsceneHead::PlayAnimation(const char *animName)
{
RpAtomic *atm;
RpHAnimHierarchy *hier;
RpHAnimAnimation *anim;
uint32 offset, size;
RwStream *stream;
assert(RwObjectGetType(m_rwObject) == rpCLUMP);
atm = GetFirstAtomic((RpClump*)m_rwObject);
hier = RpSkinAtomicGetHAnimHierarchy(atm);
sprintf(gString, "%s.anm", animName);
if(CCutsceneMgr::ms_pCutsceneDir->FindItem(gString, offset, size)){
stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG");
assert(stream);
CStreaming::MakeSpaceFor(size*2048);
CStreaming::ImGonnaUseStreamingMemory();
RwStreamSkip(stream, offset*2048);
if(RwStreamFindChunk(stream, rwID_HANIMANIMATION, nil, nil)){
anim = RpHAnimAnimationStreamRead(stream);
RpHAnimHierarchySetCurrentAnim(hier, anim);
}
CStreaming::IHaveUsedStreamingMemory();
RwStreamClose(stream, nil);
}
}
STARTPATCHES
InjectHook(0x4BA650, &CCutsceneHead::CreateRwObject_, PATCH_JUMP);
InjectHook(0x4BA690, &CCutsceneHead::DeleteRwObject_, PATCH_JUMP);
InjectHook(0x4BA760, &CCutsceneHead::ProcessControl_, PATCH_JUMP);
InjectHook(0x4BA800, &CCutsceneHead::Render_, PATCH_JUMP);
InjectHook(0x4BA6A0, &CCutsceneHead::PlayAnimation, PATCH_JUMP);
ENDPATCHES

View File

@ -6,5 +6,19 @@ class CCutsceneHead : public CCutsceneObject
{ {
public: public:
RwFrame *m_pHeadNode; RwFrame *m_pHeadNode;
CCutsceneHead(CObject *obj);
void CreateRwObject(void);
void DeleteRwObject(void);
void ProcessControl(void);
void Render(void);
void PlayAnimation(const char *animName);
void CreateRwObject_(void) { CCutsceneHead::CreateRwObject(); }
void DeleteRwObject_(void) { CCutsceneHead::DeleteRwObject(); }
void ProcessControl_(void) { CCutsceneHead::ProcessControl(); }
void Render_(void) { CCutsceneHead::Render(); }
}; };
static_assert(sizeof(CCutsceneHead) == 0x19C, "CCutsceneHead: error"); static_assert(sizeof(CCutsceneHead) == 0x19C, "CCutsceneHead: error");

View File

@ -1,2 +1,12 @@
#include "common.h" #include "common.h"
#include "CutsceneObject.h" #include "CutsceneObject.h"
CCutsceneObject::CCutsceneObject(void)
{
m_status = STATUS_SIMPLE;
bUsesCollision = false;
m_flagC20 = true;
ObjectCreatedBy = CUTSCENE_OBJECT;
m_fMass = 1.0f;
m_fTurnMass = 1.0f;
}

View File

@ -5,5 +5,6 @@
class CCutsceneObject : public CObject class CCutsceneObject : public CObject
{ {
public: public:
CCutsceneObject(void);
}; };
static_assert(sizeof(CCutsceneObject) == 0x198, "CCutsceneObject: error"); static_assert(sizeof(CCutsceneObject) == 0x198, "CCutsceneObject: error");

View File

@ -82,7 +82,7 @@ public:
uint32 m_flagD10 : 1; uint32 m_flagD10 : 1;
uint32 bDrawLast : 1; uint32 bDrawLast : 1;
uint32 m_flagD40 : 1; uint32 m_flagD40 : 1;
uint32 m_flagD80 : 1; uint32 m_flagD80 : 1; // CObject visibility?
// flagsE // flagsE
uint32 bDistanceFade : 1; uint32 bDistanceFade : 1;

View File

@ -1,9 +1,68 @@
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "Object.h"
#include "Pools.h" #include "Pools.h"
#include "Radar.h"
#include "Object.h"
WRAPPER void CObject::ObjectDamage(float amount) { EAXJMP(0x4BB240); }
int16 &CObject::nNoTempObjects = *(int16*)0x95CCA2;
void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); } void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); }
void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); } void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); }
WRAPPER void CObject::ObjectDamage(float amount) { EAXJMP(0x4BB240); } CObject::CObject(void)
{
m_type = ENTITY_TYPE_OBJECT;
m_fUprootLimit = 0.0f;
m_nCollisionDamageEffect = 0;
m_bSpecialCollisionResponseCases = 0;
m_bCameraToAvoidThisObject = 0;
ObjectCreatedBy = 0;
m_nEndOfLifeTime = 0;
// m_nRefModelIndex = -1; // duplicate
// bUseVehicleColours = false; // duplicate
m_colour2 = 0;
m_colour1 = m_colour2;
field_172 = 0;
m_obj_flag1 = false;
m_obj_flag2 = false;
m_obj_flag4 = false;
m_obj_flag8 = false;
m_obj_flag10 = false;
bHasBeenDamaged = false;
m_nRefModelIndex = -1;
bUseVehicleColours = false;
m_pCurSurface = nil;
m_pCollidingEntity = nil;
}
CObject::~CObject(void)
{
CRadar::ClearBlipForEntity(BLIP_OBJECT, CPools::GetObjectPool()->GetIndex(this));
if(m_nRefModelIndex != -1)
CModelInfo::GetModelInfo(m_nRefModelIndex)->RemoveRef();
if(ObjectCreatedBy == TEMP_OBJECT && nNoTempObjects != 0)
nNoTempObjects--;
}
void
CObject::Render(void)
{
if(m_flagD80)
return;
if(m_nRefModelIndex != -1 && ObjectCreatedBy == TEMP_OBJECT && bUseVehicleColours){
CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(m_nRefModelIndex);
assert(mi->m_type == MITYPE_VEHICLE);
mi->SetVehicleColour(m_colour1, m_colour2);
}
CEntity::Render();
}
STARTPATCHES
InjectHook(0x4BB1E0, &CObject::Render_, PATCH_JUMP);
ENDPATCHES

View File

@ -6,6 +6,7 @@ enum {
GAME_OBJECT = 1, GAME_OBJECT = 1,
MISSION_OBJECT = 2, MISSION_OBJECT = 2,
TEMP_OBJECT = 3, TEMP_OBJECT = 3,
CUTSCENE_OBJECT = 4,
}; };
class CVehicle; class CVehicle;
@ -22,7 +23,7 @@ public:
int8 m_obj_flag8 : 1; int8 m_obj_flag8 : 1;
int8 m_obj_flag10 : 1; int8 m_obj_flag10 : 1;
int8 bHasBeenDamaged : 1; int8 bHasBeenDamaged : 1;
int8 m_obj_flag40 : 1; int8 bUseVehicleColours : 1;
int8 m_obj_flag80 : 1; int8 m_obj_flag80 : 1;
int8 field_172; int8 field_172;
int8 field_173; int8 field_173;
@ -43,9 +44,19 @@ public:
CEntity *m_pCollidingEntity; CEntity *m_pCollidingEntity;
int8 m_colour1, m_colour2; int8 m_colour1, m_colour2;
static int16 &nNoTempObjects;
static void *operator new(size_t); static void *operator new(size_t);
static void operator delete(void*, size_t); static void operator delete(void*, size_t);
CObject(void);
~CObject(void);
void Render(void);
void ObjectDamage(float amount); void ObjectDamage(float amount);
void Render_(void) { CObject::Render(); }
}; };
static_assert(sizeof(CObject) == 0x198, "CObject: error"); static_assert(sizeof(CObject) == 0x198, "CObject: error");

View File

@ -15,6 +15,60 @@
#include "Automobile.h" #include "Automobile.h"
#include "Physical.h" #include "Physical.h"
CPhysical::CPhysical(void)
{
int i;
fForceMultiplier = 1.0f;
m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f);
m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f);
m_vecMoveSpeedAvg = CVector(0.0f, 0.0f, 0.0f);
m_vecTurnSpeedAvg = CVector(0.0f, 0.0f, 0.0f);
m_movingListNode = nil;
m_nStaticFrames = 0;
m_nCollisionRecords = 0;
for(i = 0; i < 6; i++)
m_aCollisionRecords[0] = nil;
field_EF = false;
m_nDamagePieceType = 0;
m_fDamageImpulse = 0.0f;
m_pDamageEntity = nil;
m_vecDamageNormal = CVector(0.0f, 0.0f, 0.0f);
bUsesCollision = true;
uAudioEntityId = -5;
unk1 = 100.0f;
m_vecCentreOfMass = CVector(0.0f, 0.0f, 0.0f);
field_EC = 0;
bIsHeavy = false;
bAffectedByGravity = true;
bInfiniteMass = false;
bIsInWater = false;
bHitByTrain = false;
m_phy_flagA80 = false;
m_fDistanceTravelled = 0.0f;
m_pedTreadable = nil;
m_carTreadable = nil;
m_phy_flagA10 = false;
m_phy_flagA20 = false;
m_nLastCollType = 0;
}
CPhysical::~CPhysical(void)
{
m_entryInfoList.Flush();
}
void void
CPhysical::Add(void) CPhysical::Add(void)
{ {

View File

@ -62,6 +62,8 @@ public:
uint8 m_nZoneLevel; uint8 m_nZoneLevel;
uint8 pad[3]; uint8 pad[3];
CPhysical(void);
~CPhysical(void);
// from CEntity // from CEntity
void Add(void); void Add(void);

View File

@ -56,6 +56,7 @@
uint8 work_buff[55000]; uint8 work_buff[55000];
char gString[256];
bool &b_FoundRecentSavedGameWantToLoad = *(bool*)0x95CDA8; bool &b_FoundRecentSavedGameWantToLoad = *(bool*)0x95CDA8;

View File

@ -16,26 +16,26 @@ public:
m_hasRwMatrix = false; m_hasRwMatrix = false;
*this = m; *this = m;
} }
CMatrix(RwMatrix *matrix, bool attach){ CMatrix(RwMatrix *matrix, bool owner = false){
m_attachment = nil; m_attachment = nil;
Attach(matrix, attach); Attach(matrix, owner);
} }
~CMatrix(void){ ~CMatrix(void){
if(m_hasRwMatrix && m_attachment) if(m_hasRwMatrix && m_attachment)
RwMatrixDestroy(m_attachment); RwMatrixDestroy(m_attachment);
} }
void Attach(RwMatrix *matrix, bool attach){ void Attach(RwMatrix *matrix, bool owner = false){
if(m_hasRwMatrix && m_attachment) if(m_hasRwMatrix && m_attachment)
RwMatrixDestroy(m_attachment); RwMatrixDestroy(m_attachment);
m_attachment = matrix; m_attachment = matrix;
m_hasRwMatrix = attach; m_hasRwMatrix = owner;
Update(); Update();
} }
void AttachRW(RwMatrix *matrix, bool attach){ void AttachRW(RwMatrix *matrix, bool owner = false){
if(m_hasRwMatrix && m_attachment) if(m_hasRwMatrix && m_attachment)
RwMatrixDestroy(m_attachment); RwMatrixDestroy(m_attachment);
m_attachment = matrix; m_attachment = matrix;
m_hasRwMatrix = attach; m_hasRwMatrix = owner;
UpdateRW(); UpdateRW();
} }
void Detach(void){ void Detach(void){