-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
167 lines (137 loc) · 5.63 KB
/
server.lua
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
myName = GetCurrentResourceName()
fileName = "shared_script '@" .. myName .. "/shared.lua'"
RegisterCommand('antidump', function(source, args)
if source ~= 0 then return end
local option = args[1]
local parameter = args[2]
if option == 'install' then
if parameter then
if myName == parameter then return end
local state = GetResourceState(parameter)
if state == 'missing' then
print(("[^3some_antidump^7] Resource %s is missing!"):format(parameter))
return
elseif state ~= 'started' then
print(("[^3some_antidump^7] Resource %s is not started!"):format(parameter))
return
end
if Config.IgnoredScripts[parameter] then
print(("[^3some_antidump^7] Resource %s is on the ignore list"):format(parameter))
else
local success = install(parameter)
if success == false then
print(("[^3some_antidump^7] Antidump is already installed in resource %s"):format(parameter))
end
end
else
local found = 0
local installed = 0
for i=0, GetNumResources() do
local resource = GetResourceByFindIndex(i)
if resource and myName == resource then goto continue end
if resource and GetResourceState(resource) ~= 'missing' then
found+=1
if install(resource, true) then installed+=1 end
end
::continue::
end
print(("[^3some_antidump^7] Installed antidump to %s/%s scripts"):format(installed, found))
end
elseif option == 'uninstall' then
if parameter then
if myName == parameter then return end
local state = GetResourceState(parameter)
if state == 'missing' then
print(("[^3some_antidump^7] Resource %s is missing!"):format(parameter))
return
elseif state ~= 'started' then
print(("[^3some_antidump^7] Resource %s is not started!"):format(parameter))
return
end
local success = uninstall(parameter)
if not success then
print(("[^3some_antidump^7] Antidump is not installed in resource %s"):format(parameter))
end
else
local found = 0
local uninstalled = 0
for i=0, GetNumResources() do
local resource = GetResourceByFindIndex(i)
if resource and myName == resource then goto continue end
if resource and GetResourceState(resource) ~= 'missing' then
found+=1
if uninstall(resource, true) then uninstalled+=1 end
end
::continue::
end
print(("[^3some_antidump^7] Uninstalled antidump from %s/%s scripts"):format(uninstalled, found))
end
else
print("[^3some_antidump^7] Wrong option!")
end
end)
function install(resource, auto)
local installed, manifestName = checkIfInstalled(resource)
if not installed and not manifestName then
if not auto then
print(("[^3some_antidump^7] ^1Couldn't find manifest of resource %s^7"):format(resource))
end
return
end
local manifest = LoadResourceFile(resource, manifestName)
if installed then
return false
else
for i=0, GetNumResourceMetadata(resource, 'client_script')-1 do
local data = GetResourceMetadata(resource, 'client_script', i)
if data then
if data:find('%*%*') then
print(("[^3some_antidump^7] ^1Cannot install antidump in resource %s! ^3Globbing ** used in %s^7"):format(resource, data))
return
end
end
end
manifest = fileName .. '\n' .. manifest
manifest = manifest:gsub("client_script '([^']+)'", 'antidump \'%1\'')
manifest = manifest:gsub("client_scripts%s*{", 'antidump {')
SaveResourceFile(resource, manifestName, manifest, manifest:len())
print(("[^3some_antidump^7] ^2Installed antidump in resource %s^7"):format(resource))
return true
end
end
function uninstall(resource, auto)
local installed, manifestName = checkIfInstalled(resource)
if not installed and not manifestName then
if not auto then
print(("[^3some_antidump^7] ^1Couldn't find manifest of resource %s^7"):format(resource))
end
return
end
local manifest = LoadResourceFile(resource, manifestName)
if installed then
manifest = manifest:gsub(fileName .. '\n', '')
manifest = manifest:gsub("antidump '([^']+)'", 'client_script \'%1\'')
manifest = manifest:gsub("antidump%s*{", 'client_scripts {')
SaveResourceFile(resource, manifestName, manifest, manifest:len())
print(("[^3some_antidump^7] ^2Uninstalled antidump from resource %s^7"):format(resource))
return true
else
return false
end
end
function checkIfInstalled(resource)
if GetResourceState(resource) == 'started' then
local manifestName = 'fxmanifest.lua'
local manifest = LoadResourceFile(resource, manifestName)
if not manifest then
manifestName = '__resource.lua'
manifest = LoadResourceFile(resource, manifestName)
end
if not manifest then
return false
end
return string.find(manifest, fileName), manifestName
else
return false
end
end