Skip to content

Commit

Permalink
fixed ai response to threat
Browse files Browse the repository at this point in the history
added dev helper for windowed game debug
  • Loading branch information
DiaLight committed Aug 20, 2024
1 parent 8b9309a commit 7512809
Show file tree
Hide file tree
Showing 21 changed files with 1,816 additions and 511 deletions.
1,532 changes: 1,052 additions & 480 deletions mapping/DKII_EXE_v170.sgmap

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ add_executable(${TARGET}
dk2/CGameComponent.cpp
dk2/PlayerCfg.cpp
dk2/RegKey.cpp
dk2/MyComputerPlayer.cpp
dk2/entities/entities_type.cpp
dk2/entities/CCreature.cpp
dk2/entities/CPlayer.cpp

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

${DKII_RESOURCES_FILE}
)
Expand Down
8 changes: 4 additions & 4 deletions src/dk2/CGameComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
if (!MyResources_instance.gameCfg.useFe2d_unk1) this->mt_profiler.constructor2();
CCommunicationInterface *v2_comm_i;
v2_comm_i = &CNetworkCommunication_instance;
if ( MyResources_instance.gameCfg.useFe != 3 )
if ( MyResources_instance.gameCfg.useFe_playMode != 3 )
v2_comm_i = &CLocalCommunication_instance;
// CCommunicationInterface *v32;
// v32 = v2_comm_i; // probably seh
Expand Down Expand Up @@ -246,7 +246,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
useFe3d = MyResources_instance.gameCfg.useFe3d;
MyResources_instance.gameCfg.useFe2d_unk1 = 0;
}
if ( MyResources_instance.gameCfg.useFe == 3 && !useFe3d ) {
if ( MyResources_instance.gameCfg.useFe_playMode == 3 && !useFe3d ) {
Pos2i pos;
pos.x = 0;
pos.y = 0;
Expand Down Expand Up @@ -299,8 +299,8 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
if ( useFe3d ) return 0;
if ( MyResources_instance.gameCfg.unk_f16C ) {
MyResources_instance.gameCfg.useFe3d = 1;
MyResources_instance.gameCfg.useFe_unk3 = MyResources_instance.gameCfg.useFe;
MyResources_instance.gameCfg.useFe = 5;
MyResources_instance.gameCfg.useFe_unk3 = MyResources_instance.gameCfg.useFe_playMode;
MyResources_instance.gameCfg.useFe_playMode = 5;
wcsncpy(MyResources_instance.gameCfg.levelName, L"FrontEnd3DLevel", 64u);
MyResources_instance.gameCfg.levelName[63] = 0;
MyResources_instance.gameCfg.hasSaveFile = 0;
Expand Down
324 changes: 324 additions & 0 deletions src/dk2/MyComputerPlayer.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/dkii_exe_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#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"
#include "patches/game_version_patch.h"


int32_t dk2::MyGame::isOsCompatible() {
Expand Down Expand Up @@ -211,7 +211,7 @@ BOOL __cdecl dk2::parse_command_line(int argc, const char **argv) {
MyResources_instance.video_settings.cmd_flag_SOFTWAREFILTER = 1;
} else if (!_strcmpi(*cur_token, "-FE3D")) { // Defines 3D FrontEnd (?)
MyResources_instance.gameCfg.useFe3d = 1;
MyResources_instance.gameCfg.useFe = 1;
MyResources_instance.gameCfg.useFe_playMode = 1;
wcsncpy(MyResources_instance.gameCfg.levelName, L"FrontEnd3DLevel", 64);
MyResources_instance.gameCfg.levelName[63] = 0;
MyResources_instance.gameCfg.hasSaveFile = 0;
Expand All @@ -221,7 +221,7 @@ BOOL __cdecl dk2::parse_command_line(int argc, const char **argv) {
cmd_flag_FrontEnd3D_unk8 = 1;
} else if (!_strcmpi(*cur_token, "-FE")) { // Defines 2D FrontEnd (I tried and the screen stayed black so, beware!) (?)
MyResources_instance.gameCfg.useFe3d = 0;
MyResources_instance.gameCfg.useFe = 1;
MyResources_instance.gameCfg.useFe_playMode = 1;
wcsncpy(MyResources_instance.gameCfg.levelName, L"FrontEnd3DLevel", 64);
MyResources_instance.gameCfg.levelName[63] = 0;
MyResources_instance.gameCfg.hasSaveFile = 0;
Expand Down Expand Up @@ -304,7 +304,7 @@ void __cdecl dk2::CTextBox_renderVersion(dk2::CTextBox *textBox, CFrontEndCompon
renderer.selectMyCR(&status, 0);
renderer.selectMyTR(&status, 2);
wchar_t wstring[64];
if(char *version = version_patch::getFileVersion()) {
if(char *version = game_version_patch::getFileVersion()) {
swprintf(wstring, L"%S", version);
} else {
swprintf(wstring, L"V%lu.%lu", g_majorVersion, g_minorVersion);
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ bool dk2::dk2_main2() {
return false;
}
if ( MyResources_instance.gameCfg.f124 ) {
MyResources_instance.gameCfg.useFe = 1;
MyResources_instance.gameCfg.useFe_playMode = 1;
MyResources_instance.gameCfg.useFe_unkTy = 3;
} else if ( MyResources_instance.gameCfg.f128 == 1 ) {
MyResources_instance.gameCfg.useFe = 4;
MyResources_instance.gameCfg.useFe_playMode = 4;
MyResources_instance.gameCfg.useFe_unkTy = 3;
} else if ( !cmd_flag_FrontEnd3D_unk8 ) {
if ( MyGame_instance.sub_559790() < 240.0 && getDevIdxSupportsLinearPerspective() != -1
Expand All @@ -56,7 +56,7 @@ bool dk2::dk2_main2() {
MyResources_instance.gameCfg.useFe2d_unk2 = 1;
}
MyResources_instance.gameCfg.useFe3d = 1;
MyResources_instance.gameCfg.useFe = 5;
MyResources_instance.gameCfg.useFe_playMode = 5;
_wcsncpy(MyResources_instance.gameCfg.levelName, L"FrontEnd3DLevel", 0x40u);
MyResources_instance.gameCfg.levelName[63] = 0;
MyResources_instance.gameCfg.hasSaveFile = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Created by DiaLight on 06.08.2024.
//

#include "version_patch.h"
#include "game_version_patch.h"
#include <Windows.h>
#include <cstdio>

bool version_patch::enabled = true;
bool game_version_patch::enabled = true;

bool resolveFileVersion(char *out) {
bool status = false;
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace {
char versionCache[64] = {0};
}

char *version_patch::getFileVersion() {
char *game_version_patch::getFileVersion() {
if(!enabled) return nullptr;
if(versionCache[0] == '\0') if(!resolveFileVersion(versionCache)) enabled = false;
if(versionCache[0] == '\0') return nullptr;
Expand Down
16 changes: 16 additions & 0 deletions src/patches/game_version_patch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by DiaLight on 06.08.2024.
//

#ifndef FLAME_GAME_VERSION_PATCH_H
#define FLAME_GAME_VERSION_PATCH_H



namespace game_version_patch {
extern bool enabled;
char *getFileVersion();
}


#endif //FLAME_GAME_VERSION_PATCH_H
1 change: 1 addition & 0 deletions src/patches/micro_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bool force_32bit_everything::enabled = true;
bool disable_bonus_damage::enabled = false;
bool backstab_fix::enabled = true;
bool workshop_manufacture_build_time_fix::enabled = true;
bool response_to_threat_fix::enabled = true;
bool use_wasd_by_default_patch::enabled = true;

void use_wasd_by_default_patch::useAlternativeName(LPCSTR &lpValueName) {
Expand Down
4 changes: 4 additions & 0 deletions src/patches/micro_patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ namespace workshop_manufacture_build_time_fix {
extern bool enabled;
}

namespace response_to_threat_fix {
extern bool enabled;
}

namespace use_wasd_by_default_patch {
extern bool enabled;
void useAlternativeName(LPCSTR &lpValueName);
Expand Down
16 changes: 0 additions & 16 deletions src/patches/version_patch.h

This file was deleted.

3 changes: 3 additions & 0 deletions src/replace_globals.map
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
00506B70 int getManufactureRequired(uint16_t); // --- /* auto */
004C3200 int creatureDidWorkshopWork(int, CCreature *); /* auto */

# CComputerPlayer.h
004FE0B0 char tickRespondToAttack(char); // --------- /* auto */

# PlayerCfg.h
005604C0 void fillKeyMaps(); // --------------------- /* auto */

Expand Down
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
add_subdirectory(msvc_mangler)
add_subdirectory(delinker)
add_subdirectory(genapi)
if(DEV_DK2_DIR)
add_subdirectory(devhelper)
endif()
18 changes: 18 additions & 0 deletions tools/devhelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(TARGET devhelper)

enable_language(ASM_MASM)
add_library(${TARGET} SHARED
dllmain.cpp
mimicry.cpp
console.cpp
game_version.cpp
)

target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_compile_definitions(${TARGET} PRIVATE DIRECTINPUT_VERSION=0x0500 DIRECT3D_VERSION=0x0600)

add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:${TARGET}>
"${DEV_DK2_DIR}/devht.dll"
)
58 changes: 58 additions & 0 deletions tools/devhelper/console.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Created by DiaLight on 16.08.2024.
//

#include "console.h"
#include <Windows.h>
#include <ios>
#include <io.h>
#include <fcntl.h>


void RedirectStandardIo() {
/* This clever code have been found at:
Adding Console I/O to a Win32 GUI App
Windows Developer Journal, December 1997
http://dslweb.nwnexus.com/~ast/dload/guicon.htm
Andrew Tucker's Home Page */

// redirect unbuffered STDOUT to the console
long lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle > 0) {
FILE *fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
}

// redirect unbuffered STDIN to the console
lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle > 0) {
FILE *fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
}

// redirect unbuffered STDERR to the console
lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle > 0) {
FILE *fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0 );
}

// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
}


bool initConsole() {
AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
freopen_s((FILE**)stderr, "CONOUT$", "w", stderr);

RedirectStandardIo();
return true;
}
12 changes: 12 additions & 0 deletions tools/devhelper/console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by DiaLight on 16.08.2024.
//

#ifndef FLAME_CONSOLE_H
#define FLAME_CONSOLE_H


bool initConsole();


#endif //FLAME_CONSOLE_H
Loading

0 comments on commit 7512809

Please sign in to comment.