Skip to content

Commit

Permalink
implement auto gsi installation for payday 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Sep 6, 2024
1 parent 96049bf commit c52c008
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 107 deletions.
25 changes: 19 additions & 6 deletions Project-Aurora/Project-Aurora/Profiles/Payday 2/Control_PD2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@
<Grid>
<TabControl>
<TabItem Header="Overview for Payday 2">
<Grid>
<TextBlock Margin="10,5,0,0" VerticalAlignment="Top" TextWrapping="Wrap" HorizontalAlignment="Left" Width="770"><Run Text="In order for Payday 2 support to work, you have to install the BLT Lua hook"/><Run Text=", BeardLib"/><Run Text=" and the GSI mod for Payday 2. Press the &quot;Get BLT Hook&quot; button to be taken to the BLT download page"/><Run Text=". Press the &quot;Get"/><Run Text=" BeardLib"/><Run Text="&quot;"/><Run Text=" button to be taken to its github page where it can be downloaded"/><Run Text=". Afterwards, you can press &quot;Install GSI for Payday 2&quot; to automatically install the GSI mod. (You need to have the BLT hook for GSI mod to function)"/></TextBlock>
<Button x:Name="get_hook_button" Content="Get BLT Hook" HorizontalAlignment="Left" Margin="10,83,0,0" VerticalAlignment="Top" Click="get_hook_button_Click"/>
<Button x:Name="get_lib_button" Content="Get BeardLib" HorizontalAlignment="Left" Margin="91,83,0,0" VerticalAlignment="Top" Click="get_lib_button_Click"/>
<Button x:Name="install_mod_button" Content="Install GSI for Payday 2" HorizontalAlignment="Left" Margin="10,108,0,0" VerticalAlignment="Top" Click="install_mod_button_Click" Width="153"/>
</Grid>
<StackPanel>
<TextBlock Margin="10,5,0,0" VerticalAlignment="Top" TextWrapping="Wrap" HorizontalAlignment="Left" Width="770">
<Run Text="In order for Payday 2 support to work, you have to install the BLT Lua hook"/>
<Run Text=", BeardLib"/>
<Run Text=" and the GSI mod for Payday 2. Press the &quot;Get BLT Hook&quot; button to be taken to the BLT download page"/>
<Run Text=". Press the &quot;Get"/>
<Run Text=" BeardLib"/>
<Run Text="&quot;"/>
<Run Text=" button to be taken to its github page where it can be downloaded"/>
<Run Text=". Afterwards, you can press &quot;Install GSI for Payday 2&quot; to automatically install the GSI mod. (You need to have the BLT hook for GSI mod to function)"/>
<LineBreak/><LineBreak/>
BeardLib needs to be installed to mods folder of Payday 2 after installing BLT Hook
</TextBlock>
<StackPanel Orientation="Horizontal" Margin="0,10,0,10">
<Button Content="Get BLT Hook" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="get_hook_button_Click"/>
<Button Content="Get BeardLib" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="get_lib_button_Click"/>
</StackPanel>
<Button x:Name="InstallModButton" Content="Install GSI for Payday 2" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="install_mod_button_Click" Width="153"/>
</StackPanel>
</TabItem>
<TabItem Header="Preview">
<Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using AuroraRgb.Profiles.Payday_2.GSI;
using AuroraRgb.Profiles.Payday_2.GSI.Nodes;
using AuroraRgb.Utils.Steam;
using ICSharpCode.SharpZipLib.Zip;

namespace AuroraRgb.Profiles.Payday_2;

Expand All @@ -29,53 +25,19 @@ private void get_hook_button_Click(object? sender, RoutedEventArgs e)
Process.Start("explorer", @"https://superblt.znix.xyz/");
}

private void install_mod_button_Click(object? sender, RoutedEventArgs e)
private async void install_mod_button_Click(object? sender, RoutedEventArgs e)
{
var pd2Path = SteamUtils.GetGamePath(218620);

if (string.IsNullOrWhiteSpace(pd2Path))
InstallModButton.IsEnabled = false;
var errorMessage = await Pd2GsiUtils.InstallMod();
if (errorMessage != null)
{
MessageBox.Show("Payday 2 is not installed through Steam.\r\nCould not install the GSI mod.");
return;
MessageBox.Show(errorMessage);
}

if (!Directory.Exists(pd2Path))
else
{
MessageBox.Show("Payday 2 directory is not found.\r\nCould not install the GSI mod.");
return;
MessageBox.Show("GSI for Payday 2 installed.");
}

if (!Directory.Exists(Path.Combine(pd2Path, "mods")))
{
MessageBox.Show("BLT Hook was not found.\r\nCould not install the GSI mod.");
return;
}

//copy gsi config file
using var gsiConfigFile = new MemoryStream(Properties.Resources.PD2_GSI);
File.WriteAllBytes(Path.Combine(pd2Path, "GSI", "Aurora.xml"), gsiConfigFile.ToArray());

var modFolder = Path.Combine(pd2Path, "mods", "GSI");

const string zipUrl = "https://github.com/Aurora-RGB/Payday2-GSI/archive/refs/heads/main.zip";
using var webClient = new WebClient();
using var zipStream = new MemoryStream(webClient.DownloadData(zipUrl));
using var zipInputStream = new ZipInputStream(zipStream);
while (zipInputStream.GetNextEntry() is { } entry)
{
if (!entry.IsFile)
continue;

var entryName = entry.Name;
var fullPath = Path.Combine(modFolder, entryName).Replace("\\Payday2-GSI-main", "");

Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

using var entryFileStream = File.Create(fullPath);
zipInputStream.CopyTo(entryFileStream);
}

MessageBox.Show("GSI for Payday 2 installed.");
InstallModButton.IsEnabled = true;
}

