Skip to content

Commit

Permalink
M16.mix 파일를 항상 최신화하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BlacklightsC committed Jul 18, 2020
1 parent 1e966d4 commit 571e3e1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 35 deletions.
42 changes: 28 additions & 14 deletions Cirnix.CLRHook/Injector.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion Cirnix.Forms/HistoryForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 2 additions & 1 deletion Cirnix.Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Cirnix.Forms/Update/ReleaseChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 17 additions & 1 deletion Cirnix.Global/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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<byte[]> ReadFile(string path)
{
byte[] data;
Expand Down
40 changes: 27 additions & 13 deletions Cirnix.Memory/GameModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
}
}
}
11 changes: 7 additions & 4 deletions Cirnix.Worker/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ internal static async Task<bool> 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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 571e3e1

Please sign in to comment.