Browse Source

Steamworks API

Krzysztof Krysiński 2 years ago
parent
commit
69ed094a18

+ 0 - 2
src/PixiEditor.Platform.MSStore/MicrosoftStorePlatform.cs

@@ -8,6 +8,4 @@ public sealed class MicrosoftStorePlatform : IPlatform
     }
     }
 
 
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new MSAdditionalContentProvider();
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new MSAdditionalContentProvider();
-
-    public static IPlatform Current { get; } = new MicrosoftStorePlatform();
 }
 }

+ 0 - 2
src/PixiEditor.Platform.Standalone/StandalonePlatform.cs

@@ -8,6 +8,4 @@ public sealed class StandalonePlatform : IPlatform
     }
     }
 
 
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new StandaloneAdditionalContentProvider();
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new StandaloneAdditionalContentProvider();
-
-    public static IPlatform Current { get; } = new StandalonePlatform();
 }
 }

+ 25 - 0
src/PixiEditor.Platform.Steam/PixiEditor.Platform.Steam.csproj

@@ -10,4 +10,29 @@
       <ProjectReference Include="..\PixiEditor.Platform\PixiEditor.Platform.csproj" />
       <ProjectReference Include="..\PixiEditor.Platform\PixiEditor.Platform.csproj" />
     </ItemGroup>
     </ItemGroup>
 
 
+    <ItemGroup>
+      <PackageReference Include="Steamworks.NET" Version="20.1.0" />
+    </ItemGroup>
+
+  <ItemGroup Condition="'$(Platform)' == 'x86'">
+    <None Update="steam_api.dll">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Platform)' == 'AnyCPU'">
+    <None Update="steam_api.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Update="steam_api64.dll">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Platform)' == 'x64'">
+    <None Update="steam_api64.dll">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
 </Project>
 </Project>

+ 12 - 2
src/PixiEditor.Platform.Steam/SteamAdditionalContentProvider.cs

@@ -1,9 +1,19 @@
-namespace PixiEditor.Platform.Steam;
+using Steamworks;
+
+namespace PixiEditor.Platform.Steam;
 
 
 public sealed class SteamAdditionalContentProvider : IAdditionalContentProvider
 public sealed class SteamAdditionalContentProvider : IAdditionalContentProvider
 {
 {
+    private Dictionary<AdditionalContentProduct, AppId_t> productIds = new()
+    {
+        { AdditionalContentProduct.SupporterPack, new AppId_t(2435860) }
+    };
+
     public bool IsContentAvailable(AdditionalContentProduct product)
     public bool IsContentAvailable(AdditionalContentProduct product)
     {
     {
-        return true;
+        if(!productIds.ContainsKey(product)) return false;
+
+        AppId_t appId = productIds[product];
+        return SteamApps.BIsDlcInstalled(appId);
     }
     }
 }
 }

+ 12 - 4
src/PixiEditor.Platform.Steam/SteamPlatform.cs

@@ -1,13 +1,21 @@
-namespace PixiEditor.Platform.Steam;
+using Steamworks;
+
+namespace PixiEditor.Platform.Steam;
 
 
 public class SteamPlatform : IPlatform
 public class SteamPlatform : IPlatform
 {
 {
     public bool PerformHandshake()
     public bool PerformHandshake()
     {
     {
-        return true;
+        try
+        {
+            SteamAPI.Init();
+            return true;
+        }
+        catch
+        {
+            return false;
+        }
     }
     }
 
 
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new SteamAdditionalContentProvider();
     public IAdditionalContentProvider? AdditionalContentProvider { get; } = new SteamAdditionalContentProvider();
-
-    public static IPlatform Current { get; } = new SteamPlatform();
 }
 }

BIN
src/PixiEditor.Platform.Steam/steam_api.dll


BIN
src/PixiEditor.Platform.Steam/steam_api64.dll


+ 11 - 1
src/PixiEditor.Platform/IPlatform.cs

@@ -2,7 +2,17 @@
 
 
 public interface IPlatform
 public interface IPlatform
 {
 {
-    public static IPlatform Current { get; }
+    public static IPlatform Current { get; private set; }
     public bool PerformHandshake();
     public bool PerformHandshake();
     public IAdditionalContentProvider? AdditionalContentProvider { get; }
     public IAdditionalContentProvider? AdditionalContentProvider { get; }
+
+    public static void RegisterPlatform(IPlatform platform)
+    {
+        if (Current != null)
+        {
+            throw new InvalidOperationException("Platform already initialized.");
+        }
+
+        Current = platform;
+    }
 }
 }

+ 3 - 2
src/PixiEditor.Platform/PlatformServiceCollection.cs

@@ -1,4 +1,5 @@
-using Microsoft.Extensions.DependencyInjection;
+using System.Reflection;
+using Microsoft.Extensions.DependencyInjection;
 
 
 namespace PixiEditor.Platform;
 namespace PixiEditor.Platform;
 
 