private void preview_gamestate_SelectionChanged(object? sender, SelectionChangedEventArgs e)
Expand Down
70 changes: 70 additions & 0 deletions Project-Aurora/Project-Aurora/Profiles/Payday 2/GSI/Pd2GsiUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AuroraRgb.Properties;
using AuroraRgb.Utils.Steam;
using ICSharpCode.SharpZipLib.Zip;

namespace AuroraRgb.Profiles.Payday_2.GSI;

public static class Pd2GsiUtils
{
/// <summary>
/// Installs GSI mod for Payday 2
/// </summary>
/// <returns>error message if fails</returns>
public static async Task<string?> InstallMod()
{
var pd2Path = await SteamUtils.GetGamePathAsync(218620);

if (string.IsNullOrWhiteSpace(pd2Path))
{
return "Payday 2 is not installed through Steam.\r\nCould not install the GSI mod.";
}

if (!Directory.Exists(pd2Path))
{
return "Payday 2 directory is not found.\r\nCould not install the GSI mod.";
}

if (!Directory.Exists(Path.Combine(pd2Path, "mods")))
{
return "BLT Hook was not found.\r\nCould not install the GSI mod.";
}

//create GSI config folder, in case game is not run with GSI mod installed
var gsiConfigDir = Path.Combine(pd2Path, "GSI");
Directory.CreateDirectory(gsiConfigDir);

//copy gsi config file
using var gsiConfigFile = new MemoryStream(Resources.PD2_GSI);
await File.WriteAllBytesAsync(Path.Combine(pd2Path, "GSI", "Aurora.xml"), gsiConfigFile.ToArray());

// extract mod
await ExtractPd2Mod(pd2Path);

return null;
}

private static async Task ExtractPd2Mod(string pd2Path)
{
const string zipUrl = "https://github.com/Aurora-RGB/Payday2-GSI/archive/refs/heads/main.zip";
var modFolder = Path.Combine(pd2Path, "mods", "GSI");
using var webClient = new WebClient();
using var zipStream = new MemoryStream(webClient.DownloadData(zipUrl));
await using var zipInputStream = new ZipInputStream(zipStream);
while (zipInputStream.GetNextEntry() is { } entry)
{
if (!entry.IsFile)
continue;

var entryName = entry.Name;
var fullPath = Path.Combine(modFolder, entryName).Replace("\\Payday2-GSI-main", "");

Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

await using var entryFileStream = File.Create(fullPath);
await zipInputStream.CopyToAsync(entryFileStream);
}
}
}
18 changes: 14 additions & 4 deletions Project-Aurora/Project-Aurora/Profiles/Payday 2/PD2Application.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
using AuroraRgb.Profiles.Payday_2.Layers;
using System.Threading.Tasks;
using AuroraRgb.Profiles.Payday_2.GSI;
using AuroraRgb.Profiles.Payday_2.Layers;
using AuroraRgb.Settings;

namespace AuroraRgb.Profiles.Payday_2;

public class PD2 : Application
public class PD2 : GsiApplication
{
public PD2()
: base(new LightEventConfig {
Name = "Payday 2",
ID = "pd2",
AppID= "218620",
ProcessNames = new[] { "payday2_win32_release.exe" },
ProcessNames = ["payday2_win32_release.exe"],
SettingsType = typeof(FirstTimeApplicationSettings),
ProfileType = typeof(PD2Profile),
OverviewControlType = typeof(Pd2),
GameStateType = typeof(GSI.GameState_PD2),
GameStateType = typeof(GameState_PD2),
IconURI = "Resources/pd2_64x64.png"
})
{
AllowLayer<PD2BackgroundLayerHandler>();
AllowLayer<PD2FlashbangLayerHandler>();
AllowLayer<PD2StatesLayerHandler>();
}

protected override async Task<bool> DoInstallGsi()
{
var errorMessage = await Pd2GsiUtils.InstallMod();
return errorMessage == null;
}
}
99 changes: 48 additions & 51 deletions Project-Aurora/Project-Aurora/Profiles/Payday 2/PD2Profile.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
using System.Drawing;
using AuroraRgb.Profiles.Payday_2.Layers;
using AuroraRgb.Settings;
using AuroraRgb.Settings.Layers;
using Common.Devices;

