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

Commit 7f4a8f5

Browse files
committed
breaking game resolution limits
1 parent a841e7d commit 7f4a8f5

39 files changed

+14676
-2983
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ fabric.properties
7979
# Ember project
8080
/build
8181
dev.h
82+
/dev

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,23 @@ set(SOURCES
9898
api/Buf.cpp
9999
api/patch.cpp
100100
patches/reduce_title_screen_time.cpp
101-
patches/force_windowed_mode.cpp
101+
patches/control_windowed_mode.cpp
102102
patches/add_win10_support.cpp
103103
patches/mouse_dinput/fix_relative_mouse_data.cpp
104104
patches/mouse_dinput/replace_mouse_dinput_to_user32.cpp
105105
patches/mouse_user32/fix_mouse_pos_on_resized_window.cpp
106106
patches/fix_close_window.cpp
107107
patches/use_cwd_as_dk2_home_dir.cpp
108+
patches/screen_resolution/patch_menu_resolution.cpp
109+
patches/screen_resolution/patch_game_resolution.cpp
110+
patches/screen_resolution/expand_surf_idx_array.cpp
111+
patches/screen_resolution/expand_surf_hash_list.cpp
112+
patches/screen_resolution/patch_draw_buffer_extra_size.cpp
113+
patches/screen_resolution/replace_custom_heap.cpp
114+
patches/screen_resolution/dpi_aware.cpp
115+
reimpl/SurfHashList__probablySort.cpp
116+
reimpl/draw3dScene.cpp
117+
stdex.cpp
108118
)
109119
if(REVERSE_MODE)
110120
enable_language(ASM_MASM)

api.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <ios>
1919
#include <io.h>
2020
#include <fcntl.h>
21+
#include <stdex.h>
2122

2223
std::wstring g_curExeDir;
2324

@@ -223,8 +224,17 @@ namespace api {
223224
HookHandle *allReadyToStart = nullptr;
224225
std::vector<std::function<void()>> ALL_READY_TO_START;
225226

227+
std::vector<std::string> EMBER_ARGS;
228+
std::vector<std::string> DK2_ARGS;
229+
226230
int __cdecl proxy_main(int argc, char *argv[]) {
227231
int exitCode = -1;
232+
argc = DK2_ARGS.size();
233+
std::vector<char *> args;
234+
args.reserve(DK2_ARGS.size());
235+
for(auto &arg : DK2_ARGS) args.push_back((char *) arg.c_str());
236+
args.push_back(NULL);
237+
argv = &*args.begin();
228238

229239
for(auto &F : BEFORE_MAIN) {
230240
exitCode = F(argc, argv);
@@ -237,6 +247,24 @@ namespace api {
237247
return exitCode;
238248
}
239249

250+
std::string findArgValue(const std::string &name) {
251+
for(auto &arg : EMBER_ARGS) {
252+
if(arg.starts_with(name + "=")) {
253+
return arg.substr(name.length() + 1);
254+
}
255+
}
256+
return std::string();
257+
}
258+
259+
bool hasFlag(const std::string &name) {
260+
for(auto &arg : EMBER_ARGS) {
261+
if(arg == name) {
262+
return true;
263+
}
264+
}
265+
return false;
266+
}
267+
240268
bool initialize() {
241269
#ifdef REVERSE_MODE
242270
AllocConsole();
@@ -257,6 +285,25 @@ namespace api {
257285
printf("bootstrap patcher base: %p\n", g_bootstrap_patcher);
258286
printf("dk2 base: %p\n", dk2_base);
259287

288+
int nArgs;
289+
LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
290+
if(szArglist == NULL) {
291+
printf("CommandLineToArgvW failed\n");
292+
return false;
293+
}
294+
for(int i = 0; i < nArgs; i++) {
295+
std::wstring warg(szArglist[i]);
296+
std::string arg = utf8_encode(warg);
297+
printf("%d: %ws\n", i, szArglist[i]);
298+
if(i != 0 && arg.starts_with("-ember:")) {
299+
arg = arg.substr(7);
300+
EMBER_ARGS.push_back(arg);
301+
} else DK2_ARGS.push_back(arg);
302+
}
303+
304+
305+
LocalFree(szArglist);
306+
260307
g_curExeDir.resize(MAX_PATH, L'\0');
261308
if(GetModuleFileNameW(g_bootstrap_patcher, &*g_curExeDir.begin(), MAX_PATH) == 0) return false;
262309
wchar_t *p1 = wcsrchr(&*g_curExeDir.begin(), '/');

api/stacktrace.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <sstream>
1515
#include <iomanip>
1616

17+
#define hex32(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(8) << ((uint32_t) val) << std::dec
18+
#define hex16(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(4) << ((uint16_t) val) << std::dec
19+
#define hex8(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(2) << ((uint8_t) val) << std::dec
20+
1721
enum SpOpKind {
1822
SP_Invalid,
1923
SP,
@@ -384,9 +388,6 @@ class LoadedModules {
384388
}
385389
};
386390

387-
#define hex32(val) std::uppercase << std::setfill(L'0') << std::setw(8) << std::hex << (val) << std::dec
388-
#define hex16(val) std::uppercase << std::setfill(L'0') << std::setw(4) << std::hex << (val) << std::dec
389-
390391
bool visit_dk2_frame(CONTEXT *ctx, StackLimits &limits, std::wstringstream &ss) {
391392
uint32_t rva = (uint8_t *) ctx->Eip - dk2_base;
392393
auto it = stacktrace::find_le(rva);

include/api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ namespace api {
4949
extern std::vector<std::function<void(int argc, char *argv[], int &exitCode)>> AFTER_MAIN;
5050
extern std::vector<std::function<void()>> ALL_READY_TO_START;
5151

52+
extern std::vector<std::string> EMBER_ARGS;
53+
extern std::vector<std::string> DK2_ARGS;
54+
5255
bool initialize();
5356

57+
std::string findArgValue(const std::string &name);
58+
bool hasFlag(const std::string &name);
59+
5460
}
5561

5662
bool replaceXrefs(uint8_t *fun, void *proxy);
5763

64+
std::vector<std::string> split(const std::string &s, char separator);
65+
5866
#endif //EMBER_API_H

include/api/patch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <vector>
99
#include <functional>
1010

11+
void write_jump(uint8_t *pos, void *to);
12+
void write_call(uint8_t *pos, void *to);
13+
1114
class PatchBuilder {
1215
std::vector<uint8_t> proxy;
1316
public:

include/dk2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ namespace dk2 {
432432
int field_F4D;
433433
__int16 field_F51;
434434

435-
/*005581B0*/ void prepareScreen(int dwWidth, int dwHeight, int dwRGBBitCount, int isWindowed, int a6, int a7);
435+
/*005581B0*/ int prepareScreen(int dwWidth, int dwHeight, int dwRGBBitCount, int isWindowed, int a6, int a7);
436436
/*005595C0*/ void debugMsg(char *format, ...);
437437

438438
};

include/dk2/CFrontEndComponent.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ namespace dk2 {
203203
BYTE gap_61A4[336];
204204
AABB aabb15_x8[8];
205205
BYTE gap6374[669];
206-
MySurface surf61_x3[3];
207-
MySurface surf62_x3[3];
206+
MySurface surf61_x3_applyBtn[3];
207+
MySurface surf62_x3_exitBtn[3];
208208
BYTE gap_6701[4];
209209
BYTE field_6705;
210210
BYTE field_6706;
@@ -223,7 +223,7 @@ namespace dk2 {
223223
AABB aabb16_x16x30x6[16][30][6];
224224
MySurface surf64_x16x30x6[16][30][6];
225225
DWORD cglow_obj_start;
226-
MySurface surf65;
226+
MySurface surf65_btnRenderOut;
227227
MySurface surf66_x16[16];
228228
AABB aabb17_x16x30[16][30];
229229
BYTE gap2FE0D[1292];
@@ -295,10 +295,20 @@ namespace dk2 {
295295
int f311F6;
296296

297297
/*005340F0*/ void showTitleScreen();
298+
299+
/*005306F0*/ static int __cdecl execute(unsigned int idx, int command, CFrontEndComponent *obj);
300+
/*0052FAF0*/ static int __cdecl onKeyboardActionWithCtrl(
301+
int keyCode,
302+
int isPressed,
303+
int controlKeyFlags,
304+
CFrontEndComponent *frontend);
305+
298306
};
299307
#pragma pack(pop)
300308
static_assert(sizeof(CFrontEndComponent) == 0x311FA);
301309

302310
}
311+
// ?CFrontEndComponent_static_onKeyboardActionWithCtrl@@YAHHHHPAVCFrontEndComponent@dk2@@@Z
312+
// ?onKeyboardActionWithCtrl@CFrontEndComponent@dk2@@SAHHHHPAV12@@Z
303313

304314
#endif //EMBER_CFRONTENDCOMPONENT_H

include/dk2/gui.h

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,14 @@
66
#define EMBER_GUI_H
77

88
#include <dk2/utils.h>
9+
#include <dk2/gui_elements.h>
910

1011
namespace dk2 {
1112

1213
struct CWindow;
1314
struct CGuiManager;
1415
struct CDefaultPlayerInterface;
1516

16-
struct CGadget { // vft=0066ED14
17-
struct vtbl_t {
18-
void (__fastcall *scalar_deleting_destructor)(void *_this, void *edx, bool del);
19-
};
20-
inline vtbl_t *vtbl() { return *(vtbl_t **) this; }
21-
virtual ~CGadget();
22-
23-
int x_offs;
24-
int y_offs;
25-
int width;
26-
int height;
27-
Area2i pos;
28-
29-
};
30-
static_assert(sizeof(CGadget) == 0x24);
31-
32-
#pragma pack(push, 1)
33-
struct CButton : public CGadget {
34-
DWORD field_20;
35-
DWORD f24_renderFun;
36-
DWORD field_28;
37-
DWORD f2C_textId;
38-
DWORD f30_idxLow;
39-
int f34_idxHigh;
40-
DWORD f38_unkIdx;
41-
BYTE field_3C;
42-
DWORD field_3D;
43-
DWORD field_41;
44-
DWORD f45_containsCursor;
45-
int f49_actionFun;
46-
int field_4D;
47-
CWindow *f51_pWindow;
48-
DWORD field_55;
49-
DWORD field_59;
50-
DWORD f5D_isVisible;
51-
WORD f61_posFlags;
52-
DWORD field_63;
53-
DWORD field_67;
54-
DWORD field_6B;
55-
BYTE f6F_kind;
56-
DWORD f70_;
57-
DWORD f74_prev;
58-
CButton *f78_next;
59-
virtual ~CButton();
60-
61-
};
62-
#pragma pack(pop)
63-
static_assert(sizeof(CButton) == 0x80);
64-
6517
#pragma pack(push, 1)
6618
struct ButtonCfg {
6719
char f0_kind;
@@ -72,7 +24,7 @@ namespace dk2 {
7224
DWORD field_E;
7325
DWORD field_12;
7426
DWORD field_16;
75-
DWORD field_1A;
27+
DWORD f1A__actionId;
7628
WORD f1E_posFlags;
7729
__int16 f20_x;
7830
__int16 f22_y;
@@ -233,11 +185,11 @@ namespace dk2 {
233185
};
234186

235187
class gui_globals {
236-
/*006AE4E0*/ static WindowCfg *view006AE4E0[];
237-
/*00693EF8*/ static WindowCfg *view00693EF8[];
188+
/*006AE4E0*/ static WindowCfg *mainView[];
189+
/*00693EF8*/ static WindowCfg *gameView[];
238190
public:
239-
inline static WindowCfg **getMainGuiConfig() { return (WindowCfg **) funptr<&view006AE4E0>(); }
240-
inline static WindowCfg **getInGameGuiConfig() { return (WindowCfg **) funptr<&view00693EF8>(); }
191+
inline static WindowCfg **getMainGuiConfig() { return (WindowCfg **) funptr<&mainView>(); }
192+
inline static WindowCfg **getInGameGuiConfig() { return (WindowCfg **) funptr<&gameView>(); }
241193

242194
static WindowCfg *getMainWindowCfg(MainGuiId id) {
243195
auto *pos = dk2::gui_globals::getMainGuiConfig();

include/dk2/gui_elements.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// Created by DiaLight on 24.09.2022.
3+
//
4+
5+
#ifndef EMBER_GUI_ELEMENTS_H
6+
#define EMBER_GUI_ELEMENTS_H
7+
8+
namespace dk2 {
9+
10+
struct CWindow;
11+
struct CGuiManager;
12+
struct CDefaultPlayerInterface;
13+
struct CFrontEndComponent;
14+
15+
struct CGadget { // vft=0066ED14
16+
struct vtbl_t {
17+
void (__fastcall *scalar_deleting_destructor)(void *_this, void *edx, bool del);
18+
};
19+
inline vtbl_t *vtbl() { return *(vtbl_t **) this; }
20+
virtual ~CGadget();
21+
22+
int x_offs;
23+
int y_offs;
24+
int width;
25+
int height;
26+
Area2i pos;
27+
28+
};
29+
static_assert(sizeof(CGadget) == 0x24);
30+
31+
#pragma pack(push, 1)
32+
struct CButton : public CGadget {
33+
DWORD field_20;
34+
DWORD f24_renderFun;
35+
DWORD field_28;
36+
DWORD f2C_textId;
37+
DWORD f30_idxLow;
38+
int f34_idxHigh;
39+
DWORD f38_unkIdx;
40+
BYTE field_3C;
41+
DWORD field_3D;
42+
DWORD field_41;
43+
DWORD f45_containsCursor;
44+
void *f49_actionFun;
45+
int field_4D;
46+
CWindow *f51_pWindow;
47+
DWORD field_55;
48+
DWORD field_59;
49+
DWORD f5D_isVisible;
50+
WORD f61_posFlags;
51+
DWORD field_63;
52+
DWORD field_67;
53+
DWORD field_6B;
54+
BYTE f6F_kind;
55+
DWORD f70_;
56+
DWORD f74_prev;
57+
CButton *f78_next;
58+
virtual ~CButton();
59+
60+
};
61+
#pragma pack(pop)
62+
static_assert(sizeof(CButton) == 0x80);
63+
64+
#pragma pack(push, 1)
65+
struct CClickButton : public CButton {
66+
67+
virtual ~CClickButton();
68+
69+
static void __cdecl renderExitBtn(dk2::CClickButton *btn, dk2::CFrontEndComponent *frontend);
70+
static void __cdecl renderApplyBtn(dk2::CClickButton *btn, dk2::CFrontEndComponent *frontend);
71+
};
72+
#pragma pack(pop)
73+
static_assert(sizeof(CClickButton) == 0x80);
74+
75+
}
76+
77+
#endif //EMBER_GUI_ELEMENTS_H

0 commit comments

Comments
 (0)