TBL editor working, saves to txt file, DB, TBL, works in game

This commit is contained in:
Hash Borgir
2023-06-14 02:40:21 -06:00
parent 29621fa46c
commit 9ed54b5d33
4 changed files with 466 additions and 63 deletions

View File

@@ -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);
}
}
}

View File

@@ -79,7 +79,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link" id="Chars-tab" data-toggle="tab" href="#Chars" role="tab" aria-controls="Chars" aria-selected="false">Character Editor</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="tbl-tab" data-toggle="tab" href="#Tbl" role="tab" aria-controls="Tbl" aria-selected="false">TBL Editor</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Doc-tab" data-toggle="tab" href="#Doc" role="tab" aria-controls="Doc" aria-selected="false">Documentation Generator</a>
</li>
@@ -116,6 +118,9 @@
<div class="tab-pane fade" id="Chars" role="tabpanel" aria-labelledby="Chars-tab">
<?php require_once 'tabs/Chars.php'; ?>
</div>
<div class="tab-pane fade" id="Tbl" role="tabpanel" aria-labelledby="Tbl-tab">
<?php require_once 'tabs/Tbl.php'; ?>
</div>
<div class="tab-pane fade" id="Debug" role="tabpanel" aria-labelledby="Debug-tab">
<?php require_once 'tabs/Debug.php'; ?>
</div>