diff --git a/Partypacker/Core/Server.cs b/Partypacker/Core/Server.cs new file mode 100644 index 0000000..f89f38a --- /dev/null +++ b/Partypacker/Core/Server.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace Partypacker.Core +{ + internal class Server + { + public static KeyValuePair GET(string URL = "/") + { + if (URL.StartsWith("/")) + URL = "https://example.com" + URL; + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); + request.Method = "GET"; + // request.Headers.Add("my-header", "my-value"); + + string Response = ""; + try + { + var WebResponse = request.GetResponse(); + + StreamReader sr = new StreamReader(WebResponse.GetResponseStream()); + Response = sr.ReadToEnd(); + sr.Close(); + + return new KeyValuePair(true, Response); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return new KeyValuePair(false, string.Empty); + } + } + public static KeyValuePair POST(string URL = "/", string Body = "") + { + if (URL.StartsWith("/")) + URL = "https://example.com" + URL; + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); + request.Method = "POST"; + request.ContentType = "text/plain"; + + string Response = ""; + try + { + var WebRequest = request.GetRequestStream(); + WebRequest.Write(Encoding.UTF8.GetBytes(Body), 0, Body.Length); + + var WebResponse = request.GetResponse(); + + StreamReader sr = new StreamReader(WebResponse.GetResponseStream()); + Response = sr.ReadToEnd(); + sr.Close(); + + return new KeyValuePair(true, Response); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return new KeyValuePair(false, string.Empty); + } + } + } + + +} diff --git a/Partypacker/Core/Win32.cs b/Partypacker/Core/Win32.cs index e4037fa..6320995 100644 --- a/Partypacker/Core/Win32.cs +++ b/Partypacker/Core/Win32.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; -namespace Partypacker.Core +namespace Partypacker { internal static class Win32 { diff --git a/Partypacker/NewFile1.txt b/Partypacker/NewFile1.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Partypacker/NewFile1.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Partypacker/Partypacker.csproj b/Partypacker/Partypacker.csproj index 8332a03..4afd260 100644 --- a/Partypacker/Partypacker.csproj +++ b/Partypacker/Partypacker.csproj @@ -5,6 +5,8 @@ net7.0 enable enable + icon.ico + icon.ico @@ -12,5 +14,12 @@ + + + + True + + + diff --git a/Partypacker/Program.cs b/Partypacker/Program.cs index 457a434..1f0638e 100644 --- a/Partypacker/Program.cs +++ b/Partypacker/Program.cs @@ -1,12 +1,26 @@ -using Partypacker; +using Partypacker.Net; using Pastel; +using System.Diagnostics; using System.Drawing; +using static Partypacker.Win32; -Console.SetWindowSize(75, 20); +namespace Partypacker +{ + public static class Program + { + private static SetConsoleCtrlEventHandler CtrlHandler; + private static Proxy Proxx; -Console.CursorVisible = false; + private static void Main(string[] args) + { + ushort? port = 6969; -Console.WriteLine(@" + Console.SetWindowSize(75, 20); + Console.SetBufferSize(75, 20); + + Console.CursorVisible = false; + + Console.WriteLine(@" _____ _ _ | __ \ | | | | | |__) |_ _ _ __| |_ _ _ _ __ __ _ ___| | _____ _ __ @@ -15,44 +29,85 @@ Console.WriteLine(@" |_| \__,_|_| \__|\__, | .__/ \__,_|\___|_|\_\___|_| __/ | | |___/|_| ".Pastel(Color.IndianRed)); -Console.WriteLine("-----------------------------------------------------------".Pastel(Color.CadetBlue)); + Console.WriteLine("-----------------------------------------------------------".Pastel(Color.CadetBlue)); -Console.WriteLine("Welcome to Partypacker - Select an option below:"); + Console.WriteLine("Welcome to Partypacker - Select an option below:"); -ConsoleKeyInfo ReceivedKeyInput; -int SelectedOptionIndex = 0; -bool Running = true; -SelectableOption[] Options = new SelectableOption[] -{ - new SelectableOption("Launch Fortnite", () => { Console.WriteLine("cool!"); }), - new SelectableOption("Open Dashboard", () => { Console.WriteLine("epic!"); }), - new SelectableOption("Settings", () => { Console.WriteLine("awesome!"); }) -}; + ConsoleKeyInfo ReceivedKeyInput; + int SelectedOptionIndex = 0; + bool Running = true; + SelectableOption[] Options = new SelectableOption[] + { + new SelectableOption("Launch Fortnite", () => + Run(port, () => Process.Start("com.epicgames.launcher://apps/fn%3A4fe75bbc5a674f4f9b356b5c90567da5%3AFortnite?action=launch&silent=true"))), + new SelectableOption("Open Dashboard", () => { Console.WriteLine("epic!"); }), + new SelectableOption("Settings", () => { Console.WriteLine("awesome!"); }) + }; -while (Running) -{ - (int left, int top) = Console.GetCursorPosition(); - for (int i = 0; i < Options.Length; i++) - { - bool Selected = SelectedOptionIndex == i; - SelectableOption Option = Options[i]; - Console.WriteLine($"{(Selected ? ">".Pastel(Color.LimeGreen) : " ")} {Option.Name.Pastel(Selected ? Color.DarkGreen : Color.Gray)}"); + try + { + while (Running) + { + (int left, int top) = Console.GetCursorPosition(); + for (int i = 0; i < Options.Length; i++) + { + bool Selected = SelectedOptionIndex == i; + SelectableOption Option = Options[i]; + Console.WriteLine($"{(Selected ? ">".Pastel(Color.LimeGreen) : " ")} {Option.Name.Pastel(Selected ? Color.DarkGreen : Color.Gray)}"); + } + + ReceivedKeyInput = Console.ReadKey(); + switch (ReceivedKeyInput.Key) + { + case ConsoleKey.UpArrow: + SelectedOptionIndex--; + break; + case ConsoleKey.DownArrow: + SelectedOptionIndex++; + break; + case ConsoleKey.Enter: + Options[SelectedOptionIndex].OnPress.Invoke(); + break; + } + + Console.SetCursorPosition(left, top); + SelectedOptionIndex = Math.Clamp(SelectedOptionIndex, 0, Options.Length); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + OnApplicationExit(); + } + } + + private static void Run(ushort? port, Action Finish) + { + CtrlHandler = CleanUp; + SetConsoleCtrlHandler(CtrlHandler, true); + Proxx = port switch + { + null => new Proxy(), + _ => new Proxy((ushort)port) + }; + Proxx.StartProxy(); + + Finish.Invoke(); + } + + public static void OnApplicationExit() + { + CleanUp(CtrlType.CTRL_C_EVENT); + } + + private static bool CleanUp(CtrlType ctrlType) + { + Proxx.StopProxy(); + return true; + } } +} - ReceivedKeyInput = Console.ReadKey(); - switch (ReceivedKeyInput.Key) - { - case ConsoleKey.UpArrow: - SelectedOptionIndex--; - break; - case ConsoleKey.DownArrow: - SelectedOptionIndex++; - break; - case ConsoleKey.Enter: - Options[SelectedOptionIndex].OnPress.Invoke(); - break; - } - - Console.SetCursorPosition(left, top); - SelectedOptionIndex = Math.Clamp(SelectedOptionIndex, 0, Options.Length); -} \ No newline at end of file diff --git a/Partypacker/Proxy/PrivateKeyDeleters.cs b/Partypacker/Proxy/PrivateKeyDeleters.cs index 7aa39f3..3c1bf04 100644 --- a/Partypacker/Proxy/PrivateKeyDeleters.cs +++ b/Partypacker/Proxy/PrivateKeyDeleters.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; -namespace Partypacker.Proxy +namespace Partypacker.Net { internal class PrivateKeyDeleters { diff --git a/Partypacker/Proxy/Proxy.cs b/Partypacker/Proxy/Proxy.cs index 75b51f3..6840654 100644 --- a/Partypacker/Proxy/Proxy.cs +++ b/Partypacker/Proxy/Proxy.cs @@ -8,9 +8,11 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using static Fiddler.FiddlerApplication; -using static Partypacker.Core.Win32; +using static Partypacker.Win32; +using Pastel; +using System.Drawing; -namespace Partypacker.Proxy +namespace Partypacker.Net { internal class Proxy { @@ -18,23 +20,14 @@ namespace Partypacker.Proxy // https://github.com/PsychoPast/LawinServer/blob/master/LawinServer/Proxy/Proxy.cs // without it, fiddler-less proxying would have never been achieved - #region VARIABLES private const string Proxy_Server = "ProxyServer"; - private const string Proxy_Enable = "ProxyEnable"; - private readonly AppRegistry appRegistry; - private readonly string proxyKey = @$"{Registry.CurrentUser}\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"; - private readonly FiddlerCoreStartupSettings startupSettings; - private (object _currentProxyServer, int _defaultUserProxyState) proxySettings; - private (string _fiddlerCert, string _privateKey) _fiddlerCertInfos; - private int count = 0; - #endregion public Proxy() : this(9999) { } //default port @@ -123,9 +116,8 @@ namespace Partypacker.Proxy { appRegistry.Dispose(); BeforeRequest += OnBeforeRequest; - AfterSessionComplete += OnAfterSessionComplete; Startup(startupSettings); - Console.WriteLine($"Proxy started listening on port {startupSettings.ListenPort}."); + Console.WriteLine($"Proxy started listening on port {startupSettings.ListenPort.ToString().Pastel(Color.LimeGreen)}."); } public bool StopProxy() @@ -137,38 +129,33 @@ namespace Partypacker.Proxy #region EVENT_HANDLERS private void OnBeforeRequest(Session oSession) { - if (oSession.hostname.Contains(".ol.epicgames.com")) + if (oSession.PathAndQuery.Contains("/content/api/pages/fortnite-game/spark-tracks") + || oSession.HostnameIs("cdn.qstv.on.epicgames.com") + || oSession.PathAndQuery.Contains("/master.blurl") + || oSession.PathAndQuery.Contains("/main.blurl") + ) { if (oSession.HTTPMethodIs("CONNECT")) { oSession["x-replywithtunnel"] = "FortniteTunnel"; return; } - oSession.fullUrl = "https://lawinserverfinal.herokuapp.com" + oSession.PathAndQuery; + string BaseURL = // thats gonna be taken on most machines but sure +#if DEBUG + "http://localhost:80"; +#else + "https://api.partypack.mcthe.dev"; +#endif + + if (oSession.PathAndQuery.Contains("/master.blurl") + || oSession.PathAndQuery.Contains("/main.blurl")) + oSession.fullUrl = BaseURL + oSession.PathAndQuery; + else + oSession.fullUrl = BaseURL + oSession.PathAndQuery; } } - - private void OnAfterSessionComplete(Session oSession) - { - if (oSession.hostname != "lawinserverfinal.herokuapp.com") - { - return; - } - if (oSession.responseCode >= 400) - { - string fullUrl = oSession.fullUrl; - string requestHeaders = oSession.oRequest.headers.ToString(); - int responseCode = oSession.responseCode; - - /*LogError($"[Endpoint] {fullUrl}\n" + - $"[ResponseCode] {responseCode}\n" + - $"[RequestHeader] {requestHeaders}\n\n" - );*/ - } - Console.Title = $"LawinServer - Redirected {++count} endpoints"; - } - #endregion +#endregion #region CLEANUP private bool ResetProxySettings() diff --git a/Partypacker/icon.ico b/Partypacker/icon.ico new file mode 100644 index 0000000..1d1c49c Binary files /dev/null and b/Partypacker/icon.ico differ