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

Add DirectSong support #465

Merged
merged 1 commit into from
Nov 5, 2023
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
16 changes: 16 additions & 0 deletions Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Daybreak._7ZipExtractor</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.34.1" />
</ItemGroup>

</Project>
42 changes: 42 additions & 0 deletions Daybreak.7ZipExtractor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Extractor is in a different executable because of memory limitations. Daybreak needs to be compiled for x86 and as such has a memory limit of 2GB.
* 7Zip algorithm may require more than 2GB memory to unpack large zip files.
* As such, Daybreak.7ZipExtractor is x64.
*/
using SharpCompress.Archives;

if (args.Length != 2)
{
return -1;
}

var archivePath = args[0];
var destinationDirectory = args[1];

using var fileStream = new FileStream(archivePath, FileMode.Open);
using var archive = ArchiveFactory.Open(fileStream);
var progress = 0d;
var count = archive.Entries.Count();
var reader = archive.ExtractAllEntries();
while (reader.MoveToNextEntry())
{
var entry = reader.Entry;
if (entry.IsDirectory)
{
var directoryName = Path.Combine(Path.GetFullPath(destinationDirectory), entry.Key);
Directory.CreateDirectory(directoryName);
continue;
}

var fileName = Path.Combine(Path.GetFullPath(destinationDirectory), entry.Key);
using var entryStream = new FileStream(fileName, FileMode.Create);
using (var stream = reader.OpenEntryStream())
{
stream.CopyTo(entryStream);
}

progress += 1d / count;
Console.WriteLine($"{progress} {fileName}");
}

return 0;
1 change: 0 additions & 1 deletion Daybreak.Tests/Services/JsonLoggerProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using NSubstitute.Extensions;
using System.Configuration;
using System.IO;
using System.Linq;
Expand Down
14 changes: 14 additions & 0 deletions Daybreak.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\CODEOWNERS = .github\CODEOWNERS
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daybreak.7ZipExtractor", "Daybreak.7ZipExtractor\Daybreak.7ZipExtractor.csproj", "{CA60F9AC-A496-4DB6-970E-ECE73B051C05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,6 +79,18 @@ Global
{4E2BB805-135D-4F02-8C53-3D8B6876D323}.Release|x64.Build.0 = Release|x64
{4E2BB805-135D-4F02-8C53-3D8B6876D323}.Release|x86.ActiveCfg = Release|x86
{4E2BB805-135D-4F02-8C53-3D8B6876D323}.Release|x86.Build.0 = Release|x86
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|x64.ActiveCfg = Debug|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|x64.Build.0 = Debug|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|x86.ActiveCfg = Debug|x64
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Debug|x86.Build.0 = Debug|x64
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|Any CPU.Build.0 = Release|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|x64.ActiveCfg = Release|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|x64.Build.0 = Release|Any CPU
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|x86.ActiveCfg = Release|x64
{CA60F9AC-A496-4DB6-970E-ECE73B051C05}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions Daybreak/Configuration/Options/DirectSongOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Daybreak.Attributes;
using Newtonsoft.Json;

namespace Daybreak.Configuration.Options;

[OptionsName(Name = "DirectSong")]
public sealed class DirectSongOptions
{
[JsonProperty(nameof(Path))]
[OptionName(Name = "Path", Description = "Folder that contains the DirectSong files")]
public string Path { get; set; } = string.Empty;

[JsonProperty(nameof(Enabled))]
[OptionName(Name = "Enabled", Description = "If true, Daybreak will setup DirectSong when launching Guild Wars")]
public bool Enabled { get; set; } = false;
}
11 changes: 11 additions & 0 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
using Daybreak.Services.ExecutableManagement;
using Daybreak.Views.Launch;
using Daybreak.Services.GWCA;
using Daybreak.Services.DirectSong;
using Daybreak.Views.Onboarding.DirectSong;
using System.Xml.Linq;
using Daybreak.Services.SevenZip;

namespace Daybreak.Configuration;

Expand Down Expand Up @@ -210,6 +214,7 @@ public override void RegisterServices(IServiceCollection services)
services.AddSingleton<IGuildWarsExecutableManager, GuildWarsExecutableManager>();
services.AddSingleton<IGWCAClient, GWCAClient>();
services.AddSingleton<IGuildwarsMemoryReader, GWCAMemoryReader>();
services.AddSingleton<ISevenZipExtractor, SevenZipExtractor>();
services.AddScoped<ICredentialManager, CredentialManager>();
services.AddScoped<IApplicationLauncher, ApplicationLauncher>();
services.AddScoped<IScreenshotProvider, ScreenshotProvider>();
Expand Down Expand Up @@ -306,6 +311,10 @@ public override void RegisterViews(IViewProducer viewProducer)
viewProducer.RegisterView<ReShadePresetView>();
viewProducer.RegisterView<LaunchConfigurationView>();
viewProducer.RegisterView<LaunchConfigurationsView>();
viewProducer.RegisterView<DirectSongInstallationView>();
viewProducer.RegisterView<DirectSongInstallationChoiceView>();
viewProducer.RegisterView<DirectSongOnboardingEntryView>();
viewProducer.RegisterView<DirectSongSwitchView>();
}

public override void RegisterStartupActions(IStartupActionProducer startupActionProducer)
Expand Down Expand Up @@ -406,6 +415,7 @@ public override void RegisterOptions(IOptionsProducer optionsProducer)
optionsProducer.RegisterOptions<GuildwarsExecutableOptions>();
optionsProducer.RegisterOptions<CredentialManagerOptions>();
optionsProducer.RegisterOptions<LaunchConfigurationServiceOptions>();
optionsProducer.RegisterOptions<DirectSongOptions>();
}

public override void RegisterNotificationHandlers(INotificationHandlerProducer notificationHandlerProducer)
Expand All @@ -425,6 +435,7 @@ public override void RegisterMods(IModsManager modsManager)
modsManager.RegisterMod<IGuildwarsScreenPlacer, GuildwarsScreenPlacer>();
modsManager.RegisterMod<IReShadeService, ReShadeService>();
modsManager.RegisterMod<IGWCAInjector, GWCAInjector>();
modsManager.RegisterMod<IDirectSongService, DirectSongService>(singleton: true);
}

private void RegisterLiteCollections(IServiceCollection services)
Expand Down
7 changes: 7 additions & 0 deletions Daybreak/Controls/MenuList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@
Cursor="Hand"
Clicked="ReShadeButton_Clicked"
ToolTip="Open ReShade manager"/>
<buttons:MenuButton Title="DirectSong"
Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}"
HighlightColor="{DynamicResource MahApps.Brushes.Accent}"
Height="30"
Cursor="Hand"
Clicked="DirectSongButton_Clicked"
ToolTip="Open DirectSong manager"/>
</local:ExpandableMenuSection.Children>
</local:ExpandableMenuSection>
<local:ExpandableMenuSection
Expand Down
6 changes: 6 additions & 0 deletions Daybreak/Controls/MenuList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Daybreak.Views;
using Daybreak.Views.Copy;
using Daybreak.Views.Launch;
using Daybreak.Views.Onboarding.DirectSong;
using Daybreak.Views.Onboarding.DSOAL;
using Daybreak.Views.Onboarding.ReShade;
using Daybreak.Views.Onboarding.Toolbox;
Expand Down Expand Up @@ -127,6 +128,11 @@ private void ReShadeButton_Clicked(object sender, EventArgs e)
this.viewManager.ShowView<ReShadeOnboardingEntryView>();
}

private void DirectSongButton_Clicked(object sender, EventArgs e)
{
this.viewManager.ShowView<DirectSongOnboardingEntryView>();
}

