Skip to content

Commit

Permalink
improvement: make native res default video mode instead of 800x600
Browse files Browse the repository at this point in the history
  • Loading branch information
yukani committed Jul 11, 2023
1 parent 589806e commit 667507b
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions source/app/platform/win/WinPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,53 @@ bool psAlwaysOnTop(bool alwaysOnTop) {
);
}

// NOTSA
auto GetNativeResolutionOfCurrentSubsystem() {
#ifdef USE_D3D9
const auto d3d = Direct3DCreate9(D3D_SDK_VERSION);
#else
const auto d3d = Direct3DCreate8(D3D_SDK_VERSION);
#endif
const notsa::ScopeGuard released3d{[d3d] { d3d->Release(); }};
assert(d3d != NULL);

D3DDISPLAYMODE nativeRes;
d3d->GetAdapterDisplayMode(RwEngineGetCurrentSubSystem(), &nativeRes);

DEV_LOG("Got native resolution from RW subsystem ({}): {} x {}", RwEngineGetCurrentSubSystem(), nativeRes.Width, nativeRes.Height);

return std::make_pair(nativeRes.Width, nativeRes.Height);
}

BOOL CheckDefaultVideoModeSupported() {
const auto numVM = RwEngineGetNumVideoModes();
for (; GcurSelVM < numVM; GcurSelVM++) { // TODO/NOTE: Why not set GcurSelVM = 0?
const auto vm = RwEngineGetVideoModeInfo(GcurSelVM);
if (vm.width == 800 && vm.height == 600 && vm.depth == 32 && (vm.flags & rwVIDEOMODEEXCLUSIVE)) {
// IMPROVEMENT/FIX_BUGS: The game will now default to native adapter
// resolution instead of 800x600.

const auto SearchVideoMode = [](int32 width, int32 height) {
for (auto i = 0; i < RwEngineGetNumVideoModes(); i++) {
const auto vm = RwEngineGetVideoModeInfo(i);
if (vm.width == width && vm.height == height && vm.depth == 32 && (vm.flags & rwVIDEOMODEEXCLUSIVE)) {
return i;
}
}

return -1;
};

if (notsa::IsFixBugs()) {
const auto&& [w, h] = GetNativeResolutionOfCurrentSubsystem();
if (const auto vm = SearchVideoMode(w, h); vm != -1) {
GcurSelVM = vm;
return TRUE;
}
/* fallthrough if native res is not supported! */
}

if (const auto vm = SearchVideoMode(800, 600); vm != -1) {
GcurSelVM = vm;
return TRUE;
}

MessageBox(NULL, "Cannot find 800x600x32 video mode", "GTA: San Andreas", IDOK);
return FALSE;
}
Expand Down

0 comments on commit 667507b

Please sign in to comment.