CLEO REDUX [Snippet] Get samp version(*js)

This is snippet for getting samp versions(From 0.3.7 R1 - 0.3.7 R4 - 2). You can use it on new cleo extension Cleo Redux: https://re.cleo.li/.

The code contains 2 functions:

- get_samp_version_id
- get_samp_version_name


JavaScript:
/*
    get_samp_version_id function is reading the "IMAGE_FILE_HEADER" of samp.dll (TimeDateStamp to be specific)
    That TimeDateStamp is based on compilation time. See this for more info:
    https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#file-headers
 
    "TimeDateStamp = The low 32 bits of the number of seconds since 00:00 January 1, 1970 (a C run-time time_t value), that indicates when the file was created. "
 
    In most versions that time stamp is located at offset 0x128 from samp.dll. In "0.3.7 R3 1" it is located at 0x120 offset though.
    --------------------------------------------------------------------
    Credits:
    *Monday - https://ugbase.eu/members/monday.17492/
    Parazitas - https://ugbase.eu/members/parazitas.39678/
    --------------------------------------------------------------------
    Original post: https://ugbase.eu/threads/get-samp-version.21452/
*/

id = Int8Array;
verzija = Int8Array;

// Usage:  get_samp_version_id();
function get_samp_version_id()
{
    x = Int8Array;
    y = Int8Array;
    if ( x = DynamicLibrary.Load("samp.dll") ) {
        x += 0x128
        y = Memory.Read(x, 4, true);

        if (y == 0x5542F47A) {
            id = /*0.3.7 - R1*/1;
        }

        if (y == 0x59C30C94) {
            id = /*0.3.7 - R2*/2;
        }

        if (y == 0x5A6A3130) {
            id = /*0.3.DL - R1*/3;
        }

        x -= 8 // samp.dll + 0x120
        y = Memory.Read(x, 4, true);

        if (y == 0x5C0B4243) {
            id = /*0.3.7 - R3 - 1*/4;
        }

        if (y == 0x5DD606CD) {
            id = /*0.3.7 - R4 - 1*/5;
        }

        if (y == 0x6094ACAB) {
            id = /*0.3.7 - R4 - 2*/6;
        }
    }
}

// Usage get_samp_version_name();
function get_samp_version_name()
{
    get_samp_version_id();
    if (id == 0) verzija = "Unknown";
    if (id == 1) verzija = "0.3.7 - R1";
    if (id == 2) verzija = "0.3.7 - R2";
    if (id == 3) verzija = "0.3.DL - R1";
    if (id == 4) verzija = "0.3.7 - R3 - 1";
    if (id == 5) verzija = "0.3.7 - R4 - 1";
    if (id == 6) verzija = "0.3.7 - R4 - 2";
}

Simple example:

JavaScript:
/// <reference path=".config/sa.d.ts" />
/// <reference no-default-lib="true" />

id = Int8Array;
verzija = Int8Array;

var p = new Player(0);

var NUMPAD7 = 103;

while(true) {

    wait(250); {

        if (Pad.IsKeyPressed(NUMPAD7) && p.isPlaying()) {

            get_samp_version_name();
            Text.PrintFormattedNow("You use SA-MP %s", 250, verzija);
        }
    }
}

function get_samp_version_id()
{
    x = Int8Array;
    y = Int8Array;
    if ( x = DynamicLibrary.Load("samp.dll") ) {
        x += 0x128
        y = Memory.Read(x, 4, true);

        if (y == 0x5542F47A) {
            id = /*0.3.7 - R1*/1;
        }

        if (y == 0x59C30C94) {
            id = /*0.3.7 - R2*/2;
        }

        if (y == 0x5A6A3130) {
            id = /*0.3.DL - R1*/3;
        }

        x -= 8 // samp.dll + 0x120
        y = Memory.Read(x, 4, true);

        if (y == 0x5C0B4243) {
            id = /*0.3.7 - R3 - 1*/4;
        }

        if (y == 0x5DD606CD) {
            id = /*0.3.7 - R4 - 1*/5;
        }

        if (y == 0x6094ACAB) {
            id = /*0.3.7 - R4 - 2*/6;
        }
    }
}

function get_samp_version_name()
{
    get_samp_version_id();
    if (id == 0) verzija = "Unknown";
    if (id == 1) verzija = "0.3.7 - R1";
    if (id == 2) verzija = "0.3.7 - R2";
    if (id == 3) verzija = "0.3.DL - R1";
    if (id == 4) verzija = "0.3.7 - R3 - 1";
    if (id == 5) verzija = "0.3.7 - R4 - 1";
    if (id == 6) verzija = "0.3.7 - R4 - 2";
}


Note: The functions inside the snippet are not mine, I just translated from .cs to .js(javascript) format to make it easier for you if someone wants to try javascript.
 
Last edited by a moderator:
Top