The online racing simulator
can somebody please explain what I am doing wrong here?


<?php 
        
/*
        requested CPP Object with $TINY->ReqI(1)->SubT(TINY_SCP)->Send() and dumped the response with print_r

        IS_CPP Object
        (
            [Size:protected] => 32
            [Type:protected] => 9
            [ReqI] => 1
            [Zero:protected] => 0
            [Pos] =>
            [H] => 65117                #Heading
            [P] => 757                  #Pitch
            [R] => 0                    #Roll
            [ViewPLID] => 0             # Unique ID of viewed player (0 = none)
            [InGameCam] => 0            # InGameCam (as reported in StatePack)
            [FOV] => 24.60000038147     # 4-byte float : FOV in degrees
            [Time] => 0                 # Time in ms to get there (0 means instant)
            [Flags] => 0                # ISS state flags
            [Pos1] => -39175822         #"Vec" : 3 ints (X, Y, Z) - 65536 means 1 metre
            [Pos2] => 11394484          #"Vec" : 3 ints (X, Y, Z) - 65536 means 1 metre
            [Pos3] => 1037662           #"Vec" : 3 ints (X, Y, Z) - 65536 means 1 metre
        )
        */

        // trying to send same camera position back
        
$this->Pos = array("Pos1" => -39175822"Pos2" => 11394484"Pos3" => 1037662);

        
IS_CPP()->Pos($this->Pos)->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Send();
?>

LFS response:

InSim : received a packet with invalid size
InSim : unknown packet (116 bytes) - PRISM v0.4.6

Right hhmm.. The PACK is most definitly wrong.. Changed;


<?php 
class IS_CPP extends Struct // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
{
    const 
PACK 'CCCxl3vvvCCfvv';
    const 
UNPACK 'CSize/CType/CReqI/CZero/l3Pos/vH/vP/vR/CViewPLID/CInGameCam/fFOV/CTime/CFlags';
?>

to


<?php 
class IS_CPP extends Struct // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
{
    const 
PACK 'CCxxl3vvvCCfCC';
    const 
UNPACK 'CSize/CType/CReqI/CZero/l3Pos/vH/vP/vR/CViewPLID/CInGameCam/fFOV/CTime/CFlags';
?>

This scares away the unknown packet message but I tried sending a packet like this;


<?php 
IS_CPP
()->Pos()->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Pos1(-39175822)->Pos2(11394484)->Pos3(1037662)->Send();
?>

and in several other combinations, the camera goes somewhere to the moon and the InSim crashes with a

InSim read error : PRISM v0.4.6

So ye... Eehhh basically I don't know how to figure out this "Vec" thing. It's not an array as I assumed earlier but if I do Pos(-39175822,11394484,1037662) then it's not helping also. I wonder where PHP gets that naming; Pos1, Pos2, Pos3 from.
In LFS/C(++), Vec is just another struct containing 3 ints.
I don't know how you'd translate that to PHP, but a hacky way would be to just replace the Pos with 3 ints

edit: It probably wants to be its own class in PHP with the relevant pack/unpack functions, but that's just a guess
You might have to live with replacing Pos with 3 ints then, unless someone can give you some better insight - I know basically nothing about the way PHP handles this kind of stuff.

As far as the packet/data that LFS gets is concerned, 3 ints is equivalent to a C struct containing 3 ints.
Would this work? (A guess based on what the php pack() funcion does)

<?php 
IS_CPP
()->Pos(pack("l3",-39175822,11394484,1037662))->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Send();
?>

edit: nm, it probably doesn't. I'll try to take a proper look into it later
No it doesn't, I tried exactly that, but maybe PHP junkies T3charmy or Dygear have a good solution to this problem. It's clearly a bug somewhere but I am lacking knowledge about pack/unpack/vec3 .
Quote from Degats :Would this work? (A guess based on what the php pack() funcion does)

<?php 
IS_CPP
()->Pos(pack("l3",-39175822,11394484,1037662))->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Send();
?>

edit: nm, it probably doesn't. I'll try to take a proper look into it later

Yep, that should work. As it's producing a datasize the same as the required input.

The key point being the `->Pos(pack('l3', $X, $Y, $Z))` in your code example.
I tried :/


<?php 
     $Vec3 
pack("l3", -39175822113944841037662);
     
IS_CPP()->Pos($Vec3)->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Send();
?>


<?php 
IS_CPP Object
(
    [
Size:protected] => 32
    
[Type:protected] => 9
    
[ReqI] =>
    [
Zero:protected] =>
    [
Pos] => r9¬²┤¦¡ ^ı☼
    
[H] => 65117
    
[P] => 757
    
[R] => 0
    
[ViewPLID] => 0
    
[InGameCam] => 0
    
[FOV] => 24.60000038147
    
[Time] => 0
    
[Flags] => 0
)
IS_CPP Packet to camtest.
?>

It might gets double packed or something? Tried to fiddle around with prism_packets.php but lost to many hours finding the correct solution.
Here.. If I debug the CPP structure, I suspect something is wrong here;



> IS_CPP Packet to camtest.
Array
(
[0] => C
[1] => C
[2] => x
[3] => x
[4] => Array
(
[0] => l
[1] => 3
)

[5] => v
[6] => v
[7] => v
[8] => C
[9] => C
[10] => f
[11] => C
[12] => C
)

Why is l3 in a multi dimensional array? I don't know.. But it feels wrong. How to make it different I don't know yet.

That Vec3 contains 3 int values in one, not separated in different containers... But when I try to pack it as one value I get invalid packet size again :/
Right.. So if I do this @prism_packets.php;


<?php 
    
public function parsePackFormat()
    {
        
$format $this::PACK# It does not like using $this::PACK directly.
        
$elements = array();

        for (
$i 0$j 1$k strLen($format); $i $k; ++$i, ++$j)
        {    
# i = Current Character; j = Look ahead for numbers.
            
if (is_string($format{$i}) && !isset($format[$j]) || !is_numeric($format[$j]))
            {
                
$elements[] = $format{$i};
            }
            else
            {
                while (isset(
$format{$j}) && is_numeric($format{$j}))
                {
                    ++
$j;    # Will be the last number of the current element.
                
}

                
$number substr($format$i 1$j - ($i 1));

                if (
$format{$i} == 'a' || $format{$i} == 'A' || $format{$i} == 'l')
                {    
# In these cases it's a string type where dealing with.
                    
$elements[] = $format{$i}.$number;
                } else { 
# In these cases, we should get an array.
                    
$elements[] = array($format{$i}, $number);
                }

                
$i $j 1# Movies the pointer to the end of this element.
            
}
        }
        
        
print_r($elements);

        return 
$elements;
    }
?>

then I get this;


> IS_CPP Packet to camtest.
Array
(
[0] => C
[1] => C
[2] => x
[3] => x
[4] => l3
[5] => v
[6] => v
[7] => v
[8] => C
[9] => C
[10] => f
[11] => C
[12] => C
)

Which I think is good...

Then this;


<?php 
    
public function pack()
    {
        
$return '';
        
$packFormat $this->parsePackFormat();
        
$propertyNumber = -1;
        
        foreach (
$this as $property => $value) {
            echo 
"value: " $value "\r\n";
            
$pkFnkFormat $packFormat[++$propertyNumber];
            
            if (
$pkFnkFormat == 'x' || $pkFnkFormat == 'l3') {
                if (
$pkFnkFormat == 'x') {
                    
$return .= pack('C'0); # null & 0 are the same thing in Binary (00000000) and Hex (x00), so null == 0.
                
} else {
                    echo 
"its a l3! \r\n";
                    
$return .= $value# it'a Vec3 already don't do anything
                
}
            } elseif (
is_array($pkFnkFormat)) {
                list(
$type$elements) = $pkFnkFormat;
                
                if ((
$j count($value)) > $elements) {
                    
$j $elements;
                }
                
                for (
$i 0$i $elements; ++$i) {
                if(isset(
$value[$i])){
                    
$return .= pack($type$value[$i]);
                } else {
                    
$return .= pack("x");
                }
                }
            } else {
                
$return .= pack($pkFnkFormat$value);
            }
        }
        
        return 
$return;
    }
?>

If I feed it with this;


<?php 
$Vec3 
pack("l3", -39175822113944841037662);
IS_CPP()->Pos($Vec3)->H(65117)->P(757)->R(0)->ViewPLID(0)->InGameCam(0)->FOV(24.60000038147)->Time(0)->Flags(0)->Send();
?>

crash! ... Crying.. Why.. Oh whyyy...
You managed to crash PHP, that's impressive from user land.

I'll take a closer look at this tonight with PRISM running instead of making wild guesses.
PRISM you mean? It crashes on this "Insim read error". Looks like packet reading goes out of sync... Then automatically restarts..

Would be nice if you can take a look, I am running out of idea's Shrug
-
(cargame.nl) DELETED by cargame.nl : removed for overview
-
(cargame.nl) DELETED by cargame.nl : removed for overview
Quote from cargame.nl :Right hhmm.. The PACK is most definitly wrong.. Changed;


<?php 
class IS_CPP extends Struct // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
{
    const 
PACK 'CCCxl3vvvCCfvv';
    const 
UNPACK 'CSize/CType/CReqI/CZero/l3Pos/vH/vP/vR/CViewPLID/CInGameCam/fFOV/CTime/CFlags';
?>

to


<?php 
class IS_CPP extends Struct // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
{
    const 
PACK 'CCxxl3vvvCCfCC';
    const 
UNPACK 'CSize/CType/CReqI/CZero/l3Pos/vH/vP/vR/CViewPLID/CInGameCam/fFOV/CTime/CFlags';
?>

This scares away the unknown packet message but

Damn it... The PACK was still wrong partly because the UNPACK is wrong too... It should be vTime and vFlags...;


<?php 
    
const PACK 'CCCxl3vvvCCfvv';
    const 
UNPACK 'CSize/CType/CReqI/CZero/l3Pos/vH/vP/vR/CViewPLID/CInGameCam/fFOV/vTime/vFlags';
?>

Now it works without hex hacks which I described in my earlier (now deleted) posts. The Vec3 structure is not the same as the packets produced by LFS but no clue how to fix this. For some reason LFS listen also to this structure.

* note that the l3 hack @function pack() still is needed!
Quote from cargame.nl :Now it works without hex hacks which I described in my earlier (now deleted) posts. The Vec3 structure is not the same as the packets produced by LFS but no clue how to fix this. For some reason LFS listen also to this structure.

* note that the l3 hack @function pack() still is needed!

Vec is 3 Ints, X, Y, Z. (12 Bytes)
Vector is 3 Floats, X, Y, Z. (12 Bytes)

While they are different things, they happen to be the same size in memory.

l3 within the function call is not a hack, it's really how it needs to be done. DarkTime's libaries handle this better then PRISM does, but it also does it with a little more overhead. It places a wrapper around the Vec structure. We could do the same thing within PRISM, the overhead it's self is negligible. The Pos function would accept $X, $Y, $Z as paramaters and pass them through to the Vec class on packing / unpacking.
I call it 'a hack'' because I handle a l3 as a string in the code above, without filling 0's. And it doesn't feel right because I cannot get the proper structure right unless I feed it with a hex pack on the end of the packet which I stole by imitating the original packet. But at least got something working after some hours of frustration, maybe makes someone else happy.. In the future..

FGED GREDG RDFGDR GSFDG