-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatches.lua
181 lines (147 loc) · 3.74 KB
/
patches.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
ioLib = exports['sandbox-patches']:GetIoLib()
osLib = exports['sandbox-patches']:GetOsLib()
ioGlobal = {
handle = nil,
}
function io.open(path, mode)
local ioObj = {
handle = ioLib:open(path, mode),
}
function ioObj:close()
return ioLib.close(self.handle)
end
function ioObj:read(mode)
local data = ioLib.read(self.handle, mode)
if data and string.sub(data, 0, 4) == 'hex:' then
return hexdecode(string.sub(data, 5))
end
return data
end
function ioObj:write(...)
local data = ''
for i = 1, select('#', ...) do
data = data .. select(i, ...)
end
data = hexencode(data)
return ioLib.write(self.handle, 'hex:' .. data)
end
function ioObj:flush()
return ioLib.flush(self.handle)
end
function ioObj:seek(whence, offset)
return ioLib.seek(self.handle, whence, offset)
end
function ioObj:lines()
return ioLib.lines(self.handle)
end
ioGlobal.handle = ioObj.handle
return ioObj.handle and ioObj or nil
end
function io.close(handle)
if handle == nil then
handle = ioGlobal.handle
end
ioGlobal.handle = nil
return ioLib.close(handle)
end
function io.read(mode)
local data = ioLib.read(ioGlobal.handle, mode)
if string.sub(data, 0, 4) == 'hex:' then
return hexdecode(string.sub(data, 5))
end
return data
end
function io.write(...)
local data = ''
for i = 1, select('#', ...) do
data = data .. select(i, ...)
end
data = hexencode(data)
return ioLib.write(ioGlobal.handle, 'hex:' .. data)
end
function io.flush()
return ioLib.flush(ioGlobal.handle)
end
function io.seek(whence, offset)
return ioLib.seek(ioGlobal.handle, whence, offset)
end
function io.input(file)
ioGlobal.handle = ioLib.input(file)
end
function io.output(file)
ioGlobal.handle = ioLib.output(file)
end
function io.lines(file)
local data = ioLib.lines(file)
if file ~= nil then
io.input()
end
end
function io.tmpfile()
return ioLib.tmpfile()
end
function io.type(obj)
return ioLib.type(obj)
end
function io.popen(cmd, mode)
local ioObj = {
handle = ioLib.popen(cmd, mode)
}
function ioObj:close()
return ioLib.close(self.handle)
end
function ioObj:read(mode)
local data = ioLib.read(self.handle, mode)
if data and string.sub(data, 0, 4) == 'hex:' then
return hexdecode(string.sub(data, 5))
end
return data
end
function ioObj:write(...)
local data = ''
for i = 1, select('#', ...) do
data = data .. select(i, ...)
end
data = hexencode(data)
return ioLib.write(self.handle, 'hex:' .. data)
end
function ioObj:flush()
return ioLib.flush(self.handle)
end
function ioObj:seek(whence, offset)
return ioLib.seek(self.handle, whence, offset)
end
function ioObj:lines()
return ioLib.lines(self.handle)
end
ioGlobal.handle = ioObj.handle
return ioObj.handle and ioObj or nil
end
function os.execute(cmd)
return osLib.execute(cmd)
end
function os.getenv(varname)
return osLib.getenv(varname)
end
function os.remove(file)
return osLib.remove(file)
end
function os.rename(old, new)
return osLib.rename(old, new)
end
function os.tmpname()
return osLib.tmpname()
end
function os.setlocale(locale, category)
return osLib.setlocale(locale, category)
end
function hexdecode(hex)
return (hex:gsub('%x%x', function(cc)
return string.char(tonumber(cc, 16))
end))
end
function hexencode(str)
return (str:gsub('.', function(c)
return string.format('%02X', string.byte(c))
end))
end