Skip to content

Commit

Permalink
Add Firmware keyword in log if it is indeed firmware (#343)
Browse files Browse the repository at this point in the history
Co-authored-by: LotP1 <rasmus.stilling.pedersen1@gmail.com>
  • Loading branch information
WilliamWsyHK and LotP1 authored Dec 7, 2024
1 parent 0bc1edd commit d007544
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class NcaExtensions
{
private static readonly TitleUpdateMetadataJsonSerializerContext _applicationSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());

public static ProcessResult Load(this Nca nca, Switch device, Nca patchNca, Nca controlNca)
public static ProcessResult Load(this Nca nca, Switch device, Nca patchNca, Nca controlNca, BlitStruct<ApplicationControlProperty>? customNacpData = null)
{
// Extract RomFs and ExeFs from NCA.
IStorage romFs = nca.GetRomFs(device, patchNca);
Expand Down Expand Up @@ -55,6 +55,10 @@ public static ProcessResult Load(this Nca nca, Switch device, Nca patchNca, Nca
{
nacpData = controlNca.GetNacp(device);
}
else if (customNacpData != null) // if the Application doesn't provide a nacp file but the Application provides an override, use the provided nacp override
{
nacpData = (BlitStruct<ApplicationControlProperty>)customNacpData;
}

/* TODO: Rework this since it's wrong and doesn't work as it takes the DisplayVersion from a "potential" non-existent update.
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public bool LoadNsp(string path, ulong applicationId)
return false;
}

public bool LoadNca(string path)
public bool LoadNca(string path, BlitStruct<ApplicationControlProperty>? customNacpData = null)
{
FileStream file = new(path, FileMode.Open, FileAccess.Read);
Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false));

ProcessResult processResult = nca.Load(_device, null, null);
ProcessResult processResult = nca.Load(_device, null, null, customNacpData);

if (processResult.ProcessId != 0 && _processesByPid.TryAdd(processResult.ProcessId, processResult))
{
Expand Down
13 changes: 10 additions & 3 deletions src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ public bool Start(Switch device)
return false;
}

bool isFirmware = ProgramId is >= 0x0100000000000819 and <= 0x010000000000081C;
bool isFirmwareApplication = ProgramId <= 0x0100000000007FFF;

string name = !isFirmware
? (isFirmwareApplication ? "Firmware Application " : "") + (!string.IsNullOrWhiteSpace(Name) ? Name : "<Unknown Name>")
: "Firmware";

// TODO: LibHac npdm currently doesn't support version field.
string version = ProgramId > 0x0100000000007FFF
? DisplayVersion
string version = !isFirmware
? (!string.IsNullOrWhiteSpace(DisplayVersion) ? DisplayVersion : "<Unknown Version>")
: device.System.ContentManager.GetCurrentFirmwareVersion()?.VersionString ?? "?";

Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {Name} v{version} [{ProgramIdText}] [{(Is64Bit ? "64-bit" : "32-bit")}]");
Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {name} v{version} [{ProgramIdText}] [{(Is64Bit ? "64-bit" : "32-bit")}]");

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Ryujinx.HLE/Switch.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using LibHac.Common;
using LibHac.Ns;
using Ryujinx.Audio.Backends.CompatLayer;
using Ryujinx.Audio.Integration;
using Ryujinx.Common.Configuration;
Expand Down Expand Up @@ -111,7 +113,7 @@ public void UpdateVSyncInterval()

public bool LoadCart(string exeFsDir, string romFsFile = null) => Processes.LoadUnpackedNca(exeFsDir, romFsFile);
public bool LoadXci(string xciFile, ulong applicationId = 0) => Processes.LoadXci(xciFile, applicationId);
public bool LoadNca(string ncaFile) => Processes.LoadNca(ncaFile);
public bool LoadNca(string ncaFile, BlitStruct<ApplicationControlProperty>? customNacpData = null) => Processes.LoadNca(ncaFile, customNacpData);
public bool LoadNsp(string nspFile, ulong applicationId = 0) => Processes.LoadNsp(nspFile, applicationId);
public bool LoadProgram(string fileName) => Processes.LoadNxo(fileName);

Expand Down
6 changes: 4 additions & 2 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Threading;
using LibHac.Common;
using LibHac.Ns;
using LibHac.Tools.FsSystem;
using Ryujinx.Audio.Backends.Dummy;
using Ryujinx.Audio.Backends.OpenAL;
Expand Down Expand Up @@ -670,7 +672,7 @@ private void HideCursorState_Changed(object sender, ReactiveEventArgs<HideCursor
_cursorState = CursorStates.ForceChangeCursor;
}

public async Task<bool> LoadGuestApplication()
public async Task<bool> LoadGuestApplication(BlitStruct<ApplicationControlProperty>? customNacpData = null)
{
InitializeSwitchInstance();
MainWindow.UpdateGraphicsConfig();
Expand Down Expand Up @@ -740,7 +742,7 @@ await ContentDialogHelper.CreateInfoDialog(
{
Logger.Info?.Print(LogClass.Application, "Loading as Firmware Title (NCA).");

if (!Device.LoadNca(ApplicationPath))
if (!Device.LoadNca(ApplicationPath, customNacpData))
{
Device.Dispose();

Expand Down
5 changes: 3 additions & 2 deletions src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using DynamicData.Binding;
using FluentAvalonia.UI.Controls;
using LibHac.Common;
using LibHac.Ns;
using Ryujinx.Ava.Common;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Input;
Expand Down Expand Up @@ -1897,7 +1898,7 @@ public async Task OpenFolder()
}
}

public async Task LoadApplication(ApplicationData application, bool startFullscreen = false)
public async Task LoadApplication(ApplicationData application, bool startFullscreen = false, BlitStruct<ApplicationControlProperty>? customNacpData = null)
{
if (AppHost != null)
{
Expand Down Expand Up @@ -1935,7 +1936,7 @@ await ContentDialogHelper.CreateInfoDialog(
this,
TopLevel);

if (!await AppHost.LoadGuestApplication())
if (!await AppHost.LoadGuestApplication(customNacpData))
{
AppHost.DisposeContext();
AppHost = null;
Expand Down
27 changes: 23 additions & 4 deletions src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Avalonia.Interactivity;
using Avalonia.Threading;
using Gommon;
using LibHac.Common;
using LibHac.Ncm;
using LibHac.Ns;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
Expand All @@ -19,6 +21,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Ryujinx.Ava.UI.Views.Main
{
Expand Down Expand Up @@ -123,18 +126,34 @@ public async void OpenSettings(object sender, RoutedEventArgs e)

public async void OpenMiiApplet(object sender, RoutedEventArgs e)
{
string contentPath = ViewModel.ContentManager.GetInstalledContentPath(0x0100000000001009, StorageId.BuiltInSystem, NcaContentType.Program);
const string name = "miiEdit";
const ulong programId = 0x0100000000001009;
string contentPath = ViewModel.ContentManager.GetInstalledContentPath(programId, StorageId.BuiltInSystem, NcaContentType.Program);

if (!string.IsNullOrEmpty(contentPath))
{
ApplicationData applicationData = new()
{
Name = "miiEdit",
Id = 0x0100000000001009,
Name = name,
Id = programId,
Path = contentPath,
};

await ViewModel.LoadApplication(applicationData, ViewModel.IsFullScreen || ViewModel.StartGamesInFullscreen);
string version = "1.0.0";
var nacpData = new BlitStruct<ApplicationControlProperty>(1);

//version buffer
Encoding.ASCII.GetBytes(version).AsSpan().CopyTo(nacpData.ByteSpan.Slice(0x3060));

//name and distributor buffer
//repeat once for each locale (the ApplicationControlProperty has 16 locales)
for (int i = 0; i < 0x10; i++)
{
Encoding.ASCII.GetBytes(name).AsSpan().CopyTo(nacpData.ByteSpan.Slice(i * 0x300));
"Ryujinx"u8.ToArray().AsSpan().CopyTo(nacpData.ByteSpan.Slice(i * 0x300 + 0x200));
}

await ViewModel.LoadApplication(applicationData, ViewModel.IsFullScreen || ViewModel.StartGamesInFullscreen, nacpData);
}
}

Expand Down

0 comments on commit d007544

Please sign in to comment.