2023-04-08 00:09:00 +00:00
using LANCommander.PlaynitePlugin.Extensions ;
2023-03-30 01:49:31 +00:00
using LANCommander.PlaynitePlugin.Services ;
2023-01-07 18:34:12 +00:00
using Playnite.SDK ;
2023-01-26 03:08:05 +00:00
using Playnite.SDK.Events ;
2023-01-05 01:23:32 +00:00
using Playnite.SDK.Models ;
using Playnite.SDK.Plugins ;
using System ;
using System.Collections.Generic ;
2023-01-17 05:45:46 +00:00
using System.Collections.ObjectModel ;
2023-01-07 18:34:12 +00:00
using System.IO ;
2023-01-05 01:23:32 +00:00
using System.Linq ;
2023-10-28 18:56:54 +00:00
using System.Web ;
2023-01-15 19:33:04 +00:00
using System.Windows ;
2023-01-05 01:23:32 +00:00
using System.Windows.Controls ;
2023-01-20 02:02:34 +00:00
using System.Windows.Media ;
2023-01-07 18:34:12 +00:00
using PN = Playnite ;
2023-01-05 01:23:32 +00:00
2023-01-08 18:09:57 +00:00
namespace LANCommander.PlaynitePlugin
2023-01-05 01:23:32 +00:00
{
2023-01-14 21:15:31 +00:00
public class LANCommanderLibraryPlugin : LibraryPlugin
2023-01-05 01:23:32 +00:00
{
public static readonly ILogger Logger = LogManager . GetLogger ( ) ;
2023-01-14 21:16:13 +00:00
internal LANCommanderSettingsViewModel Settings { get ; set ; }
2023-01-05 07:07:17 +00:00
internal LANCommanderClient LANCommander { get ; set ; }
2023-01-15 10:56:56 +00:00
internal PowerShellRuntime PowerShellRuntime { get ; set ; }
2023-03-30 01:49:31 +00:00
internal GameSaveService GameSaveService { get ; set ; }
2023-01-05 01:23:32 +00:00
public override Guid Id { get ; } = Guid . Parse ( "48e1bac7-e0a0-45d7-ba83-36f5e9e959fc" ) ;
public override string Name = > "LANCommander" ;
2023-03-20 23:37:12 +00:00
internal Dictionary < Guid , string > DownloadCache = new Dictionary < Guid , string > ( ) ;
2023-01-14 21:15:31 +00:00
public LANCommanderLibraryPlugin ( IPlayniteAPI api ) : base ( api )
2023-01-05 01:23:32 +00:00
{
Properties = new LibraryPluginProperties
{
HasSettings = true ,
} ;
2023-01-07 18:34:12 +00:00
2023-01-14 21:16:13 +00:00
Settings = new LANCommanderSettingsViewModel ( this ) ;
2023-01-26 03:08:05 +00:00
2023-01-12 02:48:39 +00:00
LANCommander = new LANCommanderClient ( Settings . ServerAddress ) ;
LANCommander . Token = new SDK . Models . AuthToken ( )
{
AccessToken = Settings . AccessToken ,
RefreshToken = Settings . RefreshToken ,
} ;
2023-01-15 10:56:56 +00:00
PowerShellRuntime = new PowerShellRuntime ( ) ;
2023-03-30 01:49:31 +00:00
GameSaveService = new GameSaveService ( LANCommander , PlayniteApi , PowerShellRuntime ) ;
2023-09-03 20:55:04 +00:00
api . UriHandler . RegisterSource ( "lancommander" , args = >
{
if ( args . Arguments . Length = = 0 )
return ;
Guid gameId ;
switch ( args . Arguments [ 0 ] . ToLower ( ) )
{
case "install" :
if ( args . Arguments . Length = = 1 )
break ;
if ( Guid . TryParse ( args . Arguments [ 1 ] , out gameId ) )
PlayniteApi . InstallGame ( gameId ) ;
break ;
case "run" :
if ( args . Arguments . Length = = 1 )
break ;
if ( Guid . TryParse ( args . Arguments [ 1 ] , out gameId ) )
PlayniteApi . StartGame ( gameId ) ;
break ;
2023-10-28 18:56:54 +00:00
case "connect" :
if ( args . Arguments . Length = = 1 )
{
ShowAuthenticationWindow ( ) ;
break ;
}
ShowAuthenticationWindow ( HttpUtility . UrlDecode ( args . Arguments [ 1 ] ) ) ;
break ;
2023-09-03 20:55:04 +00:00
}
} ) ;
2023-01-05 01:23:32 +00:00
}
2023-03-17 07:07:25 +00:00
public bool ValidateConnection ( )
{
return LANCommander . ValidateToken ( LANCommander . Token ) ;
}
2023-01-05 01:23:32 +00:00
public override IEnumerable < GameMetadata > GetGames ( LibraryGetGamesArgs args )
{
2023-01-07 20:32:52 +00:00
var gameMetadata = new List < GameMetadata > ( ) ;
2023-09-15 22:36:45 +00:00
if ( ! ValidateConnection ( ) )
2023-01-15 20:18:26 +00:00
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Authentication invalid, showing auth window..." ) ;
2023-03-17 07:07:25 +00:00
ShowAuthenticationWindow ( ) ;
2023-09-15 22:36:45 +00:00
if ( ! ValidateConnection ( ) )
{
Logger . Trace ( "User cancelled authentication." ) ;
throw new Exception ( "You must set up a valid connection to a LANCommander server." ) ;
}
2023-01-15 20:18:26 +00:00
}
2023-04-02 03:37:54 +00:00
var games = LANCommander
. GetGames ( )
2023-11-02 06:24:42 +00:00
. Where ( g = > g ! = null & & g . Archives ! = null & & g . Archives . Count ( ) > 0 ) ;
2023-04-02 03:37:54 +00:00
foreach ( var game in games )
{
try
2023-01-07 20:32:52 +00:00
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( $"Importing/updating metadata for game \" { game . Title } \ "..." ) ;
2023-01-14 21:09:45 +00:00
var manifest = LANCommander . GetGameManifest ( game . Id ) ;
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Successfully grabbed game manifest" ) ;
2023-01-07 20:32:52 +00:00
var existingGame = PlayniteApi . Database . Games . FirstOrDefault ( g = > g . GameId = = game . Id . ToString ( ) & & g . PluginId = = Id & & g . IsInstalled ) ;
2023-01-17 05:49:07 +00:00
if ( existingGame ! = null )
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Game already exists in library, updating metadata..." ) ;
2023-01-17 05:49:07 +00:00
UpdateGame ( manifest , game . Id ) ;
continue ;
}
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Game does not exist in the library, importing metadata..." ) ;
2023-01-07 20:32:52 +00:00
var metadata = new GameMetadata ( )
2023-01-06 08:39:00 +00:00
{
2023-01-16 17:32:47 +00:00
IsInstalled = false ,
2023-01-14 21:09:45 +00:00
Name = manifest . Title ,
SortingName = manifest . SortTitle ,
Description = manifest . Description ,
2023-01-07 20:32:52 +00:00
GameId = game . Id . ToString ( ) ,
2023-01-14 21:09:45 +00:00
ReleaseDate = new ReleaseDate ( manifest . ReleasedOn ) ,
//Version = game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Version,
2023-01-17 23:09:42 +00:00
Icon = new MetadataFile ( $"{Settings.ServerAddress}{manifest.Icon}" ) ,
2023-01-17 05:45:46 +00:00
GameActions = game . Actions . OrderBy ( a = > a . SortOrder ) . Select ( a = > new PN . SDK . Models . GameAction ( )
2023-01-16 17:32:47 +00:00
{
Name = a . Name ,
Arguments = a . Arguments ,
Path = a . Path ,
WorkingDir = a . WorkingDirectory ,
IsPlayAction = a . PrimaryAction
} ) . ToList ( )
2023-01-07 20:32:52 +00:00
} ;
2023-01-14 21:09:45 +00:00
if ( manifest . Genre ! = null & & manifest . Genre . Count ( ) > 0 )
metadata . Genres = new HashSet < MetadataProperty > ( manifest . Genre . Select ( g = > new MetadataNameProperty ( g ) ) ) ;
if ( manifest . Developers ! = null & & manifest . Developers . Count ( ) > 0 )
metadata . Developers = new HashSet < MetadataProperty > ( manifest . Developers . Select ( d = > new MetadataNameProperty ( d ) ) ) ;
if ( manifest . Publishers ! = null & & manifest . Publishers . Count ( ) > 0 )
metadata . Publishers = new HashSet < MetadataProperty > ( manifest . Publishers . Select ( p = > new MetadataNameProperty ( p ) ) ) ;
if ( manifest . Tags ! = null & & manifest . Tags . Count ( ) > 0 )
metadata . Tags = new HashSet < MetadataProperty > ( manifest . Tags . Select ( t = > new MetadataNameProperty ( t ) ) ) ;
metadata . Features = new HashSet < MetadataProperty > ( ) ;
if ( manifest . Singleplayer )
metadata . Features . Add ( new MetadataNameProperty ( "Singleplayer" ) ) ;
if ( manifest . LocalMultiplayer ! = null )
metadata . Features . Add ( new MetadataNameProperty ( $"Local Multiplayer {manifest.LocalMultiplayer.GetPlayerCount()}" . Trim ( ) ) ) ;
if ( manifest . LanMultiplayer ! = null )
metadata . Features . Add ( new MetadataNameProperty ( $"LAN Multiplayer {manifest.LanMultiplayer.GetPlayerCount()}" . Trim ( ) ) ) ;
if ( manifest . OnlineMultiplayer ! = null )
metadata . Features . Add ( new MetadataNameProperty ( $"Online Multiplayer {manifest.OnlineMultiplayer.GetPlayerCount()}" . Trim ( ) ) ) ;
2023-01-07 20:32:52 +00:00
gameMetadata . Add ( metadata ) ;
2023-04-02 03:37:54 +00:00
}
catch ( Exception ex )
{
2023-08-21 23:44:20 +00:00
Logger . Error ( ex , $"Could not update game \" { game . Title } \ " in library" ) ;
2023-04-02 03:37:54 +00:00
}
} ;
2023-01-07 20:32:52 +00:00
return gameMetadata ;
2023-01-05 01:23:32 +00:00
}
2023-01-07 04:12:03 +00:00
public override IEnumerable < InstallController > GetInstallActions ( GetInstallActionsArgs args )
{
if ( args . Game . PluginId ! = Id )
yield break ;
yield return new LANCommanderInstallController ( this , args . Game ) ;
}
2023-01-07 18:46:26 +00:00
public override IEnumerable < UninstallController > GetUninstallActions ( GetUninstallActionsArgs args )
{
if ( args . Game . PluginId ! = Id )
yield break ;
yield return new LANCommanderUninstallController ( this , args . Game ) ;
}
2023-01-15 10:56:56 +00:00
public override IEnumerable < GameMenuItem > GetGameMenuItems ( GetGameMenuItemsArgs args )
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Populating game menu items..." ) ;
2023-01-15 10:56:56 +00:00
if ( args . Games . Count = = 1 & & args . Games . First ( ) . IsInstalled & & ! String . IsNullOrWhiteSpace ( args . Games . First ( ) . InstallDirectory ) )
{
var nameChangeScriptPath = PowerShellRuntime . GetScriptFilePath ( args . Games . First ( ) , SDK . Enums . ScriptType . NameChange ) ;
var keyChangeScriptPath = PowerShellRuntime . GetScriptFilePath ( args . Games . First ( ) , SDK . Enums . ScriptType . KeyChange ) ;
2023-03-29 02:30:29 +00:00
var installScriptPath = PowerShellRuntime . GetScriptFilePath ( args . Games . First ( ) , SDK . Enums . ScriptType . Install ) ;
2023-01-15 10:56:56 +00:00
if ( File . Exists ( nameChangeScriptPath ) )
2023-08-21 23:44:20 +00:00
{
Logger . Trace ( $"Name change script found at path {nameChangeScriptPath}" ) ;
2023-01-15 10:56:56 +00:00
yield return new GameMenuItem
{
Description = "Change Player Name" ,
Action = ( nameChangeArgs ) = >
{
2023-03-17 07:08:04 +00:00
var oldName = Settings . PlayerName ;
2023-01-16 17:31:38 +00:00
var result = PlayniteApi . Dialogs . SelectString ( "Enter your player name" , "Change Player Name" , Settings . PlayerName ) ;
if ( result . Result = = true )
2023-10-17 01:48:12 +00:00
{
2023-03-17 07:08:04 +00:00
PowerShellRuntime . RunScript ( nameChangeArgs . Games . First ( ) , SDK . Enums . ScriptType . NameChange , $@"""{result.SelectedString}"" ""{oldName}""" ) ;
2023-10-17 01:48:12 +00:00
LANCommander . ChangeAlias ( result . SelectedString ) ;
}
2023-01-15 10:56:56 +00:00
}
} ;
2023-08-21 23:44:20 +00:00
}
2023-01-15 10:56:56 +00:00
if ( File . Exists ( keyChangeScriptPath ) )
2023-08-21 23:44:20 +00:00
{
Logger . Trace ( $"Key change script found at path {keyChangeScriptPath}" ) ;
2023-01-15 10:56:56 +00:00
yield return new GameMenuItem
{
Description = "Change Game Key" ,
Action = ( keyChangeArgs ) = >
{
2023-01-16 02:45:37 +00:00
Guid gameId ;
if ( Guid . TryParse ( keyChangeArgs . Games . First ( ) . GameId , out gameId ) )
{
// NUKIEEEE
var newKey = LANCommander . GetNewKey ( gameId ) ;
if ( String . IsNullOrEmpty ( newKey ) )
PlayniteApi . Dialogs . ShowErrorMessage ( "There are no more keys available on the server." , "No Keys Available" ) ;
else
PowerShellRuntime . RunScript ( keyChangeArgs . Games . First ( ) , SDK . Enums . ScriptType . KeyChange , $@"""{newKey}""" ) ;
}
else
{
PlayniteApi . Dialogs . ShowErrorMessage ( "This game could not be found on the server. Your game may be corrupted." ) ;
}
2023-01-15 10:56:56 +00:00
}
} ;
2023-08-21 23:44:20 +00:00
}
2023-03-29 02:30:29 +00:00
if ( File . Exists ( installScriptPath ) )
2023-08-21 23:44:20 +00:00
{
Logger . Trace ( $"Install script found at path {installScriptPath}" ) ;
2023-03-29 02:30:29 +00:00
yield return new GameMenuItem
{
Description = "Run Install Script" ,
Action = ( installArgs ) = >
{
Guid gameId ;
if ( Guid . TryParse ( installArgs . Games . First ( ) . GameId , out gameId ) )
{
PowerShellRuntime . RunScript ( installArgs . Games . First ( ) , SDK . Enums . ScriptType . Install ) ;
}
else
{
PlayniteApi . Dialogs . ShowErrorMessage ( "This game could not be found on the server. Your game may be corrupted." ) ;
}
}
} ;
2023-08-21 23:44:20 +00:00
}
2023-01-15 10:56:56 +00:00
}
}
// To add new main menu items override GetMainMenuItems
public override IEnumerable < MainMenuItem > GetMainMenuItems ( GetMainMenuItemsArgs args )
{
yield return new MainMenuItem
{
Description = "Change Player Name (All Games)" ,
Action = ( args2 ) = >
{
2023-01-20 02:02:34 +00:00
ShowNameChangeWindow ( ) ;
}
} ;
2023-03-20 23:37:12 +00:00
yield return new MainMenuItem
{
Description = "Clear Download Cache" ,
Action = ( args2 ) = >
{
foreach ( var gameId in DownloadCache . Keys )
{
File . Delete ( DownloadCache [ gameId ] ) ;
DownloadCache . Remove ( gameId ) ;
}
PlayniteApi . Dialogs . ShowMessage ( "The download cache has been cleared and any temporary files have been deleted." , "Cache Cleared!" , MessageBoxButton . OK ) ;
}
} ;
2023-01-20 02:02:34 +00:00
}
2023-01-15 10:56:56 +00:00
2023-03-29 04:10:18 +00:00
public override void OnGameStarting ( OnGameStartingEventArgs args )
{
2023-03-30 01:49:31 +00:00
GameSaveService . DownloadSave ( args . Game ) ;
2023-03-29 04:10:18 +00:00
}
2023-03-29 02:30:29 +00:00
public override void OnGameStopped ( OnGameStoppedEventArgs args )
{
2023-03-30 01:49:31 +00:00
GameSaveService . UploadSave ( args . Game ) ;
2023-03-29 04:10:18 +00:00
}
2023-01-20 02:02:34 +00:00
public override IEnumerable < TopPanelItem > GetTopPanelItems ( )
{
yield return new TopPanelItem
{
Title = "Click to change your name (All Games)" ,
Icon = new TextBlock
{
2023-01-20 06:22:10 +00:00
Text = char . ConvertFromUtf32 ( 0xeded ) ,
2023-01-20 02:02:34 +00:00
FontSize = 16 ,
FontFamily = ResourceProvider . GetResource ( "FontIcoFont" ) as FontFamily ,
Padding = new Thickness ( 10 , 0 , 10 , 0 ) ,
2023-04-08 00:09:00 +00:00
2023-01-20 02:02:34 +00:00
} ,
2023-04-08 00:09:00 +00:00
Activated = ( ) = >
{
2023-01-20 02:02:34 +00:00
ShowNameChangeWindow ( ) ;
2023-01-15 10:56:56 +00:00
}
} ;
}
2023-01-05 01:23:32 +00:00
public override ISettings GetSettings ( bool firstRunSettings )
{
2023-01-05 07:07:17 +00:00
return Settings ;
2023-01-05 01:23:32 +00:00
}
public override UserControl GetSettingsView ( bool firstRunView )
{
2023-01-14 21:19:14 +00:00
return new LANCommanderSettingsView ( this ) ;
2023-01-05 07:07:17 +00:00
}
2023-01-20 02:02:34 +00:00
public void ShowNameChangeWindow ( )
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( "Showing name change dialog!" ) ;
2023-01-20 02:02:34 +00:00
var result = PlayniteApi . Dialogs . SelectString ( "Enter your new player name. This will change your name across all installed games!" , "Enter Name" , Settings . PlayerName ) ;
if ( result . Result = = true )
{
2023-08-21 23:44:20 +00:00
Logger . Trace ( $"New name entered was \" { result . SelectedString } \ "" ) ;
2023-01-20 02:02:34 +00:00
// Check to make sure they're staying in ASCII encoding
2023-01-20 06:21:51 +00:00
if ( String . IsNullOrEmpty ( result . SelectedString ) | | result . SelectedString . Any ( c = > c > sbyte . MaxValue ) )
2023-01-20 02:02:34 +00:00
{
PlayniteApi . Dialogs . ShowErrorMessage ( "The name you supplied is invalid. Try again." ) ;
2023-08-21 23:44:20 +00:00
Logger . Trace ( "An invalid name was specified. Showing the name dialog again..." ) ;
2023-01-20 02:02:34 +00:00
ShowNameChangeWindow ( ) ;
}
else
{
Settings . PlayerName = result . SelectedString ;
2023-08-21 23:44:20 +00:00
Logger . Trace ( $"New player name of \" { Settings . PlayerName } \ " has been set!" ) ;
Logger . Trace ( "Saving plugin settings!" ) ;
2023-01-20 02:02:34 +00:00
SavePluginSettings ( Settings ) ;
var games = PlayniteApi . Database . Games . Where ( g = > g . IsInstalled ) . ToList ( ) ;
2023-10-17 01:48:12 +00:00
LANCommander . ChangeAlias ( result . SelectedString ) ;
2023-08-21 23:44:20 +00:00
Logger . Trace ( $"Running name change scripts across {games.Count} installed game(s)" ) ;
2023-01-20 02:02:34 +00:00
PowerShellRuntime . RunScripts ( games , SDK . Enums . ScriptType . NameChange , Settings . PlayerName ) ;
}
}
2023-08-21 23:44:20 +00:00
else
Logger . Trace ( "Name change was cancelled" ) ;
2023-01-20 02:02:34 +00:00
}
2023-10-28 18:56:54 +00:00
public Window ShowAuthenticationWindow ( string serverAddress = null )
2023-01-05 07:07:17 +00:00
{
2023-01-15 19:33:04 +00:00
Window window = null ;
Application . Current . Dispatcher . Invoke ( ( Action ) delegate
2023-01-05 07:07:17 +00:00
{
2023-01-15 19:33:04 +00:00
window = PlayniteApi . Dialogs . CreateWindow ( new WindowCreationOptions ( )
{
ShowMinimizeButton = false ,
} ) ;
2023-01-05 07:07:17 +00:00
2023-01-15 19:33:04 +00:00
window . Title = "Authenticate to LANCommander" ;
2023-01-15 20:18:26 +00:00
window . Width = 400 ;
window . Height = 230 ;
2023-01-15 19:33:04 +00:00
window . Content = new Views . Authentication ( this ) ;
window . DataContext = new ViewModels . Authentication ( )
{
2023-10-28 18:56:54 +00:00
ServerAddress = serverAddress ? ? Settings ? . ServerAddress
2023-01-15 19:33:04 +00:00
} ;
2023-01-05 07:07:17 +00:00
2023-01-15 19:33:04 +00:00
window . Owner = PlayniteApi . Dialogs . GetCurrentAppWindow ( ) ;
2023-03-14 07:31:42 +00:00
window . WindowStartupLocation = WindowStartupLocation . CenterOwner ;
window . ResizeMode = ResizeMode . NoResize ;
2023-01-15 19:33:04 +00:00
window . ShowDialog ( ) ;
} ) ;
2023-01-06 08:39:00 +00:00
return window ;
2023-01-05 01:23:32 +00:00
}
2023-01-07 18:34:12 +00:00
2023-01-17 05:45:46 +00:00
public void UpdateGame ( SDK . GameManifest manifest , Guid gameId )
2023-01-07 18:34:12 +00:00
{
2023-01-17 05:45:46 +00:00
var game = PlayniteApi . Database . Games . First ( g = > g . GameId = = gameId . ToString ( ) ) ;
2023-01-07 18:34:12 +00:00
2023-01-17 23:09:42 +00:00
if ( game = = null )
return ;
2023-01-17 05:45:46 +00:00
if ( game . GameActions = = null )
game . GameActions = new ObservableCollection < PN . SDK . Models . GameAction > ( ) ;
else
game . GameActions . Clear ( ) ;
2023-01-07 18:34:12 +00:00
2023-01-17 23:09:42 +00:00
game . Icon = $"{Settings.ServerAddress}{manifest.Icon}" ;
2023-03-15 22:44:01 +00:00
if ( manifest . Actions = = null )
throw new Exception ( "The game has no actions defined." ) ;
2023-01-17 05:45:46 +00:00
foreach ( var action in manifest . Actions . OrderBy ( a = > a . SortOrder ) )
{
bool isFirstAction = ! manifest . Actions . Any ( a = > a . IsPrimaryAction ) & & manifest . Actions . First ( ) . Name = = action . Name ;
2023-01-07 20:32:52 +00:00
2023-01-17 05:45:46 +00:00
game . GameActions . Add ( new PN . SDK . Models . GameAction ( )
2023-01-07 18:34:12 +00:00
{
2023-01-17 05:45:46 +00:00
Name = action . Name ,
Arguments = action . Arguments ,
Path = PlayniteApi . ExpandGameVariables ( game , action . Path ? . Replace ( '/' , Path . DirectorySeparatorChar ) ) ,
2023-01-19 01:30:08 +00:00
WorkingDir = PlayniteApi . ExpandGameVariables ( game , action . WorkingDirectory ? . Replace ( '/' , Path . DirectorySeparatorChar ) ? ? game . InstallDirectory ) ,
2023-01-17 05:45:46 +00:00
IsPlayAction = action . IsPrimaryAction | | isFirstAction
} ) ;
}
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
#region Features
var singlePlayerFeature = PlayniteApi . Database . Features . FirstOrDefault ( f = > f . Name = = "Single Player" ) ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
if ( manifest . LanMultiplayer ! = null )
{
var multiplayerInfo = manifest . LanMultiplayer ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
string playerCount = multiplayerInfo . MinPlayers = = multiplayerInfo . MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)" ;
string featureName = $"LAN Multiplayer {playerCount}" ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
if ( PlayniteApi . Database . Features . Any ( f = > f . Name = = featureName ) )
{
game . Features . Add ( PlayniteApi . Database . Features . FirstOrDefault ( f = > f . Name = = featureName ) ) ;
}
else
{
PlayniteApi . Database . Features . Add ( new GameFeature ( )
{
Name = featureName
} ) ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
game . Features . Add ( new GameFeature ( )
{
Name = $"LAN Multiplayer {playerCount}"
} ) ;
}
}
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
if ( manifest . LocalMultiplayer ! = null )
{
var multiplayerInfo = manifest . LocalMultiplayer ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
string playerCount = multiplayerInfo . MinPlayers = = multiplayerInfo . MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)" ;
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
game . Features . Add ( new GameFeature ( )
{
Name = $"Local Multiplayer {playerCount}"
} ) ;
}
2023-01-12 02:48:39 +00:00
2023-01-17 05:45:46 +00:00
if ( manifest . OnlineMultiplayer ! = null )
{
var multiplayerInfo = manifest . OnlineMultiplayer ;
2023-01-07 20:32:52 +00:00
2023-01-17 05:45:46 +00:00
string playerCount = multiplayerInfo . MinPlayers = = multiplayerInfo . MaxPlayers ? $"({multiplayerInfo.MinPlayers} players)" : $"({multiplayerInfo.MinPlayers} - {multiplayerInfo.MaxPlayers} players)" ;
2023-01-07 18:34:12 +00:00
2023-01-17 05:45:46 +00:00
game . Features . Add ( new GameFeature ( )
{
Name = $"Online Multiplayer {playerCount}"
} ) ;
2023-01-07 18:34:12 +00:00
}
2023-01-17 05:45:46 +00:00
# endregion
PlayniteApi . Database . Games . Update ( game ) ;
2023-01-07 18:34:12 +00:00
}
2023-01-05 01:23:32 +00:00
}
}