Skip to content

Commit

Permalink
fix Payday 2 integration and mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Sep 5, 2024
1 parent a3bf442 commit cbd6a7c
Show file tree
Hide file tree
Showing 36 changed files with 776 additions and 926 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private set

public event EventHandler<JsonGameStateEventArgs>? NewJsonGameState;

/// <summary>
/// <summary>
/// A GameStateListener that listens for connections on http://127.0.0.1:port/
/// </summary>
/// <param name="port"></param>
Expand Down Expand Up @@ -128,7 +128,7 @@ private void ProcessContext(HttpListenerContext context)
}
catch (Exception e)
{
Global.logger.Error(e, "[NetworkListener] ReceiveGameState error:");
Global.logger.Error(e, "[NetworkListener] ReceiveGameState error on: {Path}", path);
Global.logger.Debug("JSON: {Json}", json);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MapNode
/// <summary>
/// Current gamemode
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<MapMode>))]
public MapMode Mode { get; set; } = MapMode.Undefined;

/// <summary>
Expand All @@ -23,7 +23,7 @@ public class MapNode
/// <summary>
/// Current phase of the map
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<MapPhase>))]
public MapPhase Phase { get; set; } = MapPhase.Undefined;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PlayerNode
/// <summary>
/// Player's team
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<PlayerTeam>))]
public PlayerTeam Team { get; set; }

/// <summary>
Expand All @@ -40,7 +40,7 @@ public class PlayerNode
/// <summary>
/// Player's current activity state
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<PlayerActivity>))]
public PlayerActivity Activity { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public class RoundNode
/// <summary>
/// Current round phase
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<RoundPhase>))]
public RoundPhase Phase { get; set; }

/// <summary>
/// Current bomb state
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<BombState>))]
public BombState Bomb { get; set; }

/// <summary>
/// Round winning team
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<RoundWinTeam>))]
public RoundWinTeam WinTeam { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class WeaponNode
/// <summary>
/// Weapon type
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public WeaponType Type { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter<WeaponTypeCs>))]
public WeaponTypeCs Type { get; set; }

/// <summary>
/// Curren amount of ammo in the clip
Expand All @@ -44,14 +44,14 @@ public class WeaponNode
/// <summary>
/// Weapon's state
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<WeaponState>))]
public WeaponState State { get; set; }
}

/// <summary>
/// Enum list for all types of weapons
/// </summary>
public enum WeaponType
public enum WeaponTypeCs
{
/// <summary>
/// Undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public WeaponNode ActiveWeapon

public Dictionary<string, WeaponNode> WeaponNodes => weaponNodes;

public bool HasPrimary => _weapons.Exists(w => w.Type is WeaponType.Rifle or WeaponType.MachineGun or WeaponType.SniperRifle or WeaponType.SubmachineGun or WeaponType.Shotgun);
public bool HasRifle => _weapons.Exists(w => w.Type == WeaponType.Rifle);
public bool HasMachineGun => _weapons.Exists(w => w.Type == WeaponType.MachineGun);
public bool HasShotgun => _weapons.Exists(w => w.Type == WeaponType.Shotgun);
public bool HasSniper => _weapons.Exists(w => w.Type == WeaponType.SniperRifle);
public bool HasKnife => _weapons.Exists(w => w.Type == WeaponType.Knife);
public bool HasPrimary => _weapons.Exists(w => w.Type is WeaponTypeCs.Rifle or WeaponTypeCs.MachineGun or WeaponTypeCs.SniperRifle or WeaponTypeCs.SubmachineGun or WeaponTypeCs.Shotgun);
public bool HasRifle => _weapons.Exists(w => w.Type == WeaponTypeCs.Rifle);
public bool HasMachineGun => _weapons.Exists(w => w.Type == WeaponTypeCs.MachineGun);
public bool HasShotgun => _weapons.Exists(w => w.Type == WeaponTypeCs.Shotgun);
public bool HasSniper => _weapons.Exists(w => w.Type == WeaponTypeCs.SniperRifle);
public bool HasKnife => _weapons.Exists(w => w.Type == WeaponTypeCs.Knife);
public bool HasTaser => _weapons.Exists(w => w.Name == WeaponTaser);
public bool HasSMG => _weapons.Exists(w => w.Type == WeaponType.SubmachineGun);
public bool HasPistol => _weapons.Exists(w => w.Type == WeaponType.Pistol);
public bool HasC4 => _weapons.Exists(w => w.Type == WeaponType.C4);
public bool HasGrenade => _weapons.Exists(w => w.Type == WeaponType.Grenade);
public bool HasSMG => _weapons.Exists(w => w.Type == WeaponTypeCs.SubmachineGun);
public bool HasPistol => _weapons.Exists(w => w.Type == WeaponTypeCs.Pistol);
public bool HasC4 => _weapons.Exists(w => w.Type == WeaponTypeCs.C4);
public bool HasGrenade => _weapons.Exists(w => w.Type == WeaponTypeCs.Grenade);
public bool HasHegrenade => _weapons.Exists(w => w.Name == WeaponHegrenade);
public bool HasFlashbang => _weapons.Exists(w => w.Name == WeaponFlashbang);
public bool HasSmoke => _weapons.Exists(w => w.Name == WeaponSmokegrenade);
public bool HasDecoy => _weapons.Exists(w => w.Name == WeaponDecoy);
public bool HasIncendiary => _weapons.Exists(w => w.Name == WeaponMolotov);
public int GrenadeCount => _weapons.Sum(w => w.Type == WeaponType.Grenade ? 1 : 0);
public int GrenadeCount => _weapons.Sum(w => w.Type == WeaponTypeCs.Grenade ? 1 : 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ public class Map_Dota2
/// <summary>
/// Current game state
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<DOTA_GameState>))]
public DOTA_GameState GameState { get; set; }

