diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 38a40e3b2d..761f784df8 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -206,16 +206,24 @@ namespace vm return *this; } + template requires (std::is_copy_constructible_v) + std::pair, char, std::remove_const_t>> try_read() const + { + alignas(sizeof(T) >= 16 ? 16 : 8) char buf[sizeof(T)]{}; + const bool ok = vm::try_access(vm::cast(m_addr), buf, sizeof(T), false); + return { ok, std::bit_cast(buf) }; + } + template requires (!std::is_void_v) bool try_read(std::conditional_t, char, std::remove_const_t>& out) const { - return vm::try_access(vm::cast(m_addr), &out, sizeof(T), false); + return vm::try_access(vm::cast(m_addr), std::addressof(out), sizeof(T), false); } template requires (!std::is_void_v && !std::is_const_v) bool try_write(const std::conditional_t, char, T>& _in) const { - return vm::try_access(vm::cast(m_addr), const_cast(&_in), sizeof(T), true); + return vm::try_access(vm::cast(m_addr), const_cast(std::addressof(_in)), sizeof(T), true); } // Don't use