Skip to content

Commit 87be86d

Browse files
committed
first implementation
1 parent 0c0915d commit 87be86d

File tree

11 files changed

+268
-45
lines changed

11 files changed

+268
-45
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Congratulations, you can now start developing your plugin!
1+
## Modules
2+
- Disable device with Artemis launch
3+
- Disable Synapse bloat with every Artemis launch. This will prevent unnecessary Razer software while keeping game integrations
24

3-
Next steps:
4-
- Change the solution name to something more meaningful
5-
- Fill in the plugin.json file with the correct information
6-
- Fix the build.yml so it uploads the built plugin
7-
- Update this README.md file with relevant information about your plugin
5+
This plugin requires admin privilages, so using this will make Artemis restart with admin privileges each time it runs.
6+
7+
To make the launch faster, make the shortcut and startup task run as administrator.

src/Artemis.Plugins.ChromaDisableDeviceControl/Bootstrapper.cs

-22
This file was deleted.

src/Artemis.Plugins.ChromaDisableDeviceControl/plugin.json

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net7.0</TargetFramework>
3+
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
44
<Platforms>x64</Platforms>
55
<EnableDynamicLoading>true</EnableDynamicLoading>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="ArtemisRGB.UI.Shared" IncludeAssets="compile;build;buildTransitive" Version="1.2023.622.7" />
11+
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0-rc.1.23419.4" />
1112
</ItemGroup>
1213

