Snippets

B4T Games Epic Roller Coasters Telemetry Receiver

Updated by Lennon R. Bisolo

File snippet.cs Modified

  • Ignore whitespace
  • Hide word diff
     // Enums
     public enum RideType
     {
-        RockFalls = 0,
-        TRexKingdom = 1,
-        WyvernSiege = 2,
-        Snowland = 3,
-        NeonRider = 4,
-        Halloween = 5,
-        Armageddon = 6,
-        LostForest = 7,
-        DreadBlood = 8,
-        TuwhenaVolcano = 9,
-        None = 10,
-        TropicalIsland = 11,
-        NorthPole = 12,
-        Twilight = 13,
-        HauntedCastle = 14,
-        Oasis = 15,
-        GreatCanyon = 16,
-        SpaceStation = 17,
-        SecretCave = 18
+        NONE = 0,
+        ROCK_FALLS = 1,
+        TREX_KINGDOM = 2,
+        WYVERN_SIEGE = 3,
+        SNOW_LAND = 4,
+        NEON_RIDER = 5,
+        HALLOWEEN = 6,
+        ARMAGEDDON = 7,
+        LOST_FOREST = 8,
+        DREAD_BLOOD = 9,
+        TUWHENA_VOLCANO = 10,
+        TROPICAL_ISLAND = 11,
+        NORTH_POLE = 12,
+        TWILIGHT = 13,
+        HAUNTED_CASTLE = 14,
+        OASIS = 15,
+        GREAT_CANYON = 16,
+        SPACE_STATION = 17,
+        SECRET_CAVE = 18,
+        TUTORIAL = 19,
+        LOBBY = 20
     }
 
     public enum CartType
         GreatCanyon = 16,
         SpaceStation = 17,
         SecretCave = 18,
-        Skate = 19,
-        TeaCup = 20,
-        Rocket = 21,
-        HangGlider = 22,
-        Swing = 23
+        Skate = 19
     }
 
     public enum GunType
         SNOW_GUN = 4,
         LASER_GUN = 5,
         TOILET_GUN = 6,
-        PISTOL = 7,
+        CAL50 = 7,
         WAND = 8,
-        SHOTGUN = 9
+        SHOTGUN = 9,
+        TUWHENA_VOLCANO = 10,
+        TROPICAL_ISLAND = 11,
+        NORTH_POLE = 12,
+        TWILIGHT = 13,
+        HAUNTED_CASTLE = 14,
+        OASIS = 15,
+        GREAT_CANYON = 16,
+        SPACE_STATION = 17,
+        SECRET_CAVE = 18,
+        CAL50_SUPRESSED = 19,
     }
 }
Updated by Lennon R. Bisolo

File snippet.cs Modified

  • Ignore whitespace
  • Hide word diff
