Skip to content

Commit 1ececa0

Browse files
committed
Further work on Steam compatibility
1. Adopt changes to dfhooks 2. Install dfhooks_dfhack the `hack` folder, and generate and install an appropriate `dfhooks_dfhack.ini` into the DF folder 3. Adjust RPATH (on Linux) so dfhooks_dfhack.dll can find dfhack.dll 4. Use dfhooks preinit to get the hack base path. Use this path when initializing Core 5. in `getHackPath()`, use the collected hack base path instead of hardcoding `./hack`. 6. Fix at one instance where `hack` was hardcoded outside of `getHackPath` (note: there are others this commit does not fix) 7. Update VersionInfoFactory to use a fs `path` instead of a `string` as its argument
1 parent 7733b73 commit 1ececa0

8 files changed

Lines changed: 38 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,10 @@ set(DFHACK_DATA_DESTINATION hack)
226226

227227
## where to install things (after the build is done, classic 'make install' or package structure)
228228
# the dfhack libraries will be installed here:
229-
if(UNIX)
230-
# put the lib into DF/hack
231-
set(DFHACK_LIBRARY_DESTINATION ${DFHACK_DATA_DESTINATION})
232-
else()
233-
# windows is crap, therefore we can't do nice things with it. leave the libs on a nasty pile...
234-
set(DFHACK_LIBRARY_DESTINATION .)
235-
endif()
229+
230+
# put the lib into DF/hack
231+
# windows will find it because dfhooks will `AddDllDirectory` the hack folder at runtime
232+
set(DFHACK_LIBRARY_DESTINATION ${DFHACK_DATA_DESTINATION})
236233

237234
# external tools will be installed here:
238235
set(DFHACK_BINARY_DESTINATION .)
@@ -267,7 +264,7 @@ if(UNIX)
267264
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i686")
268265
endif()
269266
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
270-
set(CMAKE_INSTALL_RPATH ${DFHACK_LIBRARY_DESTINATION})
267+
set(CMAKE_INSTALL_RPATH "$ORIGIN/${DFHACK_LIBRARY_DESTINATION}")
271268
elseif(MSVC)
272269
# for msvc, tell it to always use 8-byte pointers to member functions to avoid confusion
273270
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vmg /vmm /MP")

depends/dfhooks

library/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ endif()
131131

132132
set(MAIN_SOURCES_WINDOWS
133133
${CONSOLE_SOURCES}
134-
Hooks.cpp
135134
)
136135

137136
if(WIN32)
@@ -453,8 +452,9 @@ if(UNIX)
453452
endif()
454453

455454
install(TARGETS dfhooks_dfhack
456-
LIBRARY DESTINATION .
457-
RUNTIME DESTINATION .)
455+
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
456+
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
457+
458458

459459
# install the main lib
460460
install(TARGETS dfhack
@@ -465,6 +465,12 @@ install(TARGETS dfhack-run dfhack-client binpatch
465465
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
466466
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
467467

468+
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dfhooks_dfhack.ini
469+
CONTENT "${DFHACK_DATA_DESTINATION}/$<TARGET_FILE_NAME:dfhooks_dfhack>")
470+
471+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dfhooks_dfhack.ini
472+
DESTINATION .)
473+
468474
endif(BUILD_LIBRARY)
469475

470476
# install the offset file

library/Core.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace DFHack {
124124

125125
static const std::filesystem::path getConfigDefaultsPath()
126126
{
127-
return Filesystem::getInstallDir() / "hack" / "data" / "dfhack-config-defaults";
127+
return Core::getInstance().getHackPath() / "data" / "dfhack-config-defaults";
128128
};
129129

130130
class MainThread {
@@ -492,7 +492,7 @@ void Core::getScriptPaths(std::vector<std::filesystem::path> *dest)
492492
if (save.size())
493493
dest->emplace_back(df_pref_path / "save" / save / "scripts");
494494
}
495-
dest->emplace_back(df_install_path / "hack" / "scripts");
495+
dest->emplace_back(getHackPath() / "scripts");
496496
for (auto & path : script_paths[2])
497497
dest->emplace_back(path);
498498
for (auto & path : script_paths[1])
@@ -1054,16 +1054,17 @@ void Core::fatal (std::string output, const char * title)
10541054

10551055
std::filesystem::path Core::getHackPath()
10561056
{
1057-
return p->getPath() / "hack";
1057+
return hack_path;
10581058
}
10591059

10601060
df::viewscreen * Core::getTopViewscreen() {
10611061
return getInstance().top_viewscreen;
10621062
}
10631063

1064-
bool Core::InitMainThread() {
1064+
bool Core::InitMainThread(std::filesystem::path path) {
10651065
// this hook is always called from DF's main (render) thread, so capture this thread id
10661066
df_render_thread = std::this_thread::get_id();
1067+
hack_path = path;
10671068

10681069
Filesystem::init();
10691070

@@ -1099,16 +1100,12 @@ bool Core::InitMainThread() {
10991100
}
11001101

11011102
// find out what we are...
1102-
#ifdef LINUX_BUILD
1103-
const char * path = "hack/symbols.xml";
1104-
#else
1105-
const char * path = "hack\\symbols.xml";
1106-
#endif
1103+
std::filesystem::path symbols_path = getHackPath() / "symbols.xml";
11071104
auto local_vif = std::make_unique<DFHack::VersionInfoFactory>();
11081105
std::cerr << "Identifying DF version.\n";
11091106
try
11101107
{
1111-
local_vif->loadFile(path);
1108+
local_vif->loadFile(symbols_path);
11121109
}
11131110
catch(Error::All & err)
11141111
{

library/Hooks.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ static bool disabled = false;
77

88
DFhackCExport const int32_t dfhooks_priority = 100;
99

10+
static std::filesystem::path basepath{"./hack"};
11+
12+
// called by the chainloader before the main thread is initialized and before any other hooks are called.
13+
DFhackCExport void dfhooks_preinit(std::filesystem::path dllpath)
14+
{
15+
basepath = dllpath.parent_path();
16+
}
17+
1018
// called from the main thread before the simulation thread is started
1119
// and the main event loop is initiated
1220
DFhackCExport void dfhooks_init() {
@@ -17,7 +25,7 @@ DFhackCExport void dfhooks_init() {
1725
}
1826

1927
// we need to init DF globals before we can check the commandline
20-
if (!DFHack::Core::getInstance().InitMainThread() || !df::global::game) {
28+
if (!DFHack::Core::getInstance().InitMainThread(basepath) || !df::global::game) {
2129
// we don't set disabled to true here so symbol generation can work
2230
return;
2331
}

library/VersionInfoFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem)
226226
} // method
227227

228228
// load the XML file with offsets
229-
bool VersionInfoFactory::loadFile(string path_to_xml)
229+
bool VersionInfoFactory::loadFile(std::filesystem::path path_to_xml)
230230
{
231-
TiXmlDocument doc( path_to_xml.c_str() );
231+
TiXmlDocument doc( path_to_xml.string().c_str() );
232232
std::cerr << "Loading " << path_to_xml << " ... ";
233233
//bool loadOkay = doc.LoadFile();
234234
if (!doc.LoadFile())

library/include/Core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ namespace DFHack
268268
struct Private;
269269
std::unique_ptr<Private> d;
270270

271-
bool InitMainThread();
271+
bool InitMainThread(std::filesystem::path path);
272272
bool InitSimulationThread();
273273
int Update (void);
274274
int Shutdown (void);
@@ -353,6 +353,8 @@ namespace DFHack
353353

354354
uint32_t unpaused_ms; // reset to 0 on map load
355355

356+
std::filesystem::path hack_path;
357+
356358
friend class CoreService;
357359
friend class ServerConnection;
358360
friend class CoreSuspender;

library/include/VersionInfoFactory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ distribution.
2626
#pragma once
2727

2828
#include <memory>
29+
#include <filesystem>
2930

3031
#include "Export.h"
3132

@@ -38,7 +39,7 @@ namespace DFHack
3839
public:
3940
VersionInfoFactory();
4041
~VersionInfoFactory();
41-
bool loadFile( std::string path_to_xml);
42+
bool loadFile( std::filesystem::path path_to_xml);
4243
bool isInErrorState() const {return error;};
4344
std::shared_ptr<const VersionInfo> getVersionInfoByMD5(std::string md5string) const;
4445
std::shared_ptr<const VersionInfo> getVersionInfoByPETimestamp(uintptr_t timestamp) const;

0 commit comments

Comments
 (0)