mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-09-18 01:22:08 +00:00
Working copy
This commit is contained in:
42
test.php
42
test.php
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Diablo 2 D2S Save File Checksum Calculator
|
||||
By Hash Borgir (https://www.psychedelicsdaily.com)
|
||||
@date 6/4/2022
|
||||
|
||||
Checksum field is at byte 12.
|
||||
Bytes 12/13/14/15 as a uint32.
|
||||
Set this to 0.
|
||||
After clearing the checksum field add up the values of all the bytes in the file and rotate the running total one bit to the left before adding the next byte.
|
||||
*/
|
||||
|
||||
function swapEndianness(string $hex) {
|
||||
return implode('', array_reverse(str_split($hex, 2)));
|
||||
}
|
||||
|
||||
function checksum($fileData) {
|
||||
$nSignature = 0;
|
||||
foreach ($fileData as $k => $byte) {
|
||||
if ($k == 12 || $k == 13 || $k == 14 || $k == 15) {
|
||||
$byte = 0;
|
||||
}
|
||||
$nSignature = ((($nSignature << 1) | ($nSignature >> 31)) + $byte & 0xFFFFFFFF);
|
||||
}
|
||||
return swapEndianness(str_pad(dechex($nSignature), 8, 0, STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
$filename = "D:\Diablo II\MODS\ironman-dev\save\Necro.d2s";
|
||||
$fp = fopen($filename, "r+b");
|
||||
|
||||
fseek($fp, 12); // go to byte 12
|
||||
fwrite($fp, pack('I', 0)); // clear the checksum field uInt32
|
||||
|
||||
$fileData = unpack('C*', file_get_contents($filename)); // open file and unpack
|
||||
|
||||
|
||||
var_dump(checksum($fileData));
|
||||
|
||||
fseek($fp, 12); // go to byte 12
|
||||
fwrite($fp, pack('H8', checksum($fileData))); // write new checksum
|
||||
fclose($fp);
|
Reference in New Issue
Block a user