From 98c46f7eb0a772a7dac948bf709726fdac7b8cd8 Mon Sep 17 00:00:00 2001 From: brian218 Date: Thu, 20 Apr 2023 20:04:10 +0800 Subject: [PATCH] sys_game: Fixed potential bugs in sys_game_get_system_sw_version() sys_game: Implemented sys_game_set_system_sw_version() --- rpcs3/Emu/Cell/lv2/lv2.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_game.cpp | 39 +++++++++++++++++++++++++++++++-- rpcs3/Emu/Cell/lv2/sys_game.h | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index 88ae1c639a..01d6192c87 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -424,7 +424,7 @@ const std::array, 1024> g_ppu_sysc BIND_SYSC(_sys_game_watchdog_start), //372 (0x174) BIND_SYSC(_sys_game_watchdog_stop), //373 (0x175) BIND_SYSC(_sys_game_watchdog_clear), //374 (0x176) - NULL_FUNC(sys_game_set_system_sw_version), //375 (0x177) ROOT + BIND_SYSC(_sys_game_set_system_sw_version), //375 (0x177) ROOT BIND_SYSC(_sys_game_get_system_sw_version), //376 (0x178) ROOT BIND_SYSC(sys_sm_set_shop_mode), //377 (0x179) ROOT BIND_SYSC(sys_sm_get_ext_event2), //378 (0x17A) ROOT diff --git a/rpcs3/Emu/Cell/lv2/sys_game.cpp b/rpcs3/Emu/Cell/lv2/sys_game.cpp index b3351f0ddc..64bd930ce0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_game.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_game.cpp @@ -1,17 +1,38 @@ #include "stdafx.h" #include "util/sysinfo.hpp" #include "util/v128.hpp" +#include "Emu/Cell/lv2/sys_process.h" #include "Emu/Memory/vm_ptr.h" #include "Emu/Cell/ErrorCodes.h" #include "Emu/System.h" #include "Emu/system_utils.hpp" #include "Emu/IdManager.h" +#include "Utilities/StrUtil.h" #include "Utilities/Thread.h" #include "sys_game.h" LOG_CHANNEL(sys_game); +struct system_sw_version +{ + system_sw_version() + { + f64 version_f = 0; + if (!try_to_float(&version_f, utils::get_firmware_version(), 0, 99.9999)) + sys_game.error("Error parsing firmware version"); + version = version_f * 10000; + } + + system_sw_version(const system_sw_version&) = delete; + + system_sw_version& operator=(const system_sw_version&) = delete; + + ~system_sw_version() = default; + + u64 version; +}; + struct board_storage { public: @@ -46,7 +67,7 @@ public: board_storage(const board_storage&) = delete; - board_storage& operator =(const board_storage&) = delete; + board_storage& operator=(const board_storage&) = delete; ~board_storage() { @@ -209,9 +230,23 @@ error_code _sys_game_watchdog_clear() return CELL_OK; } +error_code _sys_game_set_system_sw_version(u64 version) +{ + sys_game.trace("sys_game_set_system_sw_version(version=%d)", version); + + if (!g_ps3_process_info.has_root_perm()) + return CELL_EPERM; + + g_fxo->get().version = version; + + return CELL_OK; +} + u64 _sys_game_get_system_sw_version() { - return stof(utils::get_firmware_version()) * 10000; + sys_game.trace("sys_game_get_system_sw_version()"); + + return g_fxo->get().version; } error_code _sys_game_board_storage_read(vm::ptr buffer, vm::ptr status) diff --git a/rpcs3/Emu/Cell/lv2/sys_game.h b/rpcs3/Emu/Cell/lv2/sys_game.h index 77160216fc..a3c0237900 100644 --- a/rpcs3/Emu/Cell/lv2/sys_game.h +++ b/rpcs3/Emu/Cell/lv2/sys_game.h @@ -5,6 +5,7 @@ void abort_lv2_watchdog(); error_code _sys_game_watchdog_start(u32 timeout); error_code _sys_game_watchdog_stop(); error_code _sys_game_watchdog_clear(); +error_code _sys_game_set_system_sw_version(u64 version); u64 _sys_game_get_system_sw_version(); error_code _sys_game_board_storage_read(vm::ptr buffer, vm::ptr status); error_code _sys_game_board_storage_write(vm::ptr buffer, vm::ptr status);