From 5dd2d8119b961ae78c1a6fd0d00bd661d7c2b089 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 24 Feb 2016 13:21:37 -0300 Subject: [PATCH] Add initial support to Steam API (just inform to Steam that we're running) --- CMakeLists.txt | 1 + src/CMakeLists.txt | 4 ++ src/app/CMakeLists.txt | 5 +++ src/app/app.cpp | 8 ++++ src/steam/CMakeLists.txt | 5 +++ src/steam/LICENSE.txt | 20 ++++++++++ src/steam/README.md | 9 +++++ src/steam/steam.cpp | 79 ++++++++++++++++++++++++++++++++++++++++ src/steam/steam.h | 25 +++++++++++++ 9 files changed, 156 insertions(+) create mode 100644 src/steam/CMakeLists.txt create mode 100644 src/steam/LICENSE.txt create mode 100644 src/steam/README.md create mode 100644 src/steam/steam.cpp create mode 100644 src/steam/steam.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e561c52c1..5eeea2138 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" o option(ENABLE_UPDATER "Enable automatic check for updates" on) option(ENABLE_WEBSERVER "Enable support to run a webserver (for HTML5 gamedev)" off) option(ENABLE_TRIAL_MODE "Compile the trial version" off) +option(ENABLE_STEAM "Compile with Steam library" off) option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off) set(CUSTOM_WEBSITE_URL "" CACHE STRING "Enable custom local webserver to check updates") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c03912e3..b7e6d43d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,6 +116,10 @@ if(ENABLE_WEBSERVER) add_subdirectory(webserver) endif() +if(ENABLE_STEAM) + add_subdirectory(steam) +endif() + add_subdirectory(app) ###################################################################### diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index cbbed1fd5..bb99fb60b 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -454,3 +454,8 @@ endif() if(ENABLE_WEBSERVER) target_link_libraries(app-lib webserver-lib) endif() + +if(ENABLE_STEAM) + add_definitions(-DENABLE_STEAM) + target_link_libraries(app-lib steam-lib) +endif() diff --git a/src/app/app.cpp b/src/app/app.cpp index 22c67ab3f..b7298892d 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -76,6 +76,10 @@ #include +#ifdef ENABLE_STEAM + #include "steam/steam.h" +#endif + namespace app { using namespace ui; @@ -600,6 +604,10 @@ void App::run() { // Run the GUI if (isGui()) { +#ifdef ENABLE_STEAM + steam::SteamAPI steam; +#endif + #ifdef ENABLE_UPDATER // Launch the thread to check for updates. app::CheckUpdateThreadLauncher checkUpdate( diff --git a/src/steam/CMakeLists.txt b/src/steam/CMakeLists.txt new file mode 100644 index 000000000..f51ff6771 --- /dev/null +++ b/src/steam/CMakeLists.txt @@ -0,0 +1,5 @@ +# Aseprite +# Copyright (C) 2016 David Capello + +add_library(steam-lib steam.cpp) +target_link_libraries(steam-lib base-lib) diff --git a/src/steam/LICENSE.txt b/src/steam/LICENSE.txt new file mode 100644 index 000000000..9a182c0f3 --- /dev/null +++ b/src/steam/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2016 David Capello + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/steam/README.md b/src/steam/README.md new file mode 100644 index 000000000..0abdf98f8 --- /dev/null +++ b/src/steam/README.md @@ -0,0 +1,9 @@ +# Aseprite Steam Wrapper +*Copyright (C) 2016 David Capello* + +> Distributed under [MIT license](LICENSE.txt) + +This is a way to use the Steam API without linking to the static +`.lib`, so we can avoid including the official `steam_api.dll` in our +own packages (e.g. when we distribute our game outside the Steam +store). diff --git a/src/steam/steam.cpp b/src/steam/steam.cpp new file mode 100644 index 000000000..89ebd158f --- /dev/null +++ b/src/steam/steam.cpp @@ -0,0 +1,79 @@ +// Aseprite Steam Wrapper +// Copyright (c) 2016 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "steam/steam.h" + +#include "base/dll.h" +#include "base/string.h" + +namespace steam { + +typedef bool (*SteamAPI_Init_Func)(); +typedef void (*SteamAPI_Shutdown_Func)(); + +#ifdef _WIN32 + #ifdef _WIN64 + #define STEAM_API_DLL_FILENAME "steam_api64.dll" + #else + #define STEAM_API_DLL_FILENAME "steam_api.dll" + #endif +#elif defined(__APPLE__) + #define STEAM_API_DLL_FILENAME "libsteam_api.dylib" +#else + #define STEAM_API_DLL_FILENAME "libsteam_api.so" +#endif + +class SteamAPI::Impl { +public: + Impl() { + m_steamLib = base::load_dll(STEAM_API_DLL_FILENAME); + if (!m_steamLib) + return; + + auto SteamAPI_Init = base::get_dll_proc(m_steamLib, "SteamAPI_Init"); + if (!SteamAPI_Init) + return; + + if (!SteamAPI_Init()) { + LOG("Steam is not initialized...\n"); + return; + } + + LOG("Steam initialized...\n"); + } + + ~Impl() { + if (!m_steamLib) + return; + + auto SteamAPI_Shutdown = base::get_dll_proc(m_steamLib, "SteamAPI_Shutdown"); + if (SteamAPI_Shutdown) { + LOG("Steam shutdown...\n"); + SteamAPI_Shutdown(); + } + + base::unload_dll(m_steamLib); + } + +private: + base::dll m_steamLib; +}; + +SteamAPI::SteamAPI() + : m_impl(new Impl) +{ +} + +SteamAPI::~SteamAPI() +{ + delete m_impl; +} + +} // namespace steam diff --git a/src/steam/steam.h b/src/steam/steam.h new file mode 100644 index 000000000..907eee58a --- /dev/null +++ b/src/steam/steam.h @@ -0,0 +1,25 @@ +// Aseprite Steam Wrapper +// Copyright (c) 2016 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifndef STEAM_STEAM_H_INCLUDED +#define STEAM_STEAM_H_INCLUDED +#pragma once + +namespace steam { + +class SteamAPI { +public: + SteamAPI(); + ~SteamAPI(); + +private: + class Impl; + Impl* m_impl; +}; + +} // namespace steam + +#endif