#include "7z/7z.h"
uint32_t
-zlib_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen, int level,
- int strat)
+zlib_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen,
+ int level, int strat)
{
if (strat == Z_USE_7Z) {
// compress with 7z
}
uint32_t
-rlz_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen, int mode)
+rlz_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen,
+ int mode)
{
if (mode == -1) {
// theme creator compatible mode
- // we'll be just as bad as the theme creator and run _4_ compression passes
+ // we'll be just as bad as the theme creator and run _4_ compression passes
+ //
// >_>
int size5, size6, size7;
if (size7 != -1 && (size7 < size6 || size6 != -1)
&& (size7 < size5 || size5 != -1))
return size7; // okay, we're _slightly_ more optimised than
- // the theme creator :P
+ // the theme creator :P
if (size6 != -1 && (size6 < size5 || size5 != -1))
return rlzcompress (dest, srcLen, src, 6);
if (size5 != -1)
is_prime (uint32_t in)
{
if (in < 12) { // need this buffer as "lim" (below) may
- // underflow
+ // underflow
return (in <= 3 || in == 5 || in == 7 || in == 11);
}
// filter out half the results by checking if the number is even
#define APPXMLVER 1.10f
#define APPVER 1.11f
-
#ifndef TRUE
#define TRUE (uint8_t)1
#endif
// #define ALIGN_TO_4(n) (((n) + 3) >>2 <<2) // problem: upper 2 bits gets
// wiped too
-
#define UTF8_BOM ((uint32_t) 0xBFBBEF)
#define UTF16_BOM ((uint16_t) 0xFEFF)
#define UTF32_BOM ((uint32_t) 0x0000FEFF)
#define PACK_STRUCT(nam, struc) typedef struct struc __attribute__ ((packed)) nam
-uint32_t zlib_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen, int level,
- int strat);
+uint32_t zlib_compress (void *src, uint32_t srcLen, void *dest,
+ uint32_t destLen, int level, int strat);
int zlib_uncompress (void *dest, unsigned int destLen, const void *src,
unsigned int srcLen);
uint32_t zlib_unpacked_size (void *src, uint32_t srcLen);
-uint32_t rlz_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen, int mode);
+uint32_t rlz_compress (void *src, uint32_t srcLen, void *dest, uint32_t destLen,
+ int mode);
uint8_t file_exists (char *fn);
uint32_t filesize (const char *fn);
RcoTableMap RCOXML_TABLE_MODEL_FMT = NULL;
RcoTableMap RCOXML_TABLE_SOUND_FMT = NULL;
-// const RcoTableMap RCOXML_TABLE_REFTYPE = {"event", "text"}; // TODO:
+// const RcoTableMap RCOXML_TABLE_REFTYPE = {"event", "text"}; // TODO:
RcoTagMap RCOXML_TABLE_TAGS = NULL;
* replacing sound resources.\n" "\n" "\nOptions:\n" " --lang <lang>
* Language of text to replace. [English]\n" " See '%s help extract' for
* valid values.\n" " --channel <n> Replace sound channel <n>. [1]\n" "
- * --format <fmt> Format of imported resource. Only applies to image,\n" "
- * sound and model resources. You can use a format ID, or\n" " the
+ * --format <fmt> Format of imported resource. Only applies to image,\n" "
+ * * sound and model resources. You can use a format ID, or\n" " the
* following:\n"); // TODO: printf( " --pack <val> How to compress this
* resource.\n" #ifdef DISABLE_RLZ " Valid values are 'none' and 'zlib'.\n"
* #else " Valid values are 'none', 'zlib' and 'rlz'.\n" #endif " Only
* applies to images and models. By default, will use\n" " 'zlib' unless
* format is PNG/JPG/TIF/GIF where 'none' will\n" " be used.\n");
* PRINT_PACK_OPTS; return 0; } */
- /*
+ /*
* else if(!strcasecmp(app_argv[2], "list")) { printf("Syntax: %s list
- * <rcofile> [options]\n", app_argv[0]); printf(" List resources in an easy
+ * <rcofile> [options]\n", app_argv[0]); printf(" List resources in an easy
* to parse format.\n"); printf("\n"); printf("\nOptions:\n"); printf("
- * --type <type> Only list resources of a certain type.\n"); printf(" Types
+ * --type <type> Only list resources of a certain type.\n"); printf(" Types
* can be 'image', 'sound', 'model', \n"); printf(" --no-recurse Don't
* write UCS BOM.\n"); printf(" The following option only applies for
* extracting sound resources.\n"); printf(" --channel <n> Extract sound
printf
(" --ini-dir Specify directory containing Rcomage INI files.\n");
- /*
+ /*
* printf("\n"); printf("\nGeneral options:\n"); printf("\n"); printf("
* --pack \n"); */
else
MAIN_INV_CMD_SYNTAX}
if (!sRcoFile || !sXmlFile)
- MAIN_INV_CMD_SYNTAX if (gimconvOpts.ext && strlen (gimconvOpts.ext) > 5) {
- gimconvOpts.ext[5] = '\0'; // prevent buffer overflow
- if (gimconvOpts.cmd && strlen (gimconvOpts.cmd) > 255) {
- gimconvOpts.cmd[255] = '\0'; // prevent buffer overflow
- }
- if (gimconvOpts.extFlags && strlen (gimconvOpts.extFlags) > 512) {
- gimconvOpts.extFlags[512] = '\0'; // prevent buffer overflow
- }
+ MAIN_INV_CMD_SYNTAX if (gimconvOpts.ext && strlen (gimconvOpts.ext) > 5) {
+ gimconvOpts.ext[5] = '\0'; // prevent buffer overflow
+ if (gimconvOpts.cmd && strlen (gimconvOpts.cmd) > 255) {
+ gimconvOpts.cmd[255] = '\0'; // prevent buffer overflow
}
+ if (gimconvOpts.extFlags && strlen (gimconvOpts.extFlags) > 512) {
+ gimconvOpts.extFlags[512] = '\0'; // prevent buffer overflow
+ }
+ }
rRCOFile *rco = read_rco (sRcoFile);
if (entry) {
/* if(entry->id == RCO_TABLE_SOUND && entry->type == 1) { // handle
- * sound channel stuff
- *
- * } */
+ * sound channel stuff } */
if (stTextLang)
warning ("Resource '%s' is not text.", sResLabel);
if (!dump_resource (sOutFile, entry, dump_output_data, NULL)) {
if (!sNoConvVag) {
rco_map_func (rco, NULL, NULL, compile_vagconv_map);
} else
- rco_map_func (rco, NULL, NULL, compile_wavcheck_map); // verify there
- // are no
- // orphaned
- // .wav sound
- // references
+ rco_map_func (rco, NULL, NULL, compile_wavcheck_map); // verify there
+ //
+ // are no
+ // orphaned
+ // .wav sound
+ // references
if (!sNoConvVsmx) {
rco_map_func (rco, NULL, NULL, compile_vsmxconv_map);
}
fread (((char **) buf)[channels] + len[channels], 1,
READ_BUFFER, fp);
}
- /*
+ /*
* fseek(fp, 0, SEEK_END); len[channels] = ftell(fp); rewind(fp);
- *
+ *
* buf[channels] = malloc(len[channels]); fileread(fp,
* buf[channels], len[channels]); */
fclose (fp);
warning ("Unable to open file %s", app_argv[i]);
}
- uint8_t success = vag2wav (app_argv[app_argc - 1], channels, len, buf);
+ uint8_t success =
+ vag2wav (app_argv[app_argc - 1], channels, len, buf);
free (len);
while (channels--)
if (warnUnk && j == num) {
error ("Unknown option '%s'.", app_argv[i]);
exit (RETERR_SYNTAX);
- /* warning("Unknown option '%s'.", argv[i]); argv[i][0] = '\0';
+ /* warning("Unknown option '%s'.", argv[i]); argv[i][0] = '\0';
* // don't warn them again */
}
}
// *new* fix entry here as well
strcpy (entry->srcFile, fullOutName);
- entry->srcLenUnpacked = filesize (fullOutName); // get around issues of
- // conversions changing
- // filesize :P (dirty,
- // but works!)
+ entry->srcLenUnpacked = filesize (fullOutName); // get around issues of
+ //
+ // conversions changing
+ // filesize :P (dirty,
+ // but works!)
}
- /*
+ /*
* for(j=0; j<numResToWrite; j++) { if(entry->id == RCO_TABLE_SOUND) { //
* do something dirty - hack the srcFile here... outName[len+1] = '\0';
* strcpy(soundSetSrc, fullOutName); strcpy(soundSetSrc +
* strlen(soundSetSrc), "ch*.vag");
- *
+ *
* sprintf(outName + len +1, "ch%d.", j); len = strlen(outName) -1; }
* strcpy(outName + len +1, ext);
- *
+ *
* // trick dump_resource() into doing what we want it to by fiddling with
* stuff uint32_t origAddr = entry->srcAddr, origLen = entry->srcLen,
* origLenUnpacked = entry->srcLenUnpacked; if(entry->id ==
* RCO_TABLE_SOUND) { entry->srcLen = entry->srcLenUnpacked =
* ((rRCOSoundEntry*)entry->extra)->channelData[j*2]; entry->srcAddr +=
* ((rRCOSoundEntry*)entry->extra)->channelData[j*2+1]; }
- *
+ *
* if((fp = fopen(fullOutName, "wb"))) { if(!dump_resource(fp, entry))
* warning("Unable to dump resource '%s'.", labels + entry->labelOffset);
* fclose(fp); } else warning("Unable to write to file '%s'.",
* fullOutName);
- *
+ *
* entry->srcAddr = origAddr; entry->srcLen = origLen;
* entry->srcLenUnpacked = origLenUnpacked;
- *
+ *
* // *new* fix entry here as well if(entry->id != RCO_TABLE_SOUND)
* strcpy(entry->srcFile, fullOutName); } */
entry->srcAddr = 0;
char *bufOut = buf;
uint32_t outBufLen = 4096;
- /* { // feed in the BOM (is it really necessary though?) uint32_t number;
- * char* unicodePtr; if(textEntry->format == RCO_TEXT_FMT_UTF32) {
- * uint32_t bom = UTF32_BOM; if(parent->rco->eSwap) bom =
- * ENDIAN_SWAP(bom); number = sizeof(bom); unicodePtr = (char*)&bom;
- * iconv(ic, (const char**)(&unicodePtr), (size_t*)(&number), &bufOut,
- * (size_t*)(&outBufLen)); } else if(textEntry->format ==
- * RCO_TEXT_FMT_UTF8) { uint32_t bom = UTF8_BOM; number = 3; unicodePtr =
- * (char*)&bom; iconv(ic, (const char**)(&unicodePtr),
- * (size_t*)(&number), &bufOut, (size_t*)(&outBufLen)); } else { uint16_t
- * bom = UTF16_BOM; if(parent->rco->eSwap) bom = ENDIAN_SWAP(bom);
- * number = sizeof(bom); unicodePtr = (char*)&bom; iconv(ic, (const
+ /* { // feed in the BOM (is it really necessary though?) uint32_t
+ * number; char* unicodePtr; if(textEntry->format ==
+ * RCO_TEXT_FMT_UTF32) { uint32_t bom = UTF32_BOM;
+ * if(parent->rco->eSwap) bom = ENDIAN_SWAP(bom); number = sizeof(bom);
+ * unicodePtr = (char*)&bom; iconv(ic, (const char**)(&unicodePtr),
+ * (size_t*)(&number), &bufOut, (size_t*)(&outBufLen)); } else
+ * if(textEntry->format == RCO_TEXT_FMT_UTF8) { uint32_t bom = UTF8_BOM;
+ * * number = 3; unicodePtr = (char*)&bom; iconv(ic, (const
* char**)(&unicodePtr), (size_t*)(&number), &bufOut,
- * (size_t*)(&outBufLen)); } } */
+ * (size_t*)(&outBufLen)); } else { uint16_t bom = UTF16_BOM;
+ * if(parent->rco->eSwap) bom = ENDIAN_SWAP(bom); number = sizeof(bom);
+ * unicodePtr = (char*)&bom; iconv(ic, (const char**)(&unicodePtr),
+ * (size_t*)(&number), &bufOut, (size_t*)(&outBufLen)); } } */
uint32_t nullsStripped = 0;
while (dataLen) {
}
outBufLen = 4096;
bufOut = buf;
- /*
+ /*
* filewrite(fp, buf, bufOut-buf); outBufLen = 4096; bufOut = buf; */
}
if (nullsStripped)
}
// gimconv is screwy and sometimes prepends a '/' to our destination file
// so we do our feeble attempt to determine if it is a relative path
- if (dest[0] == '\\' || dest[0] == '/' || dest[0] == '.' || dest[1] == ':') // should
- // handle
- // "\file",
- // "\\network\blah"
- // and
- // "C:\file"
- // notations;
- // gimconv
- // seems
- // to
- // also
- // escape
- // if
- // first
- // char
- // ==
- // '.'
+ if (dest[0] == '\\' || dest[0] == '/' || dest[0] == '.' || dest[1] == ':') // should
+ //
+ // handle
+ // "\file",
+ // "\\network\blah"
+ // and
+ // "C:\file"
+ // notations;
+ // gimconv
+ // seems
+ // to
+ // also
+ // escape
+ // if
+ // first
+ // char
+ // ==
+ // '.'
sprintf (gimconvCmd + strlen (gimconvCmd), " \"%s\" -o \"%s\"", src, dest);
else
sprintf (gimconvCmd + strlen (gimconvCmd), " \"%s\" -o \"./%s\"", src,
void dump_text_resources (char *labels, rRCOEntry * parent, uint8_t writeHeader,
char *pathPrefix, uint8_t bWriteXML);
uint8_t dump_output_data (char *dest, void *buf, rRCOEntry * entry, void *arg);
-uint8_t dump_output_vsmxdec (char *dest, void *buf, rRCOEntry * entry, void *arg);
+uint8_t dump_output_vsmxdec (char *dest, void *buf, rRCOEntry * entry,
+ void *arg);
void compile_gimconv_map (rRCOFile * rco, rRCOEntry * entry, void *arg);
void compile_vagconv_map (rRCOFile * rco, rRCOEntry * entry, void *arg);
#define RCO_SIGNATURE 0x46525000 // .PRF (PSP Resource File?)
PACK_STRUCT (PRFHeader, {
- uint32_t signature; // RCO_SIGNATURE
+ uint32_t signature; // RCO_SIGNATURE
uint32_t version;
// 0x70 - UMD RCOs (video?), FW1.00
// 0x71 - UMD RCOs (audio?), FW1.50, FW2.50
// 0x96 - FW2.80, FW2.82, FW3.00, FW3.03, FW3.10, FW3.30, FW3.40
// 0x100 - FW3.50, FW3.52, FW5.00, FW5.55
uint32_t null;
- uint32_t compression; // upper nibble = compression, lower nibble:
- // 0=flash0 RCOs, 1=UMD RCOs????
- /*
+ uint32_t compression; // upper nibble = compression,
+ // lower nibble:
+ // 0=flash0 RCOs, 1=UMD RCOs????
+ /*
* #define RCO_COMPRESSION_NONE 0x00 // entries for 0x01 ?? #define
* RCO_COMPRESSION_ZLIB 0x10 #define RCO_COMPRESSION_RLZ 0x20 */
// main table pointers
uint32_t pTextTable; // type 3
uint32_t pSoundTable; // type 5
uint32_t pModelTable; // type 6
- uint32_t pImgTable; // type 4
- uint32_t pUnknown; // always 0xFFFFFFFF
+ uint32_t pImgTable; // type 4
+ uint32_t pUnknown; // always 0xFFFFFFFF
uint32_t pFontTable; // type 7
- uint32_t pObjTable; // type 8
+ uint32_t pObjTable; // type 8
uint32_t pAnimTable; // type 9
// text stuff
- uint32_t pTextData; // NOTE: this may == pLabelData if lTextData ==
- // 0
+ uint32_t pTextData; // NOTE: this may == pLabelData if lTextData ==
+ //
+ // 0
uint32_t lTextData; uint32_t pLabelData; uint32_t lLabelData;
uint32_t pEventData;
uint32_t lEventData;
// pointer data
- uint32_t pTextPtrs; uint32_t lTextPtrs; uint32_t pImgPtrs; uint32_t lImgPtrs;
+ uint32_t pTextPtrs; uint32_t lTextPtrs; uint32_t pImgPtrs;
+ uint32_t lImgPtrs;
uint32_t pModelPtrs; uint32_t lModelPtrs;
uint32_t pSoundPtrs;
uint32_t lSoundPtrs; uint32_t pObjPtrs; uint32_t lObjPtrs;
uint16_t typeId;
uint16_t blank;
uint32_t labelOffset;
- uint32_t eHeadSize; // = sizeof(RCOEntry) = 0x28 [ only used for
- // entries with extra info (ie not "main"
- // entries) ]
- uint32_t entrySize; // main tables (main/img etc) uses 0x28 here,
- // or is this the length of current entry (not
- // including subentries)?
+ uint32_t eHeadSize; // =
+ // sizeof(RCOEntry)
+ // =
+ // 0x28
+ // [
+ // only
+ // used
+ // for
+ // entries with extra info (ie not "main"
+ // entries) ]
+ uint32_t entrySize; // main tables (main/img etc) uses 0x28 here,
+ // or is this the length of current entry (not
+ // including subentries)?
// 0x10
uint32_t numSubentries;
uint32_t nextEntryOffset;
- uint32_t prevEntryOffset; // this is usually 0x0 however (does make
- // writing RCOs easier though :P I guess Sony's
- // tools do something similar...)
+ uint32_t prevEntryOffset; // this
+ // is
+ // usually
+ // 0x0
+ // however
+ // (does
+ // make
+ // writing RCOs easier though :P I guess Sony's
+ // tools do something similar...)
uint32_t parentTblOffset; // offset of this entry from parent table
// 0x20
uint32_t blanks[2];
#define RCO_MODEL_GMO 0x0
PACK_STRUCT (RCOImgModelEntry, {
uint16_t format;
- uint16_t compression; // RCO_DATA_COMPRESSION_* constants
+ uint16_t compression; // RCO_DATA_COMPRESSION_*
+ // constants
uint32_t sizePacked;
uint32_t offset;
- uint32_t sizeUnpacked; // this value doesn't exist if entry isn't
- // compressed
+ uint32_t sizeUnpacked; // this
+ // value
+ // doesn't
+ // exist
+ // if
+ // entry
+ // isn't
+ // compressed
});
// note, some image/model entries which aren't compressed, don't have the last
// member
PACK_STRUCT (RCOPS3ImgModelEntry, { // PS3 version of the above
uint16_t format;
- uint16_t compression; // RCO_DATA_COMPRESSION_* constants
+ uint16_t compression; // RCO_DATA_COMPRESSION_*
+ // constants
uint32_t sizePacked;
uint32_t offset;
- uint32_t something; // PS3 RCOs seem to have this extra element -
- // probably something to do with
- // planes/frames?? usually 0x1
+ uint32_t something; // PS3 RCOs
+ // seem to have
+ // this extra
+ // element -
+ // probably something to do with
+ // planes/frames?? usually 0x1
uint32_t sizeUnpacked; // this value doesn't exist if entry isn't
- // compressed
+ // compressed
});
#define RCO_SOUND_VAG 0x1
PACK_STRUCT (RCOSoundEntry, {
uint16_t format; // 0x01 = VAG
- uint16_t channels; // 1 or 2 channels
+ uint16_t channels; // 1 or 2 channels
uint32_t sizeTotal;
uint32_t offset;
// now pairs of size/offset for each channel
PACK_STRUCT (HeaderComprInfo, {
uint32_t lenPacked;
uint32_t lenUnpacked;
- uint32_t lenLongestText; // length of the longest language's text data
- // (unpacked)
+ uint32_t lenLongestText; // length
+ // of
+ // the
+ // longest
+ // language's
+ // text
+ // data
+ // (unpacked)
});
PACK_STRUCT (TextComprInfo, {
uint16_t lang;
uint16_t unknown; // always 0x1
uint32_t nextOffset; // = ALIGN_TO_4(sizeof(TextComprInfo) +
- // packedLen); is 0 for last text entry
- // regardless of what actually comes after
+ // packedLen); is 0 for last text entry
+ // regardless of what actually comes after
uint32_t packedLen;
uint32_t unpackedLen;
});
}
}
-/*
+/*
* rRCOEntry* rco_add_entry(rRCOEntry* parent, rRCOEntry* newEntry, int pos) {
* rRCOEntry* dest; if(pos != -1 && pos > (int)(parent->numSubentries)) return
* NULL;
- *
+ *
* if(!parent->numSubentries) { parent->subentries =
* (rRCOEntry*)malloc(sizeof(rRCOEntry)); dest = parent->subentries; } else {
* parent->subentries = (rRCOEntry*)realloc(parent->subentries,
* parent->numSubentries - pos; //rRCOEntry* tmpBuffer = (rRCOEntry*)malloc()
* memcpy(&(parent->subentries[pos+1]), &(parent->subentries[pos]),
* numEntriesToMove * sizeof(rRCOEntry)); } }
- *
+ *
* parent->numSubentries++; memcpy(dest, newEntry, sizeof(rRCOEntry));
- *
+ *
* return dest; } */
// parses an RCO (give it the main entry) to fix any resource which is
}
if (entry->srcCompression == RCO_DATA_COMPRESSION_RCO) {
- // special case where stuff is embedded in RCO - this should only be used
+ // special case where stuff is embedded in RCO - this should only be used
+ //
// with VSMX, so we'll take a short cut here, but:
// TODO: do some extra checks to enforce the above
#define ENDIAN_SWAP_HALF32(x) (((x) & 0xFF) << 8 | ((x) & 0xFF00) >> 8 | ((x) & 0xFF0000) << 8 | ((x) & 0xFF000000) >> 8)
- /*
+ /*
* if(!isObj && RCO_ANIM_EXTRA_REFS[type]) { uData[0] =
* ENDIAN_SWAP_HALF32(uData[0]); uData[1] = ENDIAN_SWAP(uData[1]); i = 2; } */
typedef struct __rRCOEntry {
uint8_t type; // main table uses 0x01; may be used as a
- // current entry depth value
+ // current entry depth value
uint8_t id;
// char* label;
uint32_t labelOffset;
- uint32_t offset; // absolute offset of this entry in file (only
- // used when reading/writing RCOs - means
- // nothing otherwise; also, writing the RCO may
- // change this value)
+ uint32_t offset; // absolute offset of this entry in file (only
+ // used when reading/writing RCOs - means
+ // nothing otherwise; also, writing the RCO may
+ // change this value)
// this value is also used to store the line number of the node when reading
// an XML
uint32_t srcAddr;
uint32_t srcLen;
uint32_t srcLenUnpacked;
- uint32_t srcCompression; // use RCO_DATA_COMPRESSION_* constants in
- // rcofile.h
+ uint32_t srcCompression; // use RCO_DATA_COMPRESSION_* constants in
+ // rcofile.h
void *srcBuffer; // work around for reading XML; should only be
- // used for sound and text entries; need to
- // check if srcFile contains a '*', then use
- // this
+ // used for sound and text entries; need to
+ // check if srcFile contains a '*', then use
+ // this
} rRCOEntry;
typedef struct {
RCOTextIndex *indexes;
} rRCOTextEntry;
-/* packed_struct { char* label; uint32_t length; uint32_t offset; } rRCOTextIndex; */
+/* packed_struct { char* label; uint32_t length; uint32_t offset; }
+ * rRCOTextIndex; */
typedef struct {
rRCOEntry *textEntry;
RCOTextIndex *index;
char *events;
uint32_t eventsLen;
- /*
+ /*
* // pointer segments rRCOTextIdxPtr* ptrText; uint32_t numPtrText; rRCOEntry**
* ptrImg; uint32_t numPtrImg; rRCOEntry** ptrModel; uint32_t numPtrModel;
* rRCOEntry** ptrSound; uint32_t numPtrSound; rRCOEntry** ptrObj; uint32_t
// additional info about the source (mainly used for displaying info about
// the RCO)
- uint32_t verId; // offset 0x04 in file
+ uint32_t verId; // offset 0x04 in file
uint32_t umdFlag;
uint32_t headerCompression;
uint8_t eSwap;
typedef struct {
uint32_t type;
- void *ptr; // will usu be rRCOEntry*, but may be char* for
- // events; NULL if type is nothing
+ void *ptr; // will usu be rRCOEntry*, but may be char* for
+ //
+ // events; NULL if type is nothing
uint32_t rawPtr; // raw value from source - means nothing if
- // type is known
+ // type is known
} rRCORef;
typedef struct {
uint32_t format;
uint32_t compression;
uint32_t unkCompr; // unknown - usually 0, some PS3 rcos have 1
- // here
+ // here
} rRCOImgModelEntry;
typedef struct {
uint16_t format; // 0x01 = VAG
uint16_t channels; // 1 or 2 channels
- uint32_t *channelData; // size/offset pairs
+ uint32_t *channelData; // size/offset pairs
} rRCOSoundEntry;
typedef struct {
- uint32_t format; // 1
+ uint32_t format; // 1
uint32_t compression; // 0
uint32_t unknown;
uint32_t unknown2;
float colR;
float colG;
float colB;
- float colA; // RGBA colour weights
+ float colA; // RGBA
+
+ // colour
+ // weights
float dimW;
float dimH;
float unknown;
float sclX;
- float sclY; // scale values
+ float sclY; // scale
+
+ // values
float elemScale;
- uint32_t iconOffset; // unknown weird value, appears to affect icon
- // offsetting. Only lowest byte appears to have
- // any effects - upper nibble appears to affect
- // Y offset, and lower nibble affects X offset
- // somehow.
- rRCORef loadAction; // the event/anim executed on image load (note,
- // load, not display) or describes when image
- // is loaded? (eg onShadowInit)
+ uint32_t iconOffset; // unknown weird value, appears
+ // to affect icon
+ // offsetting. Only lowest byte appears to have
+ // any effects - upper nibble appears to affect
+ // Y offset, and lower nibble affects X offset
+ // somehow.
+ rRCORef loadAction; // the event/anim executed on image load (note,
+ //
+ // load, not display) or describes when image
+ // is loaded? (eg onShadowInit)
});
-/*
+/*
* PACK_STRUCT(RCOObjSPage, { uint32_t unknown; // usu 0x111, sometimes 0xFFFF
* (only seen in UMD video RCOs) rRCORef event1; rRCORef event2; rRCORef
* event3; rRCORef event4; }); // 0x01 PACK_STRUCT(RCOObjSPlane, { RCOObjPos
* effect on height. Upper 2 bytes seem to have no effect. }); // 0x02
* PACK_STRUCT(RCOObjSButton, { // this page seems to be for buttons/pane
* items. for "buttons", has events for "Push", "FocusIn", "FocusOut" etc
- * RCOObjPos pos; rRCORef image; rRCORef shadow; // usu this & above images are
+ * RCOObjPos pos; rRCORef image; rRCORef shadow; // usu this & above images are
* img/shadow pairs rRCORef image2; rRCORef ref; rRCORef event1; rRCORef
* event2; rRCORef event3; rRCORef event4; rRCORef event5; rRCORef event6;
* rRCORef event7; rRCORef event8; uint32_t unknown; // appears to be 0xFFFFFFFF
* ref2; rRCORef ref3; rRCORef ref4; rRCORef ref5; rRCORef ref6; rRCORef event;
* rRCORef ref7; }); // 0x13 PACK_STRUCT(RCOObjSLItem, { rRCORef text; rRCORef
* ref1; rRCORef ref2; }); // 0x14 PACK_STRUCT(RCOObjSEdit, { RCOObjPos pos;
- * uint32_t unknown; // dunno whether hex or float uint32_t unknown2; // dunno whether
- * hex or float uint32_t unknown3; // dunno whether hex or float uint32_t unknown4; //
+ * uint32_t unknown; // dunno whether hex or float uint32_t unknown2; // dunno whether
+ * hex or float uint32_t unknown3; // dunno whether hex or float uint32_t unknown4; //
* dunno whether hex or float rRCORef ref1; rRCORef ref2; rRCORef event1; rRCORef
* ref3; rRCORef ref4; rRCORef ref5; rRCORef event2; rRCORef event3; rRCORef obj1;
* rRCORef obj2; rRCORef ref6; }); // 0x15 PACK_STRUCT(RCOObjSClock, { RCOObjPos
* pos; uint32_t unknown; float unknown2; rRCORef text1; rRCORef text2; rRCORef ref1;
- * rRCORef ref2; rRCORef event1; rRCORef event2; rRCORef ref3; rRCORef ref4; rRCORef
+ * rRCORef ref2; rRCORef event1; rRCORef event2; rRCORef ref3; rRCORef ref4; rRCORef
* event3; rRCORef event4; rRCORef ref5; rRCORef ref6; rRCORef event5; }); // 0x16
* PACK_STRUCT(RCOObjSIList, { RCOObjPos pos; float unknown; rRCORef ref1; rRCORef
* ref2; rRCORef event; rRCORef ref3; }); // 0x17 PACK_STRUCT(RCOObjSIItem, {
* rRCORef ref1; // [object/event] rRCORef ref2; // [object/event] rRCORef ref3; //
* [object/event] prev/up? rRCORef ref4; // [object/event] next/down? uint32_t
* unknown; // 0xFFFFFFFF or 0 }); // 0x1A
- *
+ *
* PACK_STRUCT(RCOAnimSPos, { rRCORef obj; float time; uint32_t unknown; float x;
* float y; float unknown2; }); PACK_STRUCT(RCOAnimSColour, { rRCORef obj; float
- * time; uint32_t unknown; // dunno whether float or int (probably int) float r; float
+ * time; uint32_t unknown; // dunno whether float or int (probably int) float r; float
* g; float b; float a; }); PACK_STRUCT(RCOAnimSRotate, { // TODO: this one needs
* checking rRCORef obj; float time; uint32_t unknown; // dunno whether float or int
* (probably int) uint32_t unknown2; // dunno whether float or int (probably int)
typedef struct {
char *fName;
uint32_t fSize;
- uint32_t fSizeExpanded; // file size with decompressed header
+ uint32_t fSizeExpanded; // file size with decompressed header
void *tables; // decompressed tables
uint32_t tablesSize;
}
rco->umdFlag = header.compression & 0xF; // actually, I'm usure about
- // this, but meh
+ // this, but meh
rco->headerCompression = header.compression >> 4;
rco->verId = header.version;
return NULL;
default: // this won't actually ever be executed due to
- // the new compression checking code above...
- // :/
+ // the new compression checking code above...
+ // :/
error
("[header] Unknown compression method specified (0x%x) - can't continue.",
rco->headerCompression);
// decompress text data
if (header.pTextData != RCO_NULL_PTR && header.lTextData) {
fseek (rcoH.fp, header.pTextData, SEEK_SET); // TODO: check offset
- // first!
+ // first!
TextComprInfo tci;
info ("TextData Compression info:");
}
free (readBuf);
- rcoH.fSizeExpanded += ALIGN_TO_4 (tci.unpackedLen) - ALIGN_TO_4 (tci.packedLen); // TODO:
- // need
- // to
- // check
- // if
- // this
- // is
- // correct
+ rcoH.fSizeExpanded += ALIGN_TO_4 (tci.unpackedLen) - ALIGN_TO_4 (tci.packedLen); // TODO:
+ //
+ // need
+ // to
+ // check
+ // if
+ // this
+ // is
+ // correct
if (!tci.nextOffset)
break;
rco_fread(&rcoH, dp, hl); \
} \
}
- /*
+ /*
* READ_RCO_READ_PTR_SEGMENT(header.pTextPtrs, header.lTextPtrs,
* rcoH.ptrsText, rcoH.numTextPtrs, "text");
* READ_RCO_READ_PTR_SEGMENT(header.pImgPtrs, header.lImgPtrs,
warning ("[header] Model resource pointer/length is invalid.");
}
- /*
+ /*
* rco->pDataText = header.pTextData; rco->lDataText = header.lTextData;
* if(!rco->lDataText) rco->pDataText = 0; rco->pDataImg = header.pImgData;
* rco->lDataImg = header.lImgData; if(!rco->lDataImg) rco->pDataImg = 0;
* if(!rco->lDataSound) rco->pDataSound = 0; rco->pDataModel =
* header.pModelData; rco->lDataModel = header.lModelData;
* if(!rco->lDataModel) rco->pDataModel = 0;
- *
+ *
* rco->attachSource = (char*)malloc(strlen(fn) +1);
* strcpy(rco->attachSource, fn); */
}
compression &= 0xFF;
if (compression == RCO_DATA_COMPRESSION_NONE) {
// assume that this doesn't include the packed length value
- // ...but we'll still at least _try_ to see if this isn't a short
+ // ...but we'll still at least _try_ to see if this isn't a short
+ //
// entry (not guaranteed to succeed, especially for the last
// image entry)
if (!re.nextEntryOffset ||
return;
}
- /*
+ /*
* // dirty hack for reading PS3 stuff if(rco->ps3 && extraSize ==
* rimeSize) extraSize -= sizeof(uint32_t);
- *
+ *
* if(!rco_fread(rcoH, (uint8_t*)(&rie) +sizeof(uint32_t), extraSize -
* sizeof(uint32_t))) { error("[entry (0x%x)] Unable to read entry
* extra data - file exhausted.", data->offset); return; }
// our ugly hack to get around borked update_plugin.rco when decompressed
// with Resurssiklunssi
- // the issue is that the image isn't compressed by default, so uses a short
+ // the issue is that the image isn't compressed by default, so uses a short
+ //
// image entry (ie, doesn't include decompressed size), however
- // Resurssiklunssi will compress it but won't add in this decompressed size
+ // Resurssiklunssi will compress it but won't add in this decompressed size
+ //
// since there is no room for it
// rcomage expects a decompressed size so will assume it exists (no way to
// tell if it's not there) but this will cause an alignment error for the
- // parent. The only way to detect this is, thus, trap this alignment error
+ // parent. The only way to detect this is, thus, trap this alignment error
+ //
// and check the child entry
// still, we are left without a decompressed size, thus we have to figure
// out something for this
- // we'll do this by seeing if the misalignment is -4 and the previous entry
+ // we'll do this by seeing if the misalignment is -4 and the previous entry
+ //
// is a compressed image/model; if there are child entries, we'll check
// this instead of the previous entry
// obviously this isn't guaranteed to work in 100% of cases, but will get
{
uint32_t i, i2;
- // only fix refs if type is known, and not the main object(0x800)/anim(0x900)
+ // only fix refs if type is known, and not the main object(0x800)/anim(0x900)
+ //
// table
if (entry->type != 0 && entry->type <= (int) lenNum &&
lenArray[entry->type] != -1) {
uint32_t destSize = lenArray[entry->type] * sizeof (uint32_t);
if (isObj) {
- for (i = 0, i2 = 0; i < (uint32_t) RCO_OBJ_EXTRA_LEN[entry->type]; i++, i2++)
+ for (i = 0, i2 = 0; i < (uint32_t) RCO_OBJ_EXTRA_LEN[entry->type];
+ i++, i2++)
if (RCO_OBJ_IS_REF (entry->type, i2)) {
destSize -= sizeof (uint32_t) * 2; // size of ref source
destSize += sizeof (rRCORef);
} else {
/* if(RCO_ANIM_EXTRA_REFS[entry->type]) { destSize -= sizeof(uint32_t)*2;
* // size of ref source destSize += sizeof(rRCORef); } */
- for (i = 0, i2 = 0; i < (uint32_t) RCO_ANIM_EXTRA_LEN[entry->type]; i++, i2++)
+ for (i = 0, i2 = 0; i < (uint32_t) RCO_ANIM_EXTRA_LEN[entry->type];
+ i++, i2++)
if (RCO_ANIM_IS_REF (entry->type, i2)) {
destSize -= sizeof (uint32_t) * 2; // size of ref source
destSize += sizeof (rRCORef);
i++;
destPtr += sizeof (rRCORef);
} else {
- *(uint32_t *) destPtr = *(uint32_t *) ((uint8_t *) entry->extra + i * 4);
+ *(uint32_t *) destPtr =
+ *(uint32_t *) ((uint8_t *) entry->extra + i * 4);
destPtr += sizeof (uint32_t);
}
}
// memory compression thing
void *tables;
uint32_t tablesSize;
- uint32_t tablesBuffered; // internal value used for buffering, following
- // define is the amount to increase the buffer
- // by when necessary
+ uint32_t tablesBuffered; // internal value used for buffering, following
+ //
+ // define is the amount to increase the buffer
+ // by when necessary
#define RCO_WRITE_MEM_BUFFER 65536
uint32_t memPos;
uint32_t memOffset; // should always be 0xA4
void rco_fwrite (rRCOFile_writehelper * rcoH, void *buffer, uint32_t len);
void rcowrite_fseek (rRCOFile_writehelper * rcoH, uint32_t pos);
-uint32_t rco_write_resource (FILE * dest, rRCOEntry * entry, uint32_t destCompression,
- writerco_options * opts, rRCOFile * rco);
-uint32_t rco_write_text_resource (rRCOFile_writehelper * rcoH, rRCOEntry * entry,
- uint32_t destCompression, writerco_options * opts, uint32_t lang, uint8_t isLast);
+uint32_t rco_write_resource (FILE * dest, rRCOEntry * entry,
+ uint32_t destCompression, writerco_options * opts, rRCOFile * rco);
+uint32_t rco_write_text_resource (rRCOFile_writehelper * rcoH,
+ rRCOEntry * entry, uint32_t destCompression, writerco_options * opts,
+ uint32_t lang, uint8_t isLast);
void rco_write_fix_refs (rRCOEntry * parent, rRCOFile_writehelper * rcoH,
rRCOFile * rco, const int *lenArray, const int lenNum, uint8_t isObj);
(opts.packHeader == RCO_DATA_COMPRESSION_RLZ ? 0x95 : opts.packHeader ==
RCO_DATA_COMPRESSION_ZLIB ? 0x90 : 0x71);
if (rco->verId) { // we won't actually use specified value,
- // rather, we'll require using the minimum
- // version from above
+ // rather, we'll require using the minimum
+ // version from above
if (rco->verId > header.version)
header.version = rco->verId;
}
{ // write hashtable data
- /* { // special case for text hashes if(rco->numPtrText) { header.pTextPtrs
+ /* { // special case for text hashes if(rco->numPtrText) { header.pTextPtrs
* = rcowrite_ftell(&rcoH); for(i=0; i<rco->numPtrText; i++) { uint32_t
* writePtr = 0; if(rco->ptrText[i].textEntry && rco->ptrText[i].index)
* writePtr = rco->ptrText[i].textEntry->offset + sizeof(RCOEntry) +
header.lAnimPtrs =
write_hash_table (&rcoH, rco->tblAnim, rco) * sizeof (uint32_t);
}
- /*
+ /*
* #define RCO_WRITERCO_WRITE_PTR_SECT(pd, pl, hp) { \ if(pl) { \ hp =
* rcowrite_ftell(&rcoH); \ for(i=0; i<pl; i++) { \ if(pd[i]) \
* rco_fwrite(&rcoH, &(((rRCOEntry*)(pd[i]))->offset), sizeof(uint32_t)); \
}
{ // write label/event data (and text if
- // applicable)
+ // applicable)
// write text (note, old behaviour - newer RCOs have text written in a
// different location)
if (rco->eventsLen)
rco_fwrite (&rcoH, rco->events, rco->eventsLen);
else if (rco->tblObj || rco->tblAnim) { // weird case: if there's
- // object entries, there will
- // be 4 bytes for events; I'll
- // assume this covers anim as
- // well (although there isn't
- // an RCO with anim that
- // doesn't have objects)
+ // object entries, there will
+ // be 4 bytes for events; I'll
+ // assume this covers anim as
+ // well (although there isn't
+ // an RCO with anim that
+ // doesn't have objects)
uint32_t zero = 0;
rco_fwrite (&rcoH, &zero, sizeof (zero));
* uint32_t packedSize = rco_write_resource(&rcoH,
* &(rco->tblImage->subentries[i]), RCO_DATA_COMPRESSION_NONE); // TOxDO:
* change this // TOxDO: update packed size value uint32_t curFpos =
- * rcowrite_ftell(rcoH.fp);
- *
- * totalPackedLen += (packedSize % 4 ? (packedSize/4)*4+4 : packedSize); }
- * header.lImgData = totalPackedLen; }
- *
+ * rcowrite_ftell(rcoH.fp); totalPackedLen += (packedSize % 4 ?
+ * (packedSize/4)*4+4 : packedSize); } header.lImgData = totalPackedLen; }
* totalPackedLen = 0; if(rco->tblSound) { header.pSoundData =
* rcowrite_ftell(&rcoH); header.lSoundData = rcoH.sizeSound; for(i=0;
* i<rco->tblSound->numSubentries; i++) { totalPackedLen +=
* rco_write_resource(&rcoH, &(rco->tblSound->subentries[i]),
* RCO_DATA_COMPRESSION_NONE); if(totalPackedLen %4) totalPackedLen +=
- * 4-(totalPackedLen%4); } header.lSoundData = totalPackedLen; }
- *
- * // TOxDO: write model resources } */
+ * 4-(totalPackedLen%4); } header.lSoundData = totalPackedLen; } // TOxDO:
+ * write model resources } */
if ((rco->tblImage && rco->tblImage->numSubentries)
|| (rco->tblSound && rco->tblSound->numSubentries)
return TRUE;
}
-// returns next entry offset (like the length, but the last entry returns zero)
+// returns next entry offset (like the length, but the last entry returns zero)
+//
// - doesn't really have much meaning - it's primarily used for internal
// purposes
uint32_t
-write_entry (rRCOFile_writehelper * rcoH, rRCOEntry * entry, uint32_t parentOffset,
- uint32_t prevOffset, uint8_t isLastSubentry)
+write_entry (rRCOFile_writehelper * rcoH, rRCOEntry * entry,
+ uint32_t parentOffset, uint32_t prevOffset, uint8_t isLastSubentry)
{
uint32_t fPos = rcowrite_ftell (rcoH);
rti.offset = RCO_NULL_PTR;
else if (rti.length) {
if (rcoH->tables) // compressing - we need to make the offset
- // relative to the section of text data
+ // relative to the section of text data
rti.offset = rcoH->sizeText - entryTextOffset;
else
rti.offset = rcoH->sizeText;
- } else // TODO: experimental (it seems that Sony likes
- // sticking in a weird pointer for a blank text
- // entry)
+ } else // TODO: experimental (it seems that Sony likes
+ //
+ // sticking in a weird pointer for a blank text
+ // entry)
rti.offset = entryTextOffset - 1;
- rcoH->sizeText += rti.length; // doesn't have trailing null, so no +1
- // needed
+ rcoH->sizeText += rti.length; // doesn't have trailing null, so no +1
+ //
+ // needed
// align to 4 byte boundary
rcoH->sizeText = ALIGN_TO_4 (rcoH->sizeText);
uint32_t stuffToWrite[] = { 0, RCO_NULL_PTR };
uint32_t i;
- // actually, the following is unnecessary, but we'll keep it here for
+ // actually, the following is unnecessary, but we'll keep it here for
+ //
// reference sake
if (entry->rco->eSwap) {
stuffToWrite[0] = ENDIAN_SWAP (stuffToWrite[0]);
}
// returns the length of the packed data
-// TBH, I really can't be stuffed writing a buffered copy/compress/decompressor
+// TBH, I really can't be stuffed writing a buffered copy/compress/decompressor
+//
// (and anyway, it may not work with future compression routines, so meh)
uint32_t
rco_write_resource (FILE * dest, rRCOEntry * entry, uint32_t destCompression,
filewrite (dest, bufferOut, packedSize);
free (bufferOut);
- /*
+ /*
* char buffer[65536], outBuffer[65536]; uint32_t len=entry->srcLen; z_stream
* out; if(destStream == RCO_DATA_COMPRESSION_ZLIB) { ZLIB_INIT_DEFLATE(out,
* 9, Z_DEFAULT_STRATEGY); out.next_in = buffer; out.avail_in = 65536;
* out.next_out = outBuffer; out.avail_out = 65536; }
- *
+ *
* // copy with buffer while(len) { uint32_t readAmt = (len < 65536 ? len :
* 65536); if(!fileread(src, &buffer, readAmt)) { fclose(src); return FALSE;
* }
- *
+ *
* if(destCompression == RCO_DATA_COMPRESSION_NONE) filewrite(dest, &buffer,
* readAmt); else if(destCompression == RCO_DATA_COMPRESSION_ZLIB) {
- *
+ *
* }
- *
+ *
* len -= readAmt; }
- *
+ *
* // TOxDO: also don't forget to check lenUnpacked
- *
+ *
* fclose(src);
- *
+ *
* if(destStream == RCO_DATA_COMPRESSION_ZLIB) deflateEnd(&out); */
// 4byte alignment
uint32_t
rco_write_text_resource (rRCOFile_writehelper * rcoH, rRCOEntry * entry,
- uint32_t destCompression, writerco_options * opts, uint32_t lang, uint8_t isLast)
+ uint32_t destCompression, writerco_options * opts, uint32_t lang,
+ uint8_t isLast)
{
uint32_t len = 0;
if (entry->id == RCO_TABLE_OBJ)
num = count_all_subentries (entry);
// if(!rco->ps3)
- // interestingly, it seems that some PS3 RCOs do not round to an upper prime,
+ // interestingly, it seems that some PS3 RCOs do not round to an upper prime,
+ //
// but most do
num = find_larger_prime (num);
}
void
-do_hashing (rRCOEntry * entry, rRCOFile * rco, uint8_t recurse, uint32_t * hashTable,
- uint32_t hashTableSize)
+do_hashing (rRCOEntry * entry, rRCOFile * rco, uint8_t recurse,
+ uint32_t * hashTable, uint32_t hashTableSize)
{
if (entry->labelOffset != RCO_NULL_PTR) {
uint32_t *hashPtr =
typedef struct { // unk_421D80
unsigned char literals[8 * 0xFF]; // grouped in 8 groups of 0xFF; group
- // selected by has of input position,
- // last byte and mode, the 0xFF part is
- // based on the input byte with various
- // shifts
+ // selected by has of input position,
+ // last byte and mode, the 0xFF part is
+ // based on the input byte with various
+ // shifts
unsigned char distDescLong[0xF0]; // 30x8 (match >= 4)
unsigned char distDescShort[0x40]; // 8x8 (match < 4)
unsigned char distances[12 * 0x20]; // grouped in 0x20 based on bit
- // position
+ // position
unsigned char lenDesc[0x40]; // 8 x 8; group selected by bit position,
- // position is var_C from main function
+ // position is var_C from main function
unsigned char matchlens[0xFF];
void *input; // 0xCA8
// long dword_CB0; // 0xCB0 (0x422A30) - only wrtten to in sub_405810
// long dword_CB4; // 0xCB4
int64_t rangeOffset; // 0xCB0 (0x422A30) - only written to in
- // sub_405810(), affected by write_bit and
- // write_match_len
+ // sub_405810(), affected by write_bit and
+ // write_match_len
// - appears to be a data queue - top 24 bits not used, next 8 bits->data to
// be written, next 8 bits->data mask; affected by CB8 in some way (CB8 is
// added to this)
long rangeSize; // 0xCB8
char nextOutputByte; // 0xCBC - some byte offset; 3rd byte in CB0,
- // only ever used in sub_405810; guaranteed
- // never to == 0xFF
+ // only ever used in sub_405810; guaranteed
+ // never to == 0xFF
char bytesToWrite; // 0xCBD (0x422A3D) - only used in sub_405810
char writeLock; // 0xCBE - only ever used as a switch
char lastSearchBack; // 0xCBF - some byte flag used in find_match()
float sgl_120C84;
float sgl_120C88; // starts as 0.0625 and increments by that
- // amount every time the dictionary coder fails
- // to pack stuff
+ // amount every time the dictionary coder fails
+ // to pack stuff
} RLZ_Info; // about 1.128MB
RLZ_Info rlzip;
RLZ_Info *rlzi = &rlzip;
* Bits 45 determine the default values to store in literals/distances etc array
* The first 3 bits aren't used
*/
- int var_C = 0; // var_C appears to do some tracking in regards
- // to how well the dictionary coder is packing
- // things?
+ int var_C = 0; // var_C appears to do some tracking in regards
+
+ //
+ // to how well the dictionary coder is packing
+ // things?
char realMode;
int dictSearchBack = 0; // just assign something in case... :S
// write literal
// the following code was previously sub_405A10( (((((unsigned
// int)rlzi->inputpos & 7) << 8) | lastInputByte) >> realMode) & 7 )
- int arg_ecx = (((((unsigned int) rlzi->inputpos & 7) << 8) | lastInputByte) >> realMode) & 7; // top
- // bit
- // in
- // (rlzi->inputpos
- // &
- // 7)
- // will
- // actually
- // be
- // discarded
- // -
- // that
- // is,
- // (rlzi->inputpos
- // &
- // 3)
- // should
- // give
- // the
- // same
- // result
+ int arg_ecx = (((((unsigned int) rlzi->inputpos & 7) << 8) | lastInputByte) >> realMode) & 7; // top
+
+ //
+ // bit
+ // in
+ // (rlzi->inputpos
+ // &
+ // 7)
+ // will
+ // actually
+ // be
+ // discarded
+ // -
+ // that
+ // is,
+ // (rlzi->inputpos
+ // &
+ // 3)
+ // should
+ // give
+ // the
+ // same
+ // result
int oldRangeSize = rlzi->rangeSize;
unsigned int oldOutputpos = rlzi->outputpos;
unsigned int inputVal = *(unsigned char *) ABS_INPUT_POS + 0x100;
for (; !(inputVal & 0x10000); inputVal <<= 1) // loop 8 times
- write_bit ((unsigned char *) ((unsigned int) rlzi->literals + arg_ecx * 0xFF + (inputVal >> 8) - 1), (inputVal >> 7) & 1); // last
- // arg
- // (now
- // deleted)
- // is
- // actually
- // ebx,
- // but
- // ebx
- // is
- // 3
- // at
- // this
- // time
+ write_bit ((unsigned char *) ((unsigned int) rlzi->literals + arg_ecx * 0xFF + (inputVal >> 8) - 1), (inputVal >> 7) & 1); // last
+ //
+ // arg
+ // (now
+ // deleted)
+ // is
+ // actually
+ // ebx,
+ // but
+ // ebx
+ // is
+ // 3
+ // at
+ // this
+ // time
// these values are only ever used if realMode==7, and only in
// find_match() function
i = 0;
if ((searchBackPlus1 & 0xFFFFFFFE) > 0) // if searchBackPlus1 has bits
- // other than the first set...
- // (that is, searchBackPlus1 !=
- // 0 && searchBackPlus1 != 1)
+ // other than the first set...
+ // (that is, searchBackPlus1 !=
+ // 0 && searchBackPlus1 != 1)
{ // this condition _should_ always be true, as
- // min dictSearchBack is 1, and with +1, min
- // value for searchBackPlus1 is 2
+ // min dictSearchBack is 1, and with +1, min
+ // value for searchBackPlus1 is 2
// find the position of the most significant "1"
for (i = 2; (searchBackPlus1 >> i) > 0; i++) ;
sbSignifBit = --i; // put the bit position in ebp
int var_esi;
do { // write packed thing - perhaps a length of
- // next number descriptor?
+ // next number descriptor?
var_esi = ((sbSignifBit & var_edi) > 0 ? 1 : 0); // check if
- // certain bit
- // in ebp is
- // set
+ // certain bit
+ // in ebp is
+ // set
write_bit ((unsigned char *) ((unsigned int)
&treeStore[var_ebx * 8] + sub_405B90_ret), var_esi);
var_edi >>= 1;
if (matchLen < bytesLeftMinus3)
bytesLeftMinus3 = matchLen;
- for (i = 0; i < bytesLeftMinus3; i++) // goes thru all the bytes just
- // written and pushes some
- // things into the dictionary
+ for (i = 0; i < bytesLeftMinus3; i++) // goes thru all the bytes just
+ //
+ // written and pushes some
+ // things into the dictionary
{
unsigned int brHash = *(unsigned int *) (ABS_INPUT_POS + i) << 8;
rlzi->inputpos += matchLen;
lastInputByte = *(unsigned char *) (ABS_INPUT_POS - 1);
if (rlzi->outputpos == rlzi->inputlen) // is the compressed output
- // larger than the original
- // stream?
+ // larger than the original
+ // stream?
return -1;
}
write_match_len (0xFF, var_C); // end marker or is this used for
- // flushing data?
+ // flushing data?
{ // originally sub_4058E0()
i = (rlzi->writeLock ? 5 : 4);
// that keeps track of
// no. past blocks
// packed with
- // find_match() (always
+ // find_match() (always
+ //
// var_C from
// rlzcompress())
{
}
i--;
if (i > 0) // --> identical to if(len != 0); this will
- // only be true if len >= 1 (or len<0) - eg if
- // data was packed
+ // only be true if len >= 1 (or len<0) - eg if
+ // data was packed
{
i--;
unsigned char *ptr = rlzi->matchlens + ((arg_4 & 7) + i * 8) * 4;
rlzi->rangeOffset += rangeTmp;
}
}
- arg_edx += 3; // 2 (reverse previous subtraction), and +1 for
- // the above loop
+ arg_edx += 3; // 2 (reverse previous subtraction), and +1 for
+ //
+ // the above loop
rlzi->rangeSize = (long) rangeTmp;
write_output ();
}
// 0x00000000FF??????
if ((rlzi->rangeOffset >> 0x18) != 0xFF) {
unsigned char byteOut = rlzi->nextOutputByte; // starts off as 0,
- // then becomes 3rd
- // byte of
- // rlzi->rangeOffset
+
+ // then becomes 3rd
+ // byte of
+ // rlzi->rangeOffset
rlzi->nextOutputByte = (rlzi->rangeOffset >> 0x18) & 0xFF;
do {
}
// loc_4058A4:
rlzi->bytesToWrite++;
- // rlzi->rangeOffset = (arg_CB0 << 8) & 0xFFFFFFFF; // make sure high 32 bits
+ // rlzi->rangeOffset = (arg_CB0 << 8) & 0xFFFFFFFF; // make sure high 32 bits
+ //
// are 0
// rlzi->rangeSize = arg_CB8 << 8;
rlzi->rangeOffset <<= 8;
// sub_405CE0: arg_0 = buf
// this function determines how much data we can pack into a single byte
// return of 1 = can't compress; don't think this can return 0xFF or higher
-// NEW: this function searches for distance-length, but doesn't actually encode
+// NEW: this function searches for distance-length, but doesn't actually encode
+//
// anything
int
find_match (int *searchBackUsed, unsigned char realMode)
if (bytesLeft < 2)
return 1;
if (bytesLeft < 0xFF) // if we have less bytes left than the maximum
- // block size
+ // block size
maxBlockSize = bytesLeft;
- // realMode7Threshold = ((unsigned int)(rlzi->sgl_120C84 / rlzi->sgl_120C88 +
+ // realMode7Threshold = ((unsigned int)(rlzi->sgl_120C84 / rlzi->sgl_120C88 +
+ //
// 128.5) > 0x64); //dbl_41A3B8
// realMode7Threshold = ((int)((unsigned int)(rlzi->sgl_120C84 /
// rlzi->sgl_120C88 + 128.5)) > 0x64);
#define ROUND(n) ((int)((n) + 0.5))
realMode7Threshold = (ROUND (rlzi->sgl_120C84 / rlzi->sgl_120C88) > -28);
- // the second line above generates output consistent with the good rlzpacker,
+ // the second line above generates output consistent with the good rlzpacker,
+ //
// but is this typecasting all correct?
// check if we have a continuous copy of something
searchBack = ABS_INPUT_POS - rlzi->lastSearchBack; // byte_CBF only used
- // by find_match(); is
- // initially 0
+ // by find_match(); is
+ // initially 0
if ((unsigned int) rlzi->lastSearchBack < rlzi->inputpos &&
*(unsigned char *) (searchBack - 1) == *(unsigned char *) (ABS_INPUT_POS)
&& *(unsigned char *) (searchBack) ==
// loc_405DB7:
// if we have 2 bytes left in the buffer (remember, if there's 1 byte left,
// this function would've
- // already returned), we'll either by able to pack 1 or 2 bytes into a single
+ // already returned), we'll either by able to pack 1 or 2 bytes into a single
+ //
// byte
// We can pack 2 bytes into a byte if repeat bytes (above) have been found.
if (maxBlockSize < 3) {
// loc_405DC9:
// edx = ABS_INPUT_POS; - never actually read...
unsigned int brHash = *(unsigned int *) ABS_INPUT_POS << 8; // previously
- // eax
+
+ // eax
backRef = rlzi->window[(unsigned int) brHash % RLZI_WINDOW_SIZE];
while (backRef != -1) { // found a back reference
if (backRef < (int) (rlzi->inputpos - RLZI_DICTIONARY_SIZE - 1)) // is
- // the
- // backreference
- // out
- // of
- // bounds?
+ // the
+ // backreference
+ // out
+ // of
+ // bounds?
break;
unsigned int matchAmt = matchLen + 1;
if (*(unsigned char *) ((unsigned int) rlzi->input + backRef + i) !=
*(unsigned char *) (ABS_INPUT_POS + i))
goto loc_405F97; // jumps to end of while-loop (not valid -
- // search for more references which could be
- // valid)
+ // search for more references which could be
+ // valid)
}
// see how much more we can match
break;
}
i = rlzi->inputpos - backRef - 1; // distance? penalising short matches
- // which have a large distance??
+ // which have a large distance??
if (matchAmt >= 3 && (matchAmt != 3 || (i <= 0x7F && (i <= 0x30 ||
realMode != 5)))) {
tempCompare = 0;
// loc_405F60:
for (i = 3; i < matchAmt; i++) // loop max of 6 times due to
- // code below
+ // code below
{
if (i != 3 || (*searchBackUsed <= 0x7F &&
(*searchBackUsed <= 0x30 || realMode != 5))) {
return maxBlockSize;
// since maxBlockSize <= 0xFF, this implies maxBlockSize==0xFF
if (bytesLeft <= 0xFF) // if bytesLeft < 0xFF, then
- // maxBlockSize < 0xFF will be true
- // (enforced above), thus this line is
- // essentially "if(bytesLeft == 0xFF)"
+ // maxBlockSize < 0xFF will be true
+ // (enforced above), thus this line is
+ // essentially "if(bytesLeft == 0xFF)"
{
return 0xFD; // or 0x100 - 3
}
#define VAG_SIGNATURE 0x70474156
#define VAG_VERSION 0x4000000 // 0x2000000
PACK_STRUCT (VagHeader, {
- uint32_t signature; // "VAGp"
+ uint32_t signature; // "VAGp"
uint32_t version; // 0x20
- uint32_t reserved; // 0
- uint32_t dataSize; // size of file - 0x30
+ uint32_t reserved; // 0
+ uint32_t dataSize; // size of file - 0x30
uint32_t frequency;
uint8_t reserved2[12]; // 0
char name[16];
#define WAV_PCM_FORMAT 1
#define WAV_S2_SIG 0x61746164
PACK_STRUCT (WavHeader, {
- uint32_t signature; // "RIFF"
+ uint32_t signature; // "RIFF"
uint32_t size; // filesize - 8
uint32_t format; // "WAVE"
uint32_t s1sig; // "fmt "
uint32_t s1size; // 16 for PCM
- uint16_t audioFmt; // PCM = 1
+ uint16_t audioFmt; // PCM = 1
uint16_t channels;
uint32_t frequency;
- uint32_t byterate; // = frequency * channels * bitDepth/8
+ uint32_t byterate; // = frequency
+ // * channels *
+ // bitDepth/8
uint16_t sampleSize; // = channels * bitDepth / 8
- uint16_t bitDepth; // we'll always use 16
+ uint16_t bitDepth; // we'll always use 16
uint32_t s2sig; // "data"
uint32_t s2size; // = numSamples * channels * bitDepth/8 OR
- // size-36
+ // size-36
});
// TODO: sanity checks with lengths
// take a guess at the length (we'll fix these later if wrong) - make
// assumption that all channels are of same size
- wh.s2size = (((*vagLen - sizeof (VagHeader)) / sizeof (VagChunk)) - 1) * 28 /* samples
- */ * 2 /* 16bit */ * numChannels;
+ wh.s2size = (((*vagLen - sizeof (VagHeader)) / sizeof (VagChunk)) - 1) * 28 /* samples */ * 2 /* 16bit
+ */ * numChannels;
wh.size = wh.s2size + 28;
filewrite (fp, &wh, sizeof (wh));
// pack
// I don't understand it, but it seems that the second transformation is
- // required to prevent a clipping sound effect although it should produce
+ // required to prevent a clipping sound effect although it should produce
+ //
// worse reconverts...
int8_t outBuf[28];
/* { int samples[28]; // expand 4bit -> 8bit for(j=0; j<14; j++) {
* samples[j*2] = vc->s[j] & 0xF; samples[j*2+1] = (vc->s[j] & 0xF0) >>
* 4; } for(j=0; j<28; j++) { int s = samples[j] << 12; // shift 4 bits
- * to top range of int16_t if(s & 0x8000) s |= 0xFFFF0000; double sample =
- * (double)(s >> shift) + factors2[ch*2] * f[predict][0] +
+ * to top range of int16_t if(s & 0x8000) s |= 0xFFFF0000; double sample
+ * = (double)(s >> shift) + factors2[ch*2] * f[predict][0] +
* factors2[ch*2+1] * f[predict][1]; factors2[ch*2+1] = factors2[ch*2];
* factors2[ch*2] = sample; if(wavBuf[j*wh.channels + ch] !=
* (int16_t)ROUND(sample)) { printf("a"); } } } */
return wh.channels;
}
-/*
+/*
* int wav2vag(const char* fWav, uint32_t* len, void** vagData, const char*
* vagName) { FILE* fp = fopen(fWav, "rb"); if(!fp) return 0;
- *
+ *
* WavHeader wh; fileread(fp, &wh, sizeof(wh));
- *
+ *
* #define WAV2VAG_ERROR_EXIT(s) { \ error(s, fWav); \ fclose(fp); \ return 0;
* \ }
- *
+ *
* if(wh.signature != WAV_SIGNATURE || wh.format != WAV_FORMAT)
* WAV2VAG_ERROR_EXIT("File '%s' not a valid WAV file, conversion aborted.")
* if(wh.s1sig != WAV_S1_SIG || wh.s1size != WAV_S1_SIZE_PCM || wh.s2sig !=
* rcomage's VAG handler; conversion aborted.") if(wh.audioFmt !=
* WAV_PCM_FORMAT || wh.bitDepth != 16) WAV2VAG_ERROR_EXIT("rcomage's VAG
* handler only supports 16-bit PCM data, file '%s' not converted.")
- *
+ *
* if(wh.channels > 9) WAV2VAG_ERROR_EXIT("Channels number too high for '%s'.")
- *
- * //if(wh.s2size != wh.size-36 || wh.size+8 != filesize(fWav) || wh.sampleSize
+ *
+ * //if(wh.s2size != wh.size-36 || wh.size+8 != filesize(fWav) || wh.sampleSize
* != wh.channels*wh.bitDepth/8) // WAV2VAG_ERROR_EXIT("Bad size values in WAV
* header for '%s'.")
- *
- *
+ *
+ *
* int i, j, k; // size compression is 28 16-bit samples -> 16 bytes uint32_t
* numSamples = wh.s2size / wh.sampleSize; *len = (numSamples/28 + (numSamples
* % 28 ? 2:1)) * sizeof(VagChunk) + sizeof(VagHeader); *vagData = calloc(1,
* *len * wh.channels);
- *
+ *
* for(i=0; i<wh.channels; i++) { VagHeader* vh =
* (VagHeader*)((char*)(*vagData) + *len * i); vh->signature = VAG_SIGNATURE;
- * vh->version = VAG_VERSION; vh->reserved = 0; vh->dataSize = ENDIAN_SWAP(*len
+ * vh->version = VAG_VERSION; vh->reserved = 0; vh->dataSize = ENDIAN_SWAP(*len
* - 0x30); vh->frequency = ENDIAN_SWAP(wh.frequency); strncpy(vh->name,
* vagName, 16); }
- *
- * uint32_t pos; int wavBufSize = 28 * (wh.bitDepth/8) * wh.channels; int16_t* wavBuf
+ *
+ * uint32_t pos; int wavBufSize = 28 * (wh.bitDepth/8) * wh.channels; int16_t* wavBuf
* = (int16_t*)malloc(wavBufSize); double* factors =
* (double*)calloc(wh.channels*2, sizeof(double)); double* factors2 =
* (double*)calloc(wh.channels*2, sizeof(double)); for(pos=0; pos<numSamples;
* pos += 28) { if(!fileread(fp, wavBuf, wavBufSize)) { free(wavBuf);
- * free(factors); free(factors2); WAV2VAG_ERROR_EXIT("Premature end in WAV file
+ * free(factors); free(factors2); WAV2VAG_ERROR_EXIT("Premature end in WAV file
* '%s'; conversion failed.") }
- *
+ *
* uint32_t ch; for(ch=0; ch<wh.channels; ch++) { VagChunk* vc =
* (VagChunk*)((char*)(*vagData) + *len * ch + sizeof(VagHeader) +
* sizeof(VagChunk)*(pos/28));
- *
+ *
* // find_predict double min = 1e10; double predictBuf[5][28]; int predict,
* shift; double s1, s2; for(j=0; j<5; j++) { double max = 0; s1 =
* factors[ch*2]; s2 = factors[ch*2+1]; for(k=0; k<28; k++) { double sample =
* fabs(predictBuf[j][k]); s2 = s1; s1 = sample; } if(max < min) { min = max;
* predict = j; // ???? store s1 & s2 into temp place? } // ???? if(min <= 7) {
* predict = 0; break; } } // ???? factors[ch*2] = s1; factors[ch*2+1] = s2;
- *
+ *
* // find_shift uint32_t shiftMask; for(shift=0, shiftMask=0x4000; shift<12;
* shift++, shiftMask>>=1) { if(shiftMask & ((int)min + (shiftMask >> 3)))
* break; } // so shift==12 if none found...
- *
+ *
* vc->predict_shift = ((predict << 4) & 0xF0) | (shift & 0xF); vc->flags =
* (numSamples - pos >= 28 ? 0:1);
- *
+ *
* // pack uint8_t outBuf[28]; for(k=0; k<28; k++) { double sample =
* predictBuf[predict][k] - factors2[ch*2] * f[predict][0] - factors2[ch*2+1] *
* f[predict][1]; int sample2 = ((int)(sample * (1 << shift)) + 0x800) &
- * 0xfffff000; if(sample2 > 32767) sample2 = 32767; if(sample2 < -32768) sample2
+ * 0xfffff000; if(sample2 > 32767) sample2 = 32767; if(sample2 < -32768) sample2
* = -32768; outBuf[k] = (uint8_t)(sample2 >> 8); sample2 >>= shift;
* factors2[ch*2+1] = factors2[ch*2]; factors2[ch*2] = (double)sample2 - sample;
* } for(k=0; k<14; k++) vc->s[k] = (outBuf[k*2+1] & 0xF0) | ((outBuf[k*2] >> 4)
* & 0xF); } }
- *
+ *
* free(wavBuf); free(factors); free(factors2);
- *
+ *
* // put terminating chunk for(i=0; i<wh.channels; i++) { VagChunk* vc =
* (VagChunk*)((char*)(*vagData) + *len * (i+1) - sizeof(VagChunk));
* vc->predict_shift = 0; vc->flags = 7; memset(&vc->s, 0x77, 14); }
- *
+ *
* fclose(fp); return wh.channels; } */
#ifndef __VAGHANDLER__
#define __VAGHANDLER__
#include "general.h"
-uint8_t vag2wav (const char *fWav, int numChannels, int *vagLen, void **vagData);
-int wav2vag (const char *fWav, uint32_t * len, void **vagData, const char *vagName);
+uint8_t vag2wav (const char *fWav, int numChannels, int *vagLen,
+ void **vagData);
+int wav2vag (const char *fWav, uint32_t * len, void **vagData,
+ const char *vagName);
#endif
VID_OPERATOR_EQUAL = 0xe,
VID_OPERATOR_NOT_EQUAL = 0xf,
VID_OPERATOR_CASE_LABEL = 0x10, // same as VID_OPERATOR_EQUAL, just
- // used in switch statements
+ // used in switch statements
VID_OPERATOR_LT = 0x12,
VID_OPERATOR_LTE = 0x13,
VID_PROPERTY = 0x2f,
VID_METHOD = 0x30,
VID_UNK_31 = 0x31, // appears to be an object set; pops last two
- // items off the stack
+ // items off the stack
VID_UNSET = 0x32, // guess; looks like above, but only with one
- // item
+ // item
VID_ARRAY_INDEX = 0x34,
VID_ARRAY_ELEM = 0x38, // push something into array constant
VID_SECT_START = 0x39, // jump statement; can indicate end of
- // function, end of else/for, or return to
- // beginning of loop
+ // function, end of else/for, or return to
+ // beginning of loop
VID_JUMP_TRUE = 0x3a, // jump if previous value is true
VID_JUMP_FALSE = 0x3b,
VID_CALL_FUNC = 0x3c,
#define IS_WHITESPACE(x) (x == L'\t' || x == L' ' || x == L'\n' || x == L'\r')
while (*op && IS_WHITESPACE (*op))
op++;
- /* code is BAD - can remove stuff if in a string! // don't forget to remove
- * comments! tmp = op; while(*tmp) { if(*tmp == L';') { *tmp = L'\0';
- * break; } tmp++; } */
+ /* code is BAD - can remove stuff if in a string! // don't forget to remove
+ * comments! tmp = op; while(*tmp) { if(*tmp == L';') { *tmp = L'\0'; break;
+ * * } tmp++; } */
lineLen = wcslen (op);
while (lineLen && IS_WHITESPACE (op[lineLen - 1]))
lineLen--;
case VID_UNK_31:
CHECK_INDEX (in->numProp, "prop");
if (stack && stack->depth >= 1) { // TODO: this is really not
- // correct
+ // correct
VsmxDecompileStack *obj, *val;
val = VsmxDecompileStackPop (&stack);
} else {
// function start
- SWPRINTF (op, 50, L"%%ls { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
- // L"%s
- // {\n");
+ SWPRINTF (op, 50, L"%%ls { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
+ //
+ // L"%s
+ // {\n");
}
}
case VID_JUMP_FALSE:
if (in->code[in->code[i].val.u32 - 1].id == VID_SECT_START &&
in->code[in->code[i].val.u32 - 1].val.u32 == stmtStart) {
// while loop
- SWPRINTF (op, 50, L"while( %%s ) { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
- // L"while(
- // %s
- // )
- // {\n");
+ SWPRINTF (op, 50, L"while( %%s ) { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
+ //
+ // L"while(
+ // %s
+ // )
+ // {\n");
} else {
// if statement
if (stack->depth > endStmtConcat - 1) {
VsmxDecompMarkStackPush (&mStack, &mItem);
break;
} else {
- SWPRINTF (op, 50, L"if( %%s ) { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
- // L"if(
- // %s
- // )
- // {\n");
+ SWPRINTF (op, 50, L"if( %%s ) { /* ends at %d */\n", in->code[i].val.u32); // wcscpy(op,
+ //
+ // L"if(
+ // %s
+ // )
+ // {\n");
}
}
}
#define RCOXML_TABLE_2ND_DIM 20
typedef char ((*RcoTableMap)[RCOXML_TABLE_2ND_DIM]); // doesn't make
+
// sense... I want a
- // pointer to an array,
+ // pointer to an array,
+ //
// not an array of
// pointers...
extern RcoTableMap RCOXML_TABLE_DATA_COMPRESSION;
#define strtof(a,b) (float)strtod(a,b)
-/*
+/*
* typedef struct { rRCORef* ref; char* label; } xmlrco_read_fix_refs; */
typedef struct {
// xmlChar *ptrText, *ptrImg, *ptrSound, *ptrModel, *ptrObj, *ptrAnim;
uint8_t eventQuirk);
uint32_t rcoxml_add_label_reordering (char *newLabels, uint32_t * labelPos,
char *label);
-void rcoxml_reorder_labels (char *newLabels, uint32_t * labelPos, rRCOFile * rco,
- rRCOEntry * entry);
+void rcoxml_reorder_labels (char *newLabels, uint32_t * labelPos,
+ rRCOFile * rco, rRCOEntry * entry);
int label_reorder_qsort (const rRCOEntry ** a, const rRCOEntry ** b);
void parse_obj_extra (xmlNodePtr node, rRCOEntry * entry);
void parse_anim_extra (xmlNodePtr node, rRCOEntry * entry);
xmlNodePtr nodeChild;
if (bValidDoc) { // valid document must contain at least one
- // thing under RcoFile (MainTree)
+ // thing under RcoFile (MainTree)
nodeChild = node->xmlChildrenNode;
while (nodeChild->next && nodeChild->type != XML_ELEMENT_NODE)
nodeChild = nodeChild->next;
rco->eSwap = rco->ps3;
- /*
+ /*
* rco->tblMain.id = rco->tblMain.type = 0; rco->tblMain.labelOffset = 0;
* rco->tblMain.numSubentries = rco->tblMain.extraLen = 0; */
parse_entry (nodeChild, &(rco->tblMain), rco, &fixes);
- // TODO: ensure the first table _is_ the main table (and possibly then verify
+ // TODO: ensure the first table _is_ the main table (and possibly then verify
+ //
// tree structure)
// - post fixes -
&(entry->srcLen), compr) >= 2) {
entry->srcLen -= entry->srcAddr;
entry->srcLenUnpacked = entry->srcLen; // default - assume no
- // compression
+ // compression
if (compr[0]) {
// TODO: handle situations where uncompressed size is not
// specified
- if (sscanf (compr, ";zlib[%u]", &(entry->srcLenUnpacked)) == 1) { // TODO:
- // a
- // temporary
- // fix
- // (prolly
- // need
- // to
- // add
- // more
- // compression
- // algos,
- // since
- // sscanf
- // seems
- // to
- // be
- // rather
- // basic
- // in
- // retrieving
- // %s)
+ if (sscanf (compr, ";zlib[%u]", &(entry->srcLenUnpacked)) == 1) { // TODO:
+ //
+ // a
+ // temporary
+ // fix
+ // (prolly
+ // need
+ // to
+ // add
+ // more
+ // compression
+ // algos,
+ // since
+ // sscanf
+ // seems
+ // to
+ // be
+ // rather
+ // basic
+ // in
+ // retrieving
+ // %s)
rcoxml_text_to_int ("zlib", RCOXML_TABLE_DATA_COMPRESSION,
&(entry->srcCompression));
} else if (!strcmp (compr, ";rco")) {
xmlFree (src);
} else {
entry->srcAddr = 0;
- entry->srcLen = entry->srcLenUnpacked = filesize (entry->srcFile); // won't
- // work
- // if
- // filename
- // contains
- // a
- // '*'
+ entry->srcLen = entry->srcLenUnpacked = filesize (entry->srcFile); // won't
+ //
+ // work
+ // if
+ // filename
+ // contains
+ // a
+ // '*'
}
}
}
srcBufferTmp =
realloc (srcBufferTmp,
curPos + ALIGN_TO_4 (se->channelData[i * 2]));
- uint8_t *bufferPos = (uint8_t *) (srcBufferTmp) + curPos;
+ uint8_t *bufferPos =
+ (uint8_t *) (srcBufferTmp) + curPos;
fileread (fp, bufferPos, se->channelData[i * 2]);
fclose (fp);
if (fp) {
// do we have a BOM?
- unsigned char bom[4] = { 0x80, 0x80, 0x80, 0x80 }; // dummy
- // values
- // that
- // aren't
- // used
+ unsigned char bom[4] = { 0x80, 0x80, 0x80, 0x80 }; // dummy
+ //
+ // values
+ // that
+ // aren't
+ // used
char srcFmt[10] = "", destFmt[8];
uint32_t bom32le = UTF32_BOM;
uint32_t bom32be = ENDIAN_SWAP (UTF32_BOM);
* } if(te->indexes[i].length <= 2) { // this is
* probably blank te->indexes[i].length = 0; } else {
* srcBufferTmp = realloc(srcBufferTmp, curPos +
- * ALIGN_TO_4(te->indexes[i].length)); uint8_t* bufferPos
- * = (uint8_t*)srcBufferTmp + curPos; fileread(fp,
- * bufferPos, te->indexes[i].length-2); // add
- * terminating null & any necessary padding
+ * ALIGN_TO_4(te->indexes[i].length)); uint8_t*
+ * bufferPos = (uint8_t*)srcBufferTmp + curPos;
+ * fileread(fp, bufferPos, te->indexes[i].length-2); //
+ * add terminating null & any necessary padding
* memset(bufferPos + (te->indexes[i].length-2), 0,
* ALIGN_TO_4(te->indexes[i].length) -
* (te->indexes[i].length-2)); } */
// currently very basic - resize when adding a label
// uint32_t rcoxml_add_label(rRCOFile* rco, char* label) {
uint32_t
-rcoxml_add_label (char **labels, uint32_t * labelsLen, char *label, uint8_t eventQuirk)
+rcoxml_add_label (char **labels, uint32_t * labelsLen, char *label,
+ uint8_t eventQuirk)
{
// first, see if we already have this label
uint32_t p = 0;
return p; // found
p += strlen (*labels + p) + 1;
p = ALIGN_TO_4 (p); // urgh, this is kinda a little dirty, but it
- // works; if we hit a blank 4 bytes, the above
- // line will cause it to go forward by 1, this
- // will align it forward to 4, so, if we've hit
- // some nulls, we're effectively jumping 4
- // bytes at a time
+ // works; if we hit a blank 4 bytes, the above
+ // line will cause it to go forward by 1, this
+ // will align it forward to 4, so, if we've hit
+ // some nulls, we're effectively jumping 4
+ // bytes at a time
}
// don't have it? add it
uint32_t labelLen = strlen (label) + 1;
if (eventQuirk) {
- // TODO:
+ // TODO:
}
uint32_t newLen = curLen + labelLen;
}
*labelsLen = newLen;
- /*
- * uint32_t curLen = rco->labelsLen; uint32_t newLen = rco->labelsLen + strlen(label)
+ /*
+ * uint32_t curLen = rco->labelsLen; uint32_t newLen = rco->labelsLen + strlen(label)
* + 1;
- *
+ *
* rco->labels = (char*)realloc(rco->labels, newLen); strcpy(curLen, label);
* rco->labelsLen = newLen; */
return curLen;
return p; // found
p += strlen (newLabels + p) + 1;
p = ALIGN_TO_4 (p); // dirty, but it works (see note from
- // rcoxml_add_label)
+ // rcoxml_add_label)
}
// don't have it? add it
// work out the length of this thing, lol
entry->extraLen = RCO_OBJ_EXTRA_LEN[entry->type] * sizeof (uint32_t);
- for (i = 0, i2 = 0; i < (uint32_t) RCO_OBJ_EXTRA_LEN[entry->type]; i++, i2++) {
+ for (i = 0, i2 = 0; i < (uint32_t) RCO_OBJ_EXTRA_LEN[entry->type];
+ i++, i2++) {
if (RCO_OBJ_IS_REF (entry->type, i2)) {
entry->extraLen -= 2 * sizeof (uint32_t);
entry->extraLen += sizeof (rRCORef);
warning
("[line %d] Unable to parse reference '%s' - defaulting to 'nothing'.",
node->line, (char *) val);
- /*
+ /*
* // we really need to fix refs after all entries are loaded - I'm
- * going to be lazy here since we can't actually do anything terribly
+ * going to be lazy here since we can't actually do anything terribly
* useful right now ((rRCORef*)extra)->type = RCO_REF_NONE;
* add_ref_to_fix(fixes, , (rRCORef*)extra); */
} else {
// work out the length of this thing, lol
entry->extraLen = RCO_ANIM_EXTRA_LEN[entry->type] * sizeof (uint32_t);
- for (i = 0, i2 = 0; i < (uint32_t) RCO_ANIM_EXTRA_LEN[entry->type]; i++, i2++) {
+ for (i = 0, i2 = 0; i < (uint32_t) RCO_ANIM_EXTRA_LEN[entry->type];
+ i++, i2++) {
if (RCO_ANIM_IS_REF (entry->type, i2)) {
entry->extraLen -= 2 * sizeof (uint32_t);
entry->extraLen += sizeof (rRCORef);
warning
("[line %d] Unable to parse reference '%s' - defaulting to 'nothing'.",
node->line, (char *) val);
- /*
+ /*
* // we really need to fix refs after all entries are loaded - I'm
- * going to be lazy here since we can't actually do anything terribly
+ * going to be lazy here since we can't actually do anything terribly
* useful right now ((rRCORef*)extra)->type = RCO_REF_NONE;
* add_ref_to_fix(fixes, , (rRCORef*)extra); */
} else {
}
}
-/*
+/*
* void parse_anim_extra(xmlNodePtr node, rRCOEntry* entry) {
- *
+ *
* if(entry->type <= RCO_ANIM_EXTRA_LEN_NUM && RCO_ANIM_EXTRA_LEN[entry->type]
* != -1) { uint32_t i = 0;
- *
- * entry->extraLen = 0; for(i=0, i2=0; i<(uint32_t)RCO_ANIM_EXTRA_LEN[entry->type];
+ *
+ * entry->extraLen = 0; for(i=0, i2=0; i<(uint32_t)RCO_ANIM_EXTRA_LEN[entry->type];
* i++, i2++) { if(RCO_ANIM_IS_REF(entry->type, i2)) { entry->extraLen +=
* sizeof(rRCORef); i++; } else entry->extraLen += sizeof(uint32_t); }
- *
+ *
* //if(RCO_ANIM_EXTRA_REFS[entry->type]) { // entry->extraLen =
* (RCO_ANIM_EXTRA_LEN[entry->type]-2) * sizeof(uint32_t) + sizeof(rRCORef); //}
* else { // entry->extraLen = RCO_ANIM_EXTRA_LEN[entry->type] *
* sizeof(uint32_t); //}
- *
+ *
* entry->extra = malloc(entry->extraLen); uint8_t* extra = (uint8_t*)entry->extra;
* memset(extra, 0, entry->extraLen);
- *
+ *
* uint32_t entryLen = (uint32_t)RCO_ANIM_EXTRA_LEN[entry->type];
- *
- * if(RCO_ANIM_EXTRA_REFS[entry->type]) { xmlChar* val = NULL; if(entry->type ==
+ *
+ * if(RCO_ANIM_EXTRA_REFS[entry->type]) { xmlChar* val = NULL; if(entry->type ==
* RCO_ANIM_TYPE_EVENT) val = xmlGetProp(node, _X("event")); else val =
* xmlGetProp(node, _X("object"));
- *
+ *
* if(val) { if(!rcoxml_parse_ref((char*)val, (rRCORef*)extra)) warning("[line
* %d] Unable to parse object reference '%s' - defaulting to 'nothing'.",
* node->line, (char*)val); } else { warning("[line %d] No object/event defined
* for anim entry. Defaulting to nothing.", node->line); // blank ref rRCORef*
- * dr = ((rRCORef*)extra); dr->type = RCO_REF_NONE; dr->ptr = NULL; dr->rawPtr =
+ * dr = ((rRCORef*)extra); dr->type = RCO_REF_NONE; dr->ptr = NULL; dr->rawPtr =
* RCO_NULL_PTR; } extra += sizeof(rRCORef); entryLen -=2; }
- *
+ *
* for(i=0; i<entryLen; i++) { xmlChar* val = NULL;
* if(RCO_ANIM_EXTRA_NAMES[entry->type][i][0]) { val = xmlGetProp(node,
* _X(RCO_ANIM_EXTRA_NAMES[entry->type][i])); } if(!val) { val =
* rcoxml_get_unknown_attrib(node, i); }
- *
+ *
* if(!val) { if(RCO_ANIM_EXTRA_NAMES[entry->type][i][0]) { warning("[line %d]
* Missing attribute '%s', defaulting to 0 / nothing.", node->line,
* RCO_ANIM_EXTRA_NAMES[entry->type][i]); } else { warning("[line %d] Missing
* attribute (index %d), defaulting to 0 / nothing.", node->line, i); // TODO:
* better message } *(uint32_t*)extra = 0; } else { *(uint32_t*)extra =
* rcoxml_parse_value((char*)val); xmlFree(val); }
- *
+ *
* extra += sizeof(uint32_t); } } else { // TODO: handle unknown types } } */
// TODO: this somewhat mixes normal vals with refs (not optimal) - may wish to
if (out->type == RCO_REF_NONE) { // not assigned by above ifs
if (sscanf (val, "unknown%i", (int *) &(out->type))) { // this is
- // actually
- // case
- // sensitive...
- // :|
+ // actually
+ // case
+ // sensitive...
+ // :|
out->rawPtr = strtol (colon, NULL, 10);
return TRUE;
} else {
return TRUE;
}
-/*
+/*
* // a very simple resize method :/ void add_ref_to_fix(rcoxml_read_fixes*
* fixes, char* label, rRCORef* ref) { fixes->refs =
* (xmlrco_read_fix_refs*)realloc(fixes->refs, sizeof(xmlrco_read_fix_refs) *
* (fixes->refCnt+1)); xmlrco_read_fix_refs* fr =
* &(fixes->refs[fixes->refsCnt]);
- *
- * fr->ref = ref; fr->label = (char*)malloc(strlen(label)+1); strcpy(fr->label,
+ *
+ * fr->ref = ref; fr->label = (char*)malloc(strlen(label)+1); strcpy(fr->label,
* label);
- *
+ *
* fixes->refsCnt++; } */
void
} else
extra += sizeof (uint32_t);
}
- /*
+ /*
* if(entry->id == RCO_TABLE_OBJ) { for(i=0, i2=0;
* (int)i<RCO_OBJ_EXTRA_LEN[entry->type]; i++, i2++) {
* if(RCO_OBJ_IS_REF(entry->type, i2)) { rcoxml_fix_ref((rRCORef*)extra,
* rco); extra += sizeof(rRCORef); i++; } else extra += sizeof(uint32_t); }
- *
+ *
* } else { // anim entries if(RCO_ANIM_EXTRA_REFS[entry->type]) {
* rcoxml_fix_ref((rRCORef*)extra, rco); } } */
}
uint32_t i;
- /*
+ /*
* for(i=0; i<textLen; i++) if(tmpText[i] == ',') { (*sectCnt)++; tmpText[i]
* = '\0'; } */
*sectCnt = split_comma_list (tmpText);
if (s[i] == ',') {
cnt++;
s[i] = '\0';
- } // else if(s[i] == '\t' || s[i] == '\r' || s[i]
- // == '\n' || s[i] == ' ') // whitespace
+ } // else if(s[i] == '\t' || s[i] == '\r' || s[i]
+ //
+ // == '\n' || s[i] == ' ') // whitespace
// s[i] = '\0';
return cnt;
memcpy (newStrPtr, prevP, p - prevP);
newStrPtr += p - prevP;
}
- /*
- * newStrPtr[0] = '%'; newStrPtr[1] = '1'; newStrPtr[2] = '$'; newStrPtr[3]
+ /*
+ * newStrPtr[0] = '%'; newStrPtr[1] = '1'; newStrPtr[2] = '$'; newStrPtr[3]
* = type; newStrPtr += 4; */
newStrPtr[0] = '%';
newStrPtr[1] = type;
te->indexes[i].length =
(xmlUTF8Strlen (n) + 1 /* null */ ) * charWidth;
if ((*(uint32_t *) n & 0xFFFFFF) == UTF8_BOM) { // fix for
- // older
- // versions of
- // rcomage - if
- // BOM exists,
- // reduce
- // length by 1
- // char
+ // older
+ // versions of
+ // rcomage - if
+ // BOM exists,
+ // reduce
+ // length by 1
+ // char
te->indexes[i].length -= charWidth;
}
}
iconv (ic, (char **) (&n), (size_t *) (&contentLen), &tbPtr,
(size_t *) (&outBufLen));
if (outBufLen && outBufLen == charWidth) { // *should*
- // always be
- // true
+ // always be
+ // true
memset (tbPtr, 0,
ALIGN_TO_4 (te->indexes[i].length) -
(te->indexes[i].length - outBufLen));
#define IMP(a,b) (!(a) || (b)) // logical implication, ie, a implies b
-void xmlwrite_entry (rRCOEntry * entry, uint32_t depth, rRCOFile * rco, FILE * fp,
- char *textDir, uint8_t textXmlOut, int sndDumped, uint8_t vsmxConv);
+void xmlwrite_entry (rRCOEntry * entry, uint32_t depth, rRCOFile * rco,
+ FILE * fp, char *textDir, uint8_t textXmlOut, int sndDumped,
+ uint8_t vsmxConv);
void xmlwrite_entry_extra_object (uint16_t type, uint8_t * info, rRCOFile * rco,
FILE * fp);
void xmlwrite_entry_extra_anim (uint16_t type, uint8_t * info, rRCOFile * rco,
sprintf (tagName, "Unknown_0x%x_0x%x", entry->id, entry->type);
}
- /*
+ /*
* switch(entry->id) { case RCO_TABLE_MAIN: strcpy(tagName, "Main"); break;
* case RCO_TABLE_IMG: strcpy(tagName, "Image"); break; case RCO_TABLE_SOUND:
* strcpy(tagName, "Sound"); break; case RCO_TABLE_MODEL: strcpy(tagName,
* RCO_TABLE_ANIM: if(entry->type <= RCO_ANIM_EXTRA_LEN_NUM) { char*
* animTags[] = {"Anim", "Animation", "Move", "ColourChange", "Rotate",
* "Resize", "Fade", "Delay", "FireEvent", "Lock", "Unlock", "UnknownB"};
- * tagName = animTags[entry->type]; } else sprintf(tagName, "AnimUnknown0x%x",
+ * tagName = animTags[entry->type]; } else sprintf(tagName, "AnimUnknown0x%x",
* entry->type); break; } */
for (i = 0; i < depth; i++)
}
// extra attribs
if (isMainTable) {
- /*
+ /*
* // pointer ordering uint32_t numPtrs = 0; void* ptrs; switch(entry->id) {
* case RCO_TABLE_TEXT: ptrs = rco->ptrText; numPtrs = rco->numPtrText;
* break; case RCO_TABLE_IMG: ptrs = rco->ptrImg; numPtrs = rco->numPtrImg;
* break; case RCO_TABLE_SOUND: ptrs = rco->ptrSound; numPtrs =
* rco->numPtrSound; break; case RCO_TABLE_MODEL: ptrs = rco->ptrModel;
* numPtrs = rco->numPtrModel; break; case RCO_TABLE_OBJ: ptrs =
- * rco->ptrObj; numPtrs = rco->numPtrObj; break; case RCO_TABLE_ANIM: ptrs =
+ * rco->ptrObj; numPtrs = rco->numPtrObj; break; case RCO_TABLE_ANIM: ptrs =
* rco->ptrAnim; numPtrs = rco->numPtrAnim; break; } if(numPtrs) { uint32_t j;
* fputs(" ptrorder=\"", fp); for(i=0; i<numPtrs; i++) { if(i) fputs(",",
* fp);
- *
+ *
* fputc('\n', fp); for(j=0; j<depth+2; j++) fputc('\t', fp);
- *
+ *
* // special case for text if(entry->id == RCO_TABLE_TEXT) {
- * rRCOTextIdxPtr* tip = &(((rRCOTextIdxPtr*)ptrs)[i]); if(tip->textEntry &&
+ * rRCOTextIdxPtr* tip = &(((rRCOTextIdxPtr*)ptrs)[i]); if(tip->textEntry &&
* tip->index) { char tmp[30];
* rcoxml_int_to_text(((rRCOTextEntry*)tip->textEntry->extra)->lang,
* RCOXML_TABLE_TEXT_LANG, tmp); fprintf(fp, "%s:%s", tmp, rco->labels +
return; // TODO: handle unknown object types?
for (i = 0, i2 = 0; i < numEntries; i++, i2++) { // i2 doesn't include
- // the position entry,
- // plus doesn't
- // increase twice for a
- // reference
+ // the position entry,
+ // plus doesn't
+ // increase twice for a
+ // reference
// is this entry a reference?
uint8_t isRef = RCO_OBJ_IS_REF (type, i2);
fputs ("\"", fp);
if (isRef)
i++; // need to do this since the tables consider
- // refs to take two entries
+ // refs to take two entries
}
}
void
-xmlwrite_entry_extra_anim (uint16_t type, uint8_t * info, rRCOFile * rco, FILE * fp)
+xmlwrite_entry_extra_anim (uint16_t type, uint8_t * info, rRCOFile * rco,
+ FILE * fp)
{
int numEntries = RCO_ANIM_EXTRA_LEN[type];
return; // TODO: handle unknown object types?
for (i = 0, i2 = 0; i < numEntries; i++, i2++) { // i2 doesn't include
- // the position entry,
- // plus doesn't
- // increase twice for a
- // reference
+ // the position entry,
+ // plus doesn't
+ // increase twice for a
+ // reference
// is this entry a reference?
uint8_t isRef = RCO_ANIM_IS_REF (type, i2);
fputs ("\"", fp);
if (isRef)
i++; // need to do this since the tables consider
- // refs to take two entries
+ // refs to take two entries
}
}
-/*
+/*
* void xmlwrite_entry_extra_anim(uint16_t type, uint8_t* info, rRCOFile* rco,
* FILE* fp) { int numEntries = RCO_ANIM_EXTRA_LEN[type]; int i;
- *
+ *
* if(numEntries < 1) return; // TODO: handle unknown anim types?
- *
+ *
* // TODO: this method makes the number following unknown tag names disregard
* the reference (should fix this) if(RCO_ANIM_EXTRA_REFS[type]) { if(type ==
* RCO_ANIM_TYPE_EVENT) fputs(" event=\"", fp); else fputs(" object=\"", fp);
* xml_fputref((rRCORef*)info, rco, fp); fputs("\"", fp);
- *
+ *
* info += sizeof(rRCORef); numEntries -= 2; }
- *
- * for(i=0; i<numEntries; i++) { fputc(' ', fp); // do we have a label for this
+ *
+ * for(i=0; i<numEntries; i++) { fputc(' ', fp); // do we have a label for this
* thing? if(RCO_ANIM_EXTRA_NAMES[type][i][0]) {
* fputs(RCO_ANIM_EXTRA_NAMES[type][i], fp); } else { fputs("unknown", fp);
* switch(RCO_ANIM_EXTRA_TYPES[type][i]) { case RCO_OBJ_EXTRA_TYPE_FLOAT:
* fputs("Float", fp); break; case RCO_OBJ_EXTRA_TYPE_INT: fputs("Int", fp);
* break; } fprintf(fp, "%d", i); } fputs("=\"", fp);
- *
+ *
* if(RCO_ANIM_EXTRA_TYPES[type][i] == RCO_OBJ_EXTRA_TYPE_FLOAT) fprintf(fp,
* "%g", *(float*)info); else fprintf(fp, "0x%x", *(uint32_t*)info);
- *
+ *
* info += sizeof(uint32_t); // or sizeof(float)
- *
+ *
* fputs("\"", fp); } } */
void
fputs (((rRCOEntry *) (ref->ptr))->labelOffset + rco->labels, fp);
else
fputs ("", fp); // TODO: handle situations where there isn't a
- // label...
+ // label...
}
}