build lanchdf with steam sdk

develop
Kelly Kinkade 2023-04-18 05:00:36 -05:00 committed by Kelly Kinkade
parent 649d72e658
commit 150708f21d
4 changed files with 42 additions and 6 deletions

3
.gitignore vendored

@ -80,3 +80,6 @@ tags
# external plugins
/plugins/CMakeLists.custom.txt
# steam api
depends/steam

@ -312,6 +312,19 @@ if(WIN32)
${SDLREAL_DOWNLOAD_DIR}/SDLreal.dll
"5a09604daca6b2b5ce049d79af935d6a")
endif()
# download Steam SDK
set (STEAMAPI_DIR ${dfhack_SOURCE_DIR}/depends/steam/)
download_file("https://partner.steamgames.com/downloads/steamworks_sdk_156.zip"
${STEAMAPI_DIR}/steamworks_sdk_156.zip
"af5a579990dbe5ae4c1b0689260d001b")
file(ARCHIVE_EXTRACT
INPUT ${STEAMAPI_DIR}/steamworks_sdk_156.zip
DESTINATION ${STEAMAPI_DIR})
set(STEAMAPI_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.lib")
set(STEAMAPI_SOURCE_DIR "${STEAMAPI_DIR}/sdk/public/steam")
set(STEAMAPI_SHARED_LIBRARY "${STEAMAPI_DIR}/sdk/redistributable_bin/win64/steam_api64.dll")
endif()
if(APPLE)

@ -1,7 +1,9 @@
project(package_windows)
if(WIN32)
add_executable(launchdf WIN32 launchdf.c)
install(TARGETS launchdf
DESTINATION ${DFHACK_DATA_DESTINATION})
include_directories(${STEAMAPI_SOURCE_DIR})
link_libraries(${STEAMAPI_LIBRARY})
add_executable(launchdf WIN32 launchdf.cpp)
install(TARGETS launchdf DESTINATION ${DFHACK_DATA_DESTINATION})
install(FILES ${STEAMAPI_SHARED_LIBRARY} DESTINATION ${DFHACK_DATA_DESTINATION})
endif()

@ -1,13 +1,17 @@
#include <process.h>
#include <windows.h>
#include "steam_api.h"
const uint32 DFHACK_STEAM_APPID = 2346660;
static BOOL is_running_on_wine() {
static const char *(CDECL *pwine_get_version)(void);
typedef const char* (CDECL wine_get_version)(void);
static wine_get_version* pwine_get_version;
HMODULE hntdll = GetModuleHandle("ntdll.dll");
if(!hntdll)
return FALSE;
pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version");
pwine_get_version = (wine_get_version*) GetProcAddress(hntdll, "wine_get_version");
return !!pwine_get_version;
}
@ -61,6 +65,20 @@ static BOOL launch_direct() {
}
int WINAPI wWinMain(HINSTANCE hi, HINSTANCE hpi, PWSTR cmd, int ns) {
if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) // Replace with your App ID
{
return 1;
}
if (!SteamAPI_Init())
{
printf("Fatal Error - Steam must be running to play this game (SteamAPI_Init() failed).\n");
return 1;
}
return 0;
LPCWSTR err = is_running_on_wine() ? launch_via_steam_posix() : launch_via_steam_windows();
if (err && !launch_direct()) {