Changed a whole bunch of memory shit
Added STL classes hackings
This commit is contained in:
parent
559544b3bb
commit
2b66d01247
|
|
@ -1,6 +1,9 @@
|
|||
project (fugg)
|
||||
cmake_minimum_required(VERSION 3.5.1)
|
||||
|
||||
# Flyff is based on c++14
|
||||
add_definitions(-std=c++14 -Os)
|
||||
|
||||
set(CMAKE_C_FLAGS "-Os")
|
||||
set(CMAKE_CXX_FLAGS "-Os")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
|
||||
|
|
|
|||
|
|
@ -157,7 +157,8 @@ typedef struct {
|
|||
} wasm_rt_elem_t;
|
||||
|
||||
/** A Memory object. */
|
||||
typedef struct {
|
||||
class wasm_rt_memory_t {
|
||||
public:
|
||||
/** The linear memory data, with a byte length of `size`. */
|
||||
uint8_t* data;
|
||||
/** The current and maximum page count for this Memory object. If there is no
|
||||
|
|
@ -165,7 +166,7 @@ typedef struct {
|
|||
uint32_t pages, max_pages;
|
||||
/** The current size of the linear memory, in bytes. */
|
||||
uint32_t size;
|
||||
} wasm_rt_memory_t;
|
||||
};
|
||||
|
||||
/** A Table object. */
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
add_definitions(-std=c++14 -Os)
|
||||
|
||||
add_executable(
|
||||
fugg-client
|
||||
"src/main.cpp"
|
||||
|
|
|
|||
|
|
@ -51,3 +51,80 @@ namespace fugg
|
|||
return (*import::_main)(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
void before_main_loop() {
|
||||
auto& client = fugg::Client::instance();
|
||||
}
|
||||
|
||||
#include "interop/flyff.h"
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
// std::cout << "Item has " << item_properties->size() << std::endl;
|
||||
|
||||
// std::cout << "There are " << item_properties->size() << " item properties." << std::endl;
|
||||
// for(const auto& item : *item_properties) {
|
||||
// std::cout << "Item with id " << item.translation_tag.tag << std::endl;
|
||||
// }
|
||||
|
||||
// auto test = reinterpret_cast<Pointer<int>*>(0x00035194);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// std::cout << "Test is at " << reinterpret_cast<void*>(test->to_intptr_t()) << std::endl;
|
||||
|
||||
// if((void*)test == (void*)0x00035194) {
|
||||
// std::cout << "Test is at the right address!" << std::endl;
|
||||
// }
|
||||
|
||||
// auto vector_location = fugg::ModulePointer<uintptr_t> { 0x00035194 };
|
||||
// auto ptr = fugg::ModulePointer<ThisPointerTest> { 0x00035194 };
|
||||
|
||||
// std::cout << "vector_location is at " << reinterpret_cast<void*>(0x00035194) << std::endl;
|
||||
// std::cout << "ptr is at " <<
|
||||
|
||||
// auto raw = new RawVector {
|
||||
// .begin = **fugg::ModulePointer<fugg::ModulePointer<uintptr_t>> { 0x00035194 + 0 },
|
||||
// .end = **fugg::ModulePointer<fugg::ModulePointer<uintptr_t>> { 0x00035194 + 4 },
|
||||
// .end_capacity = **fugg::ModulePointer<fugg::ModulePointer<uintptr_t>> { 0x00035194 + 8 },
|
||||
// };
|
||||
|
||||
// auto unique = std::unique_ptr<RawVector>(raw);
|
||||
// auto vec = reinterpret_cast<std::vector<flyff::ItemProperty>*>(raw);
|
||||
|
||||
// auto unique = std::unique_ptr<std::vector<flyff::ItemProperty>>(vec);
|
||||
|
||||
// std::cout << "There are " << unique->size() << " items!" << std::endl;
|
||||
|
||||
// Probably deconstructed here.
|
||||
|
||||
// std::cout << "Constructed raw. Call raw->temp..." << std::endl;
|
||||
|
||||
// std::cout << raw->temp << std::endl;
|
||||
|
||||
// std::cout << "Done calling raw->temp" << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ WASM_IMPORT_IMPL(env, _alSourceStop) = [](u32 a) {
|
|||
};
|
||||
// "L": "_alGetSourcei",
|
||||
WASM_IMPORT_IMPL(env, _alGetSourcei) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& value = fugg::module_ptr<ALint>(c);
|
||||
const auto& value = fugg::ModulePointer<ALint> { c };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alGetSourcei("
|
||||
|
|
@ -63,7 +63,7 @@ WASM_IMPORT_IMPL(env, _alGetSourcei) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'Q' */
|
||||
// "Q": "_alDeleteSources"
|
||||
WASM_IMPORT_IMPL(env, _alDeleteSources) = [](u32 a, u32 b) {
|
||||
const auto& sources = fugg::module_ptr<const ALuint>(b);
|
||||
const auto& sources = fugg::ModulePointer<const ALuint> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alDeleteSources("
|
||||
|
|
@ -102,7 +102,7 @@ WASM_IMPORT_IMPL(env, _alSourcePlay) = [](u32 a) {
|
|||
/* import: 'a' 'cb' */
|
||||
// "cb": "_alListenerfv",
|
||||
WASM_IMPORT_IMPL(env, _alListenerfv) = [](u32 a, u32 b) {
|
||||
const auto& values = fugg::module_ptr<const ALfloat>(b);
|
||||
const auto& values = fugg::ModulePointer<const ALfloat> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alListenerfv("
|
||||
|
|
@ -130,7 +130,7 @@ WASM_IMPORT_IMPL(env, _alListener3f) = [](u32 a, f32 b, f32 c, f32 d) {
|
|||
/* import: 'a' 'Sb' */
|
||||
/* _alDeleteBuffers */
|
||||
WASM_IMPORT_IMPL(env, _alDeleteBuffers) = [](u32 a, u32 b) {
|
||||
const auto& buffers = fugg::module_ptr<const ALuint>(b);
|
||||
const auto& buffers = fugg::ModulePointer<const ALuint> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alDeleteBuffers("
|
||||
|
|
@ -144,7 +144,7 @@ WASM_IMPORT_IMPL(env, _alDeleteBuffers) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'Tb' */
|
||||
/* _alBufferData */
|
||||
WASM_IMPORT_IMPL(env, _alBufferData) = [](u32 a, u32 b, u32 c, u32 d, u32 e) {
|
||||
const auto& data = fugg::module_ptr<const ALvoid>(c);
|
||||
const auto& data = fugg::ModulePointer<const ALvoid> { c };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alBufferData("
|
||||
|
|
@ -161,7 +161,7 @@ WASM_IMPORT_IMPL(env, _alBufferData) = [](u32 a, u32 b, u32 c, u32 d, u32 e) {
|
|||
/* import: 'a' 'Ub' */
|
||||
// "Ub": "_alGenBuffers",
|
||||
WASM_IMPORT_IMPL(env, _alGenBuffers) = [](u32 a, u32 b) {
|
||||
const auto& buffers = fugg::module_ptr<ALuint>(b);
|
||||
const auto& buffers = fugg::ModulePointer<ALuint> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alGenBuffers("
|
||||
|
|
@ -175,7 +175,7 @@ WASM_IMPORT_IMPL(env, _alGenBuffers) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'Vb' */
|
||||
// "Vb": "_alGetEnumValue",
|
||||
WASM_IMPORT_IMPL(env, _alGetEnumValue) = [](u32 a) {
|
||||
const auto& ename = fugg::module_ptr<const ALchar>(a);
|
||||
const auto& ename = fugg::ModulePointer<const ALchar> { a };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alGetEnumValue("
|
||||
|
|
@ -206,7 +206,7 @@ WASM_IMPORT_IMPL(env, _alcCloseDevice) = [](u32 a) {
|
|||
/* import: 'a' 'Yb' */
|
||||
// "Yb": "_alGenSources",
|
||||
WASM_IMPORT_IMPL(env, _alGenSources) = [](u32 a, u32 b) {
|
||||
const auto& sources = fugg::module_ptr<ALuint>(b);
|
||||
const auto& sources = fugg::ModulePointer<ALuint> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alGenSources("
|
||||
|
|
@ -250,7 +250,7 @@ WASM_IMPORT_IMPL(env, _alcMakeContextCurrent) = [](u32 a) {
|
|||
WASM_IMPORT_IMPL(env, _alcCreateContext) = [](u32 a, u32 b) {
|
||||
// ALCdevice is not data, but an index.
|
||||
const auto& device = reinterpret_cast<ALCdevice*>(a);
|
||||
const auto& attr_list = fugg::module_ptr<const ALCint>(b);
|
||||
const auto& attr_list = fugg::ModulePointer<const ALCint> { b };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alcCreateContext("
|
||||
|
|
@ -280,7 +280,7 @@ WASM_IMPORT_IMPL(env, _alcDestroyContext) = [](u32 a) {
|
|||
/* import: 'a' 'ac' */
|
||||
// "ac": "_alcOpenDevice",
|
||||
WASM_IMPORT_IMPL(env, _alcOpenDevice) = [](u32 a) {
|
||||
const auto& devicename = fugg::module_ptr<const ALchar>(a);
|
||||
const auto& devicename = fugg::ModulePointer<const ALchar> { a };
|
||||
|
||||
#if TRACE_AL_CALLS
|
||||
std::cout << "_alcOpenDevice("
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ WASM_IMPORT_IMPL(env, _emscripten_set_resize_callback_on_thread) = [](u32 a, u32
|
|||
// For the resize callback, pass in target = EMSCRIPTEN_EVENT_TARGET_WINDOW to get resize events from the Window object.
|
||||
const auto& target =
|
||||
reinterpret_cast<void*>(a) <= EMSCRIPTEN_EVENT_TARGET_SCREEN ?
|
||||
reinterpret_cast<const char*>(a) : fugg::module_ptr<const char>(a);
|
||||
reinterpret_cast<const char*>(a) : fugg::ModulePointer<const char> { a };
|
||||
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_resize_callback_on_thread("
|
||||
|
|
@ -36,8 +36,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_resize_callback_on_thread) = [](u32 a, u32
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenUiEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenUiEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ u32 original_devicemotion_callback = 0;
|
|||
/* import: 'a' 'sa' */
|
||||
// "sa": "_emscripten_set_devicemotion_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_devicemotion_callback_on_thread) = [](u32 a, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& user_data = fugg::module_ptr<void>(a);
|
||||
const auto& user_data = fugg::ModulePointer<void> { a };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_devicemotion_callback_on_thread("
|
||||
|
|
@ -67,8 +67,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_devicemotion_callback_on_thread) = [](u32
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenDeviceMotionEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenDeviceMotionEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ u32 original_beforeunload_callback = 0;
|
|||
/* import: 'a' 'va' */
|
||||
// "va": "_emscripten_set_beforeunload_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_beforeunload_callback_on_thread) = [](u32 a, u32 callback_, u32 target_thread) {
|
||||
const auto& user_data = fugg::module_ptr<void>(a);
|
||||
const auto& user_data = fugg::ModulePointer<void> { a };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_beforeunload_callback_on_thread("
|
||||
|
|
@ -97,8 +97,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_beforeunload_callback_on_thread) = [](u32
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const void*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const void> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -110,8 +110,8 @@ u32 original_focusout_callback = 0;
|
|||
/* import: 'a' 'Ca' */
|
||||
/* _emscripten_set_focusout_callback_on_thread */
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_focusout_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_focusout_callback_on_thread("
|
||||
|
|
@ -130,8 +130,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_focusout_callback_on_thread) = [](u32 a, u
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenFocusEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenFocusEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -143,8 +143,8 @@ u32 original_keyup_callback = 0;
|
|||
/* import: 'a' 'Da' */
|
||||
/* _emscripten_set_keyup_callback_on_thread */
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_keyup_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_keyup_callback_on_thread("
|
||||
|
|
@ -163,8 +163,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_keyup_callback_on_thread) = [](u32 a, u32
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenKeyboardEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenKeyboardEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -176,8 +176,8 @@ u32 original_keydown_callback = 0;
|
|||
/* import: 'a' 'Ea' */
|
||||
/* _emscripten_set_keydown_callback_on_thread */
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_keydown_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_keydown_callback_on_thread("
|
||||
|
|
@ -196,8 +196,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_keydown_callback_on_thread) = [](u32 a, u3
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenKeyboardEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenKeyboardEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -210,8 +210,8 @@ u32 original_wheel_callback = 0;
|
|||
/* import: 'a' 'Fa' */
|
||||
/* _emscripten_set_wheel_callback_on_thread */
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_wheel_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_wheel_callback_on_thread("
|
||||
|
|
@ -230,8 +230,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_wheel_callback_on_thread) = [](u32 a, u32
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenWheelEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenWheelEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -244,8 +244,8 @@ u32 original_mouseleave_callback = 0;
|
|||
/* import: 'a' 'Ga' */
|
||||
// "Ga": "_emscripten_set_mouseleave_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_mouseleave_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_mouseleave_callback_on_thread("
|
||||
|
|
@ -264,8 +264,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_mouseleave_callback_on_thread) = [](u32 a,
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenMouseEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenMouseEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -277,8 +277,8 @@ u32 original_mousemove_callback = 0;
|
|||
/* import: 'a' 'Ha' */
|
||||
// "Ha": "_emscripten_set_mousemove_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_mousemove_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_mousemove_callback_on_thread("
|
||||
|
|
@ -297,8 +297,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_mousemove_callback_on_thread) = [](u32 a,
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenMouseEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenMouseEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -310,8 +310,8 @@ u32 original_mouseup_callback = 0;
|
|||
/* import: 'a' 'Ia' */
|
||||
// "Ia": "_emscripten_set_mouseup_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_mouseup_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_mouseup_callback_on_thread("
|
||||
|
|
@ -330,8 +330,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_mouseup_callback_on_thread) = [](u32 a, u3
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenMouseEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenMouseEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -343,8 +343,8 @@ u32 orignal_mousedown_callback = 0;
|
|||
/* import: 'a' 'Ja' */
|
||||
// "Ja": "_emscripten_set_mousedown_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_mousedown_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_mousedown_callback_on_thread("
|
||||
|
|
@ -363,8 +363,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_mousedown_callback_on_thread) = [](u32 a,
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenMouseEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenMouseEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -376,8 +376,8 @@ u32 original_touchcancel_callback = 0;
|
|||
/* import: 'a' 'Ka' */
|
||||
// "Ka": "_emscripten_set_touchcancel_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_touchcancel_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_touchcancel_callback_on_thread("
|
||||
|
|
@ -396,8 +396,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_touchcancel_callback_on_thread) = [](u32 a
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenTouchEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenTouchEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -409,8 +409,8 @@ u32 original_touchmove_callback = 0;
|
|||
/* import: 'a' 'La' */
|
||||
// "La": "_emscripten_set_touchmove_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_touchmove_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_touchmove_callback_on_thread("
|
||||
|
|
@ -429,8 +429,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_touchmove_callback_on_thread) = [](u32 a,
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenTouchEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenTouchEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -442,8 +442,8 @@ u32 original_touchend_callback = 0;
|
|||
/* import: 'a' 'Ma' */
|
||||
// "Ma": "_emscripten_set_touchend_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_touchend_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_touchend_callback_on_thread("
|
||||
|
|
@ -462,8 +462,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_touchend_callback_on_thread) = [](u32 a, u
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenTouchEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenTouchEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -475,8 +475,8 @@ u32 original_touchstart_callback = 0;
|
|||
/* import: 'a' 'Na' */
|
||||
// "Na": "_emscripten_set_touchstart_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_touchstart_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_touchstart_callback_on_thread("
|
||||
|
|
@ -495,8 +495,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_touchstart_callback_on_thread) = [](u32 a,
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenTouchEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenTouchEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -508,7 +508,7 @@ u32 original_orientationchange_callback = 0;
|
|||
/* import: 'a' 'Pa' */
|
||||
// "Pa": "_emscripten_set_orientationchange_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_orientationchange_callback_on_thread) = [](u32 a, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& user_data = fugg::module_ptr<void>(a);
|
||||
const auto& user_data = fugg::ModulePointer<void> { a };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_orientationchange_callback_on_thread("
|
||||
|
|
@ -526,8 +526,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_orientationchange_callback_on_thread) = []
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenOrientationChangeEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenOrientationChangeEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ u32 original_visibilitychange_callback = 0;
|
|||
/* import: 'a' 'Ra' */
|
||||
// "Ra": "_emscripten_set_visibilitychange_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_visibilitychange_callback_on_thread) = [](u32 a, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& user_data = fugg::module_ptr<void>(a);
|
||||
const auto& user_data = fugg::ModulePointer<void> { a };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_visibilitychange_callback_on_thread("
|
||||
|
|
@ -557,8 +557,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_visibilitychange_callback_on_thread) = [](
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenVisibilityChangeEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenVisibilityChangeEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -570,8 +570,8 @@ u32 original_webglcontextrestored_callback = 0;
|
|||
/* import: 'a' 'Ba' */
|
||||
/* _emscripten_set_webglcontextrestored_callback_on_thread */
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_webglcontextrestored_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_webglcontextrestored_callback_on_thread("
|
||||
|
|
@ -590,8 +590,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_webglcontextrestored_callback_on_thread) =
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const void*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const void> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -603,8 +603,8 @@ u32 original_webglcontextlost_callback = 0;
|
|||
/* import: 'a' 'eb' */
|
||||
// "eb": "_emscripten_set_webglcontextlost_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_webglcontextlost_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_webglcontextlost_callback_on_thread("
|
||||
|
|
@ -623,8 +623,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_webglcontextlost_callback_on_thread) = [](
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const void*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const void> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -636,8 +636,8 @@ u32 original_fullscreenchange_callback = 0;
|
|||
/* import: 'a' 'yb' */
|
||||
// "yb": "_emscripten_set_fullscreenchange_callback_on_thread",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_fullscreenchange_callback_on_thread) = [](u32 a, u32 b, u32 use_capture, u32 callback_, u32 target_thread) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& user_data = fugg::module_ptr<void>(b);
|
||||
const auto& target = fugg::ModulePointer<const char> { a };
|
||||
const auto& user_data = fugg::ModulePointer<void> { b };
|
||||
|
||||
#if TRACE_CALLBACK_CALLS
|
||||
std::cout << "_emscripten_set_fullscreenchange_callback_on_thread("
|
||||
|
|
@ -657,8 +657,8 @@ WASM_IMPORT_IMPL(env, _emscripten_set_fullscreenchange_callback_on_thread) = [](
|
|||
|
||||
return callback(
|
||||
eventType,
|
||||
reinterpret_cast<const EmscriptenFullscreenChangeEvent*>(fugg::app_ptr(event)),
|
||||
reinterpret_cast<void*>(fugg::app_ptr(userData))
|
||||
fugg::RuntimePointer<const EmscriptenFullscreenChangeEvent> { event },
|
||||
fugg::RuntimePointer<void> { userData }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
namespace fugg {
|
||||
namespace embind {
|
||||
std::map<TypeID, const TypeInfo *const> kTypeMap = { };
|
||||
std::map<std::string, const FunctionEntry *const> kFunctionMap = { };
|
||||
std::map<emscripten::internal::EM_METHOD_CALLER, MethodCaller*> kMethodCallers = { };
|
||||
std::unordered_map<TypeID, const TypeInfo *const> kTypeMap = { };
|
||||
std::unordered_map<std::string, const FunctionEntry *const> kFunctionMap = { };
|
||||
std::unordered_map<emscripten::internal::EM_METHOD_CALLER, MethodCaller*> kMethodCallers = { };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,19 +38,14 @@ GenericWireType to_wasm_wire_type(
|
|||
// Do nothing.
|
||||
return val;
|
||||
|
||||
case Type::String: {
|
||||
case Type::String: {
|
||||
struct WireData {
|
||||
size_t length;
|
||||
char data[1];
|
||||
};
|
||||
|
||||
auto pointee = reinterpret_cast<WireData*>(
|
||||
static_cast<uintptr_t>(val)
|
||||
);
|
||||
|
||||
return static_cast<emscripten::internal::EM_GENERIC_WIRE_TYPE>(
|
||||
fugg::app_ptr(pointee)
|
||||
);
|
||||
// Strings just need to have their pointer offset.
|
||||
return fugg::RuntimePointer<WireData> { val }.as_raw();
|
||||
} break;
|
||||
|
||||
case Type::MemoryView: {
|
||||
|
|
@ -95,8 +90,8 @@ void* from_wasm_wire_type(
|
|||
void* data;
|
||||
};
|
||||
|
||||
auto data = reinterpret_cast<WireData*>(val);
|
||||
data->data = fugg::module_ptr(data->data);
|
||||
const auto& data = reinterpret_cast<WireData*>(val);
|
||||
data->data = fugg::ModulePointer<void> { data->data };
|
||||
} break;
|
||||
|
||||
default:
|
||||
|
|
@ -123,7 +118,7 @@ WASM_IMPORT_IMPL(env, __emval_decref) = [](u32 a) {
|
|||
/* import: 'a' 'c' */
|
||||
/* __emval_new_cstring */
|
||||
WASM_IMPORT_IMPL(env, __emval_new_cstring) = [](u32 value_) {
|
||||
const auto& value = fugg::module_ptr<const char>(value_);
|
||||
const auto& value = fugg::ModulePointer<const char> { value_ };
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_new_cstring("
|
||||
|
|
@ -188,8 +183,8 @@ WASM_IMPORT_IMPL(env, __emval_get_method_caller) = [](u32 argCount_, u32 argType
|
|||
/* import: 'a' 'l' */
|
||||
/* __emval_take_value */
|
||||
WASM_IMPORT_IMPL(env, __emval_take_value) = [](u32 type_, u32 argv_) {
|
||||
TypeID type = fugg::module_ptr<TypeID>(type_);
|
||||
auto argv = fugg::module_ptr<void>(argv_);
|
||||
TypeID type = fugg::ModulePointer<TypeID>(type_);
|
||||
auto argv = fugg::ModulePointer<void>(argv_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_take_value("
|
||||
|
|
@ -209,19 +204,19 @@ WASM_IMPORT_IMPL(env, __emval_take_value) = [](u32 type_, u32 argv_) {
|
|||
/* import: 'a' 'o' */
|
||||
/* __emval_run_destructors */
|
||||
WASM_IMPORT_IMPL(env, __emval_run_destructors) = [](u32 a) {
|
||||
// EM_DESTRUCTORS is a handle, so no interop required.
|
||||
const auto& destructors = reinterpret_cast<Destructors>(a);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_run_destructors("
|
||||
<< reinterpret_cast<void*>(a) << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
emscripten::internal::_emval_run_destructors(
|
||||
// EM_DESTRUCTORS is a handle, so no interop required.
|
||||
reinterpret_cast<Destructors>(a)
|
||||
);
|
||||
emscripten::internal::_emval_run_destructors(destructors);
|
||||
};
|
||||
/* __emval_get_global */
|
||||
WASM_IMPORT_IMPL(env, __emval_get_global) = [](u32 name_) {
|
||||
const auto& name = fugg::module_ptr<const char>(name_);
|
||||
const auto& name = fugg::ModulePointer<const char>(name_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_get_global("
|
||||
|
|
@ -240,8 +235,8 @@ WASM_IMPORT_IMPL(env, __emval_call_void_method) = [](u32 caller_, u32 handle_, u
|
|||
// EM_METHOD_CALLER is used as an index, so no interop is required.
|
||||
const auto& caller = reinterpret_cast<emscripten::internal::EM_METHOD_CALLER>(caller_);
|
||||
const auto& handle = reinterpret_cast<Value>(handle_);
|
||||
const auto& method_name = fugg::module_ptr<const char>(methodName_);
|
||||
const auto& argv = fugg::module_ptr<void>(argv_);
|
||||
const auto& method_name = fugg::ModulePointer<const char>(methodName_);
|
||||
const auto& argv = fugg::ModulePointer<void>(argv_);
|
||||
|
||||
const auto& method_caller = kMethodCallers[caller];
|
||||
|
||||
|
|
@ -266,8 +261,8 @@ WASM_IMPORT_IMPL(env, __emval_as) = [](u32 a, u32 b, u32 c) {
|
|||
// EM_VAL is just a number of the handle, so no interop required.
|
||||
const auto& value = reinterpret_cast<emscripten::EM_VAL>(a);
|
||||
|
||||
const auto& return_type = fugg::module_ptr<TypeID>(b);
|
||||
const auto& destructors = fugg::module_ptr<emscripten::internal::EM_DESTRUCTORS>(c);
|
||||
const auto& return_type = fugg::ModulePointer<TypeID>(b);
|
||||
const auto& destructors = fugg::ModulePointer<emscripten::internal::EM_DESTRUCTORS>(c);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_as("
|
||||
|
|
@ -294,11 +289,11 @@ WASM_IMPORT_IMPL(env, __emval_incref) = [](u32 a) {
|
|||
WASM_IMPORT_IMPL(env, __emval_call_method) = [](u32 a, u32 b, u32 c, u32 d, u32 argv_) {
|
||||
const auto& caller = reinterpret_cast<emscripten::internal::EM_METHOD_CALLER>(a);
|
||||
const auto& handle = reinterpret_cast<emscripten::EM_VAL>(b);
|
||||
const auto& method_name = fugg::module_ptr<const char>(c);
|
||||
const auto& destructors = fugg::module_ptr<emscripten::internal::EM_DESTRUCTORS>(d);
|
||||
const auto& method_name = fugg::ModulePointer<const char>(c);
|
||||
const auto& destructors = fugg::ModulePointer<emscripten::internal::EM_DESTRUCTORS>(d);
|
||||
|
||||
const auto& method_caller = kMethodCallers.at(caller);
|
||||
const auto& argv = fugg::module_ptr<void>(argv_);
|
||||
const auto& argv = fugg::ModulePointer<void>(argv_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_call_method("
|
||||
|
|
@ -324,7 +319,7 @@ WASM_IMPORT_IMPL(env, __emval_call_method) = [](u32 a, u32 b, u32 c, u32 d, u32
|
|||
};
|
||||
/* __emval_get_module_property */
|
||||
WASM_IMPORT_IMPL(env, __emval_get_module_property) = [](u32 a) {
|
||||
const auto& name = fugg::module_ptr<const char>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(a);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emval_get_module_property(" << name << ")" << std::endl;
|
||||
|
|
@ -345,10 +340,10 @@ WASM_IMPORT_IMPL(env, __emval_typeof) = [](u32 a) {
|
|||
|
||||
/* __embind_register_function */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_function) = [](u32 a, u32 arg_count, u32 c, u32 d, u32 invoker_, u32 function_) {
|
||||
const auto& name = fugg::module_ptr<const char>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(a);
|
||||
// This is an array, but not an array of pointers.
|
||||
const auto& arg_types = fugg::module_ptr<emscripten::internal::TYPEID>(c);
|
||||
const auto& signature = fugg::module_ptr<const char>(d);
|
||||
const auto& arg_types = fugg::ModulePointer<emscripten::internal::TYPEID>(c);
|
||||
const auto& signature = fugg::ModulePointer<const char>(d);
|
||||
// The invoker seems to convert the types received by the function.
|
||||
const auto& invoker = fugg::function_ref<emscripten::internal::GenericFunction>(invoker_);
|
||||
const auto& function = fugg::function_ref<emscripten::internal::GenericFunction>(function_);
|
||||
|
|
@ -382,14 +377,13 @@ WASM_IMPORT_IMPL(env, __emval_new) = [](u32 a, u32 arg_count, u32 arg_types_, u3
|
|||
auto value = reinterpret_cast<emscripten::EM_VAL>(a);
|
||||
// To prevent double converting pointers in the arg_type array, create a new
|
||||
// array.
|
||||
auto test_arg_types = new void*[arg_count];
|
||||
auto arg_types_copy = new void*[arg_count];
|
||||
|
||||
using TypeID = void*;
|
||||
auto arg_types = fugg::module_ptr<TypeID>(arg_types_);
|
||||
const auto& arg_types = fugg::ModulePointer<TypeID*>(arg_types_);
|
||||
for(int i = 0; i < arg_count; i++)
|
||||
test_arg_types[i] = fugg::module_ptr(arg_types[i]);
|
||||
arg_types_copy[i] = fugg::ModulePointer<TypeID> { arg_types[i] };
|
||||
|
||||
auto argv = fugg::module_ptr<void>(argv_);
|
||||
auto argv = fugg::ModulePointer<void>(argv_);
|
||||
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
|
|
@ -400,14 +394,16 @@ WASM_IMPORT_IMPL(env, __emval_new) = [](u32 a, u32 arg_count, u32 arg_types_, u3
|
|||
<< argv << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
return reinterpret_cast<u32>(
|
||||
emscripten::internal::_emval_new(
|
||||
value,
|
||||
arg_count,
|
||||
test_arg_types,
|
||||
from_wasm_wire_type(arg_count, test_arg_types, argv)
|
||||
)
|
||||
const auto result = emscripten::internal::_emval_new(
|
||||
value,
|
||||
arg_count,
|
||||
arg_types_copy,
|
||||
from_wasm_wire_type(arg_count, arg_types_copy, argv)
|
||||
);
|
||||
|
||||
delete[] arg_types_copy;
|
||||
|
||||
return reinterpret_cast<u32>(result);
|
||||
};
|
||||
/* import: 'a' 'ya' */
|
||||
// "ya": "_emscripten_resize_heap",
|
||||
|
|
@ -420,8 +416,8 @@ WASM_IMPORT_IMPL(env, _emscripten_resize_heap) = [](u32 a) {
|
|||
/* import: 'a' 'za' */
|
||||
/* __embind_register_std_wstring */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_std_wstring) = [](u32 a, u32 char_size, u32 c) {
|
||||
const auto& string_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(c);
|
||||
const auto& string_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(c);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_std_wstring("
|
||||
|
|
@ -440,8 +436,8 @@ WASM_IMPORT_IMPL(env, __embind_register_std_wstring) = [](u32 a, u32 char_size,
|
|||
/* import: 'a' '_a' */
|
||||
/* __embind_register_float */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_float) = [](u32 a, u32 b, u32 size) {
|
||||
const auto& float_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(b);
|
||||
const auto& float_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_float("
|
||||
|
|
@ -460,8 +456,8 @@ WASM_IMPORT_IMPL(env, __embind_register_float) = [](u32 a, u32 b, u32 size) {
|
|||
/* import: 'a' '$a' */
|
||||
/* __embind_register_std_string */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_std_string) = [](u32 a, u32 b) {
|
||||
const auto& string_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(b);
|
||||
const auto& string_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_std_string("
|
||||
|
|
@ -484,8 +480,8 @@ WASM_IMPORT_IMPL(env, __embind_register_bigint) = [](u32 registerType, u32 name_
|
|||
/* import: 'a' 'Ob' */
|
||||
/* __embind_register_emval */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_emval) = [](u32 a, u32 b) {
|
||||
const auto& emval_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(b);
|
||||
const auto& emval_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_emval("
|
||||
|
|
@ -503,8 +499,8 @@ WASM_IMPORT_IMPL(env, __embind_register_emval) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'Pb' */
|
||||
/* __embind_register_bool */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_bool) = [](u32 a, u32 b, u32 size, u32 true_value, u32 false_value) {
|
||||
const auto& bool_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(b);
|
||||
const auto& bool_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_bool("
|
||||
|
|
@ -525,8 +521,8 @@ WASM_IMPORT_IMPL(env, __embind_register_bool) = [](u32 a, u32 b, u32 size, u32 t
|
|||
/* import: 'a' 'Qb' */
|
||||
/* __embind_register_void */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_void) = [](u32 a, u32 b) {
|
||||
const auto& void_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::module_ptr<const char>(b);
|
||||
const auto& void_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& name = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_void("
|
||||
|
|
@ -545,9 +541,9 @@ WASM_IMPORT_IMPL(env, __embind_register_void) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'J' */
|
||||
/* __embind_register_memory_view */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_memory_view) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& memory_view_type = fugg::module_ptr<emscripten::internal::TYPEID>(a);
|
||||
const auto& memory_view_type = fugg::ModulePointer<emscripten::internal::TYPEID>(a);
|
||||
const auto& typed_array_index = b;
|
||||
const auto& name = fugg::module_ptr<const char>(c);
|
||||
const auto& name = fugg::ModulePointer<const char>(c);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_memory_view("
|
||||
|
|
@ -565,8 +561,8 @@ WASM_IMPORT_IMPL(env, __embind_register_memory_view) = [](u32 a, u32 b, u32 c) {
|
|||
};
|
||||
/* __embind_register_integer */
|
||||
WASM_IMPORT_IMPL(env, __embind_register_integer) = [](u32 integer_type_, u32 name_, u32 size, u32 min_range, u32 max_range) {
|
||||
const auto& integer_type = fugg::module_ptr<TypeID>(integer_type_);
|
||||
const auto& name = fugg::module_ptr<const char>(name_);
|
||||
const auto& integer_type = fugg::ModulePointer<TypeID>(integer_type_);
|
||||
const auto& name = fugg::ModulePointer<const char>(name_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_embind_register_integer("
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <emscripten.h>
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace fugg {
|
||||
namespace embind {
|
||||
|
|
@ -40,8 +41,8 @@ namespace fugg {
|
|||
const emscripten::internal::TYPEID* arg_types;
|
||||
};
|
||||
|
||||
extern std::map<TypeID, const TypeInfo *const> kTypeMap;
|
||||
extern std::map<std::string, const FunctionEntry *const> kFunctionMap;
|
||||
extern std::map<emscripten::internal::EM_METHOD_CALLER, MethodCaller*> kMethodCallers;
|
||||
extern std::unordered_map<TypeID, const TypeInfo *const> kTypeMap;
|
||||
extern std::unordered_map<std::string, const FunctionEntry *const> kFunctionMap;
|
||||
extern std::unordered_map<emscripten::internal::EM_METHOD_CALLER, MethodCaller*> kMethodCallers;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,9 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
extern void before_main_loop();
|
||||
extern void after_main_loop();
|
||||
|
||||
/* import: 'a' 'qa' */
|
||||
// "qa": "_emscripten_set_main_loop",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_main_loop) = [](u32 a, u32 fps, u32 simulate_infinite_loop) {
|
||||
|
|
@ -17,9 +20,12 @@ WASM_IMPORT_IMPL(env, _emscripten_set_main_loop) = [](u32 a, u32 fps, u32 simula
|
|||
|
||||
auto main_loop_override = []() {
|
||||
// std::cout << "This is fugg main loop being called! Calling original loop... at " << reinterpret_cast<void*>(original_main_loop) << std::endl;
|
||||
before_main_loop();
|
||||
|
||||
const auto& func = fugg::function_ref<em_callback_func>(original_main_loop);
|
||||
func();
|
||||
|
||||
after_main_loop();
|
||||
};
|
||||
|
||||
original_main_loop = a;
|
||||
|
|
@ -59,7 +65,7 @@ WASM_IMPORT_IMPL(env, _emscripten_async_wget_data) = [](u32 url_, u32 arg_, u32
|
|||
const auto& onload = fugg::function_ref<em_async_wget_onload_func>(interop_data->onload);
|
||||
// This pointer can stay unchanged, it came from inside and is going inside.
|
||||
const auto& arg = reinterpret_cast<void*>(interop_data->original_arg);
|
||||
const auto& data = reinterpret_cast<void*>(fugg::app_ptr(data_));
|
||||
const auto& data = fugg::RuntimePointer<void> { data_ };
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "onload_stub: Calling function at " << reinterpret_cast<void*>(onload) << "("
|
||||
|
|
@ -89,7 +95,7 @@ WASM_IMPORT_IMPL(env, _emscripten_async_wget_data) = [](u32 url_, u32 arg_, u32
|
|||
delete interop_data;
|
||||
};
|
||||
|
||||
const auto& url = fugg::module_ptr<const char>(url_);
|
||||
const auto& url = fugg::ModulePointer<const char> { url_ };
|
||||
|
||||
const auto data = new wget_data {
|
||||
.onload = onload_,
|
||||
|
|
@ -105,7 +111,7 @@ WASM_IMPORT_IMPL(env, _emscripten_async_wget_data) = [](u32 url_, u32 arg_, u32
|
|||
<< reinterpret_cast<void*>(onerror_) << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
std::cout << "Client: Downloading " << static_cast<const char*>(url) << std::endl;
|
||||
// std::cout << "Client: Downloading " << static_cast<const char*>(url) << std::endl;
|
||||
|
||||
// This function can allocate, which will call the Flyff runtime allocate.
|
||||
emscripten_async_wget_data(url, data, onload_stub, onerror_stub);
|
||||
|
|
@ -113,7 +119,7 @@ WASM_IMPORT_IMPL(env, _emscripten_async_wget_data) = [](u32 url_, u32 arg_, u32
|
|||
/* import: 'a' 'fb' */
|
||||
// "fb": "_emscripten_set_element_css_size",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_element_css_size) = [](u32 target_, f64 width, f64 height) {
|
||||
const auto& target = fugg::module_ptr<const char>(target_);
|
||||
const auto& target = fugg::ModulePointer<const char>(target_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emscripten_set_element_css_size("
|
||||
|
|
@ -129,7 +135,7 @@ WASM_IMPORT_IMPL(env, _emscripten_set_element_css_size) = [](u32 target_, f64 wi
|
|||
/* import: 'a' 'gb' */
|
||||
// "gb": "_emscripten_set_canvas_element_size",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_set_canvas_element_size) = [](u32 target_, u32 width, u32 height) {
|
||||
const auto& target = fugg::module_ptr<const char>(target_);
|
||||
const auto& target = fugg::ModulePointer<const char>(target_);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emscripten_set_canvas_element_size("
|
||||
|
|
@ -147,7 +153,7 @@ WASM_IMPORT_IMPL(env, _emscripten_set_canvas_element_size) = [](u32 target_, u32
|
|||
WASM_IMPORT_IMPL(env, _emscripten_get_orientation_status) = [](u32 a) {
|
||||
return static_cast<u32>(
|
||||
emscripten_get_orientation_status(
|
||||
fugg::module_ptr<EmscriptenOrientationChangeEvent>(a)
|
||||
fugg::ModulePointer<EmscriptenOrientationChangeEvent>(a)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
@ -199,10 +205,10 @@ WASM_IMPORT_IMPL(env, _emscripten_vibrate) = [](u32 a) {
|
|||
WASM_IMPORT_IMPL(env, _strftime) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
return static_cast<u32>(
|
||||
strftime(
|
||||
fugg::module_ptr<char>(a),
|
||||
fugg::ModulePointer<char>(a),
|
||||
b,
|
||||
fugg::module_ptr<char>(c),
|
||||
fugg::module_ptr<const tm>(d)
|
||||
fugg::ModulePointer<char>(c),
|
||||
fugg::ModulePointer<const tm>(d)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
@ -260,8 +266,8 @@ WASM_IMPORT_IMPL(env, _fd_write) = [](u32 a, u32 b, u32 c, u32 d) {
|
|||
WASM_IMPORT_IMPL(env, _emscripten_memcpy_big) = [](u32 dest_, u32 src_, u32 length) {
|
||||
// WASM runtime calls this, so no need to change the pointers since it's "internal".
|
||||
// Right?
|
||||
const auto& dest = fugg::module_ptr<void>(dest_);
|
||||
const auto& src = fugg::module_ptr<void>(src_);
|
||||
const auto& dest = fugg::ModulePointer<void>(dest_);
|
||||
const auto& src = fugg::ModulePointer<void>(src_);
|
||||
|
||||
#if TRACE_ALLOC
|
||||
std::cout << "_emscripten_memcpy_big("
|
||||
|
|
@ -308,14 +314,14 @@ WASM_IMPORT_IMPL(env, __tzset_js) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'Rb' */
|
||||
// "Rb": "_emscripten_log",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_log) = [](u32 flags, u32 b, u32 c) {
|
||||
const auto& format = fugg::module_ptr<const char>(b);
|
||||
const auto& format = fugg::ModulePointer<const char>(b);
|
||||
|
||||
emscripten_log(flags, format, c);
|
||||
};
|
||||
/* import: 'a' 'bc' */
|
||||
// "bc": "_emscripten_get_fullscreen_status",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_get_fullscreen_status) = [](u32 a) {
|
||||
const auto& fullscreen_status = fugg::module_ptr<EmscriptenFullscreenChangeEvent>(a);
|
||||
const auto& fullscreen_status = fugg::ModulePointer<EmscriptenFullscreenChangeEvent>(a);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emscripten_get_fullscreen_status("
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
/* import: 'a' 'i' */
|
||||
// "i": "_glDisableVertexAttribArray",
|
||||
WASM_IMPORT_IMPL(env, _glDisableVertexAttribArray) = [](u32 a) {
|
||||
const auto& index = fugg::Value<GLuint>(a);
|
||||
const auto& index = reinterpret_cast<GLuint>(a);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDisableVertexAttribArray("
|
||||
|
|
@ -25,10 +25,10 @@ WASM_IMPORT_IMPL(env, _glDisableVertexAttribArray) = [](u32 a) {
|
|||
/* import: 'a' 'j' */
|
||||
// "j": "_glUniformMatrix4fv",
|
||||
WASM_IMPORT_IMPL(env, _glUniformMatrix4fv) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
const auto& location = fugg::Value<GLuint>(a);
|
||||
const auto& count = fugg::Value<GLsizei>(b);
|
||||
const auto& transpose = fugg::Value<GLboolean>(c);
|
||||
const auto& value = fugg::module_ptr<const GLfloat>(d);
|
||||
const auto& location = reinterpret_cast<GLuint>(a);
|
||||
const auto& count = static_cast<GLsizei>(b);
|
||||
const auto& transpose = static_cast<GLboolean>(c);
|
||||
const auto& value = fugg::ModulePointer<const GLfloat>(d);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glUniformMatrix4fv("
|
||||
|
|
@ -46,7 +46,7 @@ WASM_IMPORT_IMPL(env, _glUniformMatrix4fv) = [](u32 a, u32 b, u32 c, u32 d) {
|
|||
// "d": "_glActiveTexture",
|
||||
/* _glActiveTexture */
|
||||
WASM_IMPORT_IMPL(env, _glActiveTexture) = [](u32 a) {
|
||||
const auto& texture = fugg::Value<GLenum>(a);
|
||||
const auto& texture = reinterpret_cast<GLenum>(a);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glActiveTexture("
|
||||
|
|
@ -60,8 +60,8 @@ WASM_IMPORT_IMPL(env, _glActiveTexture) = [](u32 a) {
|
|||
// "e": "_glBindTexture",
|
||||
/* _glBindTexture */
|
||||
WASM_IMPORT_IMPL(env, _glBindTexture) = [](u32 a, u32 b) {
|
||||
const auto& target = fugg::Value<GLenum>(a);
|
||||
const auto& texture = fugg::Value<GLuint>(b);
|
||||
const auto& target = reinterpret_cast<GLenum>(a);
|
||||
const auto& texture = reinterpret_cast<GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glBindTexture("
|
||||
|
|
@ -75,11 +75,11 @@ WASM_IMPORT_IMPL(env, _glBindTexture) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'f' */
|
||||
// "f": "_glVertexAttribPointer",
|
||||
WASM_IMPORT_IMPL(env, _glVertexAttribPointer) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f) {
|
||||
const auto& index = fugg::Value<GLuint>(a);
|
||||
const auto& size = fugg::Value<GLint>(b);
|
||||
const auto& type = fugg::Value<GLenum>(c);
|
||||
const auto& normalized = fugg::Value<GLboolean>(d);
|
||||
const auto& stride = fugg::Value<GLsizei>(e);
|
||||
const auto& index = reinterpret_cast<GLuint>(a);
|
||||
const auto& size = static_cast<GLint>(b);
|
||||
const auto& type = reinterpret_cast<GLenum>(c);
|
||||
const auto& normalized = static_cast<GLboolean>(d);
|
||||
const auto& stride = static_cast<GLsizei>(e);
|
||||
// Specifies a offset of the first component, so although it's a pointer,
|
||||
// it's doesn't need to be transformed.
|
||||
const auto& pointer = reinterpret_cast<const void*>(f);
|
||||
|
|
@ -100,8 +100,8 @@ WASM_IMPORT_IMPL(env, _glVertexAttribPointer) = [](u32 a, u32 b, u32 c, u32 d, u
|
|||
|
||||
// "m": "_glBindBuffer",
|
||||
WASM_IMPORT_IMPL(env, _glBindBuffer) = [](u32 a, u32 b) {
|
||||
const auto& target = fugg::Value<GLenum>(a);
|
||||
const auto& buffer = fugg::Value<GLuint>(b);
|
||||
const auto& target = reinterpret_cast<GLenum>(a);
|
||||
const auto& buffer = reinterpret_cast<GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glBindBuffer("
|
||||
|
|
@ -115,7 +115,7 @@ WASM_IMPORT_IMPL(env, _glBindBuffer) = [](u32 a, u32 b) {
|
|||
|
||||
// "n": "_glDisable",
|
||||
WASM_IMPORT_IMPL(env, _glDisable) = [](u32 a) {
|
||||
const auto& cap = fugg::Value<GLenum>(a);
|
||||
const auto& cap = reinterpret_cast<GLenum>(a);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDisable("
|
||||
|
|
@ -233,7 +233,7 @@ WASM_IMPORT_IMPL(env, _glBindFramebuffer) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'D' */
|
||||
/* _glDrawElements */
|
||||
WASM_IMPORT_IMPL(env, _glDrawElements) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
const auto& indices = fugg::module_ptr<const void*>(d);
|
||||
const auto& indices = fugg::ModulePointer<const void*>(d);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDrawElements("
|
||||
|
|
@ -255,7 +255,7 @@ WASM_IMPORT_IMPL(env, _glDrawElements) = [](u32 a, u32 b, u32 c, u32 d) {
|
|||
/* import: 'a' 'I' */
|
||||
/* "I": "_glUniform3fv" */
|
||||
WASM_IMPORT_IMPL(env, _glUniform3fv) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& value = fugg::module_ptr<const GLfloat>(c);
|
||||
const auto& value = fugg::ModulePointer<const GLfloat>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glUniform3fv("
|
||||
|
|
@ -275,7 +275,7 @@ WASM_IMPORT_IMPL(env, _glUniform3fv) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'K' */
|
||||
// "K": "_glTexImage2D",
|
||||
WASM_IMPORT_IMPL(env, _glTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 d, u32 e, u32 f, u32 g, u32 h, u32 i) {
|
||||
const auto& pixels = fugg::module_ptr<const void>(i);
|
||||
const auto& pixels = fugg::ModulePointer<const void>(i);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glTexImage2D("
|
||||
|
|
@ -333,7 +333,7 @@ WASM_IMPORT_IMPL(env, _glGetError) = []() {
|
|||
};
|
||||
// "O": "_glDeleteFramebuffers",
|
||||
WASM_IMPORT_IMPL(env, _glDeleteFramebuffers) = [](u32 a, u32 b) {
|
||||
const auto& framebuffers = fugg::module_ptr<const GLuint>(b);
|
||||
const auto& framebuffers = fugg::ModulePointer<const GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDeleteFramebuffers("
|
||||
|
|
@ -368,8 +368,8 @@ WASM_IMPORT_IMPL(env, _glColorMask) = [](u32 a, u32 b, u32 c, u32 d) {
|
|||
};
|
||||
// "R": "_glDeleteBuffers",
|
||||
WASM_IMPORT_IMPL(env, _glDeleteBuffers) = [](u32 a, u32 b) {
|
||||
const auto& n = fugg::Value<GLsizei>(a);
|
||||
const auto& buffers = fugg::module_ptr<const GLuint>(b);
|
||||
const auto& n = static_cast<GLsizei>(a);
|
||||
const auto& buffers = fugg::ModulePointer<const GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDeleteBuffers("
|
||||
|
|
@ -382,8 +382,8 @@ WASM_IMPORT_IMPL(env, _glDeleteBuffers) = [](u32 a, u32 b) {
|
|||
};
|
||||
// "S": "_glBufferData",
|
||||
WASM_IMPORT_IMPL(env, _glBufferData) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
const auto& size = fugg::Value<GLsizeiptr>(b);
|
||||
const auto& data = fugg::module_ptr<const void>(c);
|
||||
const auto& size = static_cast<GLsizeiptr>(b);
|
||||
const auto& data = fugg::ModulePointer<const void>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glBufferData("
|
||||
|
|
@ -404,8 +404,8 @@ WASM_IMPORT_IMPL(env, _glBufferData) = [](u32 a, u32 b, u32 c, u32 d) {
|
|||
/* import: 'a' 'T' */
|
||||
// "T": "_glGenBuffers",
|
||||
WASM_IMPORT_IMPL(env, _glGenBuffers) = [](u32 a, u32 b) {
|
||||
const auto& n = fugg::Value<GLsizei>(a);
|
||||
const auto& buffers = fugg::module_ptr<GLuint>(b);
|
||||
const auto& n = static_cast<GLsizei>(a);
|
||||
const auto& buffers = fugg::ModulePointer<GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGenBuffers("
|
||||
|
|
@ -453,8 +453,8 @@ WASM_IMPORT_IMPL(env, _glStencilMask) = [](u32 a) {
|
|||
/* import: 'a' 'Z' */
|
||||
// "Z": "_glGenTextures",
|
||||
WASM_IMPORT_IMPL(env, _glGenTextures) = [](u32 a, u32 b) {
|
||||
const auto& n = fugg::Value<GLsizei>(a);
|
||||
const auto& textures = fugg::module_ptr<GLuint>(b);
|
||||
const auto& n = static_cast<GLsizei>(a);
|
||||
const auto& textures = fugg::ModulePointer<GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGenTextures("
|
||||
|
|
@ -485,7 +485,7 @@ WASM_IMPORT_IMPL(env, _glUniform2f) = [](u32 a, f32 b, f32 c) {
|
|||
/* import: 'a' '$' */
|
||||
/* _glUniform2fv */
|
||||
WASM_IMPORT_IMPL(env, _glUniform2fv) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& value = fugg::module_ptr<const GLfloat>(c);
|
||||
const auto& value = fugg::ModulePointer<const GLfloat>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glUniform2fv("
|
||||
|
|
@ -534,7 +534,7 @@ WASM_IMPORT_IMPL(env, _glFramebufferTexture2D) = [](u32 a, u32 b, u32 c, u32 d,
|
|||
/* import: 'a' 'ea' */
|
||||
// "ea": "_glGetProgramiv",
|
||||
WASM_IMPORT_IMPL(env, _glGetProgramiv) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& params = fugg::module_ptr<GLint>(c);
|
||||
const auto& params = fugg::ModulePointer<GLint>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetProgramiv("
|
||||
|
|
@ -570,7 +570,7 @@ WASM_IMPORT_IMPL(env, _glStencilFunc) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'ga' */
|
||||
// "ga": "_glGenFramebuffers",
|
||||
WASM_IMPORT_IMPL(env, _glGenFramebuffers) = [](u32 a, u32 b) {
|
||||
const auto& framebuffers = fugg::module_ptr<GLuint>(b);
|
||||
const auto& framebuffers = fugg::ModulePointer<GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGenFramebuffers("
|
||||
|
|
@ -588,7 +588,7 @@ WASM_IMPORT_IMPL(env, _glGenFramebuffers) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'ia' */
|
||||
// "ia": "_glGetIntegerv",
|
||||
WASM_IMPORT_IMPL(env, _glGetIntegerv) = [](u32 a, u32 b) {
|
||||
const auto& data = fugg::module_ptr<GLint>(b);
|
||||
const auto& data = fugg::ModulePointer<GLint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetIntegerv("
|
||||
|
|
@ -687,10 +687,10 @@ WASM_IMPORT_IMPL(env, _glClearColor) = [](f32 a, f32 b, f32 c, f32 d) {
|
|||
/* import: 'a' 'Ta' */
|
||||
// "Ta": "_glGetProgramInfoLog",
|
||||
WASM_IMPORT_IMPL(env, _glGetProgramInfoLog) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
const auto& program = fugg::Value<GLuint>(a);
|
||||
const auto& buf_size = fugg::Value<GLsizei>(b);
|
||||
const auto& length = fugg::module_ptr<GLsizei>(c);
|
||||
const auto& infolog = fugg::module_ptr<GLchar>(d);
|
||||
const auto& program = reinterpret_cast<GLuint>(a);
|
||||
const auto& buf_size = static_cast<GLsizei>(b);
|
||||
const auto& length = fugg::ModulePointer<GLsizei>(c);
|
||||
const auto& infolog = fugg::ModulePointer<GLchar>(d);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetProgramInfoLog("
|
||||
|
|
@ -737,7 +737,7 @@ WASM_IMPORT_IMPL(env, _glAttachShader) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'Wa' */
|
||||
// "Wa": "_glGetShaderiv",
|
||||
WASM_IMPORT_IMPL(env, _glGetShaderiv) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& params = fugg::module_ptr<GLint>(c);
|
||||
const auto& params = fugg::ModulePointer<GLint>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetShaderiv("
|
||||
|
|
@ -789,7 +789,7 @@ WASM_IMPORT_IMPL(env, _glUniform4f) = [](u32 a, f32 b, f32 c, f32 d, f32 e) {
|
|||
/* import: 'a' 'lb' */
|
||||
// "lb": "_glCompressedTexImage2D",
|
||||
WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 internalformat, u32 width, u32 height, u32 border, u32 image_size, u32 h) {
|
||||
const auto& data = fugg::module_ptr<const void>(h);
|
||||
const auto& data = fugg::ModulePointer<const void>(h);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glCompressedTexImage2D("
|
||||
|
|
@ -818,7 +818,7 @@ WASM_IMPORT_IMPL(env, _glCompressedTexImage2D) = [](u32 target, u32 level, u32 i
|
|||
/* import: 'a' 'mb' */
|
||||
// "mb": "_glBindAttribLocation",
|
||||
WASM_IMPORT_IMPL(env, _glBindAttribLocation) = [](u32 a, u32 b, u32 c) {
|
||||
const auto& name = fugg::module_ptr<const GLchar>(c);
|
||||
const auto& name = fugg::ModulePointer<const GLchar>(c);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glBindAttribLocation("
|
||||
|
|
@ -837,10 +837,10 @@ WASM_IMPORT_IMPL(env, _glBindAttribLocation) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'nb' */
|
||||
// "nb": "_glGetActiveAttrib",
|
||||
WASM_IMPORT_IMPL(env, _glGetActiveAttrib) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f, u32 g) {
|
||||
const auto& length = fugg::module_ptr<GLsizei>(d);
|
||||
const auto& size = fugg::module_ptr<GLint>(e);
|
||||
const auto& type = fugg::module_ptr<GLenum>(f);
|
||||
const auto& name = fugg::module_ptr<GLchar>(g);
|
||||
const auto& length = fugg::ModulePointer<GLsizei>(d);
|
||||
const auto& size = fugg::ModulePointer<GLint>(e);
|
||||
const auto& type = fugg::ModulePointer<GLenum>(f);
|
||||
const auto& name = fugg::ModulePointer<GLchar>(g);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetActiveAttrib("
|
||||
|
|
@ -879,10 +879,10 @@ WASM_IMPORT_IMPL(env, _glCreateProgram) = []() {
|
|||
/* import: 'a' 'qb' */
|
||||
// "qb": "_glGetShaderInfoLog",
|
||||
WASM_IMPORT_IMPL(env, _glGetShaderInfoLog) = [](u32 a, u32 b, u32 c, u32 d) {
|
||||
const auto& shader = fugg::Value<GLuint>(a);
|
||||
const auto& buf_size = fugg::Value<GLsizei>(b);
|
||||
const auto& length = fugg::module_ptr<GLsizei>(c);
|
||||
const auto& infolog = fugg::module_ptr<GLchar>(d);
|
||||
const auto& shader = reinterpret_cast<GLuint>(a);
|
||||
const auto& buf_size = static_cast<GLsizei>(b);
|
||||
const auto& length = fugg::ModulePointer<GLsizei>(c);
|
||||
const auto& infolog = fugg::ModulePointer<GLchar>(d);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetShaderInfoLog("
|
||||
|
|
@ -915,11 +915,11 @@ WASM_IMPORT_IMPL(env, _glShaderSource) = [](u32 shader, u32 count, u32 string_,
|
|||
// to allow multiple shaders to be compiled.
|
||||
// We need to fix the pointers to point into the WASM runtime.
|
||||
|
||||
const auto& string = fugg::module_ptr<GLchar *>(string_);
|
||||
const auto& length = fugg::module_ptr<GLint>(length_);
|
||||
const auto& string = fugg::ModulePointer<GLchar *>(string_);
|
||||
const auto& length = fugg::ModulePointer<GLint>(length_);
|
||||
|
||||
for(unsigned int i = 0; i < count; i++) {
|
||||
string[i] = fugg::module_ptr(string[i]);
|
||||
string[i] = fugg::ModulePointer<GLchar> { string[i] };
|
||||
}
|
||||
|
||||
glShaderSource(
|
||||
|
|
@ -964,7 +964,9 @@ WASM_IMPORT_IMPL(env, _glGetString) = [](u32 a) {
|
|||
<< ") = " << result << std::endl;
|
||||
#endif
|
||||
|
||||
return static_cast<u32>(fugg::app_ptr(result));
|
||||
return static_cast<u32>(
|
||||
fugg::RuntimePointer<const GLubyte> { result }.as_raw()
|
||||
);
|
||||
};
|
||||
/* import: 'a' 'xb' */
|
||||
// "xb": "_glStencilOp",
|
||||
|
|
@ -987,7 +989,7 @@ WASM_IMPORT_IMPL(env, _glStencilOp) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'zb' */
|
||||
// "zb": "_glDeleteTextures",
|
||||
WASM_IMPORT_IMPL(env, _glDeleteTextures) = [](u32 a, u32 b) {
|
||||
const auto& textures = fugg::module_ptr<const GLuint>(b);
|
||||
const auto& textures = fugg::ModulePointer<const GLuint>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glDeleteTextures("
|
||||
|
|
@ -1034,7 +1036,7 @@ WASM_IMPORT_IMPL(env, _glCopyTexSubImage2D) = [](u32 a, u32 b, u32 c, u32 d, u32
|
|||
/* import: 'a' 'dc' */
|
||||
// "dc": "_glTexSubImage2D",
|
||||
WASM_IMPORT_IMPL(env, _glTexSubImage2D) = [](u32 a, u32 b, u32 c, u32 d, u32 e, u32 f, u32 g, u32 h, u32 i) {
|
||||
const auto& pixels = fugg::module_ptr<const void>(i);
|
||||
const auto& pixels = fugg::ModulePointer<const void>(i);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glTexSubImage2D("
|
||||
|
|
@ -1083,7 +1085,7 @@ WASM_IMPORT_IMPL(env, _glDrawArrays) = [](u32 a, u32 b, u32 c) {
|
|||
/* import: 'a' 'G' */
|
||||
/* _glGetUniformLocation */
|
||||
WASM_IMPORT_IMPL(env, _glGetUniformLocation) = [](u32 a, u32 b) {
|
||||
const auto& name = fugg::module_ptr<GLchar>(b);
|
||||
const auto& name = fugg::ModulePointer<GLchar>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_glGetUniformLocation("
|
||||
|
|
@ -1142,8 +1144,8 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_make_context_current) = [](u32 a) {
|
|||
/* import: 'a' 'ib' */
|
||||
// "ib": "_emscripten_webgl_create_context",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_webgl_create_context) = [](u32 a, u32 b) {
|
||||
const auto& target = fugg::module_ptr<const char>(a);
|
||||
const auto& attributes = fugg::module_ptr<const EmscriptenWebGLContextAttributes>(b);
|
||||
const auto& target = fugg::ModulePointer<const char>(a);
|
||||
const auto& attributes = fugg::ModulePointer<const EmscriptenWebGLContextAttributes>(b);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emscripten_webgl_create_context("
|
||||
|
|
@ -1162,7 +1164,7 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_create_context) = [](u32 a, u32 b) {
|
|||
/* import: 'a' 'jb' */
|
||||
// "jb": "_emscripten_webgl_init_context_attributes",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_webgl_init_context_attributes) = [](u32 a) {
|
||||
const auto& attributes = fugg::module_ptr<EmscriptenWebGLContextAttributes>(a);
|
||||
const auto& attributes = fugg::ModulePointer<EmscriptenWebGLContextAttributes>(a);
|
||||
|
||||
#if TRACE_EM_CALLS
|
||||
std::cout << "_emscripten_webgl_init_context_attributes("
|
||||
|
|
@ -1175,7 +1177,7 @@ WASM_IMPORT_IMPL(env, _emscripten_webgl_init_context_attributes) = [](u32 a) {
|
|||
/* import: 'a' 'vb' */
|
||||
// "vb": "_emscripten_webgl_enable_extension",
|
||||
WASM_IMPORT_IMPL(env, _emscripten_webgl_enable_extension) = [](u32 a, u32 b) {
|
||||
const auto& extension = fugg::module_ptr<const char>(b);
|
||||
const auto& extension = fugg::ModulePointer<const char>(b);
|
||||
|
||||
#if TRACE_GL_CALLS
|
||||
std::cout << "_emscripten_webgl_enable_extension("
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
void platform_text_edited_hook(u32 ptr, u32 selection_start, u32 selection_end) {
|
||||
// Emscripten doesn't understand sending pointers, so we have to receive an int.
|
||||
|
||||
auto text = reinterpret_cast<const char*>(fugg::app_ptr(ptr));
|
||||
auto text = fugg::RuntimePointer<const char>(ptr);
|
||||
|
||||
using PlatformTextEditedFn = void (*)(const char*, u32, u32);
|
||||
const auto& platform_text_edited = fugg::function_ref<PlatformTextEditedFn>(
|
||||
|
|
@ -55,7 +55,7 @@ void platform_captcha_completed_hook(std::string token) {
|
|||
|
||||
platform_captcha_completed_invoker(
|
||||
platform_captcha_completed,
|
||||
reinterpret_cast<WireType*>(fugg::app_ptr(wt))
|
||||
fugg::RuntimePointer<WireType>(wt)
|
||||
);
|
||||
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ void platform_websocket_message_hook(emscripten::val event) {
|
|||
fugg::embind::kFunctionMap["platform_websocket_message"]->fn
|
||||
);
|
||||
|
||||
platform_websocket_message(reinterpret_cast<Test*>(fugg::app_ptr(test)));
|
||||
platform_websocket_message(fugg::RuntimePointer<Test>(test));
|
||||
|
||||
delete test;
|
||||
}
|
||||
|
|
@ -109,4 +109,12 @@ EMSCRIPTEN_BINDINGS(my_module) {
|
|||
emscripten::function("platform_websocket_open", &platform_websocket_open_hook);
|
||||
emscripten::function("platform_websocket_close", &platform_websocket_close_hook);
|
||||
emscripten::function("platform_websocket_message", &platform_websocket_message_hook);
|
||||
}
|
||||
|
||||
extern "C" uintptr_t EMSCRIPTEN_KEEPALIVE flyff_memory_start() {
|
||||
return fugg::wasm::kMemory.data();
|
||||
}
|
||||
|
||||
extern "C" uintptr_t EMSCRIPTEN_KEEPALIVE flyff_memory_size() {
|
||||
return fugg::wasm::kMemory.size();
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "fugg.h"
|
||||
|
||||
namespace flyff {
|
||||
#include "structs/ItemProperty.h"
|
||||
#include "structs/MusicProperty.h"
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,438 @@
|
|||
typedef unsigned char undefined;
|
||||
|
||||
// typedef unsigned char bool;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned int dword;
|
||||
typedef long long longlong;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ulonglong;
|
||||
typedef unsigned char undefined1;
|
||||
typedef unsigned short undefined2;
|
||||
typedef unsigned int undefined4;
|
||||
typedef unsigned long long undefined8;
|
||||
typedef unsigned short ushort;
|
||||
typedef struct ItemProperty ItemProperty, *PItemProperty;
|
||||
|
||||
typedef struct TranslationArg TranslationArg, *PTranslationArg;
|
||||
|
||||
#include "fugg.h"
|
||||
|
||||
struct ItemProperty {
|
||||
int * * field0_0x0;
|
||||
int * field1_0x4;
|
||||
undefined field2_0x8;
|
||||
undefined field3_0x9;
|
||||
undefined field4_0xa;
|
||||
byte field5_0xb;
|
||||
int id;
|
||||
undefined field7_0x10;
|
||||
undefined field8_0x11;
|
||||
undefined field9_0x12;
|
||||
undefined field10_0x13;
|
||||
char field11_0x14;
|
||||
undefined field12_0x15;
|
||||
undefined field13_0x16;
|
||||
char field14_0x17;
|
||||
undefined field15_0x18;
|
||||
undefined field16_0x19;
|
||||
undefined field17_0x1a;
|
||||
undefined field18_0x1b;
|
||||
undefined field19_0x1c;
|
||||
undefined field20_0x1d;
|
||||
undefined field21_0x1e;
|
||||
undefined field22_0x1f;
|
||||
undefined field23_0x20;
|
||||
undefined field24_0x21;
|
||||
undefined field25_0x22;
|
||||
undefined field26_0x23;
|
||||
undefined field27_0x24;
|
||||
undefined field28_0x25;
|
||||
undefined field29_0x26;
|
||||
undefined field30_0x27;
|
||||
undefined field31_0x28;
|
||||
undefined field32_0x29;
|
||||
undefined field33_0x2a;
|
||||
undefined field34_0x2b;
|
||||
undefined field35_0x2c;
|
||||
undefined field36_0x2d;
|
||||
undefined field37_0x2e;
|
||||
undefined field38_0x2f;
|
||||
undefined field39_0x30;
|
||||
undefined field40_0x31;
|
||||
undefined field41_0x32;
|
||||
undefined field42_0x33;
|
||||
undefined field43_0x34;
|
||||
undefined field44_0x35;
|
||||
undefined field45_0x36;
|
||||
undefined field46_0x37;
|
||||
undefined field47_0x38;
|
||||
undefined field48_0x39;
|
||||
undefined field49_0x3a;
|
||||
undefined field50_0x3b;
|
||||
undefined field51_0x3c;
|
||||
undefined field52_0x3d;
|
||||
undefined field53_0x3e;
|
||||
undefined field54_0x3f;
|
||||
undefined field55_0x40;
|
||||
undefined field56_0x41;
|
||||
undefined field57_0x42;
|
||||
undefined field58_0x43;
|
||||
undefined field59_0x44;
|
||||
undefined field60_0x45;
|
||||
undefined field61_0x46;
|
||||
undefined field62_0x47;
|
||||
undefined field63_0x48;
|
||||
undefined field64_0x49;
|
||||
undefined field65_0x4a;
|
||||
undefined field66_0x4b;
|
||||
undefined field67_0x4c;
|
||||
undefined field68_0x4d;
|
||||
undefined field69_0x4e;
|
||||
undefined field70_0x4f;
|
||||
undefined field71_0x50;
|
||||
undefined field72_0x51;
|
||||
undefined field73_0x52;
|
||||
undefined field74_0x53;
|
||||
undefined field75_0x54;
|
||||
undefined field76_0x55;
|
||||
undefined field77_0x56;
|
||||
undefined field78_0x57;
|
||||
undefined field79_0x58;
|
||||
undefined field80_0x59;
|
||||
undefined field81_0x5a;
|
||||
undefined field82_0x5b;
|
||||
undefined field83_0x5c;
|
||||
undefined field84_0x5d;
|
||||
undefined field85_0x5e;
|
||||
undefined field86_0x5f;
|
||||
undefined field87_0x60;
|
||||
undefined field88_0x61;
|
||||
undefined field89_0x62;
|
||||
undefined field90_0x63;
|
||||
undefined field91_0x64;
|
||||
undefined field92_0x65;
|
||||
undefined field93_0x66;
|
||||
undefined field94_0x67;
|
||||
undefined field95_0x68;
|
||||
undefined field96_0x69;
|
||||
undefined field97_0x6a;
|
||||
undefined field98_0x6b;
|
||||
undefined field99_0x6c;
|
||||
undefined field100_0x6d;
|
||||
undefined field101_0x6e;
|
||||
undefined field102_0x6f;
|
||||
undefined field103_0x70;
|
||||
undefined field104_0x71;
|
||||
undefined field105_0x72;
|
||||
undefined field106_0x73;
|
||||
undefined field107_0x74;
|
||||
undefined field108_0x75;
|
||||
undefined field109_0x76;
|
||||
undefined field110_0x77;
|
||||
undefined field111_0x78;
|
||||
undefined field112_0x79;
|
||||
undefined field113_0x7a;
|
||||
undefined field114_0x7b;
|
||||
undefined field115_0x7c;
|
||||
undefined field116_0x7d;
|
||||
undefined field117_0x7e;
|
||||
undefined field118_0x7f;
|
||||
char field119_0x80;
|
||||
undefined field120_0x81;
|
||||
undefined field121_0x82;
|
||||
undefined field122_0x83;
|
||||
undefined field123_0x84;
|
||||
undefined field124_0x85;
|
||||
undefined field125_0x86;
|
||||
undefined field126_0x87;
|
||||
undefined field127_0x88;
|
||||
undefined field128_0x89;
|
||||
undefined field129_0x8a;
|
||||
undefined field130_0x8b;
|
||||
undefined field131_0x8c;
|
||||
undefined field132_0x8d;
|
||||
undefined field133_0x8e;
|
||||
undefined field134_0x8f;
|
||||
undefined field135_0x90;
|
||||
undefined field136_0x91;
|
||||
undefined field137_0x92;
|
||||
undefined field138_0x93;
|
||||
undefined field139_0x94;
|
||||
undefined field140_0x95;
|
||||
undefined field141_0x96;
|
||||
undefined field142_0x97;
|
||||
undefined field143_0x98;
|
||||
undefined field144_0x99;
|
||||
undefined field145_0x9a;
|
||||
undefined field146_0x9b;
|
||||
fugg::String some_string;
|
||||
undefined field148_0xa8;
|
||||
undefined field149_0xa9;
|
||||
undefined field150_0xaa;
|
||||
undefined field151_0xab;
|
||||
undefined field152_0xac;
|
||||
undefined field153_0xad;
|
||||
undefined field154_0xae;
|
||||
undefined field155_0xaf;
|
||||
undefined field156_0xb0;
|
||||
undefined field157_0xb1;
|
||||
undefined field158_0xb2;
|
||||
undefined field159_0xb3;
|
||||
undefined field160_0xb4;
|
||||
undefined field161_0xb5;
|
||||
undefined field162_0xb6;
|
||||
undefined field163_0xb7;
|
||||
undefined field164_0xb8;
|
||||
undefined field165_0xb9;
|
||||
undefined field166_0xba;
|
||||
undefined field167_0xbb;
|
||||
undefined field168_0xbc;
|
||||
undefined field169_0xbd;
|
||||
undefined field170_0xbe;
|
||||
undefined field171_0xbf;
|
||||
int field172_0xc0;
|
||||
undefined field173_0xc4;
|
||||
undefined field174_0xc5;
|
||||
undefined field175_0xc6;
|
||||
undefined field176_0xc7;
|
||||
undefined field177_0xc8;
|
||||
undefined field178_0xc9;
|
||||
undefined field179_0xca;
|
||||
undefined field180_0xcb;
|
||||
undefined field181_0xcc;
|
||||
undefined field182_0xcd;
|
||||
undefined field183_0xce;
|
||||
undefined field184_0xcf;
|
||||
undefined field185_0xd0;
|
||||
undefined field186_0xd1;
|
||||
undefined field187_0xd2;
|
||||
undefined field188_0xd3;
|
||||
undefined field189_0xd4;
|
||||
undefined field190_0xd5;
|
||||
undefined field191_0xd6;
|
||||
undefined field192_0xd7;
|
||||
undefined field193_0xd8;
|
||||
undefined field194_0xd9;
|
||||
undefined field195_0xda;
|
||||
undefined field196_0xdb;
|
||||
undefined field197_0xdc;
|
||||
undefined field198_0xdd;
|
||||
undefined field199_0xde;
|
||||
undefined field200_0xdf;
|
||||
undefined field201_0xe0;
|
||||
undefined field202_0xe1;
|
||||
undefined field203_0xe2;
|
||||
undefined field204_0xe3;
|
||||
undefined field205_0xe4;
|
||||
undefined field206_0xe5;
|
||||
undefined field207_0xe6;
|
||||
undefined field208_0xe7;
|
||||
undefined field209_0xe8;
|
||||
undefined field210_0xe9;
|
||||
undefined field211_0xea;
|
||||
undefined field212_0xeb;
|
||||
undefined field213_0xec;
|
||||
undefined field214_0xed;
|
||||
undefined field215_0xee;
|
||||
undefined field216_0xef;
|
||||
undefined field217_0xf0;
|
||||
undefined field218_0xf1;
|
||||
undefined field219_0xf2;
|
||||
undefined field220_0xf3;
|
||||
undefined field221_0xf4;
|
||||
undefined field222_0xf5;
|
||||
undefined field223_0xf6;
|
||||
undefined field224_0xf7;
|
||||
undefined field225_0xf8;
|
||||
undefined field226_0xf9;
|
||||
undefined field227_0xfa;
|
||||
undefined field228_0xfb;
|
||||
undefined field229_0xfc;
|
||||
undefined field230_0xfd;
|
||||
undefined field231_0xfe;
|
||||
undefined field232_0xff;
|
||||
undefined field233_0x100;
|
||||
undefined field234_0x101;
|
||||
undefined field235_0x102;
|
||||
undefined field236_0x103;
|
||||
undefined field237_0x104;
|
||||
undefined field238_0x105;
|
||||
undefined field239_0x106;
|
||||
undefined field240_0x107;
|
||||
undefined field241_0x108;
|
||||
undefined field242_0x109;
|
||||
undefined field243_0x10a;
|
||||
undefined field244_0x10b;
|
||||
undefined field245_0x10c;
|
||||
undefined field246_0x10d;
|
||||
undefined field247_0x10e;
|
||||
undefined field248_0x10f;
|
||||
undefined field249_0x110;
|
||||
undefined field250_0x111;
|
||||
undefined field251_0x112;
|
||||
undefined field252_0x113;
|
||||
undefined field253_0x114;
|
||||
undefined field254_0x115;
|
||||
undefined field255_0x116;
|
||||
undefined field256_0x117;
|
||||
undefined field257_0x118;
|
||||
undefined field258_0x119;
|
||||
undefined field259_0x11a;
|
||||
undefined field260_0x11b;
|
||||
undefined field261_0x11c;
|
||||
undefined field262_0x11d;
|
||||
undefined field263_0x11e;
|
||||
undefined field264_0x11f;
|
||||
undefined field265_0x120;
|
||||
undefined field266_0x121;
|
||||
undefined field267_0x122;
|
||||
undefined field268_0x123;
|
||||
undefined field269_0x124;
|
||||
undefined field270_0x125;
|
||||
undefined field271_0x126;
|
||||
undefined field272_0x127;
|
||||
undefined field273_0x128;
|
||||
undefined field274_0x129;
|
||||
undefined field275_0x12a;
|
||||
undefined field276_0x12b;
|
||||
undefined field277_0x12c;
|
||||
undefined field278_0x12d;
|
||||
undefined field279_0x12e;
|
||||
undefined field280_0x12f;
|
||||
undefined field281_0x130;
|
||||
undefined field282_0x131;
|
||||
undefined field283_0x132;
|
||||
undefined field284_0x133;
|
||||
undefined field285_0x134;
|
||||
undefined field286_0x135;
|
||||
undefined field287_0x136;
|
||||
undefined field288_0x137;
|
||||
undefined field289_0x138;
|
||||
undefined field290_0x139;
|
||||
undefined field291_0x13a;
|
||||
undefined field292_0x13b;
|
||||
undefined field293_0x13c;
|
||||
undefined field294_0x13d;
|
||||
undefined field295_0x13e;
|
||||
undefined field296_0x13f;
|
||||
undefined field297_0x140;
|
||||
undefined field298_0x141;
|
||||
undefined field299_0x142;
|
||||
undefined field300_0x143;
|
||||
undefined field301_0x144;
|
||||
undefined field302_0x145;
|
||||
undefined field303_0x146;
|
||||
undefined field304_0x147;
|
||||
undefined field305_0x148;
|
||||
undefined field306_0x149;
|
||||
undefined field307_0x14a;
|
||||
undefined field308_0x14b;
|
||||
undefined field309_0x14c;
|
||||
undefined field310_0x14d;
|
||||
undefined field311_0x14e;
|
||||
undefined field312_0x14f;
|
||||
undefined field313_0x150;
|
||||
undefined field314_0x151;
|
||||
undefined field315_0x152;
|
||||
undefined field316_0x153;
|
||||
undefined field317_0x154;
|
||||
undefined field318_0x155;
|
||||
undefined field319_0x156;
|
||||
undefined field320_0x157;
|
||||
undefined field321_0x158;
|
||||
undefined field322_0x159;
|
||||
undefined field323_0x15a;
|
||||
undefined field324_0x15b;
|
||||
int field325_0x15c;
|
||||
int * field326_0x160;
|
||||
int field327_0x164;
|
||||
undefined field328_0x168;
|
||||
undefined field329_0x169;
|
||||
undefined field330_0x16a;
|
||||
undefined field331_0x16b;
|
||||
undefined field332_0x16c;
|
||||
undefined field333_0x16d;
|
||||
undefined field334_0x16e;
|
||||
undefined field335_0x16f;
|
||||
undefined field336_0x170;
|
||||
undefined field337_0x171;
|
||||
undefined field338_0x172;
|
||||
undefined field339_0x173;
|
||||
int field340_0x174;
|
||||
int field341_0x178;
|
||||
undefined field342_0x17c;
|
||||
undefined field343_0x17d;
|
||||
undefined field344_0x17e;
|
||||
undefined field345_0x17f;
|
||||
undefined field346_0x180;
|
||||
undefined field347_0x181;
|
||||
undefined field348_0x182;
|
||||
undefined field349_0x183;
|
||||
undefined field350_0x184;
|
||||
undefined field351_0x185;
|
||||
undefined field352_0x186;
|
||||
undefined field353_0x187;
|
||||
undefined field354_0x188;
|
||||
undefined field355_0x189;
|
||||
undefined field356_0x18a;
|
||||
undefined field357_0x18b;
|
||||
undefined field358_0x18c;
|
||||
undefined field359_0x18d;
|
||||
undefined field360_0x18e;
|
||||
undefined field361_0x18f;
|
||||
undefined field362_0x190;
|
||||
undefined field363_0x191;
|
||||
undefined field364_0x192;
|
||||
undefined field365_0x193;
|
||||
undefined field366_0x194;
|
||||
undefined field367_0x195;
|
||||
undefined field368_0x196;
|
||||
undefined field369_0x197;
|
||||
undefined field370_0x198;
|
||||
undefined field371_0x199;
|
||||
undefined field372_0x19a;
|
||||
undefined field373_0x19b;
|
||||
undefined field374_0x19c;
|
||||
undefined field375_0x19d;
|
||||
undefined field376_0x19e;
|
||||
undefined field377_0x19f;
|
||||
undefined field378_0x1a0;
|
||||
undefined field379_0x1a1;
|
||||
undefined field380_0x1a2;
|
||||
undefined field381_0x1a3;
|
||||
undefined field382_0x1a4;
|
||||
undefined field383_0x1a5;
|
||||
undefined field384_0x1a6;
|
||||
undefined field385_0x1a7;
|
||||
undefined field386_0x1a8;
|
||||
undefined field387_0x1a9;
|
||||
undefined field388_0x1aa;
|
||||
undefined field389_0x1ab;
|
||||
float field390_0x1ac;
|
||||
undefined field391_0x1b0;
|
||||
undefined field392_0x1b1;
|
||||
undefined field393_0x1b2;
|
||||
undefined field394_0x1b3;
|
||||
undefined field395_0x1b4;
|
||||
undefined field396_0x1b5;
|
||||
undefined field397_0x1b6;
|
||||
undefined field398_0x1b7;
|
||||
undefined field399_0x1b8;
|
||||
undefined field400_0x1b9;
|
||||
undefined field401_0x1ba;
|
||||
undefined field402_0x1bb;
|
||||
undefined field403_0x1bc;
|
||||
undefined field404_0x1bd;
|
||||
undefined field405_0x1be;
|
||||
undefined field406_0x1bf;
|
||||
undefined field407_0x1c0;
|
||||
undefined field408_0x1c1;
|
||||
undefined field409_0x1c2;
|
||||
undefined field410_0x1c3;
|
||||
undefined field411_0x1c4;
|
||||
undefined field412_0x1c5;
|
||||
undefined field413_0x1c6;
|
||||
undefined field414_0x1c7;
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
typedef unsigned char undefined;
|
||||
|
||||
// typedef unsigned char bool;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned int dword;
|
||||
typedef long long longlong;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ulonglong;
|
||||
typedef unsigned char undefined1;
|
||||
typedef unsigned short undefined2;
|
||||
typedef unsigned int undefined4;
|
||||
typedef unsigned long long undefined8;
|
||||
typedef unsigned short ushort;
|
||||
typedef struct MusicProperty MusicProperty, *PMusicProperty;
|
||||
|
||||
#include "fugg.h"
|
||||
|
||||
struct MusicProperty {
|
||||
fugg::String name;
|
||||
int id;
|
||||
uint field2_0x10;
|
||||
bool field3_0x14;
|
||||
undefined field4_0x15;
|
||||
undefined field5_0x16;
|
||||
undefined field6_0x17;
|
||||
};
|
||||
|
||||
|
|
@ -15,9 +15,9 @@ void *malloc (size_t __size) {
|
|||
// transform it to point to the actual address where the WASM runtime memory
|
||||
// resides.
|
||||
|
||||
const auto& ptr = fugg::module_ptr<void>(
|
||||
const auto& ptr = fugg::ModulePointer<void> {
|
||||
(*import::_malloc)(__size)
|
||||
);
|
||||
};
|
||||
|
||||
#if TRACE_ALLOC
|
||||
std::cout << "FLYFF: Allocated " << __size << " bytes at " << ptr << std::endl;
|
||||
|
|
@ -40,9 +40,9 @@ void free (void *__ptr) {
|
|||
// printf("Trying to free ptr %p\n", __ptr);
|
||||
|
||||
if((*import::_free) != nullptr) {
|
||||
auto ptr = fugg::app_ptr(__ptr);
|
||||
const auto& ptr = fugg::RuntimePointer<void> { __ptr };
|
||||
|
||||
(*import::_free)(ptr);
|
||||
(*import::_free)(ptr.as_raw());
|
||||
|
||||
#if TRACE_ALLOC
|
||||
std::cout << "FLYFF: Free'd pointer at " << ptr << std::endl;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
add_library (
|
||||
fugg-core
|
||||
fugg-core
|
||||
|
||||
"include/fugg.h"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
#include "../src/memory.h"
|
||||
#include "../src/table.h"
|
||||
#include "../src/stl.h"
|
||||
|
|
|
|||
|
|
@ -3,13 +3,17 @@
|
|||
#include <client.h>
|
||||
#include <wasm-rt.h>
|
||||
|
||||
#include "pointer.h"
|
||||
|
||||
namespace fugg {
|
||||
namespace wasm {
|
||||
using pointer::BasePointer;
|
||||
|
||||
class Memory {
|
||||
wasm_rt_memory_t** memory;
|
||||
|
||||
public:
|
||||
explicit Memory(wasm_rt_memory_t** memory) : memory(memory) { }
|
||||
constexpr explicit Memory(wasm_rt_memory_t** memory) : memory(memory) { }
|
||||
|
||||
uintptr_t address_of(uintptr_t offset) const {
|
||||
if(offset != NULL)
|
||||
|
|
@ -18,57 +22,43 @@ namespace fugg {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
uintptr_t start() {
|
||||
return reinterpret_cast<uintptr_t>(
|
||||
(*memory)->data
|
||||
);
|
||||
uintptr_t data() const {
|
||||
return reinterpret_cast<uintptr_t>((*memory)->data);
|
||||
}
|
||||
|
||||
uintptr_t size() const {
|
||||
return (*memory)->size;
|
||||
}
|
||||
};
|
||||
|
||||
static auto kMemory = Memory { &Z_clientZ_memory };
|
||||
static constexpr auto kRawMemory = &Z_clientZ_memory;
|
||||
static constexpr auto kMemory = Memory { kRawMemory };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T* module_ptr(uintptr_t address) {
|
||||
return reinterpret_cast<T*>(
|
||||
wasm::kMemory.address_of(address)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T* module_ptr(T* &address) {
|
||||
return module_ptr<T>(reinterpret_cast<uintptr_t>(address));
|
||||
T& module_ref(uintptr_t address) {
|
||||
return *reinterpret_cast<T*>(wasm::kMemory.address_of(address));
|
||||
}
|
||||
|
||||
static uintptr_t app_ptr(uintptr_t offset) {
|
||||
if(offset != NULL)
|
||||
return offset - wasm::kMemory.start();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uintptr_t app_ptr(const void* offset) {
|
||||
return app_ptr(reinterpret_cast<uintptr_t>(offset));
|
||||
}
|
||||
|
||||
|
||||
// Value does not have to be offset.
|
||||
// A pointer that relative to the module's memory.
|
||||
template<typename T>
|
||||
class Value {
|
||||
T value;
|
||||
using ModulePointer = pointer::OffsetPointer<T, uintptr_t, &Z_clientZ_memory>;
|
||||
// A pointer allocated INSIDE the module's memory, but passed as global.
|
||||
template<typename T>
|
||||
using RuntimePointer = pointer::RelativePointer<T, uintptr_t, &Z_clientZ_memory>;
|
||||
// A pointer that is globally accessible in the linear memory.
|
||||
template<typename T>
|
||||
using Pointer = pointer::Pointer<T, uintptr_t>;
|
||||
|
||||
public:
|
||||
explicit Value(const T& value) : value(value) { }
|
||||
static_assert(
|
||||
sizeof(ModulePointer<unsigned char>) == sizeof(void*),
|
||||
"ModulePointer needs a size of sizeof(void*)"
|
||||
);
|
||||
|
||||
Value<T>& operator=(T value) {
|
||||
this->value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
static_assert(
|
||||
sizeof(RuntimePointer<unsigned char>) == sizeof(unsigned char*),
|
||||
"RuntimePointer needs a size of sizeof(unsigned char*)"
|
||||
);
|
||||
|
||||
// Modifies the array to let the pointers be accessible from outside the WASM runtime
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
#include <wasm-rt.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace fugg {
|
||||
namespace pointer {
|
||||
using BasePointer = unsigned char*;
|
||||
|
||||
// Absolute pointer.
|
||||
template <typename Type, typename ModulePointerType>
|
||||
class Pointer {
|
||||
const ModulePointerType offset_;
|
||||
|
||||
// `read` interface of this library.
|
||||
Type* get() const {
|
||||
return offset_ ? reinterpret_cast<Type*>(offset_) : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit Pointer(ModulePointerType offset) : offset_(offset) { }
|
||||
explicit Pointer(Type *const &offset) : offset_(reinterpret_cast<ModulePointerType>(offset)) { }
|
||||
|
||||
Type *operator->() {
|
||||
return this->get();
|
||||
}
|
||||
|
||||
// Type &operator*() const {
|
||||
// return *this->get();
|
||||
// }
|
||||
|
||||
operator Type*() const {
|
||||
return this->get();
|
||||
}
|
||||
};
|
||||
|
||||
// A pointer that is located in a `wasm_rt_memory_t`.
|
||||
template <typename Type, typename ModulePointerType, wasm_rt_memory_t *const *memory>
|
||||
class OffsetPointer {
|
||||
const ModulePointerType offset_;
|
||||
|
||||
Type* get() const {
|
||||
if(this->offset_) {
|
||||
const auto start = reinterpret_cast<ModulePointerType>((*memory)->data);
|
||||
|
||||
return reinterpret_cast<Type*>(start + this->offset_);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit OffsetPointer(const ModulePointerType& offset) : offset_(offset) { }
|
||||
explicit OffsetPointer(Type *const &offset) : offset_(reinterpret_cast<ModulePointerType>(offset)) { }
|
||||
|
||||
// FIXME: This is specificly for sending pointers to the module.
|
||||
ModulePointerType as_raw() const {
|
||||
return this->offset_;
|
||||
}
|
||||
|
||||
ModulePointerType as_pointer() const {
|
||||
return reinterpret_cast<ModulePointerType>(this->get());
|
||||
}
|
||||
|
||||
Type *operator->() {
|
||||
return this->get();
|
||||
}
|
||||
|
||||
// Type &operator*() const {
|
||||
// return *this->get();
|
||||
// }
|
||||
|
||||
operator Type*() const {
|
||||
return this->get();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type, typename ModulePointerType, wasm_rt_memory_t *const *memory>
|
||||
class RelativePointer {
|
||||
const ModulePointerType offset_;
|
||||
|
||||
Type* get() const {
|
||||
if(this->offset_) {
|
||||
const auto start = reinterpret_cast<ModulePointerType>((*memory)->data);
|
||||
|
||||
return reinterpret_cast<Type*>(this->offset_ - start);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit RelativePointer(const ModulePointerType& offset) : offset_(offset) { }
|
||||
explicit RelativePointer(Type *const &offset) : offset_(reinterpret_cast<ModulePointerType>(offset)) { }
|
||||
|
||||
// Implicit conversion to PointerType to ease passing pointers to a module.
|
||||
// FIXME: This is specificly for sending pointers to the module.
|
||||
ModulePointerType as_raw() const {
|
||||
const auto start = reinterpret_cast<ModulePointerType>((*memory)->data);
|
||||
|
||||
return this->offset_ - start;
|
||||
}
|
||||
|
||||
Type *operator->() {
|
||||
return this->get();
|
||||
}
|
||||
|
||||
// Type &operator*() const {
|
||||
// return *this->get();
|
||||
// }
|
||||
|
||||
operator Type*() const {
|
||||
return this->get();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
#include "memory.h"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
namespace fugg {
|
||||
namespace detail {
|
||||
template<typename I, typename O>
|
||||
struct ArrowProxy {
|
||||
I value;
|
||||
|
||||
O* operator->() {
|
||||
return reinterpret_cast<O*>(&value);
|
||||
}
|
||||
|
||||
O& operator*() {
|
||||
return *(operator->)();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawUniquePointer {
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawHashTable {
|
||||
RawUniquePointer<T*[]> bucket_list;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct RawBasicString {
|
||||
T* data;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
};
|
||||
static_assert(
|
||||
sizeof(RawBasicString<char>) == sizeof(std::string),
|
||||
"RawBasicString needs to have same size of std::string"
|
||||
);
|
||||
|
||||
template <class _CharT, size_t = sizeof(_CharT)>
|
||||
struct __padding
|
||||
{
|
||||
unsigned char __xx[sizeof(_CharT)-1];
|
||||
};
|
||||
|
||||
template <class _CharT>
|
||||
struct __padding<_CharT, 1>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// class String {
|
||||
// using RawString = detail::RawBasicString<char>;
|
||||
|
||||
// public:
|
||||
// explicit String(const uintptr_t& offset) : offset_(offset) { }
|
||||
// };
|
||||
|
||||
// static_assert(
|
||||
// sizeof(String) == sizeof(std::string),
|
||||
// "String needs to have the same size of std::string"
|
||||
// );
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
ModulePointer<T> begin_;
|
||||
ModulePointer<T> end_;
|
||||
ModulePointer<T> end_capacity_;
|
||||
|
||||
public:
|
||||
detail::ArrowProxy<RawVector, std::vector<T>> operator->() {
|
||||
auto temp = RawVector {
|
||||
.begin = begin_.as_pointer(),
|
||||
.end = end_.as_pointer(),
|
||||
.end_capacity = end_capacity_.as_pointer(),
|
||||
};
|
||||
|
||||
return { temp };
|
||||
}
|
||||
|
||||
auto begin() {
|
||||
return operator->()->begin();
|
||||
}
|
||||
|
||||
auto end() {
|
||||
return operator->()->end();
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(
|
||||
sizeof(Vector<int>) == sizeof(std::vector<int>),
|
||||
"Vector needs to have the same size of std::vector"
|
||||
);
|
||||
|
||||
template<class T>
|
||||
class BasicString {
|
||||
using value_type = T;
|
||||
|
||||
struct __long {
|
||||
ModulePointer<T> data;
|
||||
size_t size;
|
||||
size_t cap;
|
||||
};
|
||||
|
||||
enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
|
||||
(sizeof(__long) - 1)/sizeof(value_type) : 2};
|
||||
struct __short {
|
||||
value_type data[__min_cap];
|
||||
struct : detail::__padding<value_type>
|
||||
{
|
||||
unsigned char size;
|
||||
};
|
||||
};
|
||||
|
||||
union {
|
||||
__long __l;
|
||||
__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.
|
||||
auto temp = *reinterpret_cast<RawBasicString*>(&__l);
|
||||
// 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();
|
||||
}
|
||||
|
||||
return { temp };
|
||||
}
|
||||
|
||||
|
||||
std::basic_string<T>& operator*() {
|
||||
return *(operator->)();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
using String = BasicString<char>;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <client.h>
|
||||
#include <wasm-rt.h>
|
||||
|
||||
namespace fugg {
|
||||
namespace wasm {
|
||||
struct FunctionTable {
|
||||
};
|
||||
|
||||
struct LinearMemory {
|
||||
};
|
||||
|
||||
class Module {
|
||||
const wasm_rt_table_t *const *function_table;
|
||||
const wasm_rt_memory_t *const *memory;
|
||||
|
||||
public:
|
||||
explicit Module(
|
||||
wasm_rt_table_t **function_table,
|
||||
wasm_rt_memory_t **memory
|
||||
) : function_table(function_table), memory(memory) { }
|
||||
};
|
||||
|
||||
static auto kModule = Module { &Z_clientZ_table, &Z_clientZ_memory };
|
||||
}
|
||||
}
|
||||
Reference in New Issue