summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt17
-rw-r--r--src/core/core.cpp13
-rw-r--r--src/core/core.h12
-rw-r--r--src/core/file_sys/program_metadata.cpp2
-rw-r--r--src/core/file_sys/vfs_libzip.cpp88
-rw-r--r--src/core/file_sys/vfs_libzip.h13
-rw-r--r--src/core/hle/kernel/k_handle_table.cpp2
-rw-r--r--src/core/hle/kernel/k_process.cpp54
-rw-r--r--src/core/hle/kernel/k_process.h4
-rw-r--r--src/core/hle/kernel/k_shared_memory_info.h46
-rw-r--r--src/core/hle/kernel/kernel.h4
-rw-r--r--src/core/hle/kernel/svc.cpp14
-rw-r--r--src/core/hle/service/am/am.cpp4
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp548
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.h64
-rw-r--r--src/core/hle/service/bcat/bcat_module.cpp7
-rw-r--r--src/core/hle/service/hid/hid.cpp2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp2
-rw-r--r--src/core/hle/service/time/system_clock_core.cpp2
-rw-r--r--src/core/hle/service/time/time_zone_service.cpp4
-rw-r--r--src/core/network/network.cpp2
21 files changed, 149 insertions, 755 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 7140d0db8..9f0fbba2d 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -106,8 +106,6 @@ add_library(core STATIC
file_sys/vfs_concat.h
file_sys/vfs_layered.cpp
file_sys/vfs_layered.h
- file_sys/vfs_libzip.cpp
- file_sys/vfs_libzip.h
file_sys/vfs_offset.cpp
file_sys/vfs_offset.h
file_sys/vfs_real.cpp
@@ -218,6 +216,7 @@ add_library(core STATIC
hle/kernel/k_session.h
hle/kernel/k_shared_memory.cpp
hle/kernel/k_shared_memory.h
+ hle/kernel/k_shared_memory_info.h
hle/kernel/k_slab_heap.h
hle/kernel/k_spin_lock.cpp
hle/kernel/k_spin_lock.h
@@ -653,13 +652,6 @@ add_library(core STATIC
tools/freezer.h
)
-if (YUZU_ENABLE_BOXCAT)
- target_sources(core PRIVATE
- hle/service/bcat/backend/boxcat.cpp
- hle/service/bcat/backend/boxcat.h
- )
-endif()
-
if (MSVC)
target_compile_options(core PRIVATE
/we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
@@ -690,12 +682,7 @@ endif()
create_target_directory_groups(core)
target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
-target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus zip)
-
-if (YUZU_ENABLE_BOXCAT)
- target_compile_definitions(core PRIVATE -DYUZU_ENABLE_BOXCAT)
- target_link_libraries(core PRIVATE httplib nlohmann_json::nlohmann_json)
-endif()
+target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus)
if (ENABLE_WEB_SERVICE)
target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE)
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 50d5dab4b..bb268a319 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -421,6 +421,7 @@ struct System::Impl {
bool is_async_gpu{};
ExecuteProgramCallback execute_program_callback;
+ ExitCallback exit_callback;
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{};
@@ -798,6 +799,18 @@ void System::ExecuteProgram(std::size_t program_index) {
}
}
+void System::RegisterExitCallback(ExitCallback&& callback) {
+ impl->exit_callback = std::move(callback);
+}
+
+void System::Exit() {
+ if (impl->exit_callback) {
+ impl->exit_callback();
+ } else {
+ LOG_CRITICAL(Core, "exit_callback must be initialized by the frontend");
+ }
+}
+
void System::ApplySettings() {
if (IsPoweredOn()) {
Renderer().RefreshBaseSettings();
diff --git a/src/core/core.h b/src/core/core.h
index 715ab88e7..a796472b2 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -387,6 +387,18 @@ public:
*/
void ExecuteProgram(std::size_t program_index);
+ /// Type used for the frontend to designate a callback for System to exit the application.
+ using ExitCallback = std::function<void()>;
+
+ /**
+ * Registers a callback from the frontend for System to exit the application.
+ * @param callback Callback from the frontend to exit the application.
+ */
+ void RegisterExitCallback(ExitCallback&& callback);
+
+ /// Instructs the frontend to exit the application.
+ void Exit();
+
/// Applies any changes to settings to this core instance.
void ApplySettings();
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index 01ae1a567..35a53d36c 100644
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -77,7 +77,7 @@ void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address
aci_header.title_id = title_id;
aci_file_access.permissions = filesystem_permissions;
npdm_header.system_resource_size = system_resource_size;
- aci_kernel_capabilities = std ::move(capabilities);
+ aci_kernel_capabilities = std::move(capabilities);
}
bool ProgramMetadata::Is64BitProgram() const {
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp
deleted file mode 100644
index 00e256779..000000000
--- a/src/core/file_sys/vfs_libzip.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2019 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <string>
-
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#endif
-#include <zip.h>
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif
-
-#include "common/fs/path_util.h"
-#include "core/file_sys/vfs.h"
-#include "core/file_sys/vfs_libzip.h"
-#include "core/file_sys/vfs_vector.h"
-
-namespace FileSys {
-
-VirtualDir ExtractZIP(VirtualFile file) {
- zip_error_t error{};
-
- const auto data = file->ReadAllBytes();
- std::unique_ptr<zip_source_t, decltype(&zip_source_close)> src{
- zip_source_buffer_create(data.data(), data.size(), 0, &error), zip_source_close};
- if (src == nullptr)
- return nullptr;
-
- std::unique_ptr<zip_t, decltype(&zip_close)> zip{zip_open_from_source(src.get(), 0, &error),
- zip_close};
- if (zip == nullptr)
- return nullptr;
-
- std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>();
-
- const auto num_entries = static_cast<std::size_t>(zip_get_num_entries(zip.get(), 0));
-
- zip_stat_t stat{};
- zip_stat_init(&stat);
-
- for (std::size_t i = 0; i < num_entries; ++i) {
- const auto stat_res = zip_stat_index(zip.get(), i, 0, &stat);
- if (stat_res == -1)
- return nullptr;
-
- const std::string name(stat.name);
- if (name.empty())
- continue;
-
- if (name.back() != '/') {
- std::unique_ptr<zip_file_t, decltype(&zip_fclose)> file2{
- zip_fopen_index(zip.get(), i, 0), zip_fclose};
-
- std::vector<u8> buf(stat.size);
- if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size()))
- return nullptr;
-
- const auto parts = Common::FS::SplitPathComponents(stat.name);
- const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back());
-
- std::shared_ptr<VectorVfsDirectory> dtrv = out;
- for (std::size_t j = 0; j < parts.size() - 1; ++j) {
- if (dtrv == nullptr)
- return nullptr;
- const auto subdir = dtrv->GetSubdirectory(parts[j]);
- if (subdir == nullptr) {
- const auto temp = std::make_shared<VectorVfsDirectory>(
- std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, parts[j]);
- dtrv->AddDirectory(temp);
- dtrv = temp;
- } else {
- dtrv = std::dynamic_pointer_cast<VectorVfsDirectory>(subdir);
- }
- }
-
- if (dtrv == nullptr)
- return nullptr;
- dtrv->AddFile(new_file);
- }
- }
-
- return out;
-}
-
-} // namespace FileSys
diff --git a/src/core/file_sys/vfs_libzip.h b/src/core/file_sys/vfs_libzip.h
deleted file mode 100644
index f68af576a..000000000
--- a/src/core/file_sys/vfs_libzip.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2019 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "core/file_sys/vfs_types.h"
-
-namespace FileSys {
-
-VirtualDir ExtractZIP(VirtualFile zip);
-
-} // namespace FileSys
diff --git a/src/core/hle/kernel/k_handle_table.cpp b/src/core/hle/kernel/k_handle_table.cpp
index 6a420d5b0..44d13169f 100644
--- a/src/core/hle/kernel/k_handle_table.cpp
+++ b/src/core/hle/kernel/k_handle_table.cpp
@@ -7,7 +7,7 @@
namespace Kernel {
KHandleTable::KHandleTable(KernelCore& kernel_) : kernel{kernel_} {}
-KHandleTable ::~KHandleTable() = default;
+KHandleTable::~KHandleTable() = default;
ResultCode KHandleTable::Finalize() {
// Get the table and clear our record of it.
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index 8ead1a769..211157ccc 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -23,6 +23,7 @@
#include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/k_scoped_resource_reservation.h"
#include "core/hle/kernel/k_shared_memory.h"
+#include "core/hle/kernel/k_shared_memory_info.h"
#include "core/hle/kernel/k_slab_heap.h"
#include "core/hle/kernel/k_thread.h"
#include "core/hle/kernel/kernel.h"
@@ -254,10 +255,26 @@ ResultCode KProcess::AddSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAdd
// Lock ourselves, to prevent concurrent access.
KScopedLightLock lk(state_lock);
- // TODO(bunnei): Manage KSharedMemoryInfo list here.
+ // Try to find an existing info for the memory.
+ KSharedMemoryInfo* shemen_info = nullptr;
+ const auto iter = std::find_if(
+ shared_memory_list.begin(), shared_memory_list.end(),
+ [shmem](const KSharedMemoryInfo* info) { return info->GetSharedMemory() == shmem; });
+ if (iter != shared_memory_list.end()) {
+ shemen_info = *iter;
+ }
+
+ if (shemen_info == nullptr) {
+ shemen_info = KSharedMemoryInfo::Allocate(kernel);
+ R_UNLESS(shemen_info != nullptr, ResultOutOfMemory);
+
+ shemen_info->Initialize(shmem);
+ shared_memory_list.push_back(shemen_info);
+ }
- // Open a reference to the shared memory.
+ // Open a reference to the shared memory and its info.
shmem->Open();
+ shemen_info->Open();
return ResultSuccess;
}
@@ -267,7 +284,20 @@ void KProcess::RemoveSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr a
// Lock ourselves, to prevent concurrent access.
KScopedLightLock lk(state_lock);
- // TODO(bunnei): Manage KSharedMemoryInfo list here.
+ KSharedMemoryInfo* shemen_info = nullptr;
+ const auto iter = std::find_if(
+ shared_memory_list.begin(), shared_memory_list.end(),
+ [shmem](const KSharedMemoryInfo* info) { return info->GetSharedMemory() == shmem; });
+ if (iter != shared_memory_list.end()) {
+ shemen_info = *iter;
+ }
+
+ ASSERT(shemen_info != nullptr);
+
+ if (shemen_info->Close()) {
+ shared_memory_list.erase(iter);
+ KSharedMemoryInfo::Free(kernel, shemen_info);
+ }
// Close a reference to the shared memory.
shmem->Close();
@@ -412,6 +442,24 @@ void KProcess::Finalize() {
// Finalize the handle table and close any open handles.
handle_table.Finalize();
+ // Free all shared memory infos.
+ {
+ auto it = shared_memory_list.begin();
+ while (it != shared_memory_list.end()) {
+ KSharedMemoryInfo* info = *it;
+ KSharedMemory* shmem = info->GetSharedMemory();
+
+ while (!info->Close()) {
+ shmem->Close();
+ }
+
+ shmem->Close();
+
+ it = shared_memory_list.erase(it);
+ KSharedMemoryInfo::Free(kernel, info);
+ }
+ }
+
// Perform inherited finalization.
KAutoObjectWithSlabHeapAndContainer<KProcess, KSynchronizationObject>::Finalize();
}
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h
index a03c074fb..1a53e2be7 100644
--- a/src/core/hle/kernel/k_process.h
+++ b/src/core/hle/kernel/k_process.h
@@ -34,6 +34,7 @@ class KernelCore;
class KPageTable;
class KResourceLimit;
class KThread;
+class KSharedMemoryInfo;
class TLSPage;
struct CodeSet;
@@ -448,6 +449,9 @@ private:
/// List of threads that are running with this process as their owner.
std::list<const KThread*> thread_list;
+ /// List of shared memory that are running with this process as their owner.
+ std::list<KSharedMemoryInfo*> shared_memory_list;
+
/// Address of the top of the main thread's stack
VAddr main_thread_stack_top{};
diff --git a/src/core/hle/kernel/k_shared_memory_info.h b/src/core/hle/kernel/k_shared_memory_info.h
new file mode 100644
index 000000000..bf97a0184
--- /dev/null
+++ b/src/core/hle/kernel/k_shared_memory_info.h
@@ -0,0 +1,46 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <boost/intrusive/list.hpp>
+
+#include "common/assert.h"
+#include "core/hle/kernel/slab_helpers.h"
+
+namespace Kernel {
+
+class KSharedMemory;
+
+class KSharedMemoryInfo final : public KSlabAllocated<KSharedMemoryInfo>,
+ public boost::intrusive::list_base_hook<> {
+
+public:
+ explicit KSharedMemoryInfo() = default;
+
+ constexpr void Initialize(KSharedMemory* shmem) {
+ shared_memory = shmem;
+ }
+
+ constexpr KSharedMemory* GetSharedMemory() const {
+ return shared_memory;
+ }
+
+ constexpr void Open() {
+ ++reference_count;
+ }
+
+ constexpr bool Close() {
+ return (--reference_count) == 0;
+ }
+
+private:
+ KSharedMemory* shared_memory{};
+ size_t reference_count{};
+};
+
+} // namespace Kernel
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 901d43da9..b6658b437 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -49,6 +49,7 @@ class KScheduler;
class KServerSession;
class KSession;
class KSharedMemory;
+class KSharedMemoryInfo;
class KThread;
class KTransferMemory;
class KWritableEvent;
@@ -309,6 +310,8 @@ public:
return slab_heap_container->session;
} else if constexpr (std::is_same_v<T, KSharedMemory>) {
return slab_heap_container->shared_memory;
+ } else if constexpr (std::is_same_v<T, KSharedMemoryInfo>) {
+ return slab_heap_container->shared_memory_info;
} else if constexpr (std::is_same_v<T, KThread>) {
return slab_heap_container->thread;
} else if constexpr (std::is_same_v<T, KTransferMemory>) {
@@ -362,6 +365,7 @@ private:
KSlabHeap<KResourceLimit> resource_limit;
KSlabHeap<KSession> session;
KSlabHeap<KSharedMemory> shared_memory;
+ KSlabHeap<KSharedMemoryInfo> shared_memory_info;
KSlabHeap<KThread> thread;
KSlabHeap<KTransferMemory> transfer_memory;
KSlabHeap<KWritableEvent> writeable_event;
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 62fb06c45..f98f24a60 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -320,17 +320,19 @@ static ResultCode SendSyncRequest(Core::System& system, Handle handle) {
auto& kernel = system.Kernel();
- KScopedAutoObject session =
- kernel.CurrentProcess()->GetHandleTable().GetObject<KClientSession>(handle);
- R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
- LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName());
-
auto thread = kernel.CurrentScheduler()->GetCurrentThread();
{
KScopedSchedulerLock lock(kernel);
thread->SetState(ThreadState::Waiting);
thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
- session->SendSyncRequest(thread, system.Memory(), system.CoreTiming());
+
+ {
+ KScopedAutoObject session =
+ kernel.CurrentProcess()->GetHandleTable().GetObject<KClientSession>(handle);
+ R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
+ LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName());
+ session->SendSyncRequest(thread, system.Memory(), system.CoreTiming());
+ }
}
KSynchronizationObject* dummy{};
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 8c2e2f920..49e9787a4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -332,10 +332,10 @@ ISelfController::~ISelfController() = default;
void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_AM, "called");
- system.Shutdown();
-
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
+
+ system.Exit();
}
void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
deleted file mode 100644
index 7ca7f2aac..000000000
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ /dev/null
@@ -1,548 +0,0 @@
-// Copyright 2019 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <fmt/ostream.h>
-
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#ifndef __clang__
-#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
-#endif
-#endif
-#include <httplib.h>
-#include <mbedtls/sha256.h>
-#include <nlohmann/json.hpp>
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif
-
-#include "common/fs/file.h"
-#include "common/fs/fs.h"
-#include "common/fs/path_util.h"
-#include "common/hex_util.h"
-#include "common/logging/log.h"
-#include "common/settings.h"
-#include "core/core.h"
-#include "core/file_sys/vfs.h"
-#include "core/file_sys/vfs_libzip.h"
-#include "core/file_sys/vfs_vector.h"
-#include "core/frontend/applets/error.h"
-#include "core/hle/service/am/applets/applets.h"
-#include "core/hle/service/bcat/backend/boxcat.h"
-
-namespace Service::BCAT {
-namespace {
-
-// Prevents conflicts with windows macro called CreateFile
-FileSys::VirtualFile VfsCreateFileWrap(FileSys::VirtualDir dir, std::string_view name) {
- return dir->CreateFile(name);
-}
-
-// Prevents conflicts with windows macro called DeleteFile
-bool VfsDeleteFileWrap(FileSys::VirtualDir dir, std::string_view name) {
- return dir->DeleteFile(name);
-}
-
-constexpr ResultCode ERROR_GENERAL_BCAT_FAILURE{ErrorModule::BCAT, 1};
-
-constexpr char BOXCAT_HOSTNAME[] = "api.yuzu-emu.org";
-
-// Formatted using fmt with arg[0] = hex title id
-constexpr char BOXCAT_PATHNAME_DATA[] = "/game-assets/{:016X}/boxcat";
-constexpr char BOXCAT_PATHNAME_LAUNCHPARAM[] = "/game-assets/{:016X}/launchparam";
-
-constexpr char BOXCAT_PATHNAME_EVENTS[] = "/game-assets/boxcat/events";
-
-constexpr char BOXCAT_API_VERSION[] = "1";
-constexpr char BOXCAT_CLIENT_TYPE[] = "yuzu";
-
-// HTTP status codes for Boxcat
-enum class ResponseStatus {
- Ok = 200, ///< Operation completed successfully.
- BadClientVersion = 301, ///< The Boxcat-Client-Version doesn't match the server.
- NoUpdate = 304, ///< The digest provided would match the new data, no need to update.
- NoMatchTitleId = 404, ///< The title ID provided doesn't have a boxcat implementation.
- NoMatchBuildId = 406, ///< The build ID provided is blacklisted (potentially because of format
- ///< issues or whatnot) and has no data.
-};
-
-enum class DownloadResult {
- Success = 0,
- NoResponse,
- GeneralWebError,
- NoMatchTitleId,
- NoMatchBuildId,
- InvalidContentType,
- GeneralFSError,
- BadClientVersion,
-};
-
-constexpr std::array<const char*, 8> DOWNLOAD_RESULT_LOG_MESSAGES{
- "Success",
- "There was no response from the server.",
- "There was a general web error code returned from the server.",
- "The title ID of the current game doesn't have a boxcat implementation. If you believe an "
- "implementation should be added, contact yuzu support.",
- "The build ID of the current version of the game is marked as incompatible with the current "
- "BCAT distribution. Try upgrading or downgrading your game version or contacting yuzu support.",
- "The content type of the web response was invalid.",
- "There was a general filesystem error while saving the zip file.",
- "The server is either too new or too old to serve the request. Try using the latest version of "
- "an official release of yuzu.",
-};
-
-std::ostream& operator<<(std::ostream& os, DownloadResult result) {
- return os << DOWNLOAD_RESULT_LOG_MESSAGES.at(static_cast<std::size_t>(result));
-}
-
-constexpr u32 PORT = 443;
-constexpr u32 TIMEOUT_SECONDS = 30;
-[[maybe_unused]] constexpr u64 VFS_COPY_BLOCK_SIZE = 1ULL << 24; // 4MB
-
-std::filesystem::path GetBINFilePath(u64 title_id) {
- return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" /
- fmt::format("{:016X}/launchparam.bin", title_id);
-}
-
-std::filesystem::path GetZIPFilePath(u64 title_id) {
- return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" /
- fmt::format("{:016X}/data.zip", title_id);
-}
-
-// If the error is something the user should know about (build ID mismatch, bad client version),
-// display an error.
-void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manager,
- DownloadResult res) {
- if (res == DownloadResult::Success || res == DownloadResult::NoResponse ||
- res == DownloadResult::GeneralWebError || res == DownloadResult::GeneralFSError ||
- res == DownloadResult::NoMatchTitleId || res == DownloadResult::InvalidContentType) {
- return;
- }
-
- const auto& frontend{applet_manager.GetAppletFrontendSet()};
- frontend.error->ShowCustomErrorText(
- ResultUnknown, "There was an error while attempting to use Boxcat.",
- DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {});
-}
-
-bool VfsRawCopyProgress(FileSys::VirtualFile src, FileSys::VirtualFile dest,
- std::string_view dir_name, ProgressServiceBackend& progress,
- std::size_t block_size = 0x1000) {
- if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
- return false;
- if (!dest->Resize(src->GetSize()))
- return false;
-
- progress.StartDownloadingFile(dir_name, src->GetName(), src->GetSize());
-
- std::vector<u8> temp(std::min(block_size, src->GetSize()));
- for (std::size_t i = 0; i < src->GetSize(); i += block_size) {
- const auto read = std::min(block_size, src->GetSize() - i);
-
- if (src->Read(temp.data(), read, i) != read) {
- return false;
- }
-
- if (dest->Write(temp.data(), read, i) != read) {
- return false;
- }
-
- progress.UpdateFileProgress(i);
- }
-
- progress.FinishDownloadingFile();
-
- return true;
-}
-
-bool VfsRawCopyDProgressSingle(FileSys::VirtualDir src, FileSys::VirtualDir dest,
- ProgressServiceBackend& progress, std::size_t block_size = 0x1000) {
- if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
- return false;
-
- for (const auto& file : src->GetFiles()) {
- const auto out_file = VfsCreateFileWrap(dest, file->GetName());
- if (!VfsRawCopyProgress(file, out_file, src->GetName(), progress, block_size)) {
- return false;
- }
- }
- progress.CommitDirectory(src->GetName());
-
- return true;
-}
-
-bool VfsRawCopyDProgress(FileSys::VirtualDir src, FileSys::VirtualDir dest,
- ProgressServiceBackend& progress, std::size_t block_size = 0x1000) {
- if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
- return false;
-
- for (const auto& dir : src->GetSubdirectories()) {
- const auto out = dest->CreateSubdirectory(dir->GetName());
- if (!VfsRawCopyDProgressSingle(dir, out, progress, block_size)) {
- return false;
- }
- }
-
- return true;
-}
-
-} // Anonymous namespace
-
-class Boxcat::Client {
-public:
- Client(std::filesystem::path path_, u64 title_id_, u64 build_id_)
- : path(std::move(path_)), title_id(title_id_), build_id(build_id_) {}
-
- DownloadResult DownloadDataZip() {
- return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS,
- "application/zip");
- }
-
- DownloadResult DownloadLaunchParam() {
- return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id),
- TIMEOUT_SECONDS / 3, "application/octet-stream");
- }
-
-private:
- DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds,
- const std::string& content_type_name) {
- if (client == nullptr) {
- client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT);
- client->set_connection_timeout(timeout_seconds);
- client->set_read_timeout(timeout_seconds);
- client->set_write_timeout(timeout_seconds);
- }
-
- httplib::Headers headers{
- {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)},
- {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)},
- {std::string("Game-Build-Id"), fmt::format("{:016X}", build_id)},
- };
-
- if (Common::FS::Exists(path)) {
- Common::FS::IOFile file{path, Common::FS::FileAccessMode::Read,
- Common::FS::FileType::BinaryFile};
- if (file.IsOpen()) {
- std::vector<u8> bytes(file.GetSize());
- void(file.Read(bytes));
- const auto digest = DigestFile(bytes);
- headers.insert({std::string("If-None-Match"), Common::HexToString(digest, false)});
- }
- }
-
- const auto response = client->Get(resolved_path.c_str(), headers);
- if (response == nullptr)
- return DownloadResult::NoResponse;
-
- if (response->status == static_cast<int>(ResponseStatus::NoUpdate))
- return DownloadResult::Success;
- if (response->status == static_cast<int>(ResponseStatus::BadClientVersion))
- return DownloadResult::BadClientVersion;
- if (response->status == static_cast<int>(ResponseStatus::NoMatchTitleId))
- return DownloadResult::NoMatchTitleId;
- if (response->status == static_cast<int>(ResponseStatus::NoMatchBuildId))
- return DownloadResult::NoMatchBuildId;
- if (response->status != static_cast<int>(ResponseStatus::Ok))
- return DownloadResult::GeneralWebError;
-
- const auto content_type = response->headers.find("content-type");
- if (content_type == response->headers.end() ||
- content_type->second.find(content_type_name) == std::string::npos) {
- return DownloadResult::InvalidContentType;
- }
-
- if (!Common::FS::CreateDirs(path)) {
- return DownloadResult::GeneralFSError;
- }
-
- Common::FS::IOFile file{path, Common::FS::FileAccessMode::Append,
- Common::FS::FileType::BinaryFile};
- if (!file.IsOpen()) {
- return DownloadResult::GeneralFSError;
- }
-
- if (!file.SetSize(response->body.size())) {
- return DownloadResult::GeneralFSError;
- }
-
- if (file.Write(response->body) != response->body.size()) {
- return DownloadResult::GeneralFSError;
- }
-
- return DownloadResult::Success;
- }
-
- using Digest = std::array<u8, 0x20>;
- static Digest DigestFile(std::vector<u8> bytes) {
- Digest out{};
- mbedtls_sha256_ret(bytes.data(), bytes.size(), out.data(), 0);
- return out;
- }
-
- std::unique_ptr<httplib::SSLClient> client;
- std::filesystem::path path;
- u64 title_id;
- u64 build_id;
-};
-
-Boxcat::Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter)
- : Backend(std::move(getter)), applet_manager{applet_manager_} {}
-
-Boxcat::~Boxcat() = default;
-
-void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGetter dir_getter,
- TitleIDVersion title, ProgressServiceBackend& progress,
- std::optional<std::string> dir_name = {}) {
- progress.SetNeedHLELock(true);
-
- if (Settings::values.bcat_boxcat_local) {
- LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download.");
- const auto dir = dir_getter(title.title_id);
- if (dir)
- progress.SetTotalSize(dir->GetSize());
- progress.FinishDownload(ResultSuccess);
- return;
- }
-
- const auto zip_path = GetZIPFilePath(title.title_id);
- Boxcat::Client client{zip_path, title.title_id, title.build_id};
-
- progress.StartConnecting();
-
- const auto res = client.DownloadDataZip();
- if (res != DownloadResult::Success) {
- LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
-
- if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
- Common::FS::RemoveFile(zip_path);
- }
-
- HandleDownloadDisplayResult(applet_manager, res);
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
-
- progress.StartProcessingDataList();
-
- Common::FS::IOFile zip{zip_path, Common::FS::FileAccessMode::Read,
- Common::FS::FileType::BinaryFile};
- const auto size = zip.GetSize();
- std::vector<u8> bytes(size);
- if (!zip.IsOpen() || size == 0 || zip.Read(bytes) != bytes.size()) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!",
- Common::FS::PathToUTF8String(zip_path));
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
-
- const auto extracted = FileSys::ExtractZIP(std::make_shared<FileSys::VectorVfsFile>(bytes));
- if (extracted == nullptr) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to extract ZIP file!");
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
-
- if (dir_name == std::nullopt) {
- progress.SetTotalSize(extracted->GetSize());
-
- const auto target_dir = dir_getter(title.title_id);
- if (target_dir == nullptr || !VfsRawCopyDProgress(extracted, target_dir, progress)) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!");
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
- } else {
- const auto target_dir = dir_getter(title.title_id);
- if (target_dir == nullptr) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to get directory for title ID!");
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
-
- const auto target_sub = target_dir->GetSubdirectory(*dir_name);
- const auto source_sub = extracted->GetSubdirectory(*dir_name);
-
- progress.SetTotalSize(source_sub->GetSize());
-
- std::vector<std::string> filenames;
- {
- const auto files = target_sub->GetFiles();
- std::transform(files.begin(), files.end(), std::back_inserter(filenames),
- [](const auto& vfile) { return vfile->GetName(); });
- }
-
- for (const auto& filename : filenames) {
- VfsDeleteFileWrap(target_sub, filename);
- }
-
- if (target_sub == nullptr || source_sub == nullptr ||
- !VfsRawCopyDProgressSingle(source_sub, target_sub, progress)) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!");
- progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
- return;
- }
- }
-
- progress.FinishDownload(ResultSuccess);
-}
-
-bool Boxcat::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) {
- is_syncing.exchange(true);
-
- std::thread([this, title, &progress] {
- SynchronizeInternal(applet_manager, dir_getter, title, progress);
- }).detach();
-
- return true;
-}
-
-bool Boxcat::SynchronizeDirectory(TitleIDVersion title, std::string name,
- ProgressServiceBackend& progress) {
- is_syncing.exchange(true);
-
- std::thread([this, title, name, &progress] {
- SynchronizeInternal(applet_manager, dir_getter, title, progress, name);
- }).detach();
-
- return true;
-}
-
-bool Boxcat::Clear(u64 title_id) {
- if (Settings::values.bcat_boxcat_local) {
- LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping clear.");
- return true;
- }
-
- const auto dir = dir_getter(title_id);
-
- std::vector<std::string> dirnames;
-
- for (const auto& subdir : dir->GetSubdirectories())
- dirnames.push_back(subdir->GetName());
-
- for (const auto& subdir : dirnames) {
- if (!dir->DeleteSubdirectoryRecursive(subdir))
- return false;
- }
-
- return true;
-}
-
-void Boxcat::SetPassphrase(u64 title_id, const Passphrase& passphrase) {
- LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id,
- Common::HexToString(passphrase));
-}
-
-std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) {
- const auto bin_file_path = GetBINFilePath(title.title_id);
-
- if (Settings::values.bcat_boxcat_local) {
- LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download.");
- } else {
- Client launch_client{bin_file_path, title.title_id, title.build_id};
-
- const auto res = launch_client.DownloadLaunchParam();
- if (res != DownloadResult::Success) {
- LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
-
- if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
- Common::FS::RemoveFile(bin_file_path);
- }
-
- HandleDownloadDisplayResult(applet_manager, res);
- return std::nullopt;
- }
- }
-
- Common::FS::IOFile bin{bin_file_path, Common::FS::FileAccessMode::Read,
- Common::FS::FileType::BinaryFile};
- const auto size = bin.GetSize();
- std::vector<u8> bytes(size);
- if (!bin.IsOpen() || size == 0 || bin.Read(bytes) != bytes.size()) {
- LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!",
- Common::FS::PathToUTF8String(bin_file_path));
- return std::nullopt;
- }
-
- return bytes;
-}
-
-Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global,
- std::map<std::string, EventStatus>& games) {
- httplib::SSLClient client{BOXCAT_HOSTNAME, static_cast<int>(PORT)};
- client.set_connection_timeout(static_cast<int>(TIMEOUT_SECONDS));
- client.set_read_timeout(static_cast<int>(TIMEOUT_SECONDS));
- client.set_write_timeout(static_cast<int>(TIMEOUT_SECONDS));
-
- httplib::Headers headers{
- {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)},
- {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)},
- };
-
- if (!client.is_valid()) {
- LOG_ERROR(Service_BCAT, "Client is invalid, going offline!");
- return StatusResult::Offline;
- }
-
- if (!client.is_socket_open()) {
- LOG_ERROR(Service_BCAT, "Failed to open socket, going offline!");
- return StatusResult::Offline;
- }
-
- const auto response = client.Get(BOXCAT_PATHNAME_EVENTS, headers);
- if (response == nullptr)
- return StatusResult::Offline;
-
- if (response->status == static_cast<int>(ResponseStatus::BadClientVersion))
- return StatusResult::BadClientVersion;
-
- try {
- nlohmann::json json = nlohmann::json::parse(response->body);
-
- if (!json["online"].get<bool>())
- return StatusResult::Offline;
-
- if (json["global"].is_null())
- global = std::nullopt;
- else
- global = json["global"].get<std::string>();
-
- if (json["games"].is_array()) {
- for (const auto& object : json["games"]) {
- if (object.is_object() && object.find("name") != object.end()) {
- EventStatus detail{};
- if (object["header"].is_string()) {
- detail.header = object["header"].get<std::string>();
- } else {
- detail.header = std::nullopt;
- }
-
- if (object["footer"].is_string()) {
- detail.footer = object["footer"].get<std::string>();
- } else {
- detail.footer = std::nullopt;
- }
-
- if (object["events"].is_array()) {
- for (const auto& event : object["events"]) {
- if (!event.is_string())
- continue;
- detail.events.push_back(event.get<std::string>());
- }
- }
-
- games.insert_or_assign(object["name"], std::move(detail));
- }
- }
- }
-
- return StatusResult::Success;
- } catch (const nlohmann::json::parse_error& error) {
- LOG_ERROR(Service_BCAT, "{}", error.what());
- return StatusResult::ParseError;
- }
-}
-
-} // namespace Service::BCAT
diff --git a/src/core/hle/service/bcat/backend/boxcat.h b/src/core/hle/service/bcat/backend/boxcat.h
deleted file mode 100644
index d65b42e58..000000000
--- a/src/core/hle/service/bcat/backend/boxcat.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2019 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <atomic>
-#include <map>
-#include <optional>
-#include "core/hle/service/bcat/backend/backend.h"
-
-namespace Service::AM::Applets {
-class AppletManager;
-}
-
-namespace Service::BCAT {
-
-struct EventStatus {
- std::optional<std::string> header;
- std::optional<std::string> footer;
- std::vector<std::string> events;
-};
-
-/// Boxcat is yuzu's custom backend implementation of Nintendo's BCAT service. It is free to use and
-/// doesn't require a switch or nintendo account. The content is controlled by the yuzu team.
-class Boxcat final : public Backend {
- friend void SynchronizeInternal(AM::Applets::AppletManager& applet_manager,
- DirectoryGetter dir_getter, TitleIDVersion title,
- ProgressServiceBackend& progress,
- std::optional<std::string> dir_name);
-
-public:
- explicit Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter);
- ~Boxcat() override;
-
- bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override;
- bool SynchronizeDirectory(TitleIDVersion title, std::string name,
- ProgressServiceBackend& progress) override;
-
- bool Clear(u64 title_id) override;
-
- void SetPassphrase(u64 title_id, const Passphrase& passphrase) override;
-
- std::optional<std::vector<u8>> GetLaunchParameter(TitleIDVersion title) override;
-
- enum class StatusResult {
- Success,
- Offline,
- ParseError,
- BadClientVersion,
- };
-
- static StatusResult GetStatus(std::optional<std::string>& global,
- std::map<std::string, EventStatus>& games);
-
-private:
- std::atomic_bool is_syncing{false};
-
- class Client;
- std::unique_ptr<Client> client;
- AM::Applets::AppletManager& applet_manager;
-};
-
-} // namespace Service::BCAT
diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp
index 72294eb2e..701f634f8 100644
--- a/src/core/hle/service/bcat/bcat_module.cpp
+++ b/src/core/hle/service/bcat/bcat_module.cpp
@@ -4,7 +4,6 @@
#include <cctype>
#include <mbedtls/md5.h>
-#include "backend/boxcat.h"
#include "common/hex_util.h"
#include "common/logging/log.h"
#include "common/settings.h"
@@ -578,12 +577,6 @@ void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId(
std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system,
DirectoryGetter getter) {
-#ifdef YUZU_ENABLE_BOXCAT
- if (Settings::values.bcat_backend.GetValue() == "boxcat") {
- return std::make_unique<Boxcat>(system.GetAppletManager(), std::move(getter));
- }
-#endif
-
return std::make_unique<NullBackend>(std::move(getter));
}
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index c930996ab..8c363142c 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -106,7 +106,7 @@ void IAppletResource::DeactivateController(HidController controller) {
controllers[static_cast<size_t>(controller)]->DeactivateController();
}
-IAppletResource ::~IAppletResource() {
+IAppletResource::~IAppletResource() {
system.CoreTiming().UnscheduleEvent(pad_update_event, 0);
system.CoreTiming().UnscheduleEvent(motion_update_event, 0);
}
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
index a33e47d0b..789000294 100644
--- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
@@ -16,7 +16,7 @@ namespace Service::Nvidia::Devices {
nvdisp_disp0::nvdisp_disp0(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_)
: nvdevice{system_}, nvmap_dev{std::move(nvmap_dev_)} {}
-nvdisp_disp0 ::~nvdisp_disp0() = default;
+nvdisp_disp0::~nvdisp_disp0() = default;
NvResult nvdisp_disp0::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
std::vector<u8>& output) {
diff --git a/src/core/hle/service/time/system_clock_core.cpp b/src/core/hle/service/time/system_clock_core.cpp
index bd334bbef..5c2354cdd 100644
--- a/src/core/hle/service/time/system_clock_core.cpp
+++ b/src/core/hle/service/time/system_clock_core.cpp
@@ -13,7 +13,7 @@ SystemClockCore::SystemClockCore(SteadyClockCore& steady_clock_core_)
context.steady_time_point.clock_source_id = steady_clock_core.GetClockSourceId();
}
-SystemClockCore ::~SystemClockCore() = default;
+SystemClockCore::~SystemClockCore() = default;
ResultCode SystemClockCore::GetCurrentTime(Core::System& system, s64& posix_time) const {
posix_time = 0;
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp
index 5c3108768..3871e7316 100644
--- a/src/core/hle/service/time/time_zone_service.cpp
+++ b/src/core/hle/service/time/time_zone_service.cpp
@@ -10,8 +10,8 @@
namespace Service::Time {
-ITimeZoneService ::ITimeZoneService(Core::System& system_,
- TimeZone::TimeZoneContentManager& time_zone_manager_)
+ITimeZoneService::ITimeZoneService(Core::System& system_,
+ TimeZone::TimeZoneContentManager& time_zone_manager_)
: ServiceFramework{system_, "ITimeZoneService"}, time_zone_content_manager{time_zone_manager_} {
static const FunctionInfo functions[] = {
{0, &ITimeZoneService::GetDeviceLocationName, "GetDeviceLocationName"},
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp
index 72eea52f0..a3e0664b9 100644
--- a/src/core/network/network.cpp
+++ b/src/core/network/network.cpp
@@ -366,8 +366,6 @@ std::optional<IPv4Address> GetHostIPv4Address() {
if (res != network_interfaces.end()) {
char ip_addr[16] = {};
ASSERT(inet_ntop(AF_INET, &res->ip_address, ip_addr, sizeof(ip_addr)) != nullptr);
- LOG_INFO(Network, "IP address: {}", ip_addr);
-
return TranslateIPv4(res->ip_address);
} else {
LOG_ERROR(Network, "Couldn't find selected interface \"{}\"", selected_network_interface);