@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB; |
| 14 | 14 | |
| 15 | -class WSDBException extends \Exception{} |
|
| 15 | +class WSDBException extends \Exception {} |
|
@@ -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 |
@@ -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 | } |
@@ -17,11 +17,9 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | if($endianness === true){ // big-endian |
| 19 | 19 | $f = 'N'; |
| 20 | - } |
|
| 21 | - elseif($endianness === false){ // little-endian |
|
| 20 | + } elseif($endianness === false){ // little-endian |
|
| 22 | 21 | $f = 'V'; |
| 23 | - } |
|
| 24 | - else{ // machine byte order |
|
| 22 | + } else{ // machine byte order |
|
| 25 | 23 | $f = 'L'; |
| 26 | 24 | } |
| 27 | 25 | |
@@ -34,11 +32,9 @@ discard block |
||
| 34 | 32 | |
| 35 | 33 | if($endianness === true){ // big-endian |
| 36 | 34 | $f = 'J'; |
| 37 | - } |
|
| 38 | - elseif($endianness === false){ // little-endian |
|
| 35 | + } elseif($endianness === false){ // little-endian |
|
| 39 | 36 | $f = 'P'; |
| 40 | - } |
|
| 41 | - else{ // machine byte order |
|
| 37 | + } else{ // machine byte order |
|
| 42 | 38 | $f = 'Q'; |
| 43 | 39 | } |
| 44 | 40 | |
@@ -51,11 +47,9 @@ discard block |
||
| 51 | 47 | |
| 52 | 48 | if($endianness === true){ // big-endian |
| 53 | 49 | $f = 'G'; |
| 54 | - } |
|
| 55 | - elseif($endianness === false){ // little-endian |
|
| 50 | + } elseif($endianness === false){ // little-endian |
|
| 56 | 51 | $f = 'g'; |
| 57 | - } |
|
| 58 | - else{ // machine byte order |
|
| 52 | + } else{ // machine byte order |
|
| 59 | 53 | $f = 'f'; |
| 60 | 54 | } |
| 61 | 55 | |
@@ -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 array $dirs |
| 19 | 19 | */ |
| 20 | -class AIDXReader extends PACKReaderAbstract{ |
|
| 20 | +class AIDXReader extends PACKReaderAbstract { |
|
| 21 | 21 | |
| 22 | 22 | /** @var array */ |
| 23 | 23 | protected $dirs; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | \fread($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Size']) |
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - if($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41"){ // XDIA |
|
| 36 | + if ($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41") { // XDIA |
|
| 37 | 37 | throw new WSDBException('invalid AIDX'); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | $files = \array_fill(0, $n['files'], null); |
| 63 | 63 | |
| 64 | 64 | // create a directory object for each dir (4+4 = 8 bytes) |
| 65 | - foreach($dirs as $i => $_){ |
|
| 65 | + foreach ($dirs as $i => $_) { |
|
| 66 | 66 | $dirs[$i] = new ArchiveDirectory(\unpack('LNameOffset/LBlockIndex', \fread($this->fh, 8)), $parent); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // create a file object for each file (4+4+8+8+8+20+4 = 56 bytes) |
| 70 | - foreach($files as $i => $_){ |
|
| 70 | + foreach ($files as $i => $_) { |
|
| 71 | 71 | $files[$i] = new ArchiveFile( |
| 72 | 72 | \unpack('LNameOffset/LFlags/QFiletime/QSizeUncompressed/QSizeCompressed/a20Hash/x4', \fread($this->fh, 56)), |
| 73 | 73 | $parent |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | // apply the names to each object in the block |
| 81 | 81 | $setnames = function(array &$arr) use ($names):void{ |
| 82 | - foreach($arr ?? [] as $i => $e){ |
|
| 82 | + foreach ($arr ?? [] as $i => $e) { |
|
| 83 | 83 | $arr[$i]->Name = \DIRECTORY_SEPARATOR. |
| 84 | 84 | \substr($names, $e->NameOffset, \strpos($names, "\x00", $e->NameOffset) - $e->NameOffset); |
| 85 | 85 | } |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | $setnames($files); |
| 90 | 90 | |
| 91 | 91 | // loop through the directory stucture recursively and add the block data |
| 92 | - foreach($dirs as $i => $info){ |
|
| 93 | - if(isset($this->blocktable[$info->BlockIndex])){ |
|
| 92 | + foreach ($dirs as $i => $info) { |
|
| 93 | + if (isset($this->blocktable[$info->BlockIndex])) { |
|
| 94 | 94 | $dirs[$i]->Content = $this->getBlock($this->blocktable[$info->BlockIndex], $parent.$info->Name); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -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/x8/QRecordSize/QFieldCount/QDescriptionOffset/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/x8'; |
| 21 | 21 | |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | public function read(string $filename):ReaderInterface{ |
| 29 | 29 | $this->loadFile($filename); |
| 30 | 30 | |
| 31 | - if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD |
|
| 31 | + if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD |
|
| 32 | 32 | throw new WSDBException('invalid DTBL'); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $this->readColumnHeaders(); |
| 36 | 36 | $this->readData(); |
| 37 | 37 | |
| 38 | - if(\count($this->data) !== $this->header['RecordCount']){ |
|
| 38 | + if (\count($this->data) !== $this->header['RecordCount']) { |
|
| 39 | 39 | throw new WSDBException('invalid row count'); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -54,18 +54,18 @@ discard block |
||
| 54 | 54 | \fseek($this->fh, $this->header['DescriptionOffset'] + $this->headerSize); |
| 55 | 55 | |
| 56 | 56 | // read the column headers (4+4+8+2+2+4 = 24 bytes) |
| 57 | - for($i = 0; $i < $this->header['FieldCount']; $i++){ |
|
| 57 | + for ($i = 0; $i < $this->header['FieldCount']; $i++) { |
|
| 58 | 58 | $this->cols[$i]['header'] = \unpack('LNameLength/x4/QNameOffset/SDataType/x2/x4', \fread($this->fh, 24)); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $offset = $this->header['FieldCount'] * 24 + $this->header['DescriptionOffset'] + $this->headerSize; |
| 62 | 62 | |
| 63 | - if($this->header['FieldCount'] % 2){ |
|
| 63 | + if ($this->header['FieldCount'] % 2) { |
|
| 64 | 64 | $offset += 8; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // read the column names |
| 68 | - foreach($this->cols as $i => $col){ |
|
| 68 | + foreach ($this->cols as $i => $col) { |
|
| 69 | 69 | \fseek($this->fh, $offset + $col['header']['NameOffset']); |
| 70 | 70 | |
| 71 | 71 | // column name (UTF-16LE: length *2) |
@@ -85,21 +85,21 @@ discard block |
||
| 85 | 85 | $this->data = array_fill(0, $this->header['RecordCount'], null); |
| 86 | 86 | |
| 87 | 87 | // read a row |
| 88 | - foreach($this->data as $i => $_){ |
|
| 88 | + foreach ($this->data as $i => $_) { |
|
| 89 | 89 | $data = \fread($this->fh, $this->header['RecordSize']); |
| 90 | 90 | $row = []; |
| 91 | 91 | $j = 0; |
| 92 | 92 | $skip = false; |
| 93 | 93 | |
| 94 | 94 | // loop through the columns |
| 95 | - foreach($this->cols as $c => $col){ |
|
| 95 | + foreach ($this->cols as $c => $col) { |
|
| 96 | 96 | |
| 97 | 97 | // skip 4 bytes if the string offset is 0 (determined by $skip), the current type is string and the next isn't |
| 98 | - if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
|
| 98 | + if ($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) { |
|
| 99 | 99 | $j += 4; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - switch($col['header']['DataType']){ |
|
| 102 | + switch ($col['header']['DataType']) { |
|
| 103 | 103 | case 3: // uint32 |
| 104 | 104 | case 11: // booleans (stored as uint32 0/1) |
| 105 | 105 | $v = uint32(\substr($data, $j, 4)); $j += 4; break; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // if we run into this, a horrible thing happened |
| 120 | - if(\count($row) !== $this->header['FieldCount']){ |
|
| 120 | + if (\count($row) !== $this->header['FieldCount']) { |
|
| 121 | 121 | throw new WSDBException('invalid field count'); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $v = ''; |
| 144 | 144 | // loop through the string until we hit 2 nul bytes or the void |
| 145 | - do{ |
|
| 145 | + do { |
|
| 146 | 146 | $s = \fread($this->fh, 2); |
| 147 | 147 | $v .= $s; |
| 148 | 148 | } |
| 149 | - while($s !== "\x00\x00" && $s !== ''); |
|
| 149 | + while ($s !== "\x00\x00" && $s !== ''); |
|
| 150 | 150 | |
| 151 | 151 | \fseek($this->fh, $p); |
| 152 | 152 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB; |
| 14 | 14 | |
| 15 | -class AARCReader extends PACKReaderAbstract{ |
|
| 15 | +class AARCReader extends PACKReaderAbstract { |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @throws \codemasher\WildstarDB\WSDBException |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | \fread($this->fh, $this->blocktable[$this->header['RootInfoIndex']]['Size']) |
| 26 | 26 | ); |
| 27 | 27 | |
| 28 | - if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA |
|
| 28 | + if ($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41") { // CRAA |
|
| 29 | 29 | throw new WSDBException('invalid AARC'); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | \fseek($this->fh, $blockInfo['Offset']); |
| 36 | 36 | |
| 37 | 37 | // read the data block info (4+20+8 = 32 bytes) |
| 38 | - for($i = 0; $i < $rootInfo['Blockcount']; $i++){ |
|
| 38 | + for ($i = 0; $i < $rootInfo['Blockcount']; $i++) { |
|
| 39 | 39 | $data = unpack('LIndex/a20Hash/QSizeUncompressed', \fread($this->fh, 32)); |
| 40 | 40 | $hash = \bin2hex($data['Hash']); |
| 41 | 41 | unset($data['Hash']); |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB; |
| 14 | 14 | |
| 15 | -class ArchiveDirectory extends ArchiveItemAbstract{ |
|
| 15 | +class ArchiveDirectory extends ArchiveItemAbstract { |
|
| 16 | 16 | |
| 17 | 17 | public $BlockIndex; |
| 18 | 18 | public $Content; |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace codemasher\WildstarDB; |
| 14 | 14 | |
| 15 | -abstract class ArchiveItemAbstract{ |
|
| 15 | +abstract class ArchiveItemAbstract { |
|
| 16 | 16 | |
| 17 | 17 | public $Parent; |
| 18 | 18 | public $Name; |
| 19 | 19 | public $NameOffset; |
| 20 | 20 | |
| 21 | - public function __construct(array $data, string $parent){ |
|
| 21 | + public function __construct(array $data, string $parent) { |
|
| 22 | 22 | |
| 23 | - foreach($data as $property => $value){ |
|
| 23 | + foreach ($data as $property => $value) { |
|
| 24 | 24 | $this->{$property} = $value; |
| 25 | 25 | } |
| 26 | 26 | |