diff --git a/include/nn/err.h b/include/nn/err.h index eee3a08..1488fb0 100644 --- a/include/nn/err.h +++ b/include/nn/err.h @@ -1,30 +1,40 @@ #pragma once +#include +#include +#include +#include +#include +#include +#include #include +#include namespace nn::err { -enum ErrorCodeCategoryType : uint32_t { - unk1, - unk2, -}; +class EulaData; // TODO +class ErrorViewerJumpDestination {}; // TODO -class ApplicationErrorArg { -public: - ApplicationErrorArg(); - ApplicationErrorArg(uint32_t error_code, const char* dialog_message, - const char* fullscreen_message, - const nn::settings::LanguageCode& languageCode); - void SetApplicationErrorCodeNumber(uint32_t error_code); - void SetDialogMessage(const char* message); - void SetFullScreenMessage(const char* message); - - uint64_t unk; - uint32_t error_code; - nn::settings::LanguageCode language_code; - char dialog_message[2048]; - char fullscreen_message[2048]; -}; - -uint32_t MakeErrorCode(ErrorCodeCategoryType err_category_type, uint32_t errorCodeNumber); +ErrorCode ConvertResultToErrorCode(const Result& result); +bool CreateErrorViewerStartupParamForRecordedError(void*, std::uint64_t*, std::uint64_t, + const char*, const char*, time::PosixTime); +void ExecuteJump(ErrorViewerJumpDestination destination); +void GetErrorCodeString(char* outErrorCodeString, std::size_t errorCodeStrBufferSize, + ErrorCode errorCode); +void* GetErrorMessageDatabaseVersion(ErrorMessageDatabaseVersion* outVersion); +ErrorCode MakeErrorCode(std::uint32_t category, std::uint32_t number); void ShowApplicationError(const ApplicationErrorArg& arg); +void ShowError(Result result); +void ShowError(ErrorCode errorCode); +void ShowError(const ErrorResultVariant& errorResultVariant); +void ShowError(Result result, ResultBacktrace& backtrace); +void ShowErrorRecord(Result result, time::PosixTime timestamp); +void ShowErrorRecord(ErrorCode errorCode, time::PosixTime timestamp); +void ShowErrorRecord(const void*, std::uint64_t); +void ShowErrorWithoutJump(Result result); +void ShowErrorWithoutJump(ErrorCode errorCode); +void ShowEula(settings::system::RegionCode regionCode); +void ShowSystemError(const SystemErrorArg& arg); +void ShowSystemUpdateEula(settings::system::RegionCode regionCode, EulaData& data); +void ShowUnacceptableAddOnContentVersionError(); +void ShowUnacceptableApplicationVersionError(); } // namespace nn::err diff --git a/include/nn/err/detail/err_MessageKind.h b/include/nn/err/detail/err_MessageKind.h new file mode 100644 index 0000000..28a3033 --- /dev/null +++ b/include/nn/err/detail/err_MessageKind.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace nn::err::detail { +// What does Flv stand for? +enum class MessageKind : std::uint8_t { DialogueMessage, DialogueButton, FlvMessage, FlvButton }; +} // namespace nn::err::detail diff --git a/include/nn/err/err_ApplicationErrorArg.h b/include/nn/err/err_ApplicationErrorArg.h new file mode 100644 index 0000000..680fc35 --- /dev/null +++ b/include/nn/err/err_ApplicationErrorArg.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace nn::err { +class ApplicationErrorArg { +public: + ApplicationErrorArg(); + ApplicationErrorArg(std::uint32_t errorCode, const char* dialogMessage, + const char* fullScreenMessage, const settings::LanguageCode& languageCode); + + std::uint32_t GetApplicationErrorCodeNumber() const; + const char* GetDialogMessage() const; + const char* GetFullScreenMessage() const; + settings::LanguageCode GetLanguageCode() const; + + void SetApplicationErrorCodeNumber(std::uint32_t errorCode); + void SetDialogMessage(const char* message); + void SetFullScreenMessage(const char* message); + void SetLanguageCode(const settings::LanguageCode& languageCode); + +private: + std::int8_t _0 = 2; + std::int8_t _1 = 1; + std::int8_t padding[6]; + std::uint32_t m_ErrorCode = 0; + settings::LanguageCode m_LanguageCode; + char m_DialogMessage[2048]; + char m_FullScreenMessage[2048]; +}; +} // namespace nn::err diff --git a/include/nn/err/err_ErrorCode.h b/include/nn/err/err_ErrorCode.h new file mode 100644 index 0000000..db0250c --- /dev/null +++ b/include/nn/err/err_ErrorCode.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace nn::err { +class ErrorCode { +public: + static ErrorCode GetInvalidErrorCode(); + + ErrorCode() {} + ErrorCode(std::uint32_t category, std::uint32_t number) + : m_Category(category), m_Number(number) {} + + bool IsValid() const; + + std::uint32_t GetCategory() const { return m_Category; } + std::uint32_t GetNumber() const { return m_Number; } + +private: + std::uint32_t m_Category = 0; + std::uint32_t m_Number = 0; +}; +} // namespace nn::err diff --git a/include/nn/err/err_ErrorMessageDatabaseVersion.h b/include/nn/err/err_ErrorMessageDatabaseVersion.h new file mode 100644 index 0000000..f9885bd --- /dev/null +++ b/include/nn/err/err_ErrorMessageDatabaseVersion.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace nn::err { +class ErrorMessageDatabaseVersion { +public: +private: + std::int32_t m_Version; +}; + +static_assert(sizeof(ErrorMessageDatabaseVersion) == 4); +} // namespace nn::err diff --git a/include/nn/err/err_ErrorResultVariant.h b/include/nn/err/err_ErrorResultVariant.h new file mode 100644 index 0000000..c6af17d --- /dev/null +++ b/include/nn/err/err_ErrorResultVariant.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include + +namespace nn::err { +class ErrorResultVariant { +public: + enum class State : std::uint32_t { + Undefined, + Result, + ErrorCode, + }; + + ErrorResultVariant(); + ErrorResultVariant(const Result& result); + ErrorResultVariant(const ErrorCode& errorCode); + + State GetState() const; + + operator ErrorCode() const; + operator Result() const; + + ErrorResultVariant& operator=(const Result& result); + ErrorResultVariant& operator=(const ErrorCode& errorCode); + +private: + State m_State = State::Undefined; + union { + Result m_Result; + ErrorCode m_ErrorCode; + } m_Value; +}; +} // namespace nn::err diff --git a/include/nn/err/err_ResultBacktrace.h b/include/nn/err/err_ResultBacktrace.h new file mode 100644 index 0000000..498fc39 --- /dev/null +++ b/include/nn/err/err_ResultBacktrace.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace nn::err { +class ResultBacktrace { +public: + static void Make(ResultBacktrace* outBackTrace, const Result*, std::int32_t); + +private: + // TODO +}; +} // namespace nn::err diff --git a/include/nn/err/err_SystemErrorArg.h b/include/nn/err/err_SystemErrorArg.h new file mode 100644 index 0000000..cdd22e8 --- /dev/null +++ b/include/nn/err/err_SystemErrorArg.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +namespace nn::err { +class SystemErrorArg { +public: + SystemErrorArg(); + SystemErrorArg(ErrorCode errorCode, const char* dialogMessage, const char* fullScreenMessage, + const settings::LanguageCode& languageCode); + + void SetErrorCode(ErrorCode errorCode); + void SetDialogMessage(const char* message); + void SetFullScreenMessage(const char* message); + void SetLanguageCode(const settings::LanguageCode& languageCode); + ErrorCode GetErrorCode() const; + const char* GetDialogMessage() const; + const char* GetFullScreenMessage() const; + settings::LanguageCode GetLanguageCode() const; + void GetStartupParam() const; + +private: + std::int8_t _0 = 1; + std::int8_t _1 = 0; + std::int8_t _2 = 0; + std::int8_t _3 = 0; + std::int8_t _4 = 0; + std::int8_t _5 = 0; + std::int8_t _6 = 0; + std::int8_t _7 = 0; + ErrorCode m_ErrorCode; + settings::LanguageCode m_LanguageCode; + char m_DialogMessage[2048]; + char m_FullScreenMessage[2048]; +}; +} // namespace nn::err diff --git a/include/nn/err/err_detail.h b/include/nn/err/err_detail.h new file mode 100644 index 0000000..8e2dcae --- /dev/null +++ b/include/nn/err/err_detail.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include + +namespace nn::ns { +// TODO: move +class ApplicationErrorCodeCategory { +public: + const char* GetCategory() const { return m_Category; } + +private: + char m_Category[8]; +}; +} // namespace nn::ns + +namespace nn::err { +class ErrorMessageDatabaseVersion; +} // namespace nn::err + +namespace nn::err::detail { +bool CategoryExists(std::uint32_t category); +bool DefaultErrorMessageDataExists(std::uint32_t category); +bool ErrorMessageDataExists(ErrorCode errorCode); +bool IsApplicationErrorCodeString(const char* errorCodeString); +void MakeApplicationErrorCodeString( + char* outErrorCodeString, std::size_t errorCodeStringBufferSize, + const ns::ApplicationErrorCodeCategory& applicationErrorCodeCategory, + std::uint32_t errorCodeNumber); +void MakeErrorCodeString(char* outErrorCodeString, std::size_t errorCodeStringBufferSize, + ErrorCode errorCode); +void MakeErrorInfoCommonFilePath(char* outErrorInfoCommonFilePath, + std::size_t errorInfoCommonFilePathBufferSize, + ErrorCode errorCode); +void MakeErrorInfoDirectoryPath(char* outErrorInfoDirectoryPath, + std::size_t errorInfoDirectoryPathBufferSize, ErrorCode errorCode); +void MakeErrorInfoMessageFilePath(char* outErrorInfoMessageFilePath, + std::size_t errorInfoMessageFilePathBufferSize, + ErrorCode errorCode, settings::LanguageCode languageCode, + MessageKind messageKind); +void MakeErrorInfoModuleDirectoryPath(char* outErrorInfoModuleDirectoryPath, + std::size_t errorInfoModuleDirectoryPathBufferSize, + std::uint32_t errorCodeCategory); +void ParseApplicationErrorCodeString( + ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory, + std::uint32_t* outErrorCodeCategoryNumber, const char* errorCodeString); +void ParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString); +void* ReadMessageFile(char16_t* outBuffer, std::int32_t* outMessageLength, + std::size_t messageBufferSize, ErrorCode errorCode, + settings::LanguageCode languageCode, MessageKind messageKind); +void ReadMessageFile(char16_t* outBuffer, std::size_t bufferSize, const char* errorCodeString, + const settings::LanguageCode& languageCode); +void ReadVersion(ErrorMessageDatabaseVersion* outVersion); +bool TryParseApplicationErrorCodeString( + ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory, + std::uint32_t* outErrorCodeCategoryNumber, const char* errorCodeString); +bool TryParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString); +} // namespace nn::err::detail diff --git a/include/nn/fs/fs_Mount.h b/include/nn/fs/fs_Mount.h index f65d594..cfdc0d7 100644 --- a/include/nn/fs/fs_Mount.h +++ b/include/nn/fs/fs_Mount.h @@ -3,6 +3,10 @@ #include #include +namespace nn::ncm { +enum class SystemDataId : std::uint64_t { Err = 0x10000000000801 }; // TODO: move +} // namespace nn::ncm + namespace nn::fs { /* @@ -12,6 +16,7 @@ namespace nn::fs { bool MountSdCardForDebug(const char* mount); Result MountSdCard(const char* mountPoint); +Result MountSystemData(const char* mountPoint, ncm::SystemDataId id); bool IsSdCardInserted(); Result FormatSdCard(); Result FormatSdCardDryRun(); diff --git a/include/nn/settings.h b/include/nn/settings.h index ba99ee1..c2cb6ca 100644 --- a/include/nn/settings.h +++ b/include/nn/settings.h @@ -53,6 +53,10 @@ struct FirmwareVersion { } }; +struct RegionCode { + std::int32_t code; +}; + Result GetFirmwareVersion(FirmwareVersion*); } // namespace system diff --git a/include/vapours/results/results_common.hpp b/include/vapours/results/results_common.hpp index e124af0..6795f45 100644 --- a/include/vapours/results/results_common.hpp +++ b/include/vapours/results/results_common.hpp @@ -55,6 +55,10 @@ namespace nn { static BaseType GetDescriptionFromValue(BaseType value) noexcept { return GetBitsValue(value, ModuleBits, DescriptionBits); } + + static BaseType GetInnerValue(BaseType value) noexcept { + return GetBitsValue(value, 0, ModuleBits + DescriptionBits); + } }; /* Use CRTP for Results. */ @@ -64,12 +68,16 @@ namespace nn { using BaseType = typename ResultTraits::BaseType; static const BaseType SuccessValue = ResultTraits::SuccessValue; - int GetModule() const noexcept { - return static_cast(ResultTraits::GetModuleFromValue(static_cast(*this).GetInnerValueForDebug())); + __attribute__((always_inline)) BaseType GetModule() const noexcept { + return ResultTraits::GetModuleFromValue(static_cast(*this).GetInnerValueForDebug()); + } + + __attribute__((always_inline)) BaseType GetDescription() const noexcept { + return ResultTraits::GetDescriptionFromValue(static_cast(*this).GetInnerValueForDebug()); } - int GetDescription() const noexcept { - return static_cast(ResultTraits::GetDescriptionFromValue(static_cast(*this).GetInnerValueForDebug())); + __attribute__((always_inline)) BaseType GetValue() const noexcept { + return ResultTraits::GetInnerValue(static_cast(*this).GetInnerValueForDebug()); } }; @@ -95,11 +103,14 @@ namespace nn { bool IsSuccess() const noexcept { return m_value == SuccessValue; } bool IsFailure() const noexcept { return !IsSuccess(); } + bool operator==(Result other) const noexcept { return GetValue() == other.GetValue(); } + bool operator!=(Result other) const noexcept { return !operator==(other); } operator ResultSuccess() const noexcept; static bool CanAccept(Result result) noexcept; - int GetModule() const noexcept { return Base::GetModule(); } - int GetDescription() const noexcept { return Base::GetDescription(); } + __attribute__((always_inline)) BaseType GetModule() const noexcept { return Base::GetModule(); } + __attribute__((always_inline)) BaseType GetDescription() const noexcept { return Base::GetDescription(); } + __attribute__((always_inline)) BaseType GetValue() const noexcept { return Base::GetValue(); } }; static_assert(sizeof(Result) == sizeof(result::detail::ResultTraits::BaseType), "sizeof(Result) == sizeof(detail::ResultTraits::BaseType)"); static_assert(std::is_trivially_destructible::value, "std::is_trivially_destructible::value");