librw/tools/rsltest/rsltest.cpp

131 lines
2.9 KiB
C++
Raw Normal View History

2015-12-21 19:11:55 +00:00
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <new>
#include <rw.h>
#include <src/gtaplg.h>
using namespace std;
using namespace rw;
#include "rsl.h"
void
RslStream::relocate(void)
{
uint32 off = (uint32)this->data;
off -= 0x20;
*(uint32*)&this->reloc += off;
*(uint32*)&this->hashTab += off;
uint8 **rel = (uint8**)this->reloc;
for(uint32 i = 0; i < this->relocSize; i++){
rel[i] += off;
*this->reloc[i] += off;
}
}
2015-12-22 11:11:10 +00:00
RslFrame*
2015-12-21 20:56:47 +00:00
RslFrameForAllChildren(RslFrame *frame, RslFrameCallBack callBack, void *data)
{
for(RslFrame *child = frame->child;
child;
child = child->next)
if(callBack(child, data) == NULL)
break;
return frame;
}
2015-12-22 11:11:10 +00:00
RslClump*
2015-12-21 19:11:55 +00:00
RslClumpForAllAtomics(RslClump *clump, RslAtomicCallBack callback, void *pData)
{
RslAtomic *a;
RslLLLink *link;
for(link = rslLLLinkGetNext(&clump->atomicList.link);
link != &clump->atomicList.link;
link = link->next){
a = rslLLLinkGetData(link, RslAtomic, inClumpLink);
if(callback(a, pData) == NULL)
break;
}
return clump;
}
2015-12-22 11:11:10 +00:00
RslGeometry*
2015-12-21 19:11:55 +00:00
RslGeometryForAllMaterials(RslGeometry *geometry, RslMaterialCallBack fpCallBack, void *pData)
{
for(int32 i = 0; i < geometry->matList.numMaterials; i++)
if(fpCallBack(geometry->matList.materials[i], pData) == NULL)
break;
return geometry;
}
2015-12-21 20:56:47 +00:00
RslFrame *dumpFrameCB(RslFrame *frame, void *data)
{
2015-12-22 11:11:10 +00:00
printf(" frm: %x %s %x\n", frame->nodeId, frame->name, frame->hierId);
2015-12-21 20:56:47 +00:00
RslFrameForAllChildren(frame, dumpFrameCB, data);
return frame;
}
2015-12-21 19:11:55 +00:00
RslMaterial *dumpMaterialCB(RslMaterial *material, void*)
{
2015-12-22 11:11:10 +00:00
printf(" mat: %s %x\n", material->texname, material->refCount);
2015-12-21 19:11:55 +00:00
if(material->matfx){
RslMatFX *fx = material->matfx;
printf(" matfx: ", fx->effectType);
if(fx->effectType == 2)
printf("env[%s %f] ", fx->env.texname, fx->env.intensity);
printf("\n");
}
return material;
}
RslAtomic *dumpAtomicCB(RslAtomic *atomic, void*)
{
printf(" atm: %x %x %x %p\n", atomic->unk1, atomic->unk2, atomic->unk3, atomic->hier);
RslGeometry *g = atomic->geometry;
RslGeometryForAllMaterials(g, dumpMaterialCB, NULL);
return atomic;
}
int
main(int argc, char *argv[])
{
gta::attachPlugins();
rw::version = 0;
assert(sizeof(void*) == 4);
if(argc < 2){
printf("usage: %s [-u] in.dff\n", argv[0]);
return 0;
}
StreamFile stream;
assert(stream.open(argv[1], "rb"));
RslStream *rslstr = new RslStream;
stream.read(rslstr, 0x20);
rslstr->data = new uint8[rslstr->fileSize-0x20];
stream.read(rslstr->data, rslstr->fileSize-0x20);
stream.close();
rslstr->relocate();
RslClump *clump;
if(rslstr->numAtomics){
uint8 *p = *rslstr->hashTab;
p -= 0x24;
RslAtomic *a = (RslAtomic*)p;
clump = a->clump;
if(clump)
2015-12-21 20:56:47 +00:00
//RslClumpForAllAtomics(clump, dumpAtomicCB, NULL);
RslFrameForAllChildren(RslClumpGetFrame(clump), dumpFrameCB, NULL);
2015-12-21 19:11:55 +00:00
else
2015-12-21 20:56:47 +00:00
//dumpAtomicCB(a, NULL);
RslFrameForAllChildren(RslAtomicGetFrame(a), dumpFrameCB, NULL);
2015-12-21 19:11:55 +00:00
}
return 0;
}