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

UI: Expose games build ID for cheat management #4340

Merged
merged 25 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5c0678d
Ava UI: Expose games build ID for cheat management
gnisman Jan 24, 2023
cc5533b
Merge branch 'master' into expose-games-build-id
gnisman Jan 24, 2023
d2ed673
Fix bad merge
gnisman Jan 24, 2023
51ee35d
Change integrity check level to error on invalid
gnisman Jan 24, 2023
d65bf1e
Add support for GDK
gnisman Jan 26, 2023
aa437bf
Remove whitespace
gnisman Jan 26, 2023
f10f721
Add BID identifier
gnisman Jan 29, 2023
68207f4
PR Comments fix
gnisman Feb 3, 2023
47ea91d
Restore title id in cheats GTK window
gnisman Feb 3, 2023
83633e9
use halign center instead of margin_left
gnisman Feb 3, 2023
5da44c4
Merge branch 'master' into expose-games-build-id
gnisman Apr 1, 2023
5b1021f
Merge
gnisman Apr 1, 2023
8f4fab7
fix after merge
gnisman Apr 1, 2023
da5c9a0
PR comments fix - design AVA
gnisman Apr 19, 2023
b22a89a
PR fix - Move GetApplicationBuildId to ApplicationData class
gnisman Apr 21, 2023
496eb43
Merge branch 'master' into expose-games-build-id
gnisman Apr 21, 2023
5a7c458
PR comment fix - Add empty line before method
gnisman Apr 21, 2023
c19dee5
Merge 'origin/master' into expose-games-build-id
gnisman Apr 29, 2023
d14b220
Merge branch 'master' into expose-games-build-id
gnisman May 4, 2023
f953de5
Align with PR #4755
gnisman May 4, 2023
2518652
Merge branch 'master' into expose-games-build-id
gnisman May 5, 2023
2339333
PR comments fix
gnisman May 5, 2023
64c90f4
Change BuildId label to support translation
gnisman May 5, 2023
e655a69
Comments fix
gnisman May 6, 2023
40bb713
Remove unused BuildIdLabel property
gnisman May 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ public async void OpenCheatManager()
if (SelectedApplication != null)
{
await new CheatWindow(VirtualFileSystem, SelectedApplication.TitleId, SelectedApplication.TitleName,
GameDataExtractor.GetGameBuildId(VirtualFileSystem, SelectedApplication.Path)).ShowDialog(TopLevel as Window);
ApplicationData.GetApplicationBuildId(VirtualFileSystem, SelectedApplication.Path)).ShowDialog(TopLevel as Window);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Ryujinx.Ava/UI/Views/Main/MainMenuBarView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Ryujinx.Common.Utilities;
using Ryujinx.HLE.HOS;
using Ryujinx.Modules;
using Ryujinx.Ui.App.Common;
using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Helper;
Expand Down Expand Up @@ -178,7 +179,7 @@ public async void OpenCheatManagerForCurrentApp(object sender, RoutedEventArgs e

await new CheatWindow(Window.VirtualFileSystem,
ViewModel.AppHost.Device.Processes.ActiveApplication.ProgramIdText, name,
GameDataExtractor.GetGameBuildId(Window.VirtualFileSystem,
ApplicationData.GetApplicationBuildId(Window.VirtualFileSystem,
Window.ViewModel.SelectedApplication.Path))
.ShowDialog(Window);

Expand Down
134 changes: 134 additions & 0 deletions Ryujinx.Ui.Common/App/ApplicationData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
using LibHac.Common;
using LibHac.Ns;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Loader;
using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem;
using System;
using System.IO;

namespace Ryujinx.Ui.App.Common
{
Expand All @@ -19,5 +30,128 @@ public class ApplicationData
public double FileSizeBytes { get; set; }
public string Path { get; set; }
public BlitStruct<ApplicationControlProperty> ControlHolder { get; set; }
public static string GetApplicationBuildId(VirtualFileSystem virtualFileSystem, string titleFilePath)
gnisman marked this conversation as resolved.
Show resolved Hide resolved
{
using FileStream file = new(titleFilePath, FileMode.Open, FileAccess.Read);

Nca mainNca = null;
Nca patchNca = null;

if (!System.IO.Path.Exists(titleFilePath))
{
Logger.Error?.Print(LogClass.Application,
$"File does not exists. {titleFilePath}");
return string.Empty;
}

string extension = System.IO.Path.GetExtension(titleFilePath).ToLower();

if (extension is ".nsp" or ".xci")
{
PartitionFileSystem pfs;

if (extension == ".xci")
{
Xci xci = new(virtualFileSystem.KeySet, file.AsStorage());

pfs = xci.OpenPartition(XciPartitionType.Secure);
}
else
{
pfs = new PartitionFileSystem(file.AsStorage());
}

foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
using var ncaFile = new UniqueRef<IFile>();

pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();

Nca nca = new(virtualFileSystem.KeySet, ncaFile.Get.AsStorage());

if (nca.Header.ContentType != NcaContentType.Program)
{
continue;
}

int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);

if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
patchNca = nca;
}
else
{
mainNca = nca;
}
}
}
else if (extension == ".nca")
{
mainNca = new Nca(virtualFileSystem.KeySet, file.AsStorage());
}

if (mainNca == null)
{
Logger.Error?.Print(LogClass.Application,
"Extraction failure. The main NCA was not present in the selected file");

return string.Empty;
}

(Nca updatePatchNca, _) = ApplicationLibrary.GetGameUpdateData(virtualFileSystem,
mainNca.Header.TitleId.ToString("x16"), 0, out _);

if (updatePatchNca != null)
{
patchNca = updatePatchNca;
}

IFileSystem codeFs = null;

if (patchNca == null)
{
if (mainNca.CanOpenSection(NcaSectionType.Code))
{
codeFs = mainNca.OpenFileSystem(NcaSectionType.Code, IntegrityCheckLevel.ErrorOnInvalid);
}
}
else
{
if (patchNca.CanOpenSection(NcaSectionType.Code))
{
codeFs = mainNca.OpenFileSystemWithPatch(patchNca, NcaSectionType.Code,
IntegrityCheckLevel.ErrorOnInvalid);
}
}

if (codeFs == null)
{
Logger.Error?.Print(LogClass.Loader, "No ExeFS found in NCA");

return string.Empty;
}

const string mainExeFs = "main";

if (!codeFs.FileExists($"/{mainExeFs}"))
{
Logger.Error?.Print(LogClass.Loader, "No main binary ExeFS found in ExeFS");

return string.Empty;
}

using var nsoFile = new UniqueRef<IFile>();

codeFs.OpenFile(ref nsoFile.Ref, $"/{mainExeFs}".ToU8Span(), OpenMode.Read).ThrowIfFailure();

NsoReader reader = new NsoReader();
reader.Initialize(nsoFile.Release().AsStorage().AsFile(OpenMode.Read)).ThrowIfFailure();

const int buildIdSize = 16;

return BitConverter.ToString(reader.Header.ModuleId.ItemsRo.ToArray()).Replace("-", "").ToUpper()
[..buildIdSize];
}
}
}
136 changes: 0 additions & 136 deletions Ryujinx.Ui.Common/Helper/GameDataExtractor.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Ryujinx/Ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ private void ManageCheats_Pressed(object sender, EventArgs args)
_emulationContext.Processes.ActiveApplication.ProgramId,
_emulationContext.Processes.ActiveApplication.ApplicationControlProperties
.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString(),
GameDataExtractor.GetGameBuildId(_virtualFileSystem, _currentEmulatedGamePath));
ApplicationData.GetApplicationBuildId(_virtualFileSystem, _currentEmulatedGamePath));

window.Destroyed += CheatWindow_Destroyed;
window.Show();
Expand Down
2 changes: 1 addition & 1 deletion Ryujinx/Ui/Widgets/GameTableContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private void ManageDlc_Clicked(object sender, EventArgs args)
private void ManageCheats_Clicked(object sender, EventArgs args)
{
new CheatWindow(_virtualFileSystem, _titleId, _titleName,
GameDataExtractor.GetGameBuildId(_virtualFileSystem, _titleFilePath)).Show();
ApplicationData.GetApplicationBuildId(_virtualFileSystem, _titleFilePath)).Show();
}

private void OpenTitleModDir_Clicked(object sender, EventArgs args)
Expand Down