Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change move or die Patch folder and function to disable Corsair implementation from the Game #1857

Merged
merged 9 commits into from
Dec 30, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
<Grid>
<StackPanel>
<CheckBox x:Name="game_enabled" Content="Enable Aurora to provide lighting effects with Move or Die" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Checked="game_enabled_Checked" Unchecked="game_enabled_Checked"/>
<TextBlock Margin="10,10,64,0" Text="In order for Move or Die support to work, you have to apply the Aurora Wrapper Patch for Razer in order for Aurora to receive lighting information. Press the &quot;Patch Move or Die&quot; button to install automatically to the detected game directory. To choose manually press the &quot;Patch Move or Die Manually&quot; button and navigate to the Move or Die install directory. This should not trigger any anti-cheat, but it should be used at your own risk. P.S. You can actually apply this patch to any Razer Chroma supported game, and Aurora will work with it." VerticalAlignment="Top" TextWrapping="Wrap"/>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0">
<TextBlock Margin="10,10,64,0" VerticalAlignment="Top" TextWrapping="Wrap"><Run Text="In order for Move or Die support to work, you have to apply the Aurora Wrapper Patch for Razer in order for Aurora to receive lighting information. Press the &quot;Patch Move or Die&quot; button to install automatically to the detected game directory. To choose manually press the &quot;Patch Move or Die Manually&quot; button and navigate to the "/><Run Text="["/><Run Text="Move or Die install directory"/><Run Text="]"/><Run Text="\Love\win. This should not trigger any anti-cheat, but it should be used at your own risk. P.S. You can actually apply this patch to any Razer Chroma supported game, and Aurora will work with it."/></TextBlock>
<StackPanel Orientation="Horizontal" Margin="10,0,0,0">
<Button x:Name="patch_button" Content="Patch Move or Die" HorizontalAlignment="Left" VerticalAlignment="Top" Click="patch_button_Click"/>
<Button x:Name="patch_button_manually" Content="Patch Move or Die Manually" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="patch_button_manually_Click"/>
</StackPanel>
<Button x:Name="unpatch_button" Content="Unpatch Move or Die" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="unpatch_button_Click"/>
<TextBlock Margin="10,10,0,0" VerticalAlignment="Top" TextWrapping="Wrap"><Run Text="Optional: "/><Run Text="Move or Die's own Corsair implementation is overriding Aurora's"/><Run Text="."/><Run Text=" "/><Run Text="T"/><Run Text="his patch d"/><Run Text="isable"/><Run Text="s"/><Run Text=" "/><Run Text="RGB "/><Run Text="support for "/><Run Text="Corsair."/></TextBlock>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<Button x:Name="patch_cue_dll" Content="Disable Corsair MoD RGB support" HorizontalAlignment="Left" VerticalAlignment="Top" Click="patch_cue_dll_button_Click" Margin="10,0,0,0"/>
<Button x:Name="unpatch_cue_dll" Content="Re-enable Corsair MoD RGB support" HorizontalAlignment="Left" VerticalAlignment="Top" Click="unpatch_cue_dll_button_Click" Margin="10,0,0,0"/>
</StackPanel>
</StackPanel>
</Grid>
</TabItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Aurora.Settings;
using Aurora.Utils;
using System;
using System.IO;
using System.Windows;
Expand Down Expand Up @@ -46,67 +47,34 @@ private void unpatch_button_Click(object sender, RoutedEventArgs e)
private void patch_button_manually_Click(object sender, RoutedEventArgs e)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog();
System.Windows.Forms.DialogResult result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.InstallWrapper(dialog.SelectedPath);

MessageBox.Show("Aurora Wrapper Patch for Razer applied to\r\n" + dialog.SelectedPath);
}
}

private int GameID = 323850;
private const int GameID = 323850;

private bool InstallWrapper(string installpath = "")
{
if (String.IsNullOrWhiteSpace(installpath))
installpath = Utils.SteamUtils.GetGamePath(this.GameID);
if (string.IsNullOrWhiteSpace(installpath))
installpath = Path.Combine(SteamUtils.GetGamePath(GameID), "Love", "win");


if (!String.IsNullOrWhiteSpace(installpath))
{
using (BinaryWriter razer_wrapper_86 = new BinaryWriter(new FileStream(System.IO.Path.Combine(installpath, "RzChromaSDK.dll"), FileMode.Create)))
{
razer_wrapper_86.Write(Properties.Resources.Aurora_RazerLEDWrapper86);
}

using (BinaryWriter razer_wrapper_64 = new BinaryWriter(new FileStream(System.IO.Path.Combine(installpath, "RzChromaSDK64.dll"), FileMode.Create)))
{
razer_wrapper_64.Write(Properties.Resources.Aurora_RazerLEDWrapper64);
}

return true;
}
else
{
return false;
}
return FileUtils.TryWrite(Path.Combine(installpath, "RzChromaSDK.dll"), Properties.Resources.Aurora_RazerLEDWrapper86) &&
FileUtils.TryWrite(Path.Combine(installpath, "RzChromaSDK64.dll"), Properties.Resources.Aurora_RazerLEDWrapper64);
}

