Added D2Strings class to get strings where needed from strings table

This commit is contained in:
Hash Borgir 2022-06-20 21:21:02 -06:00
parent ade44ff427
commit 5907c8c8d3
3 changed files with 149 additions and 142 deletions

255
index.php
View File

@ -1,6 +1,5 @@
<?php <?php
session_start(); session_start();
/* /*
@ -49,65 +48,56 @@ error_reporting(E_ALL ^ E_WARNING);
ini_set('log_errors', 1); ini_set('log_errors', 1);
include "./_pdo.php"; include "./_pdo.php";
include "./config.php"; include "./config.php";
require_once "./vendor/autoload.php"; require_once "./vendor/autoload.php";
if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SESSION['modname'] . ".db"))) { if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SESSION['modname'] . ".db"))) {
// first load, no active mod, go to switchmods to select mod // first load, no active mod, go to switchmods to select mod
header("Location: /switchMods.php"); header("Location: /switchMods.php");
} else { } else {
PDO_Connect("sqlite:" . APP_DB);
$sql = "SELECT * FROM D2Modder ORDER BY lastused DESC LIMIT 1";
$lastUsedMod = PDO_FetchRow($sql);
PDO_Connect("sqlite:" . APP_DB); $_SESSION['modname'] = $lastUsedMod['modname'];
$sql = "SELECT * FROM D2Modder ORDER BY lastused DESC LIMIT 1"; $_SESSION['path'] = $lastUsedMod['path'];
$lastUsedMod = PDO_FetchRow($sql); $sql = "SELECT theme FROM `D2Modder` WHERE `modname`='{$_SESSION['modname']}'";
$res = PDO_FetchAll($sql);
$_SESSION['modname'] = $lastUsedMod['modname']; if ($res[0]['theme'] == 1) {
$_SESSION['path'] = $lastUsedMod['path']; $css = 'dark.css';
} else {
$css = '';
}
$sql = "SELECT theme FROM `D2Modder` WHERE `modname`='{$_SESSION['modname']}'"; define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
$res = PDO_FetchAll($sql); define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']);
if ($res[0]['theme'] == 1) { require_once "./src/D2Functions.php";
$css = 'dark.css'; require_once "./src/D2Database.php";
} else { require_once './src/D2Files.php';
$css = ''; require_once './src/D2TxtParser.php';
} require_once './src/D2ItemDesc.php';
require_once './src/D2Char.php';
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']);
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
require_once './src/D2ItemDesc.php';
require_once './src/D2Char.php';
require_once './src/D2CharStructureData.php'; require_once './src/D2CharStructureData.php';
$D2Files = new D2Files();
$charFiles = $D2Files->getSaveFiles();
$D2Files = new D2Files(); foreach ($charFiles as $charFile) {
$charFiles = $D2Files->getSaveFiles();
foreach($charFiles as $charFile){
$charData[] = new D2Char($charFile); // $charData goes into chars.php tab $charData[] = new D2Char($charFile); // $charData goes into chars.php tab
} }
// dump($charData[0]->charData); // dump($charData[0]->charData);
// dump($charData[1]->charData); // dump($charData[1]->charData);
// die(); // die();
$idesc = new D2ItemDesc(); $idesc = new D2ItemDesc();
$db = new D2Database(); $db = new D2Database();
$parser = new D2TxtParser(); $parser = new D2TxtParser();
// $a = ["bighead1","fallen1","corruptrogue1","goatman1","fallenshaman1","fetish1","cr_archer1","cr_lancer1","vulture1","bloodraven","andariel","smith","vulture1","blunderbore1","duriel","fetishshaman1","councilmember1","mephisto","megademon1","regurgitator1","diablo","hephasto","vilemother1","vilechild1","overseer1","imp1","succubus1","succubuswitch1","putriddefiler1","painworm1","minion1","baalcrab"]; // $a = ["bighead1","fallen1","corruptrogue1","goatman1","fallenshaman1","fetish1","cr_archer1","cr_lancer1","vulture1","bloodraven","andariel","smith","vulture1","blunderbore1","duriel","fetishshaman1","councilmember1","mephisto","megademon1","regurgitator1","diablo","hephasto","vilemother1","vilechild1","overseer1","imp1","succubus1","succubuswitch1","putriddefiler1","painworm1","minion1","baalcrab"];
// //
@ -120,8 +110,8 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
$armor = PDO_FetchAll('SELECT * FROM armor WHERE spawnable=1'); $armor = PDO_FetchAll('SELECT * FROM armor WHERE spawnable=1');
$misc = PDO_FetchAll('SELECT * FROM misc WHERE spawnable=1 $misc = PDO_FetchAll('SELECT * FROM misc WHERE spawnable=1
AND type <> "stst" AND type <> "stst"
AND type <> "sum0" AND type <> "sum0"
AND type <> "prtl" AND type <> "prtl"
@ -132,116 +122,113 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
AND type <> "key" AND type <> "key"
AND type <> "body" AND type <> "body"
'); ');
$weapon = PDO_FetchAll('SELECT * FROM weapons WHERE spawnable=1'); $weapon = PDO_FetchAll('SELECT * FROM weapons WHERE spawnable=1');
$uniqueitems = PDO_FetchAll("SELECT `index`,`code` FROM uniqueitems WHERE `enabled`='1' ORDER BY `index` ASC"); $uniqueitems = PDO_FetchAll("SELECT `index`,`code` FROM uniqueitems WHERE `enabled`='1' ORDER BY `index` ASC");
$prop = $parser->filterProps('Properties.txt'); $prop = $parser->filterProps('Properties.txt');
// If there's data, process it and save // If there's data, process it and save
if (!empty($_POST)) { if (!empty($_POST)) {
// save db name from post into conf file... why? // save db name from post into conf file... why?
require_once './src/D2Char.php'; require_once './src/D2Char.php';
$saver = new D2Char(); $saver = new D2Char();
// process post // process post
// combine armor/weapon codes // combine armor/weapon codes
foreach ($_POST as $k => $v) { foreach ($_POST as $k => $v) {
$x = str_replace("_", " ", $k); $x = str_replace("_", " ", $k);
$post[$x] = $v; $post[$x] = $v;
} }
if (!empty($post['code'])) { if (!empty($post['code'])) {
array_filter($post['code']); array_filter($post['code']);
if (!empty($post['code'][0])) { if (!empty($post['code'][0])) {
$post['code'] = $post['code'][0]; $post['code'] = $post['code'][0];
} else { } else {
$post['code'] = $post['code'][1]; $post['code'] = $post['code'][1];
} }
} }
// last 3 items are not in d2 txt, rid of them // last 3 items are not in d2 txt, rid of them
// why did I set formtype? I can't rememer, need to comment code more // why did I set formtype? I can't rememer, need to comment code more
/* /*
* *
* *
* Unique Items Form was posted here * Unique Items Form was posted here
* *
*/ */
if ($_POST['formtype'] == "uniqueitems") { if ($_POST['formtype'] == "uniqueitems") {
unset($post['formtype']); unset($post['formtype']);
unset($post['submit']); unset($post['submit']);
unset($post['item']); unset($post['item']);
// if ladder or carry1 is 0, set empty field. // if ladder or carry1 is 0, set empty field.
if (!$post['ladder']) { if (!$post['ladder']) {
$post['ladder'] = ''; $post['ladder'] = '';
} }
if (!$post['carry1']) { if (!$post['carry1']) {
$post['carry1'] = ''; $post['carry1'] = '';
} }
ddump($post); ddump($post);
$sql = "SELECT rowid,`index` from `uniqueitems` WHERE `index`=\"{$post['index']}\"";
$res = PDO_FetchRow($sql);
if ($res['index'] == $post['index']) {
$sql = "UPDATE `uniqueitems` SET ";
foreach ($post as $k => $v) {
$sql .= "`$k`=\"$v\",";
}
$sql = rtrim($sql, ",");
$sql .= ' WHERE `index`="' . $post['index'] . '"';
PDO_Execute($sql, [$post['index']]);
//ddump($x);
}
/*
*
*
* Set Items Form was posted here
*
*/ else {
$sql = "INSERT INTO `uniqueitems` (";
foreach ($post as $k => $v) {
$sql .= "`$k`,";
}
$sql = rtrim($sql, ",");
$sql .= ") VALUES (";
foreach ($post as $k => $v) {
$sql .= "'$v',";
}
$sql = rtrim($sql, ",");
$sql .= ")";
ddump($sql);
// $saver->save($u, $post);
// $saver->saveTblEnries("UniqueItems.tbl.txt");
}
}
if ($_POST['formtype'] == "setitems") {
$saver->save($s, $post);
$saver->saveTblEnries("SetItems.tbl.txt");
}
}
$sql = "SELECT rowid,`index` from `uniqueitems` WHERE `index`=\"{$post['index']}\""; // load app
require_once './src/index.php';
$res = PDO_FetchRow($sql);
if ($res['index'] == $post['index']) {
$sql = "UPDATE `uniqueitems` SET ";
foreach ($post as $k => $v) {
$sql .= "`$k`=\"$v\",";
}
$sql = rtrim($sql, ",");
$sql .= ' WHERE `index`="'.$post['index'].'"';
PDO_Execute($sql, [$post['index']]);
//ddump($x);
}
/*
*
*
* Set Items Form was posted here
*
*/ else {
$sql = "INSERT INTO `uniqueitems` (";
foreach ($post as $k => $v) {
$sql .= "`$k`,";
}
$sql = rtrim($sql, ",");
$sql .= ") VALUES (";
foreach ($post as $k => $v) {
$sql .= "'$v',";
}
$sql = rtrim($sql, ",");
$sql .= ")";
ddump($sql);
// $saver->save($u, $post);
// $saver->saveTblEnries("UniqueItems.tbl.txt");
}
}
if ($_POST['formtype'] == "setitems") {
$saver->save($s, $post);
$saver->saveTblEnries("SetItems.tbl.txt");
}
}
// load app
require_once './src/index.php';
} }
?> ?>

View File

@ -3,10 +3,12 @@
require_once 'D2CharStructureData.php'; require_once 'D2CharStructureData.php';
require_once 'D2Files.php'; require_once 'D2Files.php';
require_once 'D2BitReader.php'; require_once 'D2BitReader.php';
require_once 'D2Strings.php';
class D2Char { class D2Char {
public $cData; // char data output public $cData; // char data output
public $items; // char item data
private $sData; // char file structure data private $sData; // char file structure data
private $bData; // char binary data from d2s private $bData; // char binary data from d2s
private $filePath; // .d2s file path private $filePath; // .d2s file path
@ -23,8 +25,13 @@ class D2Char {
fseek($this->fp, $k); fseek($this->fp, $k);
$this->bData[$k] = fread($this->fp, $v); $this->bData[$k] = fread($this->fp, $v);
} }
$this->strings = new D2Strings();
return $this->parseChar(); return $this->parseChar();
}
public function parseItems(){
} }
public function parseChar() { public function parseChar() {
@ -69,6 +76,8 @@ class D2Char {
$cData['NPCIntroductions'] = $this->bData[714]; $cData['NPCIntroductions'] = $this->bData[714];
$cData['filePath'] = $this->filePath; $cData['filePath'] = $this->filePath;
$this->cData = $cData; $this->cData = $cData;
$this->parseItems();
return $this->cData; return $this->cData;
} }

11
src/D2Strings.php Normal file
View File

@ -0,0 +1,11 @@
<?php
class D2Strings {
public array $strings;
public function __construct(){
$sql = "SELECT * FROM strings";
$this->strings = PDO_FetchAssoc($sql);
return $this->strings;
}
}