#include #include #include "rwcore.h" RwUInt32 RwEngineGetVersion() { return 0x0C02FFFF; } RwBool RwStreamFindChunk(RwStream *stream, RwUInt32 type, RwUInt32 *lengthOut, RwUInt32 *versionOut) { RwUInt32 buffer[3]; RwInt32 ret; while (TRUE) { ret = RwStreamRead(stream, buffer, 3*sizeof(RwUInt32)); if (ret != 3*sizeof(RwUInt32)) return FALSE; if (buffer[0] == type) { *lengthOut = buffer[1]; *versionOut = buffer[2]; return TRUE; } RwStreamSkip(stream, buffer[1]); } } RwStream *RwStreamReadChunkHeaderInfo(RwStream *stream, RwChunkHeaderInfo *chunkHeaderInfo) { RwUInt32 buffer[3]; RwInt32 ret; ret = RwStreamRead(stream, buffer, 3*sizeof(RwUInt32)); if (ret != 3*sizeof(RwUInt32)) return NULL; chunkHeaderInfo->type = buffer[0]; chunkHeaderInfo->length = buffer[1]; chunkHeaderInfo->version = buffer[2]; return stream; } RwStream *RwStreamWriteChunkHeader(RwStream *stream, RwInt32 type, RwInt32 size) { RwInt32 version; version = RwEngineGetVersion(); if (RwStreamWrite(stream, &type, sizeof(RwInt32)) != stream) return NULL; if (RwStreamWrite(stream, &size, sizeof(RwInt32)) != stream) return NULL; if (RwStreamWrite(stream, &version, sizeof(RwInt32)) != stream) return NULL; return stream; } RwStream *RwStreamWriteReal(RwStream *stream, RwReal *reals, RwUInt32 numBytes) { if (numBytes != fwrite(reals, 1, numBytes, stream->file)) return NULL; return stream; } RwStream *RwStreamWriteInt16(RwStream *stream, RwInt16 *ints, RwUInt32 numBytes) { if (numBytes != fwrite(ints, 1, numBytes, stream->file)) return NULL; return stream; } RwStream *RwStreamWriteInt32(RwStream *stream, RwInt32 *ints, RwUInt32 numBytes) { if (numBytes != fwrite(ints, 1, numBytes, stream->file)) return NULL; return stream; } RwStream *RwStreamReadReal(RwStream *stream, RwReal *reals, RwUInt32 numBytes) { if (numBytes != fread(reals, 1, numBytes, stream->file)) return NULL; return stream; } RwStream *RwStreamReadInt16(RwStream *stream, RwInt16 *ints, RwUInt32 numBytes) { if (numBytes != fread(ints, 1, numBytes, stream->file)) return NULL; return stream; } RwStream *RwStreamReadInt32(RwStream *stream, RwInt32 *ints, RwUInt32 numBytes) { if (numBytes != fread(ints, 1, numBytes, stream->file)) return NULL; return stream; } RwUInt32 RwStreamRead(RwStream *stream, void *buffer, RwUInt32 length) { return fread(buffer, 1, length, stream->file); } RwStream *RwStreamWrite(RwStream *stream, void *buffer, RwUInt32 length) { if (length != fwrite(buffer, 1, length, stream->file)) return NULL; return stream; } RwStream *RwStreamSkip(RwStream *stream, RwUInt32 offset) { if (fseek(stream->file, offset, SEEK_CUR) == 0) return stream; return NULL; } RwUInt32 RwStreamTell(RwStream *stream) { return ftell(stream->file); } RwStream *RwStreamSeek(RwStream *stream, RwInt32 position) { if (fseek(stream->file, position, SEEK_SET) == 0) return stream; return NULL; } RwUInt32 RwStreamGetLength(RwStream *stream) { RwUInt32 len, oldpos; oldpos = RwStreamTell(stream); fseek(stream->file, 0, SEEK_END); len = RwStreamTell(stream); RwStreamSeek(stream, oldpos); return len; } RwBool RwStreamClose(RwStream *stream, void *pData) { RwInt32 ret; ret = fclose(stream->file); free(stream); if (ret == 0) return TRUE; return FALSE; } RwStream *RwStreamOpen(RwStreamType type, RwStreamAccessType access, void *pData) { RwStream *stream; RwChar mode[4]; RwChar *path; path = (RwChar *) pData; if (type != rwSTREAMFILENAME) return NULL; stream = (RwStream *) malloc(sizeof(RwStream)); if (access == rwSTREAMREAD) strcpy(mode, "rb"); else if (access == rwSTREAMWRITE) strcpy(mode, "wb"); else if (access == rwSTREAMAPPEND) strcpy(mode, "ab"); else return NULL; if ((stream->file = fopen(path, mode)) == NULL) return NULL; else return stream; } RwUInt32 RwObjectGetType(RwObject *object) { return (RwUInt32) object->type; } RwStream *RwStreamPeekInt32(RwStream *stream, RwInt32 *ints, RwUInt32 numBytes) { RwUInt32 ret; if (numBytes != (ret = fread(ints, 1, numBytes, stream->file))) { fseek(stream->file, -ret, SEEK_CUR); return NULL; } fseek(stream->file, -ret, SEEK_CUR); return stream; } const char *sections[] = { "None", "Struct", "String", "Extension", "Unknown", "Camera", "Texture", "Material", "Material List", "Atomic Section", "Plane Section", "World", "Spline", "Matrix", "Frame List", "Geometry", "Clump", "Unknown", "Light", "Unicode String", "Atomic", "Texture Native", "Texture Dictionary", "Animation Database", "Image", "Skin Animation", "Geometry List", "Anim Animation", "Team", "Crowd", "Delta Morph Animation", "Right To Render", "MultiTexture Effect Native", "MultiTexture Effect Dictionary", "Team Dictionary", "Platform Independet Texture Dictionary", "Table of Contents", "Particle Standard Global Data", "AltPipe", "Platform Independet Peds", "Patch Mesh", "Chunk Group Start", "Chunk Group End", "UV Animation Dictionary", "Coll Tree" }; /* From 0x0101 through 0x0135 */ const char *toolkitsections0[] = { "Metrics PLG", "Spline PLG", "Stereo PLG", "VRML PLG", "Morph PLG", "PVS PLG", "Memory Leak PLG", "Animation PLG", "Gloss PLG", "Logo PLG", "Memory Info PLG", "Random PLG", "PNG Image PLG", "Bone PLG", "VRML Anim PLG", "Sky Mipmap Val", "MRM PLG", "LOD Atomic PLG", "ME PLG", "Lightmap PLG", "Refine PLG", "Skin PLG", "Label PLG", "Particles PLG", "GeomTX PLG", "Synth Core PLG", "STQPP PLG", "Part PP PLG", "Collision PLG", "HAnim PLG", "User Data PLG", "Material Effects PLG", "Particle System PLG", "Delta Morph PLG", "Patch PLG", "Team PLG", "Crowd PP PLG", "Mip Split PLG", "Anisotrophy PLG", "Not used", "GCN Material PLG", "Geometric PVS PLG", "XBOX Material PLG", "Multi Texture PLG", "Chain PLG", "Toon PLG", "PTank PLG", "Particle Standard PLG", "PDS PLG", "PrtAdv PLG", "Normal Map PLG", "ADC PLG", "UV Animation PLG" }; /* From 0x0180 through 0x01c1 */ const char *toolkitsections1[] = { "Character Set PLG", "NOHS World PLG", "Import Util PLG", "Slerp PLG", "Optim PLG", "TL World PLG", "Database PLG", "Raytrace PLG", "Ray PLG", "Library PLG", "Not used", "Not used", "Not used", "Not used", "Not used", "Not used", "2D PLG", "Tile Render PLG", "JPEG Image PLG", "TGA Image PLG", "GIF Image PLG", "Quat PLG", "Spline PVS PLG", "Mipmap PLG", "MipmapK PLG", "2D Font", "Intersection PLG", "TIFF Image PLG", "Pick PLG", "BMP Image PLG", "RAS Image PLG", "Skin FX PLG", "VCAT PLG", "2D Path", "2D Brush", "2D Object", "2D Shape", "2D Scene", "2D Pick Region", "2D Object String", "2D Animation PLG", "2D Animation", "Not used", "Not used", "Not used", "Not used", "Not used", "Not used", "2D Keyframe", "2D Maestro", "Barycentric", "Platform Independent Texture Dictionary TK", "TOC TK", "TPL TK", "AltPipe TK", "Animation TK", "Skin Split Tookit", "Compressed Key TK", "Geometry Conditioning PLG", "Wing PLG", "Generic Pipeline TK", "Lightmap Conversion TK", "Filesystem PLG", "Dictionary TK", "UV Animation Linear", "UV Animation Parameter" }; const char *RSsections[] = { "Unused 1", "Unused 2", "Unused 3", "Pipeline Set", "Unused 5", "Unused 6", "Specular Material", "Unused 8", "2dfx", "Night Vertex Colors", "Collision Model", "Unused 12", "Reflection Material", "Mesh Extension", "Frame", "Unused 16" }; const RwChar *RwChunkHeaderInfoGetChunkName(RwUInt32 t) { switch (t) { case 0x50E: return "Bin Mesh PLG"; break; case 0x510: return "Native Data PLG"; break; case 0xF21E: return "ZModeler Lock"; break; default: break; } if (t <= 45) return sections[t]; else if (t <= 0x0253F2FF && t >= 0x0253F2F0) return RSsections[t-0x0253F2F0]; else if (t <= 0x0135 && t >= 0x0101) return toolkitsections0[t-0x0101]; else if (t <= 0x0180 && t >= 0x01c1) return toolkitsections1[t-0x0180]; else return "Unknown"; }