@@ -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 | } |
@@ -73,8 +73,7 @@ |
||
| 73 | 73 | __DIR__.'/maps/'.$map, |
| 74 | 74 | __DIR__.'/../public/tiles/'.$mapdir |
| 75 | 75 | ); |
| 76 | - } |
|
| 77 | - catch(ImagetilerException $e){ |
|
| 76 | + } catch(ImagetilerException $e){ |
|
| 78 | 77 | echo $e->getMessage(); |
| 79 | 78 | echo $e->getTraceAsString(); |
| 80 | 79 | } |
@@ -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 | } |
@@ -183,8 +183,7 @@ discard block |
||
| 183 | 183 | # $this->errors[$file->Hash] = $file; |
| 184 | 184 | $this->logger->error('error writing '.$dest); |
| 185 | 185 | |
| 186 | - } |
|
| 187 | - elseif($bytesWritten !== $file->SizeUncompressed){ |
|
| 186 | + } elseif($bytesWritten !== $file->SizeUncompressed){ |
|
| 188 | 187 | # $this->warnings[$file->Hash] = $file; |
| 189 | 188 | // throw new WSDBException |
| 190 | 189 | $this->logger->warning( |
@@ -220,11 +219,9 @@ discard block |
||
| 220 | 219 | // $Flags is supposed to be a bitmask |
| 221 | 220 | if($file->Flags === 1){ // no compression |
| 222 | 221 | return $content; |
| 223 | - } |
|
| 224 | - elseif($file->Flags === 3){ // deflate (probably unsed) |
|
| 222 | + } elseif($file->Flags === 3){ // deflate (probably unsed) |
|
| 225 | 223 | return gzinflate($content); |
| 226 | - } |
|
| 227 | - elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
| 224 | + } elseif($file->Flags === 5){ // lzma (requires ext-xz) |
|
| 228 | 225 | // https://bitbucket.org/mugadr_m/wildstar-studio/issues/23 |
| 229 | 226 | return xzdecode(substr($content, 0, 5).pack('Q', $file->SizeUncompressed).substr($content, 5)); |
| 230 | 227 | } |
@@ -39,8 +39,8 @@ |
||
| 39 | 39 | * @internal |
| 40 | 40 | */ |
| 41 | 41 | protected $FORMAT_HEADER = 'a4Signature/LVersion/LLanguage/LLCID/QTagNameStringLength/QTagNameStringPtr'. |
| 42 | - '/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr'. |
|
| 43 | - '/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr'; |
|
| 42 | + '/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr'. |
|
| 43 | + '/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr'; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * @var string |
@@ -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 | |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @throws \codemasher\WildstarDB\WSDBException |
| 87 | 87 | */ |
| 88 | - public function __construct(LoggerInterface $logger = null){ |
|
| 88 | + public function __construct(LoggerInterface $logger = null) { |
|
| 89 | 89 | |
| 90 | - if(PHP_INT_SIZE < 8){ |
|
| 90 | + if (PHP_INT_SIZE < 8) { |
|
| 91 | 91 | throw new WSDBException('64-bit PHP required'); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | /** |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - public function __destruct(){ |
|
| 100 | + public function __destruct() { |
|
| 101 | 101 | $this->logger->info('memory usage: '.round(memory_get_usage(true) / 1048576, 3).'MB'); |
| 102 | 102 | $this->logger->info('peak memory usage: '.round(memory_get_peak_usage(true) / 1048576, 3).'MB'); |
| 103 | 103 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function close():ReaderInterface{ |
| 111 | 111 | |
| 112 | - if(is_resource($this->fh)){ |
|
| 112 | + if (is_resource($this->fh)) { |
|
| 113 | 113 | fclose($this->fh); |
| 114 | 114 | |
| 115 | 115 | $this->fh = null; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return mixed|null |
| 131 | 131 | */ |
| 132 | - public function __get(string $name){ |
|
| 132 | + public function __get(string $name) { |
|
| 133 | 133 | return property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $this->close(); |
| 144 | 144 | # $filename = realpath($filename); |
| 145 | 145 | |
| 146 | - if(!$filename || !is_file($filename) || !is_readable($filename)){ |
|
| 146 | + if (!$filename || !is_file($filename) || !is_readable($filename)) { |
|
| 147 | 147 | throw new WSDBException('input file not readable'); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $this->logger->info('loading: '.$this->file); |
| 155 | 155 | |
| 156 | - if(strlen($header) !== $this->headerSize){ |
|
| 156 | + if (strlen($header) !== $this->headerSize) { |
|
| 157 | 157 | throw new WSDBException('cannot read header'); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function checkData():void{ |
| 177 | 177 | |
| 178 | - if(empty($this->data)){ |
|
| 178 | + if (empty($this->data)) { |
|
| 179 | 179 | throw new WSDBException('empty data, run ReaderInterface::read() first'); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | protected function saveToFile(string $data, string $file):bool{ |
| 192 | 192 | |
| 193 | - if(!is_writable(dirname($file))){ |
|
| 193 | + if (!is_writable(dirname($file))) { |
|
| 194 | 194 | throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable'); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $this->checkData(); |
| 210 | 210 | $json = json_encode($this->data, $jsonOptions); |
| 211 | 211 | |
| 212 | - if($file !== null){ |
|
| 212 | + if ($file !== null) { |
|
| 213 | 213 | $this->saveToFile($json, $file); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | fputcsv($mh, array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar); |
| 233 | 233 | |
| 234 | - foreach($this->data as $row){ |
|
| 234 | + foreach ($this->data as $row) { |
|
| 235 | 235 | fputcsv($mh, array_values($row), $delimiter, $enclosure, $escapeChar); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | fclose($mh); |
| 243 | 243 | |
| 244 | - if($file !== null){ |
|
| 244 | + if ($file !== null) { |
|
| 245 | 245 | $this->saveToFile($csv, $file); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -261,10 +261,10 @@ discard block |
||
| 261 | 261 | $sxe = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', LIBXML_BIGLINES); |
| 262 | 262 | $types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string']; |
| 263 | 263 | |
| 264 | - foreach($this->data as $row){ |
|
| 264 | + foreach ($this->data as $row) { |
|
| 265 | 265 | $item = $sxe->addChild('item'); |
| 266 | 266 | |
| 267 | - foreach(array_values($row) as $i => $value){ |
|
| 267 | + foreach (array_values($row) as $i => $value) { |
|
| 268 | 268 | $item |
| 269 | 269 | ->addChild($this->cols[$i]['name'], $value) |
| 270 | 270 | ->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]) |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | $xml = $sxe->asXML(); |
| 276 | 276 | |
| 277 | - if($file !== null){ |
|
| 277 | + if ($file !== null) { |
|
| 278 | 278 | $this->saveToFile($xml, $file); |
| 279 | 279 | } |
| 280 | 280 | |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | ->ifNotExists() |
| 295 | 295 | ; |
| 296 | 296 | |
| 297 | - foreach($this->cols as $i => $col){ |
|
| 297 | + foreach ($this->cols as $i => $col) { |
|
| 298 | 298 | |
| 299 | - switch($col['header']['DataType']){ |
|
| 299 | + switch ($col['header']['DataType']) { |
|
| 300 | 300 | case 3: $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break; |
| 301 | 301 | case 4: $createTable->decimal($col['name'], '7,3', 0); break; |
| 302 | 302 | case 11: $createTable->field($col['name'], 'BOOLEAN'); break; |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | $createTable->query(); |
| 312 | 312 | |
| 313 | - if(count($this->data) < 1){ |
|
| 313 | + if (count($this->data) < 1) { |
|
| 314 | 314 | $this->logger->notice('no records available for table '.$this->name); |
| 315 | 315 | |
| 316 | 316 | return $this; |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB\Archive; |
| 14 | 14 | |
| 15 | -abstract class ItemAbstract{ |
|
| 15 | +abstract class ItemAbstract { |
|
| 16 | 16 | |
| 17 | 17 | /** @var string */ |
| 18 | 18 | public $Parent; |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | * @param array $data |
| 28 | 28 | * @param string $parent |
| 29 | 29 | */ |
| 30 | - public function __construct(array $data, string $parent){ |
|
| 30 | + public function __construct(array $data, string $parent) { |
|
| 31 | 31 | |
| 32 | - foreach($data as $property => $value){ |
|
| 32 | + foreach ($data as $property => $value) { |
|
| 33 | 33 | $this->{$property} = $value; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * @internal |
| 28 | 28 | */ |
| 29 | 29 | protected $FORMAT_HEADER = 'a4Signature/LVersion/QTableNameLength/x8/QRecordSize/QFieldCount/QDescriptionOffset'. |
| 30 | - '/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/x8'; |
|
| 30 | + '/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/x8'; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @var bool |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | use function array_fill, count, fread, fseek, ftell, round, substr, unpack; |
| 21 | 21 | use function codemasher\WildstarDB\{float, uint32, uint64}; |
| 22 | 22 | |
| 23 | -final class DTBLReader extends ReaderAbstract{ |
|
| 23 | +final class DTBLReader extends ReaderAbstract { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | public function read(string $filename):ReaderInterface{ |
| 57 | 57 | $this->loadFile($filename); |
| 58 | 58 | |
| 59 | - if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD |
|
| 59 | + if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD |
|
| 60 | 60 | throw new WSDBException('invalid DTBL'); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $this->readColumnHeaders(); |
| 64 | 64 | $this->readData(); |
| 65 | 65 | |
| 66 | - if(count($this->data) !== $this->header['RecordCount']){ |
|
| 66 | + if (count($this->data) !== $this->header['RecordCount']) { |
|
| 67 | 67 | throw new WSDBException('invalid row count'); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | fseek($this->fh, $this->header['DescriptionOffset'] + $this->headerSize); |
| 83 | 83 | |
| 84 | 84 | // read the column headers (4+4+8+2+2+4 = 24 bytes) |
| 85 | - for($i = 0; $i < $this->header['FieldCount']; $i++){ |
|
| 85 | + for ($i = 0; $i < $this->header['FieldCount']; $i++) { |
|
| 86 | 86 | $this->cols[$i]['header'] = unpack('LNameLength/x4/QNameOffset/SDataType/x2/x4', fread($this->fh, 24)); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | $offset = $this->header['FieldCount'] * 24 + $this->header['DescriptionOffset'] + $this->headerSize; |
| 90 | 90 | |
| 91 | - if($this->header['FieldCount'] % 2){ |
|
| 91 | + if ($this->header['FieldCount'] % 2) { |
|
| 92 | 92 | $offset += 8; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // read the column names |
| 96 | - foreach($this->cols as $i => $col){ |
|
| 96 | + foreach ($this->cols as $i => $col) { |
|
| 97 | 97 | fseek($this->fh, $offset + $col['header']['NameOffset']); |
| 98 | 98 | |
| 99 | 99 | // column name (UTF-16LE: length *2) |
@@ -113,16 +113,16 @@ discard block |
||
| 113 | 113 | $this->data = array_fill(0, $this->header['RecordCount'], null); |
| 114 | 114 | |
| 115 | 115 | // read a row |
| 116 | - foreach($this->data as $i => $_){ |
|
| 116 | + foreach ($this->data as $i => $_) { |
|
| 117 | 117 | $this->rowdata = fread($this->fh, $this->header['RecordSize']); |
| 118 | 118 | $this->pos = 0; |
| 119 | 119 | $this->skip = false; |
| 120 | 120 | |
| 121 | 121 | // loop through the columns |
| 122 | - foreach($this->cols as $c => $col){ |
|
| 122 | + foreach ($this->cols as $c => $col) { |
|
| 123 | 123 | |
| 124 | 124 | // skip 4 bytes if the string offset is 0 (determined by $skip), the current type is string and the next isn't |
| 125 | - if($this->skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
|
| 125 | + if ($this->skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) { |
|
| 126 | 126 | $this->pos += 4; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // if we run into this, a horrible thing happened |
| 133 | - if(count($this->data[$i]) !== $this->header['FieldCount']){ |
|
| 133 | + if (count($this->data[$i]) !== $this->header['FieldCount']) { |
|
| 134 | 134 | throw new WSDBException('invalid field count'); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -143,24 +143,24 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return int|float|string|null |
| 145 | 145 | */ |
| 146 | - private function getValue(int $datatype){ |
|
| 146 | + private function getValue(int $datatype) { |
|
| 147 | 147 | |
| 148 | - switch($datatype){ |
|
| 148 | + switch ($datatype) { |
|
| 149 | 149 | case 3: // uint32 |
| 150 | 150 | case 11: // booleans (stored as uint32 0/1) |
| 151 | - $v = uint32(substr($this->rowdata, $this->pos, 4)); |
|
| 151 | + $v = uint32(substr($this->rowdata, $this->pos, 4)); |
|
| 152 | 152 | $this->pos += 4; |
| 153 | 153 | break; |
| 154 | 154 | case 4: // float |
| 155 | - $v = round(float(substr($this->rowdata, $this->pos, 4)), 3); // @todo: determine round precision |
|
| 155 | + $v = round(float(substr($this->rowdata, $this->pos, 4)), 3); // @todo: determine round precision |
|
| 156 | 156 | $this->pos += 4; |
| 157 | 157 | break; |
| 158 | 158 | case 20: // uint64 |
| 159 | - $v = uint64(substr($this->rowdata, $this->pos, 8)); |
|
| 159 | + $v = uint64(substr($this->rowdata, $this->pos, 8)); |
|
| 160 | 160 | $this->pos += 8; |
| 161 | 161 | break; |
| 162 | 162 | case 130: // string (UTF-16LE) |
| 163 | - $v = $this->readString(); |
|
| 163 | + $v = $this->readString(); |
|
| 164 | 164 | $this->pos += 8; |
| 165 | 165 | break; |
| 166 | 166 | |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $v = ''; |
| 185 | 185 | // loop through the string until we hit 2 nul bytes or the void |
| 186 | - do{ |
|
| 186 | + do { |
|
| 187 | 187 | $s = fread($this->fh, 2); |
| 188 | 188 | $v .= $s; |
| 189 | 189 | } |
| 190 | - while($s !== "\x00\x00" && $s !== ''); |
|
| 190 | + while ($s !== "\x00\x00" && $s !== ''); |
|
| 191 | 191 | |
| 192 | 192 | fseek($this->fh, $p); |
| 193 | 193 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @property array $dirs |
| 23 | 23 | */ |
| 24 | -final class AIDXReader extends PACKReaderAbstract{ |
|
| 24 | +final class AIDXReader extends PACKReaderAbstract { |
|
| 25 | 25 | |
| 26 | 26 | private const AIDX_ROOT = 'a4ArchiveType/LVersion/LBuildnumber/LIndex'; |
| 27 | 27 | private const AIDX_DATA = 'LNameOffset/LFlags/QFiletime/QSizeUncompressed/QSizeCompressed/a20Hash/x4'; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | // get the root info block of the AIDX file (4+4+4+4 = 16 bytes) |
| 38 | 38 | $rootInfo = unpack($this::AIDX_ROOT, fread($this->fh, 16)); |
| 39 | 39 | |
| 40 | - if($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41"){ // XDIA |
|
| 40 | + if ($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41") { // XDIA |
|
| 41 | 41 | throw new WSDBException('invalid AIDX'); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | $files = array_fill(0, $n['files'], null); |
| 67 | 67 | |
| 68 | 68 | // create a directory object for each dir (4+4 = 8 bytes) |
| 69 | - foreach($dirs as $i => $_){ |
|
| 69 | + foreach ($dirs as $i => $_) { |
|
| 70 | 70 | $dirs[$i] = new Directory(unpack('LNameOffset/LBlockIndex', fread($this->fh, 8)), $parent); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // create a file object for each file (4+4+8+8+8+20+4 = 56 bytes) |
| 74 | - foreach($files as $i => $_){ |
|
| 74 | + foreach ($files as $i => $_) { |
|
| 75 | 75 | $files[$i] = new File(unpack($this::AIDX_DATA, fread($this->fh, 56)), $parent); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | }; |
| 84 | 84 | |
| 85 | 85 | // apply the names to each object in the block |
| 86 | - foreach($dirs as $i => $e){ |
|
| 86 | + foreach ($dirs as $i => $e) { |
|
| 87 | 87 | $dirs[$i]->Name = $getname($e); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - foreach($files as $i => $e){ |
|
| 90 | + foreach ($files as $i => $e) { |
|
| 91 | 91 | $files[$i]->Name = $getname($e); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // loop through the directory stucture recursively and add the block data |
| 95 | - foreach($dirs as $i => $info){ |
|
| 96 | - if(isset($this->blocktable[$info->BlockIndex])){ |
|
| 95 | + foreach ($dirs as $i => $info) { |
|
| 96 | + if (isset($this->blocktable[$info->BlockIndex])) { |
|
| 97 | 97 | $dirs[$i]->Content = $this->getBlock($this->blocktable[$info->BlockIndex], $parent.$info->Name); |
| 98 | 98 | } |
| 99 | 99 | } |