@@ -6,7 +7,7 @@ public static class PlatformServiceCollection
 {
 {
     public static IServiceCollection AddPlatform(this IServiceCollection services)
     public static IServiceCollection AddPlatform(this IServiceCollection services)
     {
     {
-        if (IPlatform.Current == null)
+        if(IPlatform.Current == null)
             throw new InvalidOperationException("No platform was found");
             throw new InvalidOperationException("No platform was found");
 
 
         services.AddSingleton(IPlatform.Current);
         services.AddSingleton(IPlatform.Current);

+ 25 - 24
src/PixiEditor/PixiEditor.csproj

@@ -146,30 +146,6 @@
 	  <Optimize>True</Optimize>
 	  <Optimize>True</Optimize>
 	</PropertyGroup>
 	</PropertyGroup>
   
   
-  <ItemGroup Condition="'$(Configuration)' == 'DevRelease'">
-    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
-  </ItemGroup>
-
-  <ItemGroup Condition="'$(Configuration)' == 'Debug'">
-    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
-  </ItemGroup>
-
-  <ItemGroup Condition="'$(Configuration)' == 'Release'">
-    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
-  </ItemGroup>
-  
-  <ItemGroup Condition="'$(Configuration)' == 'Steam'">
-    <ProjectReference Include="..\PixiEditor.Platform.Steam\PixiEditor.Platform.Steam.csproj" />
-  </ItemGroup>
-  
-  <ItemGroup Condition="'$(Configuration)' == 'MSIX Debug'">
-    <ProjectReference Include="..\PixiEditor.Platform.MSStore\PixiEditor.Platform.MSStore.csproj" />
-  </ItemGroup>
-
-  <ItemGroup Condition="'$(Configuration)' == 'MSIX'">
-    <ProjectReference Include="..\PixiEditor.Platform.MSStore\PixiEditor.Platform.MSStore.csproj" />
-  </ItemGroup>
-  
 	<ItemGroup>
 	<ItemGroup>
 		<Compile Remove="Styles\AvalonDock\Images\**" />
 		<Compile Remove="Styles\AvalonDock\Images\**" />
 		<EmbeddedResource Remove="Styles\AvalonDock\Images\**" />
 		<EmbeddedResource Remove="Styles\AvalonDock\Images\**" />
@@ -479,6 +455,31 @@
 			<HintPath>..\..\PixiParser\src\PixiParser.Skia\bin\Debug\net5.0\PixiParser.Skia.dll</HintPath>
 			<HintPath>..\..\PixiParser\src\PixiParser.Skia\bin\Debug\net5.0\PixiParser.Skia.dll</HintPath>
 		</Reference>
 		</Reference>
 	</ItemGroup>
 	</ItemGroup>
+
+  <ItemGroup Condition="'$(Configuration)' == 'DevRelease'">
+    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Configuration)' == 'Release'">
+    <ProjectReference Include="..\PixiEditor.Platform.Standalone\PixiEditor.Platform.Standalone.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Configuration)' == 'Steam'">
+    <ProjectReference Include="..\PixiEditor.Platform.Steam\PixiEditor.Platform.Steam.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Configuration)' == 'MSIX Debug'">
+    <ProjectReference Include="..\PixiEditor.Platform.MSStore\PixiEditor.Platform.MSStore.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(Configuration)' == 'MSIX'">
+    <ProjectReference Include="..\PixiEditor.Platform.MSStore\PixiEditor.Platform.MSStore.csproj" />
+  </ItemGroup>
+  
 	<ItemGroup>
 	<ItemGroup>
 		<Compile Update="Properties\Settings.Designer.cs">
 		<Compile Update="Properties\Settings.Designer.cs">
 			<DesignTimeSharedInput>True</DesignTimeSharedInput>
 			<DesignTimeSharedInput>True</DesignTimeSharedInput>

+ 18 - 1
src/PixiEditor/Views/MainWindow.xaml.cs

@@ -1,4 +1,5 @@
 using System.ComponentModel;
 using System.ComponentModel;
+using System.Reflection;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Input;
@@ -21,7 +22,7 @@ internal partial class MainWindow : Window
     private static WriteableBitmap pixiEditorLogo;
     private static WriteableBitmap pixiEditorLogo;
 
 
     private readonly IPreferences preferences;
     private readonly IPreferences preferences;
-
+    private readonly IPlatform platform;
     private readonly IServiceProvider services;
     private readonly IServiceProvider services;
 
 
     public static MainWindow Current { get; private set; }
     public static MainWindow Current { get; private set; }
@@ -34,6 +35,8 @@ internal partial class MainWindow : Window
     {
     {
         Current = this;
         Current = this;
 
 
+        IPlatform.RegisterPlatform(GetActivePlatform());
+
         services = new ServiceCollection()
         services = new ServiceCollection()
             .AddPlatform()
             .AddPlatform()
             .AddPixiEditor()
             .AddPixiEditor()
@@ -43,7 +46,10 @@ internal partial class MainWindow : Window
         DrawingBackendApi.SetupBackend(skiaDrawingBackend);
         DrawingBackendApi.SetupBackend(skiaDrawingBackend);
 
 
         preferences = services.GetRequiredService<IPreferences>();
         preferences = services.GetRequiredService<IPreferences>();
+        platform = services.GetRequiredService<IPlatform>();
         DataContext = services.GetRequiredService<ViewModelMain>();
         DataContext = services.GetRequiredService<ViewModelMain>();
+
+        platform.PerformHandshake();
         DataContext.Setup(services);
         DataContext.Setup(services);
 
 
         InitializeComponent();
         InitializeComponent();
@@ -66,6 +72,17 @@ internal partial class MainWindow : Window
         DataContext.DocumentManagerSubViewModel.ActiveDocumentChanged += DocumentChanged;
         DataContext.DocumentManagerSubViewModel.ActiveDocumentChanged += DocumentChanged;
     }
     }
 
 
+    private IPlatform GetActivePlatform()
+    {
+#if STEAM
+        return new PixiEditor.Platform.Steam.SteamPlatform();
+#elif MSIX || MSIX_DEBUG
+        return new PixiEditor.Platform.MSStore.MicrosoftStorePlatform();
+#else
+        return new PixiEditor.Platform.Standalone.StandalonePlatform();
+#endif
+    }
+
     private void MainWindow_ContentRendered(object sender, EventArgs e)
     private void MainWindow_ContentRendered(object sender, EventArgs e)
     {
     {
         GlobalMouseHook.Instance.Initilize(this);
         GlobalMouseHook.Instance.Initilize(this);