forked from master12941/gamesense_case_opener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaseOpener.lua
1699 lines (1471 loc) · 80.1 KB
/
CaseOpener.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Made by coder man Bassn / hitome56
Main Credits ::
Sapphyrus - Big help for indexing paint kits as well as their images, big thanks :)
Yukine - Working file reading for images
zPrism - Main Test slave
Kay - Get Date Function
And also the gamesense lua discord, lots of help from there <3
]]
local ffi = require "ffi"
local localize = require "gamesense/localize" -- https://gamesense.pub/forums/viewtopic.php?id=30643
local images = require "gamesense/images" -- https://gamesense.pub/forums/viewtopic.php?id=22917
local csgo_weapons = require "gamesense/csgo_weapons" -- https://gamesense.pub/forums/viewtopic.php?id=18807
local InventoryAPI = panorama.open().InventoryAPI
local currency = "¤"
local table_remove, table_insert = table.remove, table.insert
local get_absoluteframetime, globals_curtime = globals.absoluteframetime, globals.curtime
local database_read, database_write = database.read, database.write
local math_sin, math_pi, math_floor, math_random, math_min, math_max, math_abs = math.sin, math.pi, math.floor, client.random_int, math.min, math.max, math.abs
local ui_get, ui_set, ui_new_checkbox, ui_new_slider, ui_new_combobox, ui_new_listbox, ui_new_label, ui_set_visible, ui_reference, ui_new_hotkey = ui.get, ui.set, ui.new_checkbox, ui.new_slider, ui.new_combobox, ui.new_listbox, ui.new_label, ui.set_visible, ui.reference, ui.new_hotkey
local ui_menu_position, ui_new_multiselect, ui_menu_size, ui_is_menu_open, ui_mouse_position, ui_set_callback, ui_new_button = ui.menu_position, ui.new_multiselect, ui.menu_size, ui.is_menu_open, ui.mouse_position, ui.set_callback, ui.new_button
local client_color_log, client_screen_size, client_key_state, client_set_event_callback, client_userid_to_entindex, client_exec, client_delay_call, client_reload_active_scripts = client.color_log, client.screen_size, client.key_state, client.set_event_callback, client.userid_to_entindex, client.exec, client.delay_call, client.reload_active_scripts
local renderer_line, renderer_rectangle, renderer_gradient, renderer_text = renderer.line, renderer.rectangle, renderer.gradient, renderer.text
local entity_get_prop, entity_get_local_player, entity_get_player_name = entity.get_prop, entity.get_local_player, entity.get_player_name
local case_location = "csgo_case_list_003"
local paint_kits_location = "cases_paint_kits_003"
local knife_location = "knife_list_003"
local glove_location = "glove_list_003"
local points_location = "case_pointsx"
local inventory_location = "case_inventoryX"
local case_menu_list = database_read(case_location) or nil
local case_do_update = false
local function update_cases(start, finish)
local found_something = false
for i = start, finish do -- all csgo cases are inside these indexs
local id = InventoryAPI.GetFauxItemIDFromDefAndPaintIndex(i, 0)
if InventoryAPI.GetLootListItemsCount(id) > 0 and InventoryAPI.GetAssociatedItemsCount(id) > 0 then
local first_item = InventoryAPI.GetLootListItemIdByIndex(id, 0)
local slot = InventoryAPI.GetSlot(first_item)
if slot ~= "" and slot ~= "musickit" and slot ~= "flair0" and slot ~= "customplayer" then --thx sapph
local case_name = InventoryAPI.GetItemName(id)
case_menu_list[#case_menu_list + 1] = tostring(case_name)
database_write(case_name, i) -- key system
found_something = true
end
end
end
return found_something
end
local function index_all_cases() -- gotta do right here so the combobox has all items
if case_menu_list == nil then
case_menu_list = {}
local updated = update_cases(4000, 5000)
if updated then
database_write(case_location, case_menu_list)
end
else
local last_case = database_read(case_menu_list[#case_menu_list]) + 1
local updated = update_cases(last_case, 5000)
if updated then
print("UPDATING CASES")
case_do_update = true
database_write(case_location, case_menu_list)
end
end
end
index_all_cases()
local mp = {"LUA", "B"}
local manual_sort = false
local menu = {
cases_enable = ui_new_checkbox(mp[1], mp[2], "⟡ Bassn's Case Opener ⟡"),
cases_hotkey = ui_new_hotkey (mp[1], mp[2], " Open Case Hotkey"),
cases_locked = ui_new_checkbox(mp[1], mp[2], " Lock Window Position"),
cases_pos = ui_new_combobox(mp[1], mp[2], "\n", {"Top", "Bottom"}, 1),
cases_i_pos = ui_new_combobox(mp[1], mp[2], " Inventory Side", {"Right", "Left"}, 1),
cases_audio = ui_new_checkbox(mp[1], mp[2], " Audio"),
cases_volume = ui_new_slider (mp[1], mp[2], "\nVolume", 1, 100, 50, true, "%"),
cases_speed = ui_new_checkbox(mp[1], mp[2], " Speed"),
cases_speed_v = ui_new_slider (mp[1], mp[2], "\nSpeed", 1, 5, 1, true, "x"),
cases_stats = ui_new_checkbox(mp[1], mp[2], " Show Statistics"),
cases_sell = ui_new_checkbox(mp[1], mp[2], " Auto Sell"),
cases_sell_v = ui_new_multiselect(mp[1], mp[2], "\nSell Type", {"Mil-spec grade", "Restricted", "Classified", "Covert", "Exceedingly Rare"}),
cases_show = ui_new_checkbox(mp[1], mp[2], " Always Show"),
cases_skin_c = ui_new_slider (mp[1], mp[2], " Inventory Rows", 0, 5, 2, true, nil, 1, {[0] = "Hidden"}),
cases_sort_t = ui_new_combobox(mp[1], mp[2], " Inventory Sort mode", {"Price", "Rarity", "Chance"}, 1),
cases_do_sort = ui_new_button (mp[1], mp[2], " Sort Inventory", function()
manual_sort = true
end),
cases_ascend = ui_new_checkbox(mp[1], mp[2], " Sort Ascendingly (Inverse Sort)"),
cases_auto = ui_new_checkbox(mp[1], mp[2], " Auto Sort Inventory"),
cases_chat = ui_new_checkbox(mp[1], mp[2], " Show Unbox in Chat"),
cases_chat_v = ui_new_combobox(mp[1], mp[2], "\nChat Type", {"All Chat", "Realistic Radio", "Fake Radio", "Team Chat"}, 1),
cases_chance = ui_new_checkbox(mp[1], mp[2], " - Include skin details"),
cases_indent = ui_new_checkbox(mp[1], mp[2], " - Indent Unbox Message"),
cases_rares = ui_new_checkbox(mp[1], mp[2], " - Only send message when skin is rare"),
--cases_luck = ui_new_slider (mp[1], mp[2], "Luck", 1, 1000, 1), -- sshhhhhhhhhhhhhhh, very secret ;)
cases_case = ui_new_listbox (mp[1], mp[2], " Select Case", case_menu_list, 1),
cases_update = ui_new_button (mp[1], mp[2], " Force Update Cases (Lag Spike)", function()
database_write(case_location, nil)
database_write(paint_kits_location, nil)
database_write(knife_location, nil)
database_write(glove_location, nil)
client_reload_active_scripts()
end),
cases_debug = ui_new_checkbox(mp[1], mp[2], " Debug"),
cases_spacer = ui_new_label (mp[1], mp[2], "\nCases Spacer")
}
local function setTableVisibility(table, state) -- thx to whoever made this
for i = 1, #table do
ui_set_visible(table[i], state)
end
end
client_set_event_callback("paint_ui", function() --menu item handler
setTableVisibility({menu.cases_sort_t, menu.cases_ascend, menu.cases_auto, menu.cases_show, menu.cases_locked, menu.cases_sell, menu.cases_audio, menu.cases_volume, menu.cases_spacer, menu.cases_case, menu.cases_hotkey, menu.cases_stats, menu.cases_speed, menu.cases_chat, menu.cases_skin_c, menu.cases_update, menu.cases_debug}, ui_get(menu.cases_enable))
setTableVisibility({menu.cases_pos, menu.cases_i_pos}, ui_get(menu.cases_locked) and ui_get(menu.cases_enable))
ui_set_visible(menu.cases_do_sort, not ui_get(menu.cases_auto) and ui_get(menu.cases_enable))
ui_set_visible(menu.cases_volume, ui_get(menu.cases_audio) and ui_get(menu.cases_enable))
ui_set_visible(menu.cases_speed_v, ui_get(menu.cases_speed) and ui_get(menu.cases_enable))
ui_set_visible(menu.cases_sell_v, ui_get(menu.cases_sell) and ui_get(menu.cases_enable))
setTableVisibility({menu.cases_chat_v, menu.cases_rares}, ui_get(menu.cases_chat) and ui_get(menu.cases_enable))
setTableVisibility({menu.cases_chance, menu.cases_indent}, (ui_get(menu.cases_chat_v) ~= "Realistic Radio") and ui_get(menu.cases_chat) and ui_get(menu.cases_enable))
end)
--main variables
local dpi_scale = ui_reference("MISC", "Settings", "DPI scale")
local s = tonumber(ui_get(dpi_scale):sub(1, -2))/100
local b_w = s * 7 -- border width
local x, y, w, h = database_read("cases_x") or 200, database_read("cases_y") or 200, database_read("cases_w") or 600 * s, database_read("cases_h") or 200
local screen_w, screen_h = client_screen_size()
local function clamp(num, min, max)
if num < min then
num = min
elseif num > max then
num = max
end
return num
end
ui_set_callback(menu.cases_locked, function()
if not ui_get(menu.cases_locked) then
x = x + (50 * s)
y = y + (50 * s)
x = clamp(x, 0, screen_w - 100)
y = clamp(y, 0, screen_h - 100)
end
end)
--hehe
local points = database_read(points_location) or 5000
local inventory = database_read(inventory_location) or {}
local hide_case_opener = database_read("cases_hide_menu") or false
local min_width, min_height = 200, 100
local got_offset, got_click, is_dragging, is_resizing, off_click, do_open_case, fill_case, is_in_animation, got_hide_button, added_item = false, false, false, false, false, false, true, false, false, false
local is_rsize_t, is_rsize_rb, is_rsize_l, offset_x, offset_y, offset_w, offset_h, click_x, click_y, scaled_w, scaled_h
local bttn_rest, case_item_num, case_cost, spin_speed, points_added_alpha, dpi_off_y, current_case_name, inv_page, max_pages = 0, nil, 250, 0, 0, 0, "", 0, 1
local this_case = {}
local skin_opened = {}
local skin_hover = {}
local prev_skin_hover = {}
local rarity_int = {
["Exceedingly Rare"] = 5,
["Covert"] = 4,
["Classified"] = 3,
["Restricted"] = 2,
["Mil-spec grade"] = 1,
}
local spin_x_offset, holder_h, scaled_w_ref = 0, 0, 0
--main funcs
local function valid_instance()
return (ui_is_menu_open() or ui_get(menu.cases_show))
end
local function log(text, int)
if int == 1 then
client_color_log(255, 69, 0, "[Bass's Cases] " .. text)
elseif int == 2 then
client_color_log(0, 255, 69, "[Bass's Cases] " .. text)
elseif int == 3 then
client_color_log(0, 100, 255, "[Bass's Cases] " .. text)
elseif int == 4 then
client_color_log(255, 255, 255, "[Bass's Cases] " .. text)
end
end
local function contains(item, val)
table = ui.get(item)
for i=1,#table do
if table[i] == val then
return true
end
end
return false
end
local function sort(in_table, ascend, method) -- super fucking scuffed, i just want to get this over with
local out_table = in_table
local n = #out_table
for i = 2, n do
local key = out_table[i]
local j = i - 1
if method == "rarity" then
if ascend then
while (j > 0) and rarity_int[out_table[j][method]] > rarity_int[key[method]] do
out_table[j + 1] = out_table[j]
j = j - 1
end
else
while (j > 0) and rarity_int[out_table[j][method]] < rarity_int[key[method]] do
out_table[j + 1] = out_table[j]
j = j - 1
end
end
else
-- not proud of it, but it works
if ascend then
while (j > 0) and (method == "percentage" and 100 - tonumber(string.sub(out_table[j][method], 1, #out_table[j][method] - 1)) or out_table[j][method]) > (method == "percentage" and 100 - tonumber(string.sub(key[method], 1, #key[method] - 1)) or key[method]) do
out_table[j + 1] = out_table[j]
j = j - 1
end
else
while (j > 0) and (method == "percentage" and 100 - tonumber(string.sub(out_table[j][method], 1, #out_table[j][method] - 1)) or out_table[j][method]) < (method == "percentage" and 100 - tonumber(string.sub(key[method], 1, #key[method] - 1)) or key[method]) do
out_table[j + 1] = out_table[j]
j = j - 1
end
end
end
out_table[j + 1] = key
end
return out_table
end
local function date_sort(in_table, ascend)
local out_table = in_table
local n = #out_table
for i = 2, n do
local key = out_table[i]
local j = i - 1
if ascend then
while (j > 0) and out_table[j]["date"] > key["date"] do
out_table[j + 1] = out_table[j]
j = j - 1
end
else
while (j > 0) and out_table[j]["date"] < key["date"] do
out_table[j + 1] = out_table[j]
j = j - 1
end
end
out_table[j + 1] = key
end
return out_table
end
local function pulsate(time, range, speed)
return range * (math_sin(2 * math_pi * ((speed / 10) / (range / 10) ) * time)) / 10
end
-- randomly get numbers like 69.00000000001, this fixes | also for ez 2 decimal numbers
local function fix_float(num)
return math_floor(num * 100) / 100
end
-- colors :)
function fromhex(str)
return (str:gsub('..', function (cc)
return string.char(tonumber(cc, 16))
end))
end
local function tabIndexOverflow(seed, table)
for i = 1, #table do
if seed - table[i] <= 0 then
return i, seed
end
seed = seed - table[i]
end
end
-- Credits: Kay
local function get_date()
local unix = client.unix_time()
assert(unix == nil or type(unix) == "number" or unix:find("/Date%((%d+)"), "Please input a valid number to \"getDate\"")
local unix = (type(unix) == "string" and unix:match("/Date%((%d+)") / 1000 or unix) -- This is for a certain JSON compatability. It works the same even if you don't need it
local dayCount, year, days, month = function(yr) return (yr % 4 == 0 and (yr % 100 ~= 0 or yr % 400 == 0)) and 366 or 365 end, 1970, math.ceil(unix/86400)
while days >= dayCount(year) do
days = days - dayCount(year) year = year + 1
end
month, days = tabIndexOverflow(days, {31,(dayCount(year) == 366 and 29 or 28),31,30,31,30,31,31,30,31,30,31})
return string.format("%02d/%02d/%04d", month, days, year)
end
-- Credit: Yukine / dev
local readFile_native = vtable_bind("filesystem_stdio.dll", "VBaseFileSystem011", 0, "int(__thiscall*)(void* _this, void* buf, int size, void* hFile)")
local openFile_native = vtable_bind("filesystem_stdio.dll", "VBaseFileSystem011", 2, "void*(__thiscall*)(void* _this, const char* path, const char* mode, const char* base)")
local closeFile_native = vtable_bind("filesystem_stdio.dll", "VBaseFileSystem011", 3, "void(__thiscall*)(void* _this, void* hFile)")
local getFileSize_native = vtable_bind("filesystem_stdio.dll", "VBaseFileSystem011", 7, "unsigned int(__thiscall*)(void* _this, void* hFile)")
local function validFile(path) -- kinda scuffed, works tho
local hFile = openFile_native(path, "r", "GAME")
local to_return = false
if hFile then
local fileSize = getFileSize_native(hFile)
if fileSize > 0 then
to_return = true
end
end
return to_return
end
local function readFile(path)
local hFile = openFile_native(path, "r", "GAME")
if hFile then
local fileSize = getFileSize_native(hFile)
local buffer = ffi.new("char[?]", fileSize + 1)
return {
get = function ()
return readFile_native(buffer, fileSize, hFile) and ffi.string(buffer, fileSize) or nil
end,
free = function ()
closeFile_native(hFile)
end
}
end
end
-- Credit: Sapphyrus
local function get_call_target(ptr)
local insn = ffi.cast("uint8_t*", ptr)
if insn[0] == 0xE8 then
-- relative, displacement relative to next instruction
local offset = ffi.cast("uint32_t*", insn+1)[0]
return insn + offset + 5
elseif insn[0] == 0xFF and insn[1] == 0x15 then
-- absolute
local call_addr = ffi.cast("uint32_t**", ffi.cast("const char*", ptr)+2)
return call_addr[0][0]
else
error("unknown instruction!")
end
end
-- Credit: Sapphyrus
local native_GetItemSchemaPointer = ffi.cast("intptr_t(__stdcall*)()", client.find_signature("client.dll", "\xA1\xCC\xCC\xCC\xCC\x85\xC0\x75\x53"))
local native_GetPaintKitDefinitionPointer = ffi.cast("void*(__thiscall*)(void*, int)", get_call_target(client.find_signature("client.dll", "\xE8\xCC\xCC\xCC\xCC\x8B\xF0\x8B\x4E\x7C")))
local CPaintKit_t = ffi.typeof([[
struct {
int nID;
struct {
char* buffer;
int capacity;
int grow_size;
int length;
} name;
int pad[4];
struct {
char* buffer;
int capacity;
int grow_size;
int length;
} tag;
} *
]])
-- Credit: Sapphyrus
local function get_paint_kit(index)
local item_schema = native_GetItemSchemaPointer()
if item_schema == nil then
return
end
local paint_kit_addr = native_GetPaintKitDefinitionPointer(ffi.cast("void*", item_schema + 4), index)
if paint_kit_addr == nil then
return
end
return ffi.cast(CPaintKit_t, paint_kit_addr)
end
local debug_list = {}
--stattrak item, for csgo the image for stattrack is acutally stattrack_advert.vtf so...
local queued_case, current_case, queued_case_data = {}, {}, {}
local paint_kits = database_read(paint_kits_location)
local total_kits, last_kit = 1, 0
if paint_kits == nil or case_do_update then
paint_kits = {}
for i = 1, 11000 do -- index 9001 == workshop_default
if i == 3000 then
i = 10000
end
local paint_kit = get_paint_kit(i)
if paint_kit ~= nil then
local name = ffi.string(paint_kit.name.buffer, paint_kit.name.length-1)
local tag = ffi.string(paint_kit.tag.buffer, paint_kit.tag.length-1)
local temp = paint_kits[localize(tag)]
if name == "sp_nightstripe" then
table_insert(debug_list, {name, i})
end
if temp == nil then
paint_kits[localize(tag)] = {{name, i}}
else
table_insert(paint_kits[localize(tag)], #temp + 1, {name, i})
end
end
end
database_write(paint_kits_location, paint_kits)
end
local knives = {
{"weapon_knife_css", "Classic Knife", "Classic knife", 503},
{"weapon_bayonet", "Bayonet", "Bayonet", 500},
{"weapon_knife_butterfly","Butterfly Knife", "Butterfly", 515},
{"weapon_knife_canis", "Survival Knife", "Survival", 518},
{"weapon_knife_cord", "Paracord Knife", "Paracord", 517},
{"weapon_knife_falchion", "Falchion Knife", "Falchion", 512},
{"weapon_knife_flip", "Flip Knife", "Flip", 505},
{"weapon_knife_gut", "Gut Knife", "Gut", 506},
{"weapon_knife_gypsy_jackknife", "Navaja Knife", "Navaja", 520},
{"weapon_knife_karambit", "Karambit", "Karambit", 507},
{"weapon_knife_m9_bayonet", "M9 Bayonet", "M9 Bayonet", 508},
{"weapon_knife_outdoor", "Nomad Knife", "Nomad", 521},
{"weapon_knife_push", "Shadow Daggers", "Shadow dagger", 516},
{"weapon_knife_skeleton", "Skeleton Knife", "Skeleton", 525},
{"weapon_knife_stiletto", "Stiletto Knife", "Stiletto", 522},
{"weapon_knife_survival_bowie", "Bowie Knife", "Survival bowie", 514},
{"weapon_knife_tactical", "Huntsman Knife", "Tactical", 509},
{"weapon_knife_ursus", "Ursus Knife", "Ursus", 519},
{"weapon_knife_widowmaker", "Talon Knife", "Talon", 523}
}
local valid_knife_skins = database_read(knife_location) or {} -- mega lag on first load, have detect method for new skins / cases ... etc
if valid_knife_skins[knives[1][1]] == nil or case_do_update then
for i = 1, #knives do
for j, v in pairs(paint_kits) do
for k, n in ipairs(v) do
local skin_name = n[1]
local item_image = string.format("resource/flash/econ/default_generated/%s_%s_light_large.png", knives[i][1], skin_name)
local valid_file = validFile(item_image)
if valid_file then
local data = {
name = knives[i][2] .. " | " .. j, skin = j, image = item_image , index = n[2]
}
if j == "sp_mesh_tan" then
table_insert(debug_list, {knives[i][1], data.index})
end
local temp = valid_knife_skins[knives[i][1]]
if temp == nil then
valid_knife_skins[knives[i][1]] = {data}
else
table.insert(valid_knife_skins[knives[i][1]], data )
end
end
end
end
end
database_write(knife_location, valid_knife_skins)
end
--decalre glove tags
local gloves = {
{"leather_handwraps", "Hand Wraps", "Wraps"},
{"motorcycle_gloves", "Moto Gloves", "Motorcycle"},
{"slick_gloves", "Driver Gloves", "Driver"},
{"specialist_gloves", "Specialist Gloves", "Specialist"},
{"sporty_gloves", "Sport Gloves", "Sport"},
{"studded_bloodhound_gloves", "Bloodhound Gloves", "Bloodhound"},
{"studded_brokenfang_gloves", "Broken Fang Gloves", "Broken Fang"},
{"studded_hydra_gloves", "Hydra Gloves", "Hydra"}
}
local valid_glove_skins = database_read(glove_location) or {} -- mega lag on first load, have detect method for new skins / cases ... etc
if valid_glove_skins[gloves[1][1]] == nil then
for i = 1, #gloves do
for j, v in pairs(paint_kits) do
local skin_name = v[1][1]
local item_image = string.format("resource/flash/econ/default_generated/%s_%s_light_large.png", gloves[i][1], skin_name)
local valid_file = validFile(item_image)
if valid_file then
local data = {
name = gloves[i][2] .. " | " .. j, skin = j, image = item_image, index = v[1][2]
}
local temp = valid_glove_skins[gloves[i][1]]
if temp == nil then
valid_glove_skins[gloves[i][1]] = {data}
else
table.insert(valid_glove_skins[gloves[i][1]], data )
end
end
end
end
database_write(glove_location, valid_glove_skins)
end
-- Partial Credit: Sapphyrus (Built off his foundation)
local function load_queued_case()
queued_case = {}
queued_case_data = {}
local case_selected = case_menu_list[(ui_get(menu.cases_case) or 0) + 1]
local case_index = database_read(case_selected)
local case_itemid = InventoryAPI.GetFauxItemIDFromDefAndPaintIndex(case_index, 0)
local case_skin_count = InventoryAPI.GetLootListItemsCount(case_itemid)
if ui_get(menu.cases_debug) then
client_color_log(0, 155, 255, "\nItems in " .. case_selected .. " (" .. case_index .. ") | " .. case_skin_count .. " skins")
end
queued_case_data[6] = case_skin_count
for i = 1, case_skin_count do
local itemid = InventoryAPI.GetLootListItemIdByIndex(case_itemid, i-1)
local item_image, item_name, item_rarity
local skin_index, weapon_idx = -1, -1
local fixed_index = case_skin_count - (i - 1)
local skin_image_file, valid_file = nil, false
local while_loop_is_scary = 1
while not valid_file and while_loop_is_scary <= 15 do -- very scary while loop, needed a safety net
if itemid == "0" then
item_name = localize(InventoryAPI.GetLootListUnusualItemName(case_itemid))
item_rarity = 1
item_image = string.format("resource/flash/%s.png", InventoryAPI.GetLootListUnusualItemImage(case_itemid))
else
item_name = InventoryAPI.GetItemName(itemid)
item_rarity = 8 - InventoryAPI.GetItemRarity(itemid)
local tag_name = InventoryAPI.GetItemName(itemid):match(" | (.*)") -- game skin name
--client_color_log(255, 255, 255, "\nIID : " .. tostring(itemid) .. "\nSTACK : " .. tostring(while_loop_is_scary) .. "\nIndex : " .. i .. " of " .. case_skin_count .. "\nCase : " .. tostring(case_selected) .. " - ".. tostring(case_itemid) .. "\nTag : " .. InventoryAPI.GetItemName(itemid) .. " - ".. tostring(tag_name))
local skin_name = paint_kits[tag_name][while_loop_is_scary][1] -- getting skin file name using the game skin name as a key
skin_index = paint_kits[tag_name][while_loop_is_scary][2] -- skin indexed
item_image = string.format("resource/flash/econ/default_generated/%s_%s_light_large.png", InventoryAPI.GetItemDefinitionName(itemid), skin_name)
weapon_idx = InventoryAPI.GetItemDefinitionIndex(itemid)
end
valid_file = validFile(item_image)
if ui_get(menu.cases_debug) then
if valid_file then
client_color_log(33, 255, 33, "Valid " .. while_loop_is_scary .. " : " .. item_image)
else
client_color_log(255, 33, 33, "Invalid " .. while_loop_is_scary .. ": " .. item_image)
client_color_log(255, 33, 33, "Trying next instance - " .. while_loop_is_scary + 1)
end
end
while_loop_is_scary = while_loop_is_scary + 1
end
skin_image_file = readFile(item_image)
local final_image = images.load(skin_image_file.get())
local _weapon = string.find(item_name, "|") or 2
local _skin_name = string.find(item_name, "|") or #item_name
queued_case[fixed_index] = {
image = final_image,
full_name = item_name,
skin_name = string.sub(item_name, _skin_name + 2, #item_name),
weapon = string.sub(item_name, 1, _weapon - 2) or "Knife",
weapon_idx = weapon_idx,
image_dir = item_image,
index = skin_index
}
queued_case_data[item_rarity] = (queued_case_data[item_rarity] or 0) + 1
if ui_get(menu.cases_debug) then
client_color_log(255, 255, 255, fixed_index .. " - {Image= " .. item_image .. " | Name= " .. queued_case[fixed_index].full_name .. "}")
end
end
end
load_queued_case()
ui_set_callback(menu.cases_case, load_queued_case)
local function get_start_finish(cfg, rarity)
local strt, fnsh, counter = 0, 0, 0
if rarity ~= 6 then -- errpr
rarity = rarity + 1
for i = rarity - 1, 6 do -- start array pos
strt = math_abs(strt - cfg[6 - counter])
counter = counter + 1
end
strt, counter = strt + 1, 0
for i = rarity, 6 do -- finsih array pos
fnsh = math_abs(fnsh - cfg[6 - counter])
counter = counter + 1
end
else
strt, fnsh = 1, 1
end
return {start = strt, finish = fnsh}
end
local rarity_colors = {
{r = 202, g = 171, b = 005, rarity = "Exceedingly Rare"},
{r = 235, g = 075, b = 075, rarity = "Covert"},
{r = 211, g = 044, b = 230, rarity = "Classified"},
{r = 136, g = 071, b = 255, rarity = "Restricted"},
{r = 017, g = 085, b = 221, rarity = "Mil-spec grade"},
{r = 255, g = 255, b = 255, rarity = "Error"},
}
local function get_skin_details(cfg, rarity)
local r_info = rarity_colors[rarity]
local num_pos = get_start_finish(cfg, rarity)
r_info.num = math_random(num_pos.start, num_pos.finish)
return r_info.r, r_info.g, r_info.b, r_info.rarity, r_info.num
end
local function get_r_skin(luck, item_num, cfg)
local total_points = 0
local return_skin = {}
local f_roll = fix_float(100 - (math_random(1, 10000) / 100)) -- case filler items roll
local r_roll = fix_float(100 - (math_random(1, 10000 / luck) / 100)) -- case main item roll
local skin_rarity = 0
if item_num ~= 35 then
if f_roll <= 89.10 then -- blue
skin_rarity = 5
total_points = total_points + math_random(10, 60)
elseif f_roll > 89.10 and f_roll <= 97.1 then -- pruple
skin_rarity = 4
total_points = total_points + math_random(40, 310)
elseif f_roll > 97.10 and f_roll <= 99.74 then -- pink
skin_rarity = 3
total_points = total_points + math_random(550, 2900)
elseif f_roll > 99.74 and f_roll <= 100 then -- red
skin_rarity = 2
total_points = total_points + math_random(2500, 10500)
end
else
if r_roll <= 75.96 then -- blue
skin_rarity = 5
total_points = total_points + math_random(10, 60)
elseif r_roll > 75.96 and r_roll <= 94.90 then -- pruple
skin_rarity = 4
total_points = total_points + math_random(40, 310)
elseif r_roll > 94.90 and r_roll <= 98.90 then -- pink
skin_rarity = 3
total_points = total_points + math_random(550, 2900)
elseif r_roll > 98.90 and r_roll <= 99.55 then -- red
skin_rarity = 2
total_points = total_points + math_random(2500, 10500)
elseif r_roll > 99.55 and r_roll <= 100 then -- gold
skin_rarity = 1
total_points = total_points + math_random(8000, 85000)
end
end
return_skin.r, return_skin.g, return_skin.b, return_skin.rarity, return_skin.num = get_skin_details(cfg, skin_rarity)
return_skin.rarity_int = 6 - skin_rarity
local w_roll = fix_float(100 - (math_random(0, 10000) / 100))
if w_roll >= 0 and w_roll <= 9.93 then
return_skin.wear = "Battle-Scarred"
return_skin.wear_int = math_random(44, 100)
total_points = total_points * 0.65
elseif w_roll > 9.93 and w_roll <= 17.85 then
return_skin.wear = "Well-Worn"
return_skin.wear_int = math_random(38, 45)
total_points = total_points * 0.8
elseif w_roll > 17.85 and w_roll <= 61.03 then
return_skin.wear = "Field Tested"
return_skin.wear_int = math_random(15, 39)
total_points = total_points * 1
elseif w_roll > 61.03 and w_roll <= 85.71 then
return_skin.wear = "Minimal Wear"
return_skin.wear_int = math_random(7, 16)
total_points = total_points * 1.4
elseif w_roll > 85.71 and w_roll <= 100 then
return_skin.wear_int = math_random(0, 8)
return_skin.wear = "Factory New"
total_points = total_points * 2
end
return_skin.stattrack = math_random(1, 10) == 1 and current_case[1].full_name ~= "★ Gloves ★"
if return_skin.stattrack then
total_points = total_points * 2.3
end
return_skin.percentage = tostring(fix_float((100 - r_roll) / (return_skin.stattrack and 10 or 1))) .. "%"
return_skin.points = math_floor(total_points)
local s_roll = math_random(0, 1000) -- case filler items roll
return_skin.seed = s_roll
return return_skin
end
local knife_enable, knife_combo = ui_reference("SKINS", "Model options", "Knife changer")
local glove_enable, glove_combo, glove_combo2 = ui_reference("SKINS", "Model options", "Glove changer")
local skins_listbox = ui_reference("SKINS", "Weapon Skin", "Skin")
local idx_reference = ui_reference("SKINS", "Weapon skin", "Weapon")
ui_set_visible(idx_reference, false)
local knife_apply = nil
local function idx_apply(skin)
local c_idx = ui_get(idx_reference)
if skin.type == "knife" then
ui_set(knife_enable, true)
ui_set(knife_combo, skin.eso_name)
knife_apply = skin
elseif skin.type == "glove" then
ui_set(glove_enable, true)
ui_set(glove_combo, skin.eso_name)
ui_set(glove_combo2, skin.skin_name)
else
ui_set(idx_reference, skin.weapon_idx)
local skins_enable = ui_reference("SKINS", "Weapon Skin", "Enabled")
local skins_stattrak = ui_reference("SKINS", "Weapon Skin", "StatTrak")
local skins_quality = ui_reference("SKINS", "Weapon Skin", "Quality")
local skins_seed = ui_reference("SKINS", "Weapon Skin", "Seed")
ui_set(skins_enable, true)
ui_set(skins_listbox, skin.index)
ui_set(skins_stattrak, skin.stattrack)
ui_set(skins_quality, 100 - skin.wear_int)
ui_set(skins_seed, skin.seed)
ui_set(idx_reference, c_idx)
end
end
local t_knife = {}
client_set_event_callback("net_update_start", function() -- skin applying handling
local local_player = entity.get_local_player()
if not entity.is_alive(local_player) or knife_apply == nil then return end
local weapon_ent = entity.get_player_weapon(local_player)
local current_weapon = csgo_weapons(weapon_ent) -- current_weapon.name
if current_weapon.type == "knife" then
local skins_enable = ui_reference("SKINS", "Weapon Skin", "Enabled")
local skins_stattrak = ui_reference("SKINS", "Weapon Skin", "StatTrak")
local skins_quality = ui_reference("SKINS", "Weapon Skin", "Quality")
local skins_seed = ui_reference("SKINS", "Weapon Skin", "Seed")
t_knife = knife_apply
client.delay_call(0.15, function()
ui_set(skins_enable, true)
ui_set(skins_listbox, t_knife.index)
ui_set(skins_stattrak, t_knife.stattrack)
ui_set(skins_quality, 100 - t_knife.wear_int)
ui_set(skins_seed, t_knife.seed)
end)
knife_apply = nil
end
end)
local function add_item_to_inventory(case, skin)
if skin.rarity ~= "Exceedingly Rare" then
inventory[#inventory + 1] = {
num = skin.num,
name = case[skin.num].full_name,
weapon = case[skin.num].weapon,
weapon_idx = case[skin.num].weapon_idx,
skin_name = case[skin.num].skin_name,
wear = skin.wear,
wear_int = skin.wear_int,
rarity = skin.rarity,
points = skin.points,
seed = skin.seed,
percentage = skin.percentage,
stattrack = skin.stattrack,
image_dir = case[skin.num].image_dir,
index = case[skin.num].index,
r = skin.r, g = skin.g, b = skin.b,
date = get_date(),
type = "gun",
}
else
if case[1].full_name == "★ Gloves ★" then
local rolled_int = math_random(1, 8)
local rolled_glove = valid_glove_skins[gloves[rolled_int][1]]
local glove_skin = rolled_glove[math_random(1, #rolled_glove)]
local new_skin = {
num = skin.num,
name = glove_skin.name,
weapon = gloves[rolled_int][2],
eso_name = gloves[rolled_int][2],
skin_name = glove_skin.skin,
wear = skin.wear,
rarity = skin.rarity,
points = skin.points,
percentage = skin.percentage,
stattrack = skin.stattrack,
image_dir = glove_skin.image,
index = glove_skin.index,
r = skin.r, g = skin.g, b = skin.b,
date = get_date(),
type = "glove",
}
inventory[#inventory + 1] = new_skin
else
local rolled_int = math_random(2, 19)
--lol
if current_case_name == "Operation Breakout Weapon Case" then
rolled_int = 3
elseif current_case_name == "CS20 Case" then
rolled_int = 1
elseif current_case_name == "Huntsman Weapon Case" then
rolled_int = 17
elseif current_case_name == "Falchion Case" then
rolled_int = 6
elseif current_case_name == "Shadow Case" then
rolled_int = 13
elseif current_case_name == "Operation Wildfire Case" then
rolled_int = 16
end
local rolled_knife = valid_knife_skins[knives[rolled_int][1]]
local knife_skin = rolled_knife[math_random(1, #rolled_knife)]
local new_skin = {
num = skin.num,
name = knife_skin.name,
weapon = knives[rolled_int][2],
weapon_idx = knives[rolled_int][4],
eso_name = knives[rolled_int][3],
skin_name = knife_skin.skin,
wear = skin.wear,
wear_int = skin.wear_int,
rarity = skin.rarity,
points = skin.points,
seed = skin.seed,
percentage = skin.percentage,
stattrack = skin.stattrack,
image_dir = knife_skin.image,
index = knife_skin.index,
r = skin.r, g = skin.g, b = skin.b,
date = get_date(),
type = "knife",
}
inventory[#inventory + 1] = new_skin
end
end
database_write(inventory_location, inventory)
end
local function load_inventory()
local mod_inventory = inventory -- temp copy
for i = 1, #mod_inventory do
local i_skin = mod_inventory[i]
local skin_dir = i_skin.image_dir
if validFile(skin_dir) then
local skin_image_file = readFile(skin_dir)
mod_inventory[i].image = images.load(skin_image_file.get())
end
end
inventory = mod_inventory
end
load_inventory()
-- sort
local function sort_inventory()
local type, method = ui_get(menu.cases_sort_t), "rarity_int"
if type == "Price" then
method = "points"
elseif type == "Rarity" then
method = "rarity"
elseif type == "Chance" then
method = "percentage"
end
local mod_inventory = sort(inventory, not ui_get(menu.cases_ascend), method)
inventory = mod_inventory
end
local function calc_points(difference)
points = points + difference
database_write(points_location, points)
end
local function do_stats(skin_rarity)
if skin_rarity == "Mil-spec grade" then
local old_total = database_read("cases_blues") or 0
database_write("cases_blues", old_total + 1)
elseif skin_rarity == "Restricted" then
local old_total = database_read("cases_purps") or 0
database_write("cases_purps", old_total + 1)
elseif skin_rarity == "Classified" then
local old_total = database_read("cases_pinks") or 0
database_write("cases_pinks", old_total + 1)
elseif skin_rarity == "Covert" then
local old_total = database_read("cases_reds") or 0
database_write("cases_reds", old_total + 1)
elseif skin_rarity == "Exceedingly Rare" then
local old_total = database_read("cases_golds") or 0
database_write("cases_golds", old_total + 1)
end
local old_total = database_read("cases_opened") or 0
database_write("cases_opened", old_total + 1)
end
local function reset_all() -- for whenever neccesary
database_write("cases_opened", nil)
database_write("cases_blues", nil)
database_write("cases_purps", nil)
database_write("cases_pinks", nil)
database_write("cases_reds", nil)
database_write("cases_golds", nil)
database_write(points_location, 250000)
database_write(inventory_location, nil)
database_write(case_location, nil)
points = database_read(points_location)--need to update
end
-- reset_all()
client_set_event_callback('setup_command', function (cmd)
-- when menu is open dont have the mouse doin shit behind it
-- sadly doesnt work in csgo's main menu
if not ui_is_menu_open() or not ui_get(menu.cases_enable) then
return
end
cmd.in_attack = false
cmd.in_attack2 = false
end)
local spin_lock = false
local function activate_spin()
if not spin_lock then
calc_points(-case_cost)
current_case = queued_case
current_case_name = case_menu_list[(ui_get(menu.cases_case) or 0) + 1]
bttn_rest = true
fill_case = true
do_open_case = true
fill_case = true
is_in_animation = false
spin_speed = 1
spin_x_offset = 0
added_item = false
end
end
local function skeet_box(s_x, s_y, s_w, s_h, s_alpha, do_gradient)
renderer_rectangle(s_x - 6, s_y - 6, s_w + 12, s_h + 12, 12, 12, 12, s_alpha)
renderer_rectangle(s_x - 5, s_y - 5, s_w + 10, s_h + 10, 60, 60, 60, s_alpha)
renderer_rectangle(s_x - 4, s_y - 4, s_w + 8, s_h + 8, 40, 40, 40, s_alpha)
renderer_rectangle(s_x - 1, s_y - 1, s_w + 2, s_h + 2, 60, 60, 60, s_alpha)
renderer_rectangle(s_x, s_y, s_w, s_h, 23, 23, 23, s_alpha)
if do_gradient then
renderer_gradient(s_x + 1, s_y + 1, s_w / 2 - 1, s, 55, 177, 218, s_alpha, 201, 84, 205, s_alpha, true)
renderer_gradient(s_x + s_w / 2 - 1, s_y + 1, s_w / 2, s, 201, 84, 205, s_alpha, 204, 207, 53, s_alpha, true)
end
end
local function rectangle_outline(x, y, w, h, r, g, b, a)
renderer_line(x, y, x + w, y, r, g, b, a) -- top
renderer_line(x, y + h + 1, x + w, y + h + 1, r, g, b, a) -- bottom
renderer_line(x, y, x, y + h, r, g, b, a) -- left
renderer_line(x + w, y, x + w, y + h, r, g, b, a) -- right
end