Skip to content

Commit

Permalink
ldk
Browse files Browse the repository at this point in the history
  • Loading branch information
muhopensores committed Oct 11, 2024
1 parent f794174 commit 1330920
Show file tree
Hide file tree
Showing 19 changed files with 1,455 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/D3D9Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ HRESULT WINAPI D3D9Hook::reset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS

return reset_fn(pDevice, pPresentationParameters);
}

1 change: 1 addition & 0 deletions src/D3D9Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <functional>

#include <d3d9.h>
#include <d3d9types.h>

#include "utility/FunctionHook.hpp"

Expand Down
17 changes: 13 additions & 4 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#include "mods/CustomAlolcator.hpp"
#include "utility/ExceptionHandler.hpp"
#include "mods/RendererReplace.hpp"
#include "mods/CustomAlolcator.hpp"

static HMODULE g_dinput;
static HMODULE g_styleswitcher;
//static Mod* g_renderer_replace{ nullptr };
#pragma comment(lib, "mincore")

#if 1
extern "C" {
// DirectInput8Create wrapper for dinput8.dll
Expand Down Expand Up @@ -71,6 +72,7 @@ void WINAPI startup_thread() {
#endif
}

#if 0
HANDLE filemapping {};
PULONG_PTR page_array = NULL;
ULONG_PTR number_of_pages = NULL;
Expand Down Expand Up @@ -102,18 +104,27 @@ static BOOL EnableAWE() {
CloseHandle(hToken);
return TRUE;
}
#endif

BOOL APIENTRY DllMain(HMODULE handle, DWORD reason, LPVOID reserved) {
if (reason == DLL_PROCESS_ATTACH) {
#ifndef NDEBUG
MessageBox(NULL, "Debug attach opportunity", "DMC3", MB_ICONINFORMATION);
#endif

bool pe_section_found = find_pe_section_init_arena();
if (!pe_section_found) {
g_styleswitcher = LoadLibraryA("StyleSwitcher.dll");
}
else {
g_styleswitcher = LoadLibraryA("StyleSwitcherPatched.dll");
}
#if 0
SYSTEM_INFO info;
MEMORY_BASIC_INFORMATION mbi{};
VirtualQuery((LPCVOID)0x00C36980, &mbi, sizeof(mbi));
GetSystemInfo(&info);
DWORD memory_size = 0x8200000;
#endif
#if 0
number_of_pages = memory_size / info.dwPageSize;
page_array = new ULONG_PTR[number_of_pages];
Expand Down Expand Up @@ -169,14 +180,12 @@ BOOL APIENTRY DllMain(HMODULE handle, DWORD reason, LPVOID reserved) {
#endif
}
#endif
g_styleswitcher = LoadLibraryA("StyleSwitcher.dll");

//g_renderer_replace = new RendererReplace();
//g_renderer_replace->on_initialize();
CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)startup_thread, nullptr, 0, nullptr);
}
if (reason == DLL_PROCESS_DETACH) {

FreeLibrary(g_styleswitcher);
FreeLibrary(g_dinput);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ModFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ bool ModFramework::initialize() {
auto hr = device->GetCreationParameters(&dev_params);
if (SUCCEEDED(hr)) {
if (dev_params.hFocusWindow) {
spdlog::info("[D3D Device init] D3DDEVICE_CREATION_PARAMETERS hFocusWindow={0:x}\n", (void*)dev_params.hFocusWindow);
spdlog::info("[D3D Device init] D3DDEVICE_CREATION_PARAMETERS hFocusWindow={}\n", (uintptr_t)dev_params.hFocusWindow);
m_wnd = dev_params.hFocusWindow;
} else {
spdlog::info("[D3D Device present] D3DDEVICE_CREATION_PARAMETERS hFocusWindow= is NULL\n");
Expand Down
2 changes: 1 addition & 1 deletion src/ModFramework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ModFramework {

void save_config();

Mod* m_rr;
//Mod* m_rr;
private:
void draw_ui();
void draw_about();
Expand Down
58 changes: 46 additions & 12 deletions src/Mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//#include "mods/StyleSwitcherInfo.hpp"
//#include "mods/CameraHack.hpp"

#define SPEEDRUN_MODE 1

Mods::Mods()
{
Expand All @@ -48,11 +49,19 @@ void Mods::load_mods() {
#if 1
m_mods.emplace_back(std::make_unique<QuicksilverShader>());
m_mods.emplace_back(std::make_unique<AudioStutterFix>());
#ifndef SPEEDRUN_MODE
m_mods.emplace_back(std::make_unique<InertiaThings>());
m_mods.emplace_back(std::make_unique<StyleSwitchFX>());
m_mods.emplace_back(std::make_unique<PracticeMode>()); // NOTE(): dont move this one [5]
m_mods.emplace_back(std::make_unique<BulletStop>());
#else
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE
m_mods.emplace_back(std::make_unique<UIButton>());
#ifndef SPEEDRUN_MODE
m_mods.emplace_back(std::make_unique<InputLog>()); //NOTE(): dont move this one [8]
m_mods.emplace_back(std::make_unique<DebugDraw>()); //NOTE(): dont move this one [9]
m_mods.emplace_back(std::make_unique<RgTimer>()); //NOTE(): dont move this one [10]
Expand All @@ -61,9 +70,26 @@ void Mods::load_mods() {
m_mods.emplace_back(std::make_unique<TurnSpeed>());
m_mods.emplace_back(std::make_unique<EnemyStepCooldown>());
m_mods.emplace_back(std::make_unique<NoHeightRestriction>());
#else
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE

//m_mods.emplace_back(std::make_unique<StyleSwitcherInfo>()); // crashes half the time on boot, will replace
m_mods.emplace_back(std::make_unique<EnemySpawnRate>());
m_mods.emplace_back(std::make_unique<EnemySpawnRate>()); // ldk

#ifndef SPEEDRUN_MODE
m_mods.emplace_back(std::make_unique<AreaJump>());
#else
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE


#endif

#ifndef _NDEBUG
Expand Down Expand Up @@ -109,18 +135,26 @@ void Mods::on_draw_ui() const {
for (auto& mod : m_mods) {
mod->on_draw_ui();
}
g_framework->m_rr->on_draw_ui();
//g_framework->m_rr->on_draw_ui();
}


void Mods::on_draw_custom_imgui_window() const {
#if 0
PracticeMode* p = dynamic_cast<PracticeMode*>(m_mods[6].get()); // epic footguns akimbo
InputLog* l = dynamic_cast<InputLog*>(m_mods[9].get()); // epic footguns akimbo part2
DebugDraw* d = dynamic_cast<DebugDraw*>(m_mods[10].get()); // epic footguns akimbo part3
RgTimer* t = dynamic_cast<RgTimer*>(m_mods[11].get());
p->custom_imgui_window();
l->custom_imgui_window();
d->custom_imgui_window();
t->custom_imgui_window();
#endif
PracticeMode* p = dynamic_cast<PracticeMode*>(m_mods[6].get()); // epic footguns akimbo
InputLog* l = dynamic_cast<InputLog*>(m_mods[9].get()); // epic footguns akimbo part2
DebugDraw* d = dynamic_cast<DebugDraw*>(m_mods[10].get()); // epic footguns akimbo part3
RgTimer* t = dynamic_cast<RgTimer*>(m_mods[11].get());

if (p) {
p->custom_imgui_window();
}
if (l) {
l->custom_imgui_window();
}
if (d) {
d->custom_imgui_window();
}
if (t) {
t->custom_imgui_window();
}
}
42 changes: 37 additions & 5 deletions src/mods/AreaJump.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
#include "AreaJump.hpp"


// clang-format off
static uintptr_t detour_return {NULL};
static void __declspec(naked) detour() {
__asm {
mov dword ptr [esi],007462C4h
mov dword ptr [g_devil3_main_scene_pointer], esi
jmp dword ptr [detour_return]
}
}
static uintptr_t detour1_retun {NULL};
static void __declspec(naked) detour1() {
__asm {
test eax, eax
jne original_code
ret
original_code:
push ebx
mov bl, 20
mov cl, [eax]
jmp dword ptr [detour1_retun]
}

}
// clang-format on

struct Room {
Expand Down Expand Up @@ -200,14 +223,23 @@ static constexpr std::array<Room, 189> room_items = {
};

std::optional<std::string> AreaJump::on_initialize() {
// uintptr_t base = g_framework->get_module().as<uintptr_t>();
return Mod::on_initialize();

if (!install_hook_absolute(0x005E10D9, m_function_hook, &detour, &detour_return, 6)) {
return "Failed to install CSceneGameMain::CSceneGameMain() hook";
}
#if 0
if (!install_hook_absolute(0x00695A64, m_function_hook1, &detour1, &detour1_retun, 5)) {
return "Failed to install CStage::something() hook";
}
#endif

return Mod::on_initialize();
}

void AreaJump::on_draw_ui() {
if (!ImGui::CollapsingHeader(get_name().data())) {
return;
}
if (!ImGui::CollapsingHeader(get_name().data())) {
return;
}
static char filter_inputbox[MAX_PATH] = {0};

ImGui::InputText("Filter: ", filter_inputbox, MAX_PATH);
Expand Down
3 changes: 2 additions & 1 deletion src/mods/AreaJump.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class AreaJump : public Mod {
private:
// function hook instance for our detour, convinient wrapper
// around minhook
// std::unique_ptr<FunctionHook> m_function_hook;
std::unique_ptr<FunctionHook> m_function_hook;
std::unique_ptr<FunctionHook> m_function_hook1;
};
Loading

0 comments on commit 1330920

Please sign in to comment.