Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using SteamKit2.GC.CSGO.Internal;
  4. using SteamKit2;
  5. using SteamKit2.Internal;
  6. using SteamKit2.GC;
  7. using System.Threading;
  8. using System.Collections.Concurrent;
  9. using System.Text.RegularExpressions;
  10.  
  11. /**
  12.  
  13. Too lazy to teach ppl have some sample shit code for csgo's float wear shit
  14.  
  15. **/
  16.  
  17.  
  18. namespace csgo_qq {
  19. public class InspectItem {
  20. public ulong param_s { get; set; } = 0;
  21. public ulong param_a { get; set; } = 0;
  22. public ulong param_d { get; set; } = 0;
  23. public ulong param_m { get; set; } = 0;
  24.  
  25. public static InspectItem FromLink(string link) {
  26. Match matches = LINK_REGEX.Match(link.ToLower());
  27.  
  28. if (!matches.Success)
  29. throw new ArgumentException("Bad inspection link");
  30.  
  31. return new InspectItem {
  32. param_s = matches.Groups["S"].Success ? Convert.ToUInt64(matches.Groups["S"].Value) : 0,
  33. param_a = Convert.ToUInt64(matches.Groups["A"].Value),
  34. param_d = Convert.ToUInt64(matches.Groups["D"].Value),
  35. param_m = matches.Groups["M"].Success ? Convert.ToUInt64(matches.Groups["M"].Value) : 0,
  36. };
  37. }
  38.  
  39. public bool Send(SteamGameCoordinator steamGC) {
  40. var request = new ClientGCMsgProtobuf<CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest>((uint) ECsgoGCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest);
  41.  
  42. request.Body.param_s = param_s;
  43. request.Body.param_a = param_a;
  44. request.Body.param_d = param_d;
  45. request.Body.param_m = param_m;
  46.  
  47. Console.WriteLine($"Requesting skin: ASSETID[{param_a}], DICKID[{param_d}], STEAMID[{param_s}], MARKETID[{param_m}]");
  48.  
  49. steamGC.Send(request, Client.APP_ID);
  50.  
  51. return true;
  52. }
  53.  
  54. public override string ToString() {
  55. return $"S[{param_s}] A[{param_a}] D[{param_d}] M[{param_m}]";
  56. }
  57.  
  58. public static Regex LINK_REGEX = new Regex(@"(?:s(?<S>\d+)|m(?<M>\d+))a(?<A>\d+)d(?<D>\d+)", RegexOptions.Compiled);
  59. }
  60.  
  61. public class Test {
  62. ConcurrentQueue<InspectItem> Items = new ConcurrentQueue<InspectItem>();
  63. private Thread _workerThread;
  64. private bool isRunning = false;
  65. public SteamGameCoordinator steamGC { get; set; }
  66.  
  67. public int Append(InspectItem item) {
  68. Items.Enqueue(item);
  69.  
  70. return Items.Count;
  71. }
  72.  
  73. public Test() {
  74. _workerThread = new Thread(Consume) { IsBackground = true, Name = "fuckmesenpai" };
  75. }
  76.  
  77. public void Start() {
  78. _workerThread.Start();
  79. isRunning = true;
  80. }
  81.  
  82. public void Stop() {
  83. isRunning = false;
  84. _workerThread.Abort();
  85. }
  86.  
  87. private void Consume() {
  88. while (isRunning) {
  89. InspectItem item;
  90.  
  91. if (!Items.TryDequeue(out item)) {
  92. Thread.Sleep(150);
  93. continue;
  94. }
  95.  
  96. item.Send(steamGC);
  97.  
  98. Thread.Sleep(1400);
  99. }
  100. }
  101. }
  102.  
  103. public class Client {
  104. public const uint APP_ID = 730;
  105.  
  106. public string username { get; set; }
  107. public string password { protected get; set; }
  108.  
  109. private static SteamClient steamClient { get; } = new SteamClient();
  110. private static CallbackManager manager { get; } = new CallbackManager(steamClient);
  111.  
  112. private static SteamUser steamUser { get; } = steamClient.GetHandler<SteamUser>();
  113. private static SteamFriends steamFriends { get; } = steamClient.GetHandler<SteamFriends>();
  114. private static SteamGameCoordinator steamGC { get; } = steamClient.GetHandler<SteamGameCoordinator>();
  115.  
  116. public bool isRunning, isReady;
  117.  
  118. public Test test;
  119.  
  120. public void Init(bool autoStart = false) {
  121. SteamDirectory.Initialize().Wait(); // Servers fucked
  122.  
  123. manager.Subscribe<SteamClient.ConnectedCallback>((callback) => {
  124. if (callback.Result != EResult.OK) {
  125. Stop($"Unable to connect to Steam: {callback.Result}");
  126. return;
  127. }
  128.  
  129. Console.WriteLine($"Connected to steam, logging into the account '{username}'.");
  130.  
  131. steamUser.LogOn(new SteamUser.LogOnDetails {
  132. Username = this.username,
  133. Password = this.password,
  134. });
  135.  
  136. this.password = null;
  137. });
  138.  
  139. manager.Subscribe<SteamGameCoordinator.MessageCallback>(OnMessage);
  140.  
  141. manager.Subscribe<SteamUser.LoggedOnCallback>((cb) => Launch());
  142. manager.Subscribe<SteamUser.LoggedOffCallback>((cb) => Stop($"Logged off: {cb.Result}"));
  143.  
  144. manager.Subscribe<SteamClient.DisconnectedCallback>((cb) => Stop($"Disconnected: UI[{cb.UserInitiated}]"));
  145. manager.Subscribe<SteamUser.AccountInfoCallback>(async (cb) => await steamFriends.SetPersonaState(EPersonaState.Online));
  146.  
  147. if (autoStart)
  148. Start();
  149. }
  150.  
  151. public void Start() {
  152. Console.WriteLine("Connecting to Steam...");
  153.  
  154. isRunning = true;
  155.  
  156. steamClient.Connect();
  157.  
  158. while (isRunning)
  159. manager.RunWaitCallbacks(TimeSpan.FromSeconds(5));
  160.  
  161. Console.WriteLine("Ended");
  162. Console.ReadKey();
  163. }
  164.  
  165.  
  166. public void OnMessage(SteamGameCoordinator.MessageCallback callback) {
  167. Console.WriteLine($"Msg: {callback.AppID} {callback.EMsg} {callback.Message}");
  168.  
  169. switch (callback.EMsg) {
  170. // case (uint) EGCBaseClientMsg.k_EMsgGCClientConnectionStatus: useless
  171. case (uint) ECsgoGCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse:
  172. var msg = new ClientGCMsgProtobuf<CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse>(callback.Message);
  173. Console.WriteLine($"Got skin: ASSETID[{msg.Body.iteminfo.itemid}]");
  174. break;
  175. }
  176. }
  177.  
  178. public void Launch() {
  179. Console.WriteLine("Launching the game");
  180.  
  181. var playGame = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
  182.  
  183. playGame.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = APP_ID });
  184.  
  185. steamClient.Send(playGame);
  186.  
  187. Thread.Sleep(550);
  188.  
  189. isReady = true;
  190.  
  191. test = new Test { steamGC = steamGC };
  192.  
  193. test.Start();
  194.  
  195. new string[] {
  196. "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M624118688564276523A5408039791D19281346927938555",
  197. "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198105687636A3173070464D2334815196074989997",
  198. "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198105687636A3172915484D2334815196074989997",
  199. "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198105687636A4059023842D14448148361047816919",
  200. "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198105687636A4068938673D9838858901213249043"
  201. }.ToList().ForEach(s => test.Append(InspectItem.FromLink(s)));
  202. }
  203.  
  204. public bool canCheck() => isRunning && isReady;
  205.  
  206. public bool Stop(object Message) {
  207. Console.WriteLine(Message);
  208. return isRunning = false;
  209. }
  210. }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement