Advertisement
phunkaeg

Game Engine Profile for Overload

Jul 26th, 2024
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.09 KB | Gaming | 0 0
  1. using OverloadPlugin.Properties;
  2. using System;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using System.Collections.Generic;
  6. using System.ComponentModel.Composition;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Runtime.Versioning;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using YawGEAPI;
  14. namespace OverloadPlugin
  15. {
  16.     [Export(typeof(Game))]
  17.     [ExportMetadata("Overload","Overload Motion Plugin")]
  18.     [ExportMetadata("Version","1.0")]
  19.  
  20.     public class OverloadPlugin : Game
  21.     {
  22.         public int STEAM_ID => 0; // Will start this game on steam based on Steam ID
  23.  
  24.         public string PROCESS_NAME => string.Empty;
  25.  
  26.         public bool PATCH_AVAILABLE => false; // Needs patch
  27.  
  28.         public string AUTHOR => "PhunkaeG";
  29.  
  30.         public System.Drawing.Image Logo => Resources.logo;
  31.  
  32.         public System.Drawing.Image SmallLogo => Resources.small;
  33.  
  34.         public System.Drawing.Image Background => Resources.background;
  35.  
  36.         public string Description => "<h1> Overload Plugin </h1>";
  37.  
  38.         private Thread readThread;
  39.         private volatile bool running = false;
  40.         private IProfileManager controller;
  41.         private IMainFormDispatcher dispatcher;
  42.         private UdpClient udpClient;
  43.         private IPEndPoint endPoint;
  44.  
  45.         private void ReadTelemetry()
  46.         {
  47.             try
  48.             {
  49.                 while (running)
  50.                 {
  51.                     if (udpClient.Available > 0)
  52.                     {
  53.                         byte[] data = udpClient.Receive(ref endPoint);
  54.                         string telemetryData = Encoding.ASCII.GetString(data);
  55.                         ProcessTelemetry(telemetryData);
  56.                     }
  57.                     Thread.Sleep(20); // Reduce CPU usage
  58.                 }
  59.             }
  60.             catch (Exception ex)
  61.             {
  62.                 // Handle or log exceptions
  63.                 Console.WriteLine("Error reading telemetry data: " + ex.Message);
  64.             }
  65.         }
  66.         private void ProcessTelemetry(string telemetry)
  67.         {
  68.             try
  69.             {
  70.                 string[] parts = telemetry.Split(';');
  71.                 if (parts.Length >= 14) // Make sure all parts are present
  72.                 {
  73.                     float roll = float.Parse(parts[0]);
  74.                     float pitch = float.Parse(parts[1]);
  75.                     float yaw = float.Parse(parts[2]);
  76.                     float gForceX = float.Parse(parts[6]);
  77.                     float gForceY = float.Parse(parts[7]);
  78.                     float gForceZ = float.Parse(parts[8]);
  79.  
  80.                     // Set inputs based on parsed data
  81.                     controller.SetInput(0, yaw);
  82.                     controller.SetInput(1, pitch);
  83.                     controller.SetInput(2, roll);
  84.                     // Example: Assume inputs 3, 4, 5 are set for G-forces
  85.                     controller.SetInput(3, gForceX);
  86.                     controller.SetInput(4, gForceY);
  87.                     controller.SetInput(5, gForceZ);
  88.                 }
  89.             }
  90.             catch (Exception ex)
  91.             {
  92.                 Console.WriteLine($"Error processing telemetry data: {ex.Message}");
  93.             }
  94.         }
  95.  
  96.         public LedEffect DefaultLED()
  97.         {
  98.             return new LedEffect(EFFECT_TYPE.KNIGHT_RIDER_2, 7, new YawColor[4]
  99.             {
  100.                 new YawColor((byte) 66, (byte) 135, (byte) 245),
  101.                 new YawColor((byte) 80, (byte) 80, (byte) 80),
  102.                 new YawColor((byte) 128, (byte) 3, (byte) 117),
  103.                 new YawColor((byte) 110, (byte) 201, (byte) 12)
  104.             }, 25f);
  105.         }
  106.  
  107.         public List<Profile_Component> DefaultProfile()
  108.         {
  109.             return new List<Profile_Component>();
  110.         }
  111.  
  112.         public void Exit()
  113.         {
  114.             running = false;
  115.             readThread.Join();
  116.             udpClient.Close();
  117.         }
  118.         public Dictionary<string, ParameterInfo[]> GetFeatures()
  119.         {
  120.             return new Dictionary<string, ParameterInfo[]>(); // Return empty if no features to report
  121.         }
  122.  
  123.         public string[] GetInputData()
  124.         {
  125.             return new string[] { "Yaw", "Pitch", "Roll" };
  126.  
  127.         }
  128.  
  129.         public void Init()
  130.         {
  131.             if (udpClient != null)
  132.                 udpClient.Close();
  133.  
  134.             if (readThread != null && readThread.IsAlive)
  135.                 Exit();
  136.  
  137.             endPoint = new IPEndPoint(IPAddress.Any, 4123); // Use the correct port for Overload
  138.             udpClient = new UdpClient(endPoint);
  139.  
  140.             running = true;
  141.             readThread = new Thread(ReadTelemetry);
  142.             readThread.Start();
  143.         }
  144.  
  145.         public void PatchGame()
  146.         {
  147.             // Intentionally left blank - no patching required
  148.         }
  149.  
  150.         public void SetReferences(IProfileManager controller, IMainFormDispatcher dispatcher)
  151.         {
  152.             //we need to save these references
  153.             this.controller = controller;
  154.             this.dispatcher = dispatcher;
  155.         }
  156.     }
  157. }
  158.  
Tags: yaw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement