@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace codemasher\WildstarDB; |
14 | 14 | |
15 | -class WSDBException extends \Exception{} |
|
15 | +class WSDBException extends \Exception {} |
@@ -9,6 +9,6 @@ |
||
9 | 9 | |
10 | 10 | namespace codemasher\WildstarDB; |
11 | 11 | |
12 | -if(!defined('WSDB_FUNCTIONS')){ |
|
12 | +if (!defined('WSDB_FUNCTIONS')) { |
|
13 | 13 | require_once __DIR__.'/functions.php'; |
14 | 14 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return array|string|false |
21 | 21 | */ |
22 | -function uint32($i, bool $endianness = null){ |
|
22 | +function uint32($i, bool $endianness = null) { |
|
23 | 23 | |
24 | - if($endianness === true){ // big-endian |
|
24 | + if ($endianness === true) { // big-endian |
|
25 | 25 | $f = 'N'; |
26 | 26 | } |
27 | - elseif($endianness === false){ // little-endian |
|
27 | + elseif ($endianness === false) { // little-endian |
|
28 | 28 | $f = 'V'; |
29 | 29 | } |
30 | - else{ // machine byte order |
|
30 | + else { // machine byte order |
|
31 | 31 | $f = 'L'; |
32 | 32 | } |
33 | 33 | |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array|string|false |
44 | 44 | */ |
45 | -function uint64($i, bool $endianness = null){ |
|
45 | +function uint64($i, bool $endianness = null) { |
|
46 | 46 | |
47 | - if($endianness === true){ // big-endian |
|
47 | + if ($endianness === true) { // big-endian |
|
48 | 48 | $f = 'J'; |
49 | 49 | } |
50 | - elseif($endianness === false){ // little-endian |
|
50 | + elseif ($endianness === false) { // little-endian |
|
51 | 51 | $f = 'P'; |
52 | 52 | } |
53 | - else{ // machine byte order |
|
53 | + else { // machine byte order |
|
54 | 54 | $f = 'Q'; |
55 | 55 | } |
56 | 56 | |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return array|string|false |
67 | 67 | */ |
68 | -function float($i, bool $endianness = null){ |
|
68 | +function float($i, bool $endianness = null) { |
|
69 | 69 | |
70 | - if($endianness === true){ // big-endian |
|
70 | + if ($endianness === true) { // big-endian |
|
71 | 71 | $f = 'G'; |
72 | 72 | } |
73 | - elseif($endianness === false){ // little-endian |
|
73 | + elseif ($endianness === false) { // little-endian |
|
74 | 74 | $f = 'g'; |
75 | 75 | } |
76 | - else{ // machine byte order |
|
76 | + else { // machine byte order |
|
77 | 77 | $f = 'f'; |
78 | 78 | } |
79 | 79 |
@@ -35,9 +35,9 @@ |
||
35 | 35 | 'password' => $env->DB_PASSWORD, |
36 | 36 | ]; |
37 | 37 | |
38 | -$logger = new class() extends AbstractLogger{ |
|
38 | +$logger = new class() extends AbstractLogger { |
|
39 | 39 | |
40 | - public function log($level, $message, array $context = []){ |
|
40 | + public function log($level, $message, array $context = []) { |
|
41 | 41 | echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n"; |
42 | 42 | } |
43 | 43 |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | |
46 | 46 | $outpath = __DIR__.'/maps'; |
47 | 47 | |
48 | -foreach(new DirectoryIterator($wildstar_path.'/Patch/ClientData/Map') as $dir){ |
|
48 | +foreach (new DirectoryIterator($wildstar_path.'/Patch/ClientData/Map') as $dir) { |
|
49 | 49 | $map = $dir->getFilename(); |
50 | 50 | |
51 | - if(!$dir->isDir() || $dir->isDot() || (!empty($include_maps) && !in_array($map, $include_maps))){ |
|
51 | + if (!$dir->isDir() || $dir->isDot() || (!empty($include_maps) && !in_array($map, $include_maps))) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | 54 | |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | $xmax = 0; |
59 | 59 | $ymax = 0; |
60 | 60 | |
61 | - foreach(new DirectoryIterator($dir->getPathname()) as $file){ |
|
61 | + foreach (new DirectoryIterator($dir->getPathname()) as $file) { |
|
62 | 62 | |
63 | - if($file->getExtension() !== 'bmp'){ |
|
63 | + if ($file->getExtension() !== 'bmp') { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | $y = hexdec($hex[0]); |
70 | 70 | |
71 | 71 | // exclude some empty tiles to not exaggerate map/image size |
72 | - if( |
|
72 | + if ( |
|
73 | 73 | ($map === 'Eastern' && $y < 3) |
74 | 74 | || ($map === 'AdventureMalgrave' && ($x > 80 || $y < 65)) |
75 | 75 | || ($map === 'NewCentral' && ($x > 80 || $y < 3)) |
76 | 76 | || ($map === 'MordechaiReturns' && $y < 6) |
77 | 77 | || (in_array($map, ['Western', 'AdventureLevianBay']) && ($x > 74 || $y < 46 || $y > 74)) |
78 | 78 | || ($map === 'HalonRingNew' && ($x > 56 || $y > 66)) |
79 | - ){ |
|
79 | + ) { |
|
80 | 80 | continue; |
81 | 81 | } |
82 | 82 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $textures[$y][$x] = $file->getRealPath(); |
89 | 89 | } |
90 | 90 | |
91 | - if(empty($textures)){ |
|
91 | + if (empty($textures)) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | $im->newImage(($xmax - $xmin + 1) * 512, ($ymax - $ymin + 1) * 512, '#757575'); |
97 | 97 | $im->setImageFormat('png'); |
98 | 98 | |
99 | - foreach($textures as $y => $col){ |
|
100 | - foreach($col as $x => $file){ |
|
99 | + foreach ($textures as $y => $col) { |
|
100 | + foreach ($col as $x => $file) { |
|
101 | 101 | $im->compositeImage(new Imagick($file), Imagick::COMPOSITE_OVER, ($x - $xmin) * 512, ($y - $ymin) * 512); |
102 | 102 | $logger->info($file); |
103 | 103 | } |
@@ -66,15 +66,15 @@ |
||
66 | 66 | $optimizer = (new OptimizerFactory($optimizer_settings, $logger))->get($tilerOptions->tile_format); |
67 | 67 | $map_tiler = new Imagetiler($tilerOptions, $optimizer, $logger); |
68 | 68 | |
69 | -foreach($maps as $mapdir => $map){ |
|
69 | +foreach ($maps as $mapdir => $map) { |
|
70 | 70 | |
71 | - try{ |
|
71 | + try { |
|
72 | 72 | $map_tiler->process( |
73 | 73 | __DIR__.'/maps/'.$map, |
74 | 74 | __DIR__.'/../public/tiles/'.$mapdir |
75 | 75 | ); |
76 | 76 | } |
77 | - catch(ImagetilerException $e){ |
|
77 | + catch (ImagetilerException $e) { |
|
78 | 78 | echo $e->getMessage(); |
79 | 79 | echo $e->getTraceAsString(); |
80 | 80 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | use const DIRECTORY_SEPARATOR; |
36 | 36 | |
37 | -class Extractor implements LoggerAwareInterface{ |
|
37 | +class Extractor implements LoggerAwareInterface { |
|
38 | 38 | use LoggerAwareTrait; |
39 | 39 | |
40 | 40 | public const ARCHIVES = ['ClientData', 'ClientDataDE', 'ClientDataEN', 'ClientDataFR']; |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @throws \codemasher\WildstarDB\WSDBException |
63 | 63 | */ |
64 | - public function __construct(LoggerInterface $logger){ |
|
64 | + public function __construct(LoggerInterface $logger) { |
|
65 | 65 | |
66 | - if(!extension_loaded('xz')){ |
|
66 | + if (!extension_loaded('xz')) { |
|
67 | 67 | throw new WSDBException('required extension xz missing!'); |
68 | 68 | } |
69 | 69 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | public function open(string $index):Extractor{ |
85 | 85 | $this->archivename = str_replace(['.index', '.archive'], '', basename($index)); |
86 | 86 | |
87 | - if(!in_array($this->archivename, $this::ARCHIVES)){ |
|
87 | + if (!in_array($this->archivename, $this::ARCHIVES)) { |
|
88 | 88 | throw new WSDBException('invalid archive file (Steam Wildstar not supported)'); |
89 | 89 | } |
90 | 90 | |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | $this->destination = rtrim($destination ?? $this->archivepath, '\\/'); |
107 | 107 | |
108 | 108 | // does the destination parent exist? |
109 | - if(!$this->destination || !file_exists(dirname($this->destination))){ |
|
109 | + if (!$this->destination || !file_exists(dirname($this->destination))) { |
|
110 | 110 | throw new WSDBException('invalid destination: '.$this->destination); |
111 | 111 | } |
112 | 112 | |
113 | 113 | // destination does not exist? |
114 | - if(!file_exists($this->destination)){ |
|
114 | + if (!file_exists($this->destination)) { |
|
115 | 115 | // is the parent writable? |
116 | - if(!is_writable(dirname($this->destination))){ |
|
116 | + if (!is_writable(dirname($this->destination))) { |
|
117 | 117 | throw new WSDBException('destination parent is not writable'); |
118 | 118 | } |
119 | 119 | // create it |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | // destination exists but isn't writable? |
124 | - if(!is_writable($this->destination)){ |
|
124 | + if (!is_writable($this->destination)) { |
|
125 | 125 | throw new WSDBException('destination is not writable'); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $this->warnings = []; |
129 | 129 | |
130 | - foreach($this->AIDX->data as $item){ |
|
130 | + foreach ($this->AIDX->data as $item) { |
|
131 | 131 | $this->read($item); |
132 | 132 | } |
133 | 133 | |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function read(ItemAbstract $item):void{ |
143 | 143 | |
144 | - if($item instanceof Directory){ |
|
144 | + if ($item instanceof Directory) { |
|
145 | 145 | |
146 | - foreach($item->Content as $dir){ |
|
146 | + foreach ($item->Content as $dir) { |
|
147 | 147 | |
148 | - if(!file_exists($this->destination.$dir->Parent)){ |
|
148 | + if (!file_exists($this->destination.$dir->Parent)) { |
|
149 | 149 | mkdir($this->destination.$dir->Parent, 0777, true); |
150 | 150 | } |
151 | 151 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | protected function extractFile(File $file):void{ |
168 | 168 | $dest = $this->destination.$file->Parent.$file->Name; |
169 | 169 | |
170 | - if(file_exists($dest)){ // @todo: overwrite option |
|
170 | + if (file_exists($dest)) { // @todo: overwrite option |
|
171 | 171 | $this->logger->notice('file already exists: '.$dest); |
172 | 172 | |
173 | 173 | return; |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | $this->getContent($file, $block['Offset'], $block['Size']) |
180 | 180 | ); |
181 | 181 | |
182 | - if($bytesWritten === false){ |
|
182 | + if ($bytesWritten === false) { |
|
183 | 183 | # $this->errors[$file->Hash] = $file; |
184 | 184 | $this->logger->error('error writing '.$dest); |
185 | 185 | |
186 | 186 | } |
187 | - elseif($bytesWritten !== $file->SizeUncompressed){ |
|
187 | + elseif ($bytesWritten !== $file->SizeUncompressed) { |
|
188 | 188 | # $this->warnings[$file->Hash] = $file; |
189 | 189 | // throw new WSDBException |
190 | 190 | $this->logger->warning( |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | fclose($fh); |
212 | 212 | |
213 | 213 | // hash the read data |
214 | - if(sha1($content) !== $file->Hash){ |
|
214 | + if (sha1($content) !== $file->Hash) { |
|
215 | 215 | throw new WSDBException( |
216 | 216 | sprintf('corrupt data, invalid hash: %1$s (expected %2$s for %3$s)', sha1($content), $file->Hash, $file->Name) |
217 | 217 | ); |
218 | 218 | } |
219 | 219 | |
220 | 220 | // $Flags is supposed to be a bitmask |
221 | - if($file->Flags === 1){ // no compression |
|
221 | + if ($file->Flags === 1) { // no compression |
|
222 | 222 | return $content; |
223 | 223 | } |
224 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
224 | + elseif ($file->Flags === 3) { // deflate (probably unsed) |
|
225 | 225 | return gzinflate($content); |
226 | 226 | } |
227 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
227 | + elseif ($file->Flags === 5) { // lzma (requires ext-xz) |
|
228 | 228 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
229 | 229 | return xzdecode(substr($content, 0, 5).pack('Q', $file->SizeUncompressed).substr($content, 5)); |
230 | 230 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @property string $prettyname |
26 | 26 | */ |
27 | -final class LTEXReader extends ReaderAbstract{ |
|
27 | +final class LTEXReader extends ReaderAbstract { |
|
28 | 28 | |
29 | 29 | // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c |
30 | 30 | private const LCID = [ |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function read(string $filename):ReaderInterface{ |
57 | 57 | $this->loadFile($filename); |
58 | 58 | |
59 | - if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL |
|
59 | + if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL |
|
60 | 60 | throw new WSDBException('invalid LTEX'); |
61 | 61 | } |
62 | 62 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $this->prettyname = $this->decodeString(fread($this->fh, $this->header['LongNameStringLength'] * 2)); |
66 | 66 | $this->name = 'LocalizedText_'.$this::LCID[$this->header['LCID']]; |
67 | 67 | $this->cols = [ |
68 | - ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
68 | + ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
69 | 69 | ['name' => 'LocalizedText', 'header' => ['DataType' => 130]], |
70 | 70 | ]; |
71 | 71 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | $this->data = array_fill(0, $this->header['EntryCount'], null); |
86 | 86 | |
87 | - foreach($this->data as $i => $_){ |
|
87 | + foreach ($this->data as $i => $_) { |
|
88 | 88 | // get the id and offset for the data block |
89 | 89 | $c = unpack('Lid/Loffset', fread($this->fh, 8)); |
90 | 90 | // save the current position |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | |
96 | 96 | $v = ''; |
97 | 97 | // read until we hit a double nul or the void |
98 | - do{ |
|
98 | + do { |
|
99 | 99 | $s = fread($this->fh, 2); |
100 | 100 | $v .= $s; |
101 | 101 | } |
102 | - while($s !== "\x00\x00" && $s !== ''); |
|
102 | + while ($s !== "\x00\x00" && $s !== ''); |
|
103 | 103 | |
104 | 104 | $this->data[$i] = ['ID' => $c['id'], 'LocalizedText' => $this->decodeString($v)]; |
105 | 105 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\Database\Database; |
16 | 16 | |
17 | -interface ReaderInterface{ |
|
17 | +interface ReaderInterface { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $name |