-class EpicRollerCoasters_TelemetryReceiver
+class EpicRollerCoasters_Telemetry
 {
     // Launch Options: -telemetry network
     // Launch Options: -telemetry network -port 7701
 
                 // Latest UDPPacket
                 lastReceivedUDPPacket = text;
-                //Debug.Log(">> " + lastReceivedUDPPacket);
+                //Console.WriteLine(">> " + lastReceivedUDPPacket);
 
                 // UDPPacket output example:
-                // S[027.559]Y[-004.332]P[165.854]R[-054.661]W[000.007]H[000.000]U[027.559]
-                // S[027.694]Y[-004.398]P[165.538]R[044.135]W[-000.072]H[-000.071]U[027.694]
-
-                float speed = ParseNumber("S", lastReceivedUDPPacket);
-                float yaw = ParseNumber("Y", lastReceivedUDPPacket);
-                float pitch = ParseNumber("P", lastReceivedUDPPacket);
-                float roll = ParseNumber("R", lastReceivedUDPPacket);
-                float heave = ParseNumber("H", lastReceivedUDPPacket);
-                float sway = ParseNumber("W", lastReceivedUDPPacket);
-                float surge = ParseNumber("U", lastReceivedUDPPacket);
-
-                Console.WriteLine(">> Speed: {0}, Yaw: {1}, Pitch: {2}, Roll: {3}, Heave: {4}, Sway: {5}, Surge: {6}",
-                    speed, yaw, pitch, roll, heave, sway, surge);
+                // S[005.001]V[023.729]F[008.801]Y[173.541]P[000.049]R[000.052]H[000.000]W[000.004]U[005.001]A[000.119]I[-000.001]O[000.000]N[00]C[00]G[00]
+                // S[026.953]V[044.193]F[016.940]Y[159.710]P[001.965]R[-003.653]H[000.182]W[000.170]U[026.952]A[000.480]I[000.541]O[-000.098]N[11]C[19]G[05]
+
+                float speed = GetNumber("S", lastReceivedUDPPacket);
+                float vibrationIntensity = GetNumber("V", lastReceivedUDPPacket);
+                float vibrationFrequency = GetNumber("F", lastReceivedUDPPacket);
+                float yaw = GetNumber("Y", lastReceivedUDPPacket);
+                float pitch = GetNumber("P", lastReceivedUDPPacket);
+                float roll = GetNumber("R", lastReceivedUDPPacket);
+                float heave = GetNumber("H", lastReceivedUDPPacket);
+                float sway = GetNumber("W", lastReceivedUDPPacket);
+                float surge = GetNumber("U", lastReceivedUDPPacket);
+                float yawVel = GetNumber("A", lastReceivedUDPPacket);
+                float pitchVel = GetNumber("I", lastReceivedUDPPacket);
+                float rollVel = GetNumber("O", lastReceivedUDPPacket);
+                float rideIndex = GetInt("N", lastReceivedUDPPacket);
+                float carIndex = GetInt("C", lastReceivedUDPPacket);
+                float gunIndex = GetInt("G", lastReceivedUDPPacket);
+
+                string rideName = ((RideType)rideIndex).ToString();
+                string carName = ((CartType)carIndex).ToString();
+                string gunName = ((GunType)gunIndex).ToString();
+
+                Console.WriteLine(">> Speed: {0}, Yaw: {1}, Pitch: {2}, Roll: {3}, Heave: {4}, Sway: {5}, Surge: {6}, YawVelocity: {7}, PitchVelocity: {8}, RollVelocity: {9}, RideName: {10}, CarName: {11}, GunName: {12}, VibrationIntensity: {13}, VibrationFrequency: {14}",
+                    speed, yaw, pitch, roll, heave, sway, surge, yawVel, pitchVel, rollVel, rideName, carName, gunName, vibrationIntensity, vibrationFrequency);
             }
             catch (Exception err)
             {
     }
 
     // Parse the packats
-    private static float ParseNumber(string prefix, string data)
+    private float GetNumber(string prefix, string data)
     {
         string numberRx = @"\-*\d{3}\.\d{3}";
         string dataBlockRx = @"\[" + numberRx + @"\]";
 
         return number;
     }
+
+    private int GetInt(string prefix, string data)
+    {
+        string intRx = @"\-*\d{2}";
+        string dataBlockRx = @"\[" + intRx + @"\]";
+
+        string value = new Regex(prefix + dataBlockRx).Match(data).Value;
+        int number = int.Parse(new Regex(intRx).Match(value).Value, CultureInfo.InvariantCulture);
+
+        return number;
+    }
+
+    // Enums
+    public enum RideType
+    {
+        RockFalls = 0,
+        TRexKingdom = 1,
+        WyvernSiege = 2,
+        Snowland = 3,
+        NeonRider = 4,
+        Halloween = 5,
+        Armageddon = 6,
+        LostForest = 7,
+        DreadBlood = 8,
+        TuwhenaVolcano = 9,
+        None = 10,
+        TropicalIsland = 11,
+        NorthPole = 12,
+        Twilight = 13,
+        HauntedCastle = 14,
+        Oasis = 15,
+        GreatCanyon = 16,
+        SpaceStation = 17,
+        SecretCave = 18
+    }
+
+    public enum CartType
+    {
+        RockFalls = 0,
+        TRexKingdom = 1,
+        WyvernSiege = 2,
+        Snowland = 3,
+        NeonRider = 4,
+        Halloween = 5,
+        Armageddon = 6,
+        LostForest = 7,
+        DreadBlood = 8,
+        TuwhenaVolcano = 9,
+        None = 10,
+        TropicalIsland = 11,
+        NorthPole = 12,
+        Twilight = 13,
+        HauntedCastle = 14,
+        Oasis = 15,
+        GreatCanyon = 16,
+        SpaceStation = 17,
+        SecretCave = 18,
+        Skate = 19,
+        TeaCup = 20,
+        Rocket = 21,
+        HangGlider = 22,
+        Swing = 23
+    }
+
+    public enum GunType
+    {
+        NONE = 0,
+        SLINGSHOT = 1,
+        DART = 2,
+        CROSSBOW = 3,
+        SNOW_GUN = 4,
+        LASER_GUN = 5,
+        TOILET_GUN = 6,
+        PISTOL = 7,
+        WAND = 8,
+        SHOTGUN = 9
+    }
 }
