diff --git a/WFInfo/CustomEntrypoint.cs b/WFInfo/CustomEntrypoint.cs index 0ca0104e..802f7b9c 100644 --- a/WFInfo/CustomEntrypoint.cs +++ b/WFInfo/CustomEntrypoint.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net; using System.Reflection; +using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; @@ -68,8 +69,7 @@ public static void Main() Directory.CreateDirectory(app_data_tesseract_catalog + @"\x64"); Directory.CreateDirectory(appdata_tessdata_folder); - - AvxSupport = HasAvxSupport(); + AvxSupport = isAVX2Available(); if (!AvxSupport) { @@ -134,23 +134,36 @@ public static void Main() } } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool isAVX2supported(); - // Detect if CPU has necessary optimizations - public static bool HasAvxSupport() + public static bool isAVX2Available() { - if (File.Exists(appPath + @"/old_as_fuck.boys")) - { - Console.WriteLine("Yup, she old"); - return false; - } - try - { - return (GetEnabledXStateFeatures() & 4) != 0; - } - catch + string dll = "CustomCPUID.dll"; + string path = app_data_tesseract_catalog + @"\" + dll; + string md5 = "23b463f8811480e508f10ce5e984bf2f"; + if (!File.Exists(path) || GetMD5hash(path) != md5) { - return false; + WebClient webClient = new WebClient(); + webClient.DownloadFile(tesseract_hotlink_prefix + "/" + dll, path); } + IntPtr pDll = NativeMethods.LoadLibrary(path); + IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "isAVX2supported"); + isAVX2supported isAvx2Supported = (isAVX2supported)Marshal.GetDelegateForFunctionPointer( + pAddressOfFunctionToCall, + typeof(isAVX2supported)); + return isAvx2Supported(); + } + static class NativeMethods + { + [DllImport("kernel32.dll")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll")] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32.dll")] + public static extern bool FreeLibrary(IntPtr hModule); } public static string GetMD5hash(string filePath) diff --git a/WFInfo/lib/CustomCPUID.dll b/WFInfo/lib/CustomCPUID.dll new file mode 100644 index 00000000..7c87c904 Binary files /dev/null and b/WFInfo/lib/CustomCPUID.dll differ