-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.lua
156 lines (135 loc) · 4.28 KB
/
loader.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
-- Options
#ENCRYPT = false
#ENCRYPTION_KEY = 'key!'
#DEBUG_PERF = false
-- Includes
#include 'include/nativeFunction.lua'
#if(ENCRYPT) then
# load 'include/xorCipher.lua'
# include 'include/xorCipher.lua'
--#include 'include/decrypt.lua'
#end
local f = {
rnd = math.random,
loadstr = loadstring,
load = load,
md5 = md5,
addEvent = addEvent,
addEventHandler = addEventHandler,
removeEventHandler = removeEventHandler,
triggerEvent = triggerEvent,
}
-- Check if functions are hooked
if(not areNativeFunctions(f)) then return end
local EvVerifierReady = 'AOGltgWlbU'
local EvVerifyReq = 'YSRDCiwdyY'
local EvVerified = '0CqFvjg0uc'
local EvResStart = triggerClientEvent and 'onResourceStart' or 'onClientResourceStart'
local g_ResStarting = false
local g_ResStarted = false
f.addEvent(EvVerifierReady)
f.addEvent(EvVerifyReq)
f.addEvent(EvVerified)
f.addEvent('toxic.onResReady')
local tryVerify
tryVerify = function()
--outputDebugString('tryVerify')
local n = f.rnd(0, 32000)
local onVerified
onVerified = function(code)
if(code ~= f.md5('8_ccDr-8'..tostring(n^2+93))) then return end
f.removeEventHandler(EvVerifierReady, root, tryVerify)
local side = triggerClientEvent and 'server' or 'client'
--outputDebugString('Server verified ('..getResourceName(resource)..' - '..side..')')
--loadScript = function()
--outputDebugString('Timer proc start')
-- Hook addEventHandler to catch all onResourceStart handlers
local initFuncTbl = {}
local _addEventHandler = addEventHandler
if(g_ResStarted) then
addEventHandler = function(event, element, func, ...)
if(event and element and func) then
local success = _addEventHandler(event, element, func, ...)
if(success and event == EvResStart and (element == root or element == resourceRoot)) then
table.insert(initFuncTbl, func)
end
return success
else
outputDebugString(debug.traceback('Invalid argument for addEventHandler', 2), 2)
return false
end
end
end
#if(DEBUG_PERF) then
local startTicks = getTickCount()
#end
#if(ENCRYPT) then
# local encStartTicks
# if(DEBUG_PERF) then
# encStartTicks = os.clock()*1000
# end
local code = {
# local LUA_CHUNK = __LUA_CHUNK_TBL__
# for i, part in ipairs(LUA_CHUNK) do
# part = xorEncrypt(part, ENCRYPTION_KEY)
$(('%q'):format(part)),
# end
}
# if(DEBUG_PERF) then
# local dt = os.clock()*1000 - encStartTicks
# if(dt > 50) then print(__FILE__..' encryption has taken '..dt..' ms') end
# end
#else
local code = __LUA_CHUNK_TBL__
#end
local i = 0
local function reader()
i = i + 1
#if(ENCRYPT) then
return code[i] and xorEncrypt(code[i], '$(ENCRYPTION_KEY)')
#else
return code[i]
#end
end
--outputDebugString('Loading code ('..getResourceName(resource)..' - '..side..')')
local func, err = f.load(reader)
if(not func) then
outputDebugString('Failed to load '..getResourceName(resource)..': '..err, 1)
return
end
#if(DEBUG_PERF) then
local dt = getTickCount() - startTicks
if(dt > 50) then
outputDebugString('Loading '..getResourceName(resource)..' ('..side..') has taken '..dt..' ms!', 3)
end
#end
--outputDebugString('Running code ('..getResourceName(resource)..' - '..side..')')
func()
-- Call onResourceStart handlers
--outputDebugString('Calling '..#initFuncTbl..' initializers ('..side..')')
source = resourceRoot
for i, func in ipairs(initFuncTbl) do
func(resource)
end
--outputDebugString('Finished loading '..getResourceName(resource)..' - '..side)
--end
--setTimer(loadScript, 50, 1)
--outputDebugString('Created timer')
setElementData(resourceRoot, 'toxic.notReady', false, false)
if(not g_ResStarting) then
triggerEvent('toxic.onResReady', resourceRoot, resource)
end
end
f.addEventHandler(EvVerified, resourceRoot, onVerified)
f.triggerEvent(EvVerifyReq, resourceRoot, n)
f.removeEventHandler(EvVerified, resourceRoot, onVerified)
end
local function onResStart()
g_ResStarted = true
g_ResStarting = true
f.addEventHandler(EvVerifierReady, root, tryVerify)
tryVerify()
g_ResStarting = false
end
f.addEventHandler(EvResStart, resourceRoot, onResStart)
setElementData(resourceRoot, 'toxic.notReady', true, false)