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

Added BetterDiscord support with a plugin #1708

Merged
merged 16 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl x:Class="Aurora.Profiles.Discord.Control_Discord"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Aurora.Profiles.Discord"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="850" Height="Auto" Width="Auto">
<Grid>
<TabControl>
<TabItem Header="Overview for BetterDiscord">
<StackPanel Margin="10">
<CheckBox x:Name="GameEnabled" Content="Enable Aurora to provide lighting effects with BetterDiscord. Ensure you have read the below text." Checked="GameEnabled_Checked" Unchecked="GameEnabled_Checked" />
<TextBlock HorizontalAlignment="Left" Margin="0,10" TextWrapping="Wrap" MaxWidth="824">
<Run Text="Support for BetterDiscord requires a plugin so that Aurora is able to fetch the variables from the client." />
</TextBlock>
<Button x:Name="patchButton" Content="Install BD Plugin" HorizontalAlignment="Left" Width="132" Margin="0,0,0,0" Click="PatchButton_Click"/>
<Button x:Name="unpatchButton" Content="Uninstall BD Plugin" HorizontalAlignment="Left" VerticalAlignment="Top" Width="132" Margin="0,10,0,0" Click="UnpatchButton_Click"/>
</StackPanel>
</TabItem>
</TabControl>
</Grid>
</UserControl>
105 changes: 105 additions & 0 deletions Project-Aurora/Project-Aurora/Profiles/Discord/Control_Discord.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Aurora.Profiles.Discord.GSI;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;

using System.IO;

namespace Aurora.Profiles.Discord
{
/// <summary>
/// Interaction logic for Control_Minecraft.xaml
/// </summary>
public partial class Control_Discord : UserControl {

private Application profile;

public Control_Discord(Application profile) {
this.profile = profile;

InitializeComponent();
SetSettings();


profile.ProfileChanged += (sender, e) => SetSettings();
}

private void SetSettings() {
GameEnabled.IsChecked = profile.Settings.IsEnabled;
}

private void GameEnabled_Checked(object sender, RoutedEventArgs e) {
if (IsLoaded) {
profile.Settings.IsEnabled = GameEnabled.IsChecked ?? false;
profile.SaveProfiles();
}
}

private void PatchButton_Click(object sender, RoutedEventArgs e)
{
InstallPlugin();
}

private void UnpatchButton_Click(object sender, RoutedEventArgs e)
{
UninstallPlugin();
}

private void InstallPlugin()
{
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string pluginDirectory = Path.Combine(appdata, "BetterDiscord", "plugins");

if (!Directory.Exists(pluginDirectory))
Directory.CreateDirectory(pluginDirectory);

string pluginFile = Path.Combine(pluginDirectory, "AuroraGSI.plugin.js");
if (File.Exists(pluginFile))
{
MessageBox.Show("Plugin already installed");
return;
}

try
{
using (FileStream pluginStream = File.Create(pluginFile))
{
pluginStream.Write(Properties.Resources.DiscordGSIPlugin, 0, Properties.Resources.DiscordGSIPlugin.Length);
}
MessageBox.Show("Plugin installed successfully");
}
catch (Exception e)
{
MessageBox.Show("Error installng plugin: " + e.Message);
}
}

private void UninstallPlugin()
{
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(appdata, "BetterDiscord", "plugins", "AuroraGSI.plugin.js");

if (File.Exists(path))
{
File.Delete(path);
MessageBox.Show("Plugin uninstalled successfully");
return;
}
else
{
MessageBox.Show("Plugin not found.");
return;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Aurora.Profiles.Minecraft.Layers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord
{

public class Discord : Application {

public Discord() : base(new LightEventConfig
{
Name = "Discord",
ID = "discord",
ProcessNames = new[] { "Discord.exe", "DiscordPTB.exe", "DiscordCanary.exe" },
ProfileType = typeof(DiscordProfile),
OverviewControlType = typeof(Control_Discord),
GameStateType = typeof(GSI.GameState_Discord),
Event = new GameEvent_Generic(),
IconURI = "Resources/betterdiscord.png",
EnableByDefault = false
}) { }
}
}
67 changes: 67 additions & 0 deletions Project-Aurora/Project-Aurora/Profiles/Discord/DiscordProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Aurora.Devices;
using Aurora.EffectsEngine.Animations;
using Aurora.Profiles.Minecraft.Layers;
using Aurora.Settings;
using Aurora.Settings.Layers;
using Aurora.Settings.Overrides;
using Aurora.Settings.Overrides.Logic;
using Aurora.Settings.Overrides.Logic.Builder;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aurora.Profiles.Discord {

public class DiscordProfile : ApplicationProfile {

public DiscordProfile() : base() { }

public override void Reset() {
base.Reset();

OverlayLayers = new System.Collections.ObjectModel.ObservableCollection<Layer>()
{
new Layer("Mic Mute", new SolidColorLayerHandler()
{
Properties = new LayerHandlerProperties()
{
_PrimaryColor = Color.Red,
_Sequence = new KeySequence(new DeviceKeys[] { DeviceKeys.F1, DeviceKeys.F2, DeviceKeys.F3, DeviceKeys.F4 })
}
}, new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanGSIBoolean("User/SelfMute"))),

new Layer("Deafen", new SolidColorLayerHandler()
{
Properties = new LayerHandlerProperties()
{
_PrimaryColor = Color.LimeGreen,
_Sequence = new KeySequence(new DeviceKeys[] { DeviceKeys.F5, DeviceKeys.F6, DeviceKeys.F7, DeviceKeys.F8 })
}
}, new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanGSIBoolean("User/SelfDeafen"))),

new Layer("Mentions", new SolidColorLayerHandler()
{
Properties = new LayerHandlerProperties()
{
_PrimaryColor = Color.Yellow,
_Sequence = new KeySequence(new DeviceKeys[] { DeviceKeys.F9, DeviceKeys.F10, DeviceKeys.F11, DeviceKeys.F12 })
}
}, new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanGSIBoolean("User/Mentions"))),

new Layer("Unread Messages", new SolidColorLayerHandler()
{
Properties = new LayerHandlerProperties()
{
_PrimaryColor = Color.LightBlue,
_Sequence = new KeySequence(new DeviceKeys[] { DeviceKeys.PRINT_SCREEN, DeviceKeys.SCROLL_LOCK, DeviceKeys.PAUSE_BREAK })
}
}, new OverrideLogicBuilder().SetDynamicBoolean("_Enabled", new BooleanGSIBoolean("User/UnreadMessages"))),


};
}
}
}
Loading