Skip to content

Commit

Permalink
feat(gta-streaming-five): Background minimap overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
Manzarek committed Mar 7, 2025
1 parent dd6a1a9 commit ca34a72
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ static InitFunction initFunction([] ()
if (FX_SUCCEEDED(fx::GetCurrentScriptRuntime(&runtime)))
{
fx::Resource* resource = reinterpret_cast<fx::Resource*>(runtime->GetParentObject());
int overlayIdx = sf::AddMinimapOverlay(resource->GetPath() + "/" + context.CheckArgument<const char*>(0), -1);

auto gfxFileName = context.CheckArgument<const char*>(0);
auto background = context.GetArgument<bool>(1);

int overlayIdx = sf::AddMinimapOverlay(resource->GetPath() + "/" + gfxFileName, -1, background);

resource->OnStop.Connect([=]()
{
Expand Down Expand Up @@ -168,8 +172,9 @@ static InitFunction initFunction([] ()

auto gfxFileName = context.CheckArgument<const char*>(0);
auto depth = context.GetArgument<int>(1);
auto background = context.GetArgument<bool>(2);

int overlayIdx = sf::AddMinimapOverlay(resource->GetPath() + "/" + gfxFileName, depth);
int overlayIdx = sf::AddMinimapOverlay(resource->GetPath() + "/" + gfxFileName, depth, background);

resource->OnStop.Connect([=]()
{
Expand Down
2 changes: 1 addition & 1 deletion code/components/gta-streaming-five/include/sfFontStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace sf

void GTA_STREAMING_EXPORT RegisterFontLib(const std::string& swfName);

int GTA_STREAMING_EXPORT AddMinimapOverlay(const std::string& swfName, int depth);
int GTA_STREAMING_EXPORT AddMinimapOverlay(const std::string& swfName, int depth, bool background);

void GTA_STREAMING_EXPORT RemoveMinimapOverlay(int swfId);

Expand Down
44 changes: 33 additions & 11 deletions code/components/gta-streaming-five/src/ScaleformHacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ class OverlayMethodFunctionHandler : public GFxFunctionHandler
}
};

static GFxValue overlayRootClip;
static GFxValue overlayRootClip;
static GFxValue overlayBackgroundRootClip;

static GFxValue* g_foregroundOverlay3D;
static GFxValue* g_backgroundOverlay3D;

static void(*g_origSetupTerritories)();

static GFxValue* g_foregroundOverlay3D;
static uint32_t* g_gfxId;

static void SetupTerritories()
Expand All @@ -147,6 +151,10 @@ static void SetupTerritories()
overlayRootClip = {};

g_foregroundOverlay3D->CreateEmptyMovieClip(&overlayRootClip, "asTestClip3D", -1);

overlayBackgroundRootClip = {};

g_backgroundOverlay3D->CreateEmptyMovieClip(&overlayBackgroundRootClip, "asTestBgClip3D", -1);

auto movie = _getScaleformMovie(*g_gfxId);

Expand All @@ -160,8 +168,9 @@ static void SetupTerritories()

struct MinimapOverlayLoadRequest
{
int sfwId;
int depth;
int swfId;
int depth;
bool background;
};

static std::map<std::string, MinimapOverlayLoadRequest> g_minimapOverlayLoadQueue;
Expand All @@ -185,11 +194,11 @@ static hook::cdecl_stub<bool(uint32_t, int, const char*, int, int)> _setupGfxCal

namespace sf
{
int AddMinimapOverlay(const std::string& swfName, int depth)
int AddMinimapOverlay(const std::string& swfName, int depth, bool background)
{
auto id = ++g_minimapOverlaySwfId;

g_minimapOverlayLoadQueue.insert({ swfName, { id, depth } });
g_minimapOverlayLoadQueue.insert({ swfName, { id, depth, background } });

return id;
}
Expand Down Expand Up @@ -287,16 +296,23 @@ static HookFunction hookFunction([]()
{
auto swf = std::make_shared<GFxValue>();

auto instanceName = va("id%d", request.sfwId);
auto instanceName = va("id%d", request.swfId);

overlayRootClip.CreateEmptyMovieClip(swf.get(), instanceName, request.depth);
if (request.background)
{
overlayBackgroundRootClip.CreateEmptyMovieClip(swf.get(), instanceName, request.depth);
}
else
{
overlayRootClip.CreateEmptyMovieClip(swf.get(), instanceName, request.depth);
}

GFxValue result;
GFxValue args(gfxFileName.c_str());

swf->Invoke("loadMovie", &result, &args, 1);

g_overlayClips[request.sfwId] = swf;
g_overlayClips[request.swfId] = swf;

toRemoveFromMinimapOverlayLoadQueue.insert(gfxFileName);
}
Expand All @@ -317,8 +333,14 @@ static HookFunction hookFunction([]()
g_minimapOverlayRemoveQueue.clear();
});

{
auto location = hook::get_pattern<char>("74 3B E8 ? ? ? ? 33 C9 E8", 0x31);
{
// SetupFreeways
auto location = hook::get_pattern<char>("74 3B E8 ? ? ? ? 33 C9 E8", 0x2C);

g_backgroundOverlay3D = hook::get_address<decltype(g_backgroundOverlay3D)>(hook::get_call(location) + (xbr::IsGameBuildOrGreater<2372>() ? 0x18 : 0x1C));

// SetupTerritories
location = hook::get_pattern<char>("74 3B E8 ? ? ? ? 33 C9 E8", 0x31);

g_foregroundOverlay3D = hook::get_address<decltype(g_foregroundOverlay3D)>(hook::get_call(location) + (xbr::IsGameBuildOrGreater<2372>() ? 0x18 : 0x1C));

Expand Down
3 changes: 2 additions & 1 deletion ext/native-decls/AddMinimapOverlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ game: gta5
## ADD_MINIMAP_OVERLAY

```c
int ADD_MINIMAP_OVERLAY(char* name);
int ADD_MINIMAP_OVERLAY(char* name, cs_split BOOL background);
```
Loads a minimap overlay from a GFx file in the current resource.
Expand All @@ -15,6 +15,7 @@ If you need to control the depth of overlay use [`ADD_MINIMAP_OVERLAY_WITH_DEPTH
## Parameters
* **name**: The path to a `.gfx` file in the current resource. It has to be specified as a `file`.
* **background**: Overlay is a background overlay.
## Return value
A minimap overlay ID.
3 changes: 2 additions & 1 deletion ext/native-decls/AddMinimapOverlayWithDepth.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ game: gta5
## ADD_MINIMAP_OVERLAY_WITH_DEPTH

```c
int ADD_MINIMAP_OVERLAY_WITH_DEPTH(char* name, int depth);
int ADD_MINIMAP_OVERLAY_WITH_DEPTH(char* name, int depth, cs_split BOOL background);
```
Loads a minimap overlay from a GFx file in the current resource.
## Parameters
* **name**: The path to a `.gfx` file in the current resource. It has to be specified as a `file`.
* **depth**: The depth of new overlay on the minimap. Pass `-1` for game to figure out the highest depth itself. Should not be greater than `0x7EFFFFFD`.
* **background**: Overlay is a background overlay.
## Return value
A minimap overlay ID.

0 comments on commit ca34a72

Please sign in to comment.