Advertisement
esref_21

Arduino & CS:GO, C# Code

Nov 7th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.75 KB | None | 0 0
  1. ------------------------------------TRANSLATED TO ENGLISH FOR INSTRUCTABLES------------------------------------
  2. using System;
  3. using CSGSI;
  4. using CSGSI.Nodes;
  5. using System.IO.Ports;
  6. using System.Threading;
  7. namespace CSGO_Deneme
  8. {
  9.  
  10. class Program
  11. {
  12. static SerialPort serialPort;
  13. static GameStateListener gsl;
  14.  
  15. static void Main(string[] args)
  16. {
  17. serialPort = new SerialPort();
  18. serialPort.PortName = "COM14";
  19. serialPort.BaudRate = 57600;
  20. serialPort.Parity = Parity.None;
  21. serialPort.StopBits = StopBits.One;
  22. serialPort.DataBits = 8;
  23. serialPort.Handshake = Handshake.None;
  24. serialPort.Open();
  25.  
  26. gsl = new GameStateListener(3000);
  27. gsl.NewGameState += new NewGameStateHandler(OnNewGameState);
  28. if (!gsl.Start())
  29. {
  30. Environment.Exit(0);
  31. }
  32. Console.WriteLine("Waiting..\n");
  33. }
  34.  
  35. static bool isBombPlant = false;
  36. static bool isBombDefused = false;
  37. static bool IsRoundOver = false;
  38. static string PlayerName;
  39. public static bool Once = false;
  40. static int Level = 0;
  41. static void OnNewGameState(GameState gs)
  42. {
  43. if (Once == false)
  44. {
  45. Console.WriteLine("Player Name= " + gs.Player.Name);
  46. PlayerName = gs.Player.Name;
  47. Console.WriteLine("Oynanan Harita= " + gs.Map.Name);
  48. Console.WriteLine("Oynanan Mod= " + gs.Map.Mode + "\n");
  49. Once = true;
  50. serialPort.Write("1");
  51. }
  52.  
  53. if (gs.Previously.Round.Phase == RoundPhase.Over) // When the new round started
  54. {
  55. isBombPlant = false;
  56. IsRoundOver = false;
  57. serialPort.Write("-");
  58. Console.WriteLine("-----New Round Started-----");
  59. Console.WriteLine("*Money= " + gs.Player.State.Money);
  60. Console.WriteLine("*CT=" + gs.Map.TeamCT.Score + " T=" + gs.Map.TeamT.Score);
  61. Console.WriteLine("Total Killed= " + gs.Player.MatchStats.Kills); ;
  62. Console.WriteLine("Total Death= " + gs.Player.MatchStats.Deaths);
  63. }
  64. if (gs.Previously.Player.MatchStats.Deaths != -1 && gs.Player.State.Health == 0 && gs.Player.Name == PlayerName) // If you die
  65. {
  66. Console.WriteLine("You Died!");
  67. Level = 0;
  68. serialPort.Write("-");
  69. }
  70. if (gs.Round.Phase == RoundPhase.Over && IsRoundOver == false) // If the round over
  71. {
  72. if (gs.Player.State.RoundKills != 0 && gs.Player.Name == PlayerName)
  73. {
  74. Console.Write("\nYou Killed: " + gs.Player.State.RoundKills + " Person That Round");
  75. if (gs.Player.State.RoundKillHS != 0)
  76. {
  77. Console.WriteLine(" And: " + gs.Player.State.RoundKillHS + " HS you Shooted");
  78. }
  79. }
  80.  
  81. if (gs.Round.WinTeam == RoundWinTeam.CT)
  82. {
  83. if (gs.Round.Bomb == BombState.Defused)
  84. {
  85. Console.WriteLine("*CT Win the Round bu Defusing The Bomb");
  86. }
  87. if (gs.Round.Bomb != BombState.Defused)
  88. {
  89. Console.WriteLine("*CT Win the Round");
  90. }
  91. }
  92. if (gs.Round.WinTeam == RoundWinTeam.T)
  93. {
  94. if (gs.Round.Bomb == BombState.Exploded)
  95. {
  96. Console.WriteLine("*T Win the Round By Exploding Bomb");
  97. }
  98. if (gs.Round.Bomb == BombState.Planted || gs.Round.Bomb == BombState.Undefined)
  99. {
  100. Console.WriteLine("*T Win The Round");
  101. }
  102. }
  103. IsRoundOver = true;
  104. }
  105. if (!isBombPlant && gs.Round.Bomb == BombState.Planted)
  106. {
  107. Console.WriteLine("Bomb Planted");
  108. isBombPlant = true;
  109. }
  110. if (isBombPlant && gs.Round.Bomb == BombState.Defused && isBombDefused == false)
  111. {
  112. isBombDefused = true;
  113. Console.WriteLine("Bomb Defused");
  114. }
  115. if (gs.Previously.Player.State.Health != -1 && gs.Player.Name == PlayerName) // If your health reduces
  116. {
  117. if (gs.Player.State.Health != 0 && gs.Player.State.Health != 100)
  118. {
  119. Console.WriteLine(gs.Player.State.Health + " HP Left");
  120. if (Level == 0)
  121. {
  122. Console.WriteLine("Giving Shock");
  123. Level++;
  124. serialPort.Write("+");
  125. }
  126.  
  127. }
  128. }
  129. if (gs.Previously.Player.State.Health == -1 && gs.Player.Name == PlayerName) // IF the health is stable
  130. {
  131. if (Level >0)
  132. {
  133. Level = 0;
  134. Console.WriteLine("Shock Canceling");
  135. serialPort.Write("-");
  136. }
  137. }
  138. if (gs.Player.State.Flashed != 0)
  139. {
  140. Console.WriteLine("Flash!");
  141. }
  142. if (gs.Previously.Player.MatchStats.Kills != -1 && gs.Round.Phase == RoundPhase.Live && gs.Player.Name == PlayerName) // IF you kill someone
  143. {
  144. Console.WriteLine(gs.Player.MatchStats.Kills - gs.Previously.Player.MatchStats.Kills + " Person You Killed");
  145. }
  146. if (Console.ReadKey(true).Key == ConsoleKey.Escape)
  147. {
  148. serialPort.Write("0");
  149. }
  150. }
  151. }
  152. }
  153. ---------------------------------------------------------------------------------------------------------------
  154.  
  155.  
  156.  
  157. ------------------------------------ORIGINAL CODE------------------------------------
  158. using System;
  159. using CSGSI;
  160. using CSGSI.Nodes;
  161. using System.IO.Ports;
  162. using System.Threading;
  163. namespace CSGO_Deneme
  164. {
  165.  
  166. class Program
  167. {
  168. static SerialPort seriPort;
  169. static GameStateListener gsl;
  170.  
  171. static void Main(string[] args)
  172. {
  173. seriPort = new SerialPort();
  174. seriPort.PortName = "COM14";
  175. seriPort.BaudRate = 57600;
  176. seriPort.Parity = Parity.None;
  177. seriPort.StopBits = StopBits.One;
  178. seriPort.DataBits = 8;
  179. seriPort.Handshake = Handshake.None;
  180. seriPort.Open();
  181.  
  182. gsl = new GameStateListener(3000);
  183. gsl.NewGameState += new NewGameStateHandler(OnNewGameState);
  184. if (!gsl.Start())
  185. {
  186. Environment.Exit(0);
  187. }
  188. Console.WriteLine("Bekleniliyor...\n");
  189. }
  190.  
  191. static bool BombaKuruluMu = false;
  192. static bool BombaImhaEdildiMi = false;
  193. static bool ElBittiMi = false;
  194. static string OyuncuAdi;
  195. public static bool TekSeferlik = false;
  196. static int Duzey = 0;
  197. static void OnNewGameState(GameState gs)
  198. {
  199. if (TekSeferlik == false)
  200. {
  201. Console.WriteLine("Oyuncu Adı= " + gs.Player.Name);
  202. OyuncuAdi = gs.Player.Name;
  203. Console.WriteLine("Oynanan Harita= " + gs.Map.Name);
  204. Console.WriteLine("Oynanan Mod= " + gs.Map.Mode + "\n");
  205. TekSeferlik = true;
  206. seriPort.Write("1");
  207. }
  208.  
  209. if (gs.Previously.Round.Phase == RoundPhase.Over) // Yeni Round Başladığında
  210. {
  211. BombaKuruluMu = false;
  212. ElBittiMi = false;
  213. seriPort.Write("-");
  214. Console.WriteLine("-----Yeni El Başladı-----");
  215. Console.WriteLine("*Eldeki Silah= " + gs.Player.Weapons.ActiveWeapon.Type +", "+ gs.Player.Weapons.ActiveWeapon.Name); // Sİilahı Göster
  216. Console.WriteLine("*Para= " + gs.Player.State.Money); // Parayı Göster
  217. Console.WriteLine("*CT=" + gs.Map.TeamCT.Score + " T=" + gs.Map.TeamT.Score); // Skoru Göster
  218. Console.WriteLine("Toplam Öldürdüğün Kişi= " + gs.Player.MatchStats.Kills); ; // Toplam Öldürülen Kişi Sayısını Göster
  219. Console.WriteLine("Toplam Ölüm Sayın= " + gs.Player.MatchStats.Deaths); // Toplam Ölümü Göster
  220. }
  221. if (gs.Previously.Player.MatchStats.Deaths != -1 && gs.Player.State.Health == 0 && gs.Player.Name == OyuncuAdi) // Birini Öldürürsen
  222. {
  223. Console.WriteLine("Öldün");
  224. Duzey = 0;
  225. seriPort.Write("-");
  226. }
  227. if (gs.Round.Phase == RoundPhase.Over && ElBittiMi == false) // Round Biterse
  228. {
  229. if (gs.Player.State.RoundKills != 0 && gs.Player.Name == OyuncuAdi)
  230. {
  231. Console.Write("\nBu Round " + gs.Player.State.RoundKills + " Kişiye Öldürdün");
  232. if (gs.Player.State.RoundKillHS != 0)
  233. {
  234. Console.WriteLine(" Ve " + gs.Player.State.RoundKillHS + " Kişiye HS Attın");
  235. }
  236. }
  237.  
  238. if (gs.Round.WinTeam == RoundWinTeam.CT) // CT Kazanır İse
  239. {
  240. if (gs.Round.Bomb == BombState.Defused)
  241. {
  242. Console.WriteLine("*Eli CT Bombayı İmha Ederek Aldı");
  243. }
  244. if (gs.Round.Bomb != BombState.Defused)
  245. {
  246. Console.WriteLine("*Eli CT Aldı");
  247. }
  248. }
  249. if (gs.Round.WinTeam == RoundWinTeam.T) // T Kazanır İse
  250. {
  251. if (gs.Round.Bomb == BombState.Exploded)
  252. {
  253. Console.WriteLine("*Eli T Bombayı Patlatarak Aldı");
  254. }
  255. if (gs.Round.Bomb == BombState.Planted || gs.Round.Bomb == BombState.Undefined)
  256. {
  257. Console.WriteLine("*Eli T Aldı");
  258. }
  259. }
  260. ElBittiMi = true;
  261. }
  262. if (!BombaKuruluMu && gs.Round.Bomb == BombState.Planted)
  263. {
  264. Console.WriteLine("Bomba Kuruldu");
  265. BombaKuruluMu = true;
  266. }
  267. if (BombaKuruluMu && gs.Round.Bomb == BombState.Defused && BombaImhaEdildiMi == false)
  268. {
  269. BombaImhaEdildiMi = true;
  270. Console.WriteLine("Bomba İmha Edildi");
  271. }
  272. if (gs.Previously.Player.State.Health != -1 && gs.Player.Name == OyuncuAdi) // Canın Azalır ise
  273. {
  274. if (gs.Player.State.Health != 0 && gs.Player.State.Health != 100)
  275. {
  276. Console.WriteLine(gs.Player.State.Health + " HP Kaldı");
  277. if (Duzey == 0)
  278. {
  279. Console.WriteLine("Şok Veriliyor");
  280. Duzey++;
  281. seriPort.Write("+");
  282. }
  283.  
  284. }
  285. }
  286. if (gs.Previously.Player.State.Health == -1 && gs.Player.Name == OyuncuAdi) // Can Sabit İse
  287. {
  288. if (Duzey >0)
  289. {
  290. Duzey = 0;
  291. Console.WriteLine("Şok İptal Ediliyor");
  292. seriPort.Write("-");
  293. }
  294. }
  295. if (gs.Player.State.Flashed != 0)
  296. {
  297. Console.WriteLine("Flaşın Etkisinde");
  298. }
  299. if (gs.Previously.Player.MatchStats.Kills != -1 && gs.Round.Phase == RoundPhase.Live && gs.Player.Name == OyuncuAdi) // Birini Öldürürsen
  300. {
  301. Console.WriteLine(gs.Player.MatchStats.Kills - gs.Previously.Player.MatchStats.Kills + " Kişi Öldürdün");
  302. }
  303. if (Console.ReadKey(true).Key == ConsoleKey.Escape)
  304. {
  305. seriPort.Write("0");
  306. }
  307. }
  308. }
  309. }
  310. -------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement