Skip to content

Commit

Permalink
removed bonus damage based on location
Browse files Browse the repository at this point in the history
decompiled creature damage processing
reduced title screen time
decompiled command line parsing
force enable 32bit everything flag
fixed multiplayer tab by fixing global variable import linking
  • Loading branch information
DiaLight committed Aug 3, 2024
1 parent 266906d commit 6758486
Show file tree
Hide file tree
Showing 12 changed files with 2,290 additions and 1,038 deletions.
2,902 changes: 1,879 additions & 1,023 deletions mapping/DKII_EXE_v170.sgmap

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ How to build:
- `cmake --build .`
- `cmake --install .`
- `copy "..\install\DKII-Flame-<version>.exe" "<Dungeon Keeper2 dir>/DKII-Flame.exe"`

Todo:
- limit fps
- detect no window showing
- add gog_patch
- redirect stdout/stderr
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_executable(${TARGET}
dk2/MyDxKeyboard.cpp
dk2/CFrontEndComponent.cpp
dk2/CGameComponent.cpp
dk2/entities/CCreature.cpp

patches/replace_mouse_dinput_to_user32.cpp
patches/use_wheel_to_zoom.cpp
Expand Down Expand Up @@ -46,6 +47,7 @@ target_compile_options(${TARGET} PRIVATE
/Gw # Optimize Global Data
/GS-
/Gz # use __stdcall by default
/wd4624 # Suppress warning destructor was implicitly defined as deleted
)
target_link_options(${TARGET} PRIVATE /OPT:NOREF)
target_link_options(${TARGET} PRIVATE /MAP) # generate msvc mapping file for exe
Expand Down
11 changes: 8 additions & 3 deletions src/dk2/CFrontEndComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ void dk2::CFrontEndComponent::showTitleScreen() {
MyGame_instance.prepareScreen();
if ( MyDdSurface_addRef(&this->titleScreen.dd_surf, 0) )
MyDdSurface_release(&status, &this->titleScreen.dd_surf);
// DWORD waitEnd = getTimeMs() + 10000;
DWORD waitEnd = getTimeMs() + 3000; // 10 seconds is too much
while ( getTimeMs() <= waitEnd && !skippable_title_screen::skipKeyPressed() ) ;

if(!skippable_title_screen::enabled) {
DWORD waitEnd = getTimeMs() + 10000;
while ( getTimeMs() <= waitEnd ) ;
} else {
DWORD waitEnd = getTimeMs() + skippable_title_screen::waiting_time;
while ( getTimeMs() <= waitEnd && !skippable_title_screen::skipKeyPressed() ) ;
}
MyGame_instance.prepareScreen();
}
}
6 changes: 3 additions & 3 deletions src/dk2/CGameComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
if ( !v4 ) return 0;
} else if(!MyResources_instance.gameCfg.useFe2d_unk1) {
CHAR MultiByteStr[64];
if(!unicodeToUtf8(MyResources_instance.gameCfg.arr64, MultiByteStr, 64)) return 0;
if(!unicodeToUtf8(MyResources_instance.gameCfg.levelName, MultiByteStr, 64)) return 0;
CWorld_instance.showLoadingScreen();
CWorld_instance.releaseSurface();
CWorld_instance.fun_511180();
Expand Down Expand Up @@ -301,8 +301,8 @@ dk2::CGameComponent *dk2::CGameComponent::mainGuiLoop() {
MyResources_instance.gameCfg.useFe3d = 1;
MyResources_instance.gameCfg.useFe_unk3 = MyResources_instance.gameCfg.useFe;
MyResources_instance.gameCfg.useFe = 5;
wcsncpy(MyResources_instance.gameCfg.arr64, L"FrontEnd3DLevel", 64u);
MyResources_instance.gameCfg.arr64[63] = 0;
wcsncpy(MyResources_instance.gameCfg.levelName, L"FrontEnd3DLevel", 64u);
MyResources_instance.gameCfg.levelName[63] = 0;
MyResources_instance.gameCfg.hasSaveFile = 0;
MyResources_instance.gameCfg.useFe_unkTy = 3;
return &CGameComponent_instance;
Expand Down
190 changes: 190 additions & 0 deletions src/dk2/entities/CCreature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
//
// Created by DiaLight on 02.08.2024.
//

#include "dk2/entities/CCreature.h"
#include "dk2/entities/CObject.h"
#include "dk2/entities/CPlayer.h"
#include "dk2/entities/CDoor.h"
#include "dk2/entities/CTrap.h"
#include "dk2/entities/data/MyCreatureDataObj.h"
#include "dk2/entities/data/MyDoorDataObj.h"
#include "dk2/entities/data/MyTrapDataObj.h"
#include "dk2/entities/data/MyObjectDataObj.h"
#include "dk2_globals.h"
#include "dk2_functions.h"
#include "patches/micro_patches.h"


#define StateFlags1_InHand 0x00000001
#define StateFlags1_ContributesToPortalLimit 0x00000002
#define StateFlags1_AttackAbnormalTargets 0x00000004
#define StateFlags1_RebelActive 0x00000008
#define StateFlags1_RebelLeader 0x00000010
#define StateFlags1_DeadBodyOnDestroy 0x00000020
#define StateFlags1_LeaveNoTrace 0x00000040
#define StateFlags1_Possessed 0x00000080
#define StateFlags1_HeldByPossessed 0x00000100
#define StateFlags1_ThrownByPossessed 0x00000200
#define StateFlags1_BeingElectrocuted 0x00000400
#define StateFlags1_VampireIsBat 0x00000800
#define StateFlags1_Creeping 0x00001000
#define StateFlags1_Praying 0x00002000
#define StateFlags1_Leaving 0x00004000
#define StateFlags1_CombatPitFighter 0x00008000
#define StateFlags1_CannotLeaveHealthLoss 0x00010000
#define StateFlags1_IgnoringDoors 0x00020000
#define StateFlags1_IgnoringLockedRegion 0x00040000
#define StateFlags1_CheckingAllDoors 0x00080000
#define StateFlags1_CallToArmsOn 0x00100000
#define StateFlags1_CreatureDying 0x00200000
#define StateFlags1_FightProcessCounter 0x00400000
#define StateFlags1_WasLastDroppedOnARoom 0x04000000
#define StateFlags1_ShouldDelayGetUp 0x08000000
#define StateFlags1_FlyingCreatureMovingUp 0x10000000
#define StateFlags1_LeavingLava 0x20000000
#define StateFlags1_SkeletonFromSkeletonArmy 0x40000000
#define StateFlags1_SniperMode 0x80000000

#define StateFlags2_IsHypnotised 0x00000001
#define StateFlags2_AnimBackwards 0x00000002
#define StateFlags2_CantBeResurrected 0x00000004
#define StateFlags2_InfluencedByPossessed 0x00000008
#define StateFlags2_HasBeenConverted 0x00000010
#define StateFlags2_SkipNextPayment 0x00000020
#define StateFlags2_IsAttackable 0x00000040
#define StateFlags2_DestroysRooms 0x00000080
#define StateFlags2_IsTool 0x00000100
#define StateFlags2_IsMercenary 0x00000200
#define StateFlags2_HasBeenKnockedOut 0x00000400
#define StateFlags2_DieInstantly 0x00000800
#define StateFlags2_PlayInstanceAnimation 0x00001000
#define StateFlags2_CasinoGamblingFearless 0x00002000
#define StateFlags2_TortureVoluntary 0x00004000
#define StateFlags2_IsHasted 0x00008000
#define StateFlags2_IsSlowed 0x00010000
#define StateFlags2_IsOneShotReaper 0x00040000
#define StateFlags2_ReaperComplete 0x00080000
#define StateFlags2_Fleeing 0x00100000
#define StateFlags2_InWater 0x00200000



int dk2::CCreature::processDealDamage() {
MyCreatureDataObj *f370_creatureData = this->creatureData;
this->stateFlags2 &= ~StateFlags2_PlayInstanceAnimation;
if(((unsigned int)f370_creatureData->flags >> 29) & 1) { // maybe can play animation
this->stateFlags2 |= StateFlags2_PlayInstanceAnimation;
}
if ( this->stateFlags & StateFlags1_Possessed ) {
int v4 = f370_creatureData->f5CA;
if ( g_pWorld->getGameTick() <= this->inst.startTime + v4 - 1 ) return 1;
}
int fC_data1 = this->inst.data1;
if ( !sceneObjectsPresent[fC_data1] ) return 0;
CPhysicalThing *v7_target = (CPhysicalThing *)sceneObjects[fC_data1];
if (v7_target->f12_mapWhoType == 2 ) return 0;
int v8_damage = -this->creatureData->sub_494D00(this);
if ( !v7_target->v_f34() ) return 0;
Vec3i f16_pos;
memset(&f16_pos, 0, sizeof(f16_pos));
int v25;
if ( !g_pWorld->profiler->c_bridge->v_f10C(this, 0, &f16_pos, &v25)) f16_pos = v7_target->f16_pos;
if (v7_target->fE_type == 0 ) { // CCreature
CCreature *targetCreature = (CCreature *) v7_target;
if (targetCreature->fun_4E0460() && targetCreature->lairId ) {
CObject *v9_object = (CObject *)sceneObjects[targetCreature->lairId];
if ( v9_object->typeId == 23 ) {
targetCreature->cstate.fun_476D30(84, 0);
} else {
v9_object->renderInfo.fAF = v9_object->renderInfo.fAF & 0xFE ^ 1;
targetCreature->renderInfo.fAF = targetCreature->renderInfo.fAF & 0xFE ^ 1;
int f1C_type = targetCreature->inst.type;
BOOL v11 = f1C_type != 21 && f1C_type != 0;
if ( v11 && g_Obj6E4198_arr[f1C_type].f1C )
targetCreature->inst.sub_4966A0();
Vec3i v27;
v27.x = v9_object->f16_pos.x;
v27.y = v9_object->f16_pos.y;
v27.z = v9_object->f16_pos.z;
unsigned __int16 fF0_angle = v9_object->fF0_angle;
int v14 = (-410 * fF0_angle) & 0x7FF;
v27.x += g_angle2048_to_x[v14] >> 16;
v27.y += g_angle2048_to_y[v14] >> 16;
targetCreature->fun_4B5560(&v27);
targetCreature->fun_48AD30(1);
}
}
if ( targetCreature->invulnerableTimer ) return 0;
this->sub_4998A0(this->creatureData->f77A, targetCreature->creatureData->f685, &f16_pos);
if ( (this->creatureData->flags & 0x4000) != 0
&& targetCreature->f24_playerId == this->f24_playerId ) {
this->fun_48F3F0();
this->fun_48AD30(242);
targetCreature->stateFlags &= ~StateFlags1_DeadBodyOnDestroy;
targetCreature->v_f20();
return 0;
}
if(!disable_bonus_damage_based_on_location::enabled) {
unsigned __int16 v24_angle2048 = asm_calcNegYAngle2048(
this->f16_pos.x - targetCreature->f16_pos.x,
this->f16_pos.y - targetCreature->f16_pos.y) & 0x7FF;
if ( v24_angle2048 > 0x3FFu )
v24_angle2048 = 2046 - v24_angle2048;
int v17_angleDiv20 = (v24_angle2048 & 0x3FF) / 20;
int v18_newDamage = v8_damage;
if ( v17_angleDiv20 > 15 ) {
v18_newDamage = v8_damage + v8_damage * v17_angleDiv20 / 100;
}
// printf("%d:%d:%d->%d:%d:%d damage=%d(+%d) loc:{%d,%d} -> {%d,%d} vec:{%d,%d} a:%d(%d) degrees:%.2f\n",
// this->f24_playerId, this->f0_tagId, this->f3C_health,
// targetCreature->f24_playerId, targetCreature->f0_tagId, targetCreature->f3C_health,
// -v8_damage, -(v18_newDamage - v8_damage),
// this->f16_pos.x, this->f16_pos.y,
// targetCreature->f16_pos.x, targetCreature->f16_pos.y,
// this->f16_pos.x - targetCreature->f16_pos.x, this->f16_pos.y - targetCreature->f16_pos.y,
// v24_angle2048, v17_angleDiv20, (float) v24_angle2048 / 2048 * 360
// );
v8_damage = v18_newDamage;
}
}
if (v7_target->fE_type == 4 ) // CDoor
this->sub_4998A0(this->creatureData->f77A, ((CDoor *) v7_target)->typeData->fB3, &f16_pos);
if (v7_target->fE_type == 3 ) // CTrap
this->sub_4998A0(this->creatureData->f77A, ((CTrap *) v7_target)->typeData->fBF, &f16_pos);
if (v7_target->fE_type == 2 ) // CObject
this->sub_4998A0(this->creatureData->f77A, ((CObject *) v7_target)->typeObj->f11C, &f16_pos);
if ( v8_damage ) {
CPlayer *f26_pPlayer_owner = this->f26_pPlayer_owner;
char v20 = f26_pPlayer_owner->cryptPowersPeopleActive[6];
if ( v20 > 0 )
v8_damage = 10 * v8_damage * (v20 + 10) / 100;
char v21 = f26_pPlayer_owner->cryptPowersPeopleActive[7];
if ( v21 > 0 )
v8_damage = v8_damage * (15 * v21 + 100) / 100;
if (this->typeId == 19 && v7_target->fE_type == 0) { // CCreature
CCreature *targetCreature = (CCreature *) v7_target;
targetCreature->stateFlags2 |= StateFlags2_CantBeResurrected;
targetCreature->processTakeDamage(v8_damage, this->f24_playerId, 0);
targetCreature->stateFlags2 &= ~StateFlags2_CantBeResurrected;
} else {
v7_target->processTakeDamage(v8_damage, this->f24_playerId, 0);
}
if ((this->creatureData->flags & 0x4000) != 0 && v7_target->fE_type == 0) { // CCreature
CCreature *targetCreature = (CCreature *) v7_target;
if(targetCreature->typeId == 28) {
targetCreature->fun_490120(v8_damage, this->f24_playerId, 0);
}
}
}
if ( (this->creatureData->flags & 0x4000) != 0 ) {
if ( v7_target->v_f28() )
this->fun_48AD30(239);
}
this->field_2A = MySound_ptr->v_fun_5678F0(
this->field_2A,
this->creatureData->f6E3,
219,
&this->f16_pos);
return 0;
}
Loading

0 comments on commit 6758486

Please sign in to comment.