Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using RestSharp;
- using TarkovLibrary.Library.API;
- namespace TarkovLibrary.Library
- {
- public class Web
- {
- private Dictionary<Endpoint, RestClient> _clients = new Dictionary<Endpoint, RestClient>();
- public readonly string BSG_LAUNCHER_VERSION = "";
- public readonly string EFT_CLIENT_VERSION = "";
- public readonly string UNITY_VERSION = "";
- private string EFT_SESSION = "";
- private const string EFT_HWID = "your hwid here";
- public enum Endpoint
- {
- Launcher,
- Production,
- Ragfair,
- Trading
- }
- public Web()
- {
- _clients.Add(Endpoint.Launcher, new RestClient("https://launcher.escapefromtarkov.com"));
- _clients.Add(Endpoint.Production, new RestClient("https://prod.escapefromtarkov.com"));
- _clients.Add(Endpoint.Ragfair, new RestClient("https://ragfair.escapefromtarkov.com"));
- _clients.Add(Endpoint.Trading, new RestClient("https://trading.escapefromtarkov.com"));
- BSG_LAUNCHER_VERSION = "0.9.2.970";
- EFT_CLIENT_VERSION = "0.12.3.5776";
- UNITY_VERSION = "2018.4.13f1";
- }
- public string GetHWID()
- {
- return EFT_HWID;
- }
- public void SetSession(string sess)
- {
- EFT_SESSION = sess;
- }
- /// <summary>
- /// Used for the first login request to eft
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="p">The endpoint requested</param>
- /// <param name="offset">The offset to the endpoint</param>
- /// <param name="json">The content</param>
- /// <returns></returns>
- public async Task<T> PostLow<T>(Endpoint p, string offset, string json)
- {
- RestClient client = _clients[p];
- RestRequest request = new RestRequest(offset, DataFormat.None); // We set the DataFormat to none to prevent RestSharp from throwing errors, since the data is still inflated
- request.Method = Method.POST; // Post it to bsg
- request.AddJsonBody(json); // Add our body
- request.AddHeader("Content-Type", "application/json");
- request.AddHeader("User-Agent", $"BSG Launcher {BSG_LAUNCHER_VERSION}");
- IRestResponse response = await client.ExecuteAsync(request);
- BaseResponse<T> data = GetContentFromResponse<T>(response);
- return data.Get();
- }
- /// <summary>
- /// Used to exchange tokens with EFT to get our session
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="p"></param>
- /// <param name="offset"></param>
- /// <param name="json"></param>
- /// <param name="token">The token from PostLow with the login offset</param>
- /// <returns></returns>
- public async Task<T> PostMedium<T>(Endpoint p, string offset, string json, string token)
- {
- RestClient client = _clients[p];
- RestRequest request = new RestRequest(offset, DataFormat.None); // We set the DataFormat to none to prevent RestSharp from throwing errors, since the data is still inflated
- request.Method = Method.POST; // Post it to bsg
- request.AddJsonBody(json); // Add our body
- request.AddHeader("Content-Type", "application/json");
- request.AddHeader("User-Agent", $"BSG Launcher {BSG_LAUNCHER_VERSION}");
- request.AddHeader("Authorization", token);
- IRestResponse response = await client.ExecuteAsync(request);
- BaseResponse<T> data = GetContentFromResponse<T>(response);
- return data.Get();
- }
- /// <summary>
- /// Used to post to the general API
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="p"></param>
- /// <param name="offset"></param>
- /// <param name="json"></param>
- /// <returns></returns>
- public async Task<T> PostHigh<T>(Endpoint p, string offset, string json)
- {
- RestClient client = _clients[p];
- RestRequest request = new RestRequest(offset, DataFormat.None); // We set the DataFormat to none to prevent RestSharp from throwing errors, since the data is still inflated
- request.Method = Method.POST; // Post it to bsg
- request.AddJsonBody(json); // Add our body
- request.AddHeader("Content-Type", "application/json");
- request.AddHeader("User-Agent", $"UnityPlayer/{UNITY_VERSION} (UnityWebRequest/1.0, libcurl/7.52.0-DEV)");
- request.AddHeader("App-Version", $"EFT Client {EFT_CLIENT_VERSION}");
- request.AddHeader("X-Unity-Version", $"{UNITY_VERSION}");
- request.AddCookie("PHPSESSID", EFT_SESSION);
- IRestResponse response = await client.ExecuteAsync(request);
- BaseResponse<T> data = GetContentFromResponse<T>(response);
- return data.Get();
- }
- /// <summary>
- /// Same as post high, but returns a string response of the raw json
- /// </summary>
- /// <param name="p"></param>
- /// <param name="offset"></param>
- /// <param name="json"></param>
- /// <returns></returns>
- public async Task<string> PostRaw(Endpoint p, string offset, string json)
- {
- RestClient client = _clients[p];
- RestRequest request = new RestRequest(offset, DataFormat.None); // We set the DataFormat to none to prevent RestSharp from throwing errors, since the data is still inflated
- request.Method = Method.POST; // Post it to bsg
- request.AddJsonBody(json); // Add our body
- request.AddHeader("Content-Type", "application/json");
- request.AddHeader("User-Agent", $"UnityPlayer/{UNITY_VERSION} (UnityWebRequest/1.0, libcurl/7.52.0-DEV)");
- request.AddHeader("App-Version", $"EFT Client {EFT_CLIENT_VERSION}");
- request.AddHeader("X-Unity-Version", $"{UNITY_VERSION}");
- request.AddCookie("PHPSESSID", EFT_SESSION);
- IRestResponse response = await client.ExecuteAsync(request);
- byte[] bytes = response.RawBytes;
- string content = Encoding.UTF8.GetString(Utilities.Decompress(bytes));
- return content;
- }
- private BaseResponse<T> GetContentFromResponse<T>(IRestResponse response)
- {
- byte[] bytes = response.RawBytes;
- string content = Encoding.UTF8.GetString(Utilities.Decompress(bytes));
- return JsonConvert.DeserializeObject<BaseResponse<T>>(content);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.IO.Compression;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- namespace TarkovLibrary.Library
- {
- public class Utilities
- {
- public static string MD5Hash(string input)
- {
- using (MD5 md5Hash = MD5.Create())
- {
- byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
- StringBuilder sBuilder = new StringBuilder();
- for (int i = 0; i < data.Length; i++)
- {
- sBuilder.Append(data[i].ToString("x2"));
- }
- return sBuilder.ToString();
- }
- }
- public static byte[] Decompress(byte[] gzip)
- {
- using (GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress))
- {
- const int size = 4096;
- byte[] buffer = new byte[size];
- using (MemoryStream memory = new MemoryStream())
- {
- int count = 0;
- do
- {
- count = stream.Read(buffer, 0, size);
- if (count > 0)
- {
- memory.Write(buffer, 0, count);
- }
- }
- while (count > 0);
- return memory.ToArray();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment