-
Notifications
You must be signed in to change notification settings - Fork 13
d2char method
HarpyWar edited this page Jan 16, 2019
·
3 revisions
This method allows you to:
- Edit Diablo 2 charsave files (modify a flag like died or ladder, change name, delete/add items, etc)
- Edit Diablo 2 single items pulled from charsave
- Edit D2DBS charinfo files
Diablo 2 Character Editor is an example of usage.
Send a file and return json object which can be edited and send back to [PUT] method to get modified file.
fileType
allowed values are [charinfo
, charsave
, charitem
] depending on appropriated file format which you upload.
For example, if you want parse charsave file then upload in onto URL https://api.pvpgn.pro/d2char?type=charsave
Returned object also depends on the uploaded file type:
PHP Example
<?php
define('MULTIPART_BOUNDARY', '--------------------------' . microtime(true));
$url = "https://api.pvpgn.pro/d2char";
$filename = "aerobus.d2s";
$file_contents = file_get_contents($filename);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary=' . MULTIPART_BOUNDARY,
'content' => "--" . MULTIPART_BOUNDARY . "\r\n" .
"Content-Disposition: form-data; name=\"file\"; filename=\"" . basename($filename) . "\"\r\n" .
"Content-Type: application/octet-stream\r\n\r\n" .
$file_contents ."\r\n--" . MULTIPART_BOUNDARY . "--\r\n",
)
));
// execute request
$response = file_get_contents($url, false, $context);
// print json result
print_r($response);
Send returned json object from the [POST] method and return bytes of the generated file.
PHP Example
// continue of the above example where $response is returned json string
...
// convert string to json object to get only "data" field
$json = json_decode($response);
$charsave = $json->data;
// edit some data, for example character name
$charsave->name = "hello world";
// convert json object to string
$json_data = json_encode($charsave);
$context = stream_context_create([
'http' => [
'method' => 'PUT',
'header' => "Content-type: application/json\r\n" .
"Accept: application/json\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($json_data) . "\r\n",
'protocol_version' => 1.1,
'content' => $json_data
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
// send request
$file_contents_new = file_get_contents($url, false, $context);
// save response bytes into a file
file_put_contents("newchar.d2s", $file_contents_new);