PDA

View Full Version : MPR - How to get laps done?


jscorrea
5th April 2006, 06:02
Hello all,

Look this code:

if(fread($rp, 6) == "LFSMPR")
{
fread($rp, 14);
$r["ringe"] = hexdec(bin2hex(fread($rp, 1)));
$r["skill"] = hexdec(bin2hex(fread($rp, 1)));
$r["tuul"] = hexdec(bin2hex(fread($rp, 1)));
$r["wind"] = hexdec(bin2hex(fread($rp, 1)));
$r["version"] = trim(fread($rp, 8));

fread($rp, 8);
$area = trim(fread($rp, 32));
$config = hexdec(bin2hex(fread($rp, 1)));
$reversed = hexdec(bin2hex(fread($rp, 1)));

$r["ilm"] = hexdec(bin2hex(fread($rp, 1)));
$r["rada"] = $areas[$area].$config.($reversed ? "r" : "");

$finished = hexdec(bin2hex(fread($rp, 1)));

fread($rp, 4);

for($i = 0; $i < $finished; $i++)
{
$o[$i]["soitja"] = trim(fread($rp, 24));
$o[$i]["plate"] = trim(fread($rp, 8));
$o[$i]["auto"] = trim(fread($rp, 32));
//$o[$i]["laps_c"] = hexdec(bin2hex(fread($rp, 1)));
fread($rp, 1);
$o[$i]["pits"] = hexdec(bin2hex (fread($rp, 1). $pits[$i]));
fread($rp, 1);
$o[$i]["maha"] = hexdec(bin2hex(fread($rp, 1)));
$o[$i]["lopp"] = msht2int(fread($rp, 4));
$o[$i]["parim"] = msht2int(fread($rp, 4));

fread($rp, 4);
}
}
In which place of this code do I insert to obtain laps completed for each racer?

Sorry for my english...

Regards:thumb:

colcob
5th April 2006, 19:30
Is this your code, or have you got it from somewhere. Because just glancing at it, it looks like you just need to uncomment the line \\$o[$i]["laps_c"] = hexdec(bin2hex(fread($rp, 1)));

jscorrea
5th April 2006, 19:36
Sorry,

I was not very clearly.

How to include a line in my code that it allows to show the numbers to me of laps completed of each players?

JS

jscorrea
5th April 2006, 19:38
Is this your code, or have you got it from somewhere. Because just glancing at it, it looks like you just need to uncomment the line \\$o[$i]["laps_c"] = hexdec(bin2hex(fread($rp, 1)));


This line was created by me Col, if uncommnet give error.

JS

jscorrea
5th April 2006, 19:54
A piece of PHP code:

for($i = 0; $i < $finished; $i++)
{
$o[$i]["player_name"] = trim(fread($rp, 24));
$o[$i]["plate"] = trim(fread($rp, 8));
$o[$i]["car"] = trim(fread($rp, 32));
//$o[$i]["laps_c"] = hexdec(bin2hex(fread($rp, 1)));
fread($rp, 1);
$o[$i]["pits"] = hexdec(bin2hex (fread($rp, 1). $pits[$i]));
fread($rp, 1);
$o[$i]["?????"] = hexdec(bin2hex(fread($rp, 1)));
$o[$i]["overall_time"] = msht2int(fread($rp, 4));
$o[$i]["best_lap"] = msht2int(fread($rp, 4));

fread($rp, 4);
}

A piece of MPR Header code:

RESULT INFO : size 80 bytes per finished player

24 char 0 player name : text, ends 0, no colours
8 char 24 number plate : text, NOTE : NO ZERO AT END
4 char 32 short car name : text, ends 0
24 byte 36 0 : -
1 word 60 laps done : total laps completed
1 word 62 player flags : driver settings (see NOTES)
1 byte 64 confirm flags : penalties (see NOTES)
1 byte 65 number of stops : pit stops count
1 byte 66 0 : -
1 byte 67 0 : -
1 time 68 overall time : msht time
1 time 72 best lap time : msht time (first check point)
1 int 76 0 : -

this is a line:

1 word 60 laps done : total laps completed


JS

filur
5th April 2006, 20:10
A piece of PHP code:

Confusing, you're reading 24 bytes of player name, 8 bytes of number plate, 32 bytes of short car string which is only 4 bytes, then you do nothing about the 24 NUL bytes, the commented line attempts to read a 2-byte word as 1 byte, attempt to skip next 2-byte word by reading 1 byte, etc.

Or am i too tired? :)

jscorrea
6th April 2006, 02:40
Confusing, you're reading 24 bytes of player name, 8 bytes of number plate, 32 bytes of short car string which is only 4 bytes, then you do nothing about the 24 NUL bytes, the commented line attempts to read a 2-byte word as 1 byte, attempt to skip next 2-byte word by reading 1 byte, etc.

Or am i too tired? :)

yes is very strange, but this works!!

This code is from priits (tourney system), the code of other MPR parser is almost identical.

The only thing what i need is "laps done for each racer"..im not understand...

JS

jscorrea
6th April 2006, 04:06
finaly, the right code....

for($i = 0; $i < $finished; $i++)
{
$o[$i]["soitja"] = trim(fread($rp, 24));
$o[$i]["plate"] = trim(fread($rp, 8));
$o[$i]["auto"] = trim(fread($rp, 4));
fread($rp, 24);
$o[$i]["laps_c"] = hexdec(bin2hex(fread($rp, 2)))/256;
fread($rp, 2);
fread($rp, 1);
$o[$i]["pits"] = hexdec(bin2hex (fread($rp, 1). $pits[$i]));
fread($rp, 1);
fread($rp, 1);
//$o[$i]["maha"] = hexdec(bin2hex(fread($rp, 1)));
$o[$i]["lopp"] = msht2int(fread($rp, 4));
$o[$i]["parim"] = msht2int(fread($rp, 4));

fread($rp, 4);
}