-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSkybox Changer.lua
315 lines (225 loc) · 8.65 KB
/
Skybox Changer.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
-- Skybox Changer, Made By Exodouding (13429) for skeet.cc/gamesense.pub
local ffi = require("ffi")
local Skyboxes =
{
["Assault"] = "sky_cs15_daylight04_hdr",
["Aztec"] = "jungle",
["Baggage"] = "cs_baggage_skybox_",
["Canals"] = "sky_venice",
["Clear"] = "nukeblank",
["Clouds"] = "sky_cs15_daylight02_hdr",
["Clouds (2)"] = "vertigo",
["Clouds (Dark)"] = "sky_csgo_cloudy01",
["Cobblestone"] = "sky_cs15_daylight03_hdr",
["Daylight"] = "sky_cs15_daylight01_hdr",
["Daylight (2)"] = "vertigoblue_hdr",
["Dusty"] = "sky_dust",
["Gray"] = "sky_day02_05_hdr",
["Italy"] = "italy",
["Monastery"] = "embassy",
["Night"] =" sky_csgo_night02",
["Night (2)"] = "sky_csgo_night02b",
["Night (Flat)"] = "sky_csgo_night_flat",
["Rainy"] = "vietnam",
["Tibet"] = "cs_tibet",
["Vertigo"] = "office"
}
local function Patterns(module, interface, signature, typestring)
local interface = client.create_interface(module, interface) or error("invalid interface", 2)
local signature = client.find_signature(module, signature) or error("invalid signature", 2)
local success, typeof = pcall(ffi.typeof, typestring)
if not success then
error(typeof, 2)
end
local fnptr = ffi.cast(typeof, signature) or error("invalid typecast", 2)
return function(...)
return fnptr(interface, ...)
end
end
local int_ptr = ffi.typeof("int[1]")
local char_buffer = ffi.typeof("char[?]")
local find_first = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x6A\x00\xFF\x75\x10\xFF\x75\x0C\xFF\x75\x08\xE8\xCC\xCC\xCC\xCC\x5D", "const char*(__thiscall*)(void*, const char*, const char*, int*)")
local find_next = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x83\xEC\x0C\x53\x8B\xD9\x8B\x0D\xCC\xCC\xCC\xCC", "const char*(__thiscall*)(void*, int)")
local find_close = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x53\x8B\x5D\x08\x85", "void(__thiscall*)(void*, int)")
local current_directory = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x56\x8B\x75\x08\x56\xFF\x75\x0C", "bool(__thiscall*)(void*, char*, int)")
local add_to_searchpath = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x81\xEC\xCC\xCC\xCC\xCC\x8B\x55\x08\x53\x56\x57", "void(__thiscall*)(void*, const char*, const char*, int)")
local find_is_directory = Patterns("filesystem_stdio.dll", "VFileSystem017", "\x55\x8B\xEC\x0F\xB7\x45\x08", "bool(__thiscall*)(void*, int)")
local function GetCustomSkybox()
local files = {}
local file_handle = int_ptr()
local file = find_first("*", "XGAME", file_handle)
while file ~= nil do
local file_name = ffi.string(file)
if find_is_directory(file_handle[0]) == false and (file_name:find("dn.vtf")) then
files[#files+1] = file_name:sub(1, -7)
end
file = find_next(file_handle[0])
end
find_close(file_handle[0])
return files
end
local function NormalizeFileName(name)
local first_letter = name:sub(1, 1)
local rest = name:sub(2)
name = "Custom: ".. first_letter:upper() .. rest
if name:find("_") then
name = name:gsub("_", " ")
end
if name:find(".vtf") then
name = name:gsub(".vtf", "")
end
return name
end
local function TableDifference(t1, t2)
local diff = {}
for k, v in pairs(t1) do
if t2[k] ~= v then
diff[k] = v
end
end
for k, v in pairs(t2) do
if t1[k] ~= v then
diff[k] = v
end
end
return next(diff) ~= nil
end
local function CompareSkyboxNames(a, b)
local function GetComparisonValue(name)
if name:sub(1, 6) == "Custom" then
return "\255" .. name
else
return name
end
end
local nameA, numA = a:match("(%D+)(%d*)")
local nameB, numB = b:match("(%D+)(%d*)")
nameA = GetComparisonValue(nameA)
nameB = GetComparisonValue(nameB)
if nameA == nameB then
if numA == "" then
return false
elseif numB == "" then
return true
else
return tonumber(numA) < tonumber(numB)
end
else
return nameA < nameB
end
end
local skybox_names = {}
local old_custom_skyboxes = nil
local function CollectSkybox()
local current_path = char_buffer(192)
current_directory(current_path, ffi.sizeof(current_path))
current_path = string.format("%s\\csgo\\materials\\skybox", ffi.string(current_path))
add_to_searchpath(current_path, "XGAME", 0)
local custom_skyboxes = GetCustomSkybox()
if old_custom_skyboxes ~= nil and TableDifference(custom_skyboxes, old_custom_skyboxes) then
client.reload_active_scripts()
end
for i = 1, #custom_skyboxes do
local file_name = custom_skyboxes[i]
local normalized_name = NormalizeFileName(file_name)
if not Skyboxes[normalized_name] then
Skyboxes[normalized_name] = file_name
skybox_names[#skybox_names + 1] = normalized_name
end
end
old_custom_skyboxes = custom_skyboxes
local temp_skybox_names = {}
for k, v in pairs(Skyboxes) do
temp_skybox_names[#temp_skybox_names + 1] = k
end
table.sort(temp_skybox_names, CompareSkyboxNames)
skybox_names = temp_skybox_names
end
local function CollectSkyboxRefresh()
CollectSkybox()
client.delay_call(5, CollectSkyboxRefresh)
end
CollectSkyboxRefresh()
local skybox = ui.new_checkbox("VISUALS", "Effects", "Skybox Changer")
local skybox_names_listbox = ui.new_listbox("VISUALS", "Effects", "Skybox Names", skybox_names)
local skybox_color_checkbox = ui.new_checkbox("VISUALS", "Effects", "Skybox Color")
local skybox_color = ui.new_color_picker("VISUALS", "Effects", "Skybox Color", 255, 255, 255, 255)
local remove_3d_sky = ui.new_checkbox("VISUALS", "Effects", "Remove 3D Sky")
ui.set_visible(skybox_names_listbox, false)
local load_name_sky_address = client.find_signature("engine.dll", "\x55\x8B\xEC\x81\xEC\xCC\xCC\xCC\xCC\x56\x57\x8B\xF9\xC7\x45") or error("signature for load_name_sky is outdated")
local load_name_sky = ffi.cast(ffi.typeof("void(__fastcall*)(const char*)"), load_name_sky_address)
local default_skyname = nil
local function UpdateSkybox()
if default_skyname == nil then
default_skyname = cvar.sv_skyname:get_string()
end
if not ui.get(skybox) then
load_name_sky(default_skyname)
return
end
local name = skybox_names[ui.get(skybox_names_listbox) + 1]
load_name_sky(Skyboxes[name])
end
local function SkyboxColor()
if not entity.get_local_player() then
return
end
if ui.get(skybox_color_checkbox) then
local r, g, b, a = ui.get(skybox_color)
local materials = materialsystem.find_materials("skybox/")
for i=1, #materials do
materials[i]:color_modulate(r, g, b)
materials[i]:alpha_modulate(a)
end
else
local materials = materialsystem.find_materials("skybox/")
for i=1, #materials do
materials[i]:color_modulate(255, 255, 255)
materials[i]:alpha_modulate(255)
end
end
end
local function PlayerConnectFull(evt)
if client.userid_to_entindex(evt.userid) == entity.get_local_player() then
default_skyname = nil
UpdateSkybox()
SkyboxColor()
CollectSkybox()
end
end
local function Skybox(x)
ui.set_visible(skybox_names_listbox, ui.get(x))
if not ui.get(x) then
if default_skyname ~= nil then
load_name_sky(default_skyname)
else
load_name_sky(cvar.sv_skyname:get_string())
end
else
SkyboxColor()
UpdateSkybox()
end
end
local function Remove3DSky()
client.set_cvar("r_3dsky", ui.get(remove_3d_sky) and 0 or 1)
end
local function Unload()
if not entity.get_local_player() then
return
end
if default_skyname ~= nil then
load_name_sky(default_skyname)
end
local materials = materialsystem.find_materials("skybox/")
for i=1, #materials do
materials[i]:color_modulate(255, 255, 255)
materials[i]:alpha_modulate(255)
end
client.set_cvar("r_3dsky", 1)
end
ui.set_callback(skybox_names_listbox, UpdateSkybox)
ui.set_callback(remove_3d_sky, Remove3DSky)
ui.set_callback(skybox, Skybox)
client.set_event_callback("player_connect_full", PlayerConnectFull)
client.set_event_callback("pre_render_3d", SkyboxColor)
client.set_event_callback("shutdown", Unload)