Sunday, August 17, 2014

Some Silkroad workarounds

Silkroad workarounds will go in this blog message.

 Lets start with item variance parameter decoding. Code is pretty much hack-n-slash, but at least u can see how its made.

Here is way to decode item variance writen at PHP. Ye, u have to fix some lil shit, plus its writen asap... but it wont be hard to fix all the problems it has.

[item_stats.class.php]
<?php

class CItemInfo
{
private $m_ItemType = 0;
private $m_nCurParam = 0;
private $m_CurStatParams = array();

public static $s_WeaponStatNames =
array('Durability', 'PhyReinforce', 'MagReinforce', 'HitRatio', 'PhyAttack', 'MagAttack', 'CriticalRatio');

public static $s_EquipmentStatNames =
array('Durability', 'PhyReinforce', 'MagReinforce', 'PhyDefense', 'MagDefense', 'ParryRatio');

public static $s_ShieldStatNames =
array('Durability', 'PhyReinforce', 'MagReinforce', 'BlockRatio', 'PhyDefense', 'MagDefense');

public static $s_AccessoryStatNames =
array('PhyAbsorb', 'MagAbsorb');



public function __construct($item_type)
{
if($item_type > 3 || $item_type < 0) die("Item with type > 4 or < 0 !!1 (CItemInfo)!!");
$this -> m_ItemType = $item_type;
}

public function AddParam($param_value)
{
$this -> m_CurStatParams[$this -> m_nCurParam++] = $param_value;
}

public function GetParamCountForItem()
{
switch($this -> m_ItemType)
{
case 0:
{
return count(self::$s_WeaponStatNames);
}
break;
case 1:
{
return count(self::$s_EquipmentStatNames);
}
break;
case 2:
{
return count(self::$s_ShieldStatNames);
}
break;
case 3:
{
return count(self::$s_AccessoryStatNames);
}
break;
}
}

public function GetParams()
{
$result = array(array());



switch($this -> m_ItemType)
{
case 0:
{
for($i = 0; $i < count (self::$s_WeaponStatNames); $i++)
{
$result[$i] =
array(self::$s_WeaponStatNames[$i] => $this -> m_CurStatParams[$i]);
}
}
break;
case 1:
{
for($i = 0; $i < count (self::$s_EquipmentStatNames); $i++)
{
$result[$i] =
array(self::$s_EquipmentStatNames[$i] => $this -> m_CurStatParams[$i]);
}
}
break;
case 2:
{
for($i = 0; $i < count (self::$s_ShieldStatNames); $i++)
{
$result[$i] =
array(self::$s_ShieldStatNames[$i] => $this -> m_CurStatParams[$i]);
}
}
break;
case 3:
{
for($i = 0; $i < count (self::$s_AccessoryStatNames); $i++)
{
$result[$i] =
array(self::$s_AccessoryStatNames[$i] => $this -> m_CurStatParams[$i]);
}
}
break;
}
return $result;
}
}

class CItemClass
{

static $s_Instance;

private function __construct()
{

}

protected function __clone()
{

}

static public function Instance()
{
if(is_null(self::$s_Instance))
{
self::$s_Instance = new self();
}
return self::$s_Instance;
}

public function PercentageFromBitvalue($bitvalue)
{
return round(($bitvalue * 100 / 31) - 0.5 , 0);
}


public function GetVarianceDump($variance, $item_type_id)
{
$result = null;
$g_Item = new CItemInfo($item_type_id);

$n = 0;
$nParams = $g_Item -> GetParamCountForItem();
while($n < $nParams)
{
$cur_stat = $variance & 0x1F;
$g_Item -> AddParam($this -> PercentageFromBitvalue($cur_stat));
$variance >>= 5;
$n++;

}

//print_r($g_Item -> GetParams());
return $g_Item -> GetParams();
}
}
?>

Usage example:

[get_whitestats.php]

<html>
<head>
<title>ohai squirl</title>
</head>

<body>
<center>
<table border = '1' cellspacing = '2' cellpadding = '2'>
<form method='post'>
<td>Variance</td><td><input type='text' name='variance'></td><tr/>
<td>ItemType</td>
<td>
<select name = 'item_type'>
<option value='0'>Weapon</option>
<option value='1'>Armor</option>
<option value='2'>Shield</option>
<option value='3'>Accessory</option>
</select>
</td>
<td><input type='submit' value='Gib meh'></td>
</form>
</table>
</center>
</body>

</html>

<?php
if(!empty($_POST['variance']))
{
include('item_stats.class.php');

$instance = CItemClass::Instance();

//$a = (long) ($_POST['variance']);
print_r(
$instance -> GetVarianceDump((float)($_POST['variance']), $_POST['item_type'])
);
}
?>