Skip to content

Commit

Permalink
feat(extra-natives-rdr3): add GET_CURRENT_SCREEN_RESOLUTION for RedM
Browse files Browse the repository at this point in the history
  • Loading branch information
outsider31000 committed Feb 16, 2025
1 parent c1cff3d commit f3ca611
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions code/components/extra-natives-rdr3/src/GraphicsNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ static WorldhorizonManager* g_worldhorizonMgr;

CViewportGame** g_viewportGame;

static int* g_calculatedWidth = 0;
static int* g_calculatedHeight = 0;

static HookFunction hookFunction([]()
{
static_assert(sizeof(ScriptImRequest) == 64);
Expand Down Expand Up @@ -145,6 +148,13 @@ static HookFunction hookFunction([]()
g_origRenderScriptIm = hook::trampoline(location, RenderScriptIm);
}

{
auto location = hook::get_pattern<char>("89 05 ? ? ? ? 89 0D ? ? ? ? F3 0F 5E");

g_calculatedWidth = hook::get_address<int*>(location + 2);
g_calculatedHeight = hook::get_address<int*>(location + 8);
}

fx::ScriptEngine::RegisterNativeHandler("SET_DRAW_ORIGIN", [](fx::ScriptContext& context)
{
DrawOriginStore& store = g_drawOriginStore[*g_updateBufferIndex];
Expand Down Expand Up @@ -313,4 +323,21 @@ static HookFunction hookFunction([]()
normalOut->y = XMVectorGetY(normalVector);
normalOut->z = XMVectorGetZ(normalVector);
});

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

if (!width || !height)
{
context.SetResult<bool>(false);
return;
}

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

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

```c
BOOL GET_CURRENT_SCREEN_RESOLUTION(int* width, int* height);
```
Gets the current screen resolution.
```lua
local _, width, height = GetCurrentScreenResolution()
print(width, height)
```

0 comments on commit f3ca611

Please sign in to comment.