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

Commit 8b1a5d0

Browse files
committed
added extracting cached textures
update mappings refactoring
1 parent 17feeaa commit 8b1a5d0

34 files changed

+5126
-4023
lines changed

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ add_custom_command(
8787
)
8888

8989
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS- /Gz")
90+
91+
add_library(win32_gui_layout STATIC win32_gui_layout.cpp)
92+
target_include_directories(win32_gui_layout PUBLIC ${CMAKE_CURRENT_LIST_DIR})
93+
9094
set(SOURCES
9195
main.cpp
9296
api.cpp
@@ -115,6 +119,7 @@ set(SOURCES
115119
patches/screen_resolution/fix_surface_buffer_size_on_max_resolution.cpp
116120
reimpl/SurfHashList__probablySort.cpp
117121
reimpl/draw3dScene.cpp
122+
tools/unpack_texture_cache.cpp
118123
stdex.cpp
119124
)
120125
if(REVERSE_MODE)
@@ -134,8 +139,11 @@ else()
134139
endif()
135140
add_dependencies(bootstrap_patcher dll_exports stack_map references_map)
136141
target_include_directories(bootstrap_patcher PRIVATE include)
137-
target_link_libraries(bootstrap_patcher PRIVATE Dbghelp Shcore)
138-
target_compile_definitions(bootstrap_patcher PRIVATE DIRECTINPUT_VERSION=0x0500)
142+
target_link_libraries(bootstrap_patcher PRIVATE Dbghelp Shcore Comctl32 win32_gui_layout)
143+
target_compile_definitions(bootstrap_patcher PRIVATE DIRECTINPUT_VERSION=0x0500 DIRECT3D_VERSION=0x0600)
144+
145+
add_subdirectory(vendor)
146+
target_link_libraries(bootstrap_patcher PRIVATE lodepng)
139147

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

api/stacktrace_window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <ShlObj.h>
1111
#include <windowsx.h>
1212
#include <sstream>
13-
#include "../win32_gui_layout.h"
13+
#include <win32_gui_layout.h>
1414

1515
#define EmberPatcher_title _T("Ember DK2 patcher")
1616
#define EmberPatcher_class _T("EmberPatcher")

include/api.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,7 @@
99
#include <cstdint>
1010
#include <functional>
1111
#include <api/window.h>
12-
13-
template<typename T>
14-
uint8_t *follow(T &&ptr) {
15-
union {
16-
T *fun;
17-
uint8_t **ptr;
18-
} val = {
19-
.fun = &ptr
20-
};
21-
uint8_t *pos = *val.ptr;
22-
#ifdef REVERSE_MODE
23-
if(*pos++ != 0xE9) return nullptr;
24-
pos = (pos + 4) + *(uint32_t *) pos;
25-
if(*pos++ != 0xB8) return nullptr;
26-
pos = *(uint8_t **) pos;
27-
#else
28-
if(*pos++ != 0xFF) return nullptr;
29-
if(*pos++ != 0x25) return nullptr;
30-
pos = *(uint8_t **) pos;
31-
pos = *(uint8_t **) pos;
32-
#endif
33-
return pos;
34-
}
35-
template<auto Fun>
36-
uint8_t *funptr() { return follow(Fun); }
12+
#include <api/imports.h>
3713

3814
extern HINSTANCE g_bootstrap_patcher;
3915

include/api/imports.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Created by DiaLight on 26.12.2022.
3+
//
4+
5+
#ifndef EMBER_IMPORTS_H
6+
#define EMBER_IMPORTS_H
7+
8+
9+
template<typename T>
10+
uint8_t *follow(T &&ptr) {
11+
union {
12+
T *fun;
13+
uint8_t **ptr;
14+
} val = {
15+
.fun = &ptr
16+
};
17+
uint8_t *pos = *val.ptr;
18+
#ifdef REVERSE_MODE
19+
if(*pos++ != 0xE9) return nullptr;
20+
pos = (pos + 4) + *(uint32_t *) pos;
21+
if(*pos++ != 0xB8) return nullptr;
22+
pos = *(uint8_t **) pos;
23+
#else
24+
if(*pos++ != 0xFF) return nullptr;
25+
if(*pos++ != 0x25) return nullptr;
26+
pos = *(uint8_t **) pos;
27+
pos = *(uint8_t **) pos;
28+
#endif
29+
return pos;
30+
}
31+
template<auto Fun>
32+
uint8_t *funptr() { return follow(Fun); }
33+
34+
35+
#endif //EMBER_IMPORTS_H

include/dk2.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ddraw.h>
99
#include <dinput.h>
1010
#include <api.h>
11+
#include <dk2/globals.h>
1112
#include <dk2/dd.h>
1213
#include <dk2/window.h>
1314
#include <dk2/dinput.h>
@@ -23,27 +24,6 @@
2324

2425
namespace dk2 {
2526

26-
__analysis_noreturn
27-
/*00638440*/ void __cdecl start();
28-
/*005A5DA0*/ int __cdecl main(int argc, char *argv[]);
29-
/*005B74A0*/ void __cdecl resolveDk2HomeDir();
30-
31-
class globals {
32-
/*0079D01C*/ static HINSTANCE hInstance;
33-
/*0079D980*/ static char dk2HomeDir[MAX_PATH];
34-
public:
35-
/*005B2DA0*/ static void __cdecl setHInstance(HINSTANCE hInst);
36-
/*005B2D90*/ static HINSTANCE __cdecl getHInstance();
37-
// msvc is importing data as functions. So we follow import jump to get actual data address
38-
inline static HINSTANCE *getHInstancePtr() { return (HINSTANCE *) funptr<&hInstance>(); }
39-
40-
/*005B2E50*/ static void __cdecl setAppExitStatus(bool shouldExit);
41-
/*005B2E40*/ static bool __cdecl isAppExitStatusSet();
42-
43-
inline static char *getDk2HomeDir() { return (char *) funptr<&dk2HomeDir>(); }
44-
45-
};
46-
4727
// use BOOL instead of bool! sizeof(bool) == 1 sizeof(BOOL) == 4
4828
/*00557FD0*/ BOOL __stdcall isOsVersionGE(int maxVersion, int minVersion, uint16_t CSDVersion);
4929

include/dk2/dd.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@
1010

1111
namespace dk2 {
1212

13-
class dd {
14-
/*0079D020*/ static HWND hWnd;
15-
/*0079D3D0*/ static LPDIRECTDRAW lpDD;
16-
/*0079D3F0*/ static LPDIRECTDRAW lpSurfaceDD;
17-
18-
public:
19-
/*005B2DC0*/ static void __cdecl setHWindow(HWND hWnd);
20-
/*005B2DB0*/ static HWND __cdecl getHWindow();
21-
inline static HWND *getHWindowPtr() { return (HWND *) funptr<&hWnd>(); }
22-
23-
inline static LPDIRECTDRAW *getDD() { return (LPDIRECTDRAW *) funptr<&lpDD>(); }
24-
inline static LPDIRECTDRAW *getSurfaceDD() { return (LPDIRECTDRAW *) funptr<&lpSurfaceDD>(); }
25-
/*005B5410*/ static void __cdecl setSurfaceDD(LPDIRECTDRAW lpDD);
26-
27-
/*005B4390*/ static status_t &__cdecl init(status_t &status, DWORD width, DWORD height, DWORD displayBitness, DWORD surfFlags, LPPALETTEENTRY palette);
28-
/*005B4230*/ static void __cdecl destroy();
29-
30-
};
31-
3213
struct MyDdSurface{
3314
uint32_t field_0;
3415
uint32_t field_4;

include/dk2/globals.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Created by DiaLight on 27.12.2022.
3+
//
4+
5+
#ifndef EMBER_GLOBALS_H
6+
#define EMBER_GLOBALS_H
7+
8+
#include <api/imports.h>
9+
10+
namespace dk2 {
11+
12+
__analysis_noreturn
13+
/*00638440*/ void __cdecl start();
14+
/*005A5DA0*/ int __cdecl main(int argc, char *argv[]);
15+
/*005B74A0*/ void __cdecl resolveDk2HomeDir();
16+
17+
class globals {
18+
/*0079D01C*/ static HINSTANCE hInstance;
19+
/*0079D980*/ static char dk2HomeDir[MAX_PATH];
20+
public:
21+
/*005B2DA0*/ static void __cdecl setHInstance(HINSTANCE hInst);
22+
/*005B2D90*/ static HINSTANCE __cdecl getHInstance();
23+
// msvc is importing data as functions. So we follow import jump to get actual data address
24+
inline static HINSTANCE *getHInstancePtr() { return (HINSTANCE *) funptr<&hInstance>(); }
25+
26+
/*005B2E50*/ static void __cdecl setAppExitStatus(bool shouldExit);
27+
/*005B2E40*/ static bool __cdecl isAppExitStatusSet();
28+
29+
inline static char *getDk2HomeDir() { return (char *) funptr<&dk2HomeDir>(); }
30+
31+
};
32+
33+
using status_t = int;
34+
35+
class dd {
36+
/*0079D020*/ static HWND hWnd;
37+
/*0079D3D0*/ static LPDIRECTDRAW lpDD;
38+
/*0079D3F0*/ static LPDIRECTDRAW lpSurfaceDD;
39+
40+
public:
41+
/*005B2DC0*/ static void __cdecl setHWindow(HWND hWnd);
42+
/*005B2DB0*/ static HWND __cdecl getHWindow();
43+
inline static HWND *getHWindowPtr() { return (HWND *) funptr<&hWnd>(); }
44+
45+
inline static LPDIRECTDRAW *getDD() { return (LPDIRECTDRAW *) funptr<&lpDD>(); }
46+
inline static LPDIRECTDRAW *getSurfaceDD() { return (LPDIRECTDRAW *) funptr<&lpSurfaceDD>(); }
47+
/*005B5410*/ static void __cdecl setSurfaceDD(LPDIRECTDRAW lpDD);
48+
49+
/*005B4390*/ static status_t &__cdecl init(status_t &status, DWORD width, DWORD height, DWORD displayBitness, DWORD surfFlags, LPPALETTEENTRY palette);
50+
/*005B4230*/ static void __cdecl destroy();
51+
52+
};
53+
54+
}
55+
56+
#endif //EMBER_GLOBALS_H

0 commit comments

Comments
 (0)