From d19ac5b260d850a82550972019121f3a7d120c65 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 22:56:15 +0200 Subject: [PATCH] - separated the game specific Steam code from the pure backend. --- src/CMakeLists.txt | 1 + src/posix/i_system.h | 55 +--------- src/win32/i_steam.cpp | 224 +++++++++++++++++++++++++++++++++++++++++ src/win32/i_system.cpp | 143 -------------------------- src/win32/i_system.h | 31 ------ 5 files changed, 228 insertions(+), 226 deletions(-) create mode 100644 src/win32/i_steam.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02b4638f7..35cd65592 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -447,6 +447,7 @@ set( PLAT_WIN32_SOURCES win32/i_rawps2.cpp win32/i_xinput.cpp win32/i_main.cpp + win32/i_steam.cpp win32/i_system.cpp win32/i_specialpaths.cpp win32/st_start.cpp diff --git a/src/posix/i_system.h b/src/posix/i_system.h index 09473091e..1988d16be 100644 --- a/src/posix/i_system.h +++ b/src/posix/i_system.h @@ -1,29 +1,3 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// -// 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 http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: -// System specific interface stuff. -// -//----------------------------------------------------------------------------- - - #ifndef __I_SYSTEM__ #define __I_SYSTEM__ @@ -34,9 +8,10 @@ #define __solaris__ 1 #endif -#include "doomtype.h" #include #include +#include "tarray.h" +#include "zstring.h" struct ticcmd_t; struct WadStuff; @@ -51,34 +26,11 @@ void CalculateCPUSpeed(void); unsigned int I_MakeRNGSeed(); -// -// Called by D_DoomLoop, -// called before processing any tics in a frame -// (just after displaying a frame). -// Time consuming syncronous operations -// are performed here (joystick reading). -// Can call D_PostEvent. -// + void I_StartFrame (void); - -// -// Called by D_DoomLoop, -// called before processing each tic in a frame. -// Quick syncronous operations are performed here. -// Can call D_PostEvent. void I_StartTic (void); -// Asynchronous interrupt functions should maintain private queues -// that are read by the synchronous functions -// to be converted into events. - -// Either returns a null ticcmd, -// or calls a loadable driver to build it. -// This ticcmd will then be modified by the gameloop -// for normal input. -ticcmd_t *I_BaseTiccmd (void); - // Print a console string void I_PrintStr (const char *str); @@ -100,7 +52,6 @@ bool I_WriteIniFailed (); class FGameTexture; bool I_SetCursor(FGameTexture *); - static inline char *strlwr(char *str) { char *ptr = str; diff --git a/src/win32/i_steam.cpp b/src/win32/i_steam.cpp new file mode 100644 index 000000000..cf5ccb0c7 --- /dev/null +++ b/src/win32/i_steam.cpp @@ -0,0 +1,224 @@ +/* +** i_system.cpp +** Timers, pre-console output, IWAD selection, and misc system routines. +** +**--------------------------------------------------------------------------- +** Copyright 1998-2009 Randy Heit +** Copyright (C) 2007-2012 Skulltag Development Team +** Copyright (C) 2007-2016 Zandronum Development Team +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** 4. Redistributions in any form must be accompanied by information on how to +** obtain complete source code for the software and any accompanying software +** that uses the software. The source code must either be included in the +** distribution or be available for no more than the cost of distribution plus +** a nominal fee, and must be freely redistributable under reasonable +** conditions. For an executable file, complete source code means the source +** code for all modules it contains. It does not include source code for +** modules or files that typically accompany the major components of the +** operating system on which the executable file runs. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include +#include +#include +#include +#include +#include + +#include + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +#include "hardware.h" +#include "printf.h" + +#include "version.h" +#include "i_sound.h" +#include "resource.h" +#include "stats.h" +#include "v_text.h" +#include "utf8.h" + +#include "d_main.h" +#include "d_net.h" +#include "g_game.h" +#include "i_input.h" +#include "c_dispatch.h" +#include "templates.h" +#include "gameconfigfile.h" +#include "v_font.h" +#include "g_level.h" +#include "doomstat.h" +#include "i_system.h" +#include "bitmap.h" +#include "cmdlib.h" +#include "i_interface.h" + +//========================================================================== +// +// QueryPathKey +// +// Returns the value of a registry key into the output variable value. +// +//========================================================================== + +static bool QueryPathKey(HKEY key, const wchar_t *keypath, const wchar_t *valname, FString &value) +{ + HKEY pathkey; + DWORD pathtype; + DWORD pathlen; + LONG res; + + value = ""; + if(ERROR_SUCCESS == RegOpenKeyEx(key, keypath, 0, KEY_QUERY_VALUE, &pathkey)) + { + if (ERROR_SUCCESS == RegQueryValueEx(pathkey, valname, 0, &pathtype, NULL, &pathlen) && + pathtype == REG_SZ && pathlen != 0) + { + // Don't include terminating null in count + TArray chars(pathlen + 1, true); + res = RegQueryValueEx(pathkey, valname, 0, NULL, (LPBYTE)chars.Data(), &pathlen); + if (res == ERROR_SUCCESS) value = FString(chars.Data()); + } + RegCloseKey(pathkey); + } + return value.IsNotEmpty(); +} + +//========================================================================== +// +// I_GetGogPaths +// +// Check the registry for GOG installation paths, so we can search for IWADs +// that were bought from GOG.com. This is a bit different from the Steam +// version because each game has its own independent installation path, no +// such thing as /SteamApps/common/. +// +//========================================================================== + +TArray I_GetGogPaths() +{ + TArray result; + FString path; + std::wstring gamepath; + +#ifdef _WIN64 + std::wstring gogregistrypath = L"Software\\Wow6432Node\\GOG.com\\Games"; +#else + // If a 32-bit ZDoom runs on a 64-bit Windows, this will be transparently and + // automatically redirected to the Wow6432Node address instead, so this address + // should be safe to use in all cases. + std::wstring gogregistrypath = L"Software\\GOG.com\\Games"; +#endif + + // Look for Ultimate Doom + gamepath = gogregistrypath + L"\\1435827232"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path); // directly in install folder + } + + // Look for Doom II + gamepath = gogregistrypath + L"\\1435848814"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path + "/doom2"); // in a subdirectory + // If direct support for the Master Levels is ever added, they are in path + /master/wads + } + + // Look for Final Doom + gamepath = gogregistrypath + L"\\1435848742"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + // in subdirectories + result.Push(path + "/TNT"); + result.Push(path + "/Plutonia"); + } + + // Look for Doom 3: BFG Edition + gamepath = gogregistrypath + L"\\1135892318"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path + "/base/wads"); // in a subdirectory + } + + // Look for Strife: Veteran Edition + gamepath = gogregistrypath + L"\\1432899949"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path); // directly in install folder + } + + return result; +} + +//========================================================================== +// +// I_GetSteamPath +// +// Check the registry for the path to Steam, so that we can search for +// IWADs that were bought with Steam. +// +//========================================================================== + +TArray I_GetSteamPath() +{ + TArray result; + static const char *const steam_dirs[] = + { + "doom 2/base", + "final doom/base", + "heretic shadow of the serpent riders/base", + "hexen/base", + "hexen deathkings of the dark citadel/base", + "ultimate doom/base", + "DOOM 3 BFG Edition/base/wads", + "Strife" + }; + + FString path; + + if (!QueryPathKey(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", L"SteamPath", path)) + { + if (!QueryPathKey(HKEY_LOCAL_MACHINE, L"Software\\Valve\\Steam", L"InstallPath", path)) + return result; + } + path += "/SteamApps/common/"; + + for(unsigned int i = 0; i < countof(steam_dirs); ++i) + { + result.Push(path + steam_dirs[i]); + } + + return result; +} diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 4a2ddcdf3..48bf64541 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -71,16 +71,11 @@ #include "v_text.h" #include "utf8.h" -#include "d_main.h" -#include "d_net.h" -#include "g_game.h" #include "i_input.h" #include "c_dispatch.h" #include "templates.h" #include "gameconfigfile.h" #include "v_font.h" -#include "g_level.h" -#include "doomstat.h" #include "i_system.h" #include "bitmap.h" #include "cmdlib.h" @@ -907,144 +902,6 @@ bool I_WriteIniFailed() return MessageBoxA(Window, errortext.GetChars(), GAMENAME " configuration not saved", MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY; } -//========================================================================== -// -// QueryPathKey -// -// Returns the value of a registry key into the output variable value. -// -//========================================================================== - -static bool QueryPathKey(HKEY key, const wchar_t *keypath, const wchar_t *valname, FString &value) -{ - HKEY pathkey; - DWORD pathtype; - DWORD pathlen; - LONG res; - - value = ""; - if(ERROR_SUCCESS == RegOpenKeyEx(key, keypath, 0, KEY_QUERY_VALUE, &pathkey)) - { - if (ERROR_SUCCESS == RegQueryValueEx(pathkey, valname, 0, &pathtype, NULL, &pathlen) && - pathtype == REG_SZ && pathlen != 0) - { - // Don't include terminating null in count - TArray chars(pathlen + 1, true); - res = RegQueryValueEx(pathkey, valname, 0, NULL, (LPBYTE)chars.Data(), &pathlen); - if (res == ERROR_SUCCESS) value = FString(chars.Data()); - } - RegCloseKey(pathkey); - } - return value.IsNotEmpty(); -} - -//========================================================================== -// -// I_GetGogPaths -// -// Check the registry for GOG installation paths, so we can search for IWADs -// that were bought from GOG.com. This is a bit different from the Steam -// version because each game has its own independent installation path, no -// such thing as /SteamApps/common/. -// -//========================================================================== - -TArray I_GetGogPaths() -{ - TArray result; - FString path; - std::wstring gamepath; - -#ifdef _WIN64 - std::wstring gogregistrypath = L"Software\\Wow6432Node\\GOG.com\\Games"; -#else - // If a 32-bit ZDoom runs on a 64-bit Windows, this will be transparently and - // automatically redirected to the Wow6432Node address instead, so this address - // should be safe to use in all cases. - std::wstring gogregistrypath = L"Software\\GOG.com\\Games"; -#endif - - // Look for Ultimate Doom - gamepath = gogregistrypath + L"\\1435827232"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path); // directly in install folder - } - - // Look for Doom II - gamepath = gogregistrypath + L"\\1435848814"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path + "/doom2"); // in a subdirectory - // If direct support for the Master Levels is ever added, they are in path + /master/wads - } - - // Look for Final Doom - gamepath = gogregistrypath + L"\\1435848742"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - // in subdirectories - result.Push(path + "/TNT"); - result.Push(path + "/Plutonia"); - } - - // Look for Doom 3: BFG Edition - gamepath = gogregistrypath + L"\\1135892318"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path + "/base/wads"); // in a subdirectory - } - - // Look for Strife: Veteran Edition - gamepath = gogregistrypath + L"\\1432899949"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path); // directly in install folder - } - - return result; -} - -//========================================================================== -// -// I_GetSteamPath -// -// Check the registry for the path to Steam, so that we can search for -// IWADs that were bought with Steam. -// -//========================================================================== - -TArray I_GetSteamPath() -{ - TArray result; - static const char *const steam_dirs[] = - { - "doom 2/base", - "final doom/base", - "heretic shadow of the serpent riders/base", - "hexen/base", - "hexen deathkings of the dark citadel/base", - "ultimate doom/base", - "DOOM 3 BFG Edition/base/wads", - "Strife" - }; - - FString path; - - if (!QueryPathKey(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", L"SteamPath", path)) - { - if (!QueryPathKey(HKEY_LOCAL_MACHINE, L"Software\\Valve\\Steam", L"InstallPath", path)) - return result; - } - path += "/SteamApps/common/"; - - for(unsigned int i = 0; i < countof(steam_dirs); ++i) - { - result.Push(path + steam_dirs[i]); - } - - return result; -} //========================================================================== // diff --git a/src/win32/i_system.h b/src/win32/i_system.h index cf2673717..1e27a0368 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -22,40 +22,9 @@ void CalculateCPUSpeed (void); unsigned int I_MakeRNGSeed(); -// -// Called by D_DoomLoop, -// called before processing any tics in a frame -// (just after displaying a frame). -// Time consuming syncronous operations -// are performed here (joystick reading). -// Can call D_PostEvent. -// void I_StartFrame (void); - - -// -// Called by D_DoomLoop, -// called before processing each tic in a frame. -// Quick syncronous operations are performed here. -// Can call D_PostEvent. void I_StartTic (void); -// Asynchronous interrupt functions should maintain private queues -// that are read by the synchronous functions -// to be converted into events. - -// Either returns a null ticcmd, -// or calls a loadable driver to build it. -// This ticcmd will then be modified by the gameloop -// for normal input. -ticcmd_t *I_BaseTiccmd (void); - - -// Called by M_Responder when quit is selected. -// Clean exit, displays sell blurb. -void I_Quit (void); - - // Set the mouse cursor. The texture must be 32x32. class FGameTexture; bool I_SetCursor(FGameTexture *cursor);