This can be used to create scripts that work with various samp versions.
In order to use it, I suggest to create "includes" folder inside the "gta_sa/cleo" folder. Then create "get_samp_version.txt" file inside it and paste the code below into it.
The code below contains 2 functions:
- get_samp_version_id (returning arbitrary number so you can easily compare it in your scripts)
- get_samp_version_name
Then, the whole content of this txt file can be included in your scripts by using "$INCLUDE" directive of sanny builder like:
It should be included at the end of the script.
You could use it like this:
In order to use it, I suggest to create "includes" folder inside the "gta_sa/cleo" folder. Then create "get_samp_version.txt" file inside it and paste the code below into it.
The code below contains 2 functions:
- get_samp_version_id (returning arbitrary number so you can easily compare it in your scripts)
- get_samp_version_name
Code:
/*
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.
*/
// Usage: 0AB1: call_scm_func @get_samp_version_id 0 _returned_id 0@
:get_samp_version_id
30@ = 0
if 0AA2: 31@ = load_library "samp.dll" // IF and SET
then
31@ += 0x128
0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
if 29@ == 0x5542F47A
then
// 0.3.7 R1
30@ = 1
end
if 29@ == 0x59C30C94
then
// 0.3.7 R2
30@ = 2
end
if 29@ == 0x5A6A3130
then
// 0.3.DL R1
30@ = 3
end
31@ -= 8 // reading samp.dll + 0x120
0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
if 29@ == 0x5C0B4243
then
// 0.3.7 R3 1
30@ = 4
end
end
0AB2: ret 1 30@
// Usage: 0AB1: call_scm_func @get_samp_version_name 0 _returned_name 0@
//
// There's no need to allocate memory, it is allocated inside function. If the function is called
// repetitively then you can free memory before making another call (using: 0AC9: free_allocated_memory 0@)
:get_samp_version_name
0AB1: call_scm_func @get_samp_version_id 0 _returned_id 30@
0AC8: 31@ = allocate_memory_size 30
if 30@ == 0
then
0AD3: 31@ = format "Not recognized"
end
if 30@ == 1
then
0AD3: 31@ = format "0.3.7 R1"
end
if 30@ == 2
then
0AD3: 31@ = format "0.3.7 R2"
end
if 30@ == 3
then
0AD3: 31@ = format "0.3.DL R1"
end
if 30@ == 4
then
0AD3: 31@ = format "0.3.7 R3 1"
end
0AB2: ret 1 31@
Then, the whole content of this txt file can be included in your scripts by using "$INCLUDE" directive of sanny builder like:
{$INCLUDE includes/get_samp_version.txt}
It should be included at the end of the script.
You could use it like this:
Code:
{$CLEO}
0000:
// this testing code requires sampfuncs (but the get_samp_version.txt file doesn't)
// so you could include it in some code without sampfuncs and both functions (id, name) should still work
repeat
wait 0
until 0AFA: is_samp_available
call @get_samp_version_id 0 id 0@
call @get_samp_version_name 0 name 1@
chatmsg "%d, %s" -1 0@ 1@
0A93: end_custom_thread
{$INCLUDE includes/get_samp_version.txt}