Some refactoring but it's building!
This commit is contained in:
parent
31abe1c85b
commit
144838d708
|
|
@ -7,5 +7,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
|
||||||
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
||||||
|
|
||||||
add_subdirectory(flyff-client)
|
add_subdirectory(flyff-client)
|
||||||
add_subdirectory(fugg-core)
|
add_subdirectory(flyff-api)
|
||||||
|
|
||||||
|
add_subdirectory(fugg-api)
|
||||||
add_subdirectory(fugg-client)
|
add_subdirectory(fugg-client)
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ add_library (
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(flyff-api PUBLIC "include")
|
target_include_directories(flyff-api PUBLIC "include")
|
||||||
target_link_libraries (flyff-api LINK_PUBLIC flyff-client)
|
target_link_libraries (flyff-api PUBLIC flyff-client fugg-api)
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fugg.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../src/import.h"
|
||||||
|
|
||||||
|
namespace flyff {
|
||||||
|
#include "../src/raw/ItemProperty.h"
|
||||||
|
#include "../src/raw/MusicProperty.h"
|
||||||
|
#include "../src/raw/Mover.h"
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
// static_assert(sizeof(fugg::ModulePointer<void>) == sizeof(u32), "ModulePointer needs the same size as u32");
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
// Translate
|
||||||
|
// extern void translate(u32, u32);
|
||||||
|
// extern void w2c_f167(fugg::String*, std::string*);
|
||||||
|
extern void w2c_f167(u32, u32);
|
||||||
|
|
||||||
|
extern u32 w2c_f208(u64);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <wasm-rt.h>
|
||||||
|
#include <client.h>
|
||||||
|
|
||||||
|
namespace flyff {
|
||||||
|
static const auto& init = &Z_client_init;
|
||||||
|
|
||||||
|
static const auto& _wasm_call_ctors = &Z_clientZ____wasm_call_ctors;
|
||||||
|
static const auto& main = &Z_clientZ__main;
|
||||||
|
|
||||||
|
static const auto& malloc = &Z_clientZ__malloc;
|
||||||
|
static const auto& free = &Z_clientZ__free;
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ typedef struct ItemProperty ItemProperty, *PItemProperty;
|
||||||
|
|
||||||
typedef struct TranslationArg TranslationArg, *PTranslationArg;
|
typedef struct TranslationArg TranslationArg, *PTranslationArg;
|
||||||
|
|
||||||
#include "fugg.h"
|
#include <fugg.h>
|
||||||
|
|
||||||
struct ItemProperty {
|
struct ItemProperty {
|
||||||
int * * field0_0x0;
|
int * * field0_0x0;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "fugg.h"
|
#include <fugg.h>
|
||||||
|
|
||||||
typedef unsigned char undefined;
|
typedef unsigned char undefined;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ typedef unsigned long long undefined8;
|
||||||
typedef unsigned short ushort;
|
typedef unsigned short ushort;
|
||||||
typedef struct MusicProperty MusicProperty, *PMusicProperty;
|
typedef struct MusicProperty MusicProperty, *PMusicProperty;
|
||||||
|
|
||||||
#include "fugg.h"
|
#include <fugg.h>
|
||||||
|
|
||||||
struct MusicProperty {
|
struct MusicProperty {
|
||||||
fugg::String name;
|
fugg::String name;
|
||||||
|
|
@ -7,4 +7,4 @@ add_library (
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(flyff-client PUBLIC "include")
|
target_include_directories(flyff-client PUBLIC "include")
|
||||||
target_link_libraries (flyff-client LINK_PUBLIC wasm-rt)
|
target_link_libraries (flyff-client PUBLIC wasm-rt)
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
add_library (
|
||||||
|
fugg-api
|
||||||
|
|
||||||
|
"include/fugg.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(fugg-api PROPERTIES LINKER_LANGUAGE CXX)
|
||||||
|
|
||||||
|
target_include_directories(fugg-api PUBLIC "include")
|
||||||
|
target_link_libraries (fugg-api PUBLIC flyff-client)
|
||||||
|
|
@ -153,9 +153,9 @@ namespace fugg {
|
||||||
memcpy(&__l, &temp, sizeof(RawBasicString));
|
memcpy(&__l, &temp, sizeof(RawBasicString));
|
||||||
}
|
}
|
||||||
|
|
||||||
detail::ArrowProxy<RawBasicString, std::basic_string<T>> operator->() {
|
detail::ArrowProxy<RawBasicString, std::basic_string<T>> operator->() const {
|
||||||
// Copy the data to the stack.
|
// Copy the data to the stack.
|
||||||
auto temp = *reinterpret_cast<RawBasicString*>(&__l);
|
auto temp = *reinterpret_cast<const RawBasicString*>(&__l);
|
||||||
// If the string is using the __long representation, we need to
|
// If the string is using the __long representation, we need to
|
||||||
// change the pointer to pointer into the module memory.
|
// change the pointer to pointer into the module memory.
|
||||||
auto is_small = -1 < (char)__s.size;
|
auto is_small = -1 < (char)__s.size;
|
||||||
|
|
@ -3,19 +3,19 @@ add_executable(
|
||||||
"src/main.cpp"
|
"src/main.cpp"
|
||||||
"src/client.cpp"
|
"src/client.cpp"
|
||||||
# Symbols that flyff-client imports.
|
# Symbols that flyff-client imports.
|
||||||
"src/interop/export/gl.cpp"
|
"src/export/gl.cpp"
|
||||||
"src/interop/export/al.cpp"
|
"src/export/al.cpp"
|
||||||
"src/interop/export/callback.cpp"
|
"src/export/callback.cpp"
|
||||||
"src/interop/export/embind.cpp"
|
"src/export/embind.cpp"
|
||||||
"src/interop/export/env.cpp"
|
"src/export/env.cpp"
|
||||||
"src/interop/export/platform.cpp"
|
"src/export/platform.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Flyff is based on c++14
|
# Flyff is based on c++14
|
||||||
add_definitions(-std=c++14 -Os)
|
add_definitions(-std=c++14 -Os)
|
||||||
|
|
||||||
target_include_directories(fugg-client PUBLIC "include")
|
target_include_directories(fugg-client PUBLIC "include")
|
||||||
target_link_libraries (fugg-client LINK_PUBLIC fugg-core flyff-client)
|
target_link_libraries (fugg-client LINK_PUBLIC flyff-api)
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
fugg-client
|
fugg-client
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
#include "interop/imports.h"
|
#include <flyff.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -13,15 +13,13 @@ namespace fugg
|
||||||
// 4. Call main
|
// 4. Call main
|
||||||
// 5. Post-run
|
// 5. Post-run
|
||||||
|
|
||||||
using namespace interop;
|
|
||||||
|
|
||||||
using wasm::kMemory;
|
using wasm::kMemory;
|
||||||
using wasm::kTable;
|
using wasm::kTable;
|
||||||
|
|
||||||
Client::Client() {
|
Client::Client() {
|
||||||
// 1. Pre-run: There are no pre-runs in this binary.
|
// 1. Pre-run: There are no pre-runs in this binary.
|
||||||
// 2. Init runtime: `___wasm_call_ctors` is added to on init runtime.
|
// 2. Init runtime: `___wasm_call_ctors` is added to on init runtime.
|
||||||
(*import::__wasm_call_ctors)();
|
(*flyff::_wasm_call_ctors)();
|
||||||
}
|
}
|
||||||
|
|
||||||
Client& Client::instance() {
|
Client& Client::instance() {
|
||||||
|
|
@ -30,7 +28,7 @@ namespace fugg
|
||||||
// Initialise the WebAssembly runtime.
|
// Initialise the WebAssembly runtime.
|
||||||
wasm_rt_init();
|
wasm_rt_init();
|
||||||
// Initialise the client.
|
// Initialise the client.
|
||||||
import::init();
|
flyff::init();
|
||||||
// Only init the module once.
|
// Only init the module once.
|
||||||
initialised = true;
|
initialised = true;
|
||||||
}
|
}
|
||||||
|
|
@ -48,29 +46,20 @@ namespace fugg
|
||||||
// 3. Pre-main: There are no pre-mains in this binary.
|
// 3. Pre-main: There are no pre-mains in this binary.
|
||||||
// 4. Call main: `_main` is main in the binary.
|
// 4. Call main: `_main` is main in the binary.
|
||||||
// TODO: Fix arguments.
|
// TODO: Fix arguments.
|
||||||
return (*import::_main)(0, 0);
|
return (*flyff::main)(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "interop/flyff.h"
|
fugg::String translate(const std::string& id) {
|
||||||
|
|
||||||
void translate(const std::string& id) {
|
|
||||||
auto result = std::make_unique<fugg::detail::RawBasicString>();
|
auto result = std::make_unique<fugg::detail::RawBasicString>();
|
||||||
auto id_ = std::make_unique<fugg::String>(id);
|
auto id_ = std::make_unique<fugg::String>(id);
|
||||||
|
|
||||||
std::cout << "Result before: " << result->data << ", " << result->size << ", " << result->cap << std::endl;
|
|
||||||
|
|
||||||
flyff::api::w2c_f167(
|
flyff::api::w2c_f167(
|
||||||
fugg::RuntimePointer<fugg::detail::RawBasicString>(result.get()).as_raw(),
|
fugg::RuntimePointer<fugg::detail::RawBasicString>(result.get()).as_raw(),
|
||||||
fugg::RuntimePointer<fugg::String>(id_.get()).as_raw()
|
fugg::RuntimePointer<fugg::String>(id_.get()).as_raw()
|
||||||
);
|
);
|
||||||
|
|
||||||
std::cout << "Result after: " << reinterpret_cast<void*>(result->data) << ", "
|
return *reinterpret_cast<fugg::String*>(result.get());
|
||||||
<< result->size << ", "
|
|
||||||
<< reinterpret_cast<void*>(result->cap) << std::endl;
|
|
||||||
|
|
||||||
auto showable = *reinterpret_cast<fugg::String*>(result.get());
|
|
||||||
std::cout << "Result = " << showable->c_str() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
@ -83,11 +72,10 @@ void translate(const std::string& id) {
|
||||||
void before_main_loop() {
|
void before_main_loop() {
|
||||||
auto& client = fugg::Client::instance();
|
auto& client = fugg::Client::instance();
|
||||||
|
|
||||||
translate("ids_textclient_cannot_dropmoney");
|
const auto& test = translate("ids_textclient_cannot_dropmoney");
|
||||||
|
std::cout << test->c_str() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "interop/flyff.h"
|
|
||||||
|
|
||||||
void after_main_loop() {
|
void after_main_loop() {
|
||||||
// std::string test;
|
// std::string test;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "fugg.h"
|
#include <fugg.h>
|
||||||
|
|
||||||
namespace fugg {
|
namespace fugg {
|
||||||
class Client {
|
class Client {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "fugg.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace flyff {
|
|
||||||
#include "structs/ItemProperty.h"
|
|
||||||
#include "structs/MusicProperty.h"
|
|
||||||
#include "structs/Mover.h"
|
|
||||||
|
|
||||||
namespace api {
|
|
||||||
static_assert(sizeof(fugg::ModulePointer<void>) == sizeof(u32), "ModulePointer needs the same size as u32");
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
// Translate
|
|
||||||
// extern void translate(u32, u32);
|
|
||||||
// extern void w2c_f167(fugg::String*, std::string*);
|
|
||||||
extern void w2c_f167(u32, u32);
|
|
||||||
|
|
||||||
extern u32 w2c_f208(u64);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <wasm-rt.h>
|
|
||||||
#include <client.h>
|
|
||||||
|
|
||||||
namespace fugg {
|
|
||||||
namespace interop {
|
|
||||||
namespace import {
|
|
||||||
static const auto& init = &Z_client_init;
|
|
||||||
|
|
||||||
static const auto& __wasm_call_ctors = &Z_clientZ____wasm_call_ctors;
|
|
||||||
static const auto& _main = &Z_clientZ__main;
|
|
||||||
|
|
||||||
|
|
||||||
static const auto& _malloc = &Z_clientZ__malloc;
|
|
||||||
static const auto& _free = &Z_clientZ__free;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +1,57 @@
|
||||||
#include "fugg.h"
|
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <emscripten/heap.h>
|
#include <emscripten/heap.h>
|
||||||
#include "interop/imports.h"
|
|
||||||
|
#include <fugg.h>
|
||||||
|
#include <flyff.h>
|
||||||
|
|
||||||
|
#include "client.h"
|
||||||
|
|
||||||
void *malloc (size_t __size) {
|
void *malloc (size_t __size) {
|
||||||
// void * operator new(std::size_t __size) {
|
// void * operator new(std::size_t __size) {
|
||||||
using namespace fugg::interop;
|
|
||||||
// This malloc is always called from the runtime.
|
// This malloc is always called from the runtime.
|
||||||
|
|
||||||
if((*import::_malloc) != nullptr) {
|
if((*flyff::malloc) != nullptr) {
|
||||||
// Since this malloc is always called from the interop, we need to
|
// Since this malloc is always called from the interop, we need to
|
||||||
// transform it to point to the actual address where the WASM runtime memory
|
// transform it to point to the actual address where the WASM runtime memory
|
||||||
// resides.
|
// resides.
|
||||||
|
|
||||||
const auto& ptr = fugg::ModulePointer<void> {
|
const auto& ptr = fugg::ModulePointer<void> {
|
||||||
(*import::_malloc)(__size)
|
(*flyff::malloc)(__size)
|
||||||
};
|
};
|
||||||
|
|
||||||
// #if TRACE_ALLOC
|
#if TRACE_ALLOC
|
||||||
std::cout << "FLYFF: Allocated INSIDE " << __size << " bytes at " << reinterpret_cast<void*>(ptr.as_raw()) << std::endl;
|
std::cout << "FLYFF: Allocated INSIDE " << __size << " bytes at " << reinterpret_cast<void*>(ptr.as_raw()) << std::endl;
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
} else {
|
} else {
|
||||||
auto ptr = emscripten_builtin_malloc(__size);
|
auto ptr = emscripten_builtin_malloc(__size);
|
||||||
|
|
||||||
// #if TRACE_ALLOC
|
#if TRACE_ALLOC
|
||||||
std::cout << "FUGG: Allocated OUTSIDE " << __size << " bytes at " << reinterpret_cast<void*>(ptr) << std::endl;
|
std::cout << "FUGG: Allocated OUTSIDE " << __size << " bytes at " << reinterpret_cast<void*>(ptr) << std::endl;
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void free (void *__ptr) {
|
void free (void *__ptr) {
|
||||||
// void operator delete(void * __ptr) {
|
// void operator delete(void * __ptr) {
|
||||||
using namespace fugg::interop;
|
|
||||||
// printf("Trying to free ptr %p\n", __ptr);
|
// printf("Trying to free ptr %p\n", __ptr);
|
||||||
|
|
||||||
if((*import::_free) != nullptr) {
|
if((*flyff::free) != nullptr) {
|
||||||
const auto& ptr = fugg::RuntimePointer<void> { __ptr };
|
const auto& ptr = fugg::RuntimePointer<void> { __ptr };
|
||||||
|
|
||||||
(*import::_free)(ptr.as_raw());
|
(*flyff::free)(ptr.as_raw());
|
||||||
|
|
||||||
// #if TRACE_ALLOC
|
#if TRACE_ALLOC
|
||||||
std::cout << "FLYFF: Free'd INSIDE pointer at " << reinterpret_cast<void*>(ptr.as_raw()) << std::endl;
|
std::cout << "FLYFF: Free'd INSIDE pointer at " << reinterpret_cast<void*>(ptr.as_raw()) << std::endl;
|
||||||
// #endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
emscripten_builtin_free(__ptr);
|
emscripten_builtin_free(__ptr);
|
||||||
|
|
||||||
// #if TRACE_ALLOC
|
#if TRACE_ALLOC
|
||||||
std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast<void*>(__ptr) << std::endl;
|
std::cout << "FUGG: Free'd OUTSIDE pointer at " << reinterpret_cast<void*>(__ptr) << std::endl;
|
||||||
// #endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
add_library (
|
|
||||||
fugg-core
|
|
||||||
|
|
||||||
"include/fugg.h"
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(fugg-core PROPERTIES LINKER_LANGUAGE CXX)
|
|
||||||
|
|
||||||
target_include_directories(fugg-core PUBLIC "include")
|
|
||||||
target_link_libraries (fugg-core LINK_PUBLIC flyff-client)
|
|
||||||
Reference in New Issue