/// <summary>
/// The winning team
/// </summary>
[JsonPropertyName("win_team")]
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<DotaPlayerTeam>))]
public DotaPlayerTeam Win_team { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PlayerDota2
/// <summary>
/// Player's current activity state
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<DotaPlayerActivity>))]
public DotaPlayerActivity Activity { get; set; }

/// <summary>
Expand Down Expand Up @@ -81,7 +81,7 @@ public class PlayerDota2
/// Player's team
/// </summary>
[JsonPropertyName("team_name")]
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<DotaPlayerTeam>))]
public DotaPlayerTeam Team { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ProviderValve
/// <summary>
/// Game's version
/// </summary>
public int Version { get; set; }
public long Version { get; set; }

/// <summary>
/// Local player's Steam ID
Expand All @@ -35,5 +35,5 @@ public class ProviderValve
/// Current timestamp
/// </summary>
[JsonPropertyName("timestamp")]
public int TimeStamp { get; set; }
public long TimeStamp { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using AuroraRgb.Profiles.CSGO.GSI;
using AuroraRgb.Profiles.Discord.GSI;
using AuroraRgb.Profiles.Dota_2.GSI;
using AuroraRgb.Profiles.Payday_2.GSI;

namespace AuroraRgb.Profiles;

[JsonSerializable(typeof(GameStateCsgo))]
[JsonSerializable(typeof(GameStateDiscord))]
[JsonSerializable(typeof(GameStateDota2))]
[JsonSerializable(typeof(GameState_PD2))]
public partial class GameStateSourceGenerationContext : JsonSerializerContext;
39 changes: 28 additions & 11 deletions Project-Aurora/Project-Aurora/Profiles/Payday 2/Control_PD2.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
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 @@ -25,7 +26,7 @@ public Pd2(Application profile)

private void get_hook_button_Click(object? sender, RoutedEventArgs e)
{
Process.Start("explorer", @"http://paydaymods.com/download/");
Process.Start("explorer", @"https://superblt.znix.xyz/");
}

private void install_mod_button_Click(object? sender, RoutedEventArgs e)
Expand All @@ -50,14 +51,30 @@ private void install_mod_button_Click(object? sender, RoutedEventArgs e)
return;
}

using var gsiPd2Ms = new MemoryStream(Properties.Resources.PD2_GSI);
using (var zip = new ZipArchive(gsiPd2Ms))
//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)
{
foreach (var entry in zip.Entries)
{
entry.ExtractToFile(pd2Path, true);
}
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.");
}

Expand Down Expand Up @@ -93,8 +110,8 @@ private void preview_ammo_slider_ValueChanged(object? sender, RoutedPropertyChan
var ammoVal = (int)preview_ammo_slider.Value;
if (preview_ammo_amount is not Label) return;
preview_ammo_amount.Content = ammoVal + "%";
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.Weapons.SelectedWeapon.Current_Clip = ammoVal;
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.Weapons.SelectedWeapon.Max_Clip = 100;
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.SelectedWeapon.Current_Clip = ammoVal;
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.SelectedWeapon.Max_Clip = 100;
}

private void preview_suspicion_slider_ValueChanged(object? sender, RoutedPropertyChangedEventArgs<double> e)
Expand All @@ -116,7 +133,7 @@ private void preview_flashbang_slider_ValueChanged(object? sender, RoutedPropert
private void preview_swansong_Checked(object? sender, RoutedEventArgs e)
{
if (!IsLoaded || sender is not CheckBox { IsChecked: not null } checkBox) return;
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.IsSwanSong = checkBox.IsChecked.Value;
(_profileManager.Config.Event.GameState as GameState_PD2).Players.LocalPlayer.SwanSong = checkBox.IsChecked.Value;
}

private void get_lib_button_Click(object? sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit cbd6a7c

Please sign in to comment.