namespace AuroraRgb.Profiles.Payday_2
namespace AuroraRgb.Profiles.Payday_2;

public class PD2Profile : ApplicationProfile
{
public class PD2Profile : ApplicationProfile
public override void Reset()
{
public PD2Profile() : base()
{

}

public override void Reset()
{
base.Reset();
Layers = new System.Collections.ObjectModel.ObservableCollection<Layer>
base.Reset();
Layers =
[
new Layer("Payday 2 Flashbang", new PD2FlashbangLayerHandler()),
new Layer("Health Indicator", new PercentLayerHandler
{
new Layer("Payday 2 Flashbang", new Payday_2.Layers.PD2FlashbangLayerHandler()),
new Layer("Health Indicator", new PercentLayerHandler()
Properties = new PercentLayerHandlerProperties
{
Properties = new PercentLayerHandlerProperties()
{
_PrimaryColor = Color.FromArgb(0, 255, 0),
SecondaryColor = Color.FromArgb(255, 0, 0),
PercentType = PercentEffectType.Progressive_Gradual,
_Sequence = new KeySequence(new DeviceKeys[] {
DeviceKeys.F1, DeviceKeys.F2, DeviceKeys.F3, DeviceKeys.F4,
DeviceKeys.F5, DeviceKeys.F6, DeviceKeys.F7, DeviceKeys.F8,
DeviceKeys.F9, DeviceKeys.F10, DeviceKeys.F11, DeviceKeys.F12
}),
BlinkThreshold = 0.0,
BlinkDirection = false,
VariablePath = new VariablePath("LocalPlayer/Health/Current"),
MaxVariablePath = new VariablePath("LocalPlayer/Health/Max")
},
}),
new Layer("Ammo Indicator", new PercentLayerHandler()
_PrimaryColor = Color.FromArgb(0, 255, 0),
SecondaryColor = Color.FromArgb(255, 0, 0),
PercentType = PercentEffectType.Progressive_Gradual,
_Sequence = new KeySequence([
DeviceKeys.F1, DeviceKeys.F2, DeviceKeys.F3, DeviceKeys.F4,
DeviceKeys.F5, DeviceKeys.F6, DeviceKeys.F7, DeviceKeys.F8,
DeviceKeys.F9, DeviceKeys.F10, DeviceKeys.F11, DeviceKeys.F12
]),
BlinkThreshold = 0.0,
BlinkDirection = false,
VariablePath = new VariablePath("LocalPlayer/Health/Current"),
MaxVariablePath = new VariablePath("LocalPlayer/Health/Max")
},
}),

new Layer("Ammo Indicator", new PercentLayerHandler
{
Properties = new PercentLayerHandlerProperties
{
Properties = new PercentLayerHandlerProperties()
{
_PrimaryColor = Color.FromArgb(0, 0, 255),
SecondaryColor = Color.FromArgb(255, 0, 0),
PercentType = PercentEffectType.Progressive_Gradual,
_Sequence = new KeySequence(new DeviceKeys[] {
DeviceKeys.ONE, DeviceKeys.TWO, DeviceKeys.THREE, DeviceKeys.FOUR,
DeviceKeys.FIVE, DeviceKeys.SIX, DeviceKeys.SEVEN, DeviceKeys.EIGHT,
DeviceKeys.NINE, DeviceKeys.ZERO, DeviceKeys.MINUS, DeviceKeys.EQUALS
}),
BlinkThreshold = 0.0,
BlinkDirection = false,
VariablePath = new VariablePath("LocalPlayer/Weapons/SelectedWeapon/Current_Clip"),
MaxVariablePath = new VariablePath("LocalPlayer/Weapons/SelectedWeapon/Max_Clip")
},
}),
new Layer("Payday 2 States", new Payday_2.Layers.PD2StatesLayerHandler()),
new Layer("Payday 2 Background", new Payday_2.Layers.PD2BackgroundLayerHandler())
};
}
_PrimaryColor = Color.FromArgb(0, 0, 255),
SecondaryColor = Color.FromArgb(255, 0, 0),
PercentType = PercentEffectType.Progressive_Gradual,
_Sequence = new KeySequence([
DeviceKeys.ONE, DeviceKeys.TWO, DeviceKeys.THREE, DeviceKeys.FOUR,
DeviceKeys.FIVE, DeviceKeys.SIX, DeviceKeys.SEVEN, DeviceKeys.EIGHT,
DeviceKeys.NINE, DeviceKeys.ZERO, DeviceKeys.MINUS, DeviceKeys.EQUALS
]),
BlinkThreshold = 0.0,
BlinkDirection = false,
VariablePath = new VariablePath("LocalPlayer/Weapons/SelectedWeapon/Current_Clip"),
MaxVariablePath = new VariablePath("LocalPlayer/Weapons/SelectedWeapon/Max_Clip")
},
}),

new Layer("Payday 2 States", new PD2StatesLayerHandler()),
new Layer("Payday 2 Background", new PD2BackgroundLayerHandler())
];
}
}
}

0 comments on commit c52c008

Please sign in to comment.