static id0_boolean_t LoadObject(BE_FILE_T file, objtype *o) { id0_int_t dummy; // for active enum (anonymous type) id0_int_t activeint; // BACKWARD COMPATIBILITY id0_longword_t statedosfarptr; // Just tells if "o->next" is zero or not id0_int_t isnext; // Now reading size_t BE_Cross_read_classtype_From16LE(BE_FILE_T fp, classtype *ptr); size_t BE_Cross_read_dirtype_From16LE(BE_FILE_T fp, dirtype *ptr); if ((BE_Cross_readInt16LE(file, &o->ticcount) != 2) || (BE_Cross_readInt32LE(file, &statedosfarptr) != 4) // BACKWARD COMPATIBILITY || (BE_Cross_readInt32LE(file, &o->x) != 4) || (BE_Cross_readInt32LE(file, &o->y) != 4) || (BE_Cross_readInt16LE(file, &o->viewx) != 2) || (BE_Cross_readInt16LE(file, &o->tilex) != 2) || (BE_Cross_readInt16LE(file, &o->tiley) != 2) || (BE_Cross_readInt16LE(file, &o->viewheight) != 2) || (BE_Cross_readInt16LE(file, &o->size) != 2) // No need to read prev pointer as-is, // this is ignored on loading. So read dummy value. // Furthermore, all we need to know about next on loading is // if it's zero or not. || (BE_Cross_readInt16LE(file, &isnext) != 2) // next || (BE_Cross_readInt8LEBuffer(file, &dummy, 2) != 2) // prev // || (BE_Cross_readInt16LE(file, &activeint) != 2) || (BE_Cross_read_classtype_From16LE(file, &o->obclass) != 2) || (BE_Cross_readInt8LE(file, &o->flags) != 1) || (BE_Cross_readInt8LE(file, &dummy) != 1) // Padding due to word alignment in original code || (BE_Cross_readInt32LE(file, &o->distance) != 4) || (BE_Cross_read_dirtype_From16LE(file, &o->dir) != 2) || (BE_Cross_readInt16LE(file, &o->angle) != 2) || (BE_Cross_readInt16LE(file, &o->hitpoints) != 2) || (BE_Cross_readInt32LE(file, &o->speed) != 4) || (BE_Cross_readInt32LE(file, &o->xl) != 4) || (BE_Cross_readInt32LE(file, &o->xh) != 4) || (BE_Cross_readInt32LE(file, &o->yl) != 4) || (BE_Cross_readInt32LE(file, &o->yh) != 4) || (BE_Cross_readInt16LE(file, &o->temp1) != 2) || (BE_Cross_readInt16LE(file, &o->temp2) != 2) ) { return false; } o->active = (activetype)activeint; o->state = RefKeen_GetObjStatePtrFromDOSPointer(statedosfarptr); // HACK: All we need to know is if next was originally NULL or not o->next = isnext ? o : NULL; return true; }
static id0_boolean_t LoadGameState(BE_FILE_T file, gametype *state) { return ((BE_Cross_readInt16LE(file, &state->worldx) == 2) && (BE_Cross_readInt16LE(file, &state->worldy) == 2) && (BE_Cross_read_booleans_From16LEBuffer(file, state->leveldone, 2*sizeof(state->leveldone)/sizeof(id0_boolean_t)) == 2*sizeof(state->leveldone)/sizeof(id0_boolean_t)) && (BE_Cross_readInt32LE(file, &state->score) == 4) && (BE_Cross_readInt32LE(file, &state->nextextra) == 4) && (BE_Cross_readInt16LE(file, &state->flowerpowers) == 2) && (BE_Cross_readInt16LE(file, &state->boobusbombs) == 2) && (BE_Cross_readInt16LE(file, &state->bombsthislevel) == 2) && (BE_Cross_readInt16LE(file, &state->keys) == 2) && (BE_Cross_readInt16LE(file, &state->mapon) == 2) && (BE_Cross_readInt16LE(file, &state->lives) == 2) && (BE_Cross_readInt16LE(file, &state->difficulty) == 2) ); }
static id0_boolean_t LoadGameState(BE_FILE_T file, gametype *state) { id0_longword_t padding; // Two bytes of struct tail padding for 2015 port return ((BE_Cross_readInt16LE(file, &state->worldx) == 2) && (BE_Cross_readInt16LE(file, &state->worldy) == 2) && (((refkeen_current_gamever != BE_GAMEVER_KDREAMS2015) && (BE_Cross_read_booleans_From16LEBuffer(file, state->leveldone, 2*sizeof(state->leveldone)/sizeof(id0_boolean_t)) == 2*sizeof(state->leveldone)/sizeof(id0_boolean_t))) || ((refkeen_current_gamever == BE_GAMEVER_KDREAMS2015) && (BE_Cross_read_booleans_From32LEBuffer(file, state->leveldone, 4*sizeof(state->leveldone)/sizeof(id0_boolean_t)) == 4*sizeof(state->leveldone)/sizeof(id0_boolean_t))) ) && (BE_Cross_readInt32LE(file, &state->score) == 4) && (BE_Cross_readInt32LE(file, &state->nextextra) == 4) && (BE_Cross_readInt16LE(file, &state->flowerpowers) == 2) && (BE_Cross_readInt16LE(file, &state->boobusbombs) == 2) && (BE_Cross_readInt16LE(file, &state->bombsthislevel) == 2) && (BE_Cross_readInt16LE(file, &state->keys) == 2) && (BE_Cross_readInt16LE(file, &state->mapon) == 2) && (BE_Cross_readInt16LE(file, &state->lives) == 2) && (BE_Cross_readInt16LE(file, &state->difficulty) == 2) && (((refkeen_current_gamever != BE_GAMEVER_KDREAMS2015) || (BE_Cross_readInt16LE(file, &padding) == 2))) ); }
static id0_boolean_t LoadGameState(BE_FILE_T file, gametype *state) { return ((BE_Cross_readInt16LE(file, &state->difficulty) == 2) && (BE_Cross_readInt16LE(file, &state->mapon) == 2) && (BE_Cross_readInt16LE(file, &state->bolts) == 2) && (BE_Cross_readInt16LE(file, &state->nukes) == 2) && (BE_Cross_readInt16LE(file, &state->potions) == 2) && (BE_Cross_readInt16LEBuffer(file, state->keys, sizeof(state->keys)) == sizeof(state->keys)) && (BE_Cross_readInt16LEBuffer(file, state->scrolls, sizeof(state->scrolls)) == sizeof(state->scrolls)) && (BE_Cross_readInt32LE(file, &state->score) == 4) && (BE_Cross_readInt16LE(file, &state->body) == 2) && (BE_Cross_readInt16LE(file, &state->shotpower) == 2) ); }
//-------------------------------------------------------------------------- // BLoad() -- THIS HAS NOT BEEN FULLY TESTED! // // NOTICE : This version of BLOAD is compatable with JAMPak V3.0 and the // new fileformat... //-------------------------------------------------------------------------- id0_unsigned_long_t BLoad(const id0_char_t *SourceFile, memptr *DstPtr) { BE_FILE_T handle; memptr SrcPtr; //id0_unsigned_long_t i, j, k, r, c; //id0_word_t flags; id0_byte_t Buffer[8]; id0_unsigned_long_t SrcLen,DstLen; struct CMP1Header CompHeader; id0_boolean_t Compressed = false; memset((void *)&CompHeader,0,sizeof(struct CMP1Header)); // // Open file to load.... // if (!BE_Cross_IsFileValid(handle = BE_Cross_open_for_reading(SourceFile))) //if ((handle = open(SourceFile, O_RDONLY|O_BINARY)) == -1) return(0); // // Look for JAMPAK headers // BE_Cross_readInt8LEBuffer(handle,Buffer,4); //read(handle,Buffer,4); if (!strncmp((char *)Buffer,COMP,4)) { // // Compressed under OLD file format // Compressed = true; SrcLen = Verify(SourceFile); BE_Cross_readInt32LE(handle, &CompHeader.OrginalLen); //read(handle,(void *)&CompHeader.OrginalLen,4); CompHeader.CompType = ct_LZW; MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else if (!strncmp((char *)Buffer,CMP1,4)) { // // Compressed under new file format... // Compressed = true; SrcLen = Verify(SourceFile); BE_Cross_readInt8LEBuffer(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); //read(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); // REFKEEN - Big Endian support #ifdef REFKEEN_ARCH_BIG_ENDIAN CompHeader.CompType = BE_Cross_Swap16LE(CompHeader.CompType); CompHeader.OrginalLen = BE_Cross_Swap32LE(CompHeader.OrginalLen); CompHeader.CompressLen = BE_Cross_Swap32LE(CompHeader.CompressLen); #endif MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else DstLen = Verify(SourceFile); // // Load the file in memory... // if (Compressed) { DstLen = CompHeader.OrginalLen; // REFKEEN - Looks like this is an unsigned comparison in original EXE if (((id0_unsigned_long_t)MM_TotalFree() < SrcLen) && (CompHeader.CompType)) { if (!InitBufferedIO(handle,&lzwBIO)) Quit("No memory for buffered I/O."); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: //lzwDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); lzwDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: //lzhDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); lzhDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } FreeBufferedIO(&lzwBIO); } else { // REFKEEN - Better close the current file handle before re-opening here BE_Cross_close(handle); // CA_LoadFile(SourceFile,&SrcPtr); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: //lzwDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); lzwDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: //lzhDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); lzhDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } MM_FreePtr(&SrcPtr); // REFKEEN - File handle already closed return(DstLen); } } else { // REFKEEN - Again we close the current file handle first, then load and finally return DstLen without re-closing file handle BE_Cross_close(handle); CA_LoadFile(SourceFile,DstPtr); return(DstLen); } BE_Cross_close(handle); return(DstLen); }