PDA

View Full Version : Spr file and player flags (driver settings)


zakret
3rd April 2009, 07:24
Hi

Could someone explain me how to read and understand player flags from spr file? I would like to read if driver used mouse or keyboard, braking help etc.

This is how I do it in php:

fseek($stream,132);
$player_flags = hexdec(bin2hex(fread($stream,1)));
$player_flags = unpack("C*",$player_flags);

fseek($stream,133);
$player_flags2 = hexdec(bin2hex(fread($stream,1)));
$player_flags2 = unpack("C*",$player_flags2);


After that when I print to screen I see for example:
playerFlags -> Array ( [1] => 55 [2] => 51 )
playerFlags2 -> Array ( [1] => 54 )

so playerFlags is 73 (from ascii code 55=7, 51=3) and playerFlags2 = 6

I don't know how to split those two values:
1.
73 = 64(Braking help) + 8(auto shift)+1(left hand drive)
6 = 4(gear change blip) + 2(gear change cut)

2.
736 = 512(auto clutch) + 128(axis clutch)+64(braking help)+32(reserved ?)

3.673 = 512(auto clutch) + 128(axis clutch) + 32(reserved ?) + 1(left hand drive)

Or maybe during reading,converting (unpack) file there is a bug?

Best Regards
Tomasz Zakrecki

Dygear
3rd April 2009, 13:41
function convert_flags_hlaps($flags_hlaps) {
$data = array();
if ($flags_hlaps & 1) $data[1] = 'LEFTHANDDRIVE';
if ($flags_hlaps & 2) $data[2] = 'GEARCHANGECUT';
if ($flags_hlaps & 4) $data[4] = 'GEARCHANGEBLIP';
if ($flags_hlaps & 8) $data[8] = 'AUTOGEAR';
if ($flags_hlaps & 16) $data[16] = 'SHIFTER';
if ($flags_hlaps & 64) $data[64] = 'BRAKEHELP';
if ($flags_hlaps & 128) $data[128] = 'AXISCLUTCH';
if ($flags_hlaps & 512) $data[512] = 'AUTOCLUTCH';
if ($flags_hlaps & 1024) $data[1024] = 'MOUSESTEER';
if ($flags_hlaps & 2048) $data[2048] = 'KN';
if ($flags_hlaps & 4096) $data[4096] = 'KS';
if (!($flags_hlaps & 7168)) $data[7168] = 'WHEEL';
return $data;
}

That's how we split the values into to there own data set from the LFSWorld SDK.

What your looking for is how to handle Bit Wise Operations in PHP (http://www.php.net/language.operators.bitwise)

zakret
5th April 2009, 21:11
Hi

Thank you for answer. But i have also a little problem with reading from file. I don't know how to exactly read player flags from file and convert it to input variable for Your function. I tried:


$stream = fopen($file,"rb"))
//1 word 132 player flags : driver settings (see NOTES)
fseek($stream,132);

$player_flags = bin2hex(fread($stream,2));
or
$player_flags = bin2hex(fread($stream,1));
or
$player_flags = unpack("v*",bin2hex(fread($stream,2)));
or
$player_flags = unpack("v*",bin2hex(fread($stream,1)));
or
$player_flags = unpack("h*",bin2hex(fread($stream,2)));
or
$player_flags = unpack("h*",bin2hex(fread($stream,2)));

$player_flags = convert_flags_hlaps($player_flags);
print_r($player_flags);


but results are wrong with some downloaded hotlap from lfsworld.net (on lfsworld.net page for this hotlap I see: mouse, break help, auto gear,auto clutch and left side) but my code for this hot lap shows me:Lefthand,shifter, wheel or right hand,gear change cut,auto gear,auto-clutch, KS. I tried many ways to read this but always wrong. Could You help?

filur
5th April 2009, 21:41
I don't know how to exactly read player flags from file

$player_flags = array_pop(unpack('v', fread($stream, 2)));

zakret
6th April 2009, 10:40
Thank You, very much. Now it works.

Best Regards
TZ