Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
265 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2020 Las Venturas Playground. All rights reserved. | ||
// Use of this source code is governed by the MIT license, a copy of which can | ||
// be found in the LICENSE file. | ||
|
||
// Represents a SAMPCAC detector as defined in our private JSON file. Detectors can either be based | ||
// on expected readings, or on unexpected reasons. Immutable after construction. | ||
export class Detector { | ||
// Type of supported detectors. | ||
static kTypeAllowList; | ||
static kTypeBlockList; | ||
|
||
#address_ = null; | ||
#bytes_ = null; | ||
#name_ = null; | ||
#type_ = null; | ||
|
||
#resultBytes_ = null; | ||
#resultChecksum_ = null; | ||
|
||
constructor(detector) { | ||
if (!detector.hasOwnProperty('name') || typeof detector.name !== 'string') | ||
throw new Error(`Each detector must have a human readable name.`); | ||
|
||
this.#name_ = detector.name; | ||
|
||
if (!detector.hasOwnProperty('address') || typeof detector.address !== 'number') | ||
throw new Error(`${this}: Non-numeric address specified in configuration.`); | ||
|
||
if (!detector.hasOwnProperty('bytes') || typeof detector.bytes !== 'number') | ||
throw new Error(`${this}: Non-numeric byte length specified in configuration.`); | ||
|
||
this.#address_ = detector.address; | ||
this.#bytes_ = detector.bytes; | ||
|
||
if (detector.hasOwnProperty('blocked')) { | ||
this.#type_ = Detector.kTypeBlockList; | ||
|
||
this.#resultBytes_ = detector.blocked.bytes ?? null; | ||
this.#resultChecksum_ = detector.blocked.checksum ?? null; | ||
|
||
} else if (detector.hasOwnProperty('expected')) { | ||
this.#type_ = Detector.kTypeAllowList; | ||
|
||
this.#resultBytes_ = detector.expected.bytes ?? null; | ||
this.#resultChecksum_ = detector.expected.checksum ?? null; | ||
|
||
} else { | ||
throw new Error(`${this}: Detector either has to be a blocked or allowed type.`); | ||
} | ||
|
||
if (this.#resultBytes_ !== null && !Array.isArray(this.#resultBytes_)) | ||
throw new Error(`${this}: Result bytes must be specified as an array.`); | ||
|
||
if (this.#resultChecksum_ !== null && typeof this.#resultChecksum_ !== 'number') | ||
throw new Error(`${this}: Result checksum must be specified as a number.`); | ||
|
||
if (this.#resultBytes_ === null && this.#resultChecksum_ === null) | ||
throw new Error(`${this}: Either the result bytes or checksum must be specified.`); | ||
} | ||
|
||
// Gets the name for this detector, will be shown in the dialogs. | ||
get name() { return this.#name_; } | ||
|
||
// Gets the address at which memory has to be read. | ||
get address() { return this.#address_; } | ||
|
||
// Gets the number of bytes that have to be read from the given address. | ||
get bytes() { return this.#bytes_; } | ||
|
||
// Gets the expected result of the Detector. The polarity might have to be negated depending | ||
// on the |type| of detector this instance represents. | ||
get resultBytes() { return this.#resultBytes_; } | ||
get resultChecksum() { return this.#resultChecksum_; } | ||
|
||
// Gets the type of detector this instance represents. | ||
get type() { return this.#type_; } | ||
|
||
// Returns a textual representation of this detector. | ||
toString() { return `[object Detector("${this.#name_}")]`; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2020 Las Venturas Playground. All rights reserved. | ||
// Use of this source code is governed by the MIT license, a copy of which can | ||
// be found in the LICENSE file. | ||
|
||
// Encapsulates the results of a SAMPCAC detection run. Self-contained to enable other parts of the | ||
// code to rely on this functionality without concern. | ||
export class DetectorResults { | ||
static kResultUnavailable = 0; // results could not be obtained from the player | ||
static kResultUndeterminable = 1; // results could not be interpreted against the detector | ||
static kResultClean = 2; // results came back negative | ||
static kResultDetected = 3; // results came back positive | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// Section: Meta-information about the player | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
// Version of the SA-MP client that they're using. | ||
version = null; | ||
|
||
// Version of the SAMPCAC client that they're using. May be NULL. | ||
sampcacVersion = null; | ||
|
||
// Hardware ID assigned to the player by SAMPCAC. Based on the VMProtect Hardware ID algorithm, | ||
// and is thus easily gameable. (https://helloacm.com/decode-hardware-id/) | ||
sampcacHardwareId = null; | ||
|
||
// Boolean indicating whether the player is currently minimized. This influences whether results | ||
// will be made available, as their client has to respond to it. | ||
minimized = null; | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
// Section: Detectors | ||
// --------------------------------------------------------------------------------------------- | ||
|
||
// Map of <detector name, detector result> for each of the defined detectors. Is not guaranteed | ||
// to have entries, as the detectors are not open sourced. In effectively randomized order. | ||
detectors = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters