Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.98 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using InSimDotNet;
  4. using InSimDotNet.Packets;
  5. using InSimDotNet.Helpers;
  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 Example_Application
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             var program = new Application();
  19.             program.Start();
  20.         }
  21.     }
  22.  
  23.     class Application
  24.     {
  25.         // DECLARE ANY VARIABLES HERE
  26.         InSim insim = new InSim(); // This is saying that we are declaring a new application and calling it just 'insim'
  27.  
  28.         public void Start()
  29.         {
  30.             // Bind packet events - These will have their own Methods (voids) further below in the application
  31.             insim.Bind<IS_BTC>(ButtonClick);
  32.            
  33.  
  34.             // Start the insim application and define the settings
  35.             insim.Initialize(new InSimSettings
  36.             {
  37.                 Host = "127.0.0.1", // Host where LFS is runing
  38.                 Port = 29999, // Port to connect to LFS through
  39.                 Admin = String.Empty, // Optional game admin password - obviously this is empty, you dont really need to use it
  40.                 Interval = 250, // Depends how quick you want stuff to update, ie how quick your speed button updates etc
  41.                 Flags = InSimFlags.ISF_LOCAL | InSimFlags.ISF_MCI, // This needs to be set. ISF_LOCAL stops interfering with server side insims, ISF_MCI gives you car update packets
  42.                 IName = "CSR Application",
  43.             });
  44.  
  45.             // Confirm connection to LFS with a simple message to LFS itself and the console window
  46.             insim.Send("/echo ^3This application has connected to LFS"); // Sending text to LFS
  47.             Console.WriteLine("This application has connected to LFS"); // Sending text to the console window - Both are totally optional
  48.  
  49.             // Create buttons to send to local player
  50.             // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  51.             //  CONTAINER
  52.             insim.Send(new IS_BTN { Text = "", L = 0, T = 126, W = 30, H = 70, ReqI = 1, ClickID = 1, UCID = 0, BStyle = ButtonStyles.ISB_DARK });
  53.             //  AUTHOR DETAILS
  54.             insim.Send(new IS_BTN { Text = "^1[TC]", L = 0, T = 176, W = 16, H = 10, ReqI = 2, ClickID = 2, UCID = 0, });
  55.             insim.Send(new IS_BTN { Text = "^7CityDriving", L = 0, T = 185, W = 16, H = 3, ReqI = 3, ClickID = 3, UCID = 0, });
  56.             //  RESET
  57.             insim.Send(new IS_BTN { Text = "^2RESET", L = 16, T = 185, W = 12, H = 8, ReqI = 4, ClickID = 4, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  58.             //  AT SCENE
  59.             insim.Send(new IS_BTN { Text = "^3AT SCENE", L = 16, T = 175, W = 12, H = 8, ReqI = 5, ClickID = 5, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  60.             //  999
  61.             insim.Send(new IS_BTN { Text = "^4999", L = 16, T = 165, W = 12, H = 8, ReqI = 6, ClickID = 6, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  62.             //  SIREN
  63.             insim.Send(new IS_BTN { Text = "SIREN", L = 2, T = 165, W = 12, H = 8, ReqI = 7, ClickID = 7, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  64.             //  360 BLUES
  65.             insim.Send(new IS_BTN { Text = "360", L = 2, T = 129, W = 8, H = 5, ReqI = 8, ClickID = 8, UCID = 0, }); // TOP TEXT
  66.             insim.Send(new IS_BTN { Text = "BLUES", L = 2, T = 134, W = 8, H = 5, ReqI = 9, ClickID = 9, UCID = 0, }); // BOTTOM TEXT
  67.             insim.Send(new IS_BTN { Text = "", L = 2, T = 129, W = 8, H = 10, ReqI = 10, ClickID = 10, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  68.             //   360 LEDS
  69.             insim.Send(new IS_BTN { Text = "360", L = 11, T = 129, W = 8, H = 5, ReqI = 11, ClickID = 11, UCID = 0, }); // TOP TEXT
  70.             insim.Send(new IS_BTN { Text = "LEDS", L = 11, T = 134, W = 8, H = 5, ReqI = 12, ClickID = 12, UCID = 0, }); // BOTTOM TEXT
  71.             insim.Send(new IS_BTN { Text = "", L = 11, T = 129, W = 8, H = 10, ReqI = 13, ClickID = 13, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  72.             //  360 REDS
  73.             insim.Send(new IS_BTN { Text = "360", L = 20, T = 129, W = 8, H = 5, ReqI = 14, ClickID = 14, UCID = 0, }); // TOP TEXT
  74.             insim.Send(new IS_BTN { Text = "REDS", L = 20, T = 134, W = 8, H = 5, ReqI = 15, ClickID = 15, UCID = 0, }); // BOTTOM TEXT
  75.             insim.Send(new IS_BTN { Text = "", L = 20, T = 129, W = 8, H = 10, ReqI = 16, ClickID = 16, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  76.             //  REAR REDS
  77.             insim.Send(new IS_BTN { Text = "REAR", L = 20, T = 141, W = 8, H = 5, ReqI = 17, ClickID = 17, UCID = 0, }); // TOP TEXT
  78.             insim.Send(new IS_BTN { Text = "REDS", L = 20, T = 146, W = 8, H = 5, ReqI = 18, ClickID = 18, UCID = 0, }); // BOTTOM TEXT
  79.             insim.Send(new IS_BTN { Text = "", L = 20, T = 141, W = 8, H = 10, ReqI = 19, ClickID = 19, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  80.             //  HEADLAMP FLASH
  81.             insim.Send(new IS_BTN { Text = "H/L", L = 11, T = 141, W = 8, H = 5, ReqI = 20, ClickID = 20, UCID = 0, });  // TOP TEXT
  82.             insim.Send(new IS_BTN { Text = "FLASH", L = 11, T = 146, W = 8, H = 5, ReqI = 21, ClickID = 21, UCID = 0, }); // BOTTOM TEXT
  83.             insim.Send(new IS_BTN { Text = "", L = 11, T = 141, W = 8, H = 10, ReqI = 22, ClickID = 22, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  84.             //  HEADLAMP AND REAR FLASH
  85.             insim.Send(new IS_BTN { Text = "F/R", L = 2, T = 141, W = 8, H = 5, ReqI = 23, ClickID = 23, UCID = 0, }); // TOP TEXT
  86.             insim.Send(new IS_BTN { Text = "FLASH", L = 2, T = 146, W = 8, H = 5, ReqI = 24, ClickID = 24, UCID = 0, }); // BOTTOM TEXT
  87.             insim.Send(new IS_BTN { Text = "", L = 2, T = 141, W = 8, H = 10, ReqI = 25, ClickID = 25, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  88.             // BLANK
  89.             insim.Send(new IS_BTN { Text = "", L = 2, T = 153, W = 8, H = 5, ReqI = 26, ClickID = 26, UCID = 0, }); // TOP TEXT
  90.             insim.Send(new IS_BTN { Text = "", L = 2, T = 158, W = 8, H = 5, ReqI = 27, ClickID = 27, UCID = 0, }); // BOTTOM TEXT
  91.             insim.Send(new IS_BTN { Text = "", L = 2, T = 153, W = 8, H = 10, ReqI = 28, ClickID = 28, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  92.             //  REAR MATRIX
  93.             insim.Send(new IS_BTN { Text = "REAR", L = 11, T = 153, W = 8, H = 5, ReqI = 29, ClickID = 29, UCID = 0, }); // TOP TEXT
  94.             insim.Send(new IS_BTN { Text = "MATRIX", L = 11, T = 158, W = 8, H = 5, ReqI = 30, ClickID = 30, UCID = 0, }); // BOTTOM TEXT
  95.             insim.Send(new IS_BTN { Text = "", L = 11, T = 153, W = 8, H = 10, ReqI = 31, ClickID = 31, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  96.             // BLANK
  97.             insim.Send(new IS_BTN { Text = "", L = 20, T = 153, W = 8, H = 5, ReqI = 32, ClickID = 32, UCID = 0, }); // TOP TEXT
  98.             insim.Send(new IS_BTN { Text = "", L = 20, T = 158, W = 8, H = 5, ReqI = 33, ClickID = 33, UCID = 0, }); // BOTTOM TEXT
  99.             insim.Send(new IS_BTN { Text = "", L = 20, T = 153, W = 8, H = 10, ReqI = 34, ClickID = 34, UCID = 0, BStyle = ButtonStyles.ISB_CLICK | ButtonStyles.ISB_LIGHT });
  100.  
  101.             // Stop the application from loosing connection by adding a loop - This should be at the end of your first Starting void/method, so everything before it loads properly
  102.             while (insim.IsConnected)
  103.             {
  104.                 Thread.Sleep(200);
  105.             }
  106.         }
  107.  
  108.         public void ButtonClick(InSim insim, IS_BTC btc)
  109.         {
  110.             // Deal with button clicks here
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement