Exemplo n.º 1
0
 static int AddPlayerMade(GameObject obj, byte[] data, int fromWho)
 {
     if (obj)
     {
         // Must be alive
         byte placePlayerMadeType = data [0];
         PlacePlayerMade.AddObject(obj.GetComponent <PlayerMove>(), OperationNetwork.getVector3(data, 1), OperationNetwork.getQuaternion(data, 13), placePlayerMadeType, obj.GetComponent <Combat>().team, (short)fromWho);
     }
     return(29);
 }
Exemplo n.º 2
0
    // Static class devoted to methods that were originally in SyncGameState that involve the interpreting & representing of byte data into objects.


    public static object interpretObject(byte[] data, ref int bytePosition, object type, SyncGameState sgg, int tickNumber, bool isPlayerOwner)
    {
        object returnObject = null;

        if (type is float)
        {
            returnObject  = BitConverter.ToSingle(data, bytePosition);
            bytePosition += 4;
        }
        else if (type is int)
        {
            returnObject  = BitConverter.ToInt32(data, bytePosition);
            bytePosition += 4;
        }
        else if (type is short)
        {
            returnObject  = BitConverter.ToInt16(data, bytePosition);
            bytePosition += 2;
        }
        else if (type is byte)
        {
            returnObject  = data [bytePosition];
            bytePosition += 1;
        }
        else if (type is Vector3)             // Equals feels like good usage here.
        {
            returnObject  = OperationNetwork.getVector3(data, bytePosition);
            bytePosition += 12;
        }
        else if (type is bool)
        {
            returnObject  = BitConverter.ToBoolean(data, bytePosition);
            bytePosition += 1;
        }
        else if (type is Quaternion)
        {
            returnObject  = OperationNetwork.getQuaternion(data, bytePosition);
            bytePosition += 16;
        }
        else if (type is string)
        {
            // All strings have max 255 length.
            // Just because.
            byte length = data [bytePosition];
            bytePosition += 1;

            returnObject  = Encoding.ASCII.GetString(data, bytePosition, length);
            bytePosition += length;
        }
        else if (type is float[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new float[length];
            for (int i = 0; i < length; i++)
            {
                ((float[])returnObject) [i] = BitConverter.ToSingle(data, bytePosition);
                bytePosition += 4;
            }
        }
        else if (type is Vector3[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new Vector3[length];
            for (int i = 0; i < length; i++)
            {
                ((Vector3[])returnObject) [i] = OperationNetwork.getVector3(data, bytePosition);
                bytePosition += 12;
            }
        }
        else if (type is Vector3[][])
        {
            // Hitscan data:
            byte length = data [bytePosition];
            bytePosition += 1;
            returnObject  = new Vector3[length][];
            for (int i = 0; i < length; i++)
            {
                ((Vector3[][])returnObject) [i] = (Vector3[])interpretObject(data, ref bytePosition, new Vector3[0], null, -1, false);
            }
        }
        else if (type is SyncableType)
        {
            returnObject = ((SyncableType)type).createThis(data, ref bytePosition, sgg, tickNumber, isPlayerOwner);
        }
        else if (type is DamageNumber[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;

            returnObject = new DamageNumber[length];
            for (int i = 0; i < length; i++)
            {
                ((DamageNumber[])returnObject) [i] = new DamageNumber(data, ref bytePosition);
            }
        }
        else if (type is byte[])
        {
            byte length = data [bytePosition];             // Max 255 length
            bytePosition += 1;
            returnObject  = new byte[length];
            for (int i = 0; i < length; i++)
            {
                ((byte[])returnObject) [i] = data[bytePosition];
                bytePosition += 1;
            }
        }
        return(returnObject);
    }