Skip to content

Commit

Permalink
add eastl, add custom .pkg loading
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 committed Jun 4, 2024
1 parent 2ca118a commit bea87cc
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 90 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")

# Fetch modules
message("\nFetching modules")
include(cmake_scripts/eastl.cmake)
include(cmake_scripts/git.cmake)
include(cmake_scripts/lpeg.cmake)
include(cmake_scripts/luasocket.cmake)
Expand Down Expand Up @@ -43,14 +44,15 @@ source_group(TREE ${SRC_DIR} PREFIX "src" FILES ${SRC_MAIN})

target_include_directories(Hell2Modding PRIVATE
"${SRC_DIR}"
"${eastl_SOURCE_DIR}/include"
"${tolk_SOURCE_DIR}/include"
"${lpeg_SOURCE_DIR}"
"${luasocket_SOURCE_DIR}/src"
)

target_precompile_headers(Hell2Modding PRIVATE "${SRC_DIR}/common.hpp")

target_link_libraries(Hell2Modding PRIVATE ReturnOfModdingBase Tolk lpeg_static luasocket_static wsock32 ws2_32)
target_link_libraries(Hell2Modding PRIVATE ReturnOfModdingBase Tolk lpeg_static luasocket_static wsock32 ws2_32 EASTL)

# Warnings as errors
set_property(TARGET Hell2Modding PROPERTY COMPILE_WARNING_AS_ERROR ON)
Expand Down
9 changes: 9 additions & 0 deletions cmake_scripts/eastl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(FetchContent)

FetchContent_Declare(
eastl
GIT_REPOSITORY https://github.com/electronicarts/EASTL.git
GIT_TAG 05f4b4aef33f2f3ded08f19fa97f5a27ff35ff9f
GIT_SUBMODULES_RECURSE OFF
)
FetchContent_MakeAvailable(eastl)
6 changes: 2 additions & 4 deletions src/lua_extensions/bindings/hades/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace lua::hades::audio
static auto LoadBank_ptr = gmAddress::scan("90 84 C0 75 2B", "sgg::AudioManager::LoadBank");
if (LoadBank_ptr)
{
static auto LoadBank = LoadBank_ptr.offset(-0x2B).as_func<void(eastl_basic_string_view_char*, sgg__PackageGroup)>();
static auto LoadBank = LoadBank_ptr.offset(-0x2B).as_func<void(eastl::string_view*, sgg__PackageGroup)>();

static auto fsAppendPathComponent_ptr = gmAddress::scan("C6 44 24 30 5C", "fsAppendPathComponent");
if (fsAppendPathComponent_ptr)
Expand All @@ -48,10 +48,8 @@ namespace lua::hades::audio
static auto hook_once =
big::hooking::detour_hook_helper::add<hook_fsAppendPathComponent>("hook_fsAppendPathComponent", fsAppendPathComponent);

eastl_basic_string_view_char fp;
std::string bank_name = (char*)std::filesystem::path(file_path).stem().u8string().c_str();
fp.mpBegin = bank_name.c_str();
fp.mnCount = bank_name.size();
eastl::string_view fp(bank_name.c_str(), bank_name.size());

need_path_fix_fsAppendPathComponent = true;
fixed_path_fsAppendPathComponent = file_path;
Expand Down
69 changes: 14 additions & 55 deletions src/lua_extensions/bindings/hades/hades_ida.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <EASTL/vector.h>

namespace Vectormath
{
struct Point2
Expand All @@ -23,36 +25,12 @@ namespace Vectormath
} // namespace SSE
} // namespace Vectormath

