diff --git a/client/src/classes/Entity.cpp b/client/src/classes/Entity.cpp index 96cb5d850..6f7c98491 100644 --- a/client/src/classes/Entity.cpp +++ b/client/src/classes/Entity.cpp @@ -1,6 +1,43 @@ #include "Class.h" #include "cpp-sdk/ICore.h" +static void GetSyncInfo(js::FunctionContext& ctx) +{ + if(!ctx.CheckThis()) return; + if(!ctx.CheckArgCount(1)) return; + alt::IEntity* entity = ctx.GetThisObject(); + + const auto syncInfo = entity->GetSyncInfo(); + + js::Object obj; + obj.Set("active", syncInfo.active); + obj.Set("receivedTick", syncInfo.receivedTick); + obj.Set("fullyReceivedTick", syncInfo.fullyReceivedTick); + obj.Set("sendTick", syncInfo.sendTick); + obj.Set("ackedSendTick", syncInfo.ackedSendTick); + obj.Set("propertyCount", syncInfo.propertyCount); + obj.Set("componentCount", syncInfo.componentCount); + + js::Array componentPropertyIndex(syncInfo.componentCount); + uint32_t lastPropertyIdx = 0; + for(uint32_t i = 0; i < syncInfo.componentCount; i++) + { + const uint32_t endIdx = i == syncInfo.componentCount - 1 ? syncInfo.propertyCount : syncInfo.componentPropertyIndex[i]; + + js::Array propertiesUpdateTick(static_cast(endIdx - lastPropertyIdx)); + for (uint32_t j = lastPropertyIdx; j < endIdx; j++) + { + propertiesUpdateTick.Set(j - lastPropertyIdx, syncInfo.propertiesUpdateTick[j]); + } + + componentPropertyIndex.Set(i, propertiesUpdateTick); + lastPropertyIdx = endIdx; + } + + obj.Set("propertyUpdateTicks", componentPropertyIndex); + ctx.Return(obj); +} + static void GetByScriptID(js::FunctionContext& ctx) { if(!ctx.CheckArgCount(1)) return; @@ -20,5 +57,7 @@ extern js::Class entityClass("Entity", &sharedEntityClass, nullptr, [](js::Class { tpl.Property<&alt::IEntity::GetScriptID>("scriptID"); + tpl.Method("getSyncInfo", GetSyncInfo); + tpl.StaticFunction("getByScriptID", &GetByScriptID); }); diff --git a/types/client/index.d.ts b/types/client/index.d.ts index 0357257d1..a30161221 100644 --- a/types/client/index.d.ts +++ b/types/client/index.d.ts @@ -410,15 +410,15 @@ declare module "@altv/client" { get model(): number; readonly netOwner?: Player; readonly visible: boolean; - frozen: boolean; readonly isStreamedIn: boolean; + readonly streamSyncedMeta: Readonly; + frozen: boolean; rot: altShared.Vector3; - readonly streamSyncedMeta: Readonly; + getSyncInfo(): Data.ISyncInfo; static readonly all: ReadonlyArray; - static getByScriptID(scriptId: number): Entity | null; } @@ -1412,6 +1412,22 @@ declare module "@altv/client" { static create(opts: altShared.ColShapePolygonCreateOptions): ColShapePolygon; } + export namespace Data { + export interface ISyncInfo { + readonly active: boolean; + readonly receivedTick: number; + readonly fullyReceivedTick: number; + readonly sendTick: number; + readonly ackedSendTick: number; + readonly propertyCount: number; + readonly componentCount: number; + /** + * 2D array of property update ticks grouped by component + */ + readonly propertyUpdateTicks: number[][]; + } + } + export namespace Drawing { export function drawText2dThisFrame(text: string, pos2d?: altShared.IVector2, font?: Number, scale?: Number, color?: altShared.IRGBA, outline?: boolean, dropShadow?: boolean, textAlign?: number): void; export function drawText2d(text: string, pos2d?: altShared.IVector2, font?: Number, scale?: Number, color?: altShared.IRGBA, outline?: boolean, dropShadow?: boolean, textAlign?: number): altShared.Timers.EveryTick; diff --git a/types/client/package.json b/types/client/package.json index 3d472a0f1..3549f8edc 100644 --- a/types/client/package.json +++ b/types/client/package.json @@ -1,6 +1,6 @@ { "name": "@altv/client", - "version": "0.0.19", + "version": "0.0.20", "description": "This package contains the type definitions for the alt:V JS module v2 client types", "types": "index.d.ts", "files": [