private void KamadanButton_Clicked(object sender, EventArgs e)
{
this.viewManager.ShowView<KamadanTradeChatView>();
Expand Down
12 changes: 6 additions & 6 deletions Daybreak/Controls/SnowfallOverlay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Storyboard.TargetProperty="Time"
From="0"
To="200"
Duration="4:0:0"
Duration="0:30:0"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
Expand All @@ -38,8 +38,8 @@
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform1" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" />
<TranslateTransform x:Name="SnowfallTransform1" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
Expand All @@ -53,8 +53,8 @@
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform2" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" />
<TranslateTransform x:Name="SnowfallTransform2" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
Expand All @@ -68,8 +68,8 @@
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform3" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" />
<TranslateTransform x:Name="SnowfallTransform3" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
Expand All @@ -83,8 +83,8 @@
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform4" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" />
<TranslateTransform x:Name="SnowfallTransform4" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
Expand All @@ -98,8 +98,8 @@
Viewport="0, 0, 100, 100">
<ImageBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform x:Name="SnowfallTransform5" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" />
<TranslateTransform x:Name="SnowfallTransform5" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" />
</TransformGroup>
</ImageBrush.RelativeTransform>
</ImageBrush>
Expand Down
15 changes: 6 additions & 9 deletions Daybreak/Controls/SnowfallOverlay.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Extensions;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Daybreak.Controls;
Expand All @@ -16,7 +13,7 @@ namespace Daybreak.Controls;
/// </summary>
public partial class SnowfallOverlay : UserControl
{
private static readonly double[] Frequencies = new double[] { 0.5, 0.1, 5, 1 };
private static readonly double[] Frequencies = new double[] { 0.1, 0.025, 1, 0.25 };
private static readonly double[] Amplitudes = new double[] { 1, 0.1, 0.1, 0.2 };
private static readonly double Divisor = Amplitudes.Sum();

Expand Down Expand Up @@ -85,11 +82,11 @@ private async void SimulateWind(CancellationToken cancellationToken)
while (!cancellationToken.IsCancellationRequested)
{
var time = this.Time;
this.SnowfallTransform1.X += this.BaseWind1 + this.GetNoise(time) * this.WindStrength1;
this.SnowfallTransform2.X += this.BaseWind2 + this.GetNoise(time - 0.02) * this.WindStrength2;
this.SnowfallTransform3.X += this.BaseWind3 + this.GetNoise(time - 0.03) * this.WindStrength3;
this.SnowfallTransform4.X += this.BaseWind4 + this.GetNoise(time - 0.05) * this.WindStrength4;
this.SnowfallTransform5.X += this.BaseWind5 + this.GetNoise(time - 0.08) * this.WindStrength5;
this.SnowfallTransform1.X += (this.BaseWind1 + (this.GetNoise(time) * this.WindStrength1)) / this.FlakeSize1;
this.SnowfallTransform2.X += (this.BaseWind2 + (this.GetNoise(time - 0.02) * this.WindStrength2)) / this.FlakeSize2;
this.SnowfallTransform3.X += (this.BaseWind3 + (this.GetNoise(time - 0.03) * this.WindStrength3)) / this.FlakeSize3;
this.SnowfallTransform4.X += (this.BaseWind4 + (this.GetNoise(time - 0.05) * this.WindStrength4)) / this.FlakeSize4;
this.SnowfallTransform5.X += (this.BaseWind5 + (this.GetNoise(time - 0.08) * this.WindStrength5)) / this.FlakeSize5;
await Task.Delay(16, cancellationToken).ConfigureAwait(true);
}
}
Expand Down
6 changes: 5 additions & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.8.137</Version>
<Version>0.9.8.138</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down Expand Up @@ -123,6 +123,10 @@
<Folder Include="GWCA\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Daybreak.7ZipExtractor\Daybreak.7ZipExtractor.csproj" />
</ItemGroup>


<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="echo.&gt;$(Version).version" />
Expand Down
20 changes: 10 additions & 10 deletions Daybreak/Launch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@
<controls:SnowfallOverlay
Visibility="{Binding ElementName=_this, Path=WintersdayMode, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
Opacity="0.4"
BaseWind1="0.000074"
BaseWind2="0.000087"
BaseWind3="0.000073"
BaseWind4="0.000065"
BaseWind5="0.000062"
WindStrength1="0.0005"
WindStrength2="0.001"
WindStrength3="0.0008"
WindStrength4="0.0007"
WindStrength5="0.0006"
BaseWind1="0.00247"
BaseWind2="0.000427"
BaseWind3="0.000443"
BaseWind4="0.000405"
BaseWind5="0.000362"
WindStrength1="0.06"
WindStrength2="0.01"
WindStrength3="0.0096"
WindStrength4="0.0098"
WindStrength5="0.009"
FlakeSize1="14"
FlakeSize2="6"
FlakeSize3="4.6"
Expand Down
30 changes: 30 additions & 0 deletions Daybreak/Models/Progress/DirectSongInstallationStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

namespace Daybreak.Models.Progress;
public sealed class DirectSongInstallationStatus : DownloadStatus
{
public static readonly LoadStatus StartingStep = new DirectSongInstallationStep("Starting");
public static readonly LoadStatus ExtractingFiles = new DirectSongInstallationStep("Extracting files");
public static readonly LoadStatus Finished = new DirectSongInstallationStep("Installation has finished");
public static readonly LoadStatus SetupRegistry = new DirectSongInstallationStep("Setting up registry entries");
public static LoadStatus Extracting(double progress) => new DirectSongInstallationProgressStep("Extracting DirectSong archive", progress);

public DirectSongInstallationStatus()
{
this.CurrentStep = StartingStep;
}

public sealed class DirectSongInstallationStep : LoadStatus
{
internal DirectSongInstallationStep(string name) : base(name)
{
}
}

public sealed class DirectSongInstallationProgressStep : LoadStatus
{
internal DirectSongInstallationProgressStep(string name, double progress) : base(name)
{
this.Progress = progress;
}
}
}
Loading
Loading