DC6 to PNG item conversion. Read in order from docpath,d2modder img path

This commit is contained in:
Hash Borgir
2022-06-24 22:36:35 -06:00
parent 40fcc4fdfb
commit b7fdaa585e
1708 changed files with 89 additions and 12 deletions

View File

@@ -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