From 6ae374100bc5c3f6d6f449b1c9666bd001acb63c Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 22 Oct 2023 02:31:32 +0200 Subject: [PATCH] early-access version 3941 --- README.md | 2 +- src/common/thread.cpp | 24 +-------- .../system_archive/system_version.cpp | 4 ++ src/core/hle/service/ptm/ts.cpp | 40 ++++++++++++++- src/core/hle/service/ptm/ts.h | 6 +-- src/core/hle/service/set/set_sys.cpp | 49 ++++++++++++------- 6 files changed, 77 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 510b109b1..d0d3de64f 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3940. +This is the source code for early-access 3941. ## Legal Notice diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 223c3d2ab..6cdb648dd 100755 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -11,6 +11,7 @@ #include #elif defined(_WIN32) #include +#include "common/string_util.h" #else #if defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) #include @@ -82,29 +83,8 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { #ifdef _MSC_VER // Sets the debugger-visible name of the current thread. -// Uses trick documented in: -// https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code void SetCurrentThreadName(const char* name) { - static const DWORD MS_VC_EXCEPTION = 0x406D1388; - -#pragma pack(push, 8) - struct THREADNAME_INFO { - DWORD dwType; // must be 0x1000 - LPCSTR szName; // pointer to name (in user addr space) - DWORD dwThreadID; // thread ID (-1=caller thread) - DWORD dwFlags; // reserved for future use, must be zero - } info; -#pragma pack(pop) - - info.dwType = 0x1000; - info.szName = name; - info.dwThreadID = std::numeric_limits::max(); - info.dwFlags = 0; - - __try { - RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); - } __except (EXCEPTION_CONTINUE_EXECUTION) { - } + SetThreadDescription(GetCurrentThread(), UTF8ToUTF16W(name).data()); } #else // !MSVC_VER, so must be POSIX threads diff --git a/src/core/file_sys/system_archive/system_version.cpp b/src/core/file_sys/system_archive/system_version.cpp index 1ad40c1cc..1152b2731 100755 --- a/src/core/file_sys/system_archive/system_version.cpp +++ b/src/core/file_sys/system_archive/system_version.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "common/logging/log.h" #include "core/file_sys/system_archive/system_version.h" #include "core/file_sys/vfs_vector.h" #include "core/hle/api_version.h" @@ -12,6 +13,9 @@ std::string GetLongDisplayVersion() { } VirtualDir SystemVersion() { + LOG_WARNING(Common_Filesystem, "called - Using hardcoded firmware version '{}'", + GetLongDisplayVersion()); + VirtualFile file = std::make_shared(std::vector(0x100), "file"); file->WriteObject(HLE::ApiVersion::HOS_VERSION_MAJOR, 0); file->WriteObject(HLE::ApiVersion::HOS_VERSION_MINOR, 1); diff --git a/src/core/hle/service/ptm/ts.cpp b/src/core/hle/service/ptm/ts.cpp index 2aa35159e..d42fecbe5 100755 --- a/src/core/hle/service/ptm/ts.cpp +++ b/src/core/hle/service/ptm/ts.cpp @@ -9,6 +9,35 @@ namespace Service::PTM { +enum class Location : u8 { + Internal, + External, +}; + +class ISession : public ServiceFramework { +public: + explicit ISession(Core::System& system_) : ServiceFramework{system_, "ISession"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, nullptr, "GetTemperatureRange"}, + {2, nullptr, "SetMeasurementMode"}, + {4, &ISession::GetTemperature, "GetTemperature"}, + }; + // clang-format on + + RegisterHandlers(functions); + } + +private: + void GetTemperature(HLERequestContext& ctx) { + constexpr f32 temperature = 35; + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(temperature); + } +}; + TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} { // clang-format off static const FunctionInfo functions[] = { @@ -16,7 +45,7 @@ TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} { {1, &TS::GetTemperature, "GetTemperature"}, {2, nullptr, "SetMeasurementMode"}, {3, &TS::GetTemperatureMilliC, "GetTemperatureMilliC"}, - {4, nullptr, "OpenSession"}, + {4, &TS::OpenSession, "OpenSession"}, }; // clang-format on @@ -47,4 +76,13 @@ void TS::GetTemperatureMilliC(HLERequestContext& ctx) { rb.Push(temperature); } +void TS::OpenSession(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + [[maybe_unused]] const u32 device_code = rp.Pop(); + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(ResultSuccess); + rb.PushIpcInterface(system); +} + } // namespace Service::PTM diff --git a/src/core/hle/service/ptm/ts.h b/src/core/hle/service/ptm/ts.h index f8cb31820..397c76f38 100755 --- a/src/core/hle/service/ptm/ts.h +++ b/src/core/hle/service/ptm/ts.h @@ -14,13 +14,9 @@ public: ~TS() override; private: - enum class Location : u8 { - Internal, - External, - }; - void GetTemperature(HLERequestContext& ctx); void GetTemperatureMilliC(HLERequestContext& ctx); + void OpenSession(HLERequestContext& ctx); }; } // namespace Service::PTM diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index d4039a2df..3455d3ec7 100755 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -5,8 +5,13 @@ #include "common/logging/log.h" #include "common/settings.h" #include "common/string_util.h" +#include "core/core.h" +#include "core/file_sys/content_archive.h" #include "core/file_sys/errors.h" -#include "core/file_sys/system_archive/system_version.h" +#include "core/file_sys/nca_metadata.h" +#include "core/file_sys/registered_cache.h" +#include "core/file_sys/romfs.h" +#include "core/file_sys/system_archive/system_archive.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/set/set.h" @@ -22,18 +27,30 @@ enum class GetFirmwareVersionType { Version2, }; -void GetFirmwareVersionImpl(HLERequestContext& ctx, GetFirmwareVersionType type) { - LOG_WARNING(Service_SET, "called - Using hardcoded firmware version '{}'", - FileSys::SystemArchive::GetLongDisplayVersion()); - +void GetFirmwareVersionImpl(Core::System& system, HLERequestContext& ctx, + GetFirmwareVersionType type) { ASSERT_MSG(ctx.GetWriteBufferSize() == 0x100, "FirmwareVersion output buffer must be 0x100 bytes in size!"); - // Instead of using the normal procedure of checking for the real system archive and if it - // doesn't exist, synthesizing one, I feel that that would lead to strange bugs because a - // used is using a really old or really new SystemVersion title. The synthesized one ensures - // consistence (currently reports as 5.1.0-0.0) - const auto archive = FileSys::SystemArchive::SystemVersion(); + constexpr u64 FirmwareVersionSystemDataId = 0x0100000000000809; + auto& fsc = system.GetFileSystemController(); + + // Attempt to load version data from disk + const FileSys::RegisteredCache* bis_system{}; + std::unique_ptr nca{}; + FileSys::VirtualDir romfs{}; + + bis_system = fsc.GetSystemNANDContents(); + if (bis_system) { + nca = bis_system->GetEntry(FirmwareVersionSystemDataId, FileSys::ContentRecordType::Data); + } + if (nca) { + romfs = FileSys::ExtractRomFS(nca->GetRomFS()); + } + if (!romfs) { + romfs = FileSys::ExtractRomFS( + FileSys::SystemArchive::SynthesizeSystemArchive(FirmwareVersionSystemDataId)); + } const auto early_exit_failure = [&ctx](std::string_view desc, Result code) { LOG_ERROR(Service_SET, "General failure while attempting to resolve firmware version ({}).", @@ -42,13 +59,7 @@ void GetFirmwareVersionImpl(HLERequestContext& ctx, GetFirmwareVersionType type) rb.Push(code); }; - if (archive == nullptr) { - early_exit_failure("The system version archive couldn't be synthesized.", - FileSys::ERROR_FAILED_MOUNT_ARCHIVE); - return; - } - - const auto ver_file = archive->GetFile("file"); + const auto ver_file = romfs->GetFile("file"); if (ver_file == nullptr) { early_exit_failure("The system version archive didn't contain the file 'file'.", FileSys::ERROR_INVALID_ARGUMENT); @@ -87,12 +98,12 @@ void SET_SYS::SetLanguageCode(HLERequestContext& ctx) { void SET_SYS::GetFirmwareVersion(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); - GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version1); + GetFirmwareVersionImpl(system, ctx, GetFirmwareVersionType::Version1); } void SET_SYS::GetFirmwareVersion2(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); - GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version2); + GetFirmwareVersionImpl(system, ctx, GetFirmwareVersionType::Version2); } void SET_SYS::GetAccountSettings(HLERequestContext& ctx) {