Skip to content

Commit 9d93f30

Browse files
committed
Merge pull request #1 from thelink2012/develop
v1.1.0
2 parents dc0015b + fad759c commit 9d93f30

File tree

12 files changed

+257
-58
lines changed

12 files changed

+257
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/cmalcor-gui/obj/
44
/cmalcor/bin/
55
/cmalcor/obj/
6+
/cmalcor/build_temp/
67

78
#################
89
## C++

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Fortunately, it's not a device limitation: After reversing into the firmware, be
44

55
I hope this is useful for the Alcor owners. I specially went after this because the brightness of any of the predefined colors except the red wasn't really confortable for my eyes.
66

7+
*This also works on the Mizar with the mizar_patch!*
8+
79
## Installation
810

911
### Option 1: Binary

build-win32.bat

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
@echo off
66

77
cd cmalcor
8-
premake5 vs2015 && msbuild CmAlcor.sln /p:configuration=Release /p:platform=Win32
8+
mkdir build_temp
9+
mkdir build_temp\alcor
10+
mkdir build_temp\mizar
11+
premake5 vs2015 --outdir=build_temp/alcor && cd build_temp/alcor && msbuild CmAlcor.sln /p:configuration=Release /p:platform=Win32 && cd ../..
12+
if %errorlevel% neq 0 exit /b %errorlevel%
13+
premake5 vs2015 --outdir=build_temp/mizar --mizar && cd build_temp/mizar && msbuild CmAlcor.sln /p:configuration=Release /p:platform=Win32 && cd ../..
914
if %errorlevel% neq 0 exit /b %errorlevel%
1015
cd ..
1116

@@ -15,9 +20,12 @@ if %errorlevel% neq 0 exit /b %errorlevel%
1520
cd ..
1621

1722
mkdir bin
23+
mkdir bin\mizar_patch
1824

19-
copy /y /d "cmalcor\bin\cmalcor.exe" "bin\"
20-
copy /y /d "cmalcor\bin\cmalcor.dll" "bin\"
25+
copy /y /d "cmalcor\build_temp\alcor\bin\cmalcor.exe" "bin\"
26+
copy /y /d "cmalcor\build_temp\alcor\bin\cmalcor.dll" "bin\"
27+
copy /y /d "cmalcor\build_temp\mizar\bin\cmalcor.exe" "bin\mizar_patch\"
28+
copy /y /d "cmalcor\build_temp\mizar\bin\cmalcor.dll" "bin\mizar_patch\"
2129
ilmerge /targetplatform:v4 /out:bin/CmAlcorGUI.exe "cmalcor-gui/bin/Release/CmAlcorGUI.exe" "cmalcor-gui/bin/Release/Cyotek.Windows.Forms.ColorPicker.dll"
2230
copy /y /d "cmalcor-gui\bin\Release\DarkUI.dll" "bin\"
2331
copy /y /d "cmalcor-gui\bin\Release\CmAlcorGUI.exe.config" "bin\"
@@ -27,6 +35,15 @@ echo Better viewed on GitHub: https://github.com/thelink2012/cmalcor/blob/master
2735
echo. >> bin/readme.txt
2836
type README.md >> bin/readme.txt
2937

38+
echo Those files allows the application to work with the CM Storm Mizar. >bin/mizar_patch/readme.txt
39+
echo. >>bin/mizar_patch/readme.txt
40+
echo Copy and replace the files in the directory CmAlcorGUI.exe is in. >>bin/mizar_patch/readme.txt
41+
echo. >>bin/mizar_patch/readme.txt
42+
echo I don't own a Mizar and did very small tests on someone that owns it, so I can't guarantee that this works great. >>bin/mizar_patch/readme.txt
43+
echo. >>bin/mizar_patch/readme.txt
44+
echo If it breaks something, see the 'Troubleshooting ^> CoolerMaster Warranty' section of the main readme as it explains how to erase the memory. >>bin/mizar_patch/readme.txt
45+
echo. >>bin/mizar_patch/readme.txt
46+
3047
echo =================== https://github.com/thelink2012/cmalcor =================== > bin/license.txt
3148
echo. >> bin/license.txt
3249
type LICENSE >> bin/license.txt

cmalcor-gui/Firmware.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Text;
34
using System.Threading.Tasks;
45

56
namespace CmAlcorGUI
67
{
78
public class FirmwareException : Exception
89
{
910
public FirmwareException(int error)
10-
: base(String.Format("Firmware call failed with error code: {0}.", error))
11+
: base(String.Format("{0}", Firmware.ErrorToString(error)))
1112
{
1213
}
1314
}
@@ -35,10 +36,41 @@ public static int LibraryVersion()
3536
return CmAlcor_LibraryVersion();
3637
}
3738

39+
/// <summary>
40+
/// Gets the compilation flags of the unmanaged library (cmalcor.dll).
41+
/// </summary>
42+
public static int LibraryFlags()
43+
{
44+
return CmAlcor_LibraryFlags();
45+
}
46+
47+
/// <summary>
48+
/// Gets the error message from a error id.
49+
/// </summary>
50+
/// <returns>Returns the error message string for error, or `error.ToString()` if anything wrong happens on the call.</returns>
51+
public static string ErrorToString(int error)
52+
{
53+
int capacity = 1024;
54+
var stringBuilder = new StringBuilder(capacity);
55+
if(CmAlcor_ErrorToString(error, stringBuilder, new UIntPtr((uint)capacity - 4)) != 0)
56+
{
57+
return stringBuilder.ToString();
58+
}
59+
return error.ToString();
60+
}
61+
62+
/// <summary>
63+
/// Whether the library was compiled for the CM Storm Mizar.
64+
/// </summary>
65+
public static bool IsLibraryForMizar()
66+
{
67+
return (LibraryFlags() & 0x4) != 0;
68+
}
69+
3870
/// <summary>
3971
/// Checks whether the mouse is connected on the computer.
4072
/// </summary>
41-
public static bool IsAlcorPresent()
73+
public static bool IsMousePresent()
4274
{
4375
return CmAlcor_IsMousePresent() != 0;
4476
}
@@ -134,6 +166,12 @@ public static void DisableCustomLED()
134166
[DllImport("cmalcor.dll", CallingConvention = CallingConvention.Cdecl)]
135167
private static extern int CmAlcor_LibraryVersion();
136168

169+
[DllImport("cmalcor.dll", CallingConvention = CallingConvention.Cdecl)]
170+
private static extern int CmAlcor_LibraryFlags();
171+
172+
[DllImport("cmalcor.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
173+
private static extern int CmAlcor_ErrorToString(int error, StringBuilder output, UIntPtr max_output);
174+
137175
[DllImport("cmalcor.dll", CallingConvention = CallingConvention.Cdecl)]
138176
private static extern int CmAlcor_IsMousePresent();
139177

@@ -155,6 +193,9 @@ public static void DisableCustomLED()
155193
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
156194
public delegate int Delegate_CmAlcor_LibraryVersion();
157195

196+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
197+
public delegate int Delegate_CmAlcor_LibraryFlags();
198+
158199
#endregion
159200
}
160201
}

cmalcor-gui/MainForm.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,16 @@ private void MainForm_Load(object sender, EventArgs e)
8686
Color.FromArgb(0xFF, 0xDA, 0xAA),
8787
});
8888

89-
this.startupHandlerBtn.Enabled = !HasStartupHandlerInstalled();
90-
89+
if(Firmware.IsLibraryForMizar())
90+
{
91+
this.startupHandlerBtn.Enabled = false;
92+
this.startupHandlerBtn.Visible = false;
93+
}
94+
else
95+
{
96+
this.startupHandlerBtn.Enabled = !HasStartupHandlerInstalled();
97+
}
98+
9199
UpdateUIFromMouseMemory();
92100
}
93101

@@ -210,10 +218,13 @@ private bool IsStartupLibraryOlderThanCurrent()
210218
if(libCmAlcor != IntPtr.Zero) // when doesn't exist or any other error
211219
{
212220
IntPtr ptrLibraryVersion = NativeMethods.GetProcAddress(libCmAlcor, "CmAlcor_LibraryVersion");
213-
if(ptrLibraryVersion != IntPtr.Zero)
221+
IntPtr ptrLibraryFlags = NativeMethods.GetProcAddress(libCmAlcor, "CmAlcor_LibraryFlags");
222+
if(ptrLibraryVersion != IntPtr.Zero && ptrLibraryFlags != IntPtr.Zero)
214223
{
215224
var programDataLibraryVersion = (Firmware.Delegate_CmAlcor_LibraryVersion) Marshal.GetDelegateForFunctionPointer(ptrLibraryVersion, typeof(Firmware.Delegate_CmAlcor_LibraryVersion));
216-
isOlder = (programDataLibraryVersion() < Firmware.LibraryVersion());
225+
var programDataLibraryFlags = (Firmware.Delegate_CmAlcor_LibraryFlags) Marshal.GetDelegateForFunctionPointer(ptrLibraryFlags, typeof(Firmware.Delegate_CmAlcor_LibraryFlags));
226+
isOlder = (programDataLibraryVersion() < Firmware.LibraryVersion())
227+
|| (programDataLibraryFlags() != Firmware.LibraryFlags());
217228
}
218229
NativeMethods.FreeLibrary(libCmAlcor);
219230
}

