mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-09-18 01:22:08 +00:00
DC6 to PNG item conversion. Read in order from docpath,d2modder img path
This commit is contained in:
10
test.php
10
test.php
@@ -31,7 +31,8 @@ class D2ByteReader {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function readh(int $numBytes, bool $str = true): string {
|
||||
public function readh(int $offset, int $numBytes, bool $str = true): string {
|
||||
$this->seek($offset);
|
||||
$bytes = null;
|
||||
for ($i = $this->offset; $i < $this->offset + $numBytes; $i++) {
|
||||
$str ? $bytes .= $this->data[$i] : $bytes[] = $this->data[$i];
|
||||
@@ -39,7 +40,8 @@ class D2ByteReader {
|
||||
return unpack('H*', $bytes)[1];
|
||||
}
|
||||
|
||||
public function readc(int $numBytes, bool $str = true): array {
|
||||
public function readc(int $offset, int $numBytes, bool $str = true): array {
|
||||
$this->seek($offset);
|
||||
$bytes = null;
|
||||
for ($i = $this->offset; $i < $this->offset + $numBytes; $i++) {
|
||||
$str ? $bytes .= $this->data[$i] : $bytes[] = $this->data[$i];
|
||||
@@ -158,8 +160,7 @@ $file = "D:\Diablo II\MODS\ironman-dev\save\Barb.d2s";
|
||||
$data = file_get_contents($file);
|
||||
|
||||
$c = new D2ByteReader($data);
|
||||
$c->seek(643);
|
||||
$bytes = $c->readh(5);
|
||||
$bytes = $c->readh(643, 5);
|
||||
$bits = $c->toBits($bytes);
|
||||
|
||||
$bits[4] = 1;
|
||||
@@ -171,6 +172,5 @@ $c->writeBytes(643, $newBytes);
|
||||
|
||||
$c->writeBytes(12, "00000000"); // zero old checksum
|
||||
$newChecksum = checksum(unpack('C*', $c->getData())); // get new checksum
|
||||
dump($newChecksum);
|
||||
$c->writeBytes(12, $newChecksum); // write new checksum
|
||||
file_put_contents($file, $c->getData()); // write bytestream to file
|
Reference in New Issue
Block a user