Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
added extracting cached textures
Browse files Browse the repository at this point in the history
update mappings
refactoring
  • Loading branch information
DiaLight committed Dec 27, 2022
1 parent 17feeaa commit 8b1a5d0
Show file tree
Hide file tree
Showing 34 changed files with 5,126 additions and 4,023 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ add_custom_command(
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS- /Gz")

add_library(win32_gui_layout STATIC win32_gui_layout.cpp)
target_include_directories(win32_gui_layout PUBLIC ${CMAKE_CURRENT_LIST_DIR})

set(SOURCES
main.cpp
api.cpp
Expand Down Expand Up @@ -115,6 +119,7 @@ set(SOURCES
patches/screen_resolution/fix_surface_buffer_size_on_max_resolution.cpp
reimpl/SurfHashList__probablySort.cpp
reimpl/draw3dScene.cpp
tools/unpack_texture_cache.cpp
stdex.cpp
)
if(REVERSE_MODE)
Expand All @@ -134,8 +139,11 @@ else()
endif()
add_dependencies(bootstrap_patcher dll_exports stack_map references_map)
target_include_directories(bootstrap_patcher PRIVATE include)
target_link_libraries(bootstrap_patcher PRIVATE Dbghelp Shcore)
target_compile_definitions(bootstrap_patcher PRIVATE DIRECTINPUT_VERSION=0x0500)
target_link_libraries(bootstrap_patcher PRIVATE Dbghelp Shcore Comctl32 win32_gui_layout)
target_compile_definitions(bootstrap_patcher PRIVATE DIRECTINPUT_VERSION=0x0500 DIRECT3D_VERSION=0x0600)

add_subdirectory(vendor)
target_link_libraries(bootstrap_patcher PRIVATE lodepng)

set_target_properties(bootstrap_patcher PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${BIN_DIR}")

Expand Down
2 changes: 1 addition & 1 deletion api/stacktrace_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <ShlObj.h>
#include <windowsx.h>
#include <sstream>
#include "../win32_gui_layout.h"
#include <win32_gui_layout.h>

#define EmberPatcher_title _T("Ember DK2 patcher")
#define EmberPatcher_class _T("EmberPatcher")
Expand Down
26 changes: 1 addition & 25 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,7 @@
#include <cstdint>
#include <functional>
#include <api/window.h>

template<typename T>
uint8_t *follow(T &&ptr) {
union {
T *fun;
uint8_t **ptr;
} val = {
.fun = &ptr
};
uint8_t *pos = *val.ptr;
#ifdef REVERSE_MODE
if(*pos++ != 0xE9) return nullptr;
pos = (pos + 4) + *(uint32_t *) pos;
if(*pos++ != 0xB8) return nullptr;
pos = *(uint8_t **) pos;
#else
if(*pos++ != 0xFF) return nullptr;
if(*pos++ != 0x25) return nullptr;
pos = *(uint8_t **) pos;
pos = *(uint8_t **) pos;
#endif
return pos;
}
template<auto Fun>
uint8_t *funptr() { return follow(Fun); }
#include <api/imports.h>

extern HINSTANCE g_bootstrap_patcher;

Expand Down
35 changes: 35 additions & 0 deletions include/api/imports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by DiaLight on 26.12.2022.
//

#ifndef EMBER_IMPORTS_H
#define EMBER_IMPORTS_H


template<typename T>
uint8_t *follow(T &&ptr) {
union {
T *fun;
uint8_t **ptr;
} val = {
.fun = &ptr
};
uint8_t *pos = *val.ptr;
#ifdef REVERSE_MODE
if(*pos++ != 0xE9) return nullptr;
pos = (pos + 4) + *(uint32_t *) pos;
if(*pos++ != 0xB8) return nullptr;
pos = *(uint8_t **) pos;
#else
if(*pos++ != 0xFF) return nullptr;
if(*pos++ != 0x25) return nullptr;
pos = *(uint8_t **) pos;
pos = *(uint8_t **) pos;
#endif
return pos;
}
template<auto Fun>
uint8_t *funptr() { return follow(Fun); }


#endif //EMBER_IMPORTS_H
22 changes: 1 addition & 21 deletions include/dk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ddraw.h>
#include <dinput.h>
#include <api.h>
#include <dk2/globals.h>
#include <dk2/dd.h>
#include <dk2/window.h>
#include <dk2/dinput.h>
Expand All @@ -23,27 +24,6 @@

namespace dk2 {

__analysis_noreturn
/*00638440*/ void __cdecl start();
/*005A5DA0*/ int __cdecl main(int argc, char *argv[]);
/*005B74A0*/ void __cdecl resolveDk2HomeDir();

class globals {
/*0079D01C*/ static HINSTANCE hInstance;
/*0079D980*/ static char dk2HomeDir[MAX_PATH];
public:
/*005B2DA0*/ static void __cdecl setHInstance(HINSTANCE hInst);
/*005B2D90*/ static HINSTANCE __cdecl getHInstance();
// msvc is importing data as functions. So we follow import jump to get actual data address
inline static HINSTANCE *getHInstancePtr() { return (HINSTANCE *) funptr<&hInstance>(); }

/*005B2E50*/ static void __cdecl setAppExitStatus(bool shouldExit);
/*005B2E40*/ static bool __cdecl isAppExitStatusSet();

inline static char *getDk2HomeDir() { return (char *) funptr<&dk2HomeDir>(); }

};

// use BOOL instead of bool! sizeof(bool) == 1 sizeof(BOOL) == 4
/*00557FD0*/ BOOL __stdcall isOsVersionGE(int maxVersion, int minVersion, uint16_t CSDVersion);

Expand Down
19 changes: 0 additions & 19 deletions include/dk2/dd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@

namespace dk2 {

class dd {
/*0079D020*/ static HWND hWnd;
/*0079D3D0*/ static LPDIRECTDRAW lpDD;
/*0079D3F0*/ static LPDIRECTDRAW lpSurfaceDD;

public:
/*005B2DC0*/ static void __cdecl setHWindow(HWND hWnd);
/*005B2DB0*/ static HWND __cdecl getHWindow();
inline static HWND *getHWindowPtr() { return (HWND *) funptr<&hWnd>(); }

inline static LPDIRECTDRAW *getDD() { return (LPDIRECTDRAW *) funptr<&lpDD>(); }
inline static LPDIRECTDRAW *getSurfaceDD() { return (LPDIRECTDRAW *) funptr<&lpSurfaceDD>(); }
/*005B5410*/ static void __cdecl setSurfaceDD(LPDIRECTDRAW lpDD);

/*005B4390*/ static status_t &__cdecl init(status_t &status, DWORD width, DWORD height, DWORD displayBitness, DWORD surfFlags, LPPALETTEENTRY palette);
/*005B4230*/ static void __cdecl destroy();

};

struct MyDdSurface{
uint32_t field_0;
uint32_t field_4;
Expand Down
56 changes: 56 additions & 0 deletions include/dk2/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Created by DiaLight on 27.12.2022.
//

#ifndef EMBER_GLOBALS_H
#define EMBER_GLOBALS_H

#include <api/imports.h>

namespace dk2 {

__analysis_noreturn
/*00638440*/ void __cdecl start();
/*005A5DA0*/ int __cdecl main(int argc, char *argv[]);
/*005B74A0*/ void __cdecl resolveDk2HomeDir();

class globals {
/*0079D01C*/ static HINSTANCE hInstance;
/*0079D980*/ static char dk2HomeDir[MAX_PATH];
public:
/*005B2DA0*/ static void __cdecl setHInstance(HINSTANCE hInst);
/*005B2D90*/ static HINSTANCE __cdecl getHInstance();
// msvc is importing data as functions. So we follow import jump to get actual data address
inline static HINSTANCE *getHInstancePtr() { return (HINSTANCE *) funptr<&hInstance>(); }

/*005B2E50*/ static void __cdecl setAppExitStatus(bool shouldExit);
/*005B2E40*/ static bool __cdecl isAppExitStatusSet();

inline static char *getDk2HomeDir() { return (char *) funptr<&dk2HomeDir>(); }

};

using status_t = int;

class dd {
/*0079D020*/ static HWND hWnd;
/*0079D3D0*/ static LPDIRECTDRAW lpDD;
/*0079D3F0*/ static LPDIRECTDRAW lpSurfaceDD;

public:
/*005B2DC0*/ static void __cdecl setHWindow(HWND hWnd);
/*005B2DB0*/ static HWND __cdecl getHWindow();
inline static HWND *getHWindowPtr() { return (HWND *) funptr<&hWnd>(); }

inline static LPDIRECTDRAW *getDD() { return (LPDIRECTDRAW *) funptr<&lpDD>(); }
inline static LPDIRECTDRAW *getSurfaceDD() { return (LPDIRECTDRAW *) funptr<&lpSurfaceDD>(); }
/*005B5410*/ static void __cdecl setSurfaceDD(LPDIRECTDRAW lpDD);

/*005B4390*/ static status_t &__cdecl init(status_t &status, DWORD width, DWORD height, DWORD displayBitness, DWORD surfFlags, LPPALETTEENTRY palette);
/*005B4230*/ static void __cdecl destroy();

};

}

#endif //EMBER_GLOBALS_H
Loading

0 comments on commit 8b1a5d0

Please sign in to comment.