void ReadGameConfig(FILE *f) { use_offside = fread_u8(f); training = fread_u8(f); arcade = fread_u8(f); arcade_teams = fread_u8(f); free_longpass = fread_u8(f); injuries = fread_u8(f); bookings = fread_u8(f); substitutions = fread_u8(f); newchange = fread_u8(f); newpitches = fread_u8(f); detail_level = fread_u32(f); team_a = fread_u8(f); team_b = fread_u8(f); field = fread_u8(f); strictness = fread_u8(f); fread_data(&player_type, sizeof(player_type), f); current_field = fread_u8(f); fread_data(&shirt, sizeof(shirt), f); fread_data(&palette, sizeof(palette), f); fread_data(&fieldname, sizeof(fieldname), f); time_length = fread_u32(f); }
int DecodePDBJumpTable( struct JumpTable* jumpTable, uint16_t numRecs, FILE* fp) { int i = 0; for (i = 0;i < numRecs;i++) { jumpTable[i].offset = fread_u32(fp); fread_blob(jumpTable[i].reserved, 4, fp); } #ifdef PDB_DEBUG for (i = 0;i < numRecs;i++) { printf("header->jumpTable[%02d] = 0x%08lx\n", i, jumpTable[i].offset); } #endif return 0; }
/////////////////////////////////////////////////////////////////////////////// //Local PDB decode interface define int DecodePDBHeader(struct PDBHeader* header, FILE* fp) { //Fill pdb header fread_blob(header->fileName, 32, fp); header->fileAttributes = fread_u16(fp); header->versionNumber = fread_u16(fp); header->createDate = fread_u32(fp); header->modificationDate = fread_u32(fp); header->lastBackupDate = fread_u32(fp); header->modificationNumber = fread_u32(fp); header->appInfoArea = fread_u32(fp); header->sortInfoArea = fread_u32(fp); fread_blob(header->dataBaseType, 4, fp); fread_blob(header->creatorID, 4, fp); fread_blob(header->uniqueIDSeed, 4, fp); header->nextRecord = fread_u32(fp); header->numRecs = fread_u16(fp); #ifdef PDB_DEBUG //Debug info printf("header->FileName : %s\n", header->fileName); printf("header->DatabaseType: "); printf_string(header->dataBaseType, 4); printf("\n"); printf("header->CreatorID : "); printf_string(header->creatorID, 4); printf("\n"); printf("header->NumRecs : 0x%02x\n",header->numRecs); #endif return 0; }
int DecodeBibleBookDetailInfo( struct BookDetailInfo* bookDetailInfo, FILE* fp) { int i = 0; uint16_t numChapters = 0; uint32_t lastVerseNumber = 0; //Read number of chapters bookDetailInfo->numChapters = fread_u16(fp); #ifdef PDB_DEBUG printf("bookDetailInfo.numChapters : %d\n", bookDetailInfo->numChapters); #endif //Read last verse number table numChapters = bookDetailInfo->numChapters; bookDetailInfo->lastVerseNumber = (uint16_t*)malloc(sizeof(uint16_t) * numChapters); if (bookDetailInfo->lastVerseNumber == NULL) { MSG_MALLOC_FAIL(bookDetailInfo->lastVerseNumber); return -1; } else { for (i = 0;i < numChapters;i++) { bookDetailInfo->lastVerseNumber[i] = fread_u16(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.lastVerseNumber : ...\n"); #endif } //Read chapter offset table bookDetailInfo->chapterOffset = (uint32_t*)malloc(sizeof(uint32_t) * numChapters); if (bookDetailInfo->chapterOffset == NULL) { free(bookDetailInfo->lastVerseNumber); bookDetailInfo->lastVerseNumber = NULL; MSG_MALLOC_FAIL(bookDetailInfo->chapterOffset); return -1; } else { for (i = 0;i < numChapters;i++) { bookDetailInfo->chapterOffset[i] = fread_u32(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.chapterOffset : ...\n"); #endif } //Read verse offset table lastVerseNumber = bookDetailInfo->lastVerseNumber[numChapters - 1]; bookDetailInfo->verseOffset = (uint16_t*)malloc(sizeof(uint16_t) * lastVerseNumber); if (bookDetailInfo->verseOffset == NULL) { free(bookDetailInfo->lastVerseNumber); bookDetailInfo->lastVerseNumber = NULL; free(bookDetailInfo->chapterOffset); bookDetailInfo->chapterOffset = NULL; MSG_MALLOC_FAIL(bookDetailInfo->verseOffset); return -1; } else { for (i = 0;i < lastVerseNumber;i++) { bookDetailInfo->verseOffset[i] = fread_u16(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.verseOffset : ...\n"); #endif } return 0; }
cop_font * parse_font( FILE * in_file, char const * in_name ) { /* The cop_font instance. */ cop_font * out_font = NULL; /* Used to acquire string attributes. */ uint8_t length; char * string_ptr = NULL; /* Used to acquire numeric attributes. */ uint16_t designator; /* Used to acquire the CharacterDescriptionBlock. */ uint8_t * byte_ptr = NULL; uint8_t data_count; uint16_t i; uint8_t intrans_flag; uint8_t * outtrans_data = NULL; uint8_t outtrans_data_size; uint8_t outtrans_flag; outtrans_block * outtrans_ptr = NULL; translation * translation_ptr = NULL; uint8_t * translation_start = NULL; uint8_t uint8_array[0x100]; uint16_t uint16_array[0x100]; uint8_t width_data_size; uint8_t width_flag; uint32_t * width_ptr; size_t size; /* Used for count and other values. */ uint8_t count8; /* Ensure in_name contains a value. */ if( in_name == NULL || (length = strlen( in_name )) == 0 ) return( out_font ); /* Initialize the out_font. */ out_font = mem_alloc( START_SIZE ); out_font->next_font = NULL; out_font->allocated_size = START_SIZE; out_font->next_offset = sizeof( cop_font ); /* Note: The various pointers must be entered, initially, as offsets * and then converted to pointers before returning because out_font * may be reallocated at any point and that invalidates actual pointers. */ /* Incorporate the defined name. */ length++; if( OUT_FONT_EXPAND_CHK( length ) ) { out_font = resize_cop_font( out_font, length ); } out_font->defined_name = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); strcpy( string_ptr, in_name ); OUT_FONT_ADD_OFF( length ); /* Get the font_out_name1. */ length = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( length > 0 ) { if( OUT_FONT_EXPAND_CHK( length + 1 ) ) { out_font = resize_cop_font( out_font, length + 1 ); } out_font->font_out_name1 = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); fread_buff( string_ptr, length, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } string_ptr[length] = '\0'; OUT_FONT_ADD_OFF( length + 1 ); } else { out_font->font_out_name1 = NULL; } /* Get the font_out_name2. */ length = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( length > 0 ) { if( OUT_FONT_EXPAND_CHK( length + 1 ) ) { out_font = resize_cop_font( out_font, length + 1 ); } out_font->font_out_name2 = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); fread_buff( string_ptr, length, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } string_ptr[length] = '\0'; OUT_FONT_ADD_OFF( length + 1 ); } else { out_font->font_out_name2 = NULL; } /* Get the designator and ensure it is 0x1D00. */ designator = fread_u16( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( designator != 0x1D00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the line_height. */ out_font->line_height = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the line_space. */ out_font->line_space = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_basis. */ out_font->scale_basis = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_min. */ out_font->scale_min = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_max. */ out_font->scale_max = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the char_width. */ out_font->char_width = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the CharacterDescriptionBlock. */ /* Get the size_flag, which is not needed. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data_count and the flags. */ width_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } data_count = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } outtrans_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } intrans_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the IntransBlock, if present. */ if( intrans_flag == 0 ) { out_font->intrans = NULL; } else { /* Get the designator and verify it contains 0x81. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( count8 != 0x81 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the count and verify that it contains 0x00. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data into the array. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->intrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->intrans->table ) ); } out_font->intrans = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); fread_buff( byte_ptr, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } OUT_FONT_ADD_OFF( sizeof( out_font->intrans->table ) ); } /* Get the OuttransBlock, if present. */ if( outtrans_flag == 0 ) { out_font->outtrans = NULL; } else { /* Get the next byte, which indicates the OuttransBlock data size. */ /* The name of the variable does not match the Wiki. */ outtrans_data_size = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Read the count. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* The file is positioned at the start of the data. */ /* Note: each translation is added individually; however, taken * together, they constitute the field "translations" in the Wiki. */ switch( outtrans_data_size) { case 0x81: /* The count should be 0x00. */ if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data into the local buffer. */ fread_buff( uint8_array, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Reserve space for the outtrans_block. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->outtrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->outtrans->table ) ); } out_font->outtrans = OUT_FONT_CUR_OFF(); outtrans_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->outtrans->table ) ); /* Build the actual table, which requires actual pointers in * place of the offsets recorded in *out_font: * outtrans_ptr is the pointer version of out_font->outtrans. * for each iteration: * translation_ptr is the pointer version of * outtrans->ptr->table[i]. * byte_ptr is the pointer version of * translation_ptr->ptr.data. */ for( i = 0; i < 0x100; i++ ) { /* If the first byte matches the index, there is no translation. */ if( uint8_array[i] == i) { outtrans_ptr->table[i] = NULL; } else { /* Reserve space for the translation. */ if( OUT_FONT_EXPAND_CHK( sizeof( translation ) ) ) { out_font = resize_cop_font( out_font, sizeof( translation ) ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); } outtrans_ptr->table[i] = OUT_FONT_CUR_OFF(); /* Get the translation for the current character. */ translation_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( translation ) ); /* The translation always contains exactly one character. */ size = 1; if( OUT_FONT_EXPAND_CHK( size ) ) { out_font = resize_cop_font( out_font, size ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); translation_ptr = OUT_FONT_MAP_OFF( outtrans_ptr->table[i] ); } translation_ptr->count = size; translation_ptr->data = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( size ); /* The translation character is the value in the input array. */ *byte_ptr = uint8_array[i]; } } break; case 0x82: /* The count should be equal to the data_count. */ if( count8 != data_count ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the outtrans array into the local array. */ for( i = 0; i < 0x100; i++ ) { uint16_array[i] = fread_u16( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Allocate a buffer and read the translation characters into it. */ outtrans_data = mem_alloc( data_count ); fread_buff( outtrans_data, data_count, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( outtrans_data ); outtrans_data = NULL; mem_free( out_font ); out_font = NULL; return( out_font ); } /* Initialize outtrans_ptr and the outtrans pointer in out_font. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->outtrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->outtrans->table ) ); } out_font->outtrans = OUT_FONT_CUR_OFF(); outtrans_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->outtrans->table ) ); translation_start = NULL; /* Convert the data in uint16_array to our format, which requires * actual pointers in place of the offsets recorded in *out_font: * outtrans_ptr is the pointer version of out_font->outtrans. * for each iteration: * translation_ptr is the pointer version of * outtrans->ptr->table[i]. * byte_ptr is the pointer version of * translation_ptr->ptr.data. */ for( i = 0; i < 0x100; i++ ) { /* If the first byte matches the index, there is no translation. */ if( uint16_array[i] == i) { outtrans_ptr->table[i] = NULL; } else { /* Reserve space for the translation. */ if( OUT_FONT_EXPAND_CHK( sizeof( translation ) ) ) { out_font = resize_cop_font( out_font, sizeof( translation ) ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); } outtrans_ptr->table[i] = OUT_FONT_CUR_OFF(); /* Get the translation for the current character. */ translation_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( translation ) ); /* If the first byte at uint16_array[i] is 00, then the * second byte is the one-byte translation. Otherwise, the * second byte is an offset. For little-endian computers, * at least! */ /* Set the count correctly. */ if( (uint16_array[i] & 0xff00) == 0 ) { size = 1; } else { translation_start = outtrans_data + (uint16_array[i] & 0x00ff); size = *translation_start++; } /* Allocate space and perform other common operations. */ if( OUT_FONT_EXPAND_CHK( size ) ) { out_font = resize_cop_font( out_font, size ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); translation_ptr = OUT_FONT_MAP_OFF( outtrans_ptr->table[i] ); } translation_ptr->count = size; translation_ptr->data = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( size ); /* Put the data into the buffer. */ if( (uint16_array[i] & 0xff00) == 0x00 ) { *byte_ptr = (uint16_array[i] & 0x00ff); } else { memcpy( byte_ptr, translation_start, size ); } } } mem_free( outtrans_data ); outtrans_data = NULL; break; default: mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Get the WidthBlock, if present. */ if( width_flag != 0 ) { out_font->width = NULL; } else { /* Reserve the space for width. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->width->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->width->table ) ); } out_font->width = OUT_FONT_CUR_OFF(); width_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->width->table ) ); /* Get the designator, which indicates the WidthBlock data size. */ /* The variable name does not match the field name in the Wiki. */ width_data_size = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* This byte's value is checked below. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* The file is now positioned at the start of the data. */ switch ( width_data_size ) { case 0x81: /* The WidthBlock has one-byte elements. */ /* The count should be 0x00. */ if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the width data array into an array of bytes. * It cannot be read in directly because the field is * an array of uint32_t entries. */ fread_buff( uint8_array, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Copy the data into the cop_font instance. */ for( i = 0; i < 0x100; i++ ) { width_ptr[i] = uint8_array[i]; } break; case 0x84: /* The WidthBlock has four-byte elements. */ /* The count should be 0x01. */ if( count8 != 0x01 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the width data array directly into the cop_font instance. */ for( i = 0; i < 0x100; i++ ) { width_ptr[i] = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } } break; default: mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Convert non-NULL offsets to pointers. */ if( out_font->defined_name != NULL ) { OUT_FONT_REMAP_MBR( defined_name ); } if( out_font->font_out_name1 != NULL ) { OUT_FONT_REMAP_MBR( font_out_name1 ); } if( out_font->font_out_name2 != NULL ) { OUT_FONT_REMAP_MBR( font_out_name2 ); } if( out_font->intrans != NULL ) { OUT_FONT_REMAP_MBR( intrans ); } if( out_font->outtrans != NULL ) { OUT_FONT_REMAP_MBR( outtrans ); for( i = 0; i < sizeof( outtrans_block ) / sizeof( translation * ); i++ ) { if( out_font->outtrans->table[i] != NULL ) { OUT_FONT_REMAP_MBR( outtrans->table[i] ); if( out_font->outtrans->table[i]->data != NULL ) { OUT_FONT_REMAP_MBR( outtrans->table[i]->data ); } } } } if( out_font->width != NULL ) { OUT_FONT_REMAP_MBR( width ); } return( out_font ); }