Added std::vectors shim to read from client memory
This commit is contained in:
parent
2b66d01247
commit
94d5fc7e96
|
|
@ -68,12 +68,12 @@ void before_main_loop() {
|
|||
void after_main_loop() {
|
||||
// std::string test;
|
||||
|
||||
auto& music_properties = fugg::module_ref<fugg::Vector<flyff::MusicProperty>>(0x00034f7c);
|
||||
auto& item_properties = fugg::module_ref<fugg::Vector<flyff::ItemProperty>>(0x00035194);
|
||||
// auto& music_properties = fugg::module_ref<fugg::Vector<flyff::MusicProperty>>(0x00034f7c);
|
||||
// auto& item_properties = fugg::module_ref<fugg::Vector<flyff::ItemProperty>>(0x00035194);
|
||||
|
||||
for(auto& item : item_properties) {
|
||||
std::cout << item.some_string->c_str() << std::endl;
|
||||
}
|
||||
// for(auto& item : item_properties) {
|
||||
// std::cout << item.some_string->c_str() << std::endl;
|
||||
// }
|
||||
|
||||
// auto& item_properties = fugg::module_ref<fugg::Vector<flyff::ItemProperty>>(0x00035194);
|
||||
// std::cout << "Expecting " << reinterpret_cast<void*>(fugg::wasm::kMemory.address_of(0x00035194)) << std::endl;
|
||||
|
|
|
|||
|
|
@ -20,24 +20,32 @@ namespace fugg {
|
|||
}
|
||||
};
|
||||
|
||||
struct RawVector {
|
||||
uintptr_t begin;
|
||||
uintptr_t end;
|
||||
uintptr_t end_capacity;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawUniquePointer {
|
||||
T* ptr;
|
||||
uintptr_t ptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawHashTable {
|
||||
RawUniquePointer<T*[]> bucket_list;
|
||||
RawUniquePointer<uintptr_t[]> bucket_list;
|
||||
uintptr_t first_node;
|
||||
size_t capacity;
|
||||
float unknown;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawBasicString {
|
||||
T* data;
|
||||
uintptr_t data;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
};
|
||||
static_assert(
|
||||
sizeof(RawBasicString<char>) == sizeof(std::string),
|
||||
sizeof(RawBasicString) == sizeof(std::string),
|
||||
"RawBasicString needs to have same size of std::string"
|
||||
);
|
||||
|
||||
|
|
@ -70,11 +78,7 @@ namespace fugg {
|
|||
// A class that facilitates handling vectors that are allocated in a module.
|
||||
template<typename T>
|
||||
class Vector {
|
||||
struct RawVector {
|
||||
uintptr_t begin;
|
||||
uintptr_t end;
|
||||
uintptr_t end_capacity;
|
||||
};
|
||||
using RawVector = detail::RawVector;
|
||||
|
||||
ModulePointer<T> begin_;
|
||||
ModulePointer<T> end_;
|
||||
|
|
@ -107,7 +111,7 @@ namespace fugg {
|
|||
|
||||
template<class T>
|
||||
class BasicString {
|
||||
using value_type = T;
|
||||
using RawBasicString = detail::RawBasicString;
|
||||
|
||||
struct __long {
|
||||
ModulePointer<T> data;
|
||||
|
|
@ -115,11 +119,11 @@ namespace fugg {
|
|||
size_t cap;
|
||||
};
|
||||
|
||||
enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
|
||||
(sizeof(__long) - 1)/sizeof(value_type) : 2};
|
||||
enum {__min_cap = (sizeof(__long) - 1) / sizeof(T) > 2 ?
|
||||
(sizeof(__long) - 1) / sizeof(T) : 2};
|
||||
struct __short {
|
||||
value_type data[__min_cap];
|
||||
struct : detail::__padding<value_type>
|
||||
T data[__min_cap];
|
||||
struct : detail::__padding<T>
|
||||
{
|
||||
unsigned char size;
|
||||
};
|
||||
|
|
@ -130,12 +134,6 @@ namespace fugg {
|
|||
__short __s;
|
||||
};
|
||||
|
||||
struct RawBasicString {
|
||||
uintptr_t data;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
};
|
||||
|
||||
public:
|
||||
detail::ArrowProxy<RawBasicString, std::basic_string<T>> operator->() {
|
||||
// Copy the data to the stack.
|
||||
|
|
@ -143,8 +141,6 @@ namespace fugg {
|
|||
// If the string is using the __long representation, we need to
|
||||
// change the pointer to pointer into the module memory.
|
||||
auto is_small = -1 < (char)__s.size;
|
||||
|
||||
// std::cout << "Short version of string has size " << (int)__s.size << std::endl;
|
||||
|
||||
if(!is_small) {
|
||||
temp.data = __l.data.as_pointer();
|
||||
|
|
@ -162,4 +158,45 @@ namespace fugg {
|
|||
|
||||
using String = BasicString<char>;
|
||||
|
||||
template<typename T>
|
||||
class HashTable {
|
||||
// struct __hash_node_base {
|
||||
// using node_base_pointer = uintptr_t;
|
||||
// using __first_node = __hash_node_base;
|
||||
|
||||
// node_base_pointer next;
|
||||
// };
|
||||
|
||||
// struct __hash_node : public __hash_node_base {
|
||||
// typedef T __node_value_type;
|
||||
|
||||
// size_t __hash_;
|
||||
// __node_value_type __value_;
|
||||
// };
|
||||
|
||||
|
||||
// using __node_pointer = __hash_node_base::node_base_pointer;
|
||||
// using __node_base_type = __hash_node_base;
|
||||
// using __next_pointer = __node_pointer;
|
||||
|
||||
// using RawUniquePointer = detail::RawUniquePointer;
|
||||
// using BucketList = RawUniquePointer<__next_pointer[]>;
|
||||
// using __first_node = __hash_node_base::__first_node;
|
||||
|
||||
// BucketList bucketlist;
|
||||
// __first_node first;
|
||||
|
||||
|
||||
|
||||
// typedef T* _NodePtr;
|
||||
// typedef __hash_node_types<_NodePtr> type;
|
||||
// typedef typename __make_hash_node_types<value_type>::type _NodeTypes;
|
||||
// typedef typename _NodeTypes::__next_pointer __next_pointer;
|
||||
// typedef unique_ptr<__next_pointer[]> __bucket_list;
|
||||
// __bucket_list __bucket_list_;
|
||||
|
||||
// ModulePointer<
|
||||
// RawUniquePointer<uintptr_t[]> bucket_list;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue