Refactoring result codes (#731)

* refactoring result codes

- Add a main enum who can handle some orphalin result codes and the default `ResultCode.Success` one.
- Add sub-enum by services when it's needed.
- Remove some empty line.
- Recast all service calls to ResultCode.
- Remove some unneeded static declaration.
- Delete unused `NvHelper` class.

* NvResult is back

* Fix
This commit is contained in:
Ac_K 2019-07-14 21:04:38 +02:00 committed by gdkchan
parent 4926f6523d
commit 4ad3936afd
147 changed files with 1413 additions and 1477 deletions

View file

@ -2,8 +2,6 @@ using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.SystemState;
using System;
using static Ryujinx.HLE.HOS.ErrorCode;
namespace Ryujinx.HLE.HOS.Services.Set
{
[Service("set")]
@ -13,16 +11,16 @@ namespace Ryujinx.HLE.HOS.Services.Set
[Command(0)]
// GetLanguageCode() -> nn::settings::LanguageCode
public static long GetLanguageCode(ServiceCtx context)
public ResultCode GetLanguageCode(ServiceCtx context)
{
context.ResponseData.Write(context.Device.System.State.DesiredLanguageCode);
return 0;
return ResultCode.Success;
}
[Command(1)]
// GetAvailableLanguageCodes() -> (u32, buffer<nn::settings::LanguageCode, 0xa>)
public static long GetAvailableLanguageCodes(ServiceCtx context)
public ResultCode GetAvailableLanguageCodes(ServiceCtx context)
{
return GetAvailableLanguagesCodesImpl(
context,
@ -33,32 +31,32 @@ namespace Ryujinx.HLE.HOS.Services.Set
[Command(2)] // 4.0.0+
// MakeLanguageCode(nn::settings::Language language_index) -> nn::settings::LanguageCode
public static long MakeLanguageCode(ServiceCtx context)
public ResultCode MakeLanguageCode(ServiceCtx context)
{
int languageIndex = context.RequestData.ReadInt32();
if ((uint)languageIndex >= (uint)SystemStateMgr.LanguageCodes.Length)
{
return MakeError(ErrorModule.Settings, SettingsError.LanguageOutOfRange);
return ResultCode.LanguageOutOfRange;
}
context.ResponseData.Write(SystemStateMgr.GetLanguageCode(languageIndex));
return 0;
return ResultCode.Success;
}
[Command(3)]
// GetAvailableLanguageCodeCount() -> u32
public static long GetAvailableLanguageCodeCount(ServiceCtx context)
public ResultCode GetAvailableLanguageCodeCount(ServiceCtx context)
{
context.ResponseData.Write(Math.Min(SystemStateMgr.LanguageCodes.Length, 0xF));
return 0;
return ResultCode.Success;
}
[Command(5)]
// GetAvailableLanguageCodes2() -> (u32, buffer<nn::settings::LanguageCode, 6>)
public static long GetAvailableLanguageCodes2(ServiceCtx context)
public ResultCode GetAvailableLanguageCodes2(ServiceCtx context)
{
return GetAvailableLanguagesCodesImpl(
context,
@ -69,25 +67,25 @@ namespace Ryujinx.HLE.HOS.Services.Set
[Command(6)]
// GetAvailableLanguageCodeCount2() -> u32
public static long GetAvailableLanguageCodeCount2(ServiceCtx context)
public ResultCode GetAvailableLanguageCodeCount2(ServiceCtx context)
{
context.ResponseData.Write(SystemStateMgr.LanguageCodes.Length);
return 0;
return ResultCode.Success;
}
[Command(8)] // 5.0.0+
// GetQuestFlag() -> bool
public static long GetQuestFlag(ServiceCtx context)
public ResultCode GetQuestFlag(ServiceCtx context)
{
context.ResponseData.Write(false);
Logger.PrintStub(LogClass.ServiceSet);
return 0;
return ResultCode.Success;
}
public static long GetAvailableLanguagesCodesImpl(ServiceCtx context, long position, long size, int maxSize)
public ResultCode GetAvailableLanguagesCodesImpl(ServiceCtx context, long position, long size, int maxSize)
{
int count = (int)(size / 8);
@ -105,7 +103,7 @@ namespace Ryujinx.HLE.HOS.Services.Set
context.ResponseData.Write(count);
return 0;
return ResultCode.Success;
}
}
}

View file

@ -16,14 +16,14 @@ namespace Ryujinx.HLE.HOS.Services.Set
[Command(3)]
// GetFirmwareVersion() -> buffer<nn::settings::system::FirmwareVersion, 0x1a, 0x100>
public static long GetFirmwareVersion(ServiceCtx context)
public ResultCode GetFirmwareVersion(ServiceCtx context)
{
return GetFirmwareVersion2(context);
}
[Command(4)]
// GetFirmwareVersion2() -> buffer<nn::settings::system::FirmwareVersion, 0x1a, 0x100>
public static long GetFirmwareVersion2(ServiceCtx context)
public ResultCode GetFirmwareVersion2(ServiceCtx context)
{
long replyPos = context.Request.RecvListBuff[0].Position;
long replySize = context.Request.RecvListBuff[0].Size;
@ -34,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Set
{
context.Memory.WriteBytes(replyPos, firmwareData);
return 0;
return ResultCode.Success;
}
const byte majorFwVersion = 0x03;
@ -78,32 +78,32 @@ namespace Ryujinx.HLE.HOS.Services.Set
context.Memory.WriteBytes(replyPos, ms.ToArray());
}
return 0;
return ResultCode.Success;
}
[Command(23)]
// GetColorSetId() -> i32
public static long GetColorSetId(ServiceCtx context)
public ResultCode GetColorSetId(ServiceCtx context)
{
context.ResponseData.Write((int)context.Device.System.State.ThemeColor);
return 0;
return ResultCode.Success;
}
[Command(24)]
// GetColorSetId() -> i32
public static long SetColorSetId(ServiceCtx context)
public ResultCode SetColorSetId(ServiceCtx context)
{
int colorSetId = context.RequestData.ReadInt32();
context.Device.System.State.ThemeColor = (ColorSet)colorSetId;
return 0;
return ResultCode.Success;
}
[Command(38)]
// GetSettingsItemValue(buffer<nn::settings::SettingsName, 0x19, 0x48>, buffer<nn::settings::SettingsItemKey, 0x19, 0x48>) -> (u64, buffer<unknown, 6, 0>)
public static long GetSettingsItemValue(ServiceCtx context)
public ResultCode GetSettingsItemValue(ServiceCtx context)
{
long classPos = context.Request.PtrBuff[0].Position;
long classSize = context.Request.PtrBuff[0].Size;
@ -159,10 +159,10 @@ namespace Ryujinx.HLE.HOS.Services.Set
Logger.PrintError(LogClass.ServiceSet, $"{askedSetting} not found!");
}
return 0;
return ResultCode.Success;
}
public static byte[] GetFirmwareData(Switch device)
public byte[] GetFirmwareData(Switch device)
{
long titleId = 0x0100000000000809;
string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, ContentType.Data);

View file

@ -1708,4 +1708,4 @@ namespace Ryujinx.HLE.HOS.Services.Set
{ "wlan_debug!skip_wlan_boot", false }
};
}
}
}

View file

@ -0,0 +1,12 @@
namespace Ryujinx.HLE.HOS.Services.Set
{
enum ResultCode
{
ModuleId = 105,
ErrorCodeShift = 9,
Success = 0,
LanguageOutOfRange = (625 << ErrorCodeShift) | ModuleId
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.HLE.HOS.Services.Set
{
static class SettingsError
{
public const int LanguageOutOfRange = 625;
}
}