Skip to content

feat(extra-natives-rdr3): add GET_ASPECT_RATIO native RedM #3285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions code/components/extra-natives-rdr3/src/GraphicsNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,32 @@ static HookFunction hookFunction([]()

fx::ScriptEngine::RegisterNativeHandler("GET_CURRENT_SCREEN_RESOLUTION", [](fx::ScriptContext& context)
{
int width = 0;
int height = 0;
int width = 0;
int height = 0;

if (g_screenWidth && g_screenHeight)
{
width = *g_screenWidth;
height = *g_screenHeight;
width = *g_screenWidth;
height = *g_screenHeight;
}

*context.GetArgument<int*>(0) = width;
*context.GetArgument<int*>(1) = height;
});

fx::ScriptEngine::RegisterNativeHandler("GET_ASPECT_RATIO", [](fx::ScriptContext& context)
{
int width = 0;
int height = 0;
float aspectRatio = 0.0f;

if (g_screenWidth && g_screenHeight)
{
width = *g_screenWidth;
height = *g_screenHeight;
aspectRatio = static_cast<float>(width) / static_cast<float>(height);
}

context.SetResult<float>(aspectRatio);
});
});
17 changes: 17 additions & 0 deletions ext/native-decls/GetAspectRatio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
ns: CFX
apiset: client
game: rdr3
---
## GET_ASPECT_RATIO

```c
float GET_ASPECT_RATIO();
```

Gets the current aspect ratio

```lua
local ratio = GetAspectRatio()
print(string.format("%.2f", ratio))
```