mirror of
https://github.com/zeldaret/ss
synced 2026-06-09 12:36:09 -04:00
d_rawarchive followups (#42)
* d_rawarchive followups * symbols hygiene * Add Egg function
This commit is contained in:
+14
-25
@@ -1,18 +1,8 @@
|
||||
#include <d/d_rawarchive.h>
|
||||
#include <rvl/VI.h>
|
||||
|
||||
class UnkManager {
|
||||
public:
|
||||
/* vtable at 8050df50 */
|
||||
/** 800651c0 */
|
||||
virtual void CreateArc(void *data, const char *path);
|
||||
/** 800653d0 */
|
||||
virtual void DestroyArc(const char *path);
|
||||
|
||||
u32 stage;
|
||||
};
|
||||
|
||||
extern "C" int fn_80061B10(void *d, u32 len) {
|
||||
int computeChecksumInner(void *d, u32 len) {
|
||||
u32 *data = (u32 *)d;
|
||||
u32 result = 0;
|
||||
// Compiler will unroll this loop
|
||||
@@ -22,16 +12,15 @@ extern "C" int fn_80061B10(void *d, u32 len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" int fn_80061BA0(void *data, u32 len) {
|
||||
int result = fn_80061B10(data, len);
|
||||
int computeChecksum(void *data, u32 len) {
|
||||
int result = computeChecksumInner(data, len);
|
||||
return result != 0 ? result : -1;
|
||||
}
|
||||
|
||||
extern "C" void fn_80061BE0(UnkManager *mgr, const char *name, size_t len) {
|
||||
// Sets stage to all spaces
|
||||
mgr->stage = 0x20202020;
|
||||
// copies the stage name?
|
||||
memcpy((char *)&mgr->stage, name, len);
|
||||
void setPrefix(ArcCallbackHandler *mgr, const char *name, size_t len) {
|
||||
mgr->mPrefix = ' ';
|
||||
// Copy the actual name
|
||||
memcpy(&mgr->mPrefix, name, len);
|
||||
}
|
||||
|
||||
dRawArcEntry_c::dRawArcEntry_c() {
|
||||
@@ -55,18 +44,18 @@ dRawArcEntry_c::~dRawArcEntry_c() {
|
||||
}
|
||||
|
||||
void dRawArcEntry_c::searchCallback(void *arg, void *data, const ARCDirEntry *entry, const char *path, bool ctrl) {
|
||||
UnkManager *mgr = (UnkManager *)arg;
|
||||
ArcCallbackHandler *mgr = (ArcCallbackHandler *)arg;
|
||||
if (entry->isDir) {
|
||||
int len = strlen(entry->name);
|
||||
fn_80061BE0(mgr, entry->name, len <= 4 ? len : 4);
|
||||
setPrefix(mgr, entry->name, len <= 4 ? len : 4);
|
||||
} else {
|
||||
// dolphin: arg vtable at 8050df50
|
||||
// any others?
|
||||
if (ctrl) {
|
||||
mgr->CreateArc(data, path);
|
||||
mgr->CreateArcEntry(data, path);
|
||||
// branch to 800651c0, sets up room
|
||||
} else {
|
||||
mgr->DestroyArc(path);
|
||||
mgr->DestroyArcEntry(path);
|
||||
// branch to 800653d0, destroys room
|
||||
}
|
||||
}
|
||||
@@ -153,7 +142,7 @@ BOOL dRawArcEntry_c::checkArcExistsOnDiskInner(SizedString<128> &path, const cha
|
||||
return true;
|
||||
}
|
||||
|
||||
int dRawArcEntry_c::mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap) {
|
||||
int dRawArcEntry_c::mount(const char *name, void *data, ArcCallbackHandler *callbackArg, u8 mountDirection, EGG::Heap *heap) {
|
||||
mArcName = name;
|
||||
mpArc = EGG::Archive::mount(data, heap, (mountDirection == 0 || mountDirection == 1) ? 4 : -4);
|
||||
if (mpArc == nullptr) {
|
||||
@@ -201,7 +190,7 @@ int dRawArcEntry_c::ensureLoadedMaybe(void *callbackArg) {
|
||||
int result = onMount(callbackArg);
|
||||
mHeap::restoreCurrentHeap();
|
||||
mHeap::adjustFrmHeap(mpFrmHeap);
|
||||
mChecksum = fn_80061BA0(mpData, mAmountRead);
|
||||
mChecksum = computeChecksum(mpData, mAmountRead);
|
||||
if (result == -1) {
|
||||
return result;
|
||||
}
|
||||
@@ -233,7 +222,7 @@ dRawArcTable_c::~dRawArcTable_c() {
|
||||
}
|
||||
}
|
||||
|
||||
bool dRawArcTable_c::init(u16 count, void *callbackArg, EGG::Heap *heap) {
|
||||
bool dRawArcTable_c::init(u16 count, ArcCallbackHandler *callbackArg, EGG::Heap *heap) {
|
||||
mpEntries = new (heap, 0x04) dRawArcEntry_c[count]();
|
||||
if (mpEntries == nullptr) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <d/d_rawarchive.h>
|
||||
#include <egg/gfx/eggLight.h>
|
||||
#include <m/m3d/m3d.h>
|
||||
#include <toBeSorted/arc_managers/oarc_manager.h>
|
||||
#include <toBeSorted/arc_managers/current_stage_arc_manager.h>
|
||||
#include <nw4r/g3d/g3d_resfile.h>
|
||||
#include <nw4r/g3d/g3d_resmdl.h>
|
||||
#include <nw4r/g3d/g3d_resmat.h>
|
||||
|
||||
ArcCallbackHandler ArcCallbackHandler::sInstance;
|
||||
|
||||
#define NAME_DZB 'dzb '
|
||||
#define NAME_G3D 'g3d '
|
||||
#define NAME_KCL 'kcl '
|
||||
#define NAME_OARC 'oarc'
|
||||
#define NAME_RARC 'rarc'
|
||||
|
||||
extern "C" void FUN_804a7260(nw4r::g3d::ResMdl, const char *prefix);
|
||||
|
||||
|
||||
void BindSystemModelsAndLighting(nw4r::g3d::ResFile file) {
|
||||
nw4r::g3d::ResFile sysFile = OarcManager::sInstance->getMdlFromArc2("System");
|
||||
if (sysFile.mFile.IsValid()) {
|
||||
file.Bind(sysFile);
|
||||
}
|
||||
|
||||
EGG::LightManager *mgr = m3d::getLightMgr(0);
|
||||
if (mgr != nullptr && mgr->GetTextureMgr() != nullptr) {
|
||||
EGG::LightTextureManager *lightTexMgr = mgr->GetTextureMgr();
|
||||
for (int i = 0; i < file.GetResMdlNumEntries(); i++) {
|
||||
nw4r::g3d::ResMdl mdl = file.GetResMdl(i);
|
||||
lightTexMgr->replaceModelTextures(mdl);
|
||||
FUN_804a7260(mdl, "Lm");
|
||||
for (int j = 0; j < mdl.GetResMatNumEntries(); j++) {
|
||||
nw4r::g3d::ResMat mat = mdl.GetResMat(j);
|
||||
if (mat.IsOpaque()) {
|
||||
nw4r::g3d::ResMatPix pix = mat.GetResMatPix();
|
||||
u8 bAlpha;
|
||||
u8 uAlpha;
|
||||
pix.GXGetDstAlpha(&bAlpha, &uAlpha);
|
||||
if (!bAlpha) {
|
||||
pix.GXSetDstAlpha(1, 0x80);
|
||||
pix.DCStore(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void fn_8033A140(void *data);
|
||||
extern "C" void dBgWKCol__initKCollision(void *dat);
|
||||
|
||||
void ArcCallbackHandlerBase::CreateArcEntry(void *data, const char *path) {
|
||||
if (mPrefix == NAME_G3D) {
|
||||
nw4r::g3d::ResFile file = data;
|
||||
file.Init();
|
||||
file.Bind();
|
||||
BindSystemModelsAndLighting(file);
|
||||
} else if (mPrefix == NAME_KCL) {
|
||||
dBgWKCol__initKCollision(data);
|
||||
} else if (mPrefix == NAME_DZB) {
|
||||
fn_8033A140(data);
|
||||
} else if (mPrefix == NAME_OARC) {
|
||||
SizedString<64> oarcPath = path;
|
||||
char buf[64];
|
||||
sscanf(&oarcPath, "/oarc/%31[^.]arc", buf);
|
||||
u32 oldPrefix = mPrefix;
|
||||
OarcManager::sInstance->addEntryFromSuperArc(buf, data, nullptr);
|
||||
mPrefix = oldPrefix;
|
||||
} else if (mPrefix == NAME_RARC) {
|
||||
SizedString<64> oarcPath = path;
|
||||
char buf[64];
|
||||
sscanf(&oarcPath, "/rarc/%31[^.]arc", buf);
|
||||
u32 oldPrefix = mPrefix;
|
||||
CurrentStageArcManager::sInstance->addEntryFromSuperArc(buf, data);
|
||||
mPrefix = oldPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
void ArcCallbackHandlerBase::DestroyArcEntry(const char *path) {
|
||||
if (mPrefix == NAME_OARC) {
|
||||
SizedString<64> oarcPath = path;
|
||||
char buf[64];
|
||||
sscanf(&oarcPath, "/oarc/%31[^.]arc", buf);
|
||||
u32 oldPrefix = mPrefix;
|
||||
OarcManager::sInstance->decrement(buf);
|
||||
mPrefix = oldPrefix;
|
||||
} else if (mPrefix == NAME_RARC) {
|
||||
SizedString<64> oarcPath = path;
|
||||
char buf[64];
|
||||
sscanf(&oarcPath, "/rarc/%31[^.]arc", buf);
|
||||
u32 oldPrefix = mPrefix;
|
||||
CurrentStageArcManager::sInstance->decrement(buf);
|
||||
mPrefix = oldPrefix;
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,8 @@ CurrentStageArcManager::~CurrentStageArcManager() {
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
||||
extern char lbl_80575250;
|
||||
|
||||
void CurrentStageArcManager::init(EGG::Heap *heap) {
|
||||
mArcTable.init(18, &lbl_80575250, heap);
|
||||
mArcTable.init(18, &ArcCallbackHandler::sInstance, heap);
|
||||
}
|
||||
|
||||
bool CurrentStageArcManager::setStage(const char *newStage) {
|
||||
|
||||
@@ -11,10 +11,8 @@ LayoutArcManager::~LayoutArcManager() {
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
||||
extern char lbl_80575250;
|
||||
|
||||
void LayoutArcManager::init(EGG::Heap *heap) {
|
||||
mArcTable.init(16, &lbl_80575250, heap);
|
||||
mArcTable.init(16, &ArcCallbackHandler::sInstance, heap);
|
||||
}
|
||||
|
||||
bool LayoutArcManager::loadLayoutArcFromDisk(const char *object, EGG::Heap *heap) {
|
||||
|
||||
@@ -11,10 +11,8 @@ OarcManager::~OarcManager() {
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
||||
extern char lbl_80575250;
|
||||
|
||||
void OarcManager::init(EGG::Heap *heap) {
|
||||
mArcTable.init(200, &lbl_80575250, heap);
|
||||
mArcTable.init(200, &ArcCallbackHandler::sInstance, heap);
|
||||
}
|
||||
|
||||
bool OarcManager::checkIfObjectArcExistsOnDisk(const char *object) {
|
||||
|
||||
Reference in New Issue
Block a user