2022-05-07 12:25:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
|
|
set_time_limit(-1);
|
|
|
|
ini_set('max_input_time', '-1');
|
|
|
|
ini_set('max_execution_time', '0');
|
|
|
|
session_start();
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
require_once './config.php';
|
|
|
|
require_once './_pdo.php';
|
|
|
|
require_once "./src/D2Functions.php";
|
|
|
|
require_once './src/D2ItemData.php';
|
|
|
|
require_once './src/D2ItemDesc.php';
|
|
|
|
require_once './src/D2DocGenerator.php';
|
|
|
|
|
|
|
|
define('DB_FILE', "ironman-dev.db");
|
|
|
|
PDO_Connect("sqlite:" . DB_FILE);
|
|
|
|
|
2022-05-15 02:14:49 +00:00
|
|
|
$filename = "D:\Diablo II\MODS\ironman-dev\save\Test.d2s";
|
|
|
|
$fp = fopen($filename, "rb+");
|
|
|
|
$filesize = filesize($filename);
|
|
|
|
$pucData = unpack("C*",file_get_contents($filename));
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-05-15 02:14:49 +00:00
|
|
|
// ddump($pucData);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
|
|
|
|
2022-05-15 02:14:49 +00:00
|
|
|
// ddump(fseek($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);
|
|
|
|
|
2022-05-07 12:25:27 +00:00
|
|
|
fclose($fp);
|