Debian Codegraph @

main/steam_tracker.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* steam_tracker.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #if defined(STEAMAPI_ENABLED)
32
33 #include "steam_tracker.h"
34
35 #include "core/io/file_access.h"
36
37 // https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
38
39 SteamTracker::SteamTracker() {
40 String path;
41 if (OS::get_singleton()->has_feature("linuxbsd")) {
42 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libsteam_api.so");
43 if (!FileAccess::exists(path)) {
44 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../lib").path_join("libsteam_api.so");
45 if (!FileAccess::exists(path)) {
46 return;
47 }
48 }
49 } else if (OS::get_singleton()->has_feature("windows")) {
50 if (OS::get_singleton()->has_feature("64")) {
51 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("steam_api64.dll");
52 } else {
53 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("steam_api.dll");
54 }
55 if (!FileAccess::exists(path)) {
56 return;
57 }
58 } else if (OS::get_singleton()->has_feature("macos")) {
59 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("libsteam_api.dylib");
60 if (!FileAccess::exists(path)) {
61 path = OS::get_singleton()->get_executable_path().get_base_dir().path_join("../Frameworks").path_join("libsteam_api.dylib");
62 if (!FileAccess::exists(path)) {
63 return;
64 }
65 }
66 } else {
67 return;
68 }
69
70 Error err = OS::get_singleton()->open_dynamic_library(path, steam_library_handle);
71 if (err != OK) {
72 steam_library_handle = nullptr;
73 return;
74 }
75 print_verbose("Loaded SteamAPI library");
76
77 void *symbol_handle = nullptr;
78 err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_InitFlat", symbol_handle, true); // Try new API, 1.59+.
79 if (err != OK) {
80 err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_Init", symbol_handle); // Try old API.
81 if (err != OK) {
82 return;
83 }
84 steam_init_function = (SteamAPI_InitFunction)symbol_handle;
85 } else {
86 steam_init_flat_function = (SteamAPI_InitFlatFunction)symbol_handle;
87 }
88
89 err = OS::get_singleton()->get_dynamic_library_symbol_handle(steam_library_handle, "SteamAPI_Shutdown", symbol_handle);
90 if (err != OK) {
91 return;
92 }
93 steam_shutdown_function = (SteamAPI_ShutdownFunction)symbol_handle;
94
95 if (steam_init_flat_function) {
96 char err_msg[1024] = {};
97 steam_initialized = (steam_init_flat_function(&err_msg[0]) == SteamAPIInitResult_OK);
98 } else if (steam_init_function) {
99 steam_initialized = steam_init_function();
100 }
101 }
102
103 SteamTracker::~SteamTracker() {
104 if (steam_shutdown_function && steam_initialized) {
105 steam_shutdown_function();
106 }
107 if (steam_library_handle) {
108 OS::get_singleton()->close_dynamic_library(steam_library_handle);
109 }
110 }
111
112 #endif // STEAMAPI_ENABLED