From c40b9bb535a7a5ba5aabb7345ccf17866dc6de3b Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Thu, 19 Oct 2023 15:07:16 +1100 Subject: [PATCH 1/2] Add exported function so another plugin can inform dashboard of the current vehicles entity ID --- Source/Dashboard.as | 12 ++++++++++++ Source/Exports.as | 4 ++++ Source/Exports_Impl.as | 10 ++++++++++ info.toml | 1 + 4 files changed, 27 insertions(+) create mode 100644 Source/Exports.as create mode 100644 Source/Exports_Impl.as diff --git a/Source/Dashboard.as b/Source/Dashboard.as index 79f6798..59dae7b 100644 --- a/Source/Dashboard.as +++ b/Source/Dashboard.as @@ -42,6 +42,18 @@ class Dashboard } auto visState = VehicleState::ViewingPlayerState(); + // If we didn't find a vis state, use the vehicle entity ID provided by another plugin if it is recent + if (visState is null && g_InformedCurrentEntId > 0 && Time::Now - g_InformedCurrentEntIdLastAt < 100 && app.GameScene !is null) { + array@ allVis = VehicleState::GetAllVis(app.GameScene); + CSceneVehicleVis@ vis; + for (uint i = 0; i < allVis.Length; i++) { + @vis = allVis[i]; + if (vis !is null && Dev::GetOffsetUint32(vis, 0x0) == g_InformedCurrentEntId) { + @visState = vis.AsyncState; + break; + } + } + } if (visState is null) { return; } diff --git a/Source/Exports.as b/Source/Exports.as new file mode 100644 index 0000000..ba618ce --- /dev/null +++ b/Source/Exports.as @@ -0,0 +1,4 @@ +namespace Dashboard +{ + import void InformCurrentEntityId(uint EntId) from "Dashboard"; +} diff --git a/Source/Exports_Impl.as b/Source/Exports_Impl.as new file mode 100644 index 0000000..f942204 --- /dev/null +++ b/Source/Exports_Impl.as @@ -0,0 +1,10 @@ +uint g_InformedCurrentEntId; +uint g_InformedCurrentEntIdLastAt; + +namespace Dashboard +{ + void InformCurrentEntityId(uint EntId) { + g_InformedCurrentEntId = EntId; + g_InformedCurrentEntIdLastAt = Time::Now; + } +} diff --git a/info.toml b/info.toml index abbb3d6..f3da9d6 100644 --- a/info.toml +++ b/info.toml @@ -9,3 +9,4 @@ blocks = [ "Plugin_Dashboard" ] [script] dependencies = [ "VehicleState" ] timeout = 0 +exports = ["Source/Exports.as"] From c008340c65cdf640f620f2850629678c1a8fc2ff Mon Sep 17 00:00:00 2001 From: Max Kaye Date: Thu, 19 Oct 2023 15:10:26 +1100 Subject: [PATCH 2/2] fix bracket placement and add some spacing between blocks --- Source/Dashboard.as | 2 ++ Source/Exports_Impl.as | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Dashboard.as b/Source/Dashboard.as index 59dae7b..dad3dc2 100644 --- a/Source/Dashboard.as +++ b/Source/Dashboard.as @@ -42,6 +42,7 @@ class Dashboard } auto visState = VehicleState::ViewingPlayerState(); + // If we didn't find a vis state, use the vehicle entity ID provided by another plugin if it is recent if (visState is null && g_InformedCurrentEntId > 0 && Time::Now - g_InformedCurrentEntIdLastAt < 100 && app.GameScene !is null) { array@ allVis = VehicleState::GetAllVis(app.GameScene); @@ -54,6 +55,7 @@ class Dashboard } } } + if (visState is null) { return; } diff --git a/Source/Exports_Impl.as b/Source/Exports_Impl.as index f942204..1e455b0 100644 --- a/Source/Exports_Impl.as +++ b/Source/Exports_Impl.as @@ -3,7 +3,8 @@ uint g_InformedCurrentEntIdLastAt; namespace Dashboard { - void InformCurrentEntityId(uint EntId) { + void InformCurrentEntityId(uint EntId) + { g_InformedCurrentEntId = EntId; g_InformedCurrentEntIdLastAt = Time::Now; }