Refactoring HOS folder structure (#771)
* Refactoring HOS folder structure Refactoring HOS folder structure: - Added some subfolders when needed (Following structure decided in private). - Added some `Types` folders when needed. - Little cleanup here and there. - Add services placeholders for every HOS services (close #766 and #753). * Remove Types namespaces
This commit is contained in:
parent
4af3101b22
commit
a0720b5681
393 changed files with 2540 additions and 1299 deletions
|
@ -0,0 +1,8 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Am.Tcap
|
||||
{
|
||||
[Service("set:cal")]
|
||||
class IFactorySettingsServer : IpcService
|
||||
{
|
||||
public IFactorySettingsServer(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Settings
|
||||
{
|
||||
[Service("set:fd")]
|
||||
class IFirmwareDebugSettingsServer : IpcService
|
||||
{
|
||||
public IFirmwareDebugSettingsServer(ServiceCtx context) { }
|
||||
}
|
||||
}
|
109
Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs
Normal file
109
Ryujinx.HLE/HOS/Services/Settings/ISettingsServer.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.SystemState;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Settings
|
||||
{
|
||||
[Service("set")]
|
||||
class ISettingsServer : IpcService
|
||||
{
|
||||
public ISettingsServer(ServiceCtx context) { }
|
||||
|
||||
[Command(0)]
|
||||
// GetLanguageCode() -> nn::settings::LanguageCode
|
||||
public ResultCode GetLanguageCode(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(context.Device.System.State.DesiredLanguageCode);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(1)]
|
||||
// GetAvailableLanguageCodes() -> (u32, buffer<nn::settings::LanguageCode, 0xa>)
|
||||
public ResultCode GetAvailableLanguageCodes(ServiceCtx context)
|
||||
{
|
||||
return GetAvailableLanguagesCodesImpl(
|
||||
context,
|
||||
context.Request.RecvListBuff[0].Position,
|
||||
context.Request.RecvListBuff[0].Size,
|
||||
0xF);
|
||||
}
|
||||
|
||||
[Command(2)] // 4.0.0+
|
||||
// MakeLanguageCode(nn::settings::Language language_index) -> nn::settings::LanguageCode
|
||||
public ResultCode MakeLanguageCode(ServiceCtx context)
|
||||
{
|
||||
int languageIndex = context.RequestData.ReadInt32();
|
||||
|
||||
if ((uint)languageIndex >= (uint)SystemStateMgr.LanguageCodes.Length)
|
||||
{
|
||||
return ResultCode.LanguageOutOfRange;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(SystemStateMgr.GetLanguageCode(languageIndex));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(3)]
|
||||
// GetAvailableLanguageCodeCount() -> u32
|
||||
public ResultCode GetAvailableLanguageCodeCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(Math.Min(SystemStateMgr.LanguageCodes.Length, 0xF));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(5)]
|
||||
// GetAvailableLanguageCodes2() -> (u32, buffer<nn::settings::LanguageCode, 6>)
|
||||
public ResultCode GetAvailableLanguageCodes2(ServiceCtx context)
|
||||
{
|
||||
return GetAvailableLanguagesCodesImpl(
|
||||
context,
|
||||
context.Request.ReceiveBuff[0].Position,
|
||||
context.Request.ReceiveBuff[0].Size,
|
||||
SystemStateMgr.LanguageCodes.Length);
|
||||
}
|
||||
|
||||
[Command(6)]
|
||||
// GetAvailableLanguageCodeCount2() -> u32
|
||||
public ResultCode GetAvailableLanguageCodeCount2(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(SystemStateMgr.LanguageCodes.Length);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(8)] // 5.0.0+
|
||||
// GetQuestFlag() -> bool
|
||||
public ResultCode GetQuestFlag(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(false);
|
||||
|
||||
Logger.PrintStub(LogClass.ServiceSet);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public ResultCode GetAvailableLanguagesCodesImpl(ServiceCtx context, long position, long size, int maxSize)
|
||||
{
|
||||
int count = (int)(size / 8);
|
||||
|
||||
if (count > maxSize)
|
||||
{
|
||||
count = maxSize;
|
||||
}
|
||||
|
||||
for (int index = 0; index < count; index++)
|
||||
{
|
||||
context.Memory.WriteInt64(position, SystemStateMgr.GetLanguageCode(index));
|
||||
|
||||
position += 8;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
198
Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs
Normal file
198
Ryujinx.HLE/HOS/Services/Settings/ISystemSettingsServer.cs
Normal file
|
@ -0,0 +1,198 @@
|
|||
using LibHac.Fs;
|
||||
using LibHac.Fs.NcaUtils;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.SystemState;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Settings
|
||||
{
|
||||
[Service("set:sys")]
|
||||
class ISystemSettingsServer : IpcService
|
||||
{
|
||||
public ISystemSettingsServer(ServiceCtx context) { }
|
||||
|
||||
[Command(3)]
|
||||
// GetFirmwareVersion() -> buffer<nn::settings::system::FirmwareVersion, 0x1a, 0x100>
|
||||
public ResultCode GetFirmwareVersion(ServiceCtx context)
|
||||
{
|
||||
return GetFirmwareVersion2(context);
|
||||
}
|
||||
|
||||
[Command(4)]
|
||||
// GetFirmwareVersion2() -> buffer<nn::settings::system::FirmwareVersion, 0x1a, 0x100>
|
||||
public ResultCode GetFirmwareVersion2(ServiceCtx context)
|
||||
{
|
||||
long replyPos = context.Request.RecvListBuff[0].Position;
|
||||
long replySize = context.Request.RecvListBuff[0].Size;
|
||||
|
||||
byte[] firmwareData = GetFirmwareData(context.Device);
|
||||
|
||||
if (firmwareData != null)
|
||||
{
|
||||
context.Memory.WriteBytes(replyPos, firmwareData);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
const byte majorFwVersion = 0x03;
|
||||
const byte minorFwVersion = 0x00;
|
||||
const byte microFwVersion = 0x00;
|
||||
const byte unknown = 0x00; //Build?
|
||||
|
||||
const int revisionNumber = 0x0A;
|
||||
|
||||
const string platform = "NX";
|
||||
const string unknownHex = "7fbde2b0bba4d14107bf836e4643043d9f6c8e47";
|
||||
const string version = "3.0.0";
|
||||
const string build = "NintendoSDK Firmware for NX 3.0.0-10.0";
|
||||
|
||||
// http://switchbrew.org/index.php?title=System_Version_Title
|
||||
using (MemoryStream ms = new MemoryStream(0x100))
|
||||
{
|
||||
BinaryWriter writer = new BinaryWriter(ms);
|
||||
|
||||
writer.Write(majorFwVersion);
|
||||
writer.Write(minorFwVersion);
|
||||
writer.Write(microFwVersion);
|
||||
writer.Write(unknown);
|
||||
|
||||
writer.Write(revisionNumber);
|
||||
|
||||
writer.Write(Encoding.ASCII.GetBytes(platform));
|
||||
|
||||
ms.Seek(0x28, SeekOrigin.Begin);
|
||||
|
||||
writer.Write(Encoding.ASCII.GetBytes(unknownHex));
|
||||
|
||||
ms.Seek(0x68, SeekOrigin.Begin);
|
||||
|
||||
writer.Write(Encoding.ASCII.GetBytes(version));
|
||||
|
||||
ms.Seek(0x80, SeekOrigin.Begin);
|
||||
|
||||
writer.Write(Encoding.ASCII.GetBytes(build));
|
||||
|
||||
context.Memory.WriteBytes(replyPos, ms.ToArray());
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(23)]
|
||||
// GetColorSetId() -> i32
|
||||
public ResultCode GetColorSetId(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write((int)context.Device.System.State.ThemeColor);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(24)]
|
||||
// GetColorSetId() -> i32
|
||||
public ResultCode SetColorSetId(ServiceCtx context)
|
||||
{
|
||||
int colorSetId = context.RequestData.ReadInt32();
|
||||
|
||||
context.Device.System.State.ThemeColor = (ColorSet)colorSetId;
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[Command(38)]
|
||||
// GetSettingsItemValue(buffer<nn::settings::SettingsName, 0x19, 0x48>, buffer<nn::settings::SettingsItemKey, 0x19, 0x48>) -> (u64, buffer<unknown, 6, 0>)
|
||||
public ResultCode GetSettingsItemValue(ServiceCtx context)
|
||||
{
|
||||
long classPos = context.Request.PtrBuff[0].Position;
|
||||
long classSize = context.Request.PtrBuff[0].Size;
|
||||
|
||||
long namePos = context.Request.PtrBuff[1].Position;
|
||||
long nameSize = context.Request.PtrBuff[1].Size;
|
||||
|
||||
long replyPos = context.Request.ReceiveBuff[0].Position;
|
||||
long replySize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
byte[] Class = context.Memory.ReadBytes(classPos, classSize);
|
||||
byte[] name = context.Memory.ReadBytes(namePos, nameSize);
|
||||
|
||||
string askedSetting = Encoding.ASCII.GetString(Class).Trim('\0') + "!" + Encoding.ASCII.GetString(name).Trim('\0');
|
||||
|
||||
NxSettings.Settings.TryGetValue(askedSetting, out object nxSetting);
|
||||
|
||||
if (nxSetting != null)
|
||||
{
|
||||
byte[] settingBuffer = new byte[replySize];
|
||||
|
||||
if (nxSetting is string stringValue)
|
||||
{
|
||||
if (stringValue.Length + 1 > replySize)
|
||||
{
|
||||
Logger.PrintError(LogClass.ServiceSet, $"{askedSetting} String value size is too big!");
|
||||
}
|
||||
else
|
||||
{
|
||||
settingBuffer = Encoding.ASCII.GetBytes(stringValue + "\0");
|
||||
}
|
||||
}
|
||||
|
||||
if (nxSetting is int intValue)
|
||||
{
|
||||
settingBuffer = BitConverter.GetBytes(intValue);
|
||||
}
|
||||
else if (nxSetting is bool boolValue)
|
||||
{
|
||||
settingBuffer[0] = boolValue ? (byte)1 : (byte)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(nxSetting.GetType().Name);
|
||||
}
|
||||
|
||||
context.Memory.WriteBytes(replyPos, settingBuffer);
|
||||
|
||||
Logger.PrintDebug(LogClass.ServiceSet, $"{askedSetting} set value: {nxSetting} as {nxSetting.GetType()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.PrintError(LogClass.ServiceSet, $"{askedSetting} not found!");
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public byte[] GetFirmwareData(Switch device)
|
||||
{
|
||||
long titleId = 0x0100000000000809;
|
||||
string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, ContentType.Data);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath);
|
||||
|
||||
using(IStorage firmwareStorage = new LocalStorage(firmwareTitlePath, FileAccess.Read))
|
||||
{
|
||||
Nca firmwareContent = new Nca(device.System.KeySet, firmwareStorage);
|
||||
|
||||
if (!firmwareContent.CanOpenSection(NcaSectionType.Data))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IFileSystem firmwareRomFs = firmwareContent.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel);
|
||||
|
||||
IFile firmwareFile = firmwareRomFs.OpenFile("/file", OpenMode.Read);
|
||||
|
||||
byte[] data = new byte[firmwareFile.GetSize()];
|
||||
|
||||
firmwareFile.Read(data, 0);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1711
Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs
Normal file
1711
Ryujinx.HLE/HOS/Services/Settings/NxSettings.cs
Normal file
File diff suppressed because it is too large
Load diff
12
Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs
Normal file
12
Ryujinx.HLE/HOS/Services/Settings/ResultCode.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Settings
|
||||
{
|
||||
enum ResultCode
|
||||
{
|
||||
ModuleId = 105,
|
||||
ErrorCodeShift = 9,
|
||||
|
||||
Success = 0,
|
||||
|
||||
LanguageOutOfRange = (625 << ErrorCodeShift) | ModuleId
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue