diff --git a/packages/colandreas/src/definitions/index.ts b/packages/colandreas/src/definitions/index.ts index 5cf3f484..c51d9c2d 100644 --- a/packages/colandreas/src/definitions/index.ts +++ b/packages/colandreas/src/definitions/index.ts @@ -1,3 +1,4 @@ export const MAX_CA_OBJECTS = 50000; export const WATER_OBJECT = 20000; export const FLOAT_INFINITY = 0x7f800000; +export const MAX_MULTICAST_SIZE = 99; diff --git a/packages/colandreas/src/functions/index.ts b/packages/colandreas/src/functions/index.ts index 5b3e2049..17a892a0 100644 --- a/packages/colandreas/src/functions/index.ts +++ b/packages/colandreas/src/functions/index.ts @@ -115,17 +115,17 @@ function isInWater(instance: Player | Vehicle) { if (!pos) return false; const { x, y, z } = pos; - const ret = rayCastMultiLine(x, y, z + 1000.0, x, y, z - 1000.0, 10); + const { + collisions, + z: retZ, + modelIds, + } = rayCastMultiLine(x, y, z + 1000.0, x, y, z - 1000.0, 10); - if (!ret) return false; - - const { collisions, z: retZ, modelIds } = ret; + if (collisions <= 0) return false; let depth = FLOAT_INFINITY; let instanceDepth = FLOAT_INFINITY; - if (collisions <= 0) return false; - for (let i = 0, j = 0; i < collisions; i++) { if (modelIds[i] !== WATER_OBJECT) continue; diff --git a/packages/colandreas/src/natives/index.ts b/packages/colandreas/src/natives/index.ts index ecafd01a..fde9c78b 100644 --- a/packages/colandreas/src/natives/index.ts +++ b/packages/colandreas/src/natives/index.ts @@ -1,3 +1,5 @@ +import { MAX_MULTICAST_SIZE } from "../definitions"; + export function init() { return Boolean(samp.callNative("CA_Init", "")); } @@ -34,20 +36,7 @@ export function rayCastLine( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLine", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z] = samp.callNative( + const [x, y, z, result] = samp.callNative( "CA_RayCastLine", "ffffffFFF", startX, @@ -57,6 +46,9 @@ export function rayCastLine( endY, endZ ) as number[]; + + if (!result) return null; + return { result, x, y, z }; } @@ -68,20 +60,7 @@ export function rayCastLineID( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineID", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z] = samp.callNative( + const [x, y, z, result] = samp.callNative( "CA_RayCastLineID", "ffffffFFF", startX, @@ -91,6 +70,9 @@ export function rayCastLineID( endY, endZ ) as number[]; + + if (!result) return null; + return { result, x, y, z }; } @@ -103,21 +85,7 @@ export function rayCastLineExtraID( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineExtraID", - "iffffff", - type, - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z] = samp.callNative( + const [x, y, z, result] = samp.callNative( "CA_RayCastLineExtraID", "iffffffFFF", type, @@ -128,6 +96,9 @@ export function rayCastLineExtraID( endY, endZ ) as number[]; + + if (!result) return null; + return { result, x, y, z }; } @@ -138,43 +109,29 @@ export function rayCastMultiLine( endX: number, endY: number, endZ: number, - size: number + size = MAX_MULTICAST_SIZE ) { - const collisions = samp.callNative( - "CA_RayCastMultiLine", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - const [x, y, z, dist, modelIds] = samp.callNative( + const [x, y, z, dist, modelIds, result] = samp.callNative( "CA_RayCastMultiLine", - "ffffffAiAiAiAiAii", + "ffffffVVVVAi", startX, startY, startZ, endX, endY, endZ, - size, - size, - size, - size, - size, size - ) as number[][]; + ) as [number[], number[], number[], number[], number[], number]; + + const len = result > 0 ? result : 0; return { - collisions, - x, - y, - z, - dist, - modelIds, + collisions: result, + x: x.slice(0, len), + y: y.slice(0, len), + z: z.slice(0, len), + dist: dist.slice(0, len), + modelIds: modelIds.slice(0, len), }; } @@ -186,20 +143,7 @@ export function rayCastLineAngle( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineAngle", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z, rx, ry, rz] = samp.callNative( + const [x, y, z, rx, ry, rz, result] = samp.callNative( "CA_RayCastLineAngle", "ffffffFFFFFF", startX, @@ -210,6 +154,8 @@ export function rayCastLineAngle( endZ ) as number[]; + if (!result) return null; + return { result, x, y, z, rx, ry, rz }; } @@ -221,20 +167,7 @@ export function rayCastReflectionVector( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastReflectionVector", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z, nx, ny, nz] = samp.callNative( + const [x, y, z, nx, ny, nz, result] = samp.callNative( "CA_RayCastReflectionVector", "ffffffFFFFFF", startX, @@ -245,6 +178,8 @@ export function rayCastReflectionVector( endZ ) as number[]; + if (!result) return null; + return { result, x, y, z, nx, ny, nz }; } @@ -256,20 +191,7 @@ export function rayCastLineNormal( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineNormal", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number; - - if (result === 0) return null; - - const [x, y, z, nx, ny, nz] = samp.callNative( + const [x, y, z, nx, ny, nz, result] = samp.callNative( "CA_RayCastLineNormal", "ffffffFFFFFF", startX, @@ -280,6 +202,8 @@ export function rayCastLineNormal( endZ ) as number[]; + if (!result) return null; + return { result, x, y, z, nx, ny, nz }; } @@ -321,34 +245,26 @@ export function quatToEuler(x: number, y: number, z: number, w: number) { } export function getModelBoundingSphere(modelId: number) { - const result = Boolean( - samp.callNative("CA_GetModelBoundingSphere", "i", modelId) - ); - - if (!result) return null; - - const [offX, offY, offZ, radius] = samp.callNative( + const [offX, offY, offZ, radius, result] = samp.callNative( "CA_GetModelBoundingSphere", "iFFFF", modelId ) as number[]; + if (!result) return null; + return { offX, offY, offZ, radius }; } export function getModelBoundingBox(modelId: number) { - const result = Boolean( - samp.callNative("CA_GetModelBoundingBox", "i", modelId) - ); - - if (!result) return null; - - const [minX, minY, minZ, maxX, maxY, maxZ] = samp.callNative( + const [minX, minY, minZ, maxX, maxY, maxZ, result] = samp.callNative( "CA_GetModelBoundingBox", "iFFFFFF", modelId ) as number[]; + if (!result) return null; + return { minX, minY, minZ, maxX, maxY, maxZ }; } @@ -360,20 +276,7 @@ export function rayCastLineEx( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineEx", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ); - - if (result === 0) return null; - - const [x, y, z, rx, ry, rz, rw, cx, cy, cz] = samp.callNative( + const [x, y, z, rx, ry, rz, rw, cx, cy, cz, result] = samp.callNative( "CA_RayCastLineEx", "ffffffFFFFFFFFFF", startX, @@ -384,6 +287,8 @@ export function rayCastLineEx( endZ ) as number[]; + if (!result) return null; + return { x, y, z, rx, ry, rz, rw, cx, cy, cz }; } @@ -395,29 +300,19 @@ export function rayCastLineAngleEx( endY: number, endZ: number ) { - const result = samp.callNative( - "CA_RayCastLineAngleEx", - "ffffff", - startX, - startY, - startZ, - endX, - endY, - endZ - ); + const [x, y, z, rx, ry, rz, ocx, ocy, ocz, orx, ory, orz, result] = + samp.callNative( + "CA_RayCastLineAngleEx", + "ffffffFFFFFFFFFFFF", + startX, + startY, + startZ, + endX, + endY, + endZ + ) as number[]; - if (result === 0) return null; - - const [x, y, z, rx, ry, rz, ocx, ocy, ocz, orx, ory, orz] = samp.callNative( - "CA_RayCastLineAngleEx", - "ffffffFFFFFFFFFFFF", - startX, - startY, - startZ, - endX, - endY, - endZ - ) as number[]; + if (!result) return null; return { x, y, z, rx, ry, rz, ocx, ocy, ocz, orx, ory, orz }; }