-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatives_overloader.lua
126 lines (107 loc) · 2.97 KB
/
natives_overloader.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
local serverSide = IsDuplicityVersion()
LOGGER_PATH = 'https://gist.githubusercontent.com/itIsMaku/a603a23c34582464083ba0ce5d2bbcff/raw/d6488d0d1d09d96dee8076c3add72c2580be6c5d/logger.lua'
GIT_NATIVES_TREE_PATH = 'https://api.github.com/repos/citizenfx/natives/git/trees/master?recursive=1'
STARTING_PATHS = {
'APP',
'AUDIO',
'BRAIN',
'CAM',
'CLOCK',
'CUTSCENE',
'DATAFILE',
'DECORATOR',
'DLC',
'ENTITY',
'EVENT',
'FILES',
'FIRE',
'GRAPHICS',
'HUD',
'INTERIOR',
'ITEMSET',
'LOADINGSCREEN',
'LOCALIZATION',
'MISC',
'MOBILE',
'MONEY',
'NETSHOPPING',
'NETWORK',
'OBJECT',
'PAD',
'PATHFIND',
'PED',
'PHYSICS',
'PLAYER',
'RECORDING',
'REPLAY',
'SAVEMIGRATION',
'SCRIPT',
'SHAPETEST',
'SOCIALCLUB',
'STATS',
'STREAMING',
'SYSTEM',
'TASK',
'VEHICLE',
'WATER',
'WEAPON',
'ZONE',
}
IGNORE_NATIVES = {
['Wait'] = true
}
local function overload(native)
load(string.format([[
local _%s = %s
%s = function(...)
print('^3[overloader] | ^7Native: ^3%s^7, params: ', ...)
return _%s(...)
end
]], native, native, native, native, native))()
end
if serverSide then
local function getPathContent(path, expectJson)
local p = promise.new()
PerformHttpRequest(path, function(statusCode, response, headers)
p:resolve(expectJson and json.decode(response) or response)
end, 'GET', '', { ['Content-Type'] = 'application/json' })
return Citizen.Await(p)
end
local logger = getPathContent(LOGGER_PATH, false)
load(logger)()
log.info('Fetching natives tree from [%s]...', GIT_NATIVES_TREE_PATH)
local nativesResponse = getPathContent(GIT_NATIVES_TREE_PATH, true)
log.info('Response received, parsing...')
local nativesTree = nativesResponse.tree
if nativesTree == nil then
log.error('Failed to fetch natives tree.')
return
end
local natives = {}
local size = 0
for _, nativeEntry in ipairs(nativesTree) do
for _, startingPath in ipairs(STARTING_PATHS) do
if nativeEntry.path:find(startingPath) == 1 then
local nativeName = nativeEntry.path:match('([^/]+)%.md$')
if nativeName and not IGNORE_NATIVES[nativeName] then
natives[nativeName] = true
size = size + 1
end
end
end
end
log.info('Found %d natives, overloading...', size)
for native, _ in pairs(natives) do
overload(native)
end
log.info('Overloading completed.')
TriggerClientEvent('overloader:natives', -1, logger, natives, size)
end
RegisterNetEvent('overloader:natives', function(logger, natives, size)
load(logger)()
log.info('Overloading %d natives...', size)
for native, _ in pairs(natives) do
overload(native)
end
log.info('Overloading completed.')
end)