implemented CObjectData

This commit is contained in:
aap 2019-06-19 18:35:51 +02:00
parent 864f719b1e
commit 2ec11b000d
10 changed files with 153 additions and 23 deletions

View File

@ -1,5 +1,103 @@
#include "common.h"
#include "patcher.h"
#include "main.h"
#include "ModelInfo.h"
#include "Object.h"
#include "FileMgr.h"
#include "ObjectData.h"
WRAPPER void CObjectData::Initialise(const char *filename) { EAXJMP(0x4BC0E0); }
CObjectInfo CObjectData::ms_aObjectInfo[NUMOBJECTINFO];
// Another ugly file reader
void
CObjectData::Initialise(const char *filename)
{
char *p, *lp;
char line[1024], name[256];
int id;
float percentSubmerged;
int damageEffect, responseCase, camAvoid;
CBaseModelInfo *mi;
CFileMgr::SetDir("");
CFileMgr::LoadFile(filename, work_buff, 55000, "r");
id = 0;
p = (char*)work_buff;
while(*p != '*'){
// skip over white space and comments
while(*p == ' ' || *p == '\n' || *p == '\r' || *p == ';')
if(*p == ';')
while(*p != '\n' && *p != '*')
p++;
else
p++;
if(*p == '*')
break;
// read one line
lp = line;
while(*p != '\n' && *p != '*'){
*lp++ = *p == ',' ? ' ' : *p;
p++;
}
if(*p == '\n')
p++;
*lp = '\0'; // FIX: game wrote '\n' here
assert(id < NUMOBJECTINFO);
sscanf(line, "%s %f %f %f %f %f %f %f %d %d %d", name,
&ms_aObjectInfo[id].m_fMass,
&ms_aObjectInfo[id].m_fTurnMass,
&ms_aObjectInfo[id].m_fAirResistance,
&ms_aObjectInfo[id].m_fElasticity,
&percentSubmerged,
&ms_aObjectInfo[id].m_fUprootLimit,
&ms_aObjectInfo[id].m_fCollisionDamageMultiplier,
&damageEffect, &responseCase, &camAvoid);
ms_aObjectInfo[id].m_fBuoyancy = 100.0f/percentSubmerged * 0.008*ms_aObjectInfo[id].m_fMass;
ms_aObjectInfo[id].m_nCollisionDamageEffect = damageEffect;
ms_aObjectInfo[id].m_nSpecialCollisionResponseCases = responseCase;
ms_aObjectInfo[id].m_bCameraToAvoidThisObject = camAvoid;
mi = CModelInfo::GetModelInfo(name, nil);
if(mi)
mi->SetObjectID(id++);
else
debug("CObjectData: Cannot find object %s\n", name);
}
}
void
CObjectData::SetObjectData(int32 modelId, CObject &object)
{
CObjectInfo *objinfo;
if(CModelInfo::GetModelInfo(modelId)->GetObjectID() == -1)
return;
objinfo = &ms_aObjectInfo[CModelInfo::GetModelInfo(modelId)->GetObjectID()];
object.m_fMass = objinfo->m_fMass;
object.m_fTurnMass = objinfo->m_fTurnMass;
object.m_fAirResistance = objinfo->m_fAirResistance;
object.m_fElasticity = objinfo->m_fElasticity;
object.m_fBuoyancy = objinfo->m_fBuoyancy;
object.m_fUprootLimit = objinfo->m_fUprootLimit;
object.m_fCollisionDamageMultiplier = objinfo->m_fCollisionDamageMultiplier;
object.m_nCollisionDamageEffect = objinfo->m_nCollisionDamageEffect;
object.m_nSpecialCollisionResponseCases = objinfo->m_nSpecialCollisionResponseCases;
object.m_bCameraToAvoidThisObject = objinfo->m_bCameraToAvoidThisObject;
if(object.m_fMass >= 99998.0){
object.bInfiniteMass = true;
object.bAffectedByGravity = false;
object.m_flagB2 = true;
}
}
STARTPATCHES
InjectHook(0x4BC0E0, CObjectData::Initialise, PATCH_JUMP);
InjectHook(0x4BC270, CObjectData::SetObjectData, PATCH_JUMP);
ENDPATCHES

View File

@ -1,7 +1,27 @@
#pragma once
class CObject;
class CObjectInfo
{
public:
float m_fMass;
float m_fTurnMass;
float m_fAirResistance;
float m_fElasticity;
float m_fBuoyancy;
float m_fUprootLimit;
float m_fCollisionDamageMultiplier;
uint8 m_nCollisionDamageEffect;
uint8 m_nSpecialCollisionResponseCases;
bool m_bCameraToAvoidThisObject;
};
static_assert(sizeof(CObjectInfo) == 0x20, "CObjectInfo: error");
class CObjectData
{
static CObjectInfo ms_aObjectInfo[NUMOBJECTINFO];
public:
static void Initialise(const char *filename);
static void SetObjectData(int32 modelId, CObject &object);
};

View File

