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

Commit

Permalink
added ability to zoom with mouse wheel
Browse files Browse the repository at this point in the history
added movement fast bind to wasd model
  • Loading branch information
DiaLight committed Jan 16, 2023
1 parent fbbe361 commit fd3617d
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 32 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(SOURCES
patches/hires_textures/expand_size_hash_table.cpp
patches/fix_usage_unitialized_structure.cpp
patches/unlimited_zoom_hack.cpp
patches/use_wheel_to_zoom.cpp
reimpl/SurfHashList__probablySort.cpp
reimpl/draw3dScene.cpp
tools/unpack_texture_cache.cpp
Expand Down
1 change: 1 addition & 0 deletions include/patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace patch {
bool expand_size_hash_table();
bool fix_usage_uninitialized_structure();
bool unlimited_zoom_hack();
bool use_wheel_to_zoom();

}

Expand Down
2 changes: 2 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
string (REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string (REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS-")

add_executable(launcher WIN32
launcher.cpp
layout.cpp
Expand All @@ -10,6 +11,7 @@ add_executable(launcher WIN32
status.cpp
utils.cpp
dd_modes.cpp
keyboard_bind.cpp
)
target_include_directories(launcher PRIVATE include)
target_link_libraries(launcher Shcore Ddraw win32_gui_layout)
Expand Down
10 changes: 10 additions & 0 deletions launcher/include/keyboard_bind.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by DiaLight on 16.01.2023.
//

#ifndef EMBER_KEYBOARD_BIND_H
#define EMBER_KEYBOARD_BIND_H

bool bindWasd();

#endif //EMBER_KEYBOARD_BIND_H
11 changes: 7 additions & 4 deletions launcher/include/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ extern gui::edit_elem_t TextField;
extern gui::button_elem_t StartBtn;
extern gui::combobox_elem_t MenuModesCombo;
extern gui::combobox_elem_t GameModesCombo;
extern gui::button_elem_t DPIBtn;
extern gui::button_elem_t FullscreenBtn;
extern gui::button_elem_t UnlimitedZoomBtn;
extern gui::button_elem_t DPIChk;
extern gui::button_elem_t FullscreenChk;
extern gui::button_elem_t UnlimitedZoomChk;
extern gui::button_elem_t Wheel2ZoomChk;
extern gui::button_elem_t BindWasdBtn;

extern gui::button_elem_t ResExtractBtn;
extern gui::button_elem_t ResOpenBtn;
extern gui::button_elem_t ResRedirectBtn;
extern gui::button_elem_t ResRedirectChk;

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

Expand Down
8 changes: 8 additions & 0 deletions launcher/include/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef EMBER_REGISTRY_H
#define EMBER_REGISTRY_H

#include <string>
#include <vector>

bool persistence_getStr(const std::wstring &name, std::wstring &value);
bool persistence_setStr(const std::wstring &name, const std::wstring &value);
Expand All @@ -14,4 +16,10 @@ bool persistence_setDword(const std::wstring &name, DWORD value);
void saveDk2Path(std::wstring &dk2Dir);
void loadDk2Path(std::wstring &dk2Dir);

bool dk2Cfg_getDword(const std::wstring &section, const std::wstring &name, DWORD &value);
bool dk2Cfg_setDword(const std::wstring &section, const std::wstring &name, DWORD value);

bool dk2Cfg_getBytes(const std::wstring &section, const std::wstring &name, std::vector<char> &value);
bool dk2Cfg_setBytes(const std::wstring &section, const std::wstring &name, const std::vector<char> &value);

#endif //EMBER_REGISTRY_H
128 changes: 128 additions & 0 deletions launcher/keyboard_bind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Created by DiaLight on 16.01.2023.
//
#include <Windows.h>
#include <registry.h>
#include <status.h>
#include "dinput.h"
#include <vector>
#include <map>

enum Dk2Key {
Key_ZoomIn = 14, // home
Key_ZoomOut = 15, // end
Key_MoveUp = 16, // up
Key_MoveDown = 17, // down
Key_MoveLeft = 18, // left
Key_MoveRight = 19, // right

Key_RotateLeft = 22, // del
Key_RotateRight = 23, // pgdn

Key_PitchUp = 47, // ctrl + home
Key_PitchDown = 48, // ctrl + end

Key_RollLeft = 49, // ctrl + Insert
Key_RollRight = 50, // ctrl + delete

Key_YawLeft = 51, // ctrl + pgup
Key_YawRight = 52, // ctrl + pgdn
};

struct DxKeyEntry {
uint32_t dxKey;
uint32_t modifierFlags;
};

std::map<int, DxKeyEntry> defaultKeyTable = {
{1, {0xD2, 0}},
{2, {0x52, 0}},
{3, {0x39, 0}},
{4, {0x9D, 0}},
{5, {0x36, 0}},
{6, {2, 0}},
{7, {3, 0}},
{8, {4, 0}},
{9, {5, 0}},
{10, {6, 0}},
{11, {7, 0}},
{12, {8, 0}},
{13, {0x22, 2}},
{Key_ZoomIn, {DIK_HOME, 0}},
{Key_ZoomOut, {DIK_END, 0}},
{Key_MoveUp, {DIK_UP, 0}},
{Key_MoveDown, {DIK_DOWN, 0}},
{Key_MoveLeft, {DIK_LEFT, 0}},
{Key_MoveRight, {DIK_RIGHT, 0}},
{20, {0x1D, 0}},
{21, {0x2A, 0}},
{Key_RotateLeft, {DIK_DELETE, 0}},
{Key_RotateRight, {DIK_PGDN, 0}},
{24, {1, 0}},
{25, {0xB7, 0}},
{26, {0xC9, 0}},
{27, {0xF, 0}},
{28, {0xD, 0}}, // Japanese Keyboard case f0_dxKey=0x90
{29, {0xC, 0}},
{30, {0x3B, 0}},
{31, {0x3C, 0}},
{32, {0x3D, 0}},
{33, {0x3E, 0}},
{34, {0x3F, 0}},
{35, {0x40, 0}},
{36, {0x1E, 0}},
{37, {0x21, 0}},
{38, {0x22, 0}},
{39, {0x23, 0}},
{40, {0x17, 0}},
{41, {0x32, 0}},
{42, {0x19, 0}},
{43, {0x2D, 0}},
{44, {0x2C, 0}},
{45, {0x34, 1}},
{46, {0x33, 1}},
{Key_PitchUp, {DIK_HOME, 2}},
{Key_PitchDown, {DIK_END, 2}},
{Key_RollLeft, {DIK_INSERT, 2}},
{Key_RollRight, {DIK_DELETE, 2}},
{Key_YawLeft, {DIK_PGUP, 2}},
{Key_YawRight, {DIK_PGDN, 2}},
{53, {0x34, 2}},
{54, {0x33, 2}},
{56, {0x1F, 2}},
{55, {0x26, 2}},
{57, {0x13, 2}},
{58, {0x1E, 4}},
{59, {2, 4}},
{60, {3, 4}},
{61, {4, 4}},
{62, {5, 4}},
{63, {0x19, 2}},
};

bool bindWasd() {
std::vector<char> buf;
if(!dk2Cfg_getBytes(L"Player", L"Key Table", buf)) {
printStatus("[ERROR]: failed to load keymap");
return false;
}
size_t count = buf.size() / sizeof(DxKeyEntry);
auto *items = (DxKeyEntry *) buf.data();
// for (int j = 0; j < count; ++j) {
// auto &it = items[j];
// printStatus("%d: %X -> %X", j, it.modifierFlags, it.dxKey);
// }
items[Key_MoveUp].dxKey = DIK_W;
items[Key_MoveLeft].dxKey = DIK_A;
items[Key_MoveDown].dxKey = DIK_S;
items[Key_MoveRight].dxKey = DIK_D;
items[Key_RotateLeft].dxKey = DIK_E;
items[Key_RotateRight].dxKey = DIK_Q;

if(!dk2Cfg_setBytes(L"Player", L"Key Table", buf)) {
printStatus("[ERROR]: failed to save keymap");
return false;
}
printStatus("keymap updated successfully");
return true;
}
58 changes: 40 additions & 18 deletions launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "utils.h"
#include "launcher.h"
#include "status.h"
#include "keyboard_bind.h"

std::wstring g_dk2Dir;
std::wstring g_curExeDir;
Expand Down Expand Up @@ -187,33 +188,41 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
DWORD isFullscreen = 0;
if(persistence_getDword(L"fullscreen", isFullscreen)) {
FullscreenBtn.setCheck((int) isFullscreen);
FullscreenChk.setCheck((int) isFullscreen);
} else {
FullscreenBtn.setCheck(BST_INDETERMINATE);
FullscreenChk.setCheck(BST_INDETERMINATE);
}
}
{
DWORD check = 0;
if(persistence_getDword(L"dpi_aware", check)) {
DPIBtn.setCheck((int) check);
DPIChk.setCheck((int) check);
} else {
DPIBtn.setCheck(BST_UNCHECKED);
DPIChk.setCheck(BST_UNCHECKED);
}
}
{
DWORD check = 0;
if(persistence_getDword(L"unlimited_zoom", check)) {
UnlimitedZoomBtn.setCheck((int) check);
UnlimitedZoomChk.setCheck((int) check);
} else {
UnlimitedZoomBtn.setCheck(BST_UNCHECKED);
UnlimitedZoomChk.setCheck(BST_UNCHECKED);
}
}
{
DWORD check = 0;
if(persistence_getDword(L"wheel2zoom", check)) {
Wheel2ZoomChk.setCheck((int) check);
} else {
Wheel2ZoomChk.setCheck(BST_UNCHECKED);
}
}
{
DWORD check = 0;
if(persistence_getDword(L"redirect_textures", check)) {
ResRedirectBtn.setCheck((int) check);
ResRedirectChk.setCheck((int) check);
} else {
ResRedirectBtn.setCheck(BST_UNCHECKED);
ResRedirectChk.setCheck(BST_UNCHECKED);
}
}
std::wstring menu_resolution;
Expand Down Expand Up @@ -280,19 +289,23 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
wss << L'\"' << g_curExeDir << L"/bootstrap_patcher.exe" << L'\"';
wss << " -32BITEVERYTHING";
int check;
check = DPIBtn.getCheck();
check = DPIChk.getCheck();
if(check == BST_CHECKED) {
wss << " -ember:dpi_aware";
}
check = UnlimitedZoomBtn.getCheck();
check = UnlimitedZoomChk.getCheck();
if(check == BST_CHECKED) {
wss << " -ember:unlimited_zoom";
}
check = ResRedirectBtn.getCheck();
check = Wheel2ZoomChk.getCheck();
if(check == BST_CHECKED) {
wss << " -ember:wheel2zoom";
}
check = ResRedirectChk.getCheck();
if(check == BST_CHECKED) {
wss << " -ember:redirect_textures";
}
check = FullscreenBtn.getCheck();
check = FullscreenChk.getCheck();
if(check != BST_INDETERMINATE) {
wss << " -ember:fullscreen=";
wss << (check == BST_CHECKED ? "true" : "false");
Expand Down Expand Up @@ -330,11 +343,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
std::wstringstream wss;
wss << L'\"' << g_curExeDir << L"/bootstrap_patcher.exe" << L'\"';
wss << " -32BITEVERYTHING";
int check = DPIBtn.getCheck();
int check = DPIChk.getCheck();
if(check == BST_CHECKED) {
wss << " -ember:dpi_aware";
}
check = FullscreenBtn.getCheck();
check = FullscreenChk.getCheck();
if(check != BST_INDETERMINATE) {
wss << " -ember:fullscreen=";
wss << (check == BST_CHECKED ? "true" : "false");
Expand Down Expand Up @@ -375,6 +388,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
std::wstring path = ss.str();
std::filesystem::create_directories(path);
ShellExecuteW(NULL, L"open", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
} else if (hm == BindWasdBtn.id) {
bindWasd();
updateStatus();

// } else if (hm == GameModesCombo.id) {
// if(HIWORD(wParam) == CBN_SELCHANGE) {
// auto &mode = screenModeList[GameModesCombo.getCurSel()];
Expand Down Expand Up @@ -402,10 +419,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return (INT_PTR)(HBRUSH)BGColorBrush;
}
case WM_DESTROY:
persistence_setDword(L"fullscreen", (DWORD) FullscreenBtn.getCheck());
persistence_setDword(L"dpi_aware", (DWORD) DPIBtn.getCheck());
persistence_setDword(L"unlimited_zoom", (DWORD) UnlimitedZoomBtn.getCheck());
persistence_setDword(L"redirect_textures", (DWORD) ResRedirectBtn.getCheck());
persistence_setDword(L"fullscreen", (DWORD) FullscreenChk.getCheck());
persistence_setDword(L"dpi_aware", (DWORD) DPIChk.getCheck());
persistence_setDword(L"unlimited_zoom", (DWORD) UnlimitedZoomChk.getCheck());
persistence_setDword(L"wheel2zoom", (DWORD) Wheel2ZoomChk.getCheck());
persistence_setDword(L"redirect_textures", (DWORD) ResRedirectChk.getCheck());
{
auto &mode = g_screenModeList[MenuModesCombo.getCurSel()];
std::wstringstream ss;
Expand Down Expand Up @@ -508,3 +526,7 @@ int WINAPI WinMain(

return (int)msg.wParam;
}

int main() {
return WinMain(GetModuleHandleA(NULL), NULL, NULL, SW_NORMAL);
}
23 changes: 15 additions & 8 deletions launcher/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ gui::label_elem_t MenuLabel(L"Menu resolution:", WS_VISIBLE | WS_TABSTOP);
gui::combobox_elem_t MenuModesCombo(L"", CBS_DISABLENOSCROLL | CBS_DROPDOWNLIST | CBS_DROPDOWN | WS_OVERLAPPED | WS_VISIBLE);
gui::label_elem_t GameLabel(L"Game resolution:", WS_VISIBLE | WS_TABSTOP);
gui::combobox_elem_t GameModesCombo(L"", CBS_DISABLENOSCROLL | CBS_DROPDOWNLIST | CBS_DROPDOWN | WS_OVERLAPPED | WS_VISIBLE);
gui::button_elem_t DPIBtn(L"DPI aware:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t FullscreenBtn(L"Fullscreen:", BS_CHECKBOX | BS_AUTO3STATE | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t UnlimitedZoomBtn(L"Unlimited zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t DPIChk(L"DPI aware:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t FullscreenChk(L"Fullscreen:", BS_CHECKBOX | BS_AUTO3STATE | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t UnlimitedZoomChk(L"Unlimited zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t Wheel2ZoomChk(L"Wheel to zoom:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t BindWasdBtn(L"Bind WASD", WS_VISIBLE | WS_BORDER);


gui::label_elem_t ResLabel(L"Resources:", WS_VISIBLE | WS_TABSTOP);
gui::button_elem_t ResExtractBtn(L"Extract", WS_VISIBLE | WS_BORDER);
gui::button_elem_t ResOpenBtn(L"Open", WS_VISIBLE | WS_BORDER);
gui::button_elem_t ResRedirectBtn(L"Redirect resources:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);
gui::button_elem_t ResRedirectChk(L"Redirect resources:", BS_CHECKBOX | BS_AUTOCHECKBOX | BS_PUSHBUTTON | BS_LEFTTEXT | WS_VISIBLE | WS_BORDER);


struct : gui::layout_t {
Expand Down Expand Up @@ -54,11 +57,15 @@ struct : gui::layout_t {
});
gap(10);
hor(-1, 20, [this] {
visit(DPIBtn, 80, size.h);
visit(DPIChk, 80, size.h);
gap(20);
visit(FullscreenChk, 80, size.h);
gap(20);
visit(UnlimitedZoomChk, 105, size.h);
gap(20);
visit(FullscreenBtn, 80, size.h);
visit(Wheel2ZoomChk, 105, size.h);
gap(20);
visit(UnlimitedZoomBtn, 105, size.h);
visit(BindWasdBtn, 70, size.h);
});
gap(10);
hor(-1, 20, [this] {
Expand All @@ -68,7 +75,7 @@ struct : gui::layout_t {
gap(20);
visit(ResOpenBtn, 80, size.h);
gap(20);
visit(ResRedirectBtn, 130, size.h);
visit(ResRedirectChk, 130, size.h);
});
// body end

Expand Down
Loading

0 comments on commit fd3617d

Please sign in to comment.