Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using InSimDotNet;
- using InSimDotNet.Packets;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Siren_Application
- {
- class Program
- {
- static void Main(string[] args)
- {
- var program = new SirenApplication();
- program.Start();
- }
- }
- class SirenApplication
- {
- // Declare variables and starting values
- InSim insim = new InSim();
- bool CONNECTED;
- public bool PoliceSirenBool;
- public bool PoliceSirenOn;
- public bool PoliceSirenSlow;
- public bool PoliceSirenFast;
- public bool PoliceSirenPier;
- public bool PoliceSirenOff;
- public static long lastTime;
- // DLL Connection to use key states for siren
- [DllImport("user32.dll")]
- public static extern short GetAsyncKeyState(int vKey);
- // Key Press Returns
- public bool KeyPressed(int vk)
- {
- return (GetAsyncKeyState(vk) & 32768) != 0;
- }
- public void Start()
- {
- // Start the insim application and define the settings
- insim.Initialize(new InSimSettings
- {
- Host = "127.0.0.1",
- Port = 29999,
- Admin = String.Empty,
- Flags = InSimFlags.ISF_LOCAL,
- IName = "Siren App"
- });
- // Confirm connection with local message to LFS and console exe
- insim.Send("/echo ^3Siren Application Connected");
- Console.WriteLine("Siren Application Connected");
- // Activate siren
- PoliceSirenOn = true;
- PoliceSirenSlow = true;
- PoliceSirenFast = false;
- PoliceSirenOff = false;
- PoliceSirenBool = true;
- Thread sirenController = new Thread(new ThreadStart(SirenController));
- sirenController.Start();
- // Keep the connection alive by setting CONNECTED to true and create a loop
- CONNECTED = true;
- while(CONNECTED)
- {
- Thread.Sleep(1);
- }
- }
- public void SirenController()
- {
- // Confirm that this void / method has been started as a new thread
- insim.Send("/echo Siren Controller Thread STARTED");
- var timeNow = DateTime.Now.Ticks / 10000;
- var timesinceLast = timeNow - lastTime;
- PoliceSirenSlow = true;
- while (PoliceSirenBool)
- {
- if (KeyPressed(0x21))
- {
- if (timesinceLast > 1 && timesinceLast < 500)
- {
- insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_OFF });
- PoliceSirenSlow = true;
- PoliceSirenFast = false;
- PoliceSirenPier = false;
- }
- else
- if (PoliceSirenSlow)
- {
- insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_SLOW });
- PoliceSirenSlow = false;
- PoliceSirenFast = true;
- PoliceSirenPier = false;
- lastTime = DateTime.Now.Ticks / 10000;
- }
- else
- if (PoliceSirenFast)
- {
- insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_HORN_OFF + LocalCarSwitches.LCS_SIREN_FAST });
- PoliceSirenSlow = false;
- PoliceSirenFast = false;
- PoliceSirenPier = true;
- lastTime = DateTime.Now.Ticks / 10000;
- }
- else
- if (PoliceSirenPier)
- {
- while (KeyPressed(0x42))
- {
- if (!KeyPressed(0x42))
- {
- Console.WriteLine("b is pressed");
- }
- }
- insim.Send(new IS_SMALL { ReqI = 0, SubT = SmallType.SMALL_LCS, UVal = LocalCarSwitches.LCS_SIREN_OFF + 327688 });
- PoliceSirenSlow = true;
- PoliceSirenFast = false;
- PoliceSirenPier = false;
- lastTime = DateTime.Now.Ticks / 10000;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement