diff --git a/Extra/Discord.cs b/Extra/Discord.cs new file mode 100644 index 0000000..d96df20 --- /dev/null +++ b/Extra/Discord.cs @@ -0,0 +1,82 @@ +using DiscordRPC; +using DiscordRPC.Logging; +using Button = DiscordRPC.Button; + +namespace YuukiPS_Launcher.Extra +{ + public class Discord + { + public DiscordRpcClient client; + + public void Ready(string appid = "1023479009335582830") + { + if (client == null) + { + client = new DiscordRpcClient(appid); + client.Logger = new ConsoleLogger() { Level = LogLevel.Warning }; + client.RegisterUriScheme(); + + //Subscribe to events + client.OnReady += (sender, e) => + { + Console.WriteLine("Received Ready from user {0}", e.User.Username); + UpdateStatus("Getting ready", "Wait"); + }; + client.OnPresenceUpdate += (sender, e) => + { + Console.WriteLine("Received Update! {0}", e.Presence); + }; + + //Connect to the RPC + client.Initialize(); + } + + } + + public void UpdateStatus(string details, string state, string iconkey = "") + { + if (client != null) + { + var Editor = new RichPresence() + { + Details = details, + State = state + }; + if (!string.IsNullOrEmpty(iconkey)) + { + Editor.Assets = new Assets() + { + LargeImageKey = iconkey, + LargeImageText = state + }; + } + else + { + Editor.Assets = new Assets() + { + LargeImageKey = "yuuki", + LargeImageText = "YuukiPS" + }; + } + if (state.Contains("In Game")) + { + Editor.Buttons = new Button[] + { + new Button() { Label = "Join", Url = "https://ps.yuuki.me/" } + }; + } + client.SetPresence(Editor); + } + + } + + public void Stop() + { + if (client != null) + { + client.Dispose(); + client = null; + } + } + } +} diff --git a/Main.cs b/Main.cs index 2643486..20e1813 100644 --- a/Main.cs +++ b/Main.cs @@ -9,40 +9,32 @@ namespace YuukiPS_Launcher { public partial class Main : Form { + + // Main Function private ProxyController? proxy; private Process? progress; + // Server List Thread thServerList; List ListServer; - // https://nightly.link/akbaryahya/YuukiPS-Launcher/actions/runs/2947968074/YuukiPS.zip - // https://api.github.com/repos/akbaryahya/YuukiPS-Launcher/actions/artifacts - + // Folder public static string CurrentlyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""); private static string DataConfig = Path.Combine(CurrentlyPath, "data"); private static string Modfolder = Path.Combine(CurrentlyPath, "mod"); - // TODO: hapus nanti ini - - - // TODO: hapus nanti ini - //string PathfileGame = ""; - //string PathMetadata = ""; - //string PathUA = ""; - - //string DL_Patch = ""; - + // Config default string VersionGame = ""; string WatchFile = ""; bool IsGameRun = false; bool DoneCheck = true; - bool ShouldIcheck = false; - - int GameMode = 0; // 0 - tanpa patch, 1 - patch int GameChannel = 0; int GameMetode = 1; + // Extra + Extra.Discord discord = new Extra.Discord(); + public Main() { InitializeComponent(); @@ -53,19 +45,25 @@ private void Main_Load(object sender, EventArgs e) { Console.WriteLine("Loading...."); - // Create missing Files + // Create missing folder Directory.CreateDirectory(DataConfig); Directory.CreateDirectory(Modfolder); // Before starting make sure proxy is turned off CheckProxy(true); + // Check Update CheckUpdate(); + + // Check Game Version CheckVersionGame(); // Server List GetServerList(); UpdateServerListTimer(); + + // Extra + discord.Ready(); } public bool CheckVersionGame() @@ -201,6 +199,7 @@ public bool CheckVersionGame() Console.WriteLine("File Game: " + PathfileGame); Console.WriteLine("MD5 Game Currently: " + Game_LOC_Original_MD5); + return true; } @@ -932,29 +931,24 @@ public void CheckUpdate() private static string GetLauncherPath(String version = "Genshin Impact") { RegistryKey key = Registry.LocalMachine; - - if (key == null) + if (key != null) { - return ""; - } - - var tes1 = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + version); // 原神 - if (tes1 != null) - { - var testes1 = tes1.GetValue("InstallPath"); - if (testes1 != null) + var tes1 = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + version); + if (tes1 != null) { - var testestestes1 = testes1.ToString(); - if (testestestes1 != null) + var testes1 = tes1.GetValue("InstallPath"); + if (testes1 != null) { - return testestestes1; - } + var testestestes1 = testes1.ToString(); + if (testestestes1 != null) + { + return testestestes1; + } + } } } - return ""; - } // Check Game Install @@ -1267,6 +1261,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e) Console.WriteLine(tes); } DoneCheck = true; + discord.UpdateStatus("Not playing", "Stop", "sleep"); } } else @@ -1275,7 +1270,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e) IsGameRun = true; btStart.Text = "Stop"; DoneCheck = false; - ShouldIcheck = true; + discord.UpdateStatus("Currently in Server " + GetHost.Text, "In Game", "on"); } } @@ -1461,7 +1456,6 @@ private void CheckProxyRun_Tick(object sender, EventArgs e) [Obsolete] void CheckProxy(bool force_off = false) { - // Before starting make sure proxy is turned off try { // Metode 1 diff --git a/YuukiPS Launcher.csproj b/YuukiPS Launcher.csproj index e86d0cd..ef8bd39 100644 --- a/YuukiPS Launcher.csproj +++ b/YuukiPS Launcher.csproj @@ -12,8 +12,8 @@ Properties\app.manifest - 2022.9.21.2303 - 2022.9.21.2303 + 2022.9.25.0720 + 2022.9.25.0720 true YuukiPS @@ -45,6 +45,7 @@ +