Skip to content

Commit

Permalink
Revert "Windowed Mode (#580)"
Browse files Browse the repository at this point in the history
This reverts commit f652cb7.
  • Loading branch information
yukani authored Jul 16, 2023
1 parent 3976c25 commit 63793c0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 112 deletions.
32 changes: 8 additions & 24 deletions source/app/platform/win/VideoMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,19 @@ char** GetVideoModeList() {
}
gCurrentGpu = RwEngineGetCurrentSubSystem();

const auto numVidModes = RwEngineGetNumVideoModes();
uint32 numVidModes = RwEngineGetNumVideoModes();
assert(numVidModes != -1 && "Failed to get Video Modes");

gVideoModes = (char**)CMemoryMgr::Calloc(numVidModes, sizeof(char*));

for (auto modeId = 0; modeId < numVidModes; modeId++) {
for (auto modeId = 0u; modeId < numVidModes; modeId++) {
const auto videoMode = RwEngineGetVideoModeInfo(modeId);

gVideoModes[modeId] = nullptr;

if ((videoMode.flags & rwVIDEOMODEEXCLUSIVE) == 0) {
if (notsa::IsFixBugs()) {
gVideoModes[modeId] = (char*)CMemoryMgr::Calloc(100, sizeof(char));
sprintf_s(gVideoModes[modeId], 100 * sizeof(char), "WINDOWED");

#ifdef VIDEO_MODE_LOGS
DEV_LOG("Available video mode id={:02d}: {}", modeId, gVideoModes[modeId]);
#endif
} else {
// Ignore windowed mode.
#ifdef VIDEO_MODE_LOGS
DEV_LOG("Unavailable video mode id={:02d}: {} X {} X {} [reason: video mode not exclusive]", modeId, videoMode.width, videoMode.height, videoMode.depth);
DEV_LOG("Unavailable video mode id={:02d}: {} X {} X {} [reason: video mode not exclusive]", modeId, videoMode.width, videoMode.height, videoMode.depth);
#endif
}
continue;
}

Expand All @@ -61,27 +50,22 @@ char** GetVideoModeList() {
continue;
}

const auto aspectRatio = float(videoMode.height) / float(videoMode.width);
if (!IsFullScreenRatio(aspectRatio) && !IsWideScreenRatio(aspectRatio)) {
float fRatio = float(videoMode.height) / float(videoMode.width);
if (!IS_FULLSCREEN_RATIO(fRatio) && !IS_WIDESCREEN_RATIO(fRatio)) {
#ifdef VIDEO_MODE_LOGS
const auto gcd = std::gcd(videoMode.width, videoMode.height);
const auto ratioW = videoMode.width / gcd, ratioH = videoMode.height / gcd;
DEV_LOG("Unavailable video mode id={:02d}: {} X {} X {} [reason: ratio {}:{}]", modeId, videoMode.width, videoMode.height, videoMode.depth, ratioW, ratioH);
DEV_LOG("Unavailable video mode id={:02d}: {} X {} X {} [reason: ratio {:0.2f}]", modeId, videoMode.width, videoMode.height, videoMode.depth, fRatio);
#endif
continue;
}

if (videoMode.width != APP_MINIMAL_WIDTH || videoMode.height != APP_MINIMAL_HEIGHT) {
if (s_OSStatus.VRAM.Avail - videoMode.height * videoMode.width * videoMode.depth / 8 <= GAME_FREE_VIDEO_MEM_REQUIRED) {
#ifdef VIDEO_MODE_LOGS
DEV_LOG("Unavailable video mode id={:02d}: {} X {} X {} [reason: out of vram]", modeId, videoMode.width, videoMode.height, videoMode.depth);
#endif
continue;
}
}

gVideoModes[modeId] = (char*)CMemoryMgr::Calloc(100, sizeof(char));
sprintf_s(gVideoModes[modeId], 100 * sizeof(char), "%lu X %lu X %lu", videoMode.width, videoMode.height, videoMode.depth);
gVideoModes[modeId] = (char*)CMemoryMgr::Calloc(100, sizeof(char)); // 100 chars
sprintf_s(gVideoModes[modeId], 100 * sizeof(char), "%lu X %lu X %lu", videoMode.width, videoMode.height, videoMode.depth); // rwsprintf

#ifdef VIDEO_MODE_LOGS
DEV_LOG("Available video mode id={:02d}: {}", modeId, gVideoModes[modeId]);
Expand Down
9 changes: 1 addition & 8 deletions source/app/platform/win/VideoModeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ void FillAvailableVMs(HWND hVMSel) {
const auto numVM = RwEngineGetNumVideoModes();
for (auto i = 0; i < numVM; i++) {
const auto vmi = RwEngineGetVideoModeInfo(i);
static char vmName[1024];

if (notsa::IsFixBugs() && (vmi.flags & rwVIDEOMODEEXCLUSIVE) == 0) {
*std::format_to(vmName, "WINDOWED") = 0;
const auto idx = SendMessage(hVMSel, CB_ADDSTRING, NULL, (LPARAM)vmName); // Add entry, and get it's index
SendMessage(hVMSel, CB_SETITEMDATA, idx, i); // Set index of that entry to correspond to `i`
continue;
}

if ((vmi.flags & rwVIDEOMODEEXCLUSIVE) == 0 || vmi.width < APP_MINIMAL_WIDTH || vmi.height < APP_MINIMAL_HEIGHT) {
continue;
Expand All @@ -73,6 +65,7 @@ void FillAvailableVMs(HWND hVMSel) {

// NOTSA: Provide aspect ratio info (W:H) instead of 'FULLSCREEN' and 'WIDESCREEN'.
if (IsFullScreenRatio(aspectr) || IsWideScreenRatio(aspectr)) {
static char vmName[1024];
*std::format_to(vmName, "{} x {} x {} ({}:{})", vmi.width, vmi.height, vmi.depth, ratioW, ratioH) = 0;
const auto idx = SendMessage(hVMSel, CB_ADDSTRING, NULL, (LPARAM)vmName); // Add entry, and get it's index
SendMessage(hVMSel, CB_SETITEMDATA, idx, i); // Set index of that entry to correspond to `i`
Expand Down
21 changes: 5 additions & 16 deletions source/app/platform/win/WinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "WndProc.h"

#include "extensions/Configs/FastLoader.hpp"
#include "extensions/Configs/WindowedMode.hpp"

constexpr auto NO_FOREGROUND_PAUSE = true;

Expand Down Expand Up @@ -46,28 +45,18 @@ bool InitApplication(HINSTANCE hInstance) {

// 0x745560
HWND InitInstance(HINSTANCE hInstance) {
// NOTSA/HACK: With this hack we can set a specific value for
// windowed mode. Also this is so stupid it needs to be changed
// after 'window-stretch-freeze' bug fixed.
RsGlobal.maximumWidth = g_WindowedModeConfig.WindowWidth;
RsGlobal.maximumHeight = g_WindowedModeConfig.WindowHeight;

RECT winRt;
GetClientRect(GetDesktopWindow(), &winRt);

RECT rect = { 0, 0, RsGlobal.maximumWidth, RsGlobal.maximumHeight };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
const auto width = rect.right - rect.left, height = rect.bottom - rect.top;

return CreateWindowEx(
0,
APP_CLASS,
RsGlobal.appName,
WS_OVERLAPPEDWINDOW,
(g_WindowedModeConfig.Centered) ? (winRt.right - winRt.left - width) / 2 : CW_USEDEFAULT,
(g_WindowedModeConfig.Centered) ? (winRt.bottom - winRt.top - height) / 2 : CW_USEDEFAULT,
width,
height,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
nullptr,
nullptr,
hInstance,
Expand Down Expand Up @@ -431,6 +420,6 @@ void InjectWinMainStuff() {
RH_ScopedGlobalInstall(CommandLineToArgv, 0x746480, { .reversed = false });

// Unhooking these 2 after the game has started will do nothing
RH_ScopedGlobalInstall(NOTSA_WinMain, 0x748710, { .locked = true });
RH_ScopedGlobalInstall(NOTSA_WinMain, 0x748710);
RH_ScopedGlobalInstall(InitInstance, 0x745560);
}
9 changes: 1 addition & 8 deletions source/app/platform/win/WinPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,7 @@ bool psSelectDevice() {

if (!UseDefaultVM && !MultipleSubSystems) {
const auto vmDisplay = FrontEndMenuManager.m_nDisplayVideoMode;

// IMPROVEMENT/NOTSA: Originally `vmDisplay == 0`.
// Originally 0 (which is windowed vm) is a sentinel value for resolution settings.
// If that sentinel value is selected, the game searches for 'real default video mode'. (SA: 800x600)
//
// Zero as a sentinel value prevents us to save the game with windowed mode, so it's converted to -1.
// Look at: `SetToDefaultSettings` lambda at CMenuManager::LoadSettings.
if (vmDisplay == -1 || !GetVideoModeList()[vmDisplay]) {
if (!vmDisplay || !GetVideoModeList()[vmDisplay]) {
if (IsVMNotSelected && !CheckDefaultVideoModeSupported()) {
return FALSE;
}
Expand Down
2 changes: 0 additions & 2 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ void WaitForDebugger() {
static constexpr auto DEFAULT_INI_FILENAME = "gta-reversed.ini";

#include "extensions/Configs/FastLoader.hpp"
#include "extensions/Configs/WindowedMode.hpp"

void LoadConfigurations() {
// Firstly load the INI into the memory.
g_ConfigurationMgr.Load(DEFAULT_INI_FILENAME);

// Then load all specific configurations.
g_FastLoaderConfig.Load();
g_WindowedModeConfig.Load();
// ...
}

Expand Down
17 changes: 0 additions & 17 deletions source/extensions/Configs/WindowedMode.hpp

This file was deleted.

43 changes: 8 additions & 35 deletions source/extensions/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,18 @@
#include <optional>
#include <unordered_map>
#include <fstream>
#include <filesystem>

#include "app_debug.h"

static inline class {
using IniContent = std::unordered_map<std::string, std::unordered_map<std::string, std::string>>;
IniContent m_content{};

struct NewConfigFile {
std::ofstream out;
std::string lastSection;
};
std::optional<NewConfigFile> m_createdIniFile{};

public:
template <typename Ret = std::string>
Ret GetIniValue(const std::string& section, const std::string& key, Ret&& _default) {
if (m_content.empty() || !m_content.contains(section) || !m_content[section].contains(key)) {
if (m_createdIniFile.has_value()) {
if (std::exchange(m_createdIniFile->lastSection, section) != section)
m_createdIniFile->out << "\n[" << section << "]\n";

if constexpr (std::is_same_v<Ret, bool>)
m_createdIniFile->out << key << " = " << std::boolalpha << _default << "\n";
else
m_createdIniFile->out << key << " = " << _default << "\n";
}
return _default;
}
std::optional<Ret> GetIniValue(const std::string& section, const std::string& key) {
if (m_content.empty() || !m_content.contains(section) || !m_content[section].contains(key))
return {};

const auto& str = m_content[section][key];
if constexpr (std::is_same_v<Ret, std::string>) {
Expand All @@ -43,25 +26,15 @@ static inline class {

auto [_, ec] = std::from_chars(str.data(), str.data() + str.size(), rt);
if (ec != std::errc{})
return _default;
return {};

return rt;
} else {
return _default;
return {};
}
}

void Load(const std::filesystem::path& fileName) {
if (!std::filesystem::exists(fileName)) {
DEV_LOG("Configuration file {} doesn't exist! A new one will be generated.", fileName.string());
DEV_LOG("Using the provided config file with comments is recommended.");

auto out = std::ofstream{fileName};
out << "; GTA-Reversed configuration file generated at " << std::chrono::system_clock::now();
m_createdIniFile = {std::move(out), ""};
return;
}

void Load(const std::string& fileName) {
std::ifstream in(fileName);
assert(!in.bad());

Expand Down Expand Up @@ -114,7 +87,7 @@ static inline class {
static constexpr auto IniSectionName = name

#define GET_INI_CONFIG_VALUE(key, _default) \
g_ConfigurationMgr.GetIniValue<decltype(_default)>(IniSectionName, key, _default)
g_ConfigurationMgr.GetIniValue<decltype(_default)>(IniSectionName, key).value_or(_default)

#define STORE_INI_CONFIG_VALUE(key_var, _default) \
key_var = g_ConfigurationMgr.GetIniValue<decltype(key_var)>(IniSectionName, #key_var, _default)
key_var = g_ConfigurationMgr.GetIniValue<decltype(key_var)>(IniSectionName, #key_var).value_or(_default)
4 changes: 2 additions & 2 deletions source/game_sa/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void CMenuManager::SetDefaultPreferences(eMenuScreen screen) {
m_bWidescreenOn = false;
m_bMapLegend = false;
m_nRadarMode = eRadarMode::MAPS_AND_BLIPS;
m_nDisplayVideoMode = -1; // Originally m_nPrefsVideoMode. Look at: `psSelectDevice`.
m_nDisplayVideoMode = m_nPrefsVideoMode;
m_ShowLocationsBlips = true;
m_ShowContactsBlips = true;
m_ShowMissionBlips = true;
Expand Down Expand Up @@ -600,7 +600,7 @@ void CMenuManager::LoadSettings() {
SetDefaultPreferences(SCREEN_DISPLAY_SETTINGS);
SetDefaultPreferences(SCREEN_DISPLAY_ADVANCED);
SetDefaultPreferences(SCREEN_CONTROLLER_SETUP);
m_nPrefsVideoMode = -1; // Originally 0. Look at: `psSelectDevice`.
m_nPrefsVideoMode = 0;
m_nPrefsLanguage = eLanguage::AMERICAN;
m_nRadioStation = 1;

Expand Down

0 comments on commit 63793c0

Please sign in to comment.