Created by Lennon R. Bisolo

File snippet.cs Added

  • Ignore whitespace
  • Hide word diff
+class EpicRollerCoasters_TelemetryReceiver
+{
+    // Launch Options: -telemetry network
+    // Launch Options: -telemetry network -port 7701
+    // Launch Options: -telemetry network -ip 127.0.0.1 -port 7701
+
+    // Default port: 7701
+    private static int port = 7701;
+
+    private static UdpClient client;
+    private static IPEndPoint anyIP;
+
+    public static string lastReceivedUDPPacket = "";
+
+    static void Main(string[] args)
+    {
+        anyIP = new IPEndPoint(IPAddress.Any, 0);
+        client = new UdpClient(port);
+
+        Thread receiveThread = new Thread(new ThreadStart(ReceiveData));
+        receiveThread.IsBackground = true;
+        receiveThread.Start();
+
+        // Holds the MainThread while looking for data
+        receiveThread.Join();
+    }
+
+    private static void ReceiveData()
+    {
+        while (true)
+        {
+            try
+            {
+                byte[] data = client.Receive(ref anyIP);
+
+                string text = Encoding.UTF8.GetString(data);
+
+                // Latest UDPPacket
+                lastReceivedUDPPacket = text;
+                //Debug.Log(">> " + lastReceivedUDPPacket);
+
+                // UDPPacket output example:
+                // S[027.559]Y[-004.332]P[165.854]R[-054.661]W[000.007]H[000.000]U[027.559]
+                // S[027.694]Y[-004.398]P[165.538]R[044.135]W[-000.072]H[-000.071]U[027.694]
+
+                float speed = ParseNumber("S", lastReceivedUDPPacket);
+                float yaw = ParseNumber("Y", lastReceivedUDPPacket);
+                float pitch = ParseNumber("P", lastReceivedUDPPacket);
+                float roll = ParseNumber("R", lastReceivedUDPPacket);
+                float heave = ParseNumber("H", lastReceivedUDPPacket);
+                float sway = ParseNumber("W", lastReceivedUDPPacket);
+                float surge = ParseNumber("U", lastReceivedUDPPacket);
+
+                Console.WriteLine(">> Speed: {0}, Yaw: {1}, Pitch: {2}, Roll: {3}, Heave: {4}, Sway: {5}, Surge: {6}",
+                    speed, yaw, pitch, roll, heave, sway, surge);
+            }
+            catch (Exception err)
+            {
+                Console.WriteLine("[UDPReceive] Error: " + err.ToString());
+            }
+        }
+    }
+
+    // Parse the packats
+    private static float ParseNumber(string prefix, string data)
+    {
+        string numberRx = @"\-*\d{3}\.\d{3}";
+        string dataBlockRx = @"\[" + numberRx + @"\]";
+
+        string value = new Regex(prefix + dataBlockRx).Match(data).Value;
+        float number = float.Parse(new Regex(numberRx).Match(value).Value, CultureInfo.InvariantCulture);
+
+        return number;
+    }
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.