[Lua] MemoryClean

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
script_name('MemoryClean')
script_authors('DarkP1xel', 'Azller Lollison')
script_url('https://blast.hk/threads/20961/')
local memory = require 'memory'
local auto = false
local limit = 300
local smsg = true
local function round(num, idp)
local mult = 10 ^ (idp or 0)
return math.floor(num * mult + 0.5) / mult
end
local function get_memory()
return round(memory.read(0x8E4CB4, 4, true) / 1048576, 1)
end
local function CheckMemory()
local info = get_memory()
if info >= limit then info = '{FF0000}' .. info .. '{FFFFFF}' end
sampAddChatMessage(('{6A5ACD}[MemoryClean]{FFFFFF} Память заполнена на %s МБ.'):format(info), 0x01A0E9)
end
local function CleanMemory()
-- адреса памяти можно взять тут https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CGame.cpp
callFunction(0x53C500, 2, 2, true, true)
callFunction(0x53C810, 1, 1, true)
callFunction(0x53BED0, 0, 0)
callFunction(0x40CF80, 0, 0)
callFunction(0x53C440, 0, 0)
callFunction(0x707770, 0, 0)
callFunction(0x4090A0, 0, 0)
callFunction(0x5A18B0, 0, 0)
callFunction(0x53C4A0, 0, 0)
callFunction(0x53C240, 0, 0)
local detectX, detectY, detectZ = getCharCoordinates(PLAYER_PED)
requestCollision(detectX, detectY)
loadScene(detectX, detectY, detectZ)
sampAddChatMessage('{6A5ACD}[MemoryClean]{FFFFFF} Очистка памяти прошла успешно.', 0x01A0E9)
smsg = true
end
local function AutoCleanMemory()
auto = not auto
sampAddChatMessage(('{6A5ACD}[MemoryClean]{FFFFFF} Автоматическая очистка памяти %s.'):format(auto and '{00AA00}Включена{FFFFFF}' or '{FF0000}Выключена{FFFFFF}'), 0x01A0E9)
end
function main()
repeat wait(0) until isSampAvailable()
sampRegisterChatCommand('acln', AutoCleanMemory)
sampRegisterChatCommand('cln', CleanMemory)
sampRegisterChatCommand('cmem', CheckMemory)
while true do wait(0)
if get_memory() > limit then
if auto then
CleanMemory()
elseif smsg then
sampAddChatMessage(('{6A5ACD}[MemoryClean]{FFFFFF} Память преодолела отметку в %d МБ.'):format(limit), 0x01A0E9)
smsg = false
end
end
end
end