1314
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using Artemis.Core;
3+
using Artemis.Core.Modules;
4+
5+
namespace Artemis.Plugins.ChromaSdkHacks;
6+
7+
[PluginFeature(Name = "Disable Bloat")]
8+
public class DisableBloatModule : Module
9+
{
10+
private bool _afterLaunch;
11+
12+
private readonly PluginSettings _pluginSettings;
13+
14+
public DisableBloatModule(PluginSettings pluginSettings)
15+
{
16+
_pluginSettings = pluginSettings;
17+
}
18+
19+
public override void Enable()
20+
{
21+
var manuallyEnabled = _pluginSettings.GetSetting("DisableBloat", false);
22+
if (!manuallyEnabled.Value && !_afterLaunch)
23+
{
24+
_afterLaunch = true;
25+
throw new ArtemisPluginException("Not manually enabled");
26+
}
27+
28+
manuallyEnabled.Value = true;
29+
manuallyEnabled.Save();
30+
31+
RazerChromaUtils.DisableChromaBloat();
32+
}
33+
34+
public override void Disable()
35+
{
36+
}
37+
38+
public override void Update(double deltaTime)
39+
{
40+
}
41+
42+
public override List<IModuleActivationRequirement>? ActivationRequirements => null;
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
using Artemis.Core;
3+
using Artemis.Core.Modules;
4+
5+
namespace Artemis.Plugins.ChromaSdkHacks;
6+
7+
[PluginFeature(Name = "Disable Device Control")]
8+
public class DisableDeviceControlModule : Module
9+
{
10+
public override void Enable()
11+
{
12+
RazerChromaUtils.DisableDeviceControlAsync().Wait();
13+
}
14+
15+
public override void Disable()
16+
{
17+
}
18+
19+
public override void Update(double deltaTime)
20+
{
21+
}
22+
23+
public override List<IModuleActivationRequirement>? ActivationRequirements => null;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.ServiceProcess;
5+
using System.Threading.Tasks;
6+
using Microsoft.Win32;
7+
8+
namespace Artemis.Plugins.ChromaSdkHacks;
9+
10+
public static class RazerChromaUtils
11+
{
12+
public static async Task DisableDeviceControlAsync()
13+
{
14+
const string file = """
15+
<?xml version="1.0" encoding="utf-8"?>
16+
<devices>
17+
</devices>
18+
""";
19+
20+
List<Task> tasks = new();
21+
var chromaPath = GetChromaPath();
22+
if (chromaPath != null)
23+
{
24+
tasks.Add(File.WriteAllTextAsync(chromaPath + "\\Devices.xml", file));
25+
}
26+
27+
var chromaPath64 = GetChromaPath64();
28+
if (chromaPath64 != null)
29+
{
30+
tasks.Add(File.WriteAllTextAsync(chromaPath64 + "\\Devices.xml", file));
31+
}
32+
33+
await Task.WhenAll(tasks.ToArray());
34+
35+
RestartChromaService();
36+
}
37+
38+
public static void DisableChromaBloat()
39+
{
40+
DisableService("Razer Chroma SDK Server");
41+
DisableService("Razer Chroma Stream Server");
42+
DisableService("Razer Central Service");
43+
DisableService("Razer Game Manager Service");
44+
DisableService("Razer Synapse Service");
45+
}
46+
47+
private static void DisableService(string serviceName)
48+
{
49+
using var service = new ServiceController(serviceName);
50+
ServiceHelper.ChangeStartMode(service, ServiceStartMode.Manual);
51+
if (!service.CanStop) return;
52+
service.Stop();
53+
service.WaitForStatus(ServiceControllerStatus.Stopped);
54+
}
55+
56+
private static void RestartChromaService()
57+
{
58+
using var service = new ServiceController("Razer Chroma SDK Service");
59+
if (service.Status == ServiceControllerStatus.Running)
60+
{
61+
try
62+
{
63+
service.Stop(true);
64+
service.WaitForStatus(ServiceControllerStatus.Stopped);
65+
}
66+
catch(Exception)
67+
{
68+
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(2));
69+
}
70+
}
71+
72+
if (service.Status != ServiceControllerStatus.Stopped) return;
73+
service.Start();
74+
service.WaitForStatus(ServiceControllerStatus.Running);
75+
}
76+
77+
private static string? GetChromaPath()
78+
{
79+
using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
80+
var key = hklm.OpenSubKey(@"Software\Razer Chroma SDK");
81+
var path = key?.GetValue("InstallPath", null) as string;
82+
return path;
83+
}
84+
85+
private static string? GetChromaPath64()
86+
{
87+
using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
88+
var key = hklm.OpenSubKey(@"Software\Razer Chroma SDK");
89+
var path = key?.GetValue("InstallPath64", null) as string;
90+
return path;
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Runtime.InteropServices;
4+
using System.ServiceProcess;
5+
6+
namespace Artemis.Plugins.ChromaSdkHacks;
7+
8+
/// <summary>
9+
/// http://peterkellyonline.blogspot.com/2011/04/configuring-windows-service.html
10+
/// </summary>
11+
public static class ServiceHelper
12+
{
13+
[DllImport(Advapi32Dll, CharSet = CharSet.Unicode, SetLastError = true)]
14+
private static extern bool ChangeServiceConfig(
15+
IntPtr hService,
16+
uint nServiceType,
17+
uint nStartType,
18+
uint nErrorControl,
19+
string? lpBinaryPathName,
20+
string? lpLoadOrderGroup,
21+
IntPtr lpdwTagId,
22+
[In] char[]? lpDependencies,
23+
string? lpServiceStartName,
24+
string? lpPassword,
25+
string? lpDisplayName);
26+
27+
[DllImport(Advapi32Dll, SetLastError = true, CharSet = CharSet.Auto)]
28+
private static extern IntPtr OpenService(IntPtr hScManager, string lpServiceName, uint dwDesiredAccess);
29+
30+
[DllImport(Advapi32Dll, EntryPoint = "OpenSCManagerW", ExactSpelling = true, CharSet = CharSet.Unicode,
31+
SetLastError = true)]
32+
private static extern IntPtr OpenSCManager(
33+
string machineName, string databaseName, uint dwAccess);
34+
35+
[DllImport(Advapi32Dll, EntryPoint = "CloseServiceHandle")]
36+
private static extern int CloseServiceHandle(IntPtr hScObject);
37+
38+
private const uint ServiceNoChange = 0xFFFFFFFF;
39+
private const uint ServiceQueryConfig = 0x00000001;
40+
private const uint ServiceChangeConfig = 0x00000002;
41+
private const uint ScManagerAllAccess = 0x000F003F;
42+
private const string Advapi32Dll = "advapi32.dll";
43+
44+
public static void ChangeStartMode(ServiceController svc, ServiceStartMode mode)
45+
{
46+
var scManagerHandle = OpenSCManager(null, null, ScManagerAllAccess);
47+
if (scManagerHandle == IntPtr.Zero)
48+
{
49+
throw new ExternalException("Open Service Manager Error");
50+
}
51+
52+
var serviceHandle = OpenService(
53+
scManagerHandle,
54+
svc.ServiceName,
55+
ServiceQueryConfig | ServiceChangeConfig);
56+
57+
if (serviceHandle == IntPtr.Zero)
58+
{
59+
throw new ExternalException("Open Service Error");
60+
}
61+
62+
var result = ChangeServiceConfig(
63+
serviceHandle,
64+
ServiceNoChange,
65+
(uint)mode,
66+
ServiceNoChange,
67+
null,
68+
null,
69+
IntPtr.Zero,
70+
null,
71+
null,
72+
null,
73+
null);
74+
75+
if (result == false)
76+
{
77+
var nError = Marshal.GetLastWin32Error();
78+
var win32Exception = new Win32Exception(nError);
79+
throw new ExternalException("Could not change service start type: "
80+
+ win32Exception.Message);
81+
}
82+
83+
CloseServiceHandle(serviceHandle);
84+
CloseServiceHandle(scManagerHandle);
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Guid": "2C7B2A91-6ACF-409C-806E-0D9917187E13",
3+
"Name": "Chroma SDK Hacks",
4+
"Description": "Disables Chroma SDK's device control so that Razer devices can be controlled with only OpenRGB",
5+
"Author": "Aytackydln",
6+
"Repository": "https://github.com/Aytackydln/Artemis.Plugins.ChromaSdkHacks",
7+
"Icon": "Snake",
8+
"Version": "1.0.0.0",
9+
"Main": "Artemis.Plugins.ChromaSdkHacks.dll",
10+
"AutoEnableProperties": true,
11+
"RequiresAdmin": true,
12+
"Platforms": "Windows",
13+
"Api": "1.0.0"
14+
}

src/Artemis.Plugins.sln renamed to src/RazerChromaHacks.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.3.32922.545
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Plugins.ChromaDisableDeviceControl", "Artemis.Plugins.ChromaDisableDeviceControl\Artemis.Plugins.ChromaDisableDeviceControl.csproj", "{E4AA9438-EAD4-4B2D-BC47-43BE4A830158}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Plugins.ChromaSdkHacks", "Artemis.Plugins.ChromaSdkHacks\Artemis.Plugins.ChromaSdkHacks.csproj", "{E4AA9438-EAD4-4B2D-BC47-43BE4A830158}"
66
EndProject
77
Global
88
GlobalSection(SolutionProperties) = preSolution

0 commit comments

Comments
 (0)