@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | namespace codemasher\WildstarDB; |
17 | 17 | |
18 | -class DTBLReader extends ReaderAbstract{ |
|
18 | +class DTBLReader extends ReaderAbstract { |
|
19 | 19 | |
20 | 20 | protected $FORMAT_HEADER = 'a4Signature/LVersion/QTableNameLength/QUnknown1/QRecordSize/QFieldCount/QDescriptionOffset/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/QUnknown2'; |
21 | 21 | protected $FORMAT_COLUMN = 'LNameLength/LUnknown1/QNameOffset/SDataType/SUnknown2/LUnknown3'; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | protected function init():void{ |
28 | 28 | |
29 | - if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD |
|
29 | + if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD |
|
30 | 30 | throw new WSDBException('invalid DTBL'); |
31 | 31 | } |
32 | 32 | |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | |
37 | 37 | \fseek($this->fh, $this->header['DescriptionOffset'] + $this->headerSize); |
38 | 38 | |
39 | - for($i = 0; $i < $this->header['FieldCount']; $i++){ |
|
39 | + for ($i = 0; $i < $this->header['FieldCount']; $i++) { |
|
40 | 40 | $this->cols[$i]['header'] = \unpack($this->FORMAT_COLUMN, \fread($this->fh, 0x18)); |
41 | 41 | } |
42 | 42 | |
43 | 43 | $offset = $this->header['FieldCount'] * 0x18 + $this->header['DescriptionOffset'] + $this->headerSize; |
44 | 44 | |
45 | - if($this->header['FieldCount'] % 2){ |
|
45 | + if ($this->header['FieldCount'] % 2) { |
|
46 | 46 | $offset += 8; |
47 | 47 | } |
48 | 48 | |
49 | - foreach($this->cols as $i => $col){ |
|
49 | + foreach ($this->cols as $i => $col) { |
|
50 | 50 | \fseek($this->fh, $offset + $col['header']['NameOffset']); |
51 | 51 | |
52 | 52 | $this->cols[$i]['name'] = $this->decodeString(\fread($this->fh, $col['header']['NameLength'] * 2)); |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | |
67 | 67 | \fseek($this->fh, $this->header['EntryOffset'] + $this->headerSize); |
68 | 68 | |
69 | - for($i = 0; $i < $this->header['RecordCount']; $i++){ |
|
69 | + for ($i = 0; $i < $this->header['RecordCount']; $i++) { |
|
70 | 70 | $data = \fread($this->fh, $this->header['RecordSize']); |
71 | 71 | $row = []; |
72 | 72 | $j = 0; |
73 | 73 | $skip = false; |
74 | 74 | |
75 | - foreach($this->cols as $c => $col){ |
|
75 | + foreach ($this->cols as $c => $col) { |
|
76 | 76 | |
77 | - if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
|
77 | + if ($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) { |
|
78 | 78 | $j += 4; |
79 | 79 | } |
80 | 80 | |
81 | - switch($col['header']['DataType']){ |
|
81 | + switch ($col['header']['DataType']) { |
|
82 | 82 | case 3: // uint32 |
83 | 83 | case 11: // booleans (stored as uint32 0/1) |
84 | 84 | $v = uint32(\substr($data, $j, 4)); $j += 4; break; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $row[$col['name']] = $v; |
96 | 96 | } |
97 | 97 | |
98 | - if(\count($row) !== $this->header['FieldCount']){ |
|
98 | + if (\count($row) !== $this->header['FieldCount']) { |
|
99 | 99 | throw new WSDBException('invalid field count'); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | \fclose($this->fh); |
106 | 106 | |
107 | - if(\count($this->data) !== $this->header['RecordCount']){ |
|
107 | + if (\count($this->data) !== $this->header['RecordCount']) { |
|
108 | 108 | throw new WSDBException('invalid row count'); |
109 | 109 | } |
110 | 110 | |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | |
128 | 128 | $v = ''; |
129 | 129 | |
130 | - do{ |
|
130 | + do { |
|
131 | 131 | $s = \fread($this->fh, 2); |
132 | 132 | $v .= $s; |
133 | 133 | } |
134 | - while($s !== "\x00\x00" && $s !== ''); |
|
134 | + while ($s !== "\x00\x00" && $s !== ''); |
|
135 | 135 | |
136 | 136 | \fseek($this->fh, $p); |
137 | 137 |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @throws \codemasher\WildstarDB\WSDBException |
76 | 76 | */ |
77 | - public function __construct(LoggerInterface $logger = null){ |
|
77 | + public function __construct(LoggerInterface $logger = null) { |
|
78 | 78 | |
79 | - if(\PHP_INT_SIZE < 8){ |
|
79 | + if (\PHP_INT_SIZE < 8) { |
|
80 | 80 | throw new WSDBException('64-bit PHP required'); |
81 | 81 | } |
82 | 82 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @return void |
88 | 88 | */ |
89 | - public function __destruct(){ |
|
89 | + public function __destruct() { |
|
90 | 90 | |
91 | - if(\is_resource($this->fh)){ |
|
91 | + if (\is_resource($this->fh)) { |
|
92 | 92 | \fclose($this->fh); |
93 | 93 | } |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return mixed|null |
101 | 101 | */ |
102 | - public function __get(string $name){ |
|
102 | + public function __get(string $name) { |
|
103 | 103 | return \property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null; |
104 | 104 | } |
105 | 105 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | protected function loadFile(string $filename):void{ |
113 | 113 | $filename = \realpath($filename); |
114 | 114 | |
115 | - if(!$filename || !\is_file($filename) || !\is_readable($filename)){ |
|
115 | + if (!$filename || !\is_file($filename) || !\is_readable($filename)) { |
|
116 | 116 | throw new WSDBException('input file not readable'); |
117 | 117 | } |
118 | 118 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | $this->logger->info('loading: '.$this->file); |
126 | 126 | |
127 | - if(\strlen($header) !== $this->headerSize){ |
|
127 | + if (\strlen($header) !== $this->headerSize) { |
|
128 | 128 | throw new WSDBException('cannot read header'); |
129 | 129 | } |
130 | 130 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | protected function checkData():void{ |
148 | 148 | |
149 | - if(empty($this->data)){ |
|
149 | + if (empty($this->data)) { |
|
150 | 150 | throw new WSDBException('empty data, run DTBLReader::read() first'); |
151 | 151 | } |
152 | 152 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function saveToFile(string $data, string $file):bool{ |
163 | 163 | |
164 | - if(!\is_writable(\dirname($file))){ |
|
164 | + if (!\is_writable(\dirname($file))) { |
|
165 | 165 | throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable'); |
166 | 166 | } |
167 | 167 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $json = \json_encode($this->data, $jsonOptions); |
181 | 181 | |
182 | - if($file !== null){ |
|
182 | + if ($file !== null) { |
|
183 | 183 | $this->saveToFile($json, $file); |
184 | 184 | } |
185 | 185 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | \fputcsv($mh, \array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar); |
203 | 203 | |
204 | - foreach($this->data as $row){ |
|
204 | + foreach ($this->data as $row) { |
|
205 | 205 | \fputcsv($mh, \array_values($row), $delimiter, $enclosure, $escapeChar); |
206 | 206 | } |
207 | 207 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | |
212 | 212 | \fclose($mh); |
213 | 213 | |
214 | - if($file !== null){ |
|
214 | + if ($file !== null) { |
|
215 | 215 | $this->saveToFile($csv, $file); |
216 | 216 | } |
217 | 217 | |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | $sxe = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', \LIBXML_BIGLINES); |
232 | 232 | $types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string']; |
233 | 233 | |
234 | - foreach($this->data as $row){ |
|
234 | + foreach ($this->data as $row) { |
|
235 | 235 | $item = $sxe->addChild('item'); |
236 | 236 | |
237 | - foreach(\array_values($row) as $i => $value){ |
|
237 | + foreach (\array_values($row) as $i => $value) { |
|
238 | 238 | $item |
239 | 239 | ->addChild($this->cols[$i]['name'], $value) |
240 | 240 | ->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | $xml = $sxe->asXML(); |
246 | 246 | |
247 | - if($file !== null){ |
|
247 | + if ($file !== null) { |
|
248 | 248 | $this->saveToFile($xml, $file); |
249 | 249 | } |
250 | 250 | |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | ->ifNotExists() |
265 | 265 | ; |
266 | 266 | |
267 | - foreach($this->cols as $i => $col){ |
|
267 | + foreach ($this->cols as $i => $col) { |
|
268 | 268 | |
269 | - switch($col['header']['DataType']){ |
|
269 | + switch ($col['header']['DataType']) { |
|
270 | 270 | case 3: $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break; |
271 | 271 | case 4: $createTable->decimal($col['name'], '7,3', 0); break; |
272 | 272 | case 11: $createTable->field($col['name'], 'BOOLEAN'); break; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | |
281 | 281 | $createTable->query(); |
282 | 282 | |
283 | - if(\count($this->data) < 1){ |
|
283 | + if (\count($this->data) < 1) { |
|
284 | 284 | $this->logger->notice('no records available for table '.$this->name); |
285 | 285 | return $this; |
286 | 286 | } |
@@ -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 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @property string $prettyname |
19 | 19 | */ |
20 | -class LTEXReader extends ReaderAbstract{ |
|
20 | +class LTEXReader extends ReaderAbstract { |
|
21 | 21 | |
22 | 22 | // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c |
23 | 23 | protected const LCID = [ |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | protected function init():void{ |
42 | 42 | |
43 | - if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL |
|
43 | + if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL |
|
44 | 44 | throw new WSDBException('invalid LTEX'); |
45 | 45 | } |
46 | 46 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $this->prettyname = $this->decodeString(\fread($this->fh, $this->header['LongNameStringLength'] * 2)); |
50 | 50 | $this->name = 'LocalizedText_'.$this::LCID[$this->header['LCID']]; |
51 | 51 | $this->cols = [ |
52 | - ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
52 | + ['name' => 'ID', 'header' => ['DataType' => 3]], |
|
53 | 53 | ['name' => 'LocalizedText', 'header' => ['DataType' => 130]], |
54 | 54 | ]; |
55 | 55 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | \fseek($this->fh, $this->headerSize + $this->header['EntryIndexPtr']); |
69 | 69 | |
70 | - for($i = 0; $i < $this->header['EntryCount']; $i++){ |
|
70 | + for ($i = 0; $i < $this->header['EntryCount']; $i++) { |
|
71 | 71 | $id = uint32(\fread($this->fh, 4)); |
72 | 72 | $pos = uint32(\fread($this->fh, 4)); |
73 | 73 | $p = \ftell($this->fh); |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | |
76 | 76 | \fseek($this->fh, $this->headerSize + $this->header['NameStorePtr'] + $pos * 2); |
77 | 77 | |
78 | - do{ |
|
78 | + do { |
|
79 | 79 | $s = \fread($this->fh, 2); |
80 | 80 | $v .= $s; |
81 | 81 | } |
82 | - while($s !== "\x00\x00" && $s !== ''); |
|
82 | + while ($s !== "\x00\x00" && $s !== ''); |
|
83 | 83 | |
84 | 84 | $this->data[$i] = ['ID' => $id, 'LocalizedText' => $this->decodeString($v)]; |
85 | 85 | \fseek($this->fh, $p); |