Skip to content
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

feat(extra-natives-rdr3): add GET_CURRENT_SCREEN_RESOLUTION for RedM #3159

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
30 changes: 28 additions & 2 deletions code/components/extra-natives-rdr3/src/GraphicsNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static hook::cdecl_stub<void()> initScriptImBuffer([]()
return hook::get_pattern("48 89 5C 24 ? 57 48 83 EC 20 0F B7 05 ? ? ? ? 33 FF");
});

static void(*g_origRenderScriptIm)();
static void (*g_origRenderScriptIm)();
static void RenderScriptIm()
{
// The game never uses this buffer itself, but it *may* be changed in the future updates.
Expand Down Expand Up @@ -88,7 +88,7 @@ struct DrawOriginStore
char pad_404[12];
};

static bool(*isGamePaused)();
static bool (*isGamePaused)();

static int* g_renderBufferIndex;
static int* g_updateBufferIndex;
Expand All @@ -107,6 +107,9 @@ static WorldhorizonManager* g_worldhorizonMgr;

CViewportGame** g_viewportGame;

static int* g_screenWidth;
static int* g_screenHeight;

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_screenWidth = hook::get_address<int*>(location + 2);
g_screenHeight = 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,20 @@ static HookFunction hookFunction([]()
normalOut->y = XMVectorGetY(normalVector);
normalOut->z = XMVectorGetZ(normalVector);
});

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

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

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

});
});
18 changes: 18 additions & 0 deletions ext/native-decls/GetCurrentScreenResolution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
ns: CFX
apiset: client
game: rdr3
---
## GET_CURRENT_SCREEN_RESOLUTION

```c
void GET_CURRENT_SCREEN_RESOLUTION(int* width, int* height);
```

Gets the current screen resolution.

```lua
local width, height = GetCurrentScreenResolution()
print(string.format("Current screen resolution: %dx%d", width, height))

```
Loading