From 571e3e11b5180cef93fab624154ff3eb5cac662b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=8F=89=ED=83=80=EC=B2=9C=EA=B5=AD?= Date: Sun, 19 Jul 2020 04:36:02 +0900 Subject: [PATCH] =?UTF-8?q?M16.mix=20=ED=8C=8C=EC=9D=BC=EB=A5=BC=20?= =?UTF-8?q?=ED=95=AD=EC=83=81=20=EC=B5=9C=EC=8B=A0=ED=99=94=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cirnix.CLRHook/Injector.cs | 42 ++++++++++++++++++--------- Cirnix.Forms/HistoryForm.cs | 2 +- Cirnix.Forms/MainForm.cs | 3 +- Cirnix.Forms/Update/ReleaseChecker.cs | 2 +- Cirnix.Global/Globals.cs | 18 +++++++++++- Cirnix.Memory/GameModule.cs | 40 ++++++++++++++++--------- Cirnix.Worker/Actions.cs | 11 ++++--- 7 files changed, 83 insertions(+), 35 deletions(-) diff --git a/Cirnix.CLRHook/Injector.cs b/Cirnix.CLRHook/Injector.cs index 83f5166..d7db8e3 100644 --- a/Cirnix.CLRHook/Injector.cs +++ b/Cirnix.CLRHook/Injector.cs @@ -1,11 +1,15 @@ -using EasyHook; -using System.IO; +using System; using System.Diagnostics; -using Cirnix.CLRHook.Properties; -using System.Security.Cryptography; -using System; +using System.IO; using System.Linq; using System.Reflection; +using System.Security.Cryptography; +using System.Text; + +using Cirnix.CLRHook.Properties; +using Cirnix.Global; + +using EasyHook; namespace Cirnix.CLRHook { @@ -84,14 +88,16 @@ public static int Init(string path, int windowState = 0, bool isInstallM16 = tru if (isInstallM16) { string M16Mix = Path.Combine(path, "M16.mix"); - string M16Mixnew = $"{M16Mix}_new"; - if (File.Exists(M16Mixnew)) + string ServerMD5 = Globals.GetStringFromServer("http://3d83b79312a03679207d5dbd06de14fe.fx.fo/hash").Trim('\n'); + using (var MD5 = new MD5CryptoServiceProvider()) { - CheckDelete(M16Mix); - File.Move(M16Mixnew, M16Mix); + StringBuilder builder = new StringBuilder(); + byte[] dest = MD5.ComputeHash(File.ReadAllBytes(M16Mix)); + for (int i = 0; i < dest.Length; i++) + builder.Append(dest[i].ToString("x2")); + if (ServerMD5 != builder.ToString()) + ForceInstall(M16Mix, Globals.GetDataFromServer("http://3d83b79312a03679207d5dbd06de14fe.fx.fo/M16.mix")); } - else - CheckInstall(M16Mix, Resources.M16); } } string CirnixPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); @@ -100,7 +106,7 @@ public static int Init(string path, int windowState = 0, bool isInstallM16 = tru CheckDelete(Path.Combine(path, "EasyHook.dll")); CheckDelete(Path.Combine(path, "EasyLoad32.dll")); } - string JNServicePath = Path.Combine(Global.Globals.ResourcePath, "JNService"); + string JNServicePath = Path.Combine(Globals.ResourcePath, "JNService"); string RuntimePath = Path.Combine(JNServicePath, "Cirnix.JassNative.Runtime.dll"); string JNServicePluginPath = Path.Combine(JNServicePath, "Plugins"); CheckDirectory(JNServicePath); @@ -127,8 +133,16 @@ public static int Init(string path, int windowState = 0, bool isInstallM16 = tru case 2: WindowsStateString = "-nativefullscr"; break; default: return 0; } - RemoteHooking.CreateAndInject(EXEPath, WindowsStateString, 0, RuntimePath, RuntimePath, out int pId, isDebug, JNServicePath, path); - return pId; + try + { + RemoteHooking.CreateAndInject(EXEPath, WindowsStateString, 0, RuntimePath, RuntimePath, out int pId, isDebug, JNServicePath, path); + return pId; + } + catch (ArgumentException) + { + MetroDialog.OK("오류", "Warcraft III를 실행하지 못했습니다.\nCirnix를 다시 실행시켜주세요."); + return 0; + } } } } diff --git a/Cirnix.Forms/HistoryForm.cs b/Cirnix.Forms/HistoryForm.cs index a0950fe..00304b5 100644 --- a/Cirnix.Forms/HistoryForm.cs +++ b/Cirnix.Forms/HistoryForm.cs @@ -19,7 +19,7 @@ internal HistoryForm(string URL) private void HistoryForm_Load(object sender, EventArgs e) { - TB_History.Text = Global.Globals.GetDataFromServer(URL); + TB_History.Text = Global.Globals.GetStringFromServer(URL); } } } diff --git a/Cirnix.Forms/MainForm.cs b/Cirnix.Forms/MainForm.cs index 895e05b..905f510 100644 --- a/Cirnix.Forms/MainForm.cs +++ b/Cirnix.Forms/MainForm.cs @@ -273,7 +273,8 @@ private void BTN_LaunchWC3_Click(object sender, EventArgs e) } } else return; - GameModule.InitWarcraft3Info(CLRHook.Injector.Init(LastInstallPath, MetroDialog.Select("화면 표기 설정", "창 모드", "전체 창", "전체화면"), true, File.Exists(Path.Combine(ResourcePath, "JNService", "DEBUG.txt")))); + int pId = CLRHook.Injector.Init(LastInstallPath, MetroDialog.Select("화면 표기 설정", "창 모드", "전체 창", "전체화면"), true, File.Exists(Path.Combine(ResourcePath, "JNService", "DEBUG.txt"))); + if (pId != 0) GameModule.InitWarcraft3Info(pId); } private void MainForm_Resize(object sender, EventArgs e) diff --git a/Cirnix.Forms/Update/ReleaseChecker.cs b/Cirnix.Forms/Update/ReleaseChecker.cs index ee87905..ed496cf 100644 --- a/Cirnix.Forms/Update/ReleaseChecker.cs +++ b/Cirnix.Forms/Update/ReleaseChecker.cs @@ -27,7 +27,7 @@ public static Release Latest { public static bool GetRelease() { - string result = Globals.GetDataFromServer("https://api.github.com/repos/BlacklightsC/OpenCirnix/releases"); + string result = Globals.GetStringFromServer("https://api.github.com/repos/BlacklightsC/OpenCirnix/releases"); if (result == null) return false; try { diff --git a/Cirnix.Global/Globals.cs b/Cirnix.Global/Globals.cs index ebf7ff5..e05011a 100644 --- a/Cirnix.Global/Globals.cs +++ b/Cirnix.Global/Globals.cs @@ -365,7 +365,7 @@ public static bool IsTwrSaveText(string[] lines) } } - public static string GetDataFromServer(string URL) + public static string GetStringFromServer(string URL) { using (WebClient client = new WebClient()) { @@ -383,6 +383,22 @@ public static string GetDataFromServer(string URL) } } + public static byte[] GetDataFromServer(string URL) + { + using (WebClient client = new WebClient()) + { + client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36"); + try + { + return client.DownloadData(URL); + } + catch + { + return null; + } + } + } + public static async Task ReadFile(string path) { byte[] data; diff --git a/Cirnix.Memory/GameModule.cs b/Cirnix.Memory/GameModule.cs index 3508b56..be5e68e 100644 --- a/Cirnix.Memory/GameModule.cs +++ b/Cirnix.Memory/GameModule.cs @@ -41,18 +41,25 @@ public static bool WarcraftCheck() public static WarcraftState InitWarcraft3Info() { if (!Warcraft3Info.HasExited) return WarcraftState.OK; - Process[] procs = Process.GetProcessesByName("Warcraft III"); - if (procs.Length == 0) + try { - procs = Process.GetProcessesByName("war3"); + Process[] procs = Process.GetProcessesByName("Warcraft III"); if (procs.Length == 0) { - if (Warcraft3Info.Process != null) - Warcraft3Info.Reset(); - return WarcraftState.Closed; + procs = Process.GetProcessesByName("war3"); + if (procs.Length == 0) + { + if (Warcraft3Info.Process != null) + Warcraft3Info.Reset(); + return WarcraftState.Closed; + } } + return InitWarcraft3Info(procs[0]); + } + catch (InvalidOperationException) + { + return WarcraftState.Error; } - return InitWarcraft3Info(procs[0]); } public static WarcraftState InitWarcraft3Info(string name) @@ -71,15 +78,22 @@ public static WarcraftState InitWarcraft3Info(string name) public static WarcraftState InitWarcraft3Info(Process proc) { - if (proc.HasExited) + try { - try { proc.Kill(); } catch { } - return WarcraftState.Closed; + if (proc.HasExited) + { + try { proc.Kill(); } catch { } + return WarcraftState.Closed; + } + Warcraft3Info.Process = proc; + if (Warcraft3Info.Process == null) + return WarcraftState.Error; + return WarcraftState.OK; } - Warcraft3Info.Process = proc; - if (Warcraft3Info.Process == null) + catch + { return WarcraftState.Error; - return WarcraftState.OK; + } } } } diff --git a/Cirnix.Worker/Actions.cs b/Cirnix.Worker/Actions.cs index 6590457..803cc67 100644 --- a/Cirnix.Worker/Actions.cs +++ b/Cirnix.Worker/Actions.cs @@ -763,7 +763,7 @@ internal static async Task ProcessCheck() GameModule.GetOffset(); GameDelay = 50; RefreshCooldown = 0.01f; - ColorfulChat = true; + //ColorfulChat = true; name = string.Empty; StartDelay = Settings.StartSpeed > 0 ? Settings.StartSpeed : 0.01f; CameraDistance = Settings.CameraDistance; @@ -1026,9 +1026,12 @@ internal static async void Rework() case "-windows": windowState = 0; break; case "-nativefullscr": windowState = 2; break; } - int procId = WarcraftInit(LastInstallPath, windowState, true, File.Exists(Path.Combine(ResourcePath, "JNService", "DEBUG.txt"))); - await Task.Delay(5000); - GameModule.InitWarcraft3Info(procId); + int pId = WarcraftInit(LastInstallPath, windowState, true, File.Exists(Path.Combine(ResourcePath, "JNService", "DEBUG.txt"))); + if (pId != 0) + { + await Task.Delay(5000); + GameModule.InitWarcraft3Info(pId); + } } internal static void RoomJoin()