mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-12-21 06:43:58 -06:00
better item parsing, displaying in char page, needs more work
This commit is contained in:
@@ -133,17 +133,26 @@ WHERE sk.charclass = '$class'";
|
||||
public function parseItems() {
|
||||
$i_TotalOffset = strpos($this->data, "JM"); // Find the offset of the "JM" marker in the data
|
||||
fseek($this->fp, $i_TotalOffset + 2); // Move the file pointer to the next position after the "JM" marker
|
||||
// get total # of items
|
||||
$i_Total = unpack('S*', (fread($this->fp, 2)))[1]; // Read 2 bytes from the file and unpack them as an unsigned short (16-bit) value
|
||||
|
||||
// get offsets for each item from total, so if 50, run loop 50 times
|
||||
// grab the offset of each item, each item starts with JM, skim JM (+2)
|
||||
$i_Offsets = [];
|
||||
for ($i = 0; $i <= $i_Total; $i++) {
|
||||
$i_Offsets[] = strposX($this->data, "JM", $i + 2); // Find the offsets of the "JM" markers for each item
|
||||
}
|
||||
// foreach item offset, get item data byte length between the JMs
|
||||
// k = item #, like 0,1,2,3, etc.
|
||||
// v = actual offset of item
|
||||
foreach ($i_Offsets as $k => $v) {
|
||||
$itemOffsets[$v] = $i_Offsets[$k + 1] - $i_Offsets[$k]; // Calculate the length of each item's data by subtracting consecutive offsets
|
||||
$itemOffsets[$v] = $i_Offsets[$k + 1] - $i_Offsets[$k]; // Calculate the length of each item's data by subtracting consecutive offsets in bytes
|
||||
}
|
||||
array_pop($itemOffsets); // Remove the last element from the itemOffsets array
|
||||
|
||||
array_pop($itemOffsets); // Remove the last element from the itemOffsets array, not sure why
|
||||
|
||||
|
||||
//now get items. For each itemOffsets, create new D2Item object that parses the bitstream
|
||||
// readh(offset, numbytes), convert toBits, feed into D2Item
|
||||
$_items = [];
|
||||
foreach ($itemOffsets as $offset => $bytes) {
|
||||
$this->items[] = new D2Item($this->ByteReader->toBits($this->ByteReader->readh($offset, $bytes))); // Create a new D2Item object and add it to the items array
|
||||
|
||||
Reference in New Issue
Block a user