Skip to content

Commit

Permalink
implement first person view mouse control
Browse files Browse the repository at this point in the history
inline fix_mouse_pos_on_resized_window to replace_mouse_dinput_to_user32
patch version display
decompile CTextBox_renderVersion
  • Loading branch information
DiaLight committed Aug 7, 2024
1 parent deaa02e commit 4ea67db
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 243 deletions.
481 changes: 294 additions & 187 deletions mapping/DKII_EXE_v170.sgmap

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ set(TARGET dkii_res)
set(VER_PRODUCT_NUMBER 1)
set(VER_PRODUCT_VERSION 7)
set(VER_BUILD_NUMBER 0)
set(VER_BUILD_DATE 0)
set(VER_REVISION_NUMBER 0)
if(CONFIGURE_DATE)
set(VER_BUILD_DATE "${CONFIGURE_DATE}")
set(VER_FILE_SUFFIX "${CONFIGURE_DATE}")
endif ()
set(VER_PROJECT_URL "https://github.com/DiaLight/Flame")
set(VER_PRODUCT_NAME "DKII-Flame")
set(VER_DESCRIPTION "DKII unofficial relinking with replaces")

set(VER_RES_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(VER_COMMENTS "url: ${VER_PROJECT_URL}, date: ${VER_BUILD_DATE}")
set(VER_COMMENTS "url: ${VER_PROJECT_URL}")
set(VER_FILE_SUFFIX " Flame build")
if(NOT VER_BUILD_NUMBER EQUAL 0)
string(APPEND VER_FILE_SUFFIX ".${VER_BUILD_NUMBER}")
endif ()
if(CONFIGURE_DATE)
string(APPEND VER_COMMENTS ", date: ${CONFIGURE_DATE}")
string(APPEND VER_FILE_SUFFIX " ${CONFIGURE_DATE}")
endif ()
if(GIT_SHA1)
string(APPEND VER_COMMENTS ", commit: ${GIT_SHA1} ${GIT_DATE} ${GIT_COMMIT_SUBJECT}")
string(APPEND VER_FILE_SUFFIX " ${GIT_SHORT_SHA1}")
endif ()

configure_file(
Expand Down
6 changes: 3 additions & 3 deletions resources/resources.rc.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <windows.h>

#define VER_FILEVERSION @VER_PRODUCT_NUMBER@,@VER_PRODUCT_VERSION@,@VER_BUILD_NUMBER@,@VER_BUILD_DATE@
#define VER_FILEVERSION_STR "@VER_PRODUCT_NUMBER@.@VER_PRODUCT_VERSION@.@VER_BUILD_NUMBER@.@VER_BUILD_DATE@\0"
#define VER_FILEVERSION @VER_PRODUCT_NUMBER@,@VER_PRODUCT_VERSION@,@VER_BUILD_NUMBER@,0
#define VER_FILEVERSION_STR "@VER_PRODUCT_NUMBER@.@VER_PRODUCT_VERSION@@VER_FILE_SUFFIX@\0"

#define VER_PRODUCTVERSION @VER_PRODUCT_NUMBER@,@VER_PRODUCT_VERSION@,@VER_BUILD_NUMBER@,@VER_BUILD_DATE@
#define VER_PRODUCTVERSION @VER_PRODUCT_NUMBER@,@VER_PRODUCT_VERSION@,@VER_BUILD_NUMBER@,0
#define VER_PRODUCTVERSION_STR "@VER_PRODUCT_NUMBER@.@VER_PRODUCT_VERSION@.@VER_BUILD_NUMBER@\0"

#ifndef DEBUG
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_executable(${TARGET}
patches/replace_mouse_dinput_to_user32.cpp
patches/use_wheel_to_zoom.cpp
patches/micro_patches.cpp
patches/version_patch.cpp

${DKII_RESOURCES_FILE}
)
Expand All @@ -40,6 +41,7 @@ target_link_libraries(${TARGET} PRIVATE
# wsock32 is old link target
ws2_32 # should be better
dsound
Version
)

target_compile_options(${TARGET} PRIVATE
Expand Down
4 changes: 2 additions & 2 deletions src/dk2/CGameComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
v40.constructor();
v40.selectMyCR(&status, 2);
v40.selectMyTR(&status, 2);
unsigned __int8 *MbString = MyMbStringList_idx1091_getMbString(CWorld_instance.fA3C3);
uint8_t *MbString = MyMbStringList_idx1091_getMbString(CWorld_instance.fA3C3);
PixelMask mask;
mask.f0 = 0xFF;
mask.f1 = 0xFF;
Expand All @@ -279,7 +279,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
v40.renderText(
&status,
&aabb,
(char *)MbString,
MbString,
&g_FontObj5_instance,
0);
v40.destructor();
Expand Down
2 changes: 1 addition & 1 deletion src/dk2/MyDxKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int dk2::MyDxKeyboard::processKeyboardData(int a2) {
action->data = f4_dwData;
action->timestamp = f8_dwTimeStamp;
action->isNotHandled = 1;
this->f8_pcontrolkeys->v_fun4((DxAction *) action);
this->f8_pcontrolkeys->v_fun4_keyboard((DxAction *) action);
// hook::DIRECT_INPUT_KEYBOARD_DATA
++i;
result = a2 - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/dk2/MyDxMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void dk2::MyDxMouse::handleData(int count) {
xyz->actedAxe = f0_dwOfs;
xyz->timestamp = f8_dwTimeStamp;
xyz->isNotHandled = 1;
this->f8_pcontrolkeys->v_fun3(xyz);
this->f8_pcontrolkeys->v_fun3_mouse(xyz);
} break;
case 0xC: // rgbButtons
case 0xD:
Expand Down Expand Up @@ -111,7 +111,7 @@ void dk2::MyDxMouse::handleData(int count) {
action->data = f4_dwData;
action->timestamp = dwTimeStamp;
action->isNotHandled = 1;
this->f8_pcontrolkeys->v_fun4(action);
this->f8_pcontrolkeys->v_fun4_keyboard(action);
} break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/dk2/entities/CCreature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@


enum CCreature_typeId {
#define _CCreature_typeId(id, isEvil, camelName, snakeName) CCreature_typeId_##camelName = id,
#define _CCreature_typeId(id, isEvil, pascalName, snakeName) CCreature_typeId_##pascalName = id,
CCreature_types(_CCreature_typeId)
};

const char *CCreature_typeId_toString(int ty) {
switch (ty) {
#define _CCreature_typeId_toString(id, isEvil, camelName, snakeName) case CCreature_typeId_##camelName: return #camelName;
#define _CCreature_typeId_toString(id, isEvil, pascalName, snakeName) case CCreature_typeId_##pascalName: return #pascalName;
CCreature_types(_CCreature_typeId_toString)
}
return "Unknown";
Expand Down
43 changes: 37 additions & 6 deletions src/dkii_exe_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// Created by DiaLight on 01.07.2024.
//
#include <windowsx.h>
#include "dk2/MyGame.h"
#include "dk2/MyDxInputState.h"
#include "dk2/MyMouseUpdater.h"
#include "dk2/button/CTextBox.h"
#include "dk2_functions.h"
#include "dk2_globals.h"
#include "patches/replace_mouse_dinput_to_user32.h"
#include "patches/micro_patches.h"
#include "patches/use_wheel_to_zoom.h"
#include "patches/version_patch.h"


int32_t dk2::MyGame::isOsCompatible() {
Expand Down Expand Up @@ -69,9 +72,7 @@ void dk2::resolveDk2HomeDir() {

LRESULT dk2::CWindowTest_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
// patch::BEFORE_WINDOW_PROC
if(hide_mouse_cursor_in_window::window_proc(hWnd, Msg, wParam, lParam)) return TRUE;
replace_mouse_dinput_to_user32::emulate_dinput_from_user32(hWnd, Msg, wParam, lParam);
fix_mouse_pos_on_resized_window::window_proc(hWnd, Msg, wParam, lParam);
use_wheel_to_zoom::window_proc(hWnd, Msg, wParam, lParam);
fix_keyboard_state_on_alt_tab::window_proc(hWnd, Msg, wParam, lParam);
bring_to_foreground::window_proc(hWnd, Msg, wParam, lParam);
Expand All @@ -94,13 +95,19 @@ LRESULT dk2::CWindowTest_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
break;
}
case WM_MOUSEMOVE: {
Pos2i pos;
pos.x = LOWORD(lParam);
pos.y = HIWORD(lParam);
MyInputManagerCb_static_setMousePos(&pos);
if(replace_mouse_dinput_to_user32::enabled) {
POINT mousePos = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
replace_mouse_dinput_to_user32::handle_mouse_move(hWnd, mousePos);
} else {
Pos2i pos;
pos.x = LOWORD(lParam);
pos.y = HIWORD(lParam);
MyInputManagerCb_static_setMousePos(&pos);
}
break;
}
}
if(hide_mouse_cursor_in_window::window_proc(hWnd, Msg, wParam, lParam)) return TRUE;
if ( !getCustomDefWindowProcA() )
return DefWindowProcA(hWnd, Msg, wParam, lParam);
typedef LRESULT (__stdcall *CustomDefWindowProcA_t)(HWND, UINT, WPARAM, LPARAM);
Expand Down Expand Up @@ -283,3 +290,27 @@ BOOL __cdecl dk2::parse_command_line(int argc, const char **argv) {
return 1;
}


void __cdecl dk2::CTextBox_renderVersion(dk2::CTextBox *textBox, CFrontEndComponent *frontend) {
AABB area;
textBox->getScreenAABB(&area);
AABB scaled;
scaled = *frontend->cgui_manager.scaleAabb(&scaled, &area);

uint8_t __buf[sizeof(MyTextRenderer)];
MyTextRenderer &renderer = *(MyTextRenderer *) &__buf;
renderer.constructor();
int status;
renderer.selectMyCR(&status, 0);
renderer.selectMyTR(&status, 2);
wchar_t wstring[64];
if(char *version = version_patch::getFileVersion()) {
swprintf(wstring, L"%S", version);
} else {
swprintf(wstring, L"V%lu.%lu", g_majorVersion, g_minorVersion);
}
uint8_t mbstring[64];
MyLangObj_static_toUniToMB_2(wstring, mbstring, 64);
renderer.renderText(&status, &scaled, mbstring, &g_FontObj2_instance, NULL);
renderer.destructor();
}
22 changes: 0 additions & 22 deletions src/patches/micro_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ bool force_32bit_everything::enabled = true;
bool disable_bonus_damage::enabled = false;
bool backstab_fix::enabled = true;


namespace {
dk2::Pos2i clientSize;
}
void fix_mouse_pos_on_resized_window::window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM &lParam) {
switch (Msg) {
case WM_SIZE: {
clientSize = {LOWORD(lParam), HIWORD(lParam)};
break;
}
case WM_MOUSEMOVE: {
dk2::Pos2i pos = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
dk2::AABB renderRect = dk2::MyInputManagerCb_instance.f60_mouse->f30_aabb;
dk2::Pos2i renderSize = {renderRect.maxX - renderRect.minX, renderRect.maxY - renderRect.minY};
pos.x = (int) ((float) pos.x * (float) renderSize.x / (float) clientSize.x);
pos.y = (int) ((float) pos.y * (float) renderSize.y / (float) clientSize.y);
lParam = (pos.x & 0xFFFF) | ((pos.y & 0xFFFF) << 16);
break;
}
}
}

void fix_keyboard_state_on_alt_tab::window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
switch(Msg) {
case WM_ACTIVATEAPP:
Expand Down
4 changes: 0 additions & 4 deletions src/patches/micro_patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ namespace backstab_fix {
extern bool enabled;
}

namespace fix_mouse_pos_on_resized_window {
void window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM &lParam);
}

namespace fix_keyboard_state_on_alt_tab {
void window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
}
Expand Down
Loading

0 comments on commit 4ea67db

Please sign in to comment.