rock-mod
Version:
Rock-Mod is a powerful framework designed for creating and managing mods for Grand Theft Auto (GTA) games.
47 lines (46 loc) • 2.02 kB
JavaScript
import { CCMPNativeCallerManager } from "../native/CCMPNativeCallerManager";
import { Vector3D } from "../../../../shared/common/utils";
const START_SHAPE_TEST_LOS_PROBE = "0x7EE9F5D83DD4F90E";
const GET_SHAPE_TEST_RESULT = "0x3D87450E15D98694";
const DEFAULT_TRACE_FLAG = 7;
export class CCMPRaycastingManager {
constructor() {
this._native = new CCMPNativeCallerManager();
}
testPointToPoint(startPos, endPos, ignoreEntity, flags) {
const shapeTestHandle = this._native.callNative(START_SHAPE_TEST_LOS_PROBE, startPos.x, startPos.y, startPos.z, endPos.x, endPos.y, endPos.z, this._resolveFlags(flags), this._resolveIgnoreHandle(ignoreEntity), DEFAULT_TRACE_FLAG);
const result = this._native.callNative(GET_SHAPE_TEST_RESULT, shapeTestHandle);
const [, hit, position, surfaceNormal, entityHandle] = result;
if (!hit) {
return null;
}
return {
entityHandle,
position: this._toVector3D(position),
surfaceNormal: this._toVector3D(surfaceNormal),
};
}
_resolveFlags(flags) {
if (Array.isArray(flags)) {
return flags.reduce((acc, flag) => acc | flag, 0);
}
return flags !== null && flags !== void 0 ? flags : 0;
}
_resolveIgnoreHandle(ignoreEntity) {
if (!ignoreEntity) {
return 0;
}
const entity = Array.isArray(ignoreEntity) ? ignoreEntity[0] : ignoreEntity;
return this._isIgnoreEntity(entity) ? entity.handle : 0;
}
_isIgnoreEntity(entity) {
return typeof (entity === null || entity === void 0 ? void 0 : entity.handle) === "number";
}
_toVector3D(value) {
var _a, _b, _c;
if (Array.isArray(value)) {
return new Vector3D((_a = value[0]) !== null && _a !== void 0 ? _a : 0, (_b = value[1]) !== null && _b !== void 0 ? _b : 0, (_c = value[2]) !== null && _c !== void 0 ? _c : 0);
}
return new Vector3D(value.x, value.y, value.z);
}
}