The Corsair User Forums  

Go Back   The Corsair User Forums > Corsair Product Discussion > iCUE Software

Notices

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #16  
Old 09-29-2018, 11:03 PM
Macca_Cool Macca_Cool is offline
Registered User
Macca_Cool's PC Specs
 
Join Date: Sep 2018
Location: Melbourne, Australia
Posts: 27
POST ID # = 974694
Macca_Cool Reputation: 13
Default Getting to this stage and beyond

So @hastegag asked me how I got to here, and I'm a little stuck, so I'm posting a walkthrough to get to this stage so other interested parties can quickly hop to here and work on the hard stuff.

Tools: You're gonna need Visual Studio for C++ (or something similar, a C++ IDE). And you need the CgSDK dll file (in the Far Cry 5 install, "CgSDK.x64_2015.dll").

Getting a lib file: In the Visual C++ install directory there are a bunch of tools we need (actually just one for now). My directory is: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\". Make a folder in there called something like "input" and give yourself read/write perms (makes the next part easier). In that folder make a file called "CgSDK.x64_2015.def" it's contents will look like so: https://pastebin.com/DEx48dFG
As you can see, it's just the names of all the functions we viewed earlier. Because they aren't mangled (a C++ compiler thing, for security I assume, against this very thing ) it's super easy. Then you want to open a command prompt window in the bin folder. Now run two commands:
Code:
vcvars32.bat
lib /def:./input/CgSDK.x64_2015.def /out:./input/CgSDK.x64_2015.lib /machine:X64
Which should generate a lib file (among other things) that you can link in your Visual C++ project. In the root of my project, I made a folder called "CgSDK" and have the dll, lib and headers in it. Now in the project settings you have to import the lib. So under C/C++ -> General -> Additional Include Directories add "$(SolutionDir)CgSDK\;" (use the correct path for you). Under Linker -> General -> Additional Library Directories add the same. I also needed to add "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64;" for a reference to the ucrt file, it was a dependancy for something(?) in both my project and sample iCUE SDK projects. Under Linker -> Input -> Additional Dependancies add "CgSDK.x64_2015.lib;" and it's all setup.

Header files: As I mentioned earlier, I looked at CgSDK functions and iCUE SDK functions and noticed some common ones. Those we will already know the prototypes (input/output) for. The rest we will need to be guessing essentially (more on that later). So we have 2 header files, one for all the function and one for loading the dll. They are as follows:
(CgSDK.x64_2015Global.h) https://pastebin.com/TAVLxgAE
(CgSDK.x64_2015.h) https://pastebin.com/wbKDHc4d

Note that for the header (not global one) I have assumed boolean outputs for the CgSDK functions, this is probably not correct. Also note missing inputs. We don't know anything about them yet! In any case, throw both headers into the "CgSDK" folder and you can safely import them with:
Code:
#include "CgSDK.x64_2015.h"
Where to from here: Now we can use the functions that we know are correct (the first 4) in our program, mine looks like this: https://pastebin.com/U4e0Wtyk
Try building with my program to make sure it is all working as intended. You should be getting the same output I had (save the last 2 lines). From here we need to actually miraculously guess inputs and outputs, try a whole bunch of them, or doing something more cunning. I've already used a program called Snowman to view the Assembly code of CgSDK.dll and reconstructed C++, however all types are generic so it is almost useless to us, however we might need Assembly later. My idea to progress would be using DLL Injection. The simplest means would be to make our own CgSDK.dll (using the same header files, might need to edit global one) and then replacing (or renaming) the one in the Far Cry 5 install. Our dll would need functions that could take any input (does C++ ellipsis work?) and would attempt to parse inputs as common things (integers, char*, booleans, basically anything we've seen in the iCUE SDK. Structs will be an issue) and dump them to a text file. It will probably also need to call the functions from the actual dll with the given inputs and return their outputs (dumping them on the way). We will know it works if Far Cry lighting still works while using our dll.

No idea how plausable that is but it's the best option I can see. Good luck to anyone picking this project up.

Last edited by Macca_Cool; 09-30-2018 at 06:15 AM. Reason: Fixed error in lib command
Reply With Quote
  #17  
Old 09-29-2018, 11:22 PM
Macca_Cool Macca_Cool is offline
Registered User
Macca_Cool's PC Specs
 
Join Date: Sep 2018
Location: Melbourne, Australia
Posts: 27
POST ID # = 974699
Macca_Cool Reputation: 13
Default

Forgot to add, for replacing CgSDK in the Far Cry 5 install, our dll will need to have the correct functions accessible from the same location as the original dll . Those locations are available through the use of "DLL Export Viewer" (they were just cut-off in the screenshot I posted). I can probably post these to pastebin if anyone wants them. When I looked at the Assembly code, these locations were all jump commands that went to the function elsewhere in the dll. Our dll would need to do something similar where at these locations are jump commands to our logging functions. Doing this might require us compiling our dll and then modifying it's Assembly code to fit this, which might be a huge pain because we need to ensure that the original locations are free of any of our program.
Reply With Quote
  #18  
Old 09-30-2018, 04:30 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 907
POST ID # = 974776
hastegag Reputation: 20
Default

Wow dude, you are awesome. With your help, I got a proof of concept going! I suspect it does not carry over DPI and macros. That said, maybe it could? I would say we could compare the FarCry5 profiles with other profiles and see if they even contain those .

Video Link here

I did everything you did except started from an SDK example (had to comment out some of the repeated enums and structs in the include) and most importantly added character pointers as what was sent into CgSdkSetGame() and sent in simply FarCry5 (the name of the directory icue has the cueprofiles in).

With the events and states I did the same and named the profiles in the directory. It seems to work but there must be a difference between events and states (maybe one is able to overlap the other). As a note, I have far cry 5 but at this point I am not sure it really matters, since this seems to get us off to a good start.

