1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Implemented most LightFX functions

This commit is contained in:
SpoinkyNL 2016-12-20 00:07:30 +01:00
parent b457c566dd
commit 0ec1bfa8cf
13 changed files with 752 additions and 314 deletions

View File

@ -16,7 +16,6 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
@ -32,19 +31,19 @@
<Label Grid.Row="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content>
<AccessText TextWrapping="Wrap"
Text="By default shows indicator lights, speed and engine RPM on the keyboard" />
Text="By default shows.. nothing yet! Default profiles next update :)" />
</Label.Content>
</Label>
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Bottom"
TextWrapping="Wrap" HorizontalAlignment="Left" FontFamily="Segoe UI Semibold"
TextAlignment="Justify" Margin="5,0,0,10">
The Euro Truck Simulator 2 module uses code from the
The Project CARS module uses code from the
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate"
NavigateUri="https://github.com/Funbit/ets2-telemetry-server">
ETS2 Telemetry Web Server
NavigateUri="https://bitbucket.org/MikeyTT/pcars-api-demo">
pCars API Demo
</Hyperlink>
project by Funbit
project by MikeyTT
</TextBlock>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
@ -55,26 +54,11 @@
</StackPanel>
</Grid>
<StackPanel Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2" Margin="0,0,1,0">
<Label FontSize="20" HorizontalAlignment="Left" Content="Euro Truck Simulator 2 directory" />
<Grid>
<TextBox x:Name="GameDirectory" Height="23" TextWrapping="Wrap" Margin="5,0,30,0"
Text="{Binding Path=GameSettings.GameDirectory, Mode=TwoWay}"
cal:Message.Attach="[Event LostFocus] = [Action PlacePlugin]" />
<Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25"
Style="{DynamicResource SquareButtonStyle}" Height="26" Margin="0,-2,0,0" />
</Grid>
</StackPanel>
<!-- Profile editor -->
<ContentControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ProfileEditor" Margin="0,0,-20,0" />
<ContentControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ProfileEditor" Margin="0,0,-20,0" />
<!-- Buttons -->
<StackPanel Grid.Column="0" Grid.Row="4" Orientation="Horizontal" VerticalAlignment="Bottom">
<StackPanel Grid.Column="0" Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Bottom">
<Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100"
Style="{DynamicResource SquareButtonStyle}" />
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100"

View File

@ -26,13 +26,13 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
@ -87,13 +87,14 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIGHTFX2ARTEMIS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>LightFX2Artemis.def</ModuleDefinitionFile>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -102,14 +103,12 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;LIGHTFX2ARTEMIS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>LightFX2Artemis.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -120,15 +119,16 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LIGHTFX2ARTEMIS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>LightFX2Artemis.def</ModuleDefinitionFile>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -139,26 +139,25 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;LIGHTFX2ARTEMIS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>LightFX2Artemis.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="LightFX2Artemis.def" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\LogiLed2Artemis\main.cpp" />
<ClCompile Include="LightFxDevice.cpp" />
<ClCompile Include="LightFxLight.cpp" />
<ClCompile Include="LightFxState.cpp" />
<ClCompile Include="Source.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="LightFxDevice.h" />
<ClInclude Include="LightFxLight.h" />
<ClInclude Include="LightFxState.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -15,15 +15,16 @@
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="LightFX2Artemis.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\LogiLed2Artemis\main.cpp">
<ClCompile Include="LightFxState.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LightFxState.cpp">
<ClCompile Include="LightFxDevice.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LightFxLight.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@ -31,5 +32,11 @@
<ClInclude Include="LightFxState.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LightFxDevice.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LightFxLight.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
#include "LightFxDevice.h"
LightFxDevice::LightFxDevice()
{
}
LightFxDevice::~LightFxDevice()
{
}

View File

@ -0,0 +1,11 @@
#pragma once
#include "LightFxLight.h"
class LightFxDevice
{
public:
LightFxDevice();
~LightFxDevice();
LightFxLight Lights[128];
};

View File