cmalcor-gui/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ static void Main()
1717
Application.EnableVisualStyles();
1818
Application.SetCompatibleTextRenderingDefault(false);
1919

20-
if(Firmware.IsAlcorPresent())
20+
if(Firmware.IsMousePresent())
2121
{
2222
Application.Run(new MainForm());
2323
}
2424
else
2525
{
26-
MessageBox.Show("The CM Storm Alcor mouse is not connected or couldn't be found.",
27-
"CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
26+
string message = String.Format("The CM Storm {0} mouse is not connected or couldn't be found.",
27+
Firmware.IsLibraryForMizar()? "Mizar" : "Alcor");
28+
MessageBox.Show(message, "CmAlcorGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
2829
}
2930
}
3031
}

cmalcor/include/cmalcor.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Uses C99/C++ comments, can't bother to replace them.
77

88
#if defined(CMALCOR_COMPILING) || defined(CMALCOR_COMPILING_CLI)
9-
#define CMALCOR_CAPI_VERSION 0x010001
10-
#define CMALCOR_CAPI_VERSION_STRING "1.0.1"
9+
#define CMALCOR_CAPI_VERSION 0x010100
10+
#define CMALCOR_CAPI_VERSION_STRING "1.1.0"
1111
#endif
1212

1313
/*
@@ -77,6 +77,13 @@ extern "C" {
7777
#define CMALCOR_ERROR_BADSETTING (-15)
7878

7979

80+
/*
81+
* Library Compilation Flags
82+
*/
83+
#define CMALCOR_LIBFLAGS_DEBUG (0x1)
84+
#define CMALCOR_LIBFLAGS_MIZARPATCH (0x4)
85+
86+
8087
/*
8188
* Functions
8289
*/
@@ -89,6 +96,14 @@ extern "C" {
8996
CMALCOR_API
9097
int CmAlcor_LibraryVersion();
9198

99+
///
100+
/// Gets the compilation flags of this library.
101+
///
102+
/// See `CMALCOR_LIBFLAGS_*`.
103+
///
104+
CMALCOR_API
105+
int CmAlcor_LibraryFlags();
106+
92107
///
93108
/// Transforms a CMALCOR_ERROR_* into a string.
94109
///

cmalcor/premake5.lua

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66
Options and Actions
77
--]]
88

9+
newoption {
10+
trigger = "outdir",
11+
value = "path",
12+
description = "Output directory for the build files"
13+
}
14+
if not _OPTIONS["outdir"] then
15+
_OPTIONS["outdir"] = "."
16+
end
17+
18+
newoption {
19+
trigger = "mizar",
20+
description = "Makes a project that builds the Mizar based library"
21+
}
22+
923
--[[
1024
The Solution
1125
--]]
1226
solution "CmAlcor"
1327

1428
configurations { "Release", "Debug" }
1529

30+
location( _OPTIONS["outdir"] )
1631
targetprefix "" -- no 'lib' prefix on gcc
17-
targetdir "bin"
18-
implibdir "bin"
32+
targetdir (_OPTIONS["outdir"] .. '/' .. "bin")
33+
implibdir (_OPTIONS["outdir"] .. '/' .. "bin")
1934

2035
startproject "cmalcor-cli"
2136

@@ -29,6 +44,10 @@ solution "CmAlcor"
2944
"_SCL_SECURE_NO_WARNINGS"
3045
}
3146

47+
if _OPTIONS["mizar"] then
48+
defines { "MIZAR_PATCH=1" }
49+
end
50+
3251
includedirs { "include" }
3352

3453
configuration "Debug*"

0 commit comments

Comments
 (0)