Code:
CORSAIR_GAME_SDK bool CgSdkSetGame(char *gamename);
	CORSAIR_GAME_SDK bool CgSdkSetState(char *statename);
	CORSAIR_GAME_SDK bool CgSdkSetEvent(char *eventname);
I don't know if it mattered, but I requested non exclusive control even though the sdk docs say it is unnecessary. It also may not have mattered that I used an sdk example project to start off.

Last edited by hastegag; 09-30-2018 at 04:33 PM.
Reply With Quote
  #19  
Old 09-30-2018, 09:51 PM
Macca_Cool Macca_Cool is offline
Registered User
Macca_Cool's PC Specs
 
Join Date: Sep 2018
Location: Melbourne, Australia
Posts: 27
POST ID # = 974826
Macca_Cool Reputation: 13
Default

Awesome work! I think this is just the motivation I need to get back on it after that whole Assembly mistake. I suspect that DPI and macros would overlap as they surely don't remove your macros when you're playing Far Cry also on importing (in iCUE) there are options to not import those. As for the events vs states thing, I suspect that a state is something that you're in for a while, think when you are on fire "FC_Fire", when you're in the water "FC_Water" or in the menu "FC_Menu". I believe events will be 1 time trigger profiles, think the profiles that have "play once" set: "FC_AnimalAttack", "FC_ArcadeCoin", "FC_Explosion", etc. After these finish playing the lighting profile should switch back to the highest priority state currently active (see the priorities.cfg which will also show that overlap probably doesn't happen - does the "FC_AnimalAttack" overlap or does the keyboard go black first when in-game?). I think I tried with those same function definitions the first time without success (or at the very least, a boolean wasn't returned) but I'll have another go. The DLL Injection route may not be needed, but if I don't make any headway I'll probably give it a go and hope structs don't show up.
Reply With Quote
  #20  
Old 09-30-2018, 10:18 PM
Macca_Cool Macca_Cool is offline
Registered User
Macca_Cool's PC Specs
 
Join Date: Sep 2018
Location: Melbourne, Australia
Posts: 27
POST ID # = 974828
Macca_Cool Reputation: 13
Default

Done! States are working on my side, can load up any of them as states and it prioritises them accordingly. We could have been here last week, but I made a silly mistake. I needed to check for errors after every command, because that actually tells us what's going wrong. Just needed to request exclusive access (might be specific to my setup though, because I'm using the demo devices in iCUE - only own the Void headset). For anyone else reading this, my motivation is to get this working for my mate's desk pc that's full of Corsair stuff. It's gonna be sick!

From here I guess I'll try getting events working and then we'll try the other functions. But with just events and states, it's already a SUPER powerful tool for dynamic lighting. So I guess we've solved the thread topic too now! But we'll keep our progress here I think.
Reply With Quote
  #21  
Old 10-02-2018, 11:53 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 907
POST ID # = 975038
hastegag Reputation: 20
Default

www.smithany.com/ProfileAsArgument.rar

So I spent some more time on it this evening and could get events and states working and the clearallevents and clearallstates seems to work correctly to give it back to CUE, and I could put custom profiles in, even with custom names, provided however that the name at the top matches the name of the file (cueprofile) and it needed to be present with a legit and non redundant value in priorities.cfg having the same name. As written, the profile name can be passed in as plaintext as an argument to the ProfileArgument.exe located in x64\Release\.

So if you make an icue profile called "something" and export the lighting and be sure the name in the tree is also "something" and then save it into the Corsair farcry5 install directory, probably: C:\Program Files (x86)\Corsair\CORSAIR iCUE Software\GameSdkEffects\FarCry5\. You also need to be sure "something" is present in the profiles.cfg file. If that fails be sure the <name> part near the top of the of the qml something.cueprofile is "something" without quotes.

Keep in mind you should make a backup of that folder especially if you play farcry5 on occasion (as i do as well) or you could end up breaking or over writing something.

I couldn't get the threading right to allow folks to cancel it as needed but it opens a window and sniffs for the q key every 2 seconds and should quit and release it back to icue when pressed.

This should save some steps, but keep in mind it does not handle: dpi, timers, macros, or anything else, just straight forward lighting. There are many other things that can be done and I could only get this to work when lighting effects were set to start with profile and never stop, but this may be helpful to some as we may evolve it.
Reply With Quote
  #22  
Old 10-03-2018, 04:34 AM
Macca_Cool Macca_Cool is offline
Registered User
Macca_Cool's PC Specs
 
Join Date: Sep 2018
Location: Melbourne, Australia
Posts: 27
POST ID # = 975050
Macca_Cool Reputation: 13
Default

Awesome work man. I ended up wrapping up the functions we know for C# (albeit very poorly wrapped) and set it up to work with the CS:GO Game Integration provided by Valve. So I can confirm that using a custom game CgSdkSetGame(char* name) works and will correctly navigate to a folder by that name in the GameSdkEffects folder. With that we've got custom profiles (both states and events) to work with the SDK from C#. So in total we can use SetGame, SetState, SetEvent, ClearState, ClearAllStates, ClearAllEvents, GetLastError, PerformProtocolHandshake and the Release/RequestControl functions. I still want to look into SetState/EventWithKey. My thoughts are that it either enables hidden lighting effects within the profile or it controls blending options. The latter comes from our attempt at a flashed profile for CSGO. When we trigger the CS_Flashed event there is an approx. 1 second period where the LEDs interpolate from their current state into the flash profile, essentially blending them together. Having the ability to immediately switch would be nice and potentially part of that function. On that, the FC_AnimalAtack profile for Far Cry 5, do you know if it has a delay before showing?
Reply With Quote
Reply

Tags
icue, profiles, programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.