mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-03-11 17:55:44 +00:00
Merge branch 'master' into 'master'
nacp: add support for zlib-compressed title blocks See merge request [ryubing/ryujinx!274](https://git.ryujinx.app/ryubing/ryujinx/-/merge_requests/274)
This commit is contained in:
commit
dfdba38089
12 changed files with 173 additions and 40 deletions
|
|
@ -20,5 +20,7 @@ namespace Ryujinx.HLE.HOS.SystemState
|
|||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
BrazilianPortuguese,
|
||||
Polish,
|
||||
Thai,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ namespace Ryujinx.HLE.HOS.SystemState
|
|||
"es-419",
|
||||
"zh-Hans",
|
||||
"zh-Hant",
|
||||
"pt-BR"
|
||||
"pt-BR",
|
||||
"pl",
|
||||
"th"
|
||||
];
|
||||
|
||||
internal long DesiredKeyboardLayout { get; private set; }
|
||||
|
|
|
|||
|
|
@ -18,5 +18,7 @@ namespace Ryujinx.HLE.HOS.SystemState
|
|||
TraditionalChinese,
|
||||
SimplifiedChinese,
|
||||
BrazilianPortuguese,
|
||||
Polish,
|
||||
Thai,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Ryujinx.Common.Configuration;
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.HLE.Loaders.Executables;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using Ryujinx.Memory;
|
||||
using System.Linq;
|
||||
using static Ryujinx.HLE.HOS.ModLoader;
|
||||
|
|
@ -86,16 +87,24 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
|
||||
if (!isHomebrew && programId > 0x010000000000FFFF)
|
||||
{
|
||||
programName = nacpData.Value.Title[(int)device.System.State.DesiredTitleLanguage].NameString.ToString();
|
||||
int langIdx = (int)device.System.State.DesiredTitleLanguage;
|
||||
var titles = NacpHelper.GetTitles(in nacpData.Value);
|
||||
int titleCount = titles.Length;
|
||||
|
||||
if (langIdx < titleCount)
|
||||
{
|
||||
programName = titles[langIdx].NameString.ToString();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(programName))
|
||||
{
|
||||
foreach (ApplicationControlProperty.ApplicationTitle appTitle in nacpData.Value.Title)
|
||||
for (int i = 0; i < titleCount; i++)
|
||||
{
|
||||
if (appTitle.Name[0] != 0)
|
||||
continue;
|
||||
|
||||
programName = appTitle.NameString.ToString();
|
||||
if (titles[i].Name[0] != 0)
|
||||
{
|
||||
programName = titles[i].NameString.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,20 +194,28 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
{
|
||||
nacpStorage.Read(0, nacpData.ByteSpan);
|
||||
|
||||
programName = nacpData.Value.Title[(int)_device.System.State.DesiredTitleLanguage].NameString.ToString();
|
||||
int langIdx = (int)_device.System.State.DesiredTitleLanguage;
|
||||
var titles = Utilities.NacpHelper.GetTitles(in nacpData.Value);
|
||||
int titleCount = titles.Length;
|
||||
|
||||
if ("Switch Verification" ==
|
||||
nacpData.Value.Title[(int)TitleLanguage.AmericanEnglish].NameString.ToString())
|
||||
if (langIdx < titleCount)
|
||||
{
|
||||
programName = titles[langIdx].NameString.ToString();
|
||||
}
|
||||
|
||||
string verifyName = titles[(int)TitleLanguage.AmericanEnglish].NameString.ToString();
|
||||
if ("Switch Verification" == verifyName)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(programName))
|
||||
{
|
||||
foreach (ApplicationControlProperty.ApplicationTitle nacpTitles in nacpData.Value.Title)
|
||||
for (int i = 0; i < titleCount; i++)
|
||||
{
|
||||
if (nacpTitles.Name[0] != 0)
|
||||
continue;
|
||||
|
||||
programName = nacpTitles.NameString.ToString();
|
||||
if (titles[i].Name[0] != 0)
|
||||
{
|
||||
programName = titles[i].NameString.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Ryujinx.Common.Logging;
|
|||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.SystemState;
|
||||
using Ryujinx.HLE.Loaders.Processes.Extensions;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using Ryujinx.Horizon.Common;
|
||||
|
||||
namespace Ryujinx.HLE.Loaders.Processes
|
||||
|
|
@ -54,16 +55,24 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
{
|
||||
ulong programId = metaLoader.ProgramId;
|
||||
|
||||
Name = ApplicationControlProperties.Title[(int)titleLanguage].NameString.ToString();
|
||||
int langIdx = (int)titleLanguage;
|
||||
var titles = NacpHelper.GetTitles(in ApplicationControlProperties);
|
||||
int titleCount = titles.Length;
|
||||
|
||||
if (langIdx < titleCount)
|
||||
{
|
||||
Name = titles[langIdx].NameString.ToString();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
{
|
||||
foreach (ApplicationControlProperty.ApplicationTitle appTitle in ApplicationControlProperties.Title)
|
||||
for (int i = 0; i < titleCount; i++)
|
||||
{
|
||||
if (appTitle.Name[0] != 0)
|
||||
continue;
|
||||
|
||||
Name = appTitle.NameString.ToString();
|
||||
if (titles[i].Name[0] != 0)
|
||||
{
|
||||
Name = titles[i].NameString.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
28
src/Ryujinx.HLE/Utilities/NacpHelper.cs
Normal file
28
src/Ryujinx.HLE/Utilities/NacpHelper.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Ns;
|
||||
using Ryujinx.Horizon.Sdk.Ns;
|
||||
|
||||
namespace Ryujinx.HLE.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Bridges from LibHac's NACP struct to title resolution. All title parsing logic
|
||||
/// lives on <see cref="Ryujinx.Horizon.Sdk.Ns.ApplicationControlProperty.Title"/>; this helper
|
||||
/// reinterprets the same bytes so call sites holding LibHac's struct can use it.
|
||||
/// </summary>
|
||||
public static class NacpHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the resolved title entries (16 or 32 depending on compression).
|
||||
/// Uses the same binary layout as Horizon.Sdk so we delegate to its property.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Ryujinx.Horizon.Sdk.Ns.ApplicationControlProperty.ApplicationTitle[] GetTitles(
|
||||
in LibHac.Ns.ApplicationControlProperty nacp)
|
||||
{
|
||||
ref readonly var libHacRef = ref nacp;
|
||||
ref var horizonRef = ref Unsafe.As<LibHac.Ns.ApplicationControlProperty, Ryujinx.Horizon.Sdk.Ns.ApplicationControlProperty>(
|
||||
ref Unsafe.AsRef(in libHacRef));
|
||||
return horizonRef.Title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Horizon.Sdk.Ns
|
||||
{
|
||||
public struct ApplicationControlProperty
|
||||
{
|
||||
public Array16<ApplicationTitle> Title;
|
||||
public Array16<ApplicationTitle> TitleBlock;
|
||||
public Array37<byte> Isbn;
|
||||
public StartupUserAccountValue StartupUserAccount;
|
||||
public UserAccountSwitchLockValue UserAccountSwitchLock;
|
||||
|
|
@ -58,7 +62,10 @@ namespace Ryujinx.Horizon.Sdk.Ns
|
|||
public RepairFlagValue RepairFlag;
|
||||
public byte ProgramIndex;
|
||||
public RequiredNetworkServiceLicenseOnLaunchValue RequiredNetworkServiceLicenseOnLaunchFlag;
|
||||
public Array4<byte> Reserved3214;
|
||||
public byte ApplicationErrorCodePrefix;
|
||||
public TitleCompressionValue TitleCompression;
|
||||
public byte AcdIndex;
|
||||
public byte ApparentPlatform;
|
||||
public ApplicationNeighborDetectionClientConfiguration NeighborDetectionClientConfiguration;
|
||||
public ApplicationJitConfiguration JitConfiguration;
|
||||
public RequiredAddOnContentsSetBinaryDescriptor RequiredAddOnContentsSetBinaryDescriptors;
|
||||
|
|
@ -75,6 +82,56 @@ namespace Ryujinx.Horizon.Sdk.Ns
|
|||
public readonly string ApplicationErrorCodeCategoryString => Encoding.UTF8.GetString(ApplicationErrorCodeCategory.AsSpan()).TrimEnd('\0');
|
||||
public readonly string BcatPassphraseString => Encoding.UTF8.GetString(BcatPassphrase.AsSpan()).TrimEnd('\0');
|
||||
|
||||
private const int UncompressedTitleCount = 16;
|
||||
private const int CompressedTitleCount = 32;
|
||||
private const int TitleEntrySize = 0x300;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the resolved title entries. When <see cref="TitleCompression"/> is
|
||||
/// <see cref="TitleCompressionValue.Enable"/>, the raw <see cref="TitleBlock"/> bytes are
|
||||
/// decompressed (raw deflate) from 0x3000 into 0x6000 bytes yielding up to 32 entries.
|
||||
/// Otherwise the 16 uncompressed entries from <see cref="TitleBlock"/> are returned directly.
|
||||
/// </summary>
|
||||
public readonly ApplicationTitle[] Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TitleCompression != TitleCompressionValue.Enable)
|
||||
{
|
||||
var titles = new ApplicationTitle[UncompressedTitleCount];
|
||||
for (int i = 0; i < UncompressedTitleCount; i++)
|
||||
titles[i] = TitleBlock[i];
|
||||
return titles;
|
||||
}
|
||||
|
||||
ReadOnlySpan<byte> titleBytes = MemoryMarshal.AsBytes(TitleBlock.AsSpan());
|
||||
ushort compressedBlobSize = BinaryPrimitives.ReadUInt16LittleEndian(titleBytes);
|
||||
ReadOnlySpan<byte> compressedBlob = titleBytes.Slice(2, compressedBlobSize);
|
||||
|
||||
byte[] decompressed = new byte[CompressedTitleCount * TitleEntrySize];
|
||||
|
||||
using (var compressedStream = new MemoryStream(compressedBlob.ToArray()))
|
||||
using (var deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
|
||||
{
|
||||
int totalRead = 0;
|
||||
while (totalRead < decompressed.Length)
|
||||
{
|
||||
int read = deflateStream.Read(decompressed, totalRead, decompressed.Length - totalRead);
|
||||
if (read == 0)
|
||||
break;
|
||||
totalRead += read;
|
||||
}
|
||||
}
|
||||
|
||||
var result = new ApplicationTitle[CompressedTitleCount];
|
||||
for (int i = 0; i < CompressedTitleCount; i++)
|
||||
result[i] = MemoryMarshal.Read<ApplicationTitle>(
|
||||
decompressed.AsSpan(i * TitleEntrySize, TitleEntrySize));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ApplicationTitle
|
||||
{
|
||||
public ByteArray512 Name;
|
||||
|
|
@ -130,6 +187,8 @@ namespace Ryujinx.Horizon.Sdk.Ns
|
|||
TraditionalChinese = 13,
|
||||
SimplifiedChinese = 14,
|
||||
BrazilianPortuguese = 15,
|
||||
Polish = 16,
|
||||
Thai = 17,
|
||||
}
|
||||
|
||||
public enum Organization
|
||||
|
|
@ -302,5 +361,11 @@ namespace Ryujinx.Horizon.Sdk.Ns
|
|||
Deny = 0,
|
||||
Allow = 1,
|
||||
}
|
||||
|
||||
public enum TitleCompressionValue : byte
|
||||
{
|
||||
Disable = 0,
|
||||
Enable = 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,8 +166,9 @@ namespace Ryujinx.Headless
|
|||
ProcessResult activeProcess = Device.Processes.ActiveApplication;
|
||||
ApplicationControlProperty nacp = activeProcess.ApplicationControlProperties;
|
||||
int desiredLanguage = (int)Device.System.State.DesiredTitleLanguage;
|
||||
|
||||
string titleNameSection = string.IsNullOrWhiteSpace(nacp.Title[desiredLanguage].NameString.ToString()) ? string.Empty : $" - {nacp.Title[desiredLanguage].NameString.ToString()}";
|
||||
var titles = Ryujinx.HLE.Utilities.NacpHelper.GetTitles(in nacp);
|
||||
string titleName = desiredLanguage < titles.Length ? titles[desiredLanguage].NameString.ToString() : string.Empty;
|
||||
string titleNameSection = string.IsNullOrWhiteSpace(titleName) ? string.Empty : $" - {titleName}";
|
||||
string titleVersionSection = string.IsNullOrWhiteSpace(nacp.DisplayVersionString.ToString()) ? string.Empty : $" v{nacp.DisplayVersionString.ToString()}";
|
||||
string titleIdSection = string.IsNullOrWhiteSpace(activeProcess.ProgramIdText) ? string.Empty : $" ({activeProcess.ProgramIdText.ToUpper()})";
|
||||
string titleArchSection = activeProcess.Is64Bit ? " (64-bit)" : " (32-bit)";
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ using Ryujinx.Common.Logging;
|
|||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.SystemState;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using Ryujinx.HLE.Loaders.Npdm;
|
||||
using Ryujinx.HLE.Loaders.Processes.Extensions;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -440,8 +440,8 @@ namespace Ryujinx.Ava.Systems.AppLibrary
|
|||
|
||||
GetApplicationInformation(ref controlHolder.Value, ref application);
|
||||
|
||||
if ("Switch Verification" == controlHolder.Value
|
||||
.Title[(int)TitleLanguage.AmericanEnglish].NameString.ToString())
|
||||
string verifyName = NacpHelper.GetTitles(in controlHolder.Value)[(int)TitleLanguage.AmericanEnglish].NameString.ToString();
|
||||
if ("Switch Verification" == verifyName)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
|
@ -1391,10 +1391,14 @@ namespace Ryujinx.Ava.Systems.AppLibrary
|
|||
{
|
||||
_ = Enum.TryParse(DesiredLanguage.ToString(), out TitleLanguage desiredTitleLanguage);
|
||||
|
||||
if (controlData.Title.Length > (int)desiredTitleLanguage)
|
||||
int langIdx = (int)desiredTitleLanguage;
|
||||
var titles = NacpHelper.GetTitles(in controlData);
|
||||
int titleCount = titles.Length;
|
||||
|
||||
if (langIdx < titleCount)
|
||||
{
|
||||
data.Name = controlData.Title[(int)desiredTitleLanguage].NameString.ToString();
|
||||
data.Developer = controlData.Title[(int)desiredTitleLanguage].PublisherString.ToString();
|
||||
data.Name = titles[langIdx].NameString.ToString();
|
||||
data.Developer = titles[langIdx].PublisherString.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1404,12 +1408,11 @@ namespace Ryujinx.Ava.Systems.AppLibrary
|
|||
|
||||
if (string.IsNullOrWhiteSpace(data.Name))
|
||||
{
|
||||
foreach (ref readonly ApplicationControlProperty.ApplicationTitle controlTitle in controlData.Title)
|
||||
for (int i = 0; i < titleCount; i++)
|
||||
{
|
||||
if (!controlTitle.NameString.IsEmpty())
|
||||
if (!string.IsNullOrWhiteSpace(titles[i].NameString))
|
||||
{
|
||||
data.Name = controlTitle.NameString.ToString();
|
||||
|
||||
data.Name = titles[i].NameString.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1417,12 +1420,11 @@ namespace Ryujinx.Ava.Systems.AppLibrary
|
|||
|
||||
if (string.IsNullOrWhiteSpace(data.Developer))
|
||||
{
|
||||
foreach (ref readonly ApplicationControlProperty.ApplicationTitle controlTitle in controlData.Title)
|
||||
for (int i = 0; i < titleCount; i++)
|
||||
{
|
||||
if (!controlTitle.PublisherString.IsEmpty())
|
||||
if (!string.IsNullOrWhiteSpace(titles[i].PublisherString))
|
||||
{
|
||||
data.Developer = controlTitle.PublisherString.ToString();
|
||||
|
||||
data.Developer = titles[i].PublisherString.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ namespace Ryujinx.Ava.Systems.Configuration.System
|
|||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
BrazilianPortuguese,
|
||||
Polish,
|
||||
Thai,
|
||||
}
|
||||
|
||||
public static class LanguageEnumHelper
|
||||
|
|
|
|||
|
|
@ -168,7 +168,10 @@ namespace Ryujinx.Ava.UI.Views.Main
|
|||
if (!ViewModel.IsGameRunning)
|
||||
return;
|
||||
|
||||
string name = ViewModel.AppHost.Device.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)ViewModel.AppHost.Device.System.State.DesiredTitleLanguage].NameString.ToString();
|
||||
int langIdx = (int)ViewModel.AppHost.Device.System.State.DesiredTitleLanguage;
|
||||
ref readonly ApplicationControlProperty nacp = ref ViewModel.AppHost.Device.Processes.ActiveApplication.ApplicationControlProperties;
|
||||
var titles = Ryujinx.HLE.Utilities.NacpHelper.GetTitles(in nacp);
|
||||
string name = langIdx < titles.Length ? titles[langIdx].NameString.ToString() : string.Empty;
|
||||
|
||||
await StyleableAppWindow.ShowAsync(
|
||||
new CheatWindow(
|
||||
|
|
|
|||
Loading…
Reference in a new issue