static int statics_histogram() { unsigned int counts[1000]; memset(counts, 0, sizeof counts); INFO_PRINT << "Reading UO data..\n"; Core::open_uo_data_files(); Core::read_uo_data(); for (u16 x = 0; x < 6143; x += 8) { INFO_PRINT << "."; for (u16 y = 0; y < 4095; y += 8) { std::vector < Core::USTRUCT_STATIC > p; int count; readstaticblock(&p, &count, x, y); if (count < 1000) ++counts[count]; else ERROR_PRINT << "doh: count=" << count << "\n"; } } INFO_PRINT << "\n"; for (int i = 0; i < 1000; ++i) { if (counts[i]) INFO_PRINT << i << ": " << counts[i] << "\n"; } Core::clear_tiledata(); return 0; }
int statics_histogram() { unsigned long counts[1000]; memset( counts, 0, sizeof counts ); cout << "Reading UO data.." << endl; open_uo_data_files(); read_uo_data(); for( u16 x = 0; x < 6143; x += 8 ) { cout << "."; for( u16 y = 0; y < 4095; y += 8 ) { vector<USTRUCT_STATIC> p; int count; readstaticblock( &p, &count, x, y ); if (count > 1000) cerr << "doh: count=" << count << endl; ++counts[ count ]; } } cout << endl; for( int i = 0; i < 1000; ++i ) { if (counts[i]) cout << i << ": " << counts[i] << endl; } clear_tiledata(); return 0; }
static int defragstatics(int argc, char** argv) { const char* realm; if (argc < 2) realm = "britannia"; else realm = argv[1]; Plib::RealmDescriptor descriptor = Plib::RealmDescriptor::Load(realm); Core::uo_mapid = descriptor.uomapid; Core::uo_usedif = descriptor.uodif; Core::uo_map_width = static_cast<unsigned short>(descriptor.width); Core::uo_map_height = static_cast<unsigned short>(descriptor.height); Core::open_uo_data_files(); Core::read_uo_data(); std::string statidx = "staidx" + Clib::tostring(Core::uo_mapid) + ".mul"; std::string statics = "statics" + Clib::tostring(Core::uo_mapid) + ".mul"; Clib::RemoveFile(statidx); Clib::RemoveFile(statics); FILE* fidx = fopen(statidx.c_str(), "wb"); FILE* fmul = fopen(statics.c_str(), "wb"); int lastprogress = -1; for (u16 x = 0; x < descriptor.width; x += Plib::STATICBLOCK_CHUNK) { int progress = x * 100L / descriptor.width; if (progress != lastprogress) { INFO_PRINT << "\rRewriting statics files: " << progress << "%"; lastprogress = progress; } for (u16 y = 0; y < descriptor.height; y += Plib::STATICBLOCK_CHUNK) { std::vector<Core::USTRUCT_STATIC> pstat; int num; std::vector<Core::USTRUCT_STATIC> tilelist; readstaticblock(&pstat, &num, x, y); if (num > 0) { int currwritepos = ftell(fmul); for (int i = 0; i < num; ++i) { Core::USTRUCT_STATIC& tile = pstat[i]; if (tile.graphic < 0x4000) { bool first = true; for (const auto& stile : tilelist) { if ((tile.graphic == stile.graphic) && (tile.x_offset == stile.x_offset) && (tile.y_offset == stile.y_offset) && (tile.z == stile.z) && (tile.hue == stile.hue)) { first = false; break; } } if (first) { Core::USTRUCT_STATIC newtile; newtile.graphic = tile.graphic; newtile.x_offset = tile.x_offset; newtile.y_offset = tile.y_offset; newtile.z = tile.z; newtile.hue = tile.hue; tilelist.push_back(newtile); } } } Core::USTRUCT_IDX idx; idx.offset = ~0u; idx.length = ~0u; idx.unknown = ~0u; if (!tilelist.empty()) { idx.offset = currwritepos; for (const auto& elem : tilelist) { fwrite(&elem, sizeof(Core::USTRUCT_STATIC), 1, fmul); } currwritepos = ftell(fmul) - currwritepos; idx.length = currwritepos; idx.unknown = 0; tilelist.clear(); } fwrite(&idx, sizeof idx, 1, fidx); } else { Core::USTRUCT_IDX idx; idx.offset = ~0u; idx.length = ~0u; idx.unknown = ~0u; fwrite(&idx, sizeof idx, 1, fidx); } } } INFO_PRINT << "\rRewriting statics files: Complete\n"; fclose(fidx); fclose(fmul); return 0; }
int write_pol_static_files( const string& realm ) { unsigned int duplicates = 0; unsigned int illegales = 0; unsigned int statics = 0; unsigned int empties = 0; unsigned int nonempties = 0; unsigned int maxcount = 0; string directory = "realm/" + realm + "/"; string statidx_dat = directory + "statidx.dat"; string statics_dat = directory + "statics.dat"; string statidx_tmp = directory + "statidx.tmp"; string statics_tmp = directory + "statics.tmp"; Clib::RemoveFile( statidx_dat ); Clib::RemoveFile( statics_dat ); Clib::RemoveFile( statidx_tmp ); Clib::RemoveFile( statics_tmp ); FILE* fidx = fopen( statidx_tmp.c_str(), "wb" ); FILE* fdat = fopen( statics_tmp.c_str(), "wb" ); Plib::RealmDescriptor descriptor = Plib::RealmDescriptor::Load( realm ); int lastprogress = -1; unsigned int index = 0; for ( u16 y = 0; y < descriptor.height; y += Plib::STATICBLOCK_CHUNK ) { int progress = y * 100L / descriptor.height; if ( progress != lastprogress ) { INFO_PRINT << "\rCreating POL statics files: " << progress << "%"; lastprogress = progress; } for ( u16 x = 0; x < descriptor.width; x += Plib::STATICBLOCK_CHUNK ) { Plib::STATIC_INDEX idx; idx.index = index; fwrite( &idx, sizeof idx, 1, fidx ); vector<USTRUCT_STATIC> pstat; int num; vector<Plib::STATIC_ENTRY> vec; readstaticblock( &pstat, &num, x, y ); for ( int i = 0; i < num; ++i ) { if ( pstat[i].graphic <= config.max_tile_id ) { if ( !newstat_dont_add( vec, &pstat[i] ) ) { Plib::STATIC_ENTRY nrec; nrec.objtype = pstat[i].graphic; // TODO map these? nrec.xy = ( pstat[i].x_offset << 4 ) | pstat[i].y_offset; nrec.z = pstat[i].z; nrec.hue = pstat[i].hue; vec.push_back( nrec ); ++statics; } else { ++duplicates; } } else { ++illegales; if ( cfg_show_illegal_graphic_warning ) INFO_PRINT << " Warning: Item with illegal Graphic 0x" << fmt::hexu(pstat[i].graphic) << " in Area " << x << " " << y << " " << ( x + Plib::STATICBLOCK_CHUNK - 1 ) << " " << ( y + Plib::STATICBLOCK_CHUNK - 1 ) << "\n"; } } for ( unsigned i = 0; i < vec.size(); ++i ) { fwrite( &vec[i], sizeof( Plib::STATIC_ENTRY ), 1, fdat ); ++index; } if ( vec.empty() ) ++empties; else ++nonempties; if ( vec.size() > maxcount ) maxcount = static_cast<unsigned int>( vec.size() ); } } Plib::STATIC_INDEX idx; idx.index = index; fwrite( &idx, sizeof idx, 1, fidx ); int errors = ferror( fdat ) || ferror( fidx ); fclose( fdat ); fclose( fidx ); if ( !errors ) { INFO_PRINT << "\rCreating POL statics files: Complete\n"; rename( statidx_tmp.c_str(), statidx_dat.c_str() ); rename( statics_tmp.c_str(), statics_dat.c_str() ); } else { INFO_PRINT << "\rCreating POL statics files: Error\n"; } #ifndef NDEBUG INFO_PRINT << statics << " statics written\n" << duplicates << " duplicates eliminated\n" << illegales << " illegales eliminated\n" << empties << " empties\n" << nonempties << " nonempties\n" << maxcount << " was the highest count\n"; #endif return 0; }
int defragstatics( int argc, char **argv ) { const char* realm = FindArg2( "realm=", "britannia" ); RealmDescriptor descriptor = RealmDescriptor::Load( realm ); uo_mapid = descriptor.uomapid; uo_usedif = descriptor.uodif; uo_map_width = static_cast<unsigned short>(descriptor.width); uo_map_height = static_cast<unsigned short>(descriptor.height); open_uo_data_files(); read_uo_data(); string statidx = "staidx"+tostring(uo_mapid)+".mul"; string statics = "statics"+tostring(uo_mapid)+".mul"; RemoveFile( statidx ); RemoveFile( statics ); FILE* fidx = fopen( statidx.c_str(), "wb" ); FILE* fmul = fopen( statics.c_str(), "wb" ); int lastprogress = -1; for( u16 x = 0; x < descriptor.width; x += STATICBLOCK_CHUNK ) { int progress = x*100L/descriptor.width; if (progress != lastprogress) { cout << "\rRewriting statics files: " << progress << "%"; lastprogress=progress; } for( u16 y = 0; y < descriptor.height; y += STATICBLOCK_CHUNK ) { vector<USTRUCT_STATIC> pstat; int num; vector<USTRUCT_STATIC> tilelist; readstaticblock( &pstat, &num, x, y ); if (num>0) { long currwritepos = ftell(fmul); for( int i = 0; i < num; ++i ) { USTRUCT_STATIC& tile =pstat[i]; if (tile.graphic < 0x4000) { bool first = true; for( unsigned j = 0; j < tilelist.size(); ++j ) { USTRUCT_STATIC& stile = tilelist[j]; if ((tile.graphic==stile.graphic) && (tile.x_offset==stile.x_offset) && (tile.y_offset==stile.y_offset) && (tile.z==stile.z) && (tile.hue==stile.hue)) { first = false; break; } } if (first) { USTRUCT_STATIC newtile; newtile.graphic=tile.graphic; newtile.x_offset=tile.x_offset; newtile.y_offset=tile.y_offset; newtile.z=tile.z; newtile.hue=tile.hue; tilelist.push_back(newtile); } } } USTRUCT_IDX idx; idx.offset=~0uL; idx.length=~0uL; idx.unknown=~0uL; if (tilelist.size()>0) { idx.offset=currwritepos; for( unsigned i = 0; i < tilelist.size(); ++i ) { fwrite( &tilelist[i],sizeof(USTRUCT_STATIC),1, fmul); } currwritepos=ftell(fmul)-currwritepos; idx.length=currwritepos; idx.unknown=0; tilelist.clear(); } fwrite( &idx, sizeof idx, 1, fidx ); } else { USTRUCT_IDX idx; idx.offset = ~0uL; idx.length = ~0uL; idx.unknown = ~0uL; fwrite( &idx, sizeof idx, 1, fidx ); } } } cout << "\rRewriting statics files: Complete" << endl; return 0; }