From 8bde718b832dfffd366fb50afe788ba97f6c0457 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 13 Feb 2013 22:16:05 -0500 Subject: [PATCH] WritePString --- toolbox/toolbox.cpp | 15 +++++++++++++++ toolbox/toolbox.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index 0cd55c7..3da7df2 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -97,5 +97,20 @@ namespace ToolBox { return tmp; } + bool WritePString(uint32_t address, const std::string &s) + { + int length = s.length(); + if (length > 255) return false; + if (address == 0) return false; + + uint8_t *ptr = memoryPointer(address); + *ptr++ = (uint8_t)length; + for (char c : s) + { + *ptr++ = (uint8_t)c; + } + return true; + } + } \ No newline at end of file diff --git a/toolbox/toolbox.h b/toolbox/toolbox.h index 600391c..2800f4c 100644 --- a/toolbox/toolbox.h +++ b/toolbox/toolbox.h @@ -10,6 +10,8 @@ namespace ToolBox std::string ReadCString(uint32_t address); std::string ReadPString(uint32_t address); + bool WritePString(uint32_t address, const std::string &s); + }