@ -0,0 +1,12 @@
#include "LightFxLight.h"
LightFxLight::LightFxLight()
{
}
LightFxLight::~LightFxLight()
{
}

View File

@ -0,0 +1,11 @@
#pragma once
#include "includes/LFXDecl.h"
class LightFxLight
{
public:
LightFxLight();
~LightFxLight();
PLFX_COLOR Color;
};

View File

@ -11,3 +11,10 @@ LightFxState::LightFxState(char* game)
LightFxState::~LightFxState()
{
}
void LightFxState::Update()
{
// Serialize self
// Transmit through Pipe
}

View File

@ -1,8 +1,12 @@
#pragma once
#include "LightFxDevice.h"
class LightFxState
{
public:
LightFxState(char* game);
~LightFxState();
void Update();
char* Game;
};
LightFxDevice Devices[5];
};

View File

@ -0,0 +1,212 @@
#include <Windows.h>
#include <stdio.h>
#include <thread>
#include <complex>
#include <filesystem>
#include <fstream>
#include "../LightFX2Artemis/LightFxState.h"
#include "includes/LFX2.h"
#include "includes/LFXDecl.h"
#include "includes/log.h"
using namespace std;
LightFxState* lightFxState;
char* GetGame()
{
CHAR szPath[MAX_PATH];
GetModuleFileNameA(NULL, szPath, MAX_PATH);
return szPath;
};
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
lightFxState = new LightFxState(GetGame());
FILELog::ReportingLevel() = logDEBUG1;
FILE* log_fd = fopen("log.txt", "w");
Output2FILE::Stream() = log_fd;
FILE_LOG(logDEBUG1) << "Main called, DLL loaded into " << lightFxState->Game;
}
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)
{
FILE_LOG(logDEBUG1) << "Could not open the pipe - " << GetLastError();
return;
}
DWORD cbWritten;
WriteFile(hPipe1, msg, strlen(msg), &cbWritten, NULL);
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Initialize()
{
FILE_LOG(logDEBUG1) << "Called LFX_Initialize()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Release()
{
FILE_LOG(logDEBUG1) << "Called LFX_Release()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Reset()
{
FILE_LOG(logDEBUG1) << "Called LFX_Reset()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Update()
{
FILE_LOG(logDEBUG1) << "Called LFX_Update()";
lightFxState->Update();
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_UpdateDefault()
{
FILE_LOG(logDEBUG1) << "Called LFX_UpdateDefault()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetNumDevices(unsigned int* const numDevices)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetNumDevices()";
// Keyboard, mouse, headset, mousemat, generic
*numDevices = 5;
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetDeviceDescription(const unsigned int devIndex, char* const devDesc, const unsigned int devDescSize, unsigned char* const devType)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetDeviceDescription()";
stringstream ss;
ss << "Device " << devIndex;
string deviceName = ss.str();
if (deviceName.length() > devDescSize)
return LFX_ERROR_BUFFSIZE;
// Just assign similar LFX device types to each index
sprintf_s(devDesc, devDescSize, deviceName.c_str());
if (devIndex == 0)
*devType = LFX_DEVTYPE_KEYBOARD;
else if (devIndex == 1)
*devType = LFX_DEVTYPE_MOUSE;
else if (devIndex == 2)
*devType = LFX_DEVTYPE_SPEAKER;
else if (devIndex == 3)
*devType = LFX_DEVTYPE_GAMEPAD;
else
*devType = LFX_DEVTYPE_DESKTOP;
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetNumLights(const unsigned int devIndex, unsigned int* const numLights)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetNumLights()";
// Just do one for now
*numLights = 1;
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightDescription(const unsigned int devIndex, const unsigned int lightIndex, char* const lightDesc, const unsigned int lightDescSize)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetLightDescription()";
stringstream ss;
ss << "Device " << devIndex << "Light" << lightIndex;
string lightDescription = ss.str();
if (lightDescription.length() > lightDescSize)
return LFX_ERROR_BUFFSIZE;
sprintf_s(lightDesc, lightDescSize, lightDescription.c_str());
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightLocation(const unsigned int devIndex, const unsigned int lightIndex, PLFX_POSITION const lightLoc)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetLightLocation()";
*lightLoc = LFX_POSITION{ 0,0,0 };
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightColor(const unsigned int devIndex, const unsigned int lightIndex, PLFX_COLOR const lightCol)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetLightColor()";
*lightCol = *lightFxState->Devices[devIndex].Lights[lightIndex].Color;
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightColor(const unsigned int devIndex, const unsigned int lightIndex, const PLFX_COLOR lightCol)
{
FILE_LOG(logDEBUG1) << "Called LFX_SetLightColor()";
lightFxState->Devices[devIndex].Lights[lightIndex].Color = lightCol;
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Light(const unsigned int locationMask, const unsigned int colorVal)
{
FILE_LOG(logDEBUG1) << "Called LFX_Light()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightActionColor(const unsigned int, const unsigned int, const unsigned int, const PLFX_COLOR)
{
FILE_LOG(logDEBUG1) << "Called LFX_SetLightActionColor()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightActionColorEx(const unsigned int, const unsigned int, const unsigned int, const PLFX_COLOR, const PLFX_COLOR)
{
FILE_LOG(logDEBUG1) << "Called LFX_SetLightActionColorEx()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_ActionColor(const unsigned int, const unsigned int, const unsigned int)
{
FILE_LOG(logDEBUG1) << "Called LFX_ActionColor()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_ActionColorEx(const unsigned int, const unsigned int, const unsigned int, const unsigned int)
{
FILE_LOG(logDEBUG1) << "Called LFX_ActionColorEx()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetTiming(const int)
{
FILE_LOG(logDEBUG1) << "Called LFX_SetTiming()";
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetVersion(char* const version, const unsigned int versionSize)
{
FILE_LOG(logDEBUG1) << "Called LFX_GetVersion()";
sprintf_s(version, versionSize, "2.0.0.0");
return LFX_SUCCESS;
}

View File

@ -1,205 +0,0 @@
/***************************************************************
LFXConfigurator.h - Defines the exports for the LightFX
Config 1.0 DLL
Purpose: Provide library exports for communicating with
the LightFX Config 1.0 API
Copyright (c) 2007 Dell, Inc. All rights reserved.
Dell, Inc. makes no warranty of any kind with regard
to this material, including, but not limited to, the
implied warranties of merchantability and fitness for
a particular purpose. Dell, Inc. shall not be liable
for any errors contained herein, or for incidental or
consequential damages in connection with the furnishing,
performance or use of this material.
This document contains proprietary information which
is protected by copyright. All rights reserved.
Reproduction without the written permission of Dell
is strictly forbidden.
***************************************************************/
#pragma once
#define _EXPORTING
#ifdef _EXPORTING // To be used by SDK developer
#define FN_DECLSPEC __declspec(dllexport)
#elif _IMPORTING // To be used for dynamic linking to dll
#define FN_DECLSPEC __declspec(dllimport)
#else // To be used for linking using static library
#define FN_DECLSPEC
#endif
#ifdef _STDCALL_SUPPORTED
#define STDCALL __stdcall // Declare our calling convention
#else
#define STDCALL
#endif // STDCALL_SUPPORTED
// Return values
#define LFX_RESULT unsigned int
#define LFX_SUCCESS 0 // Success
#define LFX_FAILURE 1 // Generic failure
#define LFX_ERROR_NOINIT 2 // System not initialized yet
#define LFX_ERROR_NODEVS 3 // No devices available
#define LFX_ERROR_NOLIGHTS 4 // No lights available
#define LFX_ERROR_BUFFSIZE 5 // Buffer size too small
//event position
#define LFX_EVENTPOSITION unsigned int
#define LFX_FIRSTEVENT 0 // First event
#define LFX_NEXTEVENT 1 // Next event
//event position
#define LFX_APPTYPE unsigned int
#define LFX_GAME 0 // The application is a game
#define LFX_GENERALUSEAPP 1 // It is a general use application
#ifdef __cplusplus
extern "C" {
#endif
// LightFX Config 1.0 DLL export function declarations
/***************************************************************
Function: LFX_CONFIGURATOR_Initialize
Description:
Initializes the LightFX Config 1.0 system.
This function must be called prior to any other library calls being made. If this
function is not called, the system will not be initialized and the other functions
will return LFX_ERROR_NOINIT.
Inputs: None
Outputs: None
Returns:
LFX_SUCCESS if the system is successfully initialized, or was already initialized.
LFX_FAILURE if initialization fails.
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_Initialize();
/***************************************************************
Function: LFX_CONFIGURATOR_Release
Description:
Release the LightFX Config 1.0 system.
This function may be called when the system is no longer needed. If this
function is not called, release will still occur on process detach.
Inputs: None
Outputs: None
Returns:
LFX_SUCCESS
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_Release();
/***************************************************************
Function: LFX_CONFIGURATOR_RegisterConfigurationFile
Description:
Register an app in order to be read by the AlienFX Editor.
Inputs: Application name and full path to the config file
Outputs: None
Returns:
LFX_SUCCESS if the application is successfully registered.
LFX_FAILURE if the registration fails.
LFX_ERROR_NOINIT if the LFX_CONFIGURATOR_Initialize
function was not called before
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_RegisterConfigurationFile(char* const appFXName, char* const configurationFileFullPath, const LFX_APPTYPE appType);
/***************************************************************
Function: LFX_CONFIGURATOR_UnregisterConfigurationFile
Description:
Unregister an app. Once this function is called, the app
will not appear in AlienFX Editor and cannot be configured
Inputs: Application name
Outputs: None
Returns:
LFX_SUCCESS if the application is successfully unregistered.
LFX_FAILURE if the registration fails.
LFX_ERROR_NOINIT if the LFX_CONFIGURATOR_Initialize
function was not called before
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_UnregisterConfigurationFile(char* const appFXName);
/***************************************************************
Function: LFX_CONFIGURATOR_GetUserConfigurationFilePath
Description:
Get the user's configuration file for an application
Inputs: Application name and the size of the buffer where the
user's configuration filename is going to be returned
Outputs:
Populates a character string with the user's configuration file
Returns:
LFX_SUCCESS if the user configuration file is returned.
LFX_FAILURE if the user's configuration file cannot be returned.
LFX_ERROR_BUFFSIZE if the buffer provided is too small.
LFX_ERROR_NOINIT if the LFX_CONFIGURATOR_Initialize
function was not called before
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_GetUserConfigurationFilePath(char* const appFXName, char* const userConfigurationFilename, const unsigned int userConfigurationFilenameSize);
/***************************************************************
Function: LFX_CONFIGURATOR_GetConfigurationEvent
Description:
Get the color configuration for an event
Inputs: Application name and event id
Outputs:
Populates a color array and the amount of colors for that event
Returns:
LFX_SUCCESS if the colors for the event is returned.
LFX_FAILURE if the colors for the event cannot be returned.
LFX_ERROR_NOINIT if the LFX_CONFIGURATOR_Initialize
function was not called before
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_GetConfigurationEvent(char* const appFXName, const unsigned int eventID, unsigned int* &colors, unsigned int &colorCount);
/***************************************************************
Function: LFX_CONFIGURATOR_GetConfigurationEventAt
Description:
Get the color configuration for an event
Inputs: Application name and event position
Outputs:
Returns the event in that position and data related
Populates a character string with the event name
Populates a color array and the amount of colors for that event
Returns:
LFX_SUCCESS if there is an event to be returned.
LFX_FAILURE if the event cannot be returned.
LFX_ERROR_BUFFSIZE if the buffer provided is too small.
LFX_ERROR_NOINIT if the LFX_CONFIGURATOR_Initialize
function was not called before
***************************************************************/
FN_DECLSPEC LFX_RESULT STDCALL LFX_CONFIGURATOR_GetConfigurationEventAt(char* const appFXName, unsigned int position,
int &eventID, char* const eventName, const unsigned int eventNameSize, unsigned int* &colors, unsigned int &colorCount);
#ifdef __cplusplus
} /* end extern "C" */
#endif
// The remaining defines and typedefs are useful for explicitly linking to
// the DLL, and can be ignored if using the static lib, or implicitely linking.
#define LFX_CONFIGURATOR_DLL_NAME "LightFXConfigurator64.dll"
// LightFX Config 1.0 DLL export function names
#define LFX_CONFIGURATOR_DLL_INITIALIZE "LFX_CONFIGURATOR_Initialize"
#define LFX_CONFIGURATOR_DLL_RELEASE "LFX_CONFIGURATOR_Release"
#define LFX_CONFIGURATOR_DLL_REGISTERCONFIGURATIONFILE "LFX_CONFIGURATOR_RegisterConfigurationFile"
#define LFX_CONFIGURATOR_DLL_UNREGISTERCONFIGURATIONFILE "LFX_CONFIGURATOR_UnregisterConfigurationFile"
#define LFX_CONFIGURATOR_DLL_GETUSERCONFIGURATIONFILEPATH "LFX_CONFIGURATOR_GetUserConfigurationFilePath"
#define LFX_CONFIGURATOR_DLL_GETCONFIGURATIONEVENT "LFX_CONFIGURATOR_GetConfigurationEvent"
#define LFX_CONFIGURATOR_DLL_GETCONFIGURATIONEVENTFROMPOSITION "LFX_CONFIGURATOR_GetConfigurationEventAt"
// LightFX Config 1.0 function pointer declarations
typedef LFX_RESULT (*LFXCONFIGURATORINITIALIZE)();
typedef LFX_RESULT (*LFXCONFIGURATORRELEASE)();
typedef LFX_RESULT (*LFXCONFIGURATORREGISTERCONFIGURATIONFILE)(char* const, char* const, const LFX_APPTYPE);
typedef LFX_RESULT (*LFXCONFIGURATORUNREGISTERCONFIGURATIONFILE)(char* const);
typedef LFX_RESULT (*LFXCONFIGURATORGETUSERCONFIGURATIONFILEPATH)(char* const, char* const, const unsigned int);
typedef LFX_RESULT (*LFXCONFIGURATORGETCONFIGURATIONEVENT)(char* const, const unsigned int, unsigned int*&, unsigned int&);
typedef LFX_RESULT (*LFXCONFIGURATORGETCONFIGURATIONEVENTFROMPOSITION)(char* const, unsigned int, int&, char* const, const unsigned int, unsigned int*&, unsigned int&);

View File

@ -0,0 +1,172 @@
#ifndef __LOG_H__
#define __LOG_H__
#include <sstream>
#include <string>
#include <stdio.h>
inline std::string NowTime();
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
template <typename T>
class Log
{
public:
Log();
virtual ~Log();
std::ostringstream& Get(TLogLevel level = logINFO);
public:
static TLogLevel& ReportingLevel();
static std::string ToString(TLogLevel level);
static TLogLevel FromString(const std::string& level);
protected:
std::ostringstream os;
private:
Log(const Log&);
Log& operator =(const Log&);
};
template <typename T>
Log<T>::Log()
{
}
template <typename T>
std::ostringstream& Log<T>::Get(TLogLevel level)
{
os << "- " << NowTime();
os << " " << ToString(level) << ": ";
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
return os;
}
template <typename T>
Log<T>::~Log()
{
os << std::endl;
T::Output(os.str());
}
template <typename T>
TLogLevel& Log<T>::ReportingLevel()
{
static TLogLevel reportingLevel = logDEBUG4;
return reportingLevel;
}
template <typename T>
std::string Log<T>::ToString(TLogLevel level)
{
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
return buffer[level];
}
template <typename T>
TLogLevel Log<T>::FromString(const std::string& level)
{
if (level == "DEBUG4")
return logDEBUG4;
if (level == "DEBUG3")
return logDEBUG3;
if (level == "DEBUG2")
return logDEBUG2;
if (level == "DEBUG1")
return logDEBUG1;
if (level == "DEBUG")
return logDEBUG;
if (level == "INFO")
return logINFO;
if (level == "WARNING")
return logWARNING;
if (level == "ERROR")
return logERROR;
Log<T>().Get(logWARNING) << "Unknown logging level '" << level << "'. Using INFO level as default.";
return logINFO;
}
class Output2FILE
{
public:
static FILE*& Stream();
static void Output(const std::string& msg);
};
inline FILE*& Output2FILE::Stream()
{
static FILE* pStream = stderr;
return pStream;
}
inline void Output2FILE::Output(const std::string& msg)
{
FILE* pStream = Stream();
if (!pStream)
return;
fprintf(pStream, "%s", msg.c_str());
fflush(pStream);
}
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
//typedef Log<Output2FILE> FILELog;
#ifndef FILELOG_MAX_LEVEL
#define FILELOG_MAX_LEVEL logDEBUG4
#endif
#define FILE_LOG(level) \
if (level > FILELOG_MAX_LEVEL) ;\
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
else FILELog().Get(level)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#include <windows.h>
inline std::string NowTime()
{
const int MAX_LEN = 200;
char buffer[MAX_LEN];
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
return "Error in NowTime()";
char result[100] = {0};
static DWORD first = GetTickCount();
std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
return result;
}
#else
#include <sys/time.h>
inline std::string NowTime()
{
char buffer[11];
time_t t;
time(&t);
tm r = {0};
strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
struct timeval tv;
gettimeofday(&tv, 0);
char result[100] = {0};
std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
return result;
}
#endif //WIN32
#endif //__LOG_H__

View File

@ -1,45 +1,109 @@
// 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 <stdio.h>
#include <tchar.h>
#include <thread>
#include "LogiLedDefs.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <complex>
#include <filesystem>
#include <fstream>
#include "../LightFX2Artemis/LightFxState.h"
#include "LFX2.h"
using namespace std;
static bool g_hasInitialised = false;
static bool mustLog = false;
LightFxState* lightFxState;
static int throttle = 0;
const char* game = "";
char* GetGame()
const char* GetGame()
{
CHAR divisionFind[] = ("Division");
CHAR gtaFind[] = ("GTA");
CHAR szPath[MAX_PATH];
GetModuleFileNameA(NULL, szPath, MAX_PATH);
return szPath;
GetModuleFileNameA(NULL, szPath, MAX_PATH);
char *output;
output = strstr(szPath, divisionFind);
if (output)
return "division";
output = strstr(szPath, gtaFind);
if (output)
return "gta";
return "bf1";
};
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
lightFxState = new LightFxState(GetGame());
game = GetGame();
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "Main called, DLL loaded into " << lightFxState->Game << "\n";
myfile << "Main called, DLL loaded into " << game << "\n";
myfile.close();
}
}
return true;
}
bool LogiLedInit()
{
g_hasInitialised = true;
return true;
}
bool LogiLedGetSdkVersion(int* majorNum, int* minorNum, int* buildNum)
{
// Mimic the SDK version
*majorNum = 8;
*minorNum = 81;
*buildNum = 15;
return true;
}
bool LogiLedSetTargetDevice(int targetDevice)
{
// Logitech SDK says this function returns false if LogiLedInit hasn't been called
return g_hasInitialised;
}
bool LogiLedSaveCurrentLighting()
{
return true;
}
void Transmit(const char* msg)
{
//Pipe Init Data
@ -64,97 +128,245 @@ void Transmit(const char* msg)
WriteFile(hPipe1, msg, strlen(msg), &cbWritten, NULL);
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Initialize()
// LogiLedSetLighting appears to have an undocumented extra argument
bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage, int custom = 0)
{
return LFX_SUCCESS;
// GTA goes mental on the SetLighting calls, lets only send one in every 20
if (game == "gta")
{
throttle++;
if (throttle > 20)
throttle = 0;
else
return true;
}
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
if (custom == 0)
{
myfile << "LogiLedSetLighting called\n";
}
else
{
myfile << "LogiLedSetLighting called with custom " << custom << "\n";
}
myfile.close();
}
ostringstream os;
os << "0 " << hex << custom << " " << dec << redPercentage << " " << greenPercentage << " " << bluePercentage;
Transmit(os.str().c_str());
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Release()
bool LogiLedRestoreLighting()
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedRestoreLighting called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Reset()
bool LogiLedFlashLighting(int redPercentage, int greenPercentage, int bluePercentage, int milliSecondsDuration, int milliSecondsInterval)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedFlashLighting called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Update()
bool LogiLedPulseLighting(int redPercentage, int greenPercentage, int bluePercentage, int milliSecondsDuration, int milliSecondsInterval)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedPulseLighting called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_UpdateDefault()
bool LogiLedStopEffects()
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedStopEffects called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetNumDevices(unsigned int* const)
bool LogiLedSetLightingFromBitmap(unsigned char bitmap[])
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSetLightingFromBitmap called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetDeviceDescription(const unsigned int, char* const, const unsigned int, unsigned char* const)
bool LogiLedSetLightingForKeyWithScanCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSetLightingForKeyWithScanCode called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetNumLights(const unsigned int, unsigned int* const)
bool LogiLedSetLightingForKeyWithHidCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSetLightingForKeyWithHidCode called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightDescription(const unsigned int, const unsigned int, char* const, const unsigned int)
bool LogiLedSetLightingForKeyWithQuartzCode(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSetLightingForKeyWithQuartzCode called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightLocation(const unsigned int, const unsigned int, PLFX_POSITION const)
bool LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName keyName, int redPercentage, int greenPercentage, int bluePercentage)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSetLightingForKeyWithKeyName called\n";
myfile.close();
}
// 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))
{
ostringstream os;
os << "1 " << keyName << " " << redPercentage << " " << greenPercentage << " " << bluePercentage;
string s = os.str();
Transmit(os.str().c_str());
return true;
}
ostringstream os;
os << "1 " << keyName << " " << redPercentage << " " << greenPercentage << " " << bluePercentage;
string s = os.str();
Transmit(os.str().c_str());
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetLightColor(const unsigned int, const unsigned int, PLFX_COLOR const)
bool LogiLedSaveLightingForKey(LogiLed::KeyName keyName)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedSaveLightingForKey called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightColor(const unsigned int, const unsigned int, const PLFX_COLOR)
bool LogiLedRestoreLightingForKey(LogiLed::KeyName keyName)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedRestoreLightingForKey called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_Light(const unsigned int, const unsigned int)
bool LogiLedFlashSingleKey(LogiLed::KeyName keyName, int redPercentage, int greenPercentage, int bluePercentage, int msDuration, int msInterval)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedFlashSingleKey called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightActionColor(const unsigned int, const unsigned int, const unsigned int, const PLFX_COLOR)
bool LogiLedPulseSingleKey(LogiLed::KeyName keyName, int startRedPercentage, int startGreenPercentage, int startBluePercentage, int finishRedPercentage, int finishGreenPercentage, int finishBluePercentage, int msDuration, bool isInfinite)
{
return LFX_SUCCESS;
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedPulseSingleKey called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetLightActionColorEx(const unsigned int, const unsigned int, const unsigned int, const PLFX_COLOR, const PLFX_COLOR)
{
return LFX_SUCCESS;
bool LogiLedStopEffectsOnKey(LogiLed::KeyName keyName)
{
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedStopEffectsOnKey called\n";
myfile.close();
}
return true;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_ActionColor(const unsigned int, const unsigned int, const unsigned int)
void LogiLedShutdown()
{
return LFX_SUCCESS;
}
if (mustLog)
{
ofstream myfile;
myfile.open("log.txt", ios::out | ios::app);
myfile << "LogiLedShutdown called\n";
myfile.close();
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_ActionColorEx(const unsigned int, const unsigned int, const unsigned int, const unsigned int)
{
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_SetTiming(const int)
{
return LFX_SUCCESS;
}
FN_DECLSPEC LFX_RESULT STDCALL LFX_GetVersion(char* const, const unsigned int)
{
return LFX_SUCCESS;
}
g_hasInitialised = false;
}