Format updated for 0.5X - see here: http://en.lfsmanual.net/wiki/File_Formats#SET
<?php
php
/*
xergio - [email protected]
http://en.lfsmanual.net/wiki/User:xergio
http://en.lfsmanual.net/wiki/File_Formats#SET
http://www.lfsforum.net/showthread.php?t=14477
http://www.lfsforum.net/showthread.php?t=27054
*/
class PHPSET {
public $file;
public $headers;
public $fields;
function __construct($file) {
$this->file = trim($file);
$this->header_len = 12;
$this->body_len = 132 - $this->header_len; //132 char == \0
$this->parse();
}
public function parse($file = null) {
$this->stime = microtime(true);
if ($file) {
$this->file = trim($file);
}
if (!file_exists($this->file) or !is_file($this->file) or !preg_match('#\.set$#i', $this->file))
throw new Exception("SET not exists: ".basename($this->file)."");
if (!($f = fopen($this->file, 'rb')))
throw new Exception("Error opening ".basename($this->file)."");
if (!($header = fread($f, $this->header_len)))
throw new Exception("Error reading header");
$this->headers = new PHPSET_Header($header);
if (!($data = fread($f, $this->body_len)))
throw new Exception("Error reading data");
$this->fields = new PHPSET_Fields($data);
$this->etime = microtime(true);
$this->ptime = $this->etime - $this->stime;
if ($file) return $this;
}
}
class PHPSET_Data {
protected $data;
protected $value;
public function __set($name, $value) {
$class_name = 'PHPSET_'. $name;
if (class_exists($class_name))
$this->$name = new $class_name($value);
else if (is_string($value))
$this->$name = trim($value);
else
$this->$name = $value;
}
function __toString() {
if ($this->value) return $this->value;
return $this->data;
}
function translate($translations) {
$this->value = $translations[$this->data];
}
}
class PHPSET_Header extends PHPSET_Data {
function __construct($bin) {
$headers = unpack("A6SRSETT/x1/C1lfsInternalVersion/C1fileFormatVersion/x3", $bin);
foreach ((array)$headers as $header => $value) {
$this->$header = $value;
}
if ($this->SRSETT != 'SRSETT')
throw new Exception("File has not a valid SET format");
}
}
class PHPSET_Fields extends PHPSET_Data {
function __construct($bin) {
$fields = unpack("C1misc/C1unknown/C1handicapMassPosition/C1tyreBrand/f1brakeStrength/C1rearWingAngle/C1frontWingAngle/C1voluntaryHandicapMass/C1voluntaryIntakeRestriction/C1maxSteeringLock/C1parallelSteering/C1brakeBalance/C1engineBrakeReduction/C1centreDiffType/C1centreDiffViscousTorque/x1/C1centreDiffTorqueSplit/S1gearRatio7/S1gearRatioFinal/S1gearRatio1/S1gearRatio2/S1gearRatio3/S1gearRatio4/S1gearRatio5/S1gearRatio6/C1passenger/C1carConfig/C1tractionControlSlip/C1tractionControlEngageSpeed/frearTravel/frearSpring/frearComp/frearRebound/frearAR/x4/C1rearToe/C1rearCaster/C1rearTyreType/x1/C1LRcamberAdjust/C1RRcamberAdjust/x1/C1rearDiffClutchPack/C1rearDiffType/C1rearViscousTorque/C1rearPowerLocking/C1rearCoastLocking/S1LRtyrePressure/S1RRtyrePressure/ffrontTravel/ffrontSpring/ffrontComp/ffrontRebound/ffrontAR/x4/C1frontToe/C1frontCaster/C1frontTyreType/x1/C1LFcamberAdjust/C1RFcamberAdjust/x1/C1frontDiffClutchPack/C1frontDiffType/C1frontViscousTorque/C1frontPowerLocking/C1frontCoastLocking/S1LFtyrePressure/S1RFtyrePressure", $bin);
foreach ((array)$fields as $field => $value) {
$this->$field = $value;
}
}
}
class PHPSET_misc extends PHPSET_Data {
function __construct($data) {
$this->data = decbin($data);
}
}
class PHPSET_passenger extends PHPSET_Data {
function __construct($data) {
$this->data = decbin($data);
}
}
class PHPSET_tyreBrand extends PHPSET_Data {
function __construct($data) {
$this->data = $data;
$this->translate(array('Cromo Plain', 'Cromo', 'Torro', 'Michelin', 'Evostar'));
}
}
class PHPSET_centreDiffType extends PHPSET_Data {
function __construct($data) {
$this->data = $data;
$this->translate(array('Open', 'Viscous'));
}
}
class PHPSET_rearDiffType extends PHPSET_Data {
function __construct($data) {
$this->data = $data;
$this->translate(array('Open', 'Locked', 'Viscous', 'Clutch Pack'));
}
}
class PHPSET_frontDiffType extends PHPSET_rearDiffType {}
?>
<?php
php
require('phpset.php');
$set = new PHPSET('RB4_FE5r_test.set');
print_r($set);
?>
PHPSET Object
(
[file] => /home/salvarez/mch.lfsteam.es/forum/setups/store/RB4/FE5R/RB4_FE5r zarugor.set
[headers] => PHPSET_Header Object
(
[data:protected] =>
[value:protected] =>
[SRSETT] => SRSETT
[lfsInternalVersion] => 251
[fileFormatVersion] => 2
)
[fields] => PHPSET_Fields Object
(
[data:protected] =>
[value:protected] =>
[misc] => PHPSET_misc Object
(
[data:protected] => 10000100
[value:protected] =>
)
[unknown] => 0
[handicapMassPosition] => 50
[tyreBrand] => PHPSET_tyreBrand Object
(
[data:protected] => 3
[value:protected] => Michelin
)
[brakeStrength] => 920
[rearWingAngle] => 0
[frontWingAngle] => 0
[voluntaryHandicapMass] => 0
[voluntaryIntakeRestriction] => 0
[maxSteeringLock] => 30
[parallelSteering] => 0
[brakeBalance] => 72
[engineBrakeReduction] => 0
[centreDiffType] => PHPSET_centreDiffType Object
(
[data:protected] => 1
[value:protected] => Viscous
)
[centreDiffViscousTorque] => 20
[centreDiffTorqueSplit] => 39
[gearRatio7] => 0
[gearRatioFinal] => 32767
[gearRatio1] => 26214
[gearRatio2] => 16852
[gearRatio3] => 11047
[gearRatio4] => 7958
[gearRatio5] => 5243
[gearRatio6] => 3253
[passenger] => PHPSET_passenger Object
(
[data:protected] => 0
[value:protected] =>
)
[carConfig] => 0
[tractionControlSlip] => 20
[tractionControlEngageSpeed] => 5
[rearTravel] => 0.274268299341
[rearSpring] => 40000
[rearComp] => 4497.56103516
[rearRebound] => 5126.82910156
[rearAR] => 37000
[rearToe] => 6
[rearCaster] => 0
[rearTyreType] => 6
[LRcamberAdjust] => 20
[RRcamberAdjust] => 36
[rearDiffClutchPack] => 20
[rearDiffType] => PHPSET_rearDiffType Object
(
[data:protected] => 1
[value:protected] => Locked
)
[rearViscousTorque] => 20
[rearPowerLocking] => 80
[rearCoastLocking] => 80
[LRtyrePressure] => 162
[RRtyrePressure] => 165
[frontTravel] => 0.236869946122
[frontSpring] => 45000
[frontComp] => 4785.36572266
[frontRebound] => 6341.46337891
[frontAR] => 18000
[frontToe] => 10
[frontCaster] => 0
[frontTyreType] => 6
[LFcamberAdjust] => 29
[RFcamberAdjust] => 39
[frontDiffClutchPack] => 16
[frontDiffType] => PHPSET_frontDiffType Object
(
[data:protected] => 2
[value:protected] => Viscous
)
[frontViscousTorque] => 20
[frontPowerLocking] => 60
[frontCoastLocking] => 80
[LFtyrePressure] => 170
[RFtyrePressure] => 170
)
[header_len] => 12
[body_len] => 120
[stime] => 1266580405.69
[etime] => 1266580405.69
[ptime] => 0.000797033309937
)