summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-06-13 12:25:55 +0200
committeraap <aap@papnet.eu>2019-06-13 12:25:55 +0200
commitf407c9829fb5eac2c00867d2b31b2766dfe70540 (patch)
tree49afbef27c493ac1406c0b621a29ed5df78e9a86
parentimplemented GTA stream read functions (diff)
downloadre3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.gz
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.bz2
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.lz
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.xz
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.zst
re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.zip
Diffstat (limited to '')
-rw-r--r--src/CullZones.cpp23
-rw-r--r--src/CullZones.h1
-rw-r--r--src/RwHelper.h3
-rw-r--r--src/TxdStore.cpp51
-rw-r--r--src/TxdStore.h4
-rw-r--r--src/render/VisibilityPlugins.cpp8
-rw-r--r--src/render/VisibilityPlugins.h1
7 files changed, 85 insertions, 6 deletions
diff --git a/src/CullZones.cpp b/src/CullZones.cpp
index dc30790b..76052351 100644
--- a/src/CullZones.cpp
+++ b/src/CullZones.cpp
@@ -6,6 +6,7 @@
#include "Timer.h"
#include "Camera.h"
#include "World.h"
+#include "FileMgr.h"
#include "CullZones.h"
int32 &CCullZones::NumCullZones = *(int*)0x8F2564;
@@ -46,6 +47,27 @@ CCullZones::Init(void)
}
void
+CCullZones::ResolveVisibilities(void)
+{
+ int fd;
+
+ CFileMgr::SetDir("");
+ fd = CFileMgr::OpenFile("DATA\\cullzone.dat", "rb");
+ if(fd > 0){
+ CFileMgr::Read(fd, (char*)&NumCullZones, 4);
+ CFileMgr::Read(fd, (char*)aZones, NUMCULLZONES*sizeof(CCullZone));
+ CFileMgr::Read(fd, (char*)&NumAttributeZones, 4);
+ CFileMgr::Read(fd, (char*)aAttributeZones, NUMATTRIBZONES*sizeof(CAttributeZone));
+ CFileMgr::Read(fd, (char*)aIndices, NUMZONEINDICES*2);
+ CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForBuildings, NUMBUILDINGS*2);
+ CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForTreadables, NUMTREADABLES*2);
+ CFileMgr::CloseFile(fd);
+ }else{
+ // TODO: implement code from mobile to generate data here
+ }
+}
+
+void
CCullZones::Update(void)
{
bool invisible;
@@ -311,6 +333,7 @@ CCullZone::DoStuffEnteringZone_OneTreadable(uint16 i)
STARTPATCHES
InjectHook(0x524BC0, &CCullZones::Init, PATCH_JUMP);
+ InjectHook(0x524EC0, &CCullZones::ResolveVisibilities, PATCH_JUMP);
InjectHook(0x524F80, &CCullZones::Update, PATCH_JUMP);
InjectHook(0x525370, &CCullZones::AddCullZone, PATCH_JUMP);
InjectHook(0x5250D0, &CCullZones::ForceCullZoneCoors, PATCH_JUMP);
diff --git a/src/CullZones.h b/src/CullZones.h
index 4641f6ad..5b04b4f9 100644
--- a/src/CullZones.h
+++ b/src/CullZones.h
@@ -71,6 +71,7 @@ public:
static bool &bCullZonesDisabled;
static void Init(void);
+ static void ResolveVisibilities(void);
static void Update(void);
static void ForceCullZoneCoors(CVector coors);
static int32 FindCullZoneForCoors(CVector coors);
diff --git a/src/RwHelper.h b/src/RwHelper.h
index b65a53ad..2dbfd3ce 100644
--- a/src/RwHelper.h
+++ b/src/RwHelper.h
@@ -6,6 +6,9 @@ RwObject *GetFirstObject(RwFrame *frame);
RpAtomic *GetFirstAtomic(RpClump *clump);
RwTexDictionary *RwTexDictionaryGtaStreamRead(RwStream *stream);
+RwTexDictionary *RwTexDictionaryGtaStreamRead1(RwStream *stream);
+RwTexDictionary *RwTexDictionaryGtaStreamRead2(RwStream *stream, RwTexDictionary *texDict);
+
bool RpClumpGtaStreamRead1(RwStream *stream);
RpClump *RpClumpGtaStreamRead2(RwStream *stream);
void RpClumpGtaCancelStream(void);
diff --git a/src/TxdStore.cpp b/src/TxdStore.cpp
index 10d6e1f5..291feb2f 100644
--- a/src/TxdStore.cpp
+++ b/src/TxdStore.cpp
@@ -22,6 +22,18 @@ CTxdStore::Shutdown(void)
delete ms_pTxdPool;
}
+void
+CTxdStore::GameShutdown(void)
+{
+ int i;
+
+ for(i = 0; i < TXDSTORESIZE; i++){
+ TxdDef *def = GetSlot(i);
+ if(def && GetNumRefs(i))
+ RemoveTxdSlot(i);
+ }
+}
+
int
CTxdStore::AddTxdSlot(const char *name)
{
@@ -89,6 +101,12 @@ CTxdStore::Create(int slot)
GetSlot(slot)->texDict = RwTexDictionaryCreate();
}
+int
+CTxdStore::GetNumRefs(int slot)
+{
+ return GetSlot(slot)->refCount;
+}
+
void
CTxdStore::AddRef(int slot)
{
@@ -137,6 +155,27 @@ CTxdStore::LoadTxd(int slot, const char *filename)
return ret;
}
+bool
+CTxdStore::StartLoadTxd(int slot, RwStream *stream)
+{
+ TxdDef *def = GetSlot(slot);
+ if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){
+ def->texDict = RwTexDictionaryGtaStreamRead1(stream);
+ return def->texDict != nil;
+ }else{
+ printf("Failed to load TXD\n");
+ return nil;
+ }
+}
+
+bool
+CTxdStore::FinishLoadTxd(int slot, RwStream *stream)
+{
+ TxdDef *def = GetSlot(slot);
+ def->texDict = RwTexDictionaryGtaStreamRead2(stream, def->texDict);
+ return def->texDict != nil;
+}
+
void
CTxdStore::RemoveTxd(int slot)
{
@@ -146,15 +185,10 @@ CTxdStore::RemoveTxd(int slot)
def->texDict = nil;
}
-//bool
-//CTxdStore::isTxdLoaded(int slot)
-//{
-// return GetSlot(slot)->texDict != nil;
-//}
-
STARTPATCHES
InjectHook(0x527440, CTxdStore::Initialize, PATCH_JUMP);
InjectHook(0x527470, CTxdStore::Shutdown, PATCH_JUMP);
+ InjectHook(0x527490, CTxdStore::GameShutdown, PATCH_JUMP);
InjectHook(0x5274E0, CTxdStore::AddTxdSlot, PATCH_JUMP);
InjectHook(0x5275D0, CTxdStore::FindTxdSlot, PATCH_JUMP);
InjectHook(0x527590, CTxdStore::GetTxdName, PATCH_JUMP);
@@ -162,8 +196,13 @@ STARTPATCHES
InjectHook(0x527910, CTxdStore::PopCurrentTxd, PATCH_JUMP);
InjectHook(0x5278C0, CTxdStore::SetCurrentTxd, PATCH_JUMP);
InjectHook(0x527830, CTxdStore::Create, PATCH_JUMP);
+ InjectHook(0x527A00, CTxdStore::GetNumRefs, PATCH_JUMP);
InjectHook(0x527930, CTxdStore::AddRef, PATCH_JUMP);
InjectHook(0x527970, CTxdStore::RemoveRef, PATCH_JUMP);
InjectHook(0x5279C0, CTxdStore::RemoveRefWithoutDelete, PATCH_JUMP);
+ InjectHook(0x527700, (bool (*)(int, RwStream*))CTxdStore::LoadTxd, PATCH_JUMP);
+ InjectHook(0x5276B0, (bool (*)(int, const char*))CTxdStore::LoadTxd, PATCH_JUMP);
+ InjectHook(0x527770, CTxdStore::StartLoadTxd, PATCH_JUMP);
+ InjectHook(0x5277E0, CTxdStore::FinishLoadTxd, PATCH_JUMP);
InjectHook(0x527870, CTxdStore::RemoveTxd, PATCH_JUMP);
ENDPATCHES
diff --git a/src/TxdStore.h b/src/TxdStore.h
index a9526cf2..50a94a75 100644
--- a/src/TxdStore.h
+++ b/src/TxdStore.h
@@ -15,6 +15,7 @@ class CTxdStore
public:
static void Initialize(void);
static void Shutdown(void);
+ static void GameShutdown(void);
static int AddTxdSlot(const char *name);
static void RemoveTxdSlot(int slot);
static int FindTxdSlot(const char *name);
@@ -23,11 +24,14 @@ public:
static void PopCurrentTxd(void);
static void SetCurrentTxd(int slot);
static void Create(int slot);
+ static int GetNumRefs(int slot);
static void AddRef(int slot);
static void RemoveRef(int slot);
static void RemoveRefWithoutDelete(int slot);
static bool LoadTxd(int slot, RwStream *stream);
static bool LoadTxd(int slot, const char *filename);
+ static bool StartLoadTxd(int slot, RwStream *stream);
+ static bool FinishLoadTxd(int slot, RwStream *stream);
static void RemoveTxd(int slot);
static TxdDef *GetSlot(int slot) { return ms_pTxdPool->GetSlot(slot); }
diff --git a/src/render/VisibilityPlugins.cpp b/src/render/VisibilityPlugins.cpp
index 5608c933..316a397c 100644
--- a/src/render/VisibilityPlugins.cpp
+++ b/src/render/VisibilityPlugins.cpp
@@ -49,6 +49,13 @@ CVisibilityPlugins::Initialise(void)
}
void
+CVisibilityPlugins::Shutdown(void)
+{
+ m_alphaList.Shutdown();
+ m_alphaEntityList.Shutdown();
+}
+
+void
CVisibilityPlugins::InitAlphaEntityList(void)
{
m_alphaEntityList.Clear();
@@ -822,6 +829,7 @@ CVisibilityPlugins::GetClumpAlpha(RpClump *clump)
STARTPATCHES
InjectHook(0x527E50, CVisibilityPlugins::Initialise, PATCH_JUMP);
+ InjectHook(0x527EA0, CVisibilityPlugins::Shutdown, PATCH_JUMP);
InjectHook(0x528F90, CVisibilityPlugins::InitAlphaEntityList, PATCH_JUMP);
InjectHook(0x528FF0, CVisibilityPlugins::InsertEntityIntoSortedList, PATCH_JUMP);
InjectHook(0x528F80, CVisibilityPlugins::InitAlphaAtomicList, PATCH_JUMP);
diff --git a/src/render/VisibilityPlugins.h b/src/render/VisibilityPlugins.h
index 89222dce..65d2675a 100644
--- a/src/render/VisibilityPlugins.h
+++ b/src/render/VisibilityPlugins.h
@@ -35,6 +35,7 @@ public:
static float &ms_pedFadeDist;
static void Initialise(void);
+ static void Shutdown(void);
static void InitAlphaEntityList(void);
static bool InsertEntityIntoSortedList(CEntity *e, float dist);
static void InitAlphaAtomicList(void);