Skip to content

Commit

Permalink
GOG patch was built into the project
Browse files Browse the repository at this point in the history
moving back to fullscreen
mouse sensitivity is now working in possession
  • Loading branch information
DiaLight committed Sep 13, 2024
1 parent 913643b commit d101f59
Show file tree
Hide file tree
Showing 62 changed files with 5,106 additions and 157 deletions.
260 changes: 149 additions & 111 deletions mapping/DKII_EXE_v170.sgmap

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion mapping/ida/sgmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,26 @@ def get_size(self):
class WinapiType(Type):
kind = TypeKind.Winapi

def __init__(self, name: str, size: int = None):
def __init__(self, name: str, size: int = None, is_union: bool = False):
super().__init__()
self.name = name # type: str
self.size = size # type: int
self.is_union = is_union

def serialize_short(self):
yield from super().serialize_short()
yield f"name={self.name}"
if self.size is not None:
yield f"size={self.size}"
if self.is_union:
yield f"is_union={self.is_union}"

def deserialize(self, it: ScopeLineIter, short_props: typing.Dict[str, str]):
self.name = short_props["name"]
size_str = short_props.get("size", None)
if size_str is not None:
self.size = int(size_str)
self.is_union = short_props.get("is_union", "False").lower() == 'true'

@classmethod
def create(cls, short_props: typing.Dict[str, str]):
Expand Down
8 changes: 6 additions & 2 deletions mapping/ida/sgmap_ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def is_windows_type(tname):
'_UNICODE_STRING', '_LIST_ENTRY', '_PROCESSOR_NUMBER', '_LARGE_INTEGER',
'_ULARGE_INTEGER', '_CURDIR', '_STRING', 'tWAVEFORMATEX', '_DSCAPS', 'DSCAPS',
'DSBCAPS', '_DSBUFFERDESC', 'WAVEFORMATEX',
'CHAR', 'char', '_TBYTE', 'WCHAR', 'wchar_t'
'LPCSTR', 'CHAR', 'char', '_TBYTE', 'WCHAR', 'wchar_t'
]: return True
return False

Expand Down Expand Up @@ -489,7 +489,11 @@ def try_struct(self, tif: idaapi.tinfo_t, tname: str, size: int, winapi: str):
if tname == "LPDIDEVICEOBJECTDATA_10":
tname = "DIDEVICEOBJECTDATA"
print("replace!!")
return sgmap.WinapiType(tname, size)
til = tif.get_til()
is_union = False
if til:
is_union = tif.is_union()
return sgmap.WinapiType(tname, size, is_union)
struct_ = self.structs.get_by_name(tname)
if struct_ is not None:
return sgmap.StructType(struct_)
Expand Down
4 changes: 3 additions & 1 deletion mapping/sgmap/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ bool ArrayType::lt(const Type *rhs) const {


Type *WinapiType::create(ScopeLineIter &sli, std::map<std::string, std::string> &shortProps, SGMapArena &arena) {
return arena.types.emplace_back(new WinapiType("", 0)).get();
return arena.types.emplace_back(new WinapiType("", 0, false)).get();
}

bool WinapiType::deserialize(ScopeLineIter &sli, std::map<std::string, std::string> &shortProps, SGMapArena &arena) {
name = shortProps["name"];
size = getIntOptional(shortProps, "size", 0);
is_union = getBoolOptional(shortProps, "is_union", false);
return true;
}

Expand All @@ -280,6 +281,7 @@ size_t WinapiType::calcSize() {
bool WinapiType::lt(const Type *rhs) const {
const WinapiType *rhsty = (WinapiType *) rhs;
if(size != rhsty->size) return size < rhsty->size;
if(is_union != rhsty->is_union) return is_union < rhsty->is_union;
return name < rhsty->name;
}

Expand Down
6 changes: 5 additions & 1 deletion mapping/sgmap/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct Type {
[[nodiscard]] virtual bool link(std::map<std::string, Struct *> &structsMap) { return true; }

bool operator <(const Type& rhs) const {
// TK_Void == TK_Function in msvc mangling
if(kind == TK_Void && rhs.kind == TK_Function) return false;
if(kind == TK_Function && rhs.kind == TK_Void) return false;
if(kind != rhs.kind) return kind < rhs.kind;
return lt(&rhs);
}
Expand Down Expand Up @@ -195,8 +198,9 @@ struct WinapiType : public Type {

std::string name;
size_t size;
bool is_union;

WinapiType(std::string name, size_t size) : Type(TK_Winapi), name(std::move(name)), size(size) {}
WinapiType(std::string name, size_t size, bool is_union) : Type(TK_Winapi), name(std::move(name)), size(size), is_union(is_union) {}
~WinapiType() override = default;

[[nodiscard]] static Type *create(ScopeLineIter &sli, std::map<std::string, std::string> &shortProps, SGMapArena &arena);
Expand Down
30 changes: 27 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(TARGET flame)
add_executable(${TARGET}
main.cpp
dkii_exe_functions.cpp
window_proc_functions.cpp
dk2/MyResources.cpp
dk2/MyGame.cpp
dk2/MyDxMouse.cpp
Expand All @@ -19,14 +18,39 @@ add_executable(${TARGET}
dk2/entities/CCreature.cpp
dk2/entities/CPlayer.cpp

dk2/engine/draw_functions.cpp
dk2/engine/window_proc_functions.cpp
dk2/engine/ddraw_functions.cpp

patches/replace_mouse_dinput_to_user32.cpp
patches/use_wheel_to_zoom.cpp
patches/micro_patches.cpp
patches/game_version_patch.cpp

patches/gog_patch_dll/gog_patch_dll.cpp
patches/gog_patch_dll/gog_cfg.cpp
patches/gog_patch_dll/gog_globals.cpp
patches/gog_patch_dll/gog_fake.cpp
patches/gog_patch_dll/gog_exports.cpp
patches/gog_patch_dll/gog_patch.cpp
patches/gog_patch_dll/fake/FakeD3D.cpp
patches/gog_patch_dll/fake/FakeD3D2.cpp
patches/gog_patch_dll/fake/FakeD3D3.cpp
patches/gog_patch_dll/fake/FakeDevice3.cpp
patches/gog_patch_dll/fake/FakeDirectDraw1.cpp
patches/gog_patch_dll/fake/FakeDirectDraw2.cpp
patches/gog_patch_dll/fake/FakeDirectDraw4.cpp
patches/gog_patch_dll/fake/FakeGammaControl.cpp
patches/gog_patch_dll/fake/FakeSurface.cpp
patches/gog_patch_dll/fake/FakeSurface4.cpp
patches/gog_patch_dll/fake/FakeTexture.cpp
patches/gog_patch_dll/fake/FakeViewport3.cpp
patches/gog_patch_dll/fake/FakeZBuffer.cpp
patches/gog_patch_dll/fake/FakeUnknown.cpp

# ${DKII_RESOURCES_FILE}
)
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR} patches/gog_patch_dll)
target_compile_definitions(${TARGET} PRIVATE
DIRECTINPUT_VERSION=0x0500
DIRECT3D_VERSION=0x0600
Expand All @@ -43,7 +67,7 @@ target_link_libraries(${TARGET} PRIVATE
winmm
dinput_genlib # generated in dinput_dll/genlib
ddraw # patch - dont link against gog's PATCH.dll because patch addresses are change after recompilation
# also i fully decompiled gog's PATCH.dll and bundled in project
dxguid

imm32
# wsock32 is old link target
Expand Down
36 changes: 35 additions & 1 deletion src/dk2/CDefaultPlayerInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "dk2_functions.h"
#include "dk2_globals.h"
#include "patches/micro_patches.h"
#include "gog_patch.h"


int dk2::CDefaultPlayerInterface::tickKeyboard2() {
Expand All @@ -22,7 +23,7 @@ int dk2::CDefaultPlayerInterface::tickKeyboard2() {
int dwWidth = MyGame_instance.dwWidth;
int dwHeight = MyGame_instance.dwHeight;

if(!control_windowed_mode::disable_move_by_mouse) {
if(!control_windowed_mode::enabled) {
if ( x < 5 )
this->pushMoveKeyAction(0, 0);
if ( x > dwWidth - 5 )
Expand Down Expand Up @@ -85,3 +86,36 @@ int dk2::CDefaultPlayerInterface::tickKeyboard2() {
v18_try_catch = 2;
return this->pushAction(&v17_action);
}


void dk2::CDefaultPlayerInterface::createSurfacesForView_42CDF0(RtGuiView *view) {
CBridge *f10_c_bridge = this->profiler->c_bridge;
char *rowPos = (char *) view->surf.lpSurface;
int v4_bytesPerPix = view->dwRGBBitCount / 8;
int v13_lineSize = 32 * view->surf.lPitch;
char *v10__allyWindowText = (char *) view->surf.lpSurface;
for(unsigned int y = 0; y < view->height_32blocks; ++y) {
char *linePos = rowPos;
for(unsigned int x = 0; x < view->width_128blocks; ++x) {
int lPitch = view->surf.lPitch;
Pos2i v14_size;
v14_size.x = 128;
v14_size.y = 32;
MySurface v15_surf;
v15_surf.constructor(&v14_size, &view->surf.desc, linePos, lPitch);
int _idx = x + view->width_128blocks * y;
if(gog::RtGuiView_fix::enable) {
if(idx >= 93 && view == &dk2::CDefaultPlayerInterface_instance._allyWindowText) {
idx = 0;
}
}
int _id = view->Arrp31x400_ids[_idx];
f10_c_bridge->v_f68(_id, &v15_surf, 1);
linePos += v4_bytesPerPix * 128;
}
rowPos = &v10__allyWindowText[v13_lineSize];
v10__allyWindowText += v13_lineSize;
}
}


9 changes: 9 additions & 0 deletions src/dk2/MyDxMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "dk2/MouseXyzDxAction.h"
#include "dk2/MouseRgbDxAction.h"
#include "dk2/ControlKeysUpdater.h"
#include "dk2/MyDxKeyboard.h"
#include "dk2_functions.h"
#include "patches/replace_mouse_dinput_to_user32.h"
#include "patches/use_wheel_to_zoom.h"
Expand Down Expand Up @@ -121,3 +122,11 @@ void dk2::MyDxMouse::handleData(int count) {
}
}

uint32_t *dk2::MyDxInputManagerCb::onWindowActivated(uint32_t *psatatus, int isActivated) {
this->f54_pdxKeyboard->dx_device.updateWindowActive(isActivated);
if (!replace_mouse_dinput_to_user32::enabled) {
this->f58_pdxmouse->dx_device.updateWindowActive(isActivated);
}
this->updateCoopLevelAndSignal(psatatus);
return psatatus;
}
56 changes: 52 additions & 4 deletions src/dk2/MyGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ int dk2::MyGame::prepareScreenEx(
int isWindowed,
int screenSwap,
int screenHardware3D) {
if(control_windowed_mode::enabled) {
printf("prepareScreen %p %dx%d %d %d %d %d\n", this, dwWidth, dwHeight, dwRGBBitCount, isWindowed, screenSwap, screenHardware3D);
if (control_windowed_mode::enabled) {
printf("prepareScreen %p %dx%d %d %d %d %d\n", this, dwWidth, dwHeight, dwRGBBitCount, isWindowed, screenSwap,
screenHardware3D);
isWindowed = true; // todo: control
}
int sel_dd_idx = this->selected_dd_idx;
Expand Down Expand Up @@ -137,12 +138,11 @@ int dk2::MyGame::prepareScreenEx(
MyResources_instance.soundCfg.numberOfChannels);
MyResources_instance.soundCfg.resolveValues();
}
int screenSwap__1 = screenSwap;
this->isWindowed = isWindowed;
this->dwWidth = dwWidth;
this->dwHeight = dwHeight_;
this->dwRGBBitCount = dwRGBBitCount_;
this->_prepareScreen_a6 = screenSwap__1;
this->_prepareScreen_a6 = screenSwap;
this->_prepareScreen_a7 = screenHardware3D_;
this->f18 = 0;
this->collect3dDevices();
Expand Down Expand Up @@ -184,3 +184,51 @@ int dk2::MyGame::prepareScreenEx(
ij_ImmAssociateContext(HWindow, 0);
return 1;
}

namespace dk2 {
void inline_selectDrawEngine(dk2::MyGame *game);
}
int dk2::MyGame::init() {
inline_selectDrawEngine(this);
int status;
if (*MyInputManagerCb_static_initKeyInputs(&status) < 0) {
return 0;
}
int status_;
if (*MyInputManagerCb_static_initCursorInputs(&status_) < 0) {
return 0;
}
if (!this->createWindow(1)) {
return 0;
}
if (!this->prepareScreenEx(
MyResources_instance.video_settings.display_width,
MyResources_instance.video_settings.display_height,
MyResources_instance.video_settings.display_bitnes,
MyResources_instance.video_settings.isWindowed,
MyResources_instance.video_settings.screen_swap,
MyResources_instance.video_settings.screen_hardware3D)
&& !this->prepareScreenEx(
640,
480,
MyResources_instance.video_settings.display_bitnes,
MyResources_instance.video_settings.isWindowed,
MyResources_instance.video_settings.screen_swap,
MyResources_instance.video_settings.screen_hardware3D)) {
printf("failed to prepare screen\n");
return 0;
}
setCustomDefWindowProcA((int) myCustomDefWindowProcA);
WinEventHandlers_instance.addHandler(
0,
(void (__stdcall *)(int, int, void *)) static_MyGame_Event07_cb,
this);
this->fE71 = 0;
this->fE75 = 0;
this->recreateRequest = 0;
this->fE7D = 0;
this->moonAge = calc_moon_age();
this->f0 = 1;
this->fF51 = 0;
return 1;
}
43 changes: 43 additions & 0 deletions src/dk2/RegKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//
#include "dk2/RegKey.h"
#include "patches/micro_patches.h"
#include "gog_cfg.h"
#include "gog_patch.h"


unsigned int dk2::RegKey::settings_readBytesCount(LPCSTR lpValueName) {
Expand Down Expand Up @@ -46,3 +48,44 @@ uint32_t *__thiscall dk2::RegKey::settings_readBytes(uint32_t *pstatus, LPCSTR l
return pstatus;
}


int *dk2::RegKey::settings_readValue(int *pstatus, LPCSTR lpValueName, uint32_t *pValue) {
if(gog::RegistryConfig_patch::enable) {
if (gog::cfg::patchRegistryConfig(pstatus, lpValueName, (DWORD *) pValue) != -1) return pstatus;
}
if (!lpValueName || this->key == NULL) {
*pstatus = -1;
return pstatus;
}
DWORD Type = 0;
DWORD value;
DWORD cbData = sizeof(value);
if(RegQueryValueExA(this->key, lpValueName, NULL, &Type, (LPBYTE) &value, &cbData) != ERROR_SUCCESS) {
*pstatus = -1;
return pstatus;
}
signed int v8_type;
if (RegQueryValueExA(this->key, lpValueName, NULL, &Type, NULL, NULL) != ERROR_SUCCESS) {
HKEY tmp;
if (RegOpenKeyA(this->key, lpValueName, &tmp)) {
v8_type = -1;
} else {
RegCloseKey(tmp);
v8_type = -2;
}
} else {
v8_type = Type;
}
if (v8_type == REG_DWORD || v8_type == REG_DWORD_BIG_ENDIAN) {
*pValue = value;
*pstatus = 0;
return pstatus;
}
if (v8_type == REG_LINK) {
*pValue = _byteswap_ulong(value);
*pstatus = 0;
return pstatus;
}
*pstatus = -1;
return pstatus;
}
Loading

0 comments on commit d101f59

Please sign in to comment.