Skip to content

Commit

Permalink
implement FE scaling support
Browse files Browse the repository at this point in the history
  • Loading branch information
xan1242 committed Jul 22, 2023
1 parent d336bfd commit 6567430
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void FixWorkingDirectory() {
void LoadMapping(std::string userProfileName);
void ClearAllMappings();
std::string gProfileName;

#pragma runtime_checks("", off)
#ifdef GAME_MW
std::string oldProfileName;
uintptr_t MemCardLoadAddr = 0x005189F0;
Expand All @@ -139,7 +139,7 @@ void __stdcall MemoryCard_Load_Hook(const char* profileName) {
}
#endif

#pragma runtime_checks("", off)

#if defined(GAME_CARBON) || defined(GAME_PROSTREET)
char NFSProfileName[128];
uintptr_t DALManager_GetString_Addr = DALMANAGER_GETSTRING_ADDR;
Expand Down Expand Up @@ -1998,3 +1998,14 @@ extern "C" __declspec(dllexport) bool SetPollingState(bool state) {
bGlobalDoPolling = state;
return state;
}

#ifndef NO_FENG
extern "C" __declspec(dllexport) float GetFEScale() { return fFEScale; }

extern "C" __declspec(dllexport) float SetFEScale(float val) {
fFEScale = val;
return fFEScale;
}

extern "C" __declspec(dllexport) bool GetUseWin32Cursor() { return bUseWin32Cursor; }
#endif
16 changes: 16 additions & 0 deletions src/NFS_XtendedInput_FEng.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ bool bMouse3PressedDownOldState = false;

int MouseWheelValue = 0;

float fFEScale = 1.0f;

bool bConfineMouse = false;
int TimeSinceLastMouseMovement = 0;
bool bUseWin32Cursor = true;
Expand Down Expand Up @@ -365,6 +367,20 @@ void UpdateFECursorPos() {
GetCursorPos(&MousePos);
GetWindowRect(*(HWND*)GAME_HWND_ADDR, &windowRect);

// correct the window size to compensate for the change in FE scale
if ((*(uint32_t*)&fFEScale) != 0x3F800000) {
float SizeX = windowRect.right - windowRect.left;
float SizeY = windowRect.bottom - windowRect.top;

float scSizeX = SizeX * fFEScale;
float scSizeY = SizeY * fFEScale;

windowRect.right -= (LONG)((SizeX - scSizeX) / 2.0f);
windowRect.left += (LONG)((SizeX - scSizeX) / 2.0f);
windowRect.bottom -= (LONG)((SizeY - scSizeY) / 2.0f);
windowRect.top += (LONG)((SizeY - scSizeY) / 2.0f);
}

float ratio = 480.0 / (windowRect.bottom - windowRect.top); // scaling it to 480 height since that's what FE wants

if ((MousePos.x >= windowRect.left) || (MousePos.x <= windowRect.right) && (MousePos.y >= windowRect.top) || (MousePos.y <= windowRect.bottom))
Expand Down

0 comments on commit 6567430

Please sign in to comment.