SpellBookModel::SpellBookModel() { spells_ = ParseSpellBook(ReadInFile(GetJSonPath())); //std::sort(spells_.begin(), spells_.end(), SpellSchoolDescending); //SortBySpellName(true); //SortBySpellLevel(true); //SortBySpellSchool(true); //class_filter_.SetFilter("Warlock"); //school_filter_.SetFilter("Evocation"); //school_filter_.RemoveFilter("Evocation"); //level_filter_.SetFilter("1st-level"); //level_filter_.SetFilter("2nd-level"); //level_filter_.SetFilter("3rd-level"); //auto t = GetSpells(); //for (auto const& s : t) //print_spell_breed(s); //{ //break; //print_spell_breed(s); //std::cout << s.school << std::endl; //} }
void PortraitInit(){ // replaces sub_41EB40 // init new portraits in sprite table // note: game crashes for id > 0x7F int id = 0x3F; // entry index in heads.db for( int i = X_PORTRAIT_FIRST; i <= X_PORTRAIT_LAST; i++ ){ SpriteTable[ i ].loaded_index = id++; } memset( Loaded_Portrait_Array, 0xFF, sizeof(Loaded_Portrait_Array) ); char* fname = GetGameDirStr( "[PORTRAIT]\\script\\heads.db" ); heads_db = ReadInFile( fname ); *((DWORD*)0x00533B54) = (DWORD) &Loaded_Portrait_Array; *((BYTE*)0x004D5BD4) = 1; // g_IsPortraitInit *((DWORD*)0x00533B28) = ((DWORD)heads_db) + 1; *((DWORD*)0x004D5BC8) = 0; // timer }
int FilePacker::PackFile( const char* InFilename, const char* PackFilename, bool Compress ) { m_InFileSize = FileUtil::Size( InFilename ); ReadInFile( FileStream( InFilename, FileStream::EFM_Read ) ); if( FileUtil::Exists( PackFilename ) ) { ReadPackFile( FileStream( PackFilename, FileStream::EFM_Read ) ); } else { m_Header.m_MagicID = 'KPCD'; m_Header.m_NumFiles = 0; m_Header.m_OffsetToFiles = 0; // Fix up just before writing m_Header.m_FilesSize = 0; } AddInFile( InFilename, Compress ); WritePackFile( FileStream( PackFilename, FileStream::EFM_Write ) ); return 0; }
static void BuildLists( void ) //================================ { int index; group_list *curr_group; int group; msg_list *prev_msg; msg_list *msg_ptr; msg_list *last_non_null_msg; msg_list **p_null_msg; msg_word *word; int caret; char rec[BUFF_LEN+1]; char msg_used_at; char msg_compiler; char msg_target; char delim; fprintf( ErrCod, "#define NO_CARROT 0\n" ); fprintf( ErrCod, "#define OPR_CARROT 1\n" ); fprintf( ErrCod, "#define OPN_CARROT 2\n" ); fprintf( RCFile, "#include \"errcod.h\"\n\n" ); fprintf( RCFile, "STRINGTABLE\nBEGIN\n\n" ); group = 0; curr_group = NULL; ReadInFile( rec ); prev_msg = NULL; last_non_null_msg = NULL; for( ;; ) { if( HeadGroup == NULL ) { HeadGroup = malloc( sizeof( group_list ) ); curr_group = HeadGroup; } else { curr_group->link = malloc( sizeof( group_list ) ); curr_group = curr_group->link; } curr_group->link = NULL; curr_group->start_msg_num = group * 256; curr_group->end_msg_num = curr_group->start_msg_num; curr_group->name[0] = rec[0]; curr_group->name[1] = rec[1]; curr_group->name[2] = NULLCHAR; for( ;; ) { if( ReadInFile( rec ) != 0 ) { fprintf( RCFile, "\nEND\n" ); return; } ++RecNum; if( ( strlen( rec ) > 2 ) && ( rec[2] == ' ' ) ) // Group record break; index = 3; while( rec[index] != ' ' ) { ++index; } // End of message ID rec[index] = '\0'; ++index; ++index; // skip [ if( rec[index] != sw_language ) continue; ++index; msg_compiler = rec[index]; ++index; msg_target = rec[index]; ++index; msg_used_at = rec[index]; ++index; caret = rec[index] - '0'; ++index; ++index; // skip ] msg_ptr = InitMsg(); if( UseMessage( msg_compiler, msg_target, msg_used_at ) ) { // proccess message text AddWords( msg_ptr, &rec[index] ); } msg_ptr->caret = caret; if( msg_ptr->msg != NULL ) { fprintf( ErrCod, "#define %s %d\n", rec, curr_group->end_msg_num ); fprintf( RCFile, " %s+MSG_LANG_BASE \"", rec ); delim = ' '; for( word = msg_ptr->msg; word != NULL; word = word->link ) { if( word->link == NULL ) { delim = '"'; } fprintf( RCFile, "%s%c", word->word->word, delim ); } fprintf( RCFile, "\n" ); last_non_null_msg = msg_ptr; } curr_group->end_msg_num++; if( HeadMsg == NULL ) { HeadMsg = msg_ptr; } else { prev_msg->link = msg_ptr; } prev_msg = msg_ptr; } prev_msg = last_non_null_msg; if( last_non_null_msg == NULL ) { p_null_msg = &HeadMsg; } else { p_null_msg = &last_non_null_msg->link; } while( *p_null_msg != NULL ) { msg_ptr = (*p_null_msg)->link; free( *p_null_msg ); curr_group->end_msg_num--; *p_null_msg = msg_ptr; } ++group; } }
void Load() { // parse text file std::string path = darkomen::modmenu::getCurrentModPath(); if (path.empty()) { return; } path += "\\PRG_ENG\\xslots.txt"; if( 0xFFFFFFFF == getFileAttributes_orig( path.c_str() ) ) return; char* readbuf = ReadInFile( path.c_str() ); if( readbuf == NULL ) return; char* text = readbuf; int line = 1; while( *text != '\0' ) { // temp vars DWORD slot_id; char buf[ 12 ]; DWORD len; DWORD required_len; // scan till some content is found SkipWhiteSpaceAndComments( text ); if( *text == '\r' ) text++; if( *text == '\n' ){ text++; line++; continue; } // required_len = ReadOutWord( buf, sizeof(buf), text, &len ); if( ( required_len > sizeof(buf) ) || ( required_len <= 1 ) ){ Log( "xslot: Error ( line %d )", line ); goto the_end; } text += len; SkipWhiteSpaceAndComments( text ); // slot_id = ReadOutInteger( text, &len ); if( len == 0 ){ Log( "xslot: Error expected slot_id ( line %d )", line ); goto the_end; } text += len; SkipWhiteSpaceAndComments( text ); // if( 0 == strcmp( buf, "SPRITE" ) ){ if( slot_id > ( X_SPRITE_LAST - X_SPRITE_FIRST ) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_SPRITE_LAST - X_SPRITE_FIRST ), line ); goto the_end; } SPRITE_SLOT* p = &SpriteTable[ slot_id + X_SPRITE_FIRST ]; // required_len = ReadOutWord( p->name, sizeof(p->name), text, &len ); if( required_len > sizeof(p->name) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "sprite_file_name", sizeof(p->name), line ); goto the_end; } if( len == 0 ){ continue; } text += len; SkipWhiteSpaceAndComments( text ); // DWORD off = ReadOutInteger( text, &len ); text += len; if( len == 0 ){ Log( "xslot: Error missing sprite_type_offset ( line %d )", line ); goto the_end; } if( ( off > 0x0000023E ) || ( ( off % 0x000000E ) != 0 ) ){ Log( "xslot: Error invalid value (0x%08X) for sprite_type_offset ( line %d )", off, line ); goto the_end; } p->type_id = 8; // troop sprite offset_table[ slot_id + X_SPRITE_FIRST ] = (WORD)off; } else { if( 0 == strcmp( buf, "NAME" ) ){ if( slot_id > ( X_NAME_LAST - X_NAME_FIRST ) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_NAME_LAST - X_NAME_FIRST ), line ); goto the_end; } required_len = ReadOutWord( &x_names[slot_id][0], 64, text, &len ); if( len == 0 ){ continue; } text += len; if( required_len > 64 ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "name", 64, line ); goto the_end; } unit_name[ slot_id + X_NAME_FIRST ] = &x_names[slot_id][0]; } else { if( 0 == strcmp( buf, "BANNER" ) ){ if( slot_id > ( X_BANNER_LAST - X_BANNER_FIRST ) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_BANNER_LAST - X_BANNER_FIRST ), line ); goto the_end; } SPRITE_SLOT* p = &SpriteTable[ slot_id + X_BANNER_FIRST ]; // required_len = ReadOutWord( p->name, sizeof(p->name), text, &len ); if( required_len > sizeof(p->name) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "sprite_file_name", sizeof(p->name), line ); goto the_end; } if( len == 0 ){ continue; } text += len; SkipWhiteSpaceAndComments( text ); // DWORD shape = ReadOutInteger( text, &len ); if( len == 0 ){ Log( "xslot: Error missing banner_shape_id ( line %d )", line ); goto the_end; } text += len; p->banner_bkgrnd_id = shape; } else { if( 0 == strcmp( buf, "BOOK" ) ){ if( slot_id > ( X_BOOK_LAST - X_BOOK_FIRST ) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_BOOK_LAST - X_BOOK_FIRST ), line ); goto the_end; } // troop_book_banner_index[ slot_id + X_BOOK_FIRST ] = (char) ReadOutInteger( text, &len ); if( len == 0 ){ continue; } text += len; SkipWhiteSpaceAndComments( text ); // required_len = ReadOutWord( 0, 0, text, &len ); if( len == 0 ){ Log( "xslot: Error missing leader_pic ( line %d )", line ); } troop_book_leader_pic[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len ); if( troop_book_leader_pic[ slot_id + X_BOOK_FIRST ] == NULL ){ Log( "xslot: Alloc Failed ( line %d )", line ); goto the_end; } ReadOutWord( troop_book_leader_pic[ slot_id + X_BOOK_FIRST ], required_len, text, &len ); text += len; SkipWhiteSpaceAndComments( text ); // required_len = ReadOutWord( 0, 0, text, &len ); if( len == 0 ){ Log( "xslot: Error missing troop_pic ( line %d )", line ); goto the_end; } troop_book_unit_pic[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len ); if( troop_book_unit_pic[ slot_id + X_BOOK_FIRST ] == NULL ){ Log( "xslot: Alloc Failed ( line %d )", line ); goto the_end; } ReadOutWord( troop_book_unit_pic[ slot_id + X_BOOK_FIRST ], required_len, text, &len ); text += len; SkipWhiteSpaceAndComments( text ); // required_len = ReadOutWord( 0, 0, text, &len ); if( len == 0 ){ Log( "xslot: Error missing troop_desc ( line %d )", line ); goto the_end; } troop_book_unit_desc[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len ); if( troop_book_unit_desc[ slot_id + X_BOOK_FIRST ] == NULL ){ Log( "xslot: Alloc Failed ( line %d )", line ); goto the_end; } ReadOutWord( troop_book_unit_desc[ slot_id + X_BOOK_FIRST ], required_len, text, &len ); text += len; } else{ if( 0 == strcmp( buf, "PORTRAIT" ) ){ if( slot_id > ( X_PORTRAIT_LAST - X_PORTRAIT_FIRST ) ){ Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_PORTRAIT_LAST - X_PORTRAIT_FIRST ), line ); goto the_end; } DWORD m3d_id = ReadOutInteger( text, &len ); if( len == 0 ){ Log( "xslot: Error expected m3d_id ( line %d )", line ); goto the_end; } text += len; SPRITE_SLOT* p = &SpriteTable[ slot_id + X_PORTRAIT_FIRST ]; p->loaded_index = m3d_id; } else { Log( "xslot: Error unrecognized command \"%s\" ( line %d )", buf, line ); goto the_end; } } } } } } // while // copy original data in from the game executable memcpy( SpriteTable, (void*)0x004CEB50, 257 * sizeof( SPRITE_SLOT ) ); memcpy( offset_table, (void*)0x004EBC88, 96 * sizeof( WORD ) ); memcpy( unit_name, (void*)0x004E2640, 0x50 * sizeof( char* ) ); memcpy( troop_book_unit_pic, (void*)0x004C0940, 0x50 * sizeof( char* ) ); memcpy( troop_book_leader_pic, (void*)0x004C0A80, 0x50 * sizeof( char* ) ); memcpy( troop_book_unit_desc, (void*)0x004E2780, 0x50 * sizeof( char* ) ); memcpy( troop_book_banner_index, (void*)0x004C0BC0, 0x50 * sizeof( char ) ); // install hooks HOOK_CALL( &ReferencedPortraits, 0x00401C8A ); HOOK_CALL( &ReferencedPortraits, 0x00401E21 ); HOOK_CALL( PortraitShutdown, 0x0042A3C6 ); HOOK_CALL( PortraitInit, 0x00428A1F ); *((BYTE*)0x0041EE08) = 0x7F; // override max head_db entries (0x3F) *((BYTE*)0x0041EC9B) = 0x7F; // override max head_db entries (0x3F) WRITE_JMP( GetType, 0x004184B0 ); WRITE_JMP( AddRef, 0x004184D0 ); WRITE_JMP( Release, 0x004184F0 ); WRITE_JMP( ZeroRef, 0x00418510 ); WRITE_JMP( GetLoadedIndex, 0x00418540 ); WRITE_JMP( LoadReferencedSprites, 0x0042B510 ); WRITE_JMP( LoadedSpriteArrayUnloaded, 0x0042B600 ); WRITE_JMP( LoadReferencedBanners, 0x0042B9E0 ); *((SPRITE_SLOT**)0x004018DF) = &SpriteTable[ PORTRAIT_FIRST ]; // sub_4018A0 ( PortraitsInit ) *((SPRITE_SLOT**)0x00401910) = &SpriteTable[ PORTRAIT_LAST ]; // sub_4018A0 ( PortraitsInit ) *((DWORD**)0x0041D3A5) = &(SpriteTable[0].loaded_index); // sub_41D360 ( WHMTG_SpeakNoWait ) *((DWORD**)0x0042459C) = &(SpriteTable[0].loaded_index); // sub_424530 ( ?? ) *((DWORD**)0x0042BD81) = &(SpriteTable[0].loaded_index); // sub_42BCC0 ( ?? ) *((DWORD**)0x0042BEDD) = &(SpriteTable[0].loaded_index); // sub_42BCC0 ( ?? ) *((DWORD**)0x0042E238) = &(SpriteTable[0].loaded_index); // sub_42E1E0 ( ?? ) *((DWORD**)0x0042B705) = &(SpriteTable[0].loaded_index); // sub_42B6A0 ( ?? ) *((WORD**) 0x0047FE01) = offset_table; // sub_47FDF0 ( get sprite type info by id...? ) *((DWORD*)0x00526D24) = (DWORD)&Loaded_Sprite_Array; *((DWORD*)0x00526D2C) = (DWORD)&Loaded_Banner_Array; *((DWORD*)0x00409F11) = (DWORD)troop_book_unit_pic; *((DWORD*)0x00409F52) = (DWORD)troop_book_unit_pic; *((DWORD*)0x0040C0CC) = (DWORD)troop_book_unit_pic; *((DWORD*)0x0040C108) = (DWORD)troop_book_unit_pic; *((DWORD*)0x00409DE3) = (DWORD)troop_book_leader_pic; *((DWORD*)0x0040BD24) = (DWORD)troop_book_leader_pic; *((DWORD*)0x00409EC2) = (DWORD)unit_name; *((DWORD*)0x0040B876) = (DWORD)unit_name; *((DWORD*)0x0040BE4A) = (DWORD)unit_name; *((DWORD*)0x0040C20F) = (DWORD)unit_name; *((DWORD*)0x0040C461) = (DWORD)unit_name; *((DWORD*)0x0040D213) = (DWORD)unit_name; *((DWORD*)0x0040D9C3) = (DWORD)unit_name; *((DWORD*)0x0041985C) = (DWORD)unit_name; *((DWORD*)0x0041A5E4) = (DWORD)unit_name; *((DWORD*)0x0041B1B0) = (DWORD)unit_name; *((DWORD*)0x0041B4CA) = (DWORD)unit_name; *((DWORD*)0x0042671A) = (DWORD)unit_name; *((DWORD*)0x004286E1) = (DWORD)unit_name; *((DWORD*)0x00409E63) = (DWORD)troop_book_unit_desc; *((DWORD*)0x0040BDE0) = (DWORD)troop_book_unit_desc; *((DWORD*)0x004099B5) = (DWORD)troop_book_banner_index; *((DWORD*)0x00409DAD) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040B83D) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040BCE0) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040C1D5) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040C413) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040D97C) = (DWORD)troop_book_banner_index; *((DWORD*)0x0040E1E9) = (DWORD)troop_book_banner_index; *((DWORD*)0x004192A4) = (DWORD)troop_book_banner_index; *((DWORD*)0x0041981E) = (DWORD)troop_book_banner_index; *((DWORD*)0x0041A39E) = (DWORD)troop_book_banner_index; *((DWORD*)0x0041A5A6) = (DWORD)troop_book_banner_index; *((DWORD*)0x0041B172) = (DWORD)troop_book_banner_index; *((DWORD*)0x0041B48C) = (DWORD)troop_book_banner_index; *((DWORD*)0x00425B26) = (DWORD)troop_book_banner_index; *((DWORD*)0x00426DEB) = (DWORD)troop_book_banner_index; the_end: VirtualFree( readbuf, 0, MEM_RELEASE ); return; }