diff --git a/client/js/compatibility/classes/focusData.js b/client/js/compatibility/classes/focusData.js index aeecc7e9f..8bb8a4aa6 100644 --- a/client/js/compatibility/classes/focusData.js +++ b/client/js/compatibility/classes/focusData.js @@ -6,12 +6,27 @@ const { isVector3 } = requireBinding("shared/utils.js"); class FocusData { + static get isFocusOverriden() { + return alt.FocusData.isFocusOverriden; + } + + static get focusOverridePos() { + return alt.FocusData.focusOverridePos; + } + + static get focusOverrideOffset() { + return alt.FocusData.focusOverrideOffset; + } + + static get focusOverrideEntity() { + return alt.FocusData.focusOverrideEntity; + } + static overrideFocus(value, focusOffset) { if (isVector3(value)) { focusOffset ??= { x: 0, y: 0, z: 0 }; - alt.FocusData.focusOverridePos = value; - alt.FocusData.focusOverrideOffset = focusOffset; + alt.FocusData.overrideFocus(value, focusOffset); return; } diff --git a/client/src/namespaces/FocusDataNamespace.cpp b/client/src/namespaces/FocusDataNamespace.cpp index ea0ef55b2..a2cf2b3e9 100644 --- a/client/src/namespaces/FocusDataNamespace.cpp +++ b/client/src/namespaces/FocusDataNamespace.cpp @@ -10,12 +10,16 @@ static void FocusOverridePosGetter(js::PropertyContext& ctx) ctx.Return(alt::ICore::Instance().GetFocusOverridePos()); } -static void FocusOverridePosSetter(js::PropertyContext& ctx) +static void OverrideFocus(js::FunctionContext& ctx) { + if (!ctx.CheckArgCount(1, 2)) return; + alt::Position pos; - if(!ctx.GetValue(pos)) return; + if (!ctx.GetArg(0, pos)) return; + + auto offset = ctx.GetArg(1, { 0, 0, 0 }); - alt::ICore::Instance().OverrideFocusPosition(pos); + alt::ICore::Instance().OverrideFocusPosition(pos, offset); } static void FocusOverrideEntityGetter(js::PropertyContext& ctx) @@ -44,9 +48,11 @@ static void ClearFocusOverride(js::FunctionContext& ctx) // clang-format off extern js::Namespace focusDataNamespace("FocusData", [](js::NamespaceTemplate& tpl) { tpl.StaticProperty("isFocusOverriden", FocusOverridenGetter); - tpl.StaticProperty("focusOverridePos", FocusOverridePosGetter, FocusOverridePosSetter); + tpl.StaticProperty("focusOverridePos", FocusOverridePosGetter); tpl.StaticProperty("focusOverrideEntity", FocusOverrideEntityGetter, FocusOverrideEntitySetter); tpl.StaticProperty("focusOverrideOffset", FocusOverrideOffsetGetter); + + tpl.StaticFunction("overrideFocus", OverrideFocus); tpl.StaticFunction("clearFocusOverride", ClearFocusOverride); }); diff --git a/types/client/index.d.ts b/types/client/index.d.ts index f82c8fbbf..943739166 100644 --- a/types/client/index.d.ts +++ b/types/client/index.d.ts @@ -2112,10 +2112,11 @@ declare module "@altv/client" { export namespace FocusData { export const isFocusOverriden: boolean; - export let focusOverridePos: altShared.Vector3; + export const focusOverridePos: altShared.Vector3; export let focusOverrideEntity: Entity | null; export const focusOverrideOffset: altShared.Vector3; + export function overrideFocus(pos: altShared.IVector3, offset?: altShared.IVector3): void; export function clearFocusOverride(): void; } diff --git a/types/client/package.json b/types/client/package.json index 377a8d5a1..dd23873d6 100644 --- a/types/client/package.json +++ b/types/client/package.json @@ -1,6 +1,6 @@ { "name": "@altv/client", - "version": "0.0.44", + "version": "0.0.45", "description": "This package contains the type definitions for the alt:V JS module v2 client types", "types": "index.d.ts", "files": [