mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 04:26:03 +00:00
PHP checksum working need to refactor and make more useful, easier to use, refactor lots of code
This commit is contained in:
parent
69d4728d8c
commit
3b03e54fa5
@ -87,10 +87,14 @@ function setBit(int $n, int $p, bool $b){
|
||||
function getBit(int $b, int $p){
|
||||
return intval(($b & (1 << $p)) !== 0);
|
||||
}
|
||||
|
||||
function checksum($fileData) {
|
||||
/**
|
||||
* Calculate D2S Checksum
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
function checksum($data) : string {
|
||||
$nSignature = 0;
|
||||
foreach($fileData as $byte){
|
||||
foreach($data as $byte){
|
||||
$nSignature = ((($nSignature << 1) | ($nSignature >> 31)) + $byte) & 0xFFFFFFFF;
|
||||
}
|
||||
return swapEndianness(dechex($nSignature));
|
||||
|
8
test.php
8
test.php
@ -6,9 +6,6 @@
|
||||
require_once './src/D2Functions.php';
|
||||
require_once './src/D2BitReader.php';
|
||||
|
||||
$file = "D:\Diablo II\MODS\ironman-dev\save\Barb.d2s";
|
||||
$data = file_get_contents($file);
|
||||
|
||||
class D2ByteReader {
|
||||
|
||||
private string $data;
|
||||
@ -157,6 +154,9 @@ class D2ByteReader {
|
||||
|
||||
}
|
||||
|
||||
$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);
|
||||
@ -174,5 +174,3 @@ $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
|
||||
|
||||
//shell_exec("bin\d2scs.exe \"$file\"");
|
Loading…
Reference in New Issue
Block a user