Skip to content

Commit

Permalink
changed build approach from full relinking to exe merging
Browse files Browse the repository at this point in the history
This approach provides the following advantages:
 avoid false positive references
 preserve va addresses of original functions
  • Loading branch information
DiaLight committed Sep 7, 2024
1 parent 46e5b0c commit b084e38
Show file tree
Hide file tree
Showing 20 changed files with 1,249 additions and 222 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ venv.bak/
/mapping/ida/entry.py
**/genlib/*.exp
**/genlib/*.lib
**/genlib/*.def
**/genlib/*.map
**/delinked/*.obj
**/delinked/*.obj.map
/tools/PEview.exe
Expand Down
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,3 @@ if(CONFIGURE_DATE)
endif ()
add_subdirectory(src)

install(TARGETS dkii_flame RUNTIME DESTINATION ".")
install(FILES $<TARGET_PDB_FILE:dkii_flame> DESTINATION ".")
get_target_property(_target_map_file dkii_flame TARGET_MAP_FILE)
install(FILES ${_target_map_file} DESTINATION ".")

75 changes: 0 additions & 75 deletions how_it_works.md

This file was deleted.

76 changes: 0 additions & 76 deletions how_it_works_ru.md

This file was deleted.

3 changes: 2 additions & 1 deletion libs/dkii_exe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

add_subdirectory(delinked)
#add_subdirectory(delinked)
add_subdirectory(genlib)


set(API_HEADERS
Expand Down
39 changes: 39 additions & 0 deletions libs/dkii_exe/genlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
find_program(LIB_PROGRAM lib)
find_program(DUMPBIN_PROGRAM dumpbin)

set(GENLIB_LIB dkii.lib)

set(ABS_GENLIB_LIB ${GENLIB_LIB})
list(TRANSFORM ABS_GENLIB_LIB PREPEND "${CMAKE_CURRENT_LIST_DIR}/")

#get_target_property(GENAPI_SRCS genlib_dkii SOURCES)
#get_target_property(SOURCE_DIR genlib_dkii SOURCE_DIR)
#set(ABS_GENAPI_SRCS ${GENAPI_SRCS})
#list(TRANSFORM ABS_GENAPI_SRCS PREPEND "${SOURCE_DIR}/")
add_custom_command(
OUTPUT ${ABS_GENLIB_LIB} ${CMAKE_CURRENT_LIST_DIR}/dkii_symbols.map
# COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_HOME_DIRECTORY}/mapping/ida
# ${Python3_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/tools/genlib_dkii/main.py
COMMAND $<TARGET_FILE:genlib_dkii>
-sgmap_file ${CMAKE_HOME_DIRECTORY}/mapping/DKII_EXE_v170.sgmap
-def_file ${CMAKE_CURRENT_LIST_DIR}/dkii.def
-replace_globals ${CMAKE_HOME_DIRECTORY}/src/replace_globals.map
-exp_file ${CMAKE_CURRENT_LIST_DIR}/dkii_exp.def
-map_file ${CMAKE_CURRENT_LIST_DIR}/dkii_symbols.map
COMMAND cmd /C ${CMAKE_HOME_DIRECTORY}/tools/genlib/gen_lib.bat
${LIB_PROGRAM} ${CMAKE_HOME_DIRECTORY}/libs/dkii_exe/genlib/dkii.def ${ABS_GENLIB_LIB}
DEPENDS
# ${ABS_GENAPI_SRCS}
${CMAKE_HOME_DIRECTORY}/mapping/DKII_EXE_v170.sgmap
${CMAKE_HOME_DIRECTORY}/src/replace_globals.map
COMMENT "genlib DKII.EXE"
)


set(TARGET dkii_genlib)
add_library(${TARGET} INTERFACE
${GENLIB_LIB} # make target depend on lib file building
)
target_link_libraries(${TARGET} INTERFACE ${GENLIB_LIB}) # make target share lib dependency with others
target_link_directories(${TARGET} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) # make other targets able to find lib file

14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
Flame is a new approach to modifying compiled code Dungeon Keeper 2

Difference from the previous implementation(https://github.com/DiaLight/Ember):
* Ember converts `DKII.EXE` to `dk2.dll` and performs memory dot patches on it after the code has been loaded into memory.
* Flame parses `DKII.EXE` into `msvc` compatible `.obj` files. These files are replaced with other `.obj` files. Then they are compiled back into `DKII-Flame.EXE`
Flame recompiles some functions of `DKII.EXE` into a separate `.exe` file.
Then it merges this file with the original `.exe` file, replacing the references to
the original functions with the references to recompiled functions.
Recompiled functions are supplemented with switchable changes that fix some game bugs

For a more detailed description of how Flame works, read `how_it_works.md`
[Earlier](https://github.com/DiaLight/Flame/tree/46e5b0c1df93060bd01a83bb6d14d064e9c8c3dc "Full relinking approach"), this project implemented an approach to fully relinking `DKII.EXE`,
which contains false positive references that caused new bugs.

The latest build can be taken from the github actions

How to install:
- copy DKII-Flame-1.7.0-*.exe from github actions to game directory (no need rename to DKII-DX.exe or DKII.exe. exe name does not matter)
- copy ddraw.dll from https://github.com/narzoul/DDrawCompat/releases/tag/v0.5.3 to game directory
- copy dinput.dll from https://github.com/elishacloud/dinputto8/releases/tag/v1.0.54.0 to game directory
- (optional, but recommended) copy ddraw.dll from https://github.com/narzoul/DDrawCompat/releases/tag/v0.5.3 to game directory
- (optional, but recommended) copy dinput.dll from https://github.com/elishacloud/dinputto8/releases/tag/v1.0.54.0 to game directory
- run DKII-Flame-1.7.0-*.exe

Additional ddraw.dll and dinput.dll are fixing some graphical bugs and i think improve general stability.
Expand Down
Loading

0 comments on commit b084e38

Please sign in to comment.