@ -3,7 +3,7 @@
#include "FileMgr.h"
#include "PedStats.h"
CPedStat *(&CPedStats::ms_apPedStats)[NUM_PEDSTATS] = *(CPedStat *(*)[NUM_PEDSTATS]) *(uintptr*)0x9404D4;
CPedStats *(&CPedStats::ms_apPedStats)[NUM_PEDSTATS] = *(CPedStats *(*)[NUM_PEDSTATS]) *(uintptr*)0x9404D4;
void
CPedStats::Initialise(void)
@ -12,7 +12,7 @@ CPedStats::Initialise(void)
debug("Initialising CPedStats...\n");
for(i = 0; i < NUM_PEDSTATS; i++){
ms_apPedStats[i] = new CPedStat;
ms_apPedStats[i] = new CPedStats;
ms_apPedStats[i]->m_type = PEDSTAT_PLAYER;
ms_apPedStats[i]->m_name[8] = 'R'; // WHAT?
ms_apPedStats[i]->m_fleeDistance = 20.0f;

View File

@ -54,8 +54,11 @@ enum
STAT_GUN_PANIC = 0x80
};
struct CPedStat
class CPedStats
{
static CPedStats *(&ms_apPedStats)[NUM_PEDSTATS];
public:
ePedStats m_type;
char m_name[24];
float m_fleeDistance;
@ -67,16 +70,10 @@ struct CPedStat
float m_attackStrength;
float m_defendWeakness;
int16 m_flags;
};
static_assert(sizeof(CPedStat) == 0x34, "CPedStat: error");
class CPedStats
{
static CPedStat *(&ms_apPedStats)[NUM_PEDSTATS];
public:
static void Initialise(void);
static void Shutdown(void);
static void LoadPedStats(void);
static int32 GetPedStatType(char *name);
};
static_assert(sizeof(CPedStats) == 0x34, "CPedStats: error");

View File

@ -16,8 +16,8 @@ CObject::CObject(void)
m_type = ENTITY_TYPE_OBJECT;
m_fUprootLimit = 0.0f;
m_nCollisionDamageEffect = 0;
m_bSpecialCollisionResponseCases = 0;
m_bCameraToAvoidThisObject = 0;
m_nSpecialCollisionResponseCases = COLLRESPONSE_NONE;
m_bCameraToAvoidThisObject = false;
ObjectCreatedBy = 0;
m_nEndOfLifeTime = 0;
// m_nRefModelIndex = -1; // duplicate

View File

@ -9,6 +9,21 @@ enum {
CUTSCENE_OBJECT = 4,
};
enum {
COLLRESPONSE_NONE,
COLLRESPONSE_CHANGE_MODEL,
COLLRESPONSE_SPLIT_MODEL,
COLLRESPONSE_SMASH_COMPLETELY,
COLLRESPONSE_CHANGE_THEN_SMASH,
COLLRESPONSE_UNKNOWN5,
COLLRESPONSE_SMASH_CARDBOARD_COMPLETELY = 50,
COLLRESPONSE_SMASH_WOODENBOX_COMPLETELY = 60,
COLLRESPONSE_SMASH_TRAFFICCONE_COMPLETELY = 70,
COLLRESPONSE_SMASH_BARPOST_COMPLETELY = 80,
};
class CVehicle;
class CObject : public CPhysical
@ -28,9 +43,9 @@ public:
int8 field_172;
int8 field_173;
float m_fCollisionDamageMultiplier;
int8 m_nCollisionDamageEffect;
int8 m_bSpecialCollisionResponseCases;
int8 m_bCameraToAvoidThisObject;
uint8 m_nCollisionDamageEffect;
uint8 m_nSpecialCollisionResponseCases;
bool m_bCameraToAvoidThisObject;
int8 field_17B;
int8 field_17C;
int8 field_17D;

View File

@ -211,7 +211,7 @@ public:
bool bInVehicle;
uint8 stuff4[23];
int32 m_nPedType;
CPedStat *m_pedStats;
CPedStats *m_pedStats;
uint8 stuff5[24];
CEntity *m_pCollidingEntity;
uint8 stuff6[12];

View File

@ -1801,8 +1801,8 @@ CPhysical::ProcessCollision(void)
n = distSq > 0.32f ? NUMSTEPS(0.3f) : NUMSTEPS(0.4f);
step = savedTimeStep / n;
}else if(IsObject()){
int responsecase = ((CObject*)this)->m_bSpecialCollisionResponseCases;
if(responsecase == 1){
int responsecase = ((CObject*)this)->m_nSpecialCollisionResponseCases;
if(responsecase == COLLRESPONSE_CHANGE_MODEL){
CVector speedUp = { 0.0f, 0.0f, 0.0f };
CVector speedDown = { 0.0f, 0.0f, 0.0f };
speedUp.z = GetBoundRadius();
@ -1816,12 +1816,12 @@ CPhysical::ProcessCollision(void)
n = NUMSTEPS(0.3f);
step = savedTimeStep / n;
}
}else if(responsecase == 5){
}else if(responsecase == COLLRESPONSE_UNKNOWN5){
if(distSq >= 0.009f){
n = NUMSTEPS(0.09f);
step = savedTimeStep / n;
}
}else if(responsecase == 2 || responsecase == 4){
}else if(responsecase == COLLRESPONSE_SPLIT_MODEL || responsecase == COLLRESPONSE_CHANGE_THEN_SMASH){
if(distSq >= sq(0.15f)){
n = NUMSTEPS(0.15f);
step = savedTimeStep / n;

View File

@ -30,7 +30,7 @@ public:
float fForceMultiplier;
float m_fAirResistance;
float m_fElasticity;
float fPercentSubmerged;
float m_fBuoyancy;
CVector m_vecCentreOfMass;
CEntryInfoList m_entryInfoList;
CPtrNode *m_movingListNode;

View File

@ -52,7 +52,7 @@ public:
void DeleteCollisionModel(void);
void ClearTexDictionary(void) { m_txdSlot = -1; }
short GetObjectID(void) { return m_objectId; }
void SetObjectID(short id) { m_objectId = id; }
void SetObjectID(int16 id) { m_objectId = id; }
short GetTxdSlot(void) { return m_txdSlot; }
void AddRef(void);
void RemoveRef(void);