diff --git a/.gitignore b/.gitignore index 5115c12d8..98ca98966 100644 --- a/.gitignore +++ b/.gitignore @@ -189,3 +189,4 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt +*.opendb diff --git a/Artemis/Artemis.sln b/Artemis/Artemis.sln index cf6e97100..201149a73 100644 --- a/Artemis/Artemis.sln +++ b/Artemis/Artemis.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis", "Artemis\Artemis.csproj", "{ED9997A2-E54C-4E9F-9350-62BE672C3ABE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LogiLed2Artemis", "LogiLed2Artemis\LogiLed2Artemis.vcxproj", "{D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CD_ROM|Any CPU = CD_ROM|Any CPU @@ -54,6 +56,34 @@ Global {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x64.Build.0 = Release|x64 {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x86.ActiveCfg = Release|x86 {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x86.Build.0 = Release|x86 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|Any CPU.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|Any CPU.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|x64.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|x64.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|x86.ActiveCfg = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.CD_ROM|x86.Build.0 = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Debug|x64.ActiveCfg = Debug|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Debug|x64.Build.0 = Debug|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Debug|x86.ActiveCfg = Debug|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Debug|x86.Build.0 = Debug|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|Any CPU.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|Any CPU.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|x64.ActiveCfg = Debug|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|x64.Build.0 = Debug|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|x86.ActiveCfg = Debug|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.DVD-5|x86.Build.0 = Debug|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Release|Any CPU.ActiveCfg = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Release|x64.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Release|x64.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Release|x86.ActiveCfg = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.Release|x86.Build.0 = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|Any CPU.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|Any CPU.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|x64.ActiveCfg = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|x64.Build.0 = Release|x64 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|x86.ActiveCfg = Release|Win32 + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C}.SingleImage|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Artemis/Artemis/DAL/ProfileProvider.cs b/Artemis/Artemis/DAL/ProfileProvider.cs index a3d3aadd1..09a60f6e3 100644 --- a/Artemis/Artemis/DAL/ProfileProvider.cs +++ b/Artemis/Artemis/DAL/ProfileProvider.cs @@ -1,17 +1,24 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using Artemis.Models; +using Newtonsoft.Json; namespace Artemis.DAL { internal class ProfileProvider { + private List _profiles; + /// /// Get all profiles /// /// All profiles public List GetAll() { + ReadProfiles(); return new List(); } @@ -33,5 +40,34 @@ namespace Artemis.DAL public void AddOrUpdate(ProfileModel profile) { } + + private void ReadProfiles() + { + CheckProfiles(); + _profiles = new List(); + + // Create the directory structure + var profileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles"; + var profileFiles = Directory.GetFiles(profileFolder, "*.json", SearchOption.AllDirectories); + + // Parse the JSON files into objects and add them if they are valid + foreach (var file in profileFiles) + { + var prof = JsonConvert.DeserializeObject(File.ReadAllText(file)); + if (prof.GameName?.Length > 1 && prof.KeyboardName?.Length > 1 && prof.Name?.Length > 1) + _profiles.Add(prof); + } + } + + private void CheckProfiles() + { + // Create the directory structure + var profileFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles"; + if (Directory.Exists(profileFolder)) + return; + + Directory.CreateDirectory(profileFolder); + Debug.WriteLine("Place presets"); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs index eb7a76195..d6fa0155e 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs @@ -18,7 +18,7 @@ namespace Artemis.KeyboardProviders.Logitech Name = "Logitech G910 RGB"; CantEnableText = "Couldn't connect to your Logitech G910.\n" + "Please check your cables and updating the Logitech Gaming Software\n" + - $"A minimum version of 8.81.15 is required. (Detected {_versionString})\n\n" + + "A minimum version of 8.81.15 is required.\n\n" + "If needed, you can select a different keyboard in Artemis under settings."; Height = 6; Width = 21; @@ -42,7 +42,12 @@ namespace Artemis.KeyboardProviders.Logitech // Turn it into one long number... var version = int.Parse($"{majorNum}{minorNum}{buildNum}"); - _versionString = $"{majorNum}.{minorNum}.{buildNum}"; + CantEnableText = "Couldn't connect to your Logitech G910.\n" + + "Please check your cables and updating the Logitech Gaming Software\n" + + $"A minimum version of 8.81.15 is required (detected {majorNum}.{minorNum}.{buildNum}).\n\n" + + "If the detected version differs from the version LGS is reporting, reinstall LGS or see the FAQ.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + return version >= 88115; } diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs index 28caad6f6..b5b025e87 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs @@ -118,7 +118,7 @@ namespace Artemis.Modules.Games.TheDivision } // Parses Division key data to game data - private void InterpertrateDivisionKey(int[] parts) + private void InterpertrateDivisionKey(IReadOnlyList parts) { var keyCode = parts[1]; var rPer = parts[2]; diff --git a/Artemis/Artemis/Resources/LogitechLED.dll b/Artemis/Artemis/Resources/LogitechLED.dll index 2d722626e..044b0e799 100644 Binary files a/Artemis/Artemis/Resources/LogitechLED.dll and b/Artemis/Artemis/Resources/LogitechLED.dll differ diff --git a/Artemis/LogiLed2Artemis/Logger.cpp b/Artemis/LogiLed2Artemis/Logger.cpp new file mode 100644 index 000000000..d255c8713 --- /dev/null +++ b/Artemis/LogiLed2Artemis/Logger.cpp @@ -0,0 +1,104 @@ +// Original work by VRocker https://github.com/VRocker/LogiLed2Corsair +// I'm mainly a C# developer, and these modification aren't a piece of art, but it suits our needs. + +// The MIT License (MIT) +// +// Copyright (c) 2015 VRocker +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include "Logger.h" + +#include +#include +#include + + +// Ok this looks butt-ugleh but its just to force the default log level to debug if we compile in debug +#ifdef _DEBUG +LogLevel CLogger::m_eLogLevel = LogLevel::Debug; +#else +LogLevel CLogger::m_eLogLevel = LogLevel::All; +#endif +FILE* CLogger::m_pFile = 0; + +void CLogger::InitLogging(const char* szFile) +{ + if (!m_pFile) + { + m_pFile = fopen(szFile, "a+"); + if (!m_pFile) + { + // Hum, we couldn't open the file for writing + printf("ERROR: Unable to open log file %s.\n", szFile); + } + } +} + +void CLogger::EndLogging(void) +{ + if (m_pFile) + { + fclose(m_pFile); + m_pFile = 0; + } +} + +void CLogger::OutputLog_s(const char* sz, const LogLevel eLevel) +{ + // If the level of this log entry is less important than what we are told to log, just return + if (eLevel < m_eLogLevel) + return; + + // If we don't have a file to write to, bail. + if (!m_pFile) + return; + + char szOutput[512] = {0}; + + time_t rawtime; + struct tm* timeinfo; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + // Timestamp the log entry + size_t uiLen = sprintf(szOutput, "<%.2d/%.2d/%.2d - %.2d:%.2d:%.2d> %s\n", timeinfo->tm_mday, timeinfo->tm_mon + 1, timeinfo->tm_year + 1900, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, sz); + + // Write the text to the file + fwrite(szOutput, 1, uiLen, m_pFile); + // Flush the log file to the disk. May move this to a seperate function + fflush(m_pFile); + + // Output the text to any console that may be attached + printf("%s", szOutput); +} + +void CLogger::OutputLog(const char* sz, const LogLevel eLevel, ...) +{ + char szText[1024] = {0}; + va_list marker; + va_start(marker, eLevel); + vsprintf(szText, sz, marker); + va_end(marker); + + // Since this function is pretty much the same as the safer function, we'll just redirect it there + OutputLog_s(szText, eLevel); +} + diff --git a/Artemis/LogiLed2Artemis/Logger.h b/Artemis/LogiLed2Artemis/Logger.h new file mode 100644 index 000000000..41cab02d2 --- /dev/null +++ b/Artemis/LogiLed2Artemis/Logger.h @@ -0,0 +1,82 @@ +// Original work by VRocker https://github.com/VRocker/LogiLed2Corsair +// I'm mainly a C# developer, and these modification aren't a piece of art, but it suits our needs. + +// The MIT License (MIT) +// +// Copyright (c) 2015 VRocker +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once +#ifndef _LOGGER_H +#define _LOGGER_H + +#include + +enum class LogLevel +{ + Debug, + All, + Critical, + Warning, + Information, + User, + Internal, + None, + + // Just to force the compiler to treat the enum options as an int + FORCE_32BIT = 0x7fffffff +}; + +class CLogger +{ +public: + static LogLevel GetLogLevel(void) + { + return m_eLogLevel; + } + + static void SetLogLevel(const LogLevel e) + { +#ifndef _DEBUG + if ( e == LogLevel::Debug ) return; +#endif + m_eLogLevel = e; + } + + static void InitLogging(const char* szFile); + // Always remember to end logging when you are finished otherwise you will have file handles floating around + static void EndLogging(void); + + // Output the text to a log file. + static void OutputLog_s(const char* sz, const LogLevel eLevel); + static void OutputLog(const char* sz, const LogLevel eLevel, ...); + + static FILE* GetFile() + { + return m_pFile; + } + +private: + static LogLevel m_eLogLevel; + static FILE* m_pFile; +}; + +#endif + diff --git a/Artemis/LogiLed2Artemis/LogiLed2Artemis.def b/Artemis/LogiLed2Artemis/LogiLed2Artemis.def new file mode 100644 index 000000000..ef38be3f1 --- /dev/null +++ b/Artemis/LogiLed2Artemis/LogiLed2Artemis.def @@ -0,0 +1,49 @@ +// Original work by VRocker https://github.com/VRocker/LogiLed2Corsair +// I'm mainly a C# developer, and these modification aren't a piece of art, but it suits our needs. + +// The MIT License (MIT) +// +// Copyright (c) 2015 VRocker +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +LIBRARY LogiLed2Artemis.dll + +EXPORTS + + LogiLedInit + LogiLedGetSdkVersion + LogiLedSetTargetDevice + LogiLedSaveCurrentLighting + LogiLedSetLighting + LogiLedRestoreLighting + LogiLedFlashLighting + LogiLedPulseLighting + LogiLedStopEffects + LogiLedSetLightingFromBitmap + LogiLedSetLightingForKeyWithScanCode + LogiLedSetLightingForKeyWithHidCode + LogiLedSetLightingForKeyWithQuartzCode + LogiLedSetLightingForKeyWithKeyName + LogiLedSaveLightingForKey + LogiLedRestoreLightingForKey + LogiLedFlashSingleKey + LogiLedPulseSingleKey + LogiLedStopEffectsOnKey + LogiLedShutdown diff --git a/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj b/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj new file mode 100644 index 000000000..670478206 --- /dev/null +++ b/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj @@ -0,0 +1,168 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D2EDB8F3-F0CB-4670-B472-0B46D5800D2C} + Win32Proj + LogiLed2Artemis + LogiLed2Artemis + + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + $(LibraryPath) + + + false + + + false + $(ProjectName) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LOGILEDCORSAIR_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + LogiLed2Artemis.def + ../CUESDK/lib/i386/CUESDK_2013.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LOGILEDCORSAIR_EXPORTS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + Windows + true + LogiLed2Artemis.def + %(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;LOGILEDCORSAIR_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + LogiLed2Artemis.def + ../CUESDK/lib/i386/CUESDK_2013.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;LOGILEDCORSAIR_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + LogiLed2Artemis.def + %(AdditionalDependencies) + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj.filters b/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj.filters new file mode 100644 index 000000000..34a553926 --- /dev/null +++ b/Artemis/LogiLed2Artemis/LogiLed2Artemis.vcxproj.filters @@ -0,0 +1,41 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/Artemis/LogiLed2Artemis/LogiLedDefs.h b/Artemis/LogiLed2Artemis/LogiLedDefs.h new file mode 100644 index 000000000..e1d2a4f24 --- /dev/null +++ b/Artemis/LogiLed2Artemis/LogiLedDefs.h @@ -0,0 +1,135 @@ +#pragma once + +const int LOGITECH_LED_MOUSE = 0x0001; +const int LOGITECH_LED_KEYBOARD = 0x0002; +const int LOGITECH_LED_ALL = LOGITECH_LED_MOUSE | LOGITECH_LED_KEYBOARD; + +#define LOGI_LED_BITMAP_WIDTH 21 +#define LOGI_LED_BITMAP_HEIGHT 6 +#define LOGI_LED_BITMAP_BYTES_PER_KEY 4 + +#define LOGI_LED_BITMAP_SIZE LOGI_LED_BITMAP_WIDTH*LOGI_LED_BITMAP_HEIGHT*LOGI_LED_BITMAP_BYTES_PER_KEY + +#define LOGI_LED_DURATION_INFINITE 0 + +#define LOGI_DEVICETYPE_MONOCHROME_ORD 0 +#define LOGI_DEVICETYPE_RGB_ORD 1 +#define LOGI_DEVICETYPE_PERKEY_RGB_ORD 2 + +#define LOGI_DEVICETYPE_MONOCHROME (1 << LOGI_DEVICETYPE_MONOCHROME_ORD) +#define LOGI_DEVICETYPE_RGB (1 << LOGI_DEVICETYPE_RGB_ORD) +#define LOGI_DEVICETYPE_PERKEY_RGB (1 << LOGI_DEVICETYPE_PERKEY_RGB_ORD) + +#define LOGI_DEVICETYPE_ALL (LOGI_DEVICETYPE_MONOCHROME | LOGI_DEVICETYPE_RGB | LOGI_DEVICETYPE_PERKEY_RGB) + +namespace LogiLed +{ + typedef enum + { + ESC = 0x01, + F1 = 0x3b, + F2 = 0x3c, + F3 = 0x3d, + F4 = 0x3e, + F5 = 0x3f, + F6 = 0x40, + F7 = 0x41, + F8 = 0x42, + F9 = 0x43, + F10 = 0x44, + F11 = 0x57, + F12 = 0x58, + PRINT_SCREEN = 0x137, + SCROLL_LOCK = 0x46, + PAUSE_BREAK = 0x145, + TILDE = 0x29, + ONE = 0x02, + TWO = 0x03, + THREE = 0x04, + FOUR = 0x05, + FIVE = 0x06, + SIX = 0x07, + SEVEN = 0x08, + EIGHT = 0x09, + NINE = 0x0A, + ZERO = 0x0B, + MINUS = 0x0C, + EQUALS = 0x0D, + BACKSPACE = 0x0E, + INSERT = 0x152, + HOME = 0x147, + PAGE_UP = 0x149, + NUM_LOCK = 0x45, + NUM_SLASH = 0x135, + NUM_ASTERISK = 0x37, + NUM_MINUS = 0x4A, + TAB = 0x0F, + Q = 0x10, + W = 0x11, + E = 0x12, + R = 0x13, + T = 0x14, + Y = 0x15, + U = 0x16, + I = 0x17, + O = 0x18, + P = 0x19, + OPEN_BRACKET = 0x1A, + CLOSE_BRACKET = 0x1B, + BACKSLASH = 0x2B, + KEYBOARD_DELETE = 0x153, + END = 0x14F, + PAGE_DOWN = 0x151, + NUM_SEVEN = 0x47, + NUM_EIGHT = 0x48, + NUM_NINE = 0x49, + NUM_PLUS = 0x4E, + CAPS_LOCK = 0x3A, + A = 0x1E, + S = 0x1F, + D = 0x20, + F = 0x21, + G = 0x22, + H = 0x23, + J = 0x24, + K = 0x25, + L = 0x26, + SEMICOLON = 0x27, + APOSTROPHE = 0x28, + ENTER = 0x1C, + NUM_FOUR = 0x4B, + NUM_FIVE = 0x4C, + NUM_SIX = 0x4D, + LEFT_SHIFT = 0x2A, + Z = 0x2C, + X = 0x2D, + C = 0x2E, + V = 0x2F, + B = 0x30, + N = 0x31, + M = 0x32, + COMMA = 0x33, + PERIOD = 0x34, + FORWARD_SLASH = 0x35, + RIGHT_SHIFT = 0x36, + ARROW_UP = 0x148, + NUM_ONE = 0x4F, + NUM_TWO = 0x50, + NUM_THREE = 0x51, + NUM_ENTER = 0x11C, + LEFT_CONTROL = 0x1D, + LEFT_WINDOWS = 0x15B, + LEFT_ALT = 0x38, + SPACE = 0x39, + RIGHT_ALT = 0x138, + RIGHT_WINDOWS = 0x15C, + APPLICATION_SELECT = 0x15D, + RIGHT_CONTROL = 0x11D, + ARROW_LEFT = 0x14B, + ARROW_DOWN = 0x150, + ARROW_RIGHT = 0x14D, + NUM_ZERO = 0x52, + NUM_PERIOD = 0x53, + } KeyName; +} + diff --git a/Artemis/LogiLed2Artemis/main.cpp b/Artemis/LogiLed2Artemis/main.cpp new file mode 100644 index 000000000..c224e7daf --- /dev/null +++ b/Artemis/LogiLed2Artemis/main.cpp @@ -0,0 +1,254 @@ +// Original work by VRocker https://github.com/VRocker/LogiLed2Corsair +// I'm mainly a C# developer, and these modification aren't a piece of art, but it suits our needs. + +// The MIT License (MIT) +// +// Copyright (c) 2015 VRocker +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include "main.h" +#include +#include +#include +#include "LogiLedDefs.h" +#define WIN32_LEAN_AND_MEAN +#include +#include "Logger.h" + +#include +#include + + +static bool g_hasInitialised = false; +const char* game = ""; + +void cleanup() +{ + CLogger::EndLogging(); +} + +BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + { + atexit(cleanup); + + CLogger::InitLogging("Log.txt"); + CLogger::SetLogLevel(LogLevel::None); + + // Get the process that loaded the DLL + TCHAR divisionFind[] = _T("Division"); + TCHAR gtaFind[] = _T("GTA"); + TCHAR szPath[MAX_PATH]; + GetModuleFileName(NULL, szPath, MAX_PATH); + + if (_tcscmp(szPath, divisionFind) != 0) + game = "division"; + else if (_tcscmp(szPath, gtaFind) != 0) + game = "gta"; + + CLogger::OutputLog("Attached to process.", LogLevel::Debug); + } + break; + + case DLL_PROCESS_DETACH: + { + cleanup(); + + CLogger::OutputLog_s("Detached from process.", LogLevel::Debug); + } + break; + } + + return true; +} + +bool LogiLedInit() +{ + CLogger::OutputLog_s("Logitech LED init called.", LogLevel::Debug); + g_hasInitialised = true; + return true; +} + +bool LogiLedGetSdkVersion(int* majorNum, int* minorNum, int* buildNum) +{ + CLogger::OutputLog("LogiLedGetSdkVersion called.", LogLevel::Debug); + + // Mimic the SDK version + *majorNum = 8; + *minorNum = 81; + *buildNum = 15; + + return true; +} + +bool LogiLedSetTargetDevice(int targetDevice) +{ + CLogger::OutputLog("LogiLedSetTargetDevice called (%i)", LogLevel::Debug, targetDevice); + + // Logitech SDK says this function returns false if LogiLedInit hasn't been called + return g_hasInitialised; +} + +bool LogiLedSaveCurrentLighting() +{ + CLogger::OutputLog("LogiLedSaveCurrentLighting called (%i)", LogLevel::Debug); + return true; +} + +void Transmit(const char* msg) +{ + //Pipe Init Data + HANDLE hPipe1; + char buf[100]; + LPTSTR lpszPipename1 = TEXT("\\\\.\\pipe\\artemis"); + + hPipe1 = CreateFile(lpszPipename1, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + if (hPipe1 == NULL || hPipe1 == INVALID_HANDLE_VALUE) + { + CLogger::OutputLog("Could not open the pipe - (error %i)", LogLevel::Debug, GetLastError()); + return; + } + + DWORD cbWritten; + WriteFile(hPipe1, msg, strlen(msg), &cbWritten, NULL); + CLogger::OutputLog_s("Transmitted to pipe", LogLevel::Debug); +} + +bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) +{ + CLogger::OutputLog("LogiLedSetLighting called (%i %i %i)", LogLevel::Debug, redPercentage, greenPercentage, bluePercentage); + + std::ostringstream os; + os << "0 0 " << redPercentage << " " << greenPercentage << " " << bluePercentage; + Transmit(os.str().c_str()); + + return true; +} + +bool LogiLedRestoreLighting() +{ + CLogger::OutputLog("LogiLedRestoreLighting called", LogLevel::Debug); + return true; +} + +bool LogiLedFlashLighting(int redPercentage, int greenPercentage, int bluePercentage, int milliSecondsDuration, int milliSecondsInterval) +{ + CLogger::OutputLog("LogiLedFlashLighting called (%i %i %i %i %i)", LogLevel::Debug, redPercentage, greenPercentage, bluePercentage, milliSecondsDuration, milliSecondsInterval); + return true; +} + +bool LogiLedPulseLighting(int redPercentage, int greenPercentage, int bluePercentage, int milliSecondsDuration, int milliSecondsInterval) +{ + CLogger::OutputLog("LogiLedPulseLighting called (%i %i %i %i %i)", LogLevel::Debug, redPercentage, greenPercentage, bluePercentage, milliSecondsDuration, milliSecondsInterval); + return true; +} + +bool LogiLedStopEffects() +{ + CLogger::OutputLog_s("LogiLedStopEffects called", LogLevel::Debug); + return true; +} + +bool LogiLedSetLightingFromBitmap(unsigned char bitmap[]) +{ + CLogger::OutputLog_s("LogiLedSetLightingFromBitmap called", LogLevel::Debug); + return true; +} + +bool LogiLedSetLightingForKeyWithScanCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage) +{ + CLogger::OutputLog("LogiLedSetLightingForKeyWithScanCode called [Key: %i] (%i %i %i)", LogLevel::Debug, keyCode, redPercentage, greenPercentage, bluePercentage); + return true; +} + +bool LogiLedSetLightingForKeyWithHidCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage) +{ + CLogger::OutputLog("LogiLedSetLightingForKeyWithHidCode called [Key: %i] (%i %i %i)", LogLevel::Debug, keyCode, redPercentage, greenPercentage, bluePercentage); + return true; +} + +bool LogiLedSetLightingForKeyWithQuartzCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage) +{ + CLogger::OutputLog("LogiLedSetLightingForKeyWithQuartzCode called [Key: %i] (%i %i %i)", LogLevel::Debug, keyCode, redPercentage, greenPercentage, bluePercentage); + return true; +} + +bool LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName keyName, int redPercentage, int greenPercentage, int bluePercentage) +{ + CLogger::OutputLog("LogiLedSetLightingForKeyWithKeyName called [Key: %i] (%i %i %i)", LogLevel::Debug, keyName, redPercentage, greenPercentage, bluePercentage); + + // Only transmit interesting keys. This can most likely be done prettier, but I'm no C++ dev. + if (game == "division" && + (keyName == LogiLed::F1 || + keyName == LogiLed::F2 || + keyName == LogiLed::F3 || + keyName == LogiLed::F4 || + keyName == LogiLed::R || + keyName == LogiLed::G || + keyName == LogiLed::V) + ) + { + std::ostringstream os; + os << "1 " << keyName << " " << redPercentage << " " << greenPercentage << " " << bluePercentage; + std::string s = os.str(); + Transmit(os.str().c_str()); + } + return true; +} + +bool LogiLedSaveLightingForKey(LogiLed::KeyName keyName) +{ + CLogger::OutputLog("LogiLedSaveLightingForKey called [Key: %i]", LogLevel::Debug, keyName); + return true; +} + +bool LogiLedRestoreLightingForKey(LogiLed::KeyName keyName) +{ + CLogger::OutputLog("LogiLedRestoreLightingForKey called [Key: %i]", LogLevel::Debug, keyName); + return true; +} + +bool LogiLedFlashSingleKey(LogiLed::KeyName keyName, int redPercentage, int greenPercentage, int bluePercentage, int msDuration, int msInterval) +{ + CLogger::OutputLog("LogiLedFlashSingleKey called [Key: %i] (%i %i %i %i %i)", LogLevel::Debug, keyName, redPercentage, greenPercentage, bluePercentage, msDuration, msInterval); + return true; +} + +bool LogiLedPulseSingleKey(LogiLed::KeyName keyName, int startRedPercentage, int startGreenPercentage, int startBluePercentage, int finishRedPercentage, int finishGreenPercentage, int finishBluePercentage, int msDuration, bool isInfinite) +{ + CLogger::OutputLog("LogiLedPulseSingleKey called [Key: %i] (%i %i %i %i %i %i %i %i)", LogLevel::Debug, keyName, startRedPercentage, startGreenPercentage, startBluePercentage, finishRedPercentage, finishGreenPercentage, finishBluePercentage, msDuration, isInfinite); + return true; +} + +bool LogiLedStopEffectsOnKey(LogiLed::KeyName keyName) +{ + CLogger::OutputLog("LogiLedStopEffectsOnKey called [Key: %i]", LogLevel::Debug, keyName); + return true; +} + +void LogiLedShutdown() +{ + CLogger::OutputLog_s("LogiLedShutdown called.", LogLevel::Debug); + g_hasInitialised = false; +} + diff --git a/Artemis/LogiLed2Artemis/main.h b/Artemis/LogiLed2Artemis/main.h new file mode 100644 index 000000000..3f59c932d --- /dev/null +++ b/Artemis/LogiLed2Artemis/main.h @@ -0,0 +1,2 @@ +#pragma once +