diff --git a/ps2.cpp b/ps2.cpp new file mode 100644 index 0000000..d2ffc6f --- /dev/null +++ b/ps2.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +#include +#include + +#include "rwbase.h" +#include "rwplugin.h" +#include "rw.h" +#include "rwps2.h" + +using namespace std; + +namespace Rw { + +void +ReadNativeDataPS2(istream &stream, int32 len, void *object, int32, int32) +{ + Geometry *geometry = (Geometry*)object; + assert(FindChunk(stream, ID_STRUCT, NULL, NULL)); + assert(readUInt32(stream) == 4); + PS2InstanceDataHeader *header = new PS2InstanceDataHeader; + geometry->instData = header; + header->platform = 4; + assert(geometry->meshHeader != NULL); + header->numMeshes = geometry->meshHeader->numMeshes; + header->instanceMeshes = new PS2InstanceData[header->numMeshes]; + for(uint32 i = 0; i < header->numMeshes; i++){ + PS2InstanceData *instance = &header->instanceMeshes[i]; + uint32 buf[2]; + stream.read((char*)buf, 8); + instance->dataSize = buf[0]; + instance->noRefChain = buf[1]; + instance->data = new uint8[instance->dataSize]; + stream.read((char*)instance->data, instance->dataSize); + } +} + +void +WriteNativeDataPS2(ostream &stream, int32 len, void *object, int32, int32) +{ + Geometry *geometry = (Geometry*)object; + WriteChunkHeader(stream, ID_STRUCT, len-12); + writeUInt32(4, stream); + assert(geometry->instData != NULL); + PS2InstanceDataHeader *header = + (PS2InstanceDataHeader*)geometry->instData; + for(uint32 i = 0; i < header->numMeshes; i++){ + PS2InstanceData *instance = &header->instanceMeshes[i]; + uint32 buf[2]; + buf[0] = instance->dataSize; + buf[1] = instance->noRefChain; + stream.write((char*)buf, 8); + stream.write((char*)instance->data, instance->dataSize); + } +} + +int32 +GetSizeNativeDataPS2(void *object, int32, int32) +{ + Geometry *geometry = (Geometry*)object; + int32 size = 16; + assert(geometry->instData != NULL); + PS2InstanceDataHeader *header = + (PS2InstanceDataHeader*)geometry->instData; + for(uint32 i = 0; i < header->numMeshes; i++){ + PS2InstanceData *instance = &header->instanceMeshes[i]; + size += 8; + size += instance->dataSize; + } + return size; +} + +}