private bool UninstallWrapper()
{
String installpath = Utils.SteamUtils.GetGamePath(this.GameID);
if (!String.IsNullOrWhiteSpace(installpath))
{
string path = System.IO.Path.Combine(installpath, "RzChromaSDK.dll");
string path64 = System.IO.Path.Combine(installpath, "RzChromaSDK64.dll");

if (File.Exists(path))
File.Delete(path);
var installpath = SteamUtils.GetGamePath(GameID);

if (File.Exists(path64))
File.Delete(path64);

return true;
}
else
{
return false;
}
return FileUtils.TryDelete(Path.Combine(installpath, "Love", "win", "RzChromaSDK.dll")) &&
FileUtils.TryDelete(Path.Combine(installpath, "Love", "win", "RzChromaSDK64.dll"));
}


private void game_enabled_Checked(object sender, RoutedEventArgs e)
{
if (IsLoaded)
Expand All @@ -115,5 +83,34 @@ private void game_enabled_Checked(object sender, RoutedEventArgs e)
profile_manager.SaveProfiles();
}
}

private void patch_cue_dll_button_Click(object sender, RoutedEventArgs e)
{
string gamepath = Utils.SteamUtils.GetGamePath(GameID);

bool sucess = FileUtils.TryDisable(Path.Combine(gamepath, "Love", "win", "CUESDK.dll"));
bool sucess64 = FileUtils.TryDisable(Path.Combine(gamepath, "Love", "win", "CUESDK.x64.dll"));

if (sucess && sucess64)
MessageBox.Show("Sucesfully disabled MoD Corsair support.");
else if (sucess || sucess64)
MessageBox.Show("Error: Partly disabled MoD Corsair support. Is it already disabled?");
else
MessageBox.Show("Couldn't disabled MoD Corsair support. Is it already disabled?");
}

private void unpatch_cue_dll_button_Click(object sender, RoutedEventArgs e)
{
string gamepath = SteamUtils.GetGamePath(GameID);
bool sucess = FileUtils.TryEnable(Path.Combine(gamepath, "Love", "win", "CUESDK.dll"));
bool sucess64 = FileUtils.TryEnable(Path.Combine(gamepath, "Love", "win", "CUESDK.x64.dll"));

if (sucess && sucess64)
MessageBox.Show("Sucesfully re-enabled MoD Corsair support.");
else if (sucess || sucess64)
MessageBox.Show("Error: Partly re-enabled MoD Corsair support. Is it already enabled?");
else
MessageBox.Show("Couldn't re-enabled MoD Corsair support. Is it already enabled?");
}
}
}
5 changes: 3 additions & 2 deletions Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@
<Compile Include="Profiles\Terraria\GSI\Nodes\WorldNode.cs" />
<Compile Include="Profiles\Terraria\TerrariaApplication.cs" />
<Compile Include="Profiles\Terraria\TerrariaProfile.cs" />
<Compile Include="Profiles\Terraria\Control_Terraria.xaml.cs">
<DependentUpon>Control_Terraria.xaml</DependentUpon>
<Compile Include="Profiles\Terraria\Control_Terraria.xaml.cs">
<DependentUpon>Control_Terraria.xaml</DependentUpon>
</Compile>
<Compile Include="Settings\Control_LayerList.xaml.cs">
<DependentUpon>Control_LayerList.xaml</DependentUpon>
Expand Down Expand Up @@ -813,6 +813,7 @@
<Compile Include="Utils\Converters.cs" />
<Compile Include="Utils\DesktopUtils.cs" />
<Compile Include="Utils\DesktopDuplicator.cs" />
<Compile Include="Utils\FileUtils.cs" />
<Compile Include="Utils\FrameworkElementUtils.cs" />
<Compile Include="Utils\InputEvents.cs" />
<Compile Include="Utils\MathUtils.cs" />
Expand Down
116 changes: 116 additions & 0 deletions Project-Aurora/Project-Aurora/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aurora.Utils
{
public static class FileUtils
{
/// <summary>
/// Tries to write a given byte array to disk at the given location. Returns true if successfull
/// </summary>
/// <param name="path"></param>
/// <param name="file"></param>
/// <returns></returns>
public static bool TryWrite(string path, byte[] file)
{
try
{
using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
{
bw.Write(file);
}
return true;
}
catch (Exception e)
{
Global.logger.Error($"Error writing file \"{file}\": {e.Message}");
return false;
}
}

/// <summary>
/// Tries to delete a given file. Returns true if successful
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static bool TryDelete(string file)
{
if (!File.Exists(file))
return false;

try
{
File.Delete(file);
return true;
}
catch (Exception e)
{
Global.logger.Error($"Error deleting file \"{file}\": {e.Message}");
return false;
}
}

/// <summary>
/// Tried restoring a previously disabled file by renaming it. Returns true if successful
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static bool TryEnable(string file)
{
//if the original file exists, it's already enabled
if (File.Exists(file))
return false;

var disabled = file + ".disabled";

//if the disabled file doesnt exist, it can't be enabled
if (!File.Exists(disabled))
return false;

//otherwise, enable it
try
{
File.Move(disabled, file);
return true;
}
catch (Exception e)
{
Global.logger.Error($"Error enabling file \"{file}\": {e.Message}");
return false;
}
}

/// <summary>
/// Disables a file by appending ".disabled" to its name. Returns true if successful
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static bool TryDisable(string file)
{
//if the file we want to disable doesnt exist, return
if (!File.Exists(file))
return false;

var disabled = file + ".disabled";
try
{
//if the disabled file is already there, delete the old disabled file
if (File.Exists(disabled))
File.Delete(disabled);

//rename the original file
File.Move(file, disabled);
return true;
}
catch (Exception e)
{
Global.logger.Error($"Error disabling file \"{file}\": {e.Message}");
return false;
}
}
}
}