namespace eastl
namespace eastl_custom
{
struct allocator_forge
{
};

template<typename T, typename allocator_type, size_t pair_size>
struct compressed_pair_imp : allocator_type
{
T *mFirst;
};

template<typename T, typename allocator_type>
struct compressed_pair : compressed_pair_imp<T, allocator_type, 2>
{
};

template<typename T, typename allocator_type>
struct VectorBase
{
T *mpBegin;
T *mpEnd;
eastl::compressed_pair<T, allocator_type> mCapacityAllocator;
};

template<typename T, typename allocator_type>
struct vector : VectorBase<T, allocator_type>
{
};

namespace internal
{
struct unused_class
Expand All @@ -62,14 +40,14 @@ namespace eastl
union functor_storage_alignment
{
void(__fastcall *unused_func_ptr)();
void(__fastcall *unused_func_mem_ptr)(eastl::internal::unused_class *this_);
void(__fastcall *unused_func_mem_ptr)(eastl_custom::internal::unused_class *this_);
void *unused_ptr;
};

template<size_t size>
struct functor_storage
{
functor_storage_alignment align;
//functor_storage_alignment align;
char storage[size];
};

Expand All @@ -89,7 +67,7 @@ namespace eastl
};

template<typename T, size_t size>
struct function_detail : eastl::internal::function_base_detail<size>
struct function_detail : eastl_custom::internal::function_base_detail<size>
{
void *(__fastcall *mMgrFuncPtr)(void *, void *, ManagerOperations);
T(*mInvokeFuncPtr);
Expand All @@ -98,34 +76,15 @@ namespace eastl
} // namespace internal

template<typename T>
struct function : eastl::internal::function_detail<T, 8>
{
};

static_assert(offsetof(function<void *>, mMgrFuncPtr) == 0x10);
static_assert(offsetof(function<void *>, mInvokeFuncPtr) == 0x18);

/*template<typename T, typename allocator_type>
union basic_string_layout_union
struct function : eastl_custom::internal::function_detail<T, 16>
{
eastl::basic_string<T, allocator_type>::HeapLayout heap;
eastl::basic_string<T, allocator_type>::SSOLayout sso;
eastl::basic_string<T, allocator_type>::RawLayout raw;
};

template<typename T, typename allocator_type>
struct basic_string__Layout
{
basic_string_layout_union<T, allocator_type> ___u0;
};
constexpr size_t testaaaa = offsetof(eastl_custom::function<void *>, mMgrFuncPtr);

// TODO: this is wrong and unfinished.
template<typename T, typename allocator_type>
struct basic_string
{
eastl::compressed_pair<eastl::basic_string<T, allocator_type>::Layout, allocator_type> mPair;
};*/
} // namespace eastl
static_assert(offsetof(eastl_custom::function<void *>, mMgrFuncPtr) == 0x10);
static_assert(offsetof(eastl_custom::function<void *>, mInvokeFuncPtr) == 0x18);
} // namespace eastl_custom

namespace FMOD
{
Expand Down Expand Up @@ -186,7 +145,7 @@ namespace sgg

struct SoundAction
{
eastl::vector<eastl::function<sgg::SoundCue>, eastl::allocator_forge> mCallBacks;
eastl::vector<eastl::function<sgg::SoundCue>> mCallBacks;
};

struct /*VFT*/ AudioChannel_vtbl
Expand Down Expand Up @@ -256,8 +215,8 @@ namespace sgg

struct __declspec(align(8)) ThingDataDef
{
eastl::vector<Vectormath::Point2, eastl::allocator_forge> mPoints;
eastl::vector<UsingInfo, eastl::allocator_forge> mUsing;
eastl::vector<Vectormath::Point2> mPoints;
eastl::vector<UsingInfo> mUsing;
InteractData *mInteract;
Vectormath::Point2 mOffset;
Vectormath::Point2 mSize;
Expand Down
27 changes: 11 additions & 16 deletions src/lua_extensions/bindings/hades/inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ namespace lua::hades::inputs
static void invoke_debug_key_callback(uintptr_t mCallback)
{
// offset to get mName from DebugAction
eastl_basic_string_view_char *mName = (eastl_basic_string_view_char *)(mCallback - 0x18);
auto *mName_ = (eastl::string *)(mCallback - 0x18);

std::string mName = mName_->c_str();

if (enable_vanilla_debug_keybinds)
{
const auto it_callback = vanilla_key_callbacks.find(mName->get_text());
const auto it_callback = vanilla_key_callbacks.find(mName);
if (it_callback != vanilla_key_callbacks.end())
{
LOG(DEBUG) << it_callback->first << " (Vanilla)";
Expand All @@ -333,7 +335,7 @@ namespace lua::hades::inputs
for (const auto &mod_ : big::g_lua_manager->m_modules)
{
auto mod = (big::lua_module_ext *)mod_.get();
const auto it_callback = mod->m_data_ext.m_keybinds.find(mName->get_text());
const auto it_callback = mod->m_data_ext.m_keybinds.find(mName);
if (it_callback != mod->m_data_ext.m_keybinds.end())
{
LOG(DEBUG) << it_callback->first << " (" << mod->guid() << ")";
Expand All @@ -349,19 +351,12 @@ namespace lua::hades::inputs

static void parse_and_register_keybind(std::string &keybind, const sol::coroutine &callback, const std::string &name, auto &RegisterDebugKey, bool is_vanilla, big::lua_module_ext *mod)
{
eastl::function<void(uintptr_t)> funcy;
eastl_custom::function<void(uintptr_t)> funcy;
funcy.mMgrFuncPtr = nullptr;
funcy.mInvokeFuncPtr = invoke_debug_key_callback;
eastl_basic_string_view_char callback_name{};
callback_name.mRemainingSizeField = (char)129;
// TODO: this is leaking
callback_name.mpBegin = (char *)malloc(keybind.size());
memcpy((char *)callback_name.mpBegin, keybind.data(), keybind.size());
callback_name.mnCount = keybind.size();
eastl_basic_string_view_char nothing{};
nothing.mRemainingSizeField = (char)23;
eastl_basic_string_view_char nothing2{};
nothing2.mRemainingSizeField = (char)23;
eastl::string callback_name{keybind.data(), keybind.size()};
eastl::string nothing{};
eastl::string nothing2{};

int32_t key_modifier = 0;
int32_t key = 0;
Expand Down Expand Up @@ -435,7 +430,7 @@ namespace lua::hades::inputs

if (keybind_opt.has_value() && keybind_opt->size() && callback_opt.has_value() && callback_opt->valid())
{
auto RegisterDebugKey_good_type = RegisterDebugKey.as_func<void(int32_t a1, int32_t, eastl::function<void(uintptr_t)> *, eastl_basic_string_view_char *, void *, void *, bool, eastl_basic_string_view_char *, eastl_basic_string_view_char *, bool)>();
auto RegisterDebugKey_good_type = RegisterDebugKey.as_func<void(int32_t a1, int32_t, eastl_custom::function<void(uintptr_t)> *, eastl::string *, void *, void *, bool, eastl::string *, eastl::string *, bool)>();
parse_and_register_keybind(*keybind_opt, *callback_opt, callback_name_opt ? *callback_name_opt : "", RegisterDebugKey_good_type, false, mod);
}
}
Expand All @@ -461,7 +456,7 @@ namespace lua::hades::inputs

if (keybind_opt.has_value() && keybind_opt->size() && callback_opt.has_value() && callback_opt->valid())
{
auto RegisterDebugKey_good_type = RegisterDebugKey.as_func<void(int32_t a1, int32_t, eastl::function<void(uintptr_t)> *, eastl_basic_string_view_char *, void *, void *, bool, eastl_basic_string_view_char *, eastl_basic_string_view_char *, bool)>();
auto RegisterDebugKey_good_type = RegisterDebugKey.as_func<void(int32_t a1, int32_t, eastl_custom::function<void(uintptr_t)> *, eastl::string *, void *, void *, bool, eastl::string *, eastl::string *, bool)>();
parse_and_register_keybind(*keybind_opt, *callback_opt, callback_name_opt ? *callback_name_opt : "", RegisterDebugKey_good_type, true, nullptr);
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/lua_extensions/bindings/tolk/tolk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ namespace lua::tolk
{
for (auto i = gui_comp->mLines.mpBegin; i < gui_comp->mLines.mpEnd; i++)
{
const auto text = i->mText.get_text();
if (text.size() && !already_printed.contains(text))
if (i->mText.size() && !already_printed.contains(i->mText.c_str()))
{
already_printed.insert(text);
already_printed.insert(i->mText.c_str());
//LOG(INFO) << text << " (" << gui_comp_loc.mX << ", " << gui_comp_loc.mY << ")";
text_buffer << text << "\n";
text_buffer << i->mText.c_str() << "\n";
}
}
}
Expand Down Expand Up @@ -144,7 +143,7 @@ namespace lua::tolk
{
char m_pad[0x30];

eastl::vector<GUIComponentTextBox*, eastl::allocator_forge> mTextBoxes;
eastl::vector<GUIComponentTextBox*> mTextBoxes;
};

static_assert(offsetof(TextComponent, mTextBoxes) == 0x30);
Expand Down Expand Up @@ -172,11 +171,11 @@ namespace lua::tolk
sgg::Thing* active_thing = get_active_thing(sgg_world_ptr, thing_id);
if (active_thing && active_thing->pText)
{
for (auto i = active_thing->pText->mTextBoxes.mpBegin; i < active_thing->pText->mTextBoxes.mpEnd; i++)
for (auto i = active_thing->pText->mTextBoxes.begin(); i != active_thing->pText->mTextBoxes.end(); i++)
{
for (auto j = (*i)->mLines.mpBegin; j < (*i)->mLines.mpEnd; j++)
{
res.push_back(j->mText.get_text());
res.push_back(j->mText.c_str());
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/lua_extensions/bindings/tolk/tolk.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

struct eastl_basic_string_view_char
#include <EASTL/string.h>

/*struct eastl_basic_string_view_char
{
const char* mpBegin;
size_t mnCount;
Expand All @@ -25,7 +27,7 @@ struct eastl_basic_string_view_char
}
};
static_assert(offsetof(eastl_basic_string_view_char, mRemainingSizeField) == 0x17);
static_assert(offsetof(eastl_basic_string_view_char, mRemainingSizeField) == 0x17);*/

struct GUIComponentTextBox;

Expand All @@ -37,7 +39,7 @@ struct GUIComponentTextBox_Line
float mActualWidth;
float mFixedLineSpacing;
float mImageWidth;
eastl_basic_string_view_char mText;
eastl::string mText;
GUIComponentTextBox* mFormatter;
GUIComponentTextBox* mGraftFormatter;
};
Expand All @@ -60,7 +62,7 @@ struct GUIComponentTextBox
{
GUIComponentTextBox_vtbl* vtbl;
char m_pad[0x6'90];
eastl_basic_string_view_char mStringBuilder;
eastl::string mStringBuilder;
char m_pad2[70];
eastl_vector<GUIComponentTextBox_Line> mLines;
};
Expand Down
Loading

0 comments on commit bea87cc

Please sign in to comment.