6 #include <format/format.h> 7 #include "../clib/Program/ProgramMain.h" 8 #include "../clib/clib_endian.h" 9 #include "../clib/fileutil.h" 10 #include "../clib/logfacility.h" 11 #include "../clib/rawtypes.h" 12 #include "../plib/mapcell.h" 13 #include "../plib/mapfunc.h" 14 #include "../plib/mapserver.h" 15 #include "../plib/mapshape.h" 16 #include "../plib/maptile.h" 17 #include "../plib/maptileserver.h" 18 #include "../plib/realmdescriptor.h" 19 #ifdef USE_SYSTEM_ZLIB 22 #include "../../lib/zlib/zlib.h" 41 <<
" POLTOOL mapdump [options]\n" 43 <<
" x1 y1 [x2 y2 realm] writes polmap info to polmap.html\n" 44 <<
" POLTOOL uncompressgump FileName\n" 45 <<
" unpacks and prints 0xDD gump from given packet log\n" 46 <<
" file needs to contain a single 0xDD packetlog\n";
51 short wxl = 5485, wxh = 5500, wyl = 0, wyh = 30;
52 const std::vector<std::string>& binArgs =
programArgs();
54 std::string realmname =
"britannia";
55 if ( binArgs.size() >= 6 )
57 realmname = binArgs[5];
62 std::unique_ptr<Plib::MapServer> _owner( mapserver );
65 if ( binArgs.size() >= 3 )
67 wxl = wxh =
static_cast<short>( atoi( binArgs[1].c_str() ) );
68 wyl = wyh =
static_cast<short>( atoi( binArgs[2].c_str() ) );
70 if ( binArgs.size() >= 5 )
72 wxh =
static_cast<short>( atoi( binArgs[3].c_str() ) );
73 wyh =
static_cast<short>( atoi( binArgs[4].c_str() ) );
76 std::ofstream ofs(
"polmap.html" );
79 ofs <<
"<table border=1 cellpadding=5 cellspacing=0>" << std::endl;
80 ofs <<
"<tr><td> </td>";
81 for (
int x = wxl; x <= wxh; ++x )
83 ofs <<
"<td align=center>" << x <<
"</td>";
85 ofs <<
"</tr>" << std::endl;
86 for (
unsigned short y = wyl; y <= wyh; ++y )
88 ofs <<
"<tr><td valign=center>" << y <<
"</td>" << std::endl;
89 for (
unsigned short x = wxl; x <= wxh; ++x )
91 ofs <<
"<td align=left valign=top>";
95 mapserver->GetMapShapes( mlist, x, y, static_cast<u32>(
Plib::FLAG::ALL ) );
98 ofs <<
"landtile=" << int( tile.
landtile ) <<
"<br>";
99 ofs <<
"tilez=" << int( tile.
z ) <<
"<br>";
100 ofs <<
"z=" << int( cell.
z ) <<
"<br>";
103 for (
unsigned i = 1; i < mlist.size(); ++i )
106 <<
"solid.z=" << int( mlist[i].z ) <<
"<br>" 107 <<
"solid.height=" << int( mlist[i].height ) <<
"<br>" 111 ofs <<
"</td>" << std::endl;
113 ofs <<
"</tr>" << std::endl;
115 ofs <<
"</table>" << std::endl;
121 const std::vector<std::string>& binArgs =
programArgs();
122 if ( binArgs.size() < 3 )
130 ifstream dmp( binArgs[2] );
131 std::vector<unsigned char> bytes;
132 dmp.setf( std::ios::hex );
145 else if ( per_line == 16 )
150 else if ( isdigit( c ) )
152 else if ( c >=
'A' && c <=
'Z' )
155 if ( tmp.size() == 2 )
157 int num = std::stoi( tmp, 0, 16 );
158 bytes.push_back( static_cast<unsigned char>( num ) );
164 auto toInt = [&](
size_t i ) ->
unsigned int {
165 return ( bytes[i] << 24 ) | ( bytes[i + 1] << 16 ) | ( bytes[i + 2] << 8 ) | ( bytes[i + 3] );
167 auto toShort = [&](
size_t i ) ->
unsigned short {
return ( bytes[i] << 8 ) | ( bytes[i + 1] ); };
168 if ( bytes[index] != 0xdd )
171 auto len = toShort( index );
174 auto serial = toInt( index );
177 auto gumpid =
static_cast<unsigned int>( toInt( index ) );
181 auto x = toInt( index );
184 auto y = toInt( index );
187 auto cbuflen = toInt( index ) - 4;
189 auto datalen =
static_cast<unsigned long>( toInt( index ) );
191 std::unique_ptr<unsigned char[]> uncompressed(
new unsigned char[datalen] );
192 int res = uncompress( uncompressed.get(), &datalen, &bytes.data()[index], cbuflen );
196 std::string layout( uncompressed.get(), uncompressed.get() + datalen - 1 );
197 fmt::Writer layouttmp;
199 for (
const auto& c : layout )
207 auto linecount = toInt( index );
209 cbuflen = toInt( index ) - 4;
211 datalen =
static_cast<unsigned long>( toInt( index ) );
213 std::unique_ptr<unsigned char[]> uncompressed2(
new unsigned char[datalen] );
214 res = uncompress( uncompressed2.get(), &datalen, &bytes.data()[index], cbuflen );
217 std::string layout2( uncompressed2.get(), uncompressed2.get() + datalen );
222 for (
size_t i = 0; i < linecount; ++i )
224 unsigned short wc = ( uncompressed2[j] << 8 ) | ( uncompressed2[j + 1] );
227 std::u16string u16s( reinterpret_cast<const char16_t*>( &uncompressed2[j + 2] ), wc );
229 for (
auto c : u16s )
233 u8_conv +=
static_cast<char>( c );
236 u8_conv +=
static_cast<char>( c & 0xff );
237 u8_conv +=
static_cast<char>( ( c >> 8 ) & 0xff );
240 datatmp <<
'"' << u8_conv <<
"\"\n";
246 INFO_PRINT << datatmp.str();
253 const std::vector<std::string>& binArgs =
programArgs();
258 if ( binArgs.size() == 1 )
267 if ( binArgs[1] ==
"mapdump" )
271 else if ( binArgs[1] ==
"uncompressgump" )
277 ERROR_PRINT <<
"Unknown command " << binArgs[1] <<
"\n";
288 int main(
int argc,
char* argv[] )
291 PolToolMain->
start( argc, argv );
std::string flagstr(unsigned int flags)
static RealmDescriptor Load(const std::string &realm_name, const std::string &realm_path="")
const std::vector< std::string > & programArgs() const
int unpackCompressedGump()
static MapServer * Create(const RealmDescriptor &descriptor)
void start(int argc, char *argv[])
bool FileExists(const char *filename)