• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 16683711876

01 Aug 2025 07:40PM UTC coverage: 59.756% (-0.03%) from 59.79%
16683711876

push

github

web-flow
use c++20 (#799)

* use c++20
* increased used clang version
* compiler report and logfacility use now compile time formatting, which
means that the formatstring gets checked at compile time. (which found 2 errors)
adapted a few places since report only accepts formatting arguments
adapted a few places with logging since char[] is compile time
formatting and string or chr* is runtime formatting
* use std::ranges instead of boost
* disabled pragma_assume vs specific macro (I guess noone cares)
* needed to fix ancient ms exception code
* modernized SpinLock
* removed unused code in ECompile
* replaced std::filesystem::path::u8string with string. It now returns an actual u8string type
* cleanup layers.h added the defines for other layers which where before
  only defined in the pkt
* osmod::OpenConnection and HTTPRequest cleanup: early outs, dont check for pChild which is
  only needed for startscript and placed suspend at the very last
  position

* fix warning

* rebuild cache with new compiler version

* define c++ standard for external libs where possible

* added fixme

156 of 212 new or added lines in 26 files covered. (73.58%)

45 existing lines in 19 files now uncovered.

43621 of 72999 relevant lines covered (59.76%)

409874.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.09
/pol-core/poltool/PolToolMain.cpp
1
#include "PolToolMain.h"
2

3
#include <fstream>
4
#include <string>
5

6
#include "../clib/Program/ProgramMain.h"
7
#include "../clib/clib_endian.h"
8
#include "../clib/fileutil.h"
9
#include "../clib/logfacility.h"
10
#include "../clib/rawtypes.h"
11
#include "../plib/mapcell.h"
12
#include "../plib/mapfunc.h"
13
#include "../plib/mapserver.h"
14
#include "../plib/mapshape.h"
15
#include "../plib/maptile.h"
16
#include "../plib/maptileserver.h"
17
#include "../plib/realmdescriptor.h"
18
#include "baredistro.h"
19
#include "testenv.h"
20
#include "testfiles.h"
21

22

23
#include <zlib.h>
24

25
namespace Pol
26
{
27
namespace Clib
28
{
29
using namespace std;
30

31
///////////////////////////////////////////////////////////////////////////////
32

33
PolToolMain::PolToolMain() : ProgramMain() {}
4✔
34
///////////////////////////////////////////////////////////////////////////////
35

36
void PolToolMain::showHelp()
×
37
{
38
  ERROR_PRINTLN(
×
39
      "Usage:\n"
40
      "    \n"
41
      "  POLTOOL mapdump [options]\n"
42
      "        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"
47
      "  POLTOOL testfiles [options]\n"
48
      "        Options:\n"
49
      "          outdir=.\n"
50
      "          hsa=0\n"
51
      "          maxtiles=0x3fff\n"
52
      "          width=6144\n"
53
      "          height=4096" );
54
}
×
55

56
int PolToolMain::mapdump()
×
57
{
58
  short wxl = 5485, wxh = 5500, wyl = 0, wyh = 30;
×
59
  const std::vector<std::string>& binArgs = programArgs();
×
60
  std::string realmname = "britannia";
×
61
  if ( binArgs.size() >= 7 )
×
62
  {
63
    realmname = binArgs[6];
×
64
  }
UNCOV
65
  Plib::RealmDescriptor descriptor = Plib::RealmDescriptor::Load(
×
66
      realmname.c_str() );  // TODO: use a string in the signature of Load()
×
67
  Plib::MapServer* mapserver = Plib::MapServer::Create( descriptor );
×
68
  std::unique_ptr<Plib::MapServer> _owner( mapserver );
×
69

70
  std::unique_ptr<Plib::MapTileServer> mts( new Plib::MapTileServer( descriptor ) );
×
71
  if ( binArgs.size() >= 4 )
×
72
  {
73
    wxl = wxh = static_cast<short>( atoi( binArgs[2].c_str() ) );
×
74
    wyl = wyh = static_cast<short>( atoi( binArgs[3].c_str() ) );
×
75
  }
76
  if ( binArgs.size() >= 6 )
×
77
  {
78
    wxh = static_cast<short>( atoi( binArgs[4].c_str() ) );
×
79
    wyh = static_cast<short>( atoi( binArgs[5].c_str() ) );
×
80
  }
81

82
  std::ofstream ofs( "polmap.html" );
×
83

84
  ofs << Plib::flagdescs() << std::endl;
×
85
  ofs << "<table border=1 cellpadding=5 cellspacing=0>" << std::endl;
×
86
  ofs << "<tr><td>&nbsp;</td>";
×
87
  for ( int x = wxl; x <= wxh; ++x )
×
88
  {
89
    ofs << "<td align=center>" << x << "</td>";
×
90
  }
91
  ofs << "</tr>" << std::endl;
×
92
  for ( unsigned short y = wyl; y <= wyh; ++y )
×
93
  {
94
    ofs << "<tr><td valign=center>" << y << "</td>" << std::endl;
×
95
    for ( unsigned short x = wxl; x <= wxh; ++x )
×
96
    {
97
      ofs << "<td align=left valign=top>";
×
98

99
      Plib::MAPCELL cell = mapserver->GetMapCell( x, y );
×
100
      Plib::MapShapeList mlist;
×
101
      mapserver->GetMapShapes( mlist, x, y, static_cast<u32>( Plib::FLAG::ALL ) );
×
102
      Plib::MAPTILE_CELL tile = mts->GetMapTile( x, y );
×
103

104
      ofs << "landtile=" << int( tile.landtile ) << "<br>";
×
105
      ofs << "tilez=" << int( tile.z ) << "<br>";
×
106
      ofs << "z=" << int( cell.z ) << "<br>";
×
107
      ofs << "flags=" << Plib::flagstr( cell.flags );
×
108

109
      for ( unsigned i = 1; i < mlist.size(); ++i )
×
110
      {
111
        ofs << "<br>"
112
            << "solid.z=" << int( mlist[i].z ) << "<br>"
×
113
            << "solid.height=" << int( mlist[i].height ) << "<br>"
×
114
            << "solid.flags=" << Plib::flagstr( mlist[i].flags );
×
115
      }
116

117
      ofs << "</td>" << std::endl;
×
118
    }
×
119
    ofs << "</tr>" << std::endl;
×
120
  }
121
  ofs << "</table>" << std::endl;
×
122
  return 0;
×
123
}
×
124

125
int PolToolMain::unpackCompressedGump()
×
126
{
127
  const std::vector<std::string>& binArgs = programArgs();
×
128
  if ( binArgs.size() < 3 )
×
129
  {
130
    showHelp();
×
131
    return 1;
×
132
  }
133
  if ( !Clib::FileExists( binArgs[2] ) )
×
134
    return 1;
×
135

136
  ifstream dmp( binArgs[2] );
×
137
  std::vector<unsigned char> bytes;
×
138
  dmp.setf( std::ios::hex );
×
139
  int per_line = 0;
×
140
  while ( dmp )
×
141
  {
142
    std::string tmp;
×
143
    while ( dmp )
×
144
    {
145
      char c;
146
      dmp.get( c );
×
147
      if ( c == ' ' )
×
148
      {
149
        break;
×
150
      }
151
      else if ( per_line == 16 )  // both razor and pol have 16 bytes per line
×
152
      {
153
        if ( c == '\n' )
×
154
          per_line = 0;
×
155
      }
156
      else if ( isdigit( c ) )
×
157
        tmp += c;
×
158
      else if ( c >= 'A' && c <= 'Z' )
×
159
        tmp += c;
×
160
    }
161
    if ( tmp.size() == 2 )
×
162
    {
163
      int num = std::stoi( tmp, nullptr, 16 );
×
164
      bytes.push_back( static_cast<unsigned char>( num ) );
×
165
      ++per_line;
×
166
    }
167
  }
×
168

169
  size_t index = 0;
×
170
  auto toInt = [&]( size_t i ) -> unsigned int {
×
171
    return ( bytes[i] << 24 ) | ( bytes[i + 1] << 16 ) | ( bytes[i + 2] << 8 ) | ( bytes[i + 3] );
×
172
  };
×
173
  auto toShort = [&]( size_t i ) -> unsigned short { return ( bytes[i] << 8 ) | ( bytes[i + 1] ); };
×
174
  if ( bytes[index] != 0xdd )
×
175
    return 1;
×
176
  ++index;
×
177
  auto len = toShort( index );
×
178
  std::string msg = fmt::format( "len {}", len );
×
179
  index += 2;
×
180
  auto serial = toInt( index );
×
181
  index += 4;
×
182
  msg += fmt::format( " serial {}", serial );
×
183
  auto gumpid = static_cast<unsigned int>( toInt( index ) );
×
184
  index += 4;
×
185
  msg += fmt::format( " gumpID {}", gumpid );
×
186

187
  auto x = toInt( index );
×
188
  index += 4;
×
189
  msg += fmt::format( " x {}", x );
×
190
  auto y = toInt( index );
×
191
  index += 4;
×
192
  msg += fmt::format( " y {}", y );
×
193
  INFO_PRINTLN( msg );
×
194
  auto cbuflen = toInt( index ) - 4;
×
195
  index += 4;
×
196
  auto datalen = static_cast<unsigned long>( toInt( index ) );
×
197
  index += 4;
×
198
  std::unique_ptr<unsigned char[]> uncompressed( new unsigned char[datalen] );
×
199
  int res = uncompress( uncompressed.get(), &datalen, &bytes.data()[index], cbuflen );
×
200
  if ( res < 0 )
×
201
    return 1;
×
202
  index += cbuflen;
×
203
  std::string layout( uncompressed.get(), uncompressed.get() + datalen - 1 );
×
204
  msg = '\n';
×
205
  for ( const auto& c : layout )
×
206
  {
207
    msg += c;
×
208
    if ( c == '}' )
×
209
      msg += '\n';
×
210
  }
211
  INFO_PRINTLN( msg );
×
212

213
  auto linecount = toInt( index );
×
214
  index += 4;
×
215
  cbuflen = toInt( index ) - 4;
×
216
  index += 4;
×
217
  datalen = static_cast<unsigned long>( toInt( index ) );
×
218
  index += 4;
×
219
  std::unique_ptr<unsigned char[]> uncompressed2( new unsigned char[datalen] );
×
220
  res = uncompress( uncompressed2.get(), &datalen, &bytes.data()[index], cbuflen );
×
221
  if ( res < 0 )
×
222
    return 1;
×
223
  std::string layout2( uncompressed2.get(), uncompressed2.get() + datalen );
×
224
  msg = "\n\n";
×
225
  size_t j = 0;
×
226
  for ( size_t i = 0; i < linecount; ++i )
×
227
  {
228
    unsigned short wc = ( uncompressed2[j] << 8 ) | ( uncompressed2[j + 1] );
×
229
    if ( wc > 0 )
×
230
    {
231
      std::u16string u16s( reinterpret_cast<const char16_t*>( &uncompressed2[j + 2] ), wc );
×
232
      std::string u8_conv;
×
233
      for ( auto c : u16s )
×
234
      {
235
        c = ctBEu16( c );
×
236
        if ( c <= 256 )
×
237
          u8_conv += static_cast<char>( c );
×
238
        else
239
        {
240
          u8_conv += static_cast<char>( c & 0xff );
×
241
          u8_conv += static_cast<char>( ( c >> 8 ) & 0xff );
×
242
        }
243
      }
244
      msg += '"' + u8_conv + "\"\n";
×
245
    }
×
246
    else
247
      msg += "\"\"\n";
×
248
    j += 2 + wc * 2;
×
249
  }
250
  INFO_PRINTLN( msg );
×
251
  return 0;
×
252
}
×
253

254
int PolToolMain::main()
4✔
255
{
256
  const std::vector<std::string>& binArgs = programArgs();
4✔
257

258
  /**********************************************
259
   * show help
260
   **********************************************/
261
  if ( binArgs.size() == 1 )
4✔
262
  {
263
    showHelp();
×
264
    return 0;  // return "okay"
×
265
  }
266

267
  /**********************************************
268
   * execute the map dumping
269
   **********************************************/
270
  if ( binArgs[1] == "mapdump" )
4✔
271
  {
272
    return mapdump();
×
273
  }
274
  else if ( binArgs[1] == "uncompressgump" )
4✔
275
  {
276
    return unpackCompressedGump();
×
277
  }
278
  else if ( binArgs[1] == "testfiles" )
4✔
279
  {
280
    std::string outdir = programArgsFindEquals( "outdir=", "." );
3✔
281
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
3✔
282
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
3✔
283
    int width = programArgsFindEquals( "width=", 6144, false );
3✔
284
    int height = programArgsFindEquals( "height=", 4096, false );
3✔
285
    int mapid = programArgsFindEquals( "mapid=", 0, false );
3✔
286
    PolTool::FileGenerator g( outdir, hsa, maxtiles, mapid, width, height );
3✔
287
    g.generateTiledata();
3✔
288
    g.generateMap();
3✔
289
    g.generateStatics();
3✔
290
    g.generateMultis();
3✔
291
    return 0;
3✔
292
  }
3✔
293
  else if ( binArgs[1] == "baredistro" )
1✔
294
  {
295
    std::string outdir = programArgsFindEquals( "outdir=", "." );
×
296
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
×
297
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
×
298
    int width = programArgsFindEquals( "width=", 6144, false );
×
299
    int height = programArgsFindEquals( "height=", 4096, false );
×
300
    PolTool::BareDistro distro( outdir, hsa, maxtiles, width, height );
×
301
    distro.generate();
×
302
    return 0;
×
303
  }
×
304
  else if ( binArgs[1] == "testenv" )
1✔
305
  {
306
    std::string outdir = programArgsFindEquals( "outdir=", "." );
1✔
307
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
1✔
308
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
1✔
309
    int width = programArgsFindEquals( "width=", 6144, false );
1✔
310
    int height = programArgsFindEquals( "height=", 4096, false );
1✔
311
    PolTool::TestEnv testenv( outdir, hsa, maxtiles, width, height );
1✔
312
    testenv.generate();
1✔
313
    return 0;
1✔
314
  }
1✔
315
  else
316
  {
317
    ERROR_PRINTLN( "Unknown command {}", binArgs[1] );
×
318
    return 1;  // return "error"
×
319
  }
320
}
321
}  // namespace Clib
322
}  // namespace Pol
323

324
///////////////////////////////////////////////////////////////////////////////
325
///////////////////////////////////////////////////////////////////////////////
326
///////////////////////////////////////////////////////////////////////////////
327

328
int main( int argc, char* argv[] )
4✔
329
{
330
  Pol::Clib::PolToolMain* PolToolMain = new Pol::Clib::PolToolMain();
4✔
331
  PolToolMain->start( argc, argv );
4✔
332
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc