Skip to content

Commit

Permalink
Dust off Cyberpunk2077 (#1719)
Browse files Browse the repository at this point in the history
* Dust off the Cyberpunk2077 code a bit and enable optional archival for the base game files

* Update src/Games/NexusMods.Games.RedEngine/Cyberpunk2077Synchronizer.cs

Co-authored-by: erri120 <erri120@fossmailer.de>

---------

Co-authored-by: erri120 <erri120@fossmailer.de>
  • Loading branch information
halgari and erri120 committed Jul 4, 2024
1 parent 7bbd97f commit 7868085
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/Games/NexusMods.Games.RedEngine/Cyberpunk2077.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.IO;
using NexusMods.Abstractions.IO.StreamFactories;
using NexusMods.Abstractions.Loadouts.Synchronizers;
using NexusMods.Games.FOMOD;
using NexusMods.Games.RedEngine.ModInstallers;
using NexusMods.Paths;
Expand All @@ -26,6 +27,9 @@ public Cyberpunk2077(IEnumerable<IGameLocator> gameLocators, IFileSystem fileSys
_serviceProvider = provider;
}

protected override ILoadoutSynchronizer MakeSynchronizer(IServiceProvider provider)
=> new Cyberpunk2077Synchronizer(provider);

public override string Name => "Cyberpunk 2077";
public override GameDomain Domain => StaticDomain;
public override GamePath GetPrimaryFile(GameStore store) => new(LocationId.Game, "bin/x64/Cyberpunk2077.exe");
Expand Down
26 changes: 26 additions & 0 deletions src/Games/NexusMods.Games.RedEngine/Cyberpunk2077Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NexusMods.Abstractions.Settings;

namespace NexusMods.Games.RedEngine;

public class Cyberpunk2077Settings : ISettings
{
/// <summary>
/// If true, the contents of the Content folder will not be backed up. If the game updates
/// the loadout may become invalid. If mods are installed into this folder via the app they
/// will still be backed up as needed
/// </summary>
public bool IgnoreContentFolder { get; set; } = true;

public static ISettingsBuilder Configure(ISettingsBuilder settingsBuilder)
{
return settingsBuilder.AddToUI<Cyberpunk2077Settings>(builder => builder
.AddPropertyToUI(x => x.IgnoreContentFolder, propertyBuilder => propertyBuilder
.AddToSection(Sections.GameSpecific)
.WithDisplayName("Cyberpunk 2077: Ignore Content Folder")
.WithDescription("Don't back up the game asset folders. If the game updates this may render the loadout invalid.")
.UseBooleanContainer()
)
);

}
}
38 changes: 38 additions & 0 deletions src/Games/NexusMods.Games.RedEngine/Cyberpunk2077Synchronizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Loadouts.Synchronizers;
using NexusMods.Abstractions.Settings;

namespace NexusMods.Games.RedEngine;

public class Cyberpunk2077Synchronizer : ALoadoutSynchronizer
{
private Cyberpunk2077Settings _settings;

protected internal Cyberpunk2077Synchronizer(IServiceProvider provider) : base(provider)
{
var settingsManager = provider.GetRequiredService<ISettingsManager>();

_settings = settingsManager.Get<Cyberpunk2077Settings>();
settingsManager.GetChanges<Cyberpunk2077Settings>().Subscribe(value => _settings = value);
}

private static readonly GamePath[] IgnoredFolders =
[
new GamePath(LocationId.Game, "archive/pc/content"),
new GamePath(LocationId.Game, "archive/pc/ep1"),
];


public override bool IsIgnoredBackupPath(GamePath path)
{
if (!_settings.IgnoreContentFolder)
return false;

if (path.LocationId != LocationId.Game)
return false;

return IgnoredFolders.Any(ignore => path.Path.InFolder(ignore.Path));
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions src/Games/NexusMods.Games.RedEngine/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NexusMods.Abstractions.Games;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.Loadouts;
using NexusMods.Abstractions.Settings;
using NexusMods.Games.RedEngine.ModInstallers;

namespace NexusMods.Games.RedEngine;
Expand All @@ -10,13 +11,14 @@ public static class Services
{
public static IServiceCollection AddRedEngineGames(this IServiceCollection services)
{
services.AddGame<Cyberpunk2077>();
services.AddSingleton<IModInstaller, SimpleOverlayModInstaller>();
services.AddSingleton<IModInstaller, FolderlessModInstaller>();
services.AddSingleton<IModInstaller, AppearancePreset>();
services.AddSingleton<IModInstaller, RedModInstaller>();
services.AddSingleton<ITool, RunGameTool<Cyberpunk2077>>();
services.AddSingleton<ITool, RedModDeployTool>();
services.AddGame<Cyberpunk2077>()
.AddSingleton<IModInstaller, SimpleOverlayModInstaller>()
.AddSingleton<IModInstaller, FolderlessModInstaller>()
.AddSingleton<IModInstaller, AppearancePreset>()
.AddSingleton<IModInstaller, RedModInstaller>()
.AddSingleton<ITool, RunGameTool<Cyberpunk2077>>()
.AddSingleton<ITool, RedModDeployTool>()
.AddSettings<Cyberpunk2077Settings>();
return services;
}
}
2 changes: 1 addition & 1 deletion src/NexusMods.App/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ private static IServiceCollection AddSupportedGames(this IServiceCollection serv
{
if (experimentalSettings is { EnableAllGames: true })
{
Games.RedEngine.Services.AddRedEngineGames(services);
}

Games.RedEngine.Services.AddRedEngineGames(services);
Games.StardewValley.Services.AddStardewValley(services);
return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Settings;
using NexusMods.Extensions.Hashing;
using NexusMods.Games.TestFramework;
using NexusMods.Paths.Extensions;

namespace NexusMods.Games.RedEngine.Tests;

public class Cyberpunk2077SynchronizerTests(IServiceProvider serviceProvider) : AGameTest<Cyberpunk2077>(serviceProvider)
{

[Fact]
public async Task ContentIsIgnoredWhenSettingIsSet()
{
// Get the settings
var settings = ServiceProvider.GetRequiredService<ISettingsManager>().Get<Cyberpunk2077Settings>();
settings.IgnoreContentFolder = true;

// Setup the paths we want to edit, one will be in the `Content` folder, thus not backed up
var ignoredGamePath = new GamePath(LocationId.Game, "archive/pc/content/foo.dat".ToRelativePath());
var notIgnoredGamePath = new GamePath(LocationId.Game, "foo.dat".ToRelativePath());

var ignoredPath = GameInstallation.LocationsRegister.GetResolvedPath(ignoredGamePath);
ignoredPath.Parent.CreateDirectory();
var notIgnoredPath = GameInstallation.LocationsRegister.GetResolvedPath(notIgnoredGamePath);

// Write the files
await ignoredPath.WriteAllTextAsync("Ignore me");
var ignoredHash = await ignoredPath.XxHash64Async();
await notIgnoredPath.WriteAllTextAsync("Don't you dare ignore me!");
var notIgnoredHash = await notIgnoredPath.XxHash64Async();

// Create the loadout
var loadout = await CreateLoadout();

loadout.Files.Should().Contain(f => f.To == ignoredGamePath, "The file exists, but is ignored");
(await FileStore.HaveFile(ignoredHash)).Should().BeFalse("The file is ignored");

loadout.Files.Should().Contain(f => f.To == notIgnoredGamePath, "The file was not ignored");
(await FileStore.HaveFile(notIgnoredHash)).Should().BeTrue("The file was not ignored");

// Now disable the ignore setting
settings.IgnoreContentFolder = false;

var loadout2 = await CreateLoadout();

loadout2.Files.Should().Contain(f => f.To == ignoredGamePath, "The file exists, but is ignored");
(await FileStore.HaveFile(ignoredHash)).Should().BeTrue("The file is not ignored");
loadout2.Files.Should().Contain(f => f.To == notIgnoredGamePath, "The file was not ignored");
(await FileStore.HaveFile(notIgnoredHash)).Should().BeTrue("The file was not ignored");
}

}

0 comments on commit 7868085

Please sign in to comment.