mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-10-14 00:44:23 -05:00
TBL editor working, saves to txt file, DB, TBL, works in game
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
<?php
|
||||
|
||||
class D2Tbl
|
||||
{
|
||||
class D2Tbl {
|
||||
|
||||
/**
|
||||
* Get strings from tbl file, based on "credits/EnquettarM.pl" script (more info can be found there).
|
||||
* Credits to Ondo and Mephansteras.
|
||||
*
|
||||
* @param mixed $filePath
|
||||
* @param mixed $replaceSpecialCharacters
|
||||
*/
|
||||
public static function getStrings($filePath, $replaceSpecialCharacters = true)
|
||||
{
|
||||
* Get strings from tbl file, based on "credits/EnquettarM.pl" script (more info can be found there).
|
||||
* Credits to Ondo and Mephansteras.
|
||||
*
|
||||
* @param mixed $filePath
|
||||
* @param mixed $replaceSpecialCharacters
|
||||
*/
|
||||
public static function getStrings_backup($filePath, $replaceSpecialCharacters = true) {
|
||||
// Check file
|
||||
if(!file_exists($filePath) || !is_readable($filePath)) {
|
||||
if (!file_exists($filePath) || !is_readable($filePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,17 +19,15 @@ class D2Tbl
|
||||
$fileData = file_get_contents($filePath);
|
||||
|
||||
// Skip: 0 - 1
|
||||
|
||||
// Get elements number
|
||||
$unpack = unpack('S', substr($fileData, 2, 2));
|
||||
$elementsNumber = $unpack[1];
|
||||
|
||||
// Skip: 4 - 20
|
||||
|
||||
// Get offsets
|
||||
$offset = 21;
|
||||
$offsets = array();
|
||||
for($i = 0; $i < $elementsNumber; $i++) {
|
||||
for ($i = 0; $i < $elementsNumber; $i++) {
|
||||
$unpack = unpack('S', substr($fileData, $offset, 2));
|
||||
$offsets[] = $unpack[1];
|
||||
$offset += 2;
|
||||
@@ -40,7 +37,7 @@ class D2Tbl
|
||||
$strings = array();
|
||||
|
||||
// Read elements
|
||||
for($i = 0; $i < $elementsNumber; $i++) {
|
||||
for ($i = 0; $i < $elementsNumber; $i++) {
|
||||
$currentOffset = ($offset + ($offsets[$i] * 17));
|
||||
|
||||
// Skip 7 bytes
|
||||
@@ -70,7 +67,7 @@ class D2Tbl
|
||||
$string = trim(substr($fileData, $stringOffset, $stringLength));
|
||||
|
||||
// Replace special characters
|
||||
if($replaceSpecialCharacters) {
|
||||
if ($replaceSpecialCharacters) {
|
||||
$key = self::replaceSpecialCharacters($key);
|
||||
$string = self::replaceSpecialCharacters($string);
|
||||
}
|
||||
@@ -82,13 +79,36 @@ class D2Tbl
|
||||
return $strings;
|
||||
}
|
||||
|
||||
public static function getStrings($filePath) {
|
||||
$executablePath = getcwd() . "\bin\EnquettarM.exe";
|
||||
$processCommand = "{$executablePath} -e \"$filePath\"";
|
||||
shell_exec($processCommand);
|
||||
|
||||
$filePath = "ModString.txt";
|
||||
|
||||
$fileLines = file($filePath);
|
||||
|
||||
$rows = [];
|
||||
|
||||
$strings = [];
|
||||
foreach ($fileLines as $line) {
|
||||
$row = explode("\t", $line);
|
||||
$key = $row[0];
|
||||
$string = $row[1];
|
||||
|
||||
$strings[$key] = $string;
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace some special characters (\n, \t).
|
||||
*
|
||||
* @param mixed $text
|
||||
*/
|
||||
public static function replaceSpecialCharacters($text)
|
||||
{
|
||||
* Replace some special characters (\n, \t).
|
||||
*
|
||||
* @param mixed $text
|
||||
*/
|
||||
public static function replaceSpecialCharacters($text) {
|
||||
return str_replace(array("\n", "\t"), array("\\n", "\\t"), $text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user