Skip to content

Commit

Permalink
fix(shared, compat): Check compat class constructor length
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Mar 4, 2024
1 parent ced3fa6 commit 8222ae0
Show file tree
Hide file tree
Showing 48 changed files with 246 additions and 9 deletions.
7 changes: 6 additions & 1 deletion client/js/compatibility/classes/areaBlip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

requireBinding("client/entity.js");
/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

const { SharedBlip } = requireBinding("shared/compatibility/classes/sharedBlip.js");
const { BaseObject } = requireBinding("client/compatibility/classes/baseObject.js");
const { WorldObject } = requireBinding("client/compatibility/classes/worldObject.js");

requireBinding("client/entity.js");

class AreaBlip {
constructor(x, y, z, width, height) {
assert(arguments.length === 5, "5 arguments expected");

return alt.AreaBlip.create({
pos: { x, y, z },
scale: { x: width, y: height }
Expand Down
4 changes: 3 additions & 1 deletion client/js/compatibility/classes/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
requireBinding("client/factory.js");

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assertIsType } = requireBinding("shared/utils.js");
const { assertIsType, assert } = requireBinding("shared/utils.js");

class Audio extends alt.Audio {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 1 && args.length <= 4, "Minimum 1, maximum 4 arguments expected");

const [source, volume, radio, clearCache] = args;

return alt.Audio.create({ source, volume, radio, clearCache });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/audioCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class AudioCategory extends alt.AudioCategory {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length === 1, "1 arguments expected");

return alt.AudioCategory.get(args[0]);
}

Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/audioFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class AudioFilter extends alt.AudioFilter {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length === 1, "1 arguments expected");

return alt.AudioFilter.create({ hash: args[0] });
}

Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/audioOutputAttached.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class AudioOutputAttached extends alt.AudioOutputAttached {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 1 && args.length <= 2, "Minimum 1, maximum 2 arguments expected");

const [entity, categoryHash] = args;

return alt.AudioOutputAttached.create({ entity, categoryHash });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/audioOutputFrontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class AudioOutputFrontend extends alt.AudioOutputFrontend {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 0 && args.length <= 1, "Minimum 0, maximum 1 arguments expected");

const [categoryHash] = args;

return alt.AudioOutputFrontend.create({ categoryHash });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/audioOutputWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class AudioOutputWorld extends alt.AudioOutputWorld {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 1 && args.length <= 2, "Minimum 1, maximum 2 arguments expected");

const [pos, categoryHash] = args;

return alt.AudioOutputWorld.create({ pos, categoryHash });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/checkpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("shared/factory.js");

class Checkpoint extends alt.Checkpoint {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length == 8 || args.length == 12, "8 or 12 arguments expected");

const type = args[0];
const pos = args.length == 8 ? args[1] : { x: args[1], y: args[2], z: args[3] };
const nextPos = args.length == 8 ? args[2] : { x: args[4], y: args[5], z: args[6] };
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapeCircle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapeCircle extends alt.ColShape {
constructor(...args) {
if (!args.length) return super();

assert(args.length === 3, "3 arguments expected");

const [x, y, radius] = args;

return alt.ColShapeCircle.create({
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapeCuboid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapeCuboid extends alt.ColShape {
constructor(...args) {
if (!args.length) return super();

assert(args.length === 6, "6 arguments expected");

const [x, y, z, x2, y2, z2] = args;

return alt.ColShapeCuboid.create({
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapeCylinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapeCylinder extends alt.ColShape {
constructor(...args) {
const [x, y, z, radius, height] = args;

assert(args.length === 5, "5 arguments expected");

return alt.ColShapeCylinder.create({
pos: { x, y, z },
radius,
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapePolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapePolygon extends alt.ColShape {
constructor(...args) {
if (!args.length) return super();

assert(args.length === 3, "3 arguments expected");

const [minZ, maxZ, points] = args;

return alt.ColShapePolygon.create({
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapeRectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapeRectangle extends alt.ColShape {
constructor(...args) {
if (!args.length) return super();

assert(args.length === 4, "4 arguments expected");

const [x, y, x2, y2] = args;

return alt.ColShapeRectangle.create({
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/colshapeSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class ColshapeSphere extends alt.ColShape {
constructor(...args) {
if (!args.length) return super();

assert(args.length === 4, "4 arguments expected");

const [x, y, z, radius] = args;

return alt.ColShapeSphere.create({
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/localObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class LocalObject extends alt.LocalObject {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 3 && args.length <= 7, "Minimum 3, maximum 7 arguments expected");

const [model, pos, rot, noOffset, dynamic, useStreaming, streamingDistance] = args;

return alt.LocalObject.create({ model, pos, rot, noOffset, dynamic, useStreaming, streamingDistance });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/localPed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class LocalPed extends alt.LocalPed {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 4 && args.length <= 6, "Minimum 4, maximum 6 arguments expected");

const [model, dimension, pos, heading, useStreaming, streamingDistance] = args;

return alt.LocalPed.create({ model, dimension, pos, heading, useStreaming, streamingDistance });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/localVehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("client/factory.js");

class LocalVehicle extends alt.LocalVehicle {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 4 && args.length <= 6, "Minimum 4, maximum 6 arguments expected");

const [model, dimension, pos, rot, useStreaming, streamingDistance] = args;

return alt.LocalVehicle.create({ model, dimension, pos, rot, useStreaming, streamingDistance });
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/mapZoomData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

class MapZoomData extends alt.MapZoomData {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length === 1, "1 arguments expected");

return alt.MapZoomData.get(zoomDataId[0]);
}
}
Expand Down
5 changes: 5 additions & 0 deletions client/js/compatibility/classes/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

requireBinding("shared/factory.js");

class Marker extends alt.Marker {
constructor(...args) {
// NOTE (xLuxy): This prevents the infinite loop caused by alt.*.create
if (!args.length) return super();

assert(args.length >= 3 && args.length <= 5, "Minimum 3, maximum 5 arguments expected");

const [type, pos, color, useStreaming, streamingDistance] = args;

return alt.Marker.create({ type, pos, color, useStreaming, streamingDistance });
Expand Down
6 changes: 6 additions & 0 deletions client/js/compatibility/classes/memoryBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
/** @type {typeof import("../../../../shared/js/compatibility/utils/classes.js")} */
const { extendClassWithProperties } = requireBinding("shared/compatibility/utils/classes.js");

/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert, assertIsType } = requireBinding("shared/utils.js");

requireBinding("shared/logging.js");

class MemoryBuffer extends alt.Buffer {
constructor(size) {
assertIsType(size, "number", "1 arguments expected");
assert(size <= 1024, "You can't allocate > 1KB");

return new alt.Buffer(size);
}

Expand Down
10 changes: 7 additions & 3 deletions client/js/compatibility/classes/pointRadius.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
/// <reference path="../../../../types/client/index.d.ts" />
// import * as alt from "@altv/client";

requireBinding("client/entity.js");
/** @type {typeof import("../../../../shared/js/utils.js")} */
const { assert } = requireBinding("shared/utils.js");

const { SharedBlip } = requireBinding("shared/compatibility/classes/sharedBlip.js");
const { BaseObject } = requireBinding("client/compatibility/classes/baseObject.js");
const { WorldObject } = requireBinding("client/compatibility/classes/worldObject.js");

requireBinding("client/entity.js");

class PointBlip {
constructor(...args) {
if (args.length == 3) return alt.PointBlip.create({ pos: { x: args[0], y: args[1], z: args[2] } });
else return alt.PointBlip.create({ entity: args[0] });
assert(args.length == 3, "3 arguments expected");

return alt.PointBlip.create({ pos: { x: args[0], y: args[1], z: args[2] } });
}
}

Expand Down
Loading

0 comments on commit 8222ae0

Please sign in to comment.