Archived
1
0
Fork 0
forked from Mirror/Ryujinx

Show Game Title on Titlebar (#408)

* support reading control data

* show game info on titlebar

* use first language is default is not available

* use seperate language enums for titles

* fix hex display
This commit is contained in:
emmauss 2018-09-19 15:09:49 +03:00 committed by Thomas Guillemard
parent b8133c1997
commit fae097408e
5 changed files with 119 additions and 18 deletions

View file

@ -47,6 +47,10 @@ namespace Ryujinx.HLE.HOS
private bool HasStarted; private bool HasStarted;
public Nacp ControlData { get; set; }
public string CurrentTitle { get; private set; }
public Horizon(Switch Device) public Horizon(Switch Device)
{ {
this.Device = Device; this.Device = Device;
@ -137,6 +141,8 @@ namespace Ryujinx.HLE.HOS
throw new NotImplementedException("32-bit titles are unsupported!"); throw new NotImplementedException("32-bit titles are unsupported!");
} }
CurrentTitle = MainProcess.MetaData.ACI0.TitleId.ToString("x16");
LoadNso("rtld"); LoadNso("rtld");
MainProcess.SetEmptyArgs(); MainProcess.SetEmptyArgs();
@ -154,27 +160,28 @@ namespace Ryujinx.HLE.HOS
Xci Xci = new Xci(KeySet, File); Xci Xci = new Xci(KeySet, File);
Nca Nca = GetXciMainNca(Xci); (Nca MainNca, Nca ControlNca) = GetXciGameData(Xci);
if (Nca == null) if (MainNca == null)
{ {
Device.Log.PrintError(LogClass.Loader, "Unable to load XCI"); Device.Log.PrintError(LogClass.Loader, "Unable to load XCI");
return; return;
} }
LoadNca(Nca); LoadNca(MainNca, ControlNca);
} }
private Nca GetXciMainNca(Xci Xci) private (Nca Main, Nca Control) GetXciGameData(Xci Xci)
{ {
if (Xci.SecurePartition == null) if (Xci.SecurePartition == null)
{ {
throw new InvalidDataException("Could not find XCI secure partition"); throw new InvalidDataException("Could not find XCI secure partition");
} }
Nca MainNca = null; Nca MainNca = null;
Nca PatchNca = null; Nca PatchNca = null;
Nca ControlNca = null;
foreach (PfsFileEntry FileEntry in Xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".nca"))) foreach (PfsFileEntry FileEntry in Xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".nca")))
{ {
@ -193,6 +200,10 @@ namespace Ryujinx.HLE.HOS
PatchNca = Nca; PatchNca = Nca;
} }
} }
else if (Nca.Header.ContentType == ContentType.Control)
{
ControlNca = Nca;
}
} }
if (MainNca == null) if (MainNca == null)
@ -201,8 +212,24 @@ namespace Ryujinx.HLE.HOS
} }
MainNca.SetBaseNca(PatchNca); MainNca.SetBaseNca(PatchNca);
if (ControlNca != null)
{
ReadControlData(ControlNca);
}
return MainNca; return (MainNca, ControlNca);
}
public void ReadControlData(Nca ControlNca)
{
Romfs ControlRomfs = new Romfs(ControlNca.OpenSection(0, false));
byte[] ControlFile = ControlRomfs.GetFile("/control.nacp");
BinaryReader Reader = new BinaryReader(new MemoryStream(ControlFile));
ControlData = new Nacp(Reader);
} }
public void LoadNca(string NcaFile) public void LoadNca(string NcaFile)
@ -211,7 +238,7 @@ namespace Ryujinx.HLE.HOS
Nca Nca = new Nca(KeySet, File, true); Nca Nca = new Nca(KeySet, File, true);
LoadNca(Nca); LoadNca(Nca, null);
} }
public void LoadNsp(string NspFile) public void LoadNsp(string NspFile)
@ -231,25 +258,37 @@ namespace Ryujinx.HLE.HOS
KeySet.TitleKeys[Ticket.RightsId] = Ticket.GetTitleKey(KeySet); KeySet.TitleKeys[Ticket.RightsId] = Ticket.GetTitleKey(KeySet);
} }
Nca MainNca = null;
Nca ControlNca = null;
foreach (PfsFileEntry NcaFile in Nsp.Files.Where(x => x.Name.EndsWith(".nca"))) foreach (PfsFileEntry NcaFile in Nsp.Files.Where(x => x.Name.EndsWith(".nca")))
{ {
Nca Nca = new Nca(KeySet, Nsp.OpenFile(NcaFile), true); Nca Nca = new Nca(KeySet, Nsp.OpenFile(NcaFile), true);
if (Nca.Header.ContentType == ContentType.Program) if (Nca.Header.ContentType == ContentType.Program)
{ {
LoadNca(Nca); MainNca = Nca;
return;
} }
else if (Nca.Header.ContentType == ContentType.Control)
{
ControlNca = Nca;
}
}
if (MainNca != null)
{
LoadNca(MainNca, ControlNca);
return;
} }
Device.Log.PrintError(LogClass.Loader, "Could not find an Application NCA in the provided NSP file"); Device.Log.PrintError(LogClass.Loader, "Could not find an Application NCA in the provided NSP file");
} }
public void LoadNca(Nca Nca) public void LoadNca(Nca MainNca, Nca ControlNca)
{ {
NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs); NcaSection RomfsSection = MainNca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
NcaSection ExefsSection = Nca.Sections.FirstOrDefault(x => x?.IsExefs == true); NcaSection ExefsSection = MainNca.Sections.FirstOrDefault(x => x?.IsExefs == true);
if (ExefsSection == null) if (ExefsSection == null)
{ {
@ -265,10 +304,12 @@ namespace Ryujinx.HLE.HOS
return; return;
} }
Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false); Stream RomfsStream = MainNca.OpenSection(RomfsSection.SectionNum, false);
Device.FileSystem.SetRomFs(RomfsStream); Device.FileSystem.SetRomFs(RomfsStream);
Stream ExefsStream = Nca.OpenSection(ExefsSection.SectionNum, false); Stream ExefsStream = MainNca.OpenSection(ExefsSection.SectionNum, false);
Pfs Exefs = new Pfs(ExefsStream); Pfs Exefs = new Pfs(ExefsStream);
Npdm MetaData = null; Npdm MetaData = null;
@ -305,6 +346,35 @@ namespace Ryujinx.HLE.HOS
} }
} }
Nacp ReadControlData()
{
Romfs ControlRomfs = new Romfs(ControlNca.OpenSection(0, false));
byte[] ControlFile = ControlRomfs.GetFile("/control.nacp");
BinaryReader Reader = new BinaryReader(new MemoryStream(ControlFile));
Nacp ControlData = new Nacp(Reader);
CurrentTitle = ControlData.Languages[(int)State.DesiredTitleLanguage].Title;
if (string.IsNullOrWhiteSpace(CurrentTitle))
{
CurrentTitle = ControlData.Languages.ToList().Find(x => !string.IsNullOrWhiteSpace(x.Title)).Title;
}
return ControlData;
}
if (ControlNca != null)
{
MainProcess.ControlData = ReadControlData();
}
else
{
CurrentTitle = MainProcess.MetaData.ACI0.TitleId.ToString("x16");
}
if (!MainProcess.MetaData.Is64Bits) if (!MainProcess.MetaData.Is64Bits)
{ {
throw new NotImplementedException("32-bit titles are unsupported!"); throw new NotImplementedException("32-bit titles are unsupported!");

View file

@ -2,6 +2,7 @@ using ChocolArm64;
using ChocolArm64.Events; using ChocolArm64.Events;
using ChocolArm64.Memory; using ChocolArm64.Memory;
using ChocolArm64.State; using ChocolArm64.State;
using LibHac;
using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Diagnostics.Demangler; using Ryujinx.HLE.HOS.Diagnostics.Demangler;
using Ryujinx.HLE.HOS.Kernel; using Ryujinx.HLE.HOS.Kernel;
@ -42,6 +43,8 @@ namespace Ryujinx.HLE.HOS
public Npdm MetaData { get; private set; } public Npdm MetaData { get; private set; }
public Nacp ControlData { get; set; }
public KProcessHandleTable HandleTable { get; private set; } public KProcessHandleTable HandleTable { get; private set; }
public AppletStateMgr AppletState { get; private set; } public AppletStateMgr AppletState { get; private set; }

View file

@ -37,6 +37,8 @@ namespace Ryujinx.HLE.HOS.SystemState
internal long DesiredLanguageCode { get; private set; } internal long DesiredLanguageCode { get; private set; }
public TitleLanguage DesiredTitleLanguage { get; private set; }
internal string ActiveAudioOutput { get; private set; } internal string ActiveAudioOutput { get; private set; }
public bool DockedMode { get; set; } public bool DockedMode { get; set; }
@ -64,6 +66,8 @@ namespace Ryujinx.HLE.HOS.SystemState
public void SetLanguage(SystemLanguage Language) public void SetLanguage(SystemLanguage Language)
{ {
DesiredLanguageCode = GetLanguageCode((int)Language); DesiredLanguageCode = GetLanguageCode((int)Language);
DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), Language));
} }
public void SetAudioOutputAsTv() public void SetAudioOutputAsTv()

