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

Commit

Permalink
breaking game resolution limits
Browse files Browse the repository at this point in the history
  • Loading branch information
DiaLight committed Dec 18, 2022
1 parent a841e7d commit 7f4a8f5
Show file tree
Hide file tree
Showing 39 changed files with 14,676 additions and 2,983 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ fabric.properties
# Ember project
/build
dev.h
/dev
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,23 @@ set(SOURCES
api/Buf.cpp
api/patch.cpp
patches/reduce_title_screen_time.cpp
patches/force_windowed_mode.cpp
patches/control_windowed_mode.cpp
patches/add_win10_support.cpp
patches/mouse_dinput/fix_relative_mouse_data.cpp
patches/mouse_dinput/replace_mouse_dinput_to_user32.cpp
patches/mouse_user32/fix_mouse_pos_on_resized_window.cpp
patches/fix_close_window.cpp
patches/use_cwd_as_dk2_home_dir.cpp
patches/screen_resolution/patch_menu_resolution.cpp
patches/screen_resolution/patch_game_resolution.cpp
patches/screen_resolution/expand_surf_idx_array.cpp
patches/screen_resolution/expand_surf_hash_list.cpp
patches/screen_resolution/patch_draw_buffer_extra_size.cpp
patches/screen_resolution/replace_custom_heap.cpp
patches/screen_resolution/dpi_aware.cpp
reimpl/SurfHashList__probablySort.cpp
reimpl/draw3dScene.cpp
stdex.cpp
)
if(REVERSE_MODE)
enable_language(ASM_MASM)
Expand Down
47 changes: 47 additions & 0 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ios>
#include <io.h>
#include <fcntl.h>
#include <stdex.h>

std::wstring g_curExeDir;

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

std::vector<std::string> EMBER_ARGS;
std::vector<std::string> DK2_ARGS;

int __cdecl proxy_main(int argc, char *argv[]) {
int exitCode = -1;
argc = DK2_ARGS.size();
std::vector<char *> args;
args.reserve(DK2_ARGS.size());
for(auto &arg : DK2_ARGS) args.push_back((char *) arg.c_str());
args.push_back(NULL);
argv = &*args.begin();

for(auto &F : BEFORE_MAIN) {
exitCode = F(argc, argv);
Expand All @@ -237,6 +247,24 @@ namespace api {
return exitCode;
}

std::string findArgValue(const std::string &name) {
for(auto &arg : EMBER_ARGS) {
if(arg.starts_with(name + "=")) {
return arg.substr(name.length() + 1);
}
}
return std::string();
}

bool hasFlag(const std::string &name) {
for(auto &arg : EMBER_ARGS) {
if(arg == name) {
return true;
}
}
return false;
}

bool initialize() {
#ifdef REVERSE_MODE
AllocConsole();
Expand All @@ -257,6 +285,25 @@ namespace api {
printf("bootstrap patcher base: %p\n", g_bootstrap_patcher);
printf("dk2 base: %p\n", dk2_base);

int nArgs;
LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if(szArglist == NULL) {
printf("CommandLineToArgvW failed\n");
return false;
}
for(int i = 0; i < nArgs; i++) {
std::wstring warg(szArglist[i]);
std::string arg = utf8_encode(warg);
printf("%d: %ws\n", i, szArglist[i]);
if(i != 0 && arg.starts_with("-ember:")) {
arg = arg.substr(7);
EMBER_ARGS.push_back(arg);
} else DK2_ARGS.push_back(arg);
}


LocalFree(szArglist);

g_curExeDir.resize(MAX_PATH, L'\0');
if(GetModuleFileNameW(g_bootstrap_patcher, &*g_curExeDir.begin(), MAX_PATH) == 0) return false;
wchar_t *p1 = wcsrchr(&*g_curExeDir.begin(), '/');
Expand Down
7 changes: 4 additions & 3 deletions api/stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <sstream>
#include <iomanip>

#define hex32(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(8) << ((uint32_t) val) << std::dec
#define hex16(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(4) << ((uint16_t) val) << std::dec
#define hex8(val) std::hex << std::uppercase << std::setfill(L'0') << std::setw(2) << ((uint8_t) val) << std::dec

enum SpOpKind {
SP_Invalid,
SP,
Expand Down Expand Up @@ -384,9 +388,6 @@ class LoadedModules {
}
};

#define hex32(val) std::uppercase << std::setfill(L'0') << std::setw(8) << std::hex << (val) << std::dec
#define hex16(val) std::uppercase << std::setfill(L'0') << std::setw(4) << std::hex << (val) << std::dec

bool visit_dk2_frame(CONTEXT *ctx, StackLimits &limits, std::wstringstream &ss) {
uint32_t rva = (uint8_t *) ctx->Eip - dk2_base;
auto it = stacktrace::find_le(rva);
Expand Down
8 changes: 8 additions & 0 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ namespace api {
extern std::vector<std::function<void(int argc, char *argv[], int &exitCode)>> AFTER_MAIN;
extern std::vector<std::function<void()>> ALL_READY_TO_START;

extern std::vector<std::string> EMBER_ARGS;
extern std::vector<std::string> DK2_ARGS;

bool initialize();

std::string findArgValue(const std::string &name);
bool hasFlag(const std::string &name);

}

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

std::vector<std::string> split(const std::string &s, char separator);

#endif //EMBER_API_H
3 changes: 3 additions & 0 deletions include/api/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <vector>
#include <functional>

void write_jump(uint8_t *pos, void *to);
void write_call(uint8_t *pos, void *to);

class PatchBuilder {
std::vector<uint8_t> proxy;
public:
Expand Down
2 changes: 1 addition & 1 deletion include/dk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ namespace dk2 {
int field_F4D;
__int16 field_F51;

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

};
Expand Down
16 changes: 13 additions & 3 deletions include/dk2/CFrontEndComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ namespace dk2 {
BYTE gap_61A4[336];
AABB aabb15_x8[8];
BYTE gap6374[669];
MySurface surf61_x3[3];
MySurface surf62_x3[3];
MySurface surf61_x3_applyBtn[3];
MySurface surf62_x3_exitBtn[3];
BYTE gap_6701[4];
BYTE field_6705;
BYTE field_6706;
Expand All @@ -223,7 +223,7 @@ namespace dk2 {
AABB aabb16_x16x30x6[16][30][6];
MySurface surf64_x16x30x6[16][30][6];
DWORD cglow_obj_start;
MySurface surf65;
MySurface surf65_btnRenderOut;
MySurface surf66_x16[16];
AABB aabb17_x16x30[16][30];
BYTE gap2FE0D[1292];
Expand Down Expand Up @@ -295,10 +295,20 @@ namespace dk2 {
int f311F6;

/*005340F0*/ void showTitleScreen();

/*005306F0*/ static int __cdecl execute(unsigned int idx, int command, CFrontEndComponent *obj);
/*0052FAF0*/ static int __cdecl onKeyboardActionWithCtrl(
int keyCode,
int isPressed,
int controlKeyFlags,
CFrontEndComponent *frontend);

};
#pragma pack(pop)
static_assert(sizeof(CFrontEndComponent) == 0x311FA);

}
// ?CFrontEndComponent_static_onKeyboardActionWithCtrl@@YAHHHHPAVCFrontEndComponent@dk2@@@Z
// ?onKeyboardActionWithCtrl@CFrontEndComponent@dk2@@SAHHHHPAV12@@Z

#endif //EMBER_CFRONTENDCOMPONENT_H
60 changes: 6 additions & 54 deletions include/dk2/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,14 @@
#define EMBER_GUI_H

#include <dk2/utils.h>
#include <dk2/gui_elements.h>

namespace dk2 {

struct CWindow;
struct CGuiManager;
struct CDefaultPlayerInterface;

struct CGadget { // vft=0066ED14
struct vtbl_t {
void (__fastcall *scalar_deleting_destructor)(void *_this, void *edx, bool del);
};
inline vtbl_t *vtbl() { return *(vtbl_t **) this; }
virtual ~CGadget();

int x_offs;
int y_offs;
int width;
int height;
Area2i pos;

};
static_assert(sizeof(CGadget) == 0x24);

#pragma pack(push, 1)
struct CButton : public CGadget {
DWORD field_20;
DWORD f24_renderFun;
DWORD field_28;
DWORD f2C_textId;
DWORD f30_idxLow;
int f34_idxHigh;
DWORD f38_unkIdx;
BYTE field_3C;
DWORD field_3D;
DWORD field_41;
DWORD f45_containsCursor;
int f49_actionFun;
int field_4D;
CWindow *f51_pWindow;
DWORD field_55;
DWORD field_59;
DWORD f5D_isVisible;
WORD f61_posFlags;
DWORD field_63;
DWORD field_67;
DWORD field_6B;
BYTE f6F_kind;
DWORD f70_;
DWORD f74_prev;
CButton *f78_next;
virtual ~CButton();

};
#pragma pack(pop)
static_assert(sizeof(CButton) == 0x80);

#pragma pack(push, 1)
struct ButtonCfg {
char f0_kind;
Expand All @@ -72,7 +24,7 @@ namespace dk2 {
DWORD field_E;
DWORD field_12;
DWORD field_16;
DWORD field_1A;
DWORD f1A__actionId;
WORD f1E_posFlags;
__int16 f20_x;
__int16 f22_y;
Expand Down Expand Up @@ -233,11 +185,11 @@ namespace dk2 {
};

class gui_globals {
/*006AE4E0*/ static WindowCfg *view006AE4E0[];
/*00693EF8*/ static WindowCfg *view00693EF8[];
/*006AE4E0*/ static WindowCfg *mainView[];
/*00693EF8*/ static WindowCfg *gameView[];
public:
inline static WindowCfg **getMainGuiConfig() { return (WindowCfg **) funptr<&view006AE4E0>(); }
inline static WindowCfg **getInGameGuiConfig() { return (WindowCfg **) funptr<&view00693EF8>(); }
inline static WindowCfg **getMainGuiConfig() { return (WindowCfg **) funptr<&mainView>(); }
inline static WindowCfg **getInGameGuiConfig() { return (WindowCfg **) funptr<&gameView>(); }

static WindowCfg *getMainWindowCfg(MainGuiId id) {
auto *pos = dk2::gui_globals::getMainGuiConfig();
Expand Down
77 changes: 77 additions & 0 deletions include/dk2/gui_elements.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Created by DiaLight on 24.09.2022.
//

#ifndef EMBER_GUI_ELEMENTS_H
#define EMBER_GUI_ELEMENTS_H

namespace dk2 {

struct CWindow;
struct CGuiManager;
struct CDefaultPlayerInterface;
struct CFrontEndComponent;

struct CGadget { // vft=0066ED14
struct vtbl_t {
void (__fastcall *scalar_deleting_destructor)(void *_this, void *edx, bool del);
};
inline vtbl_t *vtbl() { return *(vtbl_t **) this; }
virtual ~CGadget();

int x_offs;
int y_offs;
int width;
int height;
Area2i pos;

};
static_assert(sizeof(CGadget) == 0x24);

#pragma pack(push, 1)
struct CButton : public CGadget {
DWORD field_20;
DWORD f24_renderFun;
DWORD field_28;
DWORD f2C_textId;
DWORD f30_idxLow;
int f34_idxHigh;
DWORD f38_unkIdx;
BYTE field_3C;
DWORD field_3D;
DWORD field_41;
DWORD f45_containsCursor;
void *f49_actionFun;
int field_4D;
CWindow *f51_pWindow;
DWORD field_55;
DWORD field_59;
DWORD f5D_isVisible;
WORD f61_posFlags;
DWORD field_63;
DWORD field_67;
DWORD field_6B;
BYTE f6F_kind;
DWORD f70_;
DWORD f74_prev;
CButton *f78_next;
virtual ~CButton();

};
#pragma pack(pop)
static_assert(sizeof(CButton) == 0x80);

#pragma pack(push, 1)
struct CClickButton : public CButton {

virtual ~CClickButton();

static void __cdecl renderExitBtn(dk2::CClickButton *btn, dk2::CFrontEndComponent *frontend);
static void __cdecl renderApplyBtn(dk2::CClickButton *btn, dk2::CFrontEndComponent *frontend);
};
#pragma pack(pop)
static_assert(sizeof(CClickButton) == 0x80);

}

#endif //EMBER_GUI_ELEMENTS_H
Loading

0 comments on commit 7f4a8f5

Please sign in to comment.