From c3464dd5c3dc6dce9818964d40e6e1e86a3f1859 Mon Sep 17 00:00:00 2001 From: 66hh <49398720+66hh@users.noreply.github.com> Date: Sun, 28 Dec 2025 19:40:53 +0800 Subject: [PATCH] Introduce try_read/try_write for emulator_object --- src/windows-emulator/emulator_utils.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/windows-emulator/emulator_utils.hpp b/src/windows-emulator/emulator_utils.hpp index f8737ff6..c1f992fc 100644 --- a/src/windows-emulator/emulator_utils.hpp +++ b/src/windows-emulator/emulator_utils.hpp @@ -104,6 +104,16 @@ class emulator_object return this->address_ != 0; } + std::optional try_read(const size_t index = 0) const + { + T obj{}; + if (this->memory_->try_read_memory(this->address_ + index * this->size(), &obj, sizeof(obj))) + { + return obj; + } + return std::nullopt; + } + T read(const size_t index = 0) const { T obj{}; @@ -111,6 +121,11 @@ class emulator_object return obj; } + bool try_write(const T& value, const size_t index = 0) const + { + return this->memory_->try_write_memory(this->address_ + index * this->size(), &value, sizeof(value)); + } + void write(const T& value, const size_t index = 0) const { this->memory_->write_memory(this->address_ + index * this->size(), &value, sizeof(value));