summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-03-13 23:35:44 +0100
committerTreeki <treeki@gmail.com>2011-03-13 23:35:44 +0100
commit793fc74bd957eea3930e30aae704e47adee5e015 (patch)
tree577e0579ef3de4e0a1063a94a7f3a4b144abcc33
parent485c95c4fc071f954c7f808b0a89eb37d147c57b (diff)
downloadkamek-793fc74bd957eea3930e30aae704e47adee5e015.tar.gz
kamek-793fc74bd957eea3930e30aae704e47adee5e015.zip
made LevelInfo into an OO class and added a header file for dWMResourceMng_c
-rw-r--r--include/g3dhax.h5
-rw-r--r--src/g3dwrap.cpp90
-rw-r--r--src/levelinfo.cpp35
-rw-r--r--src/levelinfo.h94
-rw-r--r--src/levelnames.cpp33
-rw-r--r--src/wmresourcemng.cpp4
-rw-r--r--src/wmresourcemng.h57
-rw-r--r--src/worldmap.cpp10
-rw-r--r--src/worldmap.h65
9 files changed, 162 insertions, 231 deletions
diff --git a/include/g3dhax.h b/include/g3dhax.h
index c3aeaef..703b6d6 100644
--- a/include/g3dhax.h
+++ b/include/g3dhax.h
@@ -1,3 +1,6 @@
+#ifndef __KAMEK_G3DHAX_H
+#define __KAMEK_G3DHAX_H
+
// nw4r::g3d wrapper
namespace nw4r {
@@ -166,3 +169,5 @@ void SetupTextures_Enemy(m3d::mdl_c *model, int sceneID); // 800B4170
void SetupTextures_MapObj(m3d::mdl_c *model, int sceneID); // 800B42B0
void SetupTextures_Item(m3d::mdl_c *model, int sceneID); // 800B43D0
+#endif
+
diff --git a/src/g3dwrap.cpp b/src/g3dwrap.cpp
deleted file mode 100644
index 644c5e8..0000000
--- a/src/g3dwrap.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-// nw4r::g3d wrapper
-
-namespace nw4r {
-namespace g3d {
-
-class ResFile {
- void * /*ResFileData*/ data;
-
- ResFile(void *p = NULL);
-
- void Init();
- bool CheckRevision() const;
-
- void * /*ResMdl*/ GetResMdl(const char *str) const;
- void * /*ResPltt*/ GetResPltt(const ResName n) const;
- void * /*ResTex*/ GetResTex(const char *str) const;
- void * /*ResTex*/ GetResTex(const ResName n) const;
- void * /*ResTex*/ GetResTex(u32 idx) const;
- void * /*ResAnmChr*/ GetResAnmChr(const char *str) const;
- void * /*ResAnmVis*/ GetResAnmVis(const char *str) const;
- void * /*ResAnmClr*/ GetResAnmClr(const char *str) const;
- void * /*ResAnmTexPat*/ GetResAnmTexPat(const char *str) const;
- void * /*ResAnmTexSrt*/ GetResAnmTexSrt(const char *str) const;
- void * /*ResAnmScn*/ GetResAnmScn(const char *str) const;
-
- bool Bind(ResFile rhs);
-};
-
-void *__ScnMdl__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResMdl*/ mdl,
- u32 bufferOption,
- int nView = 1);
-
-
-void *__AnmObjChrRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmChr*/ resAnm,
- void * /*ResMdl*/ resMdl,
- bool bHasCache);
-
-
-void *__AnmObjVisRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmVis*/ resAnm,
- void * /*ResMdl*/ resMdl);
-
-
-void *__AnmObjTexPatRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmTexPat*/ resAnm,
- void * /*ResMdl*/ resMdl,
- bool bHasCache);
-
-
-void *__AnmObjTexSrtRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmTexSrt*/ resAnm,
- void * /*ResMdl*/ resMdl,
- bool bHasCache);
-
-
-void *__AnmObjMatClrRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmMatClr*/ resAnm,
- void * /*ResMdl*/ resMdl,
- bool bHasCache);
-
-
-void *__AnmObjShpRes__Construct(
- void * /*MEMAllocator*/ pHeap,
- u32 *pSize,
- void * /*ResAnmShp*/ resAnm,
- void * /*ResMdl*/ resMdl,
- bool bHasCache);
-
-
-
-bool InsertIntoScene(void *scnObj); // 80164F90
-
-
-
-}
-} \ No newline at end of file
diff --git a/src/levelinfo.cpp b/src/levelinfo.cpp
index 9807fc4..c0130b0 100644
--- a/src/levelinfo.cpp
+++ b/src/levelinfo.cpp
@@ -1,19 +1,19 @@
#include "levelinfo.h"
-void LevelInfo_Prepare(FileHandle *fh) {
- void *file = fh->filePtr;
-
+void LevelInfo::load(void *buffer) {
+ data = (Header*)buffer;
+
// decrypt all the level names
- for (int sect = 0; sect < LevelInfo_GetSectionCount(file); sect++) {
+ for (int sect = 0; sect < sectionCount(); sect++) {
// parse this section
- LevelInfo_Section *thisSect = LevelInfo_GetSection(file, sect);
- LevelInfo_Entry *levels = LevelInfo_GetLevels(file, thisSect);
-
+ Section *thisSect = getSectionByIndex(sect);
+ Entry *levels = getLevelsForSection(thisSect);
+
for (int lev = 0; lev < thisSect->levelCount; lev++) {
- LevelInfo_Entry *level = &levels[lev];
-
- char *name = LevelInfo_GetName(file, level);
-
+ Entry *level = &levels[lev];
+
+ char *name = getNameForLevel(level);
+
for (int i = 0; i < level->nameLength+1; i++) {
name[i] -= 0xD0;
}
@@ -21,16 +21,17 @@ void LevelInfo_Prepare(FileHandle *fh) {
}
}
-LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level) {
- for (int i = 0; i < LevelInfo_GetSectionCount(file); i++) {
- LevelInfo_Section *sect = LevelInfo_GetSection(file, i);
-
+LevelInfo::Entry *LevelInfo::search(int world, int level) {
+ for (int i = 0; i < sectionCount(); i++) {
+ Section *sect = getSectionByIndex(i);
+
for (int j = 0; j < sect->levelCount; j++) {
- LevelInfo_Entry *entry = &LevelInfo_GetLevels(file, sect)[j];
+ Entry *entry = &getLevelsForSection(sect)[j];
if (entry->world == world && entry->level == level)
return entry;
}
}
-
+
return 0;
}
+
diff --git a/src/levelinfo.h b/src/levelinfo.h
index 1b75275..36db669 100644
--- a/src/levelinfo.h
+++ b/src/levelinfo.h
@@ -2,55 +2,55 @@
#define __NEWER_LEVELINFO_H
#include <common.h>
-#include "fileload.h"
-struct LevelInfo_Header {
- u32 magic;
- u32 sectionCount;
+class LevelInfo {
+public:
+ struct Header {
+ u32 magic;
+ u32 sectionCount;
+ u32 sectionOffsets[1];
+ };
+
+ struct Section {
+ u32 levelCount;
+ };
+
+ struct Entry {
+ u8 world;
+ u8 level;
+ u8 reserved1;
+ u8 reserved2;
+ u8 nameLength;
+ u8 reserved3;
+ u16 flags;
+ u32 nameOffset;
+ };
+
+private:
+ Header *data;
+
+public:
+ void load(void *buffer);
+
+ Entry *search(int world, int level);
+
+ u32 sectionCount() {
+ return data->sectionCount;
+ }
+
+ Section *getSectionByIndex(u32 index) {
+ return (Section*)(((char*)data) + data->sectionOffsets[index]);
+ }
+
+ Entry *getLevelsForSection(Section *section) {
+ return (Entry*)(section + 1);
+ }
+
+ char *getNameForLevel(Entry *entry) {
+ return (char*)data + entry->nameOffset;
+ }
};
-struct LevelInfo_Section {
- u32 levelCount;
-};
-
-struct LevelInfo_Entry {
- u8 world;
- u8 level;
- u8 reserved1;
- u8 reserved2;
- u8 nameLength;
- u8 reserved3;
- u16 flags;
- u32 nameOffset;
-};
-
-inline u32 LevelInfo_GetSectionCount(void *file) {
- return ((LevelInfo_Header*)file)->sectionCount;
-}
-
-inline u32 *LevelInfo_GetOffsets(void *file) {
- return (u32*)(((LevelInfo_Header*)file)+1);
-}
-
-inline LevelInfo_Section *LevelInfo_GetSection(void *file, int id) {
- u32 offs = LevelInfo_GetOffsets(file)[id];
- return (LevelInfo_Section*)(((char*)file)+offs);
-};
-
-inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, LevelInfo_Section *section) {
- return (LevelInfo_Entry*)(section+1);
-}
-
-inline LevelInfo_Entry *LevelInfo_GetLevels(void *file, int sectionID) {
- return (LevelInfo_Entry*)(LevelInfo_GetSection(file, sectionID)+1);
-}
-
-inline char *LevelInfo_GetName(void *file, LevelInfo_Entry *entry) {
- return ((char*)file)+entry->nameOffset;
-}
-
-void LevelInfo_Prepare(FileHandle *fh);
-LevelInfo_Entry *LevelInfo_Search(void *file, int world, int level);
-
#endif
+
diff --git a/src/levelnames.cpp b/src/levelnames.cpp
index b6f440e..a6f5c1b 100644
--- a/src/levelnames.cpp
+++ b/src/levelnames.cpp
@@ -19,7 +19,7 @@ int DoNames(int state) {
int wnum = (int)CurrentWorld;
int lnum = (int)CurrentLevel;
OSReport("Current Level: %d-%d\n", wnum+1, lnum+1);
-
+
// Skip the title screen
// and only process the code if the State is set to 1
// (the screen has been initialised)
@@ -28,51 +28,51 @@ int DoNames(int state) {
// grab the CRSIN object
Actor *ptr = FindActorByType(CRSIN, 0);
//OSReport("CRSIN actor found at : %08X\n", ptr);
-
+
// FIX !!!!!
-
+
if (ptr != 0) {
void *worldObj = EmbeddedLayout_FindTextBoxByName((Layout*)((u32)ptr+0xB0), "TXT_WorldName");
void *levelObj = EmbeddedLayout_FindTextBoxByName((Layout*)((u32)ptr+0xB0), "TXT_LevelName");
//OSReport("WorldObj TextBox : %08X; LevelObj TextBox : %08X\n", worldObj, levelObj);
if (worldObj == 0 || levelObj == 0) return state;
-
+
/*char *file = RetrieveFileFromArc(ARC_TABLE, "Mario", "newer/names.bin");
//OSReport("RetrieveFileFromArc returned : %08X\n", file);
char *worldname = file + (wnum * 0x40);
char *levelname = file + 0x280 + (wnum * 0xA80) + (lnum * 0x40);*/
OSReport("Loading file...\n");
- FileHandle fh;
- void *info = LoadFile(&fh, "/NewerRes/LevelInfo.bin");
-
- LevelInfo_Prepare(&fh);
- LevelInfo_Entry *entry = LevelInfo_Search(info, wnum, lnum);
- char *worldname = LevelInfo_GetName(info, entry);
+ File fh;
+ fh.open("/NewerRes/LevelInfo.bin");
+
+ LevelInfo info;
+ info.load(fh.ptr());
+ LevelInfo::Entry *entry = info.search(wnum, lnum);
+ char *worldname = info.getNameForLevel(entry);
char *levelname = "";
OSReport("Got name : %s\n", worldname);
-
+
void *vtable = *((void**)levelObj);
void *funcaddr = *((void**)((u32)vtable+0x7C));
int (*SetString)(void*, unsigned short*, unsigned short);
SetString = (int(*)(void*, unsigned short*, unsigned short))funcaddr;
-
+
unsigned short wbuffer[0x40], lbuffer[0x40];
for (int i = 0; i < 0x40; i++) {
wbuffer[i] = (unsigned short)worldname[i];
lbuffer[i] = (unsigned short)levelname[i];
}
-
+
SetString(worldObj, wbuffer, 0);
SetString(levelObj, lbuffer, 0);
-
+
OSReport("Freeing file\n");
- FreeFile(&fh);
OSReport("Inserted strings\n");
}
} else {
OSReport("Skipped\n");
}
-
+
OSReport("Reached the end of DoNames\n");
return state;
}
@@ -81,3 +81,4 @@ int DoNamesTest2(int state, u32 ptr) {
OSReport("TEST 1:%08X 2:%08X\n", state, ptr);
return DoNames(state);
}
+
diff --git a/src/wmresourcemng.cpp b/src/wmresourcemng.cpp
index ade1222..088cef4 100644
--- a/src/wmresourcemng.cpp
+++ b/src/wmresourcemng.cpp
@@ -12,7 +12,11 @@ dWMResourceMng_c::dWMResourceMng_c() {
}
dWMResourceMng_c::~dWMResourceMng_c() {
+ MapReport("dWMResourceMng_c destructed\n");
+
if (isSetLoaded) {
+ MapReport("Unloading %d resources\n", setData->count);
+
for (int i = 0; i < setData->count; i++) {
resLoaders[i].unload();
}
diff --git a/src/wmresourcemng.h b/src/wmresourcemng.h
new file mode 100644
index 0000000..910acf1
--- /dev/null
+++ b/src/wmresourcemng.h
@@ -0,0 +1,57 @@
+#ifndef __NEWER_WMRESOURCEMNG_H
+#define __NEWER_WMRESOURCEMNG_H
+
+struct WMResSetEntry {
+ u32 key;
+ u32 offset;
+};
+
+struct WMResSetHeader {
+ u32 magic;
+ u32 count;
+ WMResSetEntry entries[1]; // dynamic size
+
+ char *getName(int index) {
+ return (char*)((u32)this + entries[index].offset);
+ }
+};
+
+class dWMResourceMng_c {
+private:
+ bool hasSetPath;
+ bool isSetLoaded;
+ bool isLoadingComplete;
+
+ char setPath[0x40];
+ dDvdLoader_c setLoader;
+ dDvdLoader_c *resLoaders;
+
+ WMResSetHeader *setData;
+
+ void prepareResources();
+
+public:
+ dWMResourceMng_c();
+ ~dWMResourceMng_c();
+
+ bool loadSet(const char *setName);
+ void *operator[](u32 key);
+
+ bool isLoaded();
+
+
+ u32 resCount() {
+ return setData->count;
+ }
+
+ u32 keyForIndex(u32 index) {
+ return setData->entries[index].key;
+ }
+
+ void *dataForIndex(u32 index) {
+ return resLoaders[index].buffer;
+ }
+};
+
+#endif
+
diff --git a/src/worldmap.cpp b/src/worldmap.cpp
index 62f3de2..d24710c 100644
--- a/src/worldmap.cpp
+++ b/src/worldmap.cpp
@@ -103,7 +103,7 @@ dScNewerWorldMap_c *dScNewerWorldMap_c::build() {
#define STATE_SAVE_ERROR 27
-void dScNewerWorldMap_c::StartLevel(LevelInfo_Entry *entry) {
+void dScNewerWorldMap_c::StartLevel(LevelInfo::Entry *entry) {
for (int i = 0; i < 4; i++) {
bool isThere = QueryPlayerAvailability(i);
int id = Player_ID[i];
@@ -169,8 +169,8 @@ int dScNewerWorldMap_c::onCreate() {
*CurrentDrawFunc = NewerMapDrawFunc;
// level info
- this->levelInfo = LoadFile(&this->levelInfoFH, "/NewerRes/LevelInfo.bin");
- LevelInfo_Prepare(&this->levelInfoFH);
+ levelInfoFile.open("/NewerRes/LevelInfo.bin");
+ levelInfo.load(levelInfoFile.ptr());
// load the menu info
SaveBlock *save = GetSaveFile()->GetBlock(-1);
@@ -192,8 +192,6 @@ int dScNewerWorldMap_c::onCreate() {
}
int dScNewerWorldMap_c::onDelete() {
- FreeFile(&this->levelInfoFH);
-
FreeScene(0);
FreeScene(1);
@@ -923,7 +921,7 @@ void dScNewerWorldMap_c::ActivatePoint() {
if (this->currentPoint->type == WMPathPoint::LEVEL_TYPE) {
int w = this->currentPoint->params[0] - 1;
int l = this->currentPoint->params[1] - 1;
- LevelInfo_Entry *level = LevelInfo_Search(this->levelInfo, w, l);
+ LevelInfo::Entry *level = this->levelInfo.search(w, l);
StartLevel(level);
}
}
diff --git a/src/worldmap.h b/src/worldmap.h
index ea1cd93..8ea7e4c 100644
--- a/src/worldmap.h
+++ b/src/worldmap.h
@@ -8,15 +8,19 @@
// TODO: add Save Error state
+#ifndef __NEWER_WORLDMAP_H
+#define __NEWER_WORLDMAP_H
+
#define WM_DEBUGGING
#include <common.h>
#include <game.h>
+#include <g3dhax.h>
#include "fileload.h"
#include "levelinfo.h"
#include "worldmapdata.h"
-#include <g3dhax.h>
+#include "wmresourcemng.h"
enum WMDirection {
LEFT,
@@ -34,57 +38,6 @@ inline void MapReport(const char *str, ...) { }
void NewerMapDrawFunc();
-struct WMResSetEntry {
- u32 key;
- u32 offset;
-};
-
-struct WMResSetHeader {
- u32 magic;
- u32 count;
- WMResSetEntry entries[1]; // dynamic size
-
- char *getName(int index) {
- return (char*)((u32)this + entries[index].offset);
- }
-};
-
-class dWMResourceMng_c {
-private:
- bool hasSetPath;
- bool isSetLoaded;
- bool isLoadingComplete;
-
- char setPath[0x40];
- dDvdLoader_c setLoader;
- dDvdLoader_c *resLoaders;
-
- WMResSetHeader *setData;
-
- void prepareResources();
-
-public:
- dWMResourceMng_c();
- ~dWMResourceMng_c();
-
- bool loadSet(const char *setName);
- void *operator[](u32 key);
-
- bool isLoaded();
-
-
- u32 resCount() {
- return setData->count;
- }
-
- u32 keyForIndex(u32 index) {
- return setData->entries[index].key;
- }
-
- void *dataForIndex(u32 index) {
- return resLoaders[index].buffer;
- }
-};
class dWMMap_c : public dBase_c {
@@ -149,8 +102,8 @@ public:
void *stockItemShadow;
void *easyPairing;
- void *levelInfo;
- FileHandle levelInfoFH;
+ File levelInfoFile;
+ LevelInfo levelInfo;
dWMResourceMng_c resMng;
@@ -182,7 +135,7 @@ public:
void ActivatePoint();
- void StartLevel(LevelInfo_Entry *entry);
+ void StartLevel(LevelInfo::Entry *entry);
int onCreate();
int onDelete();
@@ -193,3 +146,5 @@ public:
static dScNewerWorldMap_c *instance;
};
+#endif
+