Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.07 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows.Forms;
  4. using InSimDotNet;
  5. using InSimDotNet.Packets;
  6. using System.Collections.Generic;
  7. using System.Threading;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace Siren_Application
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             var program = new SirenApplication();
  19.             program.Start();
  20.         }
  21.     }
  22.  
  23.     class SirenApplication
  24.     {
  25.         // Declare variables and starting values
  26.         InSim insim = new InSim();
  27.         bool CONNECTED;
  28.         public bool PoliceSirenBool;
  29.         public bool PoliceSirenOn;
  30.         public bool PoliceSirenSlow;
  31.         public bool PoliceSirenFast;
  32.         public bool PoliceSirenPier;
  33.         public bool PoliceSirenOff;
  34.         public static long lastTime;
  35.  
  36.         // DLL Connection to use key states for siren
  37.         [DllImport("user32.dll")]
  38.         public static extern short GetAsyncKeyState(int vKey);
  39.         // Key Press Returns
  40.         public bool KeyPressed(int vk)
  41.         {
  42.             return (GetAsyncKeyState(vk) & 32768) != 0;
  43.         }
  44.  
  45.         public void Start()
  46.         {
  47.             // Start the insim application and define the settings
  48.             insim.Initialize(new InSimSettings
  49.             {
  50.                 Host = "127.0.0.1",
  51.                 Port = 29999,
  52.                 Admin = String.Empty,
  53.                 Flags = InSimFlags.ISF_LOCAL,
  54.                 IName = "Siren App"
  55.             });
  56.  
  57.             // Confirm connection with local message to LFS and console exe
  58.             insim.Send("/echo ^3Siren Application Connected");
  59.             Console.WriteLine("Siren Application Connected");
  60.  
  61.             // Activate siren
  62.             PoliceSirenOn = true;
  63.             PoliceSirenSlow = true;
  64.             PoliceSirenFast = false;
  65.             PoliceSirenOff = false;
  66.             PoliceSirenBool = true;
  67.  
  68.             Thread sirenController = new Thread(new ThreadStart(SirenController));
  69.             sirenController.Start();
  70.  
  71.             // Keep the connection alive by setting CONNECTED to true and create a loop
  72.             CONNECTED = true;
  73.             while(CONNECTED)
  74.             {
  75.                 Thread.Sleep(1);
  76.             }
  77.         }
  78.  
  79.         public void SirenController()
  80.         {
  81.             // Confirm that this void / method has been started as a new thread
  82.             insim.Send("/echo Siren Controller Thread STARTED");
  83.  
  84.             var timeNow = DateTime.Now.Ticks / 10000;
  85.             var timesinceLast = timeNow - lastTime;
  86.  
  87.             PoliceSirenSlow = true;
  88.  
  89.             while (PoliceSirenBool)
  90.             {
  91.                 if (KeyPressed(0x21))
  92.                 {
  93.                         if (timesinceLast > 1 && timesinceLast < 500)
  94.                         {
  95.                             insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_OFF });
  96.                             PoliceSirenSlow = true;
  97.                             PoliceSirenFast = false;
  98.                             PoliceSirenPier = false;
  99.                         }
  100.  
  101.                         else
  102.  
  103.                         if (PoliceSirenSlow)
  104.                         {
  105.                             insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_SLOW });
  106.                             PoliceSirenSlow = false;
  107.                             PoliceSirenFast = true;
  108.                             PoliceSirenPier = false;
  109.                             lastTime = DateTime.Now.Ticks / 10000;
  110.                         }
  111.  
  112.                         else
  113.  
  114.                         if (PoliceSirenFast)
  115.                         {
  116.                             insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_FAST });
  117.                             PoliceSirenSlow = false;
  118.                             PoliceSirenFast = false;
  119.                             PoliceSirenPier = true;
  120.                             lastTime = DateTime.Now.Ticks / 10000;
  121.                         }
  122.  
  123.                         else
  124.  
  125.                         if (PoliceSirenPier)
  126.                         {
  127.                             while (KeyPressed(0x42))
  128.                             {
  129.                                 if (!KeyPressed(0x42))
  130.                                 {
  131.                                     Console.WriteLine("b is pressed");
  132.                                 }
  133.                             }
  134.                             insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_SIREN_OFF + 327688 });
  135.                             PoliceSirenSlow = true;
  136.                             PoliceSirenFast = false;
  137.                             PoliceSirenPier = false;
  138.                             lastTime = DateTime.Now.Ticks / 10000;
  139.                         }
  140.                 }
  141.             }
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement