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

Commit fd3617d

Browse files
committed
added ability to zoom with mouse wheel
added movement fast bind to wasd model
1 parent fbbe361 commit fd3617d

File tree

12 files changed

+359
-32
lines changed

12 files changed

+359
-32
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ set(SOURCES
122122
patches/hires_textures/expand_size_hash_table.cpp
123123
patches/fix_usage_unitialized_structure.cpp
124124
patches/unlimited_zoom_hack.cpp
125+
patches/use_wheel_to_zoom.cpp
125126
reimpl/SurfHashList__probablySort.cpp
126127
reimpl/draw3dScene.cpp
127128
tools/unpack_texture_cache.cpp

include/patches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace patch {
2929
bool expand_size_hash_table();
3030
bool fix_usage_uninitialized_structure();
3131
bool unlimited_zoom_hack();
32+
bool use_wheel_to_zoom();
3233

3334
}
3435

launcher/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
string (REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
33
string (REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
44
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS-")
5+
56
add_executable(launcher WIN32
67
launcher.cpp
78
layout.cpp
@@ -10,6 +11,7 @@ add_executable(launcher WIN32
1011
status.cpp
1112
utils.cpp
1213
dd_modes.cpp
14+
keyboard_bind.cpp
1315
)
1416
target_include_directories(launcher PRIVATE include)
1517
target_link_libraries(launcher Shcore Ddraw win32_gui_layout)

launcher/include/keyboard_bind.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Created by DiaLight on 16.01.2023.
3+
//
4+
5+
#ifndef EMBER_KEYBOARD_BIND_H
6+
#define EMBER_KEYBOARD_BIND_H
7+
8+
bool bindWasd();
9+
10+
#endif //EMBER_KEYBOARD_BIND_H

launcher/include/layout.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ extern gui::edit_elem_t TextField;
2323
extern gui::button_elem_t StartBtn;
2424
extern gui::combobox_elem_t MenuModesCombo;
2525
extern gui::combobox_elem_t GameModesCombo;
26-
extern gui::button_elem_t DPIBtn;
27-
extern gui::button_elem_t FullscreenBtn;
28-
extern gui::button_elem_t UnlimitedZoomBtn;
26+
extern gui::button_elem_t DPIChk;
27+
extern gui::button_elem_t FullscreenChk;
28+
extern gui::button_elem_t UnlimitedZoomChk;
29+
extern gui::button_elem_t Wheel2ZoomChk;
30+
extern gui::button_elem_t BindWasdBtn;
31+
2932
extern gui::button_elem_t ResExtractBtn;
3033
extern gui::button_elem_t ResOpenBtn;
31-
extern gui::button_elem_t ResRedirectBtn;
34+
extern gui::button_elem_t ResRedirectChk;
3235

3336
void launcher_layout(HWND hwnd, int width, int height, bool reset=false);
3437

launcher/include/registry.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef EMBER_REGISTRY_H
66
#define EMBER_REGISTRY_H
77

8+
#include <string>
9+
#include <vector>
810

911
bool persistence_getStr(const std::wstring &name, std::wstring &value);
1012
bool persistence_setStr(const std::wstring &name, const std::wstring &value);
@@ -14,4 +16,10 @@ bool persistence_setDword(const std::wstring &name, DWORD value);
1416
void saveDk2Path(std::wstring &dk2Dir);
1517
void loadDk2Path(std::wstring &dk2Dir);
1618

19+
bool dk2Cfg_getDword(const std::wstring &section, const std::wstring &name, DWORD &value);
20+
bool dk2Cfg_setDword(const std::wstring &section, const std::wstring &name, DWORD value);
21+
22+
bool dk2Cfg_getBytes(const std::wstring &section, const std::wstring &name, std::vector<char> &value);
23+
bool dk2Cfg_setBytes(const std::wstring &section, const std::wstring &name, const std::vector<char> &value);
24+
1725
#endif //EMBER_REGISTRY_H

launcher/keyboard_bind.cpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//
2+
// Created by DiaLight on 16.01.2023.
3+
//
4+
#include <Windows.h>
5+
#include <registry.h>
6+
#include <status.h>
7+
#include "dinput.h"
8+
#include <vector>
9+
#include <map>
10+
11+
enum Dk2Key {
12+
Key_ZoomIn = 14, // home
13+
Key_ZoomOut = 15, // end
14+
Key_MoveUp = 16, // up
15+
Key_MoveDown = 17, // down
16+
Key_MoveLeft = 18, // left
17+
Key_MoveRight = 19, // right
18+
19+
Key_RotateLeft = 22, // del
20+
Key_RotateRight = 23, // pgdn
21+
22+
Key_PitchUp = 47, // ctrl + home
23+
Key_PitchDown = 48, // ctrl + end
24+
25+
Key_RollLeft = 49, // ctrl + Insert
26+
Key_RollRight = 50, // ctrl + delete
27+
28+
Key_YawLeft = 51, // ctrl + pgup
29+
Key_YawRight = 52, // ctrl + pgdn
30+
};
31+
32+
struct DxKeyEntry {
33+
uint32_t dxKey;
34+
uint32_t modifierFlags;
35+
};
36+
37+
std::map<int, DxKeyEntry> defaultKeyTable = {
38+
{1, {0xD2, 0}},
39+
{2, {0x52, 0}},
40+
{3, {0x39, 0}},
41+
{4, {0x9D, 0}},
42+
{5, {0x36, 0}},
43+
{6, {2, 0}},
44+
{7, {3, 0}},
45+
{8, {4, 0}},
46+
{9, {5, 0}},
47+
{10, {6, 0}},
48+
{11, {7, 0}},
49+
{12, {8, 0}},
50+
{13, {0x22, 2}},
51+
{Key_ZoomIn, {DIK_HOME, 0}},
52+
{Key_ZoomOut, {DIK_END, 0}},
53+
{Key_MoveUp, {DIK_UP, 0}},
54+
{Key_MoveDown, {DIK_DOWN, 0}},
55+
{Key_MoveLeft, {DIK_LEFT, 0}},
56+
{Key_MoveRight, {DIK_RIGHT, 0}},
57+
{20, {0x1D, 0}},
58+
{21, {0x2A, 0}},
59+
{Key_RotateLeft, {DIK_DELETE, 0}},
60+
{Key_RotateRight, {DIK_PGDN, 0}},
61+
{24, {1, 0}},
62+
{25, {0xB7, 0}},
63+
{26, {0xC9, 0}},
64+
{27, {0xF, 0}},
65+
{28, {0xD, 0}}, // Japanese Keyboard case f0_dxKey=0x90
66+
{29, {0xC, 0}},
67+
{30, {0x3B, 0}},
68+
{31, {0x3C, 0}},
69+
{32, {0x3D, 0}},
70+
{33, {0x3E, 0}},
71+
{34, {0x3F, 0}},
72+
{35, {0x40, 0}},
73+
{36, {0x1E, 0}},
74+
{37, {0x21, 0}},
75+
{38, {0x22, 0}},
76+
{39, {0x23, 0}},
77+
{40, {0x17, 0}},
78+
{41, {0x32, 0}},
79+
{42, {0x19, 0}},
80+
{43, {0x2D, 0}},
81+
{44, {0x2C, 0}},
82+
{45, {0x34, 1}},
83+
{46, {0x33, 1}},
84+
{Key_PitchUp, {DIK_HOME, 2}},
85+
{Key_PitchDown, {DIK_END, 2}},
86+
{Key_RollLeft, {DIK_INSERT, 2}},
87+
{Key_RollRight, {DIK_DELETE, 2}},
88+
{Key_YawLeft, {DIK_PGUP, 2}},
89+
{Key_YawRight, {DIK_PGDN, 2}},
90+
{53, {0x34, 2}},
91+
{54, {0x33, 2}},
92+
{56, {0x1F, 2}},
93+
{55, {0x26, 2}},
94+
{57, {0x13, 2}},
95+
{58, {0x1E, 4}},
96+
{59, {2, 4}},
97+
{60, {3, 4}},
98+
{61, {4, 4}},
99+
{62, {5, 4}},
100+
{63, {0x19, 2}},
101+
};
102+
103+
bool bindWasd() {
104+
std::vector<char> buf;
105+
if(!dk2Cfg_getBytes(L"Player", L"Key Table", buf)) {
106+
printStatus("[ERROR]: failed to load keymap");
107+
return false;
108+
}
109+
size_t count = buf.size() / sizeof(DxKeyEntry);
110+
auto *items = (DxKeyEntry *) buf.data();
111+
// for (int j = 0; j < count; ++j) {
112+
// auto &it = items[j];
113+
// printStatus("%d: %X -> %X", j, it.modifierFlags, it.dxKey);
114+
// }
115+
items[Key_MoveUp].dxKey = DIK_W;
116+
items[Key_MoveLeft].dxKey = DIK_A;
117+
items[Key_MoveDown].dxKey = DIK_S;
118+
items[Key_MoveRight].dxKey = DIK_D;
119+
items[Key_RotateLeft].dxKey = DIK_E;
120+
items[Key_RotateRight].dxKey = DIK_Q;
121+
122+
if(!dk2Cfg_setBytes(L"Player", L"Key Table", buf)) {
123+
printStatus("[ERROR]: failed to save keymap");
124+
return false;
125+
}
126+
printStatus("keymap updated successfully");
127+
return true;
128+
}

launcher/launcher.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "utils.h"
2121
#include "launcher.h"
2222
#include "status.h"
23+
#include "keyboard_bind.h"
2324

2425
std::wstring g_dk2Dir;
2526
std::wstring g_curExeDir;
@@ -187,33 +188,41 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
187188
{
188189
DWORD isFullscreen = 0;
189190
if(persistence_getDword(L"fullscreen", isFullscreen)) {
190-
FullscreenBtn.setCheck((int) isFullscreen);
191+
FullscreenChk.setCheck((int) isFullscreen);
191192
} else {
192-
FullscreenBtn.setCheck(BST_INDETERMINATE);
193+
FullscreenChk.setCheck(BST_INDETERMINATE);
193194
}
194195
}
195196
{
196197
DWORD check = 0;
197198
if(persistence_getDword(L"dpi_aware", check)) {
198-
DPIBtn.setCheck((int) check);
199+
DPIChk.setCheck((int) check);
199200
} else {
200-
DPIBtn.setCheck(BST_UNCHECKED);
201+
DPIChk.setCheck(BST_UNCHECKED);
201202
}
202203
}
203204
{
204205
DWORD check = 0;
205206
if(persistence_getDword(L"unlimited_zoom", check)) {
206-
UnlimitedZoomBtn.setCheck((int) check);
207+
UnlimitedZoomChk.setCheck((int) check);
207208
} else {
208-
UnlimitedZoomBtn.setCheck(BST_UNCHECKED);
209+
UnlimitedZoomChk.setCheck(BST_UNCHECKED);
210+
}
211+
}
212+
{
213+
DWORD check = 0;
214+
if(persistence_getDword(L"wheel2zoom", check)) {
215+
Wheel2ZoomChk.setCheck((int) check);
216+
} else {
217+
Wheel2ZoomChk.setCheck(BST_UNCHECKED);
209218
}
210219
}
211220
{
212221
DWORD check = 0;
213222
if(persistence_getDword(L"redirect_textures", check)) {
214-
ResRedirectBtn.setCheck((int) check);
223+
ResRedirectChk.setCheck((int) check);
215224
} else {
216-
ResRedirectBtn.setCheck(BST_UNCHECKED);
225+
ResRedirectChk.setCheck(BST_UNCHECKED);
217226
}
218227
}
219228
std::wstring menu_resolution;
@@ -280,19 +289,23 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
280289
wss << L'\"' << g_curExeDir << L"/bootstrap_patcher.exe" << L'\"';
281290
wss << " -32BITEVERYTHING";
282291
int check;
283-
check = DPIBtn.getCheck();
292+
check = DPIChk.getCheck();
284293
if(check == BST_CHECKED) {
285294
wss << " -ember:dpi_aware";
286295
}
287-
check = UnlimitedZoomBtn.getCheck();
296+
check = UnlimitedZoomChk.getCheck();
288297
if(check == BST_CHECKED) {
289298
wss << " -ember:unlimited_zoom";
290299
}
291-
check = ResRedirectBtn.getCheck();
300+
check = Wheel2ZoomChk.getCheck();
301+
if(check == BST_CHECKED) {
302+
wss << " -ember:wheel2zoom";
303+
}
304+
check = ResRedirectChk.getCheck();
292305
if(check == BST_CHECKED) {
293306
wss << " -ember:redirect_textures";
294307
}
295-
check = FullscreenBtn.getCheck();
308+
check = FullscreenChk.getCheck();
296309
if(check != BST_INDETERMINATE) {
297310
wss << " -ember:fullscreen=";
298311
wss << (check == BST_CHECKED ? "true" : "false");
@@ -330,11 +343,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
330343
std::wstringstream wss;
331344
wss << L'\"' << g_curExeDir << L"/bootstrap_patcher.exe" << L'\"';
332345
wss << " -32BITEVERYTHING";
333-
int check = DPIBtn.getCheck();
346+
int check = DPIChk.getCheck();
334347
if(check == BST_CHECKED) {
335348
wss << " -ember:dpi_aware";
336349
}
337-
check = FullscreenBtn.getCheck();
350+
check = FullscreenChk.getCheck();
338351
if(check != BST_INDETERMINATE) {
339352
wss << " -ember:fullscreen=";
340353
wss << (check == BST_CHECKED ? "true" : "false");
@@ -375,6 +388,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
375388
std::wstring path = ss.str();
376389
std::filesystem::create_directories(path);
377390
ShellExecuteW(NULL, L"open", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
391+
} else if (hm == BindWasdBtn.id) {
392+
bindWasd();
393+
updateStatus();
394+
378395
// } else if (hm == GameModesCombo.id) {
379396
// if(HIWORD(wParam) == CBN_SELCHANGE) {
380397
// auto &mode = screenModeList[GameModesCombo.getCurSel()];
@@ -402,10 +419,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
402419
return (INT_PTR)(HBRUSH)BGColorBrush;
403420
}
404421
case WM_DESTROY:
405-
persistence_setDword(L"fullscreen", (DWORD) FullscreenBtn.getCheck());
406-
persistence_setDword(L"dpi_aware", (DWORD) DPIBtn.getCheck());
407-
persistence_setDword(L"unlimited_zoom", (DWORD) UnlimitedZoomBtn.getCheck());
408-
persistence_setDword(L"redirect_textures", (DWORD) ResRedirectBtn.getCheck());
422+
persistence_setDword(L"fullscreen", (DWORD) FullscreenChk.getCheck());
423+
persistence_setDword(L"dpi_aware", (DWORD) DPIChk.getCheck());
424+
persistence_setDword(L"unlimited_zoom", (DWORD) UnlimitedZoomChk.getCheck());
425+
persistence_setDword(L"wheel2zoom", (DWORD) Wheel2ZoomChk.getCheck());
426+
persistence_setDword(L"redirect_textures", (DWORD) ResRedirectChk.getCheck());
409427
{
410428
auto &mode = g_screenModeList[MenuModesCombo.getCurSel()];
411429
std::wstringstream ss;
@@ -508,3 +526,7 @@ int WINAPI WinMain(
508526

509527
return (int)msg.wParam;
510528
}
529+
530+
int main() {
531+
return WinMain(GetModuleHandleA(NULL), NULL, NULL, SW_NORMAL);
532+
}

launcher/layout.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ gui::label_elem_t MenuLabel(L"Menu resolution:", WS_VISIBLE | WS_TABSTOP);
1818
gui::combobox_elem_t MenuModesCombo(L"", CBS_DISABLENOSCROLL | CBS_DROPDOWNLIST | CBS_DROPDOWN | WS_OVERLAPPED | WS_VISIBLE);
1919
gui::label_elem_t GameLabel(L"Game resolution:", WS_VISIBLE | WS_TABSTOP);
2020
gui::combobox_elem_t GameModesCombo(L"", CBS_DISABLENOSCROLL | CBS_DROPDOWNLIST | CBS_DROPDOWN | WS_OVERLAPPED | WS_VISIBLE);
21-
gui::button_elem_t DPIBtn(L"DPI aware:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
22-
gui::button_elem_t FullscreenBtn(L"Fullscreen:", BS_CHECKBOX | BS_AUTO3STATE | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
23-
gui::button_elem_t UnlimitedZoomBtn(L"Unlimited zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
21+
gui::button_elem_t DPIChk(L"DPI aware:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
22+
gui::button_elem_t FullscreenChk(L"Fullscreen:", BS_CHECKBOX | BS_AUTO3STATE | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
23+
gui::button_elem_t UnlimitedZoomChk(L"Unlimited zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
24+
gui::button_elem_t Wheel2ZoomChk(L"Wheel to zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
25+
gui::button_elem_t BindWasdBtn(L"Bind WASD", WS_VISIBLE | WS_BORDER);
26+
2427

2528
gui::label_elem_t ResLabel(L"Resources:", WS_VISIBLE | WS_TABSTOP);
2629
gui::button_elem_t ResExtractBtn(L"Extract", WS_VISIBLE | WS_BORDER);
2730
gui::button_elem_t ResOpenBtn(L"Open", WS_VISIBLE | WS_BORDER);
28-
gui::button_elem_t ResRedirectBtn(L"Redirect resources:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
31+
gui::button_elem_t ResRedirectChk(L"Redirect resources:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
2932

3033

3134
struct : gui::layout_t {
@@ -54,11 +57,15 @@ struct : gui::layout_t {
5457
});
5558
gap(10);
5659
hor(-1, 20, [this] {
57-
visit(DPIBtn, 80, size.h);
60+
visit(DPIChk, 80, size.h);
61+
gap(20);
62+
visit(FullscreenChk, 80, size.h);
63+
gap(20);
64+
visit(UnlimitedZoomChk, 105, size.h);
5865
gap(20);
59-
visit(FullscreenBtn, 80, size.h);
66+
visit(Wheel2ZoomChk, 105, size.h);
6067
gap(20);
61-
visit(UnlimitedZoomBtn, 105, size.h);
68+
visit(BindWasdBtn, 70, size.h);
6269
});
6370
gap(10);
6471
hor(-1, 20, [this] {
@@ -68,7 +75,7 @@ struct : gui::layout_t {
6875
gap(20);
6976
visit(ResOpenBtn, 80, size.h);
7077
gap(20);
71-
visit(ResRedirectBtn, 130, size.h);
78+
visit(ResRedirectChk, 130, size.h);
7279
});
7380
// body end
7481

0 commit comments

Comments
 (0)