mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-12-02 13:36:03 +00:00
testing checksum
This commit is contained in:
parent
5e75c70664
commit
3001eaf611
42
test.php
42
test.php
@ -17,12 +17,44 @@ require_once './src/D2DocGenerator.php';
|
|||||||
define('DB_FILE', "ironman-dev.db");
|
define('DB_FILE', "ironman-dev.db");
|
||||||
PDO_Connect("sqlite:" . DB_FILE);
|
PDO_Connect("sqlite:" . DB_FILE);
|
||||||
|
|
||||||
$fp = fopen("x", "rb+");
|
$filename = "D:\Diablo II\MODS\ironman-dev\save\Test.d2s";
|
||||||
|
$fp = fopen($filename, "rb+");
|
||||||
|
$filesize = filesize($filename);
|
||||||
|
$pucData = unpack("C*",file_get_contents($filename));
|
||||||
|
|
||||||
|
// ddump($pucData);
|
||||||
|
|
||||||
|
|
||||||
fseek($fp, 0);
|
// ddump(fseek($fp, 1));
|
||||||
$y = fread($fp, 1);
|
|
||||||
|
// pucData - pointer to the byte stream of the .d2s file
|
||||||
|
// iSize - number of bytes in the stream ( filesize )
|
||||||
|
function checksum($fp, $pucData, $iSize){
|
||||||
|
// delete old checksum at offset 0x0C - byte 12
|
||||||
|
fseek($fp, 12);
|
||||||
|
// (I) unsigned integer (machine dependent size and byte order)
|
||||||
|
fwrite($fp, pack('I', 0)); // produces 4 bytes
|
||||||
|
|
||||||
|
$uiCS = 0b00000000000000000000000000000000;
|
||||||
|
|
||||||
|
// this is the whole checksum calculation
|
||||||
|
for ($j = 1; $j <= $iSize; ++$j ){
|
||||||
|
$uiCS = (($uiCS << 1)|( $uiCS >> 31)) + decbin($pucData[$j]);
|
||||||
|
// dump(decbin($pucData[$j]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dump(decbin($uiCS));
|
||||||
|
|
||||||
|
//fseek($fp, 12);
|
||||||
|
//fwrite($fp, pack('I', $uiCS));
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek($fp, 347);
|
||||||
|
fwrite($fp, pack('C', 0xFD));
|
||||||
|
fseek($fp, 348);
|
||||||
|
fwrite($fp, pack('C', 0x9F));
|
||||||
|
|
||||||
|
checksum($fp, $pucData, $filesize);
|
||||||
|
|
||||||
fseek($fp, 4);
|
|
||||||
fwrite($fp, "__");
|
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user