View file

@ -0,0 +1,21 @@
namespace Ryujinx.HLE.HOS.SystemState
{
public enum TitleLanguage
{
AmericanEnglish,
BritishEnglish,
Japanese,
French,
German,
LatinAmericanSpanish,
Spanish,
Italian,
Dutch,
CanadianFrench,
Portuguese,
Russian,
Korean,
Taiwanese,
Chinese
}
}

View file

@ -258,8 +258,11 @@ namespace Ryujinx
double HostFps = Device.Statistics.GetSystemFrameRate(); double HostFps = Device.Statistics.GetSystemFrameRate();
double GameFps = Device.Statistics.GetGameFrameRate(); double GameFps = Device.Statistics.GetGameFrameRate();
NewTitle = $"Ryujinx | Host FPS: {HostFps:0.0} | Game FPS: {GameFps:0.0} | Game Vsync: " + string TitleSection = string.IsNullOrWhiteSpace(Device.System.CurrentTitle) ? string.Empty
(Device.EnableDeviceVsync ? "On" : "Off"); : " | " + Device.System.CurrentTitle;
NewTitle = $"Ryujinx{TitleSection} | Host FPS: {HostFps:0.0} | Game FPS: {GameFps:0.0} | " +
$"Game Vsync: {(Device.EnableDeviceVsync ? "On" : "Off")}";
TitleEvent = true; TitleEvent = true;