diff --git a/.gitignore b/.gitignore index b63594d..4182d65 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,7 @@ /data.pack /.vs/ /.data.db +/steamworks_c_wrapper/_build +/steamworks_c_wrapper/sdk *.swp *~ diff --git a/CMakeLists.txt b/CMakeLists.txt index 3515bce..793ee43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,14 @@ configure_file( "${PROJECT_BINARY_DIR}/config.h" ) +if (EXISTS "${PROJECT_SOURCE_DIR}/steamworks_c_wrapper/sdk") + set(STEAM 1) +endif() + +if (STEAM) + add_subdirectory(steamworks_c_wrapper) +endif() + if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") set(CLANG 1) elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") @@ -123,6 +131,9 @@ if (NOT MSVC) endif (NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") +if (STEAM) + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSTEAM_BUILD") +endif () if (NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__FNAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") else (NOT MSVC) @@ -195,6 +206,12 @@ target_link_libraries(breakhack ${SDL2_MIXER_LIBRARY} ) +if (STEAM) + target_link_libraries(breakhack + steamworks_c_wrapper + ) +endif () + if (NOT PHYSFS_FOUND) target_link_libraries(breakhack physfs-static @@ -301,6 +318,12 @@ if (WIN32) ${CMAKE_SOURCE_DIR}/bin/SDL2_ttf.dll ${CMAKE_SOURCE_DIR}/bin/zlib1.dll ) + if (STEAM) + SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS + ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} + ${STEAMWORKS_LIBRARY} + ) + endif () endif (WIN32) include(InstallRequiredSystemLibraries) diff --git a/steam/steamworks_api_wrapper.c b/steam/steamworks_api_wrapper.c new file mode 100644 index 0000000..21060e3 --- /dev/null +++ b/steam/steamworks_api_wrapper.c @@ -0,0 +1,21 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "steamworks_api_wrapper.h" + diff --git a/steam/steamworks_api_wrapper.h b/steam/steamworks_api_wrapper.h new file mode 100644 index 0000000..121688b --- /dev/null +++ b/steam/steamworks_api_wrapper.h @@ -0,0 +1,20 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt new file mode 100644 index 0000000..4d10aea --- /dev/null +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.1) +project(steamworks_c_wrapper) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif () + +include(cmake/FindSTEAMWORKS.cmake) + +if (BIT_32) + MESSAGE("COMPILING 32 BIT") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -m32") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_DEBUG} -m32") +endif() + +set (Windows 0) +set (Apple 0) +if (WIN32) + set(Windows 1) +elseif (APPLE) + set(Apple 1) +else() + #Linux +endif () + +include_directories(${STEAMWORKS_INCLUDE_DIR}) + +add_library(steamworks_c_wrapper + src/steamworks_c_wrapper + ) + +target_link_libraries(steamworks_c_wrapper ${STEAMWORKS_LIBRARY}) diff --git a/steamworks_c_wrapper/cmake/FindSTEAMWORKS.cmake b/steamworks_c_wrapper/cmake/FindSTEAMWORKS.cmake new file mode 100644 index 0000000..87b6fd3 --- /dev/null +++ b/steamworks_c_wrapper/cmake/FindSTEAMWORKS.cmake @@ -0,0 +1,32 @@ +# - Try to find the steamworks library +# +# Once done, this will define: +# +# STEAMWORKS_INCLUDE_DIR - the Steamworks include directory +# STEAMWORKS_LIBRARIES - The libraries needed to use Steamworks + +find_path(STEAMWORKS_INCLUDE_DIR + NAMES + steam_api.h + PATHS + ${PROJECT_SOURCE_DIR}/sdk/public/steam/ +) + +if (WIN32) + find_library(STEAMWORKS_LIBRARY + NAMES + steam_api + PATHS + ${PROJECT_SOURCE_DIR}/sdk/redistributable_bin/ + ) +else() + find_library(STEAMWORKS_LIBRARY + NAMES + steam_api + PATHS + ${PROJECT_SOURCE_DIR}/sdk/redistributable_bin/linux64/ + ) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(STEAMWORKS DEFAULT_MSG STEAMWORKS_INCLUDE_DIR STEAMWORKS_LIBRARY) diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp new file mode 100644 index 0000000..16c0534 --- /dev/null +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -0,0 +1,25 @@ +#include + +extern "C" { +#include "steamworks_c_wrapper.h" +} + +extern "C" void c_SteamAPI_Init() +{ + SteamAPI_Init(); +} + +extern "C" void c_SteamAPI_Shutdown() +{ + SteamAPI_Shutdown(); +} + +extern "C" bool c_SteamUserStats_RequestCurrentStats() +{ + return SteamUserStats()->RequestCurrentStats(); +} + +extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName) +{ + return SteamUserStats()->SetAchievement(pchName); +} diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h new file mode 100644 index 0000000..afd3161 --- /dev/null +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -0,0 +1,31 @@ +#pragma once + +enum Achievements +{ + ACH_BAD_DOG = 0, + ACH_THE_DOCTOR_IS_OUT = 1, + ACH_LIGHTS_ON = 2, + ACH_BACK_TO_WORK = 5, +}; + +struct Achievement +{ + Achievements m_eAchievementID; + const char *m_pchAchievementID; + char m_rgchName[128]; + char m_rgchDescription[256]; + bool m_bAchieved; + int m_iIconImage; +}; + +void +c_SteamAPI_Init(); + +bool +c_steam_request_stats(); + +bool +c_steam_set_achievement(const char *id); + +void +c_SteamAPI_Shutdown();