Item Preview Done. Todo: Stat Rendering

This commit is contained in:
color.diff=auto
2021-05-02 05:35:38 -06:00
parent 65b3980c44
commit efa7f8f28e
987 changed files with 816 additions and 122 deletions

View File

@@ -55,12 +55,17 @@ if (!empty($_POST)) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = rtrim($_POST['path'], "\\");
$path = str_replace("\\", "\\\\", $path);
$tbl = '\\\\data\\\\local\\\\lng\\\\eng\\\\';
$path .= '\\\\data\\\\global\\\\excel\\\\';
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
path VARCHAR(255),
tbl VARCHAR(255),
lastused INT,
theme INT
)";
@@ -74,23 +79,31 @@ ERROR: INVALID PATH</h1></center>';
} else {
// set this mod to active mod in session
$_SESSION['path'] = $path;
$_SESSION['tbl'] = $tbl;
// Don't yell at me, security is the least of my considerations atm
// check modname in db
$sql = "SELECT * FROM `D2Modder` WHERE `modname`='$modname'";
$res = PDO_FetchAll($sql);
if (empty($res)) {
$sql = "INSERT INTO D2Modder(`modname`,`path`,`lastused`) VALUES(\"$modname\",\"$path\",$time)";
$sql = "INSERT INTO D2Modder(`modname`,`path`,`tbl`,`lastused`) VALUES(\"$modname\",\"$path\",\"$tbl\",$time)";
PDO_Execute($sql);
}
header("Location: /processFiles.php");
}
} else {
/*
ELSE BLOCK FOR LINUX TESTING
*/
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
path VARCHAR(255),
tbl VARCHAR(255),
lastused INT,
theme INT
)";
@@ -107,12 +120,13 @@ ERROR: INVALID PATH</h1></center>';
} else {
// set this mod to active mod in session
$_SESSION['path'] = $path;
$_SESSION['tbl'] = $path;
// Don't yell at me, security is the least of my considerations atm
// check modname in db
$sql = "SELECT * FROM `D2Modder` WHERE modname='$modname'";
$res = PDO_FetchAll($sql);
if (empty($res)) {
$sql = "INSERT INTO `D2Modder` (`modname`,`path`,`lastused`) VALUES(\"$modname\",\"$path\",$time)";
$sql = "INSERT INTO `D2Modder` (`modname`,`path`,`tbl`,`lastused`) VALUES(\"$modname\",\"$path\",\"$path\",$time)";
PDO_Execute($sql);
}
header("Location: /processFiles.php");

View File

@@ -2,43 +2,43 @@
/*
Copyright (C) 2021 Hash Borgir
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@@ -86,7 +86,7 @@ class D2Database {
}
}
}
if (!empty($data)) {
$sql .= "VALUES ";
foreach ($data as $d) {
@@ -100,9 +100,68 @@ class D2Database {
}
}
$sql = rtrim($sql, ", ");
$sql .= ";";
PDO_Execute($sql);
$res = PDO_Execute($sql);
}
}
public function writeTbl($data) {
$sql = 'CREATE TABLE IF NOT EXISTS `strings` (`Key` VARCHAR(255), `String` VARCHAR(255));';
$res = PDO_Execute($sql);
$sql = "INSERT INTO `strings` (`Key`,`String`) VALUES ";
foreach ($data as $k => $v) {
$sql .= "(\"$k\",\"$v\"),";
}
$sql = rtrim($sql, ", ");
$sql .= ";";
$res = PDO_Execute($sql);
}
public function getString($key) {
$sql = "SELECT String FROM `strings` WHERE `Key`='$key'";
$res = PDO_FetchRow($sql);
return $res;
}
public function getIscStrings($iscStat) {
$sql = "
SELECT
(
SELECT String
FROM itemstatcost as i
LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
WHERE `Stat` = '$iscStat'
)
AS string1,
(
SELECT String
FROM itemstatcost as i
LEFT JOIN strings AS `s` ON `i`.DescStr2 = `s`.`Key`
WHERE `Stat` = '$iscStat'
)
AS string2,
(
SELECT descfunc
FROM itemstatcost as i
LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
WHERE `Stat` = '$iscStat'
)
AS descfunc,
(
SELECT descval
FROM itemstatcost as i
LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
WHERE `Stat` = '$iscStat'
)
AS descval
";
return PDO_FetchRow($sql);
}
}

261
src/D2ItemDesc.php Normal file
View File

@@ -0,0 +1,261 @@
<?php
/*
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class D2ItemDesc {
/*
DescFunc: the function used for generating the description for this stat, this works like the descfuncs in SkillDesc.txt pretty much. See below for an explanation of individual functions, these are listed the way they would show up if DescVal is set to 1. This follows the syntax Char used in the old fileguide, but includes the functions he didn't cover.
1 - +[value] [string1]
2 - [value]% [string1]
3 - [value] [string1]
4 - +[value]% [string1]
5 - [value*100/128]% [string1]
6 - +[value] [string1] [string2]
7 - [value]% [string1] [string2]
8 - +[value]% [string1] [string2]
9 - [value] [string1] [string2]
10 - [value*100/128]% [string1] [string2]
11 - Repairs 1 Durability In [100 / value] Seconds
12 - +[value] [string1]
13 - +[value] to [class] Skill Levels
14 - +[value] to [skilltab] Skill Levels ([class] Only)
15 - [chance]% to case [slvl] [skill] on [event]
16 - Level [sLvl] [skill] Aura When Equipped
17 - [value] [string1] (Increases near [time])
18 - [value]% [string1] (Increases near [time])
19 - this is used by stats that use Blizzard's sprintf implementation (if you don't know what that is, it won't be of interest to you eitherway I guess), look at how prismatic is setup, the string is the format that gets passed to their sprintf spinoff.
20 - [value * -1]% [string1]
21 - [value * -1] [string1]
22 - [value]% [string1] [montype] (warning: this is bugged in vanilla and doesn't work properly, see CE forum)
23 - [value]% [string1] [monster]
24 - used for charges, we all know how that desc looks
25 - not used by vanilla, present in the code but I didn't test it yet
26 - not used by vanilla, present in the code but I didn't test it yet
27 - +[value] to [skill] ([class] Only)
28 - +[value] to [skill]
DescVal: Controls whenever and if so in what way the stat value is shown,
* 0 = doesn't show the value of the stat,
* 1 = shows the value of the stat infront of the description,
* 2 = shows the value of the stat after the description.
DescStrPos: The string used for the description when the stat value is positive.
DescStrNeg: The string used for the description when the stat value is negative.
DescStr2: An additional string used by some DescFuncs, usually used as a suffix or for aditional info (such as per character level etc).
*
*
*
* DATA SAMPLE
*
*
*
array (size=174)
'item_absorbcold' =>
array (size=6)
'Stat' => string 'item_absorbcold' (length=15)
'ID' => string '149' (length=3)
'descfunc' => string '1' (length=1)
'descval' => string '1' (length=1)
'descstrpos' => string 'ModStr5n' (length=8)
'String' => string 'Cold Absorb' (length=11)
'item_absorbcold_percent' =>
array (size=6)
'Stat' => string 'item_absorbcold_percent' (length=23)
'ID' => string '148' (length=3)
'descfunc' => string '2' (length=1)
'descval' => string '2' (length=1)
'descstrpos' => string 'ModStr5m' (length=8)
'String' => string 'Cold Absorb' (length=11)
'item_absorb_cold_perlevel' =>
array (size=6)
'Stat' => string 'item_absorb_cold_perlevel' (length=25)
'ID' => string '234' (length=3)
'descfunc' => string '6' (length=1)
'descval' => string '1' (length=1)
'descstrpos' => string 'ModStre9p' (length=9)
'String' => string 'Absorbs Cold Damage' (length=19)
'item_absorbfire' =>
array (size=6)
'Stat' => string 'item_absorbfire' (length=15)
'ID' => string '143' (length=3)
'descfunc' => string '1' (length=1)
'descval' => string '1' (length=1)
'descstrpos' => string 'ModStr5h' (length=8)
'String' => string 'Fire Absorb' (length=11)
*
*
*/
public $str = '';
// takes value, param.
// value == Value to show on this stat
public function getDesc($value, $params = []){
if (empty($params)) return false;
$v = $value;
$s1 = $params['string1'];
$s2 = $params['string2'];
if ($params['descfunc'] == 1) {
$this->str = "+$v $s1";
}
if ($params['descfunc'] == 2) {
$this->str = "$v% $s1";
}
if ($params['descfunc'] == 3) {
$this->str = "$v $s1";
}
if ($params['descfunc'] == 4) {
$this->str = "+$v% $s1";
}
if ($params['descfunc'] == 5) {
$this->str = ($v*100/128)." $s1";
}
if ($params['descfunc'] == 6) {
$this->str = "+$v $s1 $s2";
}
if ($params['descfunc'] == 7) {
$this->str = "$v% $s1 $s2";
}
if ($params['descfunc'] == 8) {
$this->str = "+$v% $s1 $s2";
}
if ($params['descfunc'] == 9) {
$this->str = "$v $s1 $s2";
}
if ($params['descfunc'] == 10) {
$this->str = ($v*100/128)." $s1 $s2";
}
if ($params['descfunc'] == 11) {
$this->str = "Repairs 1 Durability In ".(100/$value)." seconds";
}
if ($params['descfunc'] == 12) {
$this->str = "+$v $s1";
}
if ($params['descfunc'] == 13) {
$this->str = "+$v to [class] Skill Levels";
}
if ($params['descfunc'] == 14) {
$this->str = "+$v to [skilltab] Skill Levels ([class] Only)";
}
if ($params['descfunc'] == 15) {
$this->str = "[chance]% to case [slvl] [skill] on [event]";
}
if ($params['descfunc'] == 16) {
$this->str = "Level [sLvl] [skill] Aura When Equipped ";
}
if ($params['descfunc'] == 17) {
$this->str = "$v $s1 (Increases near [time])";
}
if ($params['descfunc'] == 18) {
$this->str = "$v% $s1 (Increases near [time])";
}
if ($params['descfunc'] == 19) {
$this->str = "";
}
if ($params['descfunc'] == 20) {
$this->str = ($v* -1) ."% $s1";
}
if ($params['descfunc'] == 21) {
$this->str = ($v* -1) ." $s1";
}
if ($params['descfunc'] == 22) {
$this->str = "$v% $s1 [MonType]";
}
if ($params['descfunc'] == 23) {
$this->str = "$v% $s1 [Monster]";
}
if ($params['descfunc'] == 24) {
$this->str = "+$v to Skill Charges Or Something";
}
if ($params['descfunc'] == 25) {
$this->str = "";
}
if ($params['descfunc'] == 26) {
$this->str = "";
}
if ($params['descfunc'] == 27) {
$this->str = "+$v to [skill] ([class] Only)";
}
if ($params['descfunc'] == 28) {
$this->str = "+$v to [skill] ";
}
return $this->str;
}
}

94
src/D2Tbl.php Normal file
View File

@@ -0,0 +1,94 @@
<?php
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)
{
// Check file
if(!file_exists($filePath) || !is_readable($filePath)) {
return false;
}
// Read file
$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++) {
$unpack = unpack('S', substr($fileData, $offset, 2));
$offsets[] = $unpack[1];
$offset += 2;
}
// Initialize array
$strings = array();
// Read elements
for($i = 0; $i < $elementsNumber; $i++) {
$currentOffset = ($offset + ($offsets[$i] * 17));
// Skip 7 bytes
$currentOffset += 7;
// Key offset
$unpack = unpack('L', substr($fileData, $currentOffset, 4));
$currentOffset += 4;
$keyOffset = $unpack[1];
// String offset
$unpack = unpack('L', substr($fileData, $currentOffset, 4));
$currentOffset += 4;
$stringOffset = $unpack[1];
// Key length
$keyLength = ($stringOffset - $keyOffset);
// String length
$unpack = unpack('S', substr($fileData, $currentOffset, 2));
$stringLength = $unpack[1];
// Read key
$key = trim(substr($fileData, $keyOffset, $keyLength));
// Read string
$string = trim(substr($fileData, $stringOffset, $stringLength));
// Replace special characters
if($replaceSpecialCharacters) {
$key = self::replaceSpecialCharacters($key);
$string = self::replaceSpecialCharacters($string);
}
// Add string
$strings[$key] = $string;
}
return $strings;
}
/**
* 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

@@ -1,11 +1,19 @@
<div style="height: 40px; margin: 40px 10px;"><h2>Unique Item Maker</h2></div>
<div class="row" style="margin:40px;">
<div class="col" style="text-align: center;">
<p>Search for Item</p>
<input style="border: 1px solid #999; padding: 10px;width: 420px;" id="search" type="text custom-control-inline" placeholder="Search item" name="search">
<div class="row">
<div class="offset-6 col"><h3 style="font-family:fixed; font-size:80%;">Preview</h3>
<div class="" style="height: 117px; background: url(/img/items/bg.png) no-repeat">
<img style="" class="item" src="">
</div>
</div>
</div>
<div class="row" style="margin-bottom:40px;">
<div class="col" style="">
<p>Search for Item</p>
<input style="border: 1px solid #999; padding: 10px;width: 440px;" id="search" type="text custom-control-inline" placeholder="Search item" name="search">
</div>
</div>
<div class="row" style="">
<div class="col-5">
<select name="uniqueitems" class="custom-select uniqueitems-select">
@@ -127,7 +135,7 @@
<div class="col-2" style="background: #dec;">
<p>Rarity</p>
<div class="input-group">
<input name="rarity" type="text" aria-describedby="rarityHelpBlock" required="required" class="form-control">
<input name="rarity" type="text" aria-describedby="rarityHelpBlock" class="form-control">
</div><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
</span>
<span class="form-text">Rarity: chance to pick this unique item if more then one unique item of the same base item exist, this uses the common rarity/total_rarity formula, so if you have two unique rings, one with a rarity of 100 the other with a rarity of 1, then the first will drop 100/101 percent of the time (99%) and the other will drop 1/101 percent of the time (1%), rarity can be anything between 1 and 255 (rarity of less then 1 will be set to 1 by the code).</span>
@@ -155,7 +163,7 @@
<div class="col-2" style="background: #edd;">
<p>LvlReq</p>
<input name="lvlreq" type="text" aria-describedby="lvlreqHelpBlock" required="required" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
<input name="lvl req" type="text" aria-describedby="lvlreqHelpBlock" required="required" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
</span>
<span class="form-text">Lvl Req: the character level required to use this unique item.</span>
</div>
@@ -203,8 +211,8 @@
</select>
</div>
<input type="hidden" name="type" value=""> <br>
<input type="hidden" name="uber" value=""><br>
<input type="hidden" name="*type" value=""> <br>
<input type="hidden" name="*uber" value=""><br>
<div class="col-2" style="background: #edf;">
<p>Carry 1</p>
<select name="carry1" class="custom-select" aria-describedby="carry1HelpBlock">
@@ -220,7 +228,7 @@
<div class="col-2" style="background: #def;">
<p>CostMult</p>
<input value="" name="costmult" type="text" aria-describedby="costmultHelpBlock" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
<input value="" name="cost mult" type="text" aria-describedby="costmultHelpBlock" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
</span>
<span class="form-text">Cost Mult: the base item's price is multiplied by this value when sold, repaired or bought from a vendor.</span>
</div>
@@ -228,7 +236,7 @@
<div class="col-2" style="background: #def;">
<p>CostAdd</p>
<input value="" name="costadd" type="text" aria-describedby="costaddHelpBlock" required="required" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
<input value="" name="cost add" type="text" aria-describedby="costaddHelpBlock" class="form-control"><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
</span>
<span class="form-text">Cost Add: after the price has been multiplied, this amount of gold is added to the price on top.</span>
</div>
@@ -293,7 +301,7 @@
foreach (range(01, 12) as $p) {
?>
<div class="col-2" style="padding: 15px;margin: 10px 0px; background: #ddd;">
<div class="col-2" style="background: #ddd;">
<p>Prop <?php echo $p ?>:</p>
<select class="custom-select prop<?php echo $p ?>-select" name="prop<?php echo $p ?>">
<option class="PropFirst" value=""></option>