Skip to content

Commit

Permalink
burning wooden bridges correctly
Browse files Browse the repository at this point in the history
disable zoom by wheel in main menu
disable fps limit in fullscreen mode
port limit fix
  • Loading branch information
DiaLight committed Oct 1, 2024
1 parent 1b88005 commit 6082568
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 220 deletions.
436 changes: 255 additions & 181 deletions mapping/DKII_EXE_v170.sgmap

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ add_executable(${TARGET}
dk2/PlayerCfg.cpp
dk2/RegKey.cpp
dk2/MyComputerPlayer.cpp
dk2/CRoom.cpp
dk2/button/button_types.cpp
dk2/button/CTextInput.cpp
dk2/entities/entities_type.cpp
dk2/entities/CCreature.cpp
dk2/entities/CPlayer.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/dk2/CGameComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
// hook::BEFORE_GAME_LOOP
while ( !this->exit_flag ) {
// hook::TICK_GAME_LOOP
limit_fps::call();
if(control_windowed_mode::enabled) limit_fps::call();
replace_mouse_dinput_to_user32::release_handled_dinput_actions();
if ( !MyGame_instance.isNeedBlt() ) {
MyCollectDxAction_Action dxAct;
Expand Down
185 changes: 185 additions & 0 deletions src/dk2/CRoom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//
// Created by DiaLight on 30.09.2024.
//

#include "dk2/entities/CRoom.h"
#include "room_type.h"
#include "dk2/entities/CPlayer.h"
#include "dk2_globals.h"
#include "dk2/CBridgeCmd.h"
#include "dk2/entities/data/MyRoomDataObj.h"
#include "dk2/entities/data/MyTerrainDataObj.h"
#include "dk2/world/map/MyMapElement.h"
#include "tools/bug_hunter.h"
#include "patches/micro_patches.h"


namespace dk2 {

MyMapElement *getMapElem(Pos2ub &loc) {
CMap &cmap = g_CWorld_ptr->cmap;
return &cmap.mapElements[loc.x + loc.y * cmap.width];
}

void testFire(CRoom *_this) {
MyMapElement *mapElem;
for (Pos2ub loc = _this->firstSlab; loc.x || loc.y; loc = mapElem->nextSlab) {
mapElem = getMapElem(loc);
uint8_t burnLevel = (mapElem->flags >> 1) & 0xF;
if ((mapElem->_playerId & 0x1000) == 0) continue;
if (burnLevel >= 9) continue;
mapElem->roomSetBurnLevel(burnLevel + 1);
burnLevel = (mapElem->flags >> 1) & 0xF;
if (burnLevel == 8) {
*(DWORD *) _this->field_49_union_start = 1; // FlagToBurn
mapElem->roomSetBurnLevel(9);
} else if (burnLevel == 4) {
CBridgeCmd v21_cmd;
v21_cmd.a1 = loc.x | (loc.y << 16);
v21_cmd.a2 = 0;
v21_cmd.a3 = 0;
v21_cmd.cmd = 3;
int v22_try;
v22_try = 0;
g_CWorld_ptr->execCBridgeCmd(&v21_cmd);
v22_try = -1;
}
}
}
}

int dk2::CRoom::tickWoodenBridge() {
unsigned int v3 = (this->f0_tagId + g_CWorld_ptr->getGameTick()) % (5 * Obj6F2550_instance.gameTick);
if (v3 == 0) { // fire tick
testFire(this);
}

// if nothing to burn then exit
if (*(DWORD *) this->field_49_union_start != 1) return 1;

// tick remove mapElem by burning
__int16 v8_unkIdx = this->pRoomDataObj->f421;
bool anyBridgesBurned = false;
int burnedCount = 0;
MyMapElement *mapElem;
for (Pos2ub pos = this->firstSlab; pos.x || pos.y; pos = mapElem->nextSlab) {
mapElem = getMapElem(pos);
if ((mapElem->_playerId & 0x1000) == 0) continue;
uint8_t burnLevel = (mapElem->flags >> 1) & 0xF;
if (burnLevel != 9) continue;
auto *player = (CPlayer *) sceneObjects[this->playerId];
if (!player->fun_4C5DB0(pos.x, pos.y, 0)) continue;

anyBridgesBurned = true;
++burnedCount;
mapElem->roomSetBurnLevel(0);
if (v8_unkIdx) {
CBridgeCmd v21_cmd;
v21_cmd.a1 = (pos.x << 12) + 2048;
v21_cmd.a2 = (pos.y << 12) + 2048;
v21_cmd.a3 = 0;
__int16 v14 = 0;
Pos2ub v19_bridgeLoc;
g_CWorld_ptr->v_sub_509580(v8_unkIdx, this->playerId, (int) &v21_cmd, (int) &v14, (int) &v19_bridgeLoc);
}
if (burnedCount == 8) break;
}
if (!anyBridgesBurned) *(DWORD *) this->field_49_union_start = 0; // FlagToBurn
return 1;
}

unsigned int dk2::CMap::attachToRoom(
int a2_x,
int a3_y,
unsigned __int16 a4_roomObjId,
__int16 a5_playerId,
int a6,
int a7) {
int v8_y = a3_y;
MyMapElement *v9_mapElem = &this->mapElements[a2_x + a3_y * this->width];
int v10_flags = g_MyTerrainDataObj_arr[v9_mapElem->arr6DA4A8_idx]->_flags;
if ((v10_flags & 0x80u) == 0) {
if ((v10_flags & 0x100) != 0)
v9_mapElem->_playerId |= 0x1000u;
} else {
v9_mapElem->_playerId &= ~0x1000u;
}
int typeId = ((CRoom *) sceneObjects[a4_roomObjId])->typeId;
if(wooden_bridge_burn_fix::enabled) {
if (typeId != CRoom_typeId_WoodenBridge) { // ignore reset burn level at attach cell to room
v9_mapElem->roomSetBurnLevel(0);
}
} else {
v9_mapElem->roomSetBurnLevel(0);
}
v9_mapElem->fun_4559D0(a5_playerId);
MyRoomDataObj *v11_roomDataObj = this->world->v_fun_50D0B0(typeId);
this->fun_44FC40(a2_x, v8_y, (int) v11_roomDataObj->f44E, v9_mapElem->_playerId & 0xFFF, 0, a7);
// v9_mapElem->roomId = v9_mapElem->roomId ^ ((v9_mapElem->roomId ^ a4_roomObjId) & 0xFFF);
v9_mapElem->roomId = (v9_mapElem->roomId & 0xF000) | (a4_roomObjId & 0xFFF);
return this->sub_4522A0(a2_x, v8_y);
}

int dk2::MyRooms::sub_4ED1A0(
int a2_x,
int arg4_y,
int a4_roomTypeId,
__int16 a5_playerId,
unsigned __int16 a6_roomObjId,
BYTE *a7_pNearCountNeg,
int a8) {
if ((g_MyTerrainDataObj_arr[this->world->getMapElem(a2_x, arg4_y)->arr6DA4A8_idx]->_flags & 0x80) != 0) {
int *p_y; // esi
p_y = &g_deltaLocs[0].y;
do {
int v11 = a2_x + *(p_y - 1);
int v12 = *p_y + arg4_y;
CBridgeCmd bridgeCmd;
bridgeCmd.a3 = -8192;
bridgeCmd.a1 = (v11 << 12) + 2048;
bridgeCmd.a2 = (v12 << 12) + 2048;
bridgeCmd.cmd = 8;
CWorld *f6_world = this->world;
int v20_try = 0;
f6_world->execCBridgeCmd(&bridgeCmd);
v20_try = -1;
p_y += 2;
} while ((int) p_y < (int) 0x6BC374);
// } while ( (int)p_y < (int)&dword_6BC374 );
}
CRoom *v19[4];
memset(v19, 0, sizeof(v19));
CRoom *a3 = 0;
int v14 = this->sub_4ED320(a2_x, arg4_y, a4_roomTypeId, a5_playerId, a6_roomObjId, a7_pNearCountNeg, &a3, v19);
if(wooden_bridge_burn_fix::enabled) {
if(((BYTE) a4_roomTypeId) == CRoom_typeId_WoodenBridge) {
CMap &map = this->world->cmap;
map.mapElements[a2_x + arg4_y * map.width].roomSetBurnLevel(0);
}
}
CRoom *v15 = a3;
int arg4_ya = v14;
if (!a3)
return arg4_ya;
if (a8 != 8) {
a3->orientation = a8;
v15 = a3;
}
v15->removeObject();
this->fun_4ECEB0(a3, a2_x, arg4_y);
this->fun_4EF5E0(a3);
this->RoomManager_cpp_4EDFC0((int) a3);
a3->sub_4E4480();
if ((BYTE) a4_roomTypeId == 8 || (BYTE) a4_roomTypeId == 17 || (BYTE) a4_roomTypeId == 22)
((CPlayer *) sceneObjects[(unsigned __int16) a5_playerId])->sub_4BA720(a2_x, arg4_y);
return arg4_ya;
}


const char *CRoom_typeId_toString(int ty) {
switch (ty) {
#define _CRoom_typeId_toString(id, pascalName) case CRoom_typeId_##pascalName: return #pascalName;
CRoom_types(_CRoom_typeId_toString)
}
return "Unknown";
}
8 changes: 4 additions & 4 deletions src/dk2/MyComputerPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace dk2 {
v59_loc.x = (v29_locX << 12) + 2048;
CWorld *fA_world = cp->world;
v59_loc.y = (v30_locY << 12) + 2048;
if ((fA_world->v_getMapElem_2(&v59_loc)->f8 & 0xFFF) != cp->cplayer->f0_tagId) {
if ((fA_world->v_getMapElem_2(&v59_loc)->_playerId & 0xFFF) != cp->cplayer->f0_tagId) {
unsigned int v71_locX = 0;
unsigned int v69_locY = 0;
int v32_respondIdx = (cp->flags >> 14) & 0xF;
Expand All @@ -129,7 +129,7 @@ namespace dk2 {
if ((v42_cworld->cmap.pNavigationSystem->map.ptr_ui8[
v73_locY * v42_cworld->cmap.pNavigationSystem->map.width + v33_locX] & 8) == 0
&& !v43_mapElement->sub_454110()
&& (v43_mapElement->f8 & 0xFFF) == cp->cplayer->f0_tagId) {
&& (v43_mapElement->_playerId & 0xFFF) == cp->cplayer->f0_tagId) {
v71_locX = v33_locX;
v69_locY = v73_locY;
v74_whileBool = false;
Expand All @@ -154,7 +154,7 @@ namespace dk2 {
v73_locY * v48_cworld->cmap.pNavigationSystem->map.width +
v44_locX] & 8) == 0
&& !v49_mapElem->sub_454110()
&& (v49_mapElem->f8 & 0xFFF) == cp->cplayer->f0_tagId) {
&& (v49_mapElem->_playerId & 0xFFF) == cp->cplayer->f0_tagId) {
break;
}
}
Expand All @@ -179,7 +179,7 @@ namespace dk2 {
v73_locY * v45_cworld->cmap.pNavigationSystem->map.width +
v44_locX] & 8) == 0
&& !v46_mapElem->sub_454110()
&& (v46_mapElem->f8 & 0xFFF) == cp->cplayer->f0_tagId) {
&& (v46_mapElem->_playerId & 0xFFF) == cp->cplayer->f0_tagId) {
break;
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/dk2/button/CTextInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by DiaLight on 01.10.2024.
//
#include "dk2/button/CTextInput.h"
#include "dk2/button/ButtonCfg.h"
#include "dk2_functions.h"
#include "dk2_globals.h"
#include "patches/micro_patches.h"


int dk2::CTextInput::fun_52AA10_configure(ButtonCfg *a2_cfg) {
void *v2_strId = a2_cfg->var16;
if (v2_strId) {
unsigned __int8 *MbString = MyMbStringList_idx1091_getMbString((unsigned int) v2_strId);
MBToUni_convert(MbString, this->str2, 128);
} else {
this->str2[0] = 0;
}
int f1A_inputLimit = (int) a2_cfg->var1A;
if (f1A_inputLimit == -1) {
if (MyResources_instance.playerCfg.kbLayoutId == 17)
this->f27C_inputLimit = 11;
else
this->f27C_inputLimit = 16;
} else {
if(max_host_port_number_fix::enabled) {
if(this->f70_idx == 0x212) { // port number
f1A_inputLimit++;
}
}
this->f27C_inputLimit = f1A_inputLimit;
}
this->field_280 = 0;
this->field_284 = (unsigned __int16) a2_cfg->idxHigh == 1;
memset(this->str1, 0, sizeof(this->str1));
this->field_288 = ((int) a2_cfg->idxHigh & 0xFFFF0000) == 0x10000;
return 0;
}
43 changes: 43 additions & 0 deletions src/dk2/room_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Created by DiaLight on 01.10.2024.
//

#ifndef FLAME_ROOM_TYPE_H
#define FLAME_ROOM_TYPE_H

#define CRoom_types(cb) \
cb(1, Treasury)\
cb(2, unk_2)\
cb(3, Entrance)\
cb(4, Hatchery)\
cb(5, DungeonHeart)\
cb(6, Library)\
cb(7, unk_7)\
cb(8, WoodenBridge) /* _DWORD field_49_union_start: FlagToBurn */\
cb(9, GuardPost)\
cb(10, Workshop)\
cb(11, Prison)\
cb(12, TortureRoom)\
cb(13, Temple)\
cb(14, Graveyard)\
cb(15, Casino)\
cb(16, CombatPit)\
cb(17, _StoneBridge) /* _DWORD field_49_union_start: FlagToBurn*/\
cb(18, unk_18)\
cb(19, unk_19)\
cb(20, unk_20)\
cb(21, HeroGateFrontEnd)\
cb(22, unk_22)\
cb(23, unk_23)\
cb(24, MercenaryGate)\
cb(25, HeroPortal)\
cb(26, Crypt)


enum CRoom_typeId {
#define _CRoom_typeId(id, pascalName) CRoom_typeId_##pascalName = id,
CRoom_types(_CRoom_typeId)
};
const char *CRoom_typeId_toString(int ty);

#endif //FLAME_ROOM_TYPE_H
Empty file added src/patches/dev/bridge_burn.txt
Empty file.
Empty file added src/patches/dev/state_arays.txt
Empty file.
Empty file added src/patches/dev/zoom_path.txt
Empty file.
11 changes: 6 additions & 5 deletions src/patches/gog_patch_dll/gog_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "gog_globals.h"
#include "gog_debug.h"

bool gog::RtGuiView_fix::enable = true;
bool gog::RegistryConfig_patch::enable = true;
bool gog::parseCommandLine_patch::enable = true;
bool gog::SurfaceHolder_setTexture_patch::enable = true;
bool gog::enable = true;
bool gog::RtGuiView_fix::enable = gog::enable && true;
bool gog::RegistryConfig_patch::enable = gog::enable && true;
bool gog::parseCommandLine_patch::enable = gog::enable && true;
bool gog::SurfaceHolder_setTexture_patch::enable = gog::enable && true;

bool gog::BullfrogWindow_proc_patch::enable = true;
bool gog::BullfrogWindow_proc_patch::enable = gog::enable && true;
bool gog::BullfrogWindow_proc_patch::window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
if (!enable) return false;
switch (Msg) {
Expand Down
2 changes: 0 additions & 2 deletions src/patches/gog_patch_dll/gog_patch_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using namespace gog;

bool gog::enable = true;

void _gog_print(const char *msg) {
char msg_buf[1024];
wsprintfA(msg_buf, "[GOG] %s\n", msg);
Expand Down
2 changes: 2 additions & 0 deletions src/patches/micro_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bool response_to_threat_fix::enabled = true;
bool use_wasd_by_default_patch::enabled = true;
bool print_game_start_errors::enabled = true;
bool creatures_setup_lair_fix::enabled = true;
bool wooden_bridge_burn_fix::enabled = true;
bool max_host_port_number_fix::enabled = true;

void use_wasd_by_default_patch::useAlternativeName(LPCSTR &lpValueName) {
if(!use_wasd_by_default_patch::enabled) return;
Expand Down
8 changes: 8 additions & 0 deletions src/patches/micro_patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ namespace creatures_setup_lair_fix {
extern bool enabled;
}

namespace wooden_bridge_burn_fix {
extern bool enabled;
}

namespace max_host_port_number_fix {
extern bool enabled;
}

namespace use_wasd_by_default_patch {
extern bool enabled;
void useAlternativeName(LPCSTR &lpValueName);
Expand Down
2 changes: 1 addition & 1 deletion src/patches/replace_mouse_dinput_to_user32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void move_mouse(DWORD offs, DWORD value) {

// MouseXyzDxAction *action = this->listXYZ.getOrCreateUnhandled();
auto *action = (dk2::MouseXyzDxAction *) new char[sizeof(dk2::MouseXyzDxAction)];
*(void **) action = &dk2::MouseRgbDxAction::vftable;
*(void **) action = &dk2::MouseXyzDxAction::vftable;
xyzActionsInProgress.push_back(action);

action->value = value; // relative or absolute motion
Expand Down
Loading

0 comments on commit 6082568

Please sign in to comment.