forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeemoApp.zip
More file actions
2127 lines (1952 loc) · 81.2 KB
/
Copy pathMeemoApp.zip
File metadata and controls
2127 lines (1952 loc) · 81.2 KB
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
local DEBUG = true
local function log(...)
if DEBUG then print("[AddOutfit]", ...) end
end
local MATCH_CONFIG = {
outfitRes = 0, -- مثال: 1405497 (0 = من الذاكرة)
weaponSkins = { -- weaponID → skinResID (0 أو بدون = من الذاكرة/الشنطة)
},
}
-- ========== قائمة العناصر ==========
local ITEMS = {
-- بدلات
1405485, 1405486, 1405481, 1405482, 1405488, 1405489, 1405490, 1405491,
1405492, 1405493, 1405494, 1405495, 1405496, 1405497, 1405498, 1405499,
1405629, 1405630, 1405631, 1405632, 1405633, 1405634,
-- M416 Lv.8
1101004246,
1101004236,
}
local INS_BASE = 2000000000
local PKG_SLOT = 3
local MELEE_ID = 108
local GUN_SUB = { [101]=true, [102]=true, [103]=true, [104]=true, [105]=true, [106]=true, [107]=true }
local NET_OK = NetErrorCode_NONE or "ok"
local R = { insToRes = {}, resToIns = {} }
local _matchApplied = false
-- ========== ذاكرة اللبس ==========
local function cache()
_G.AddOutfitEquippedCache = _G.AddOutfitEquippedCache or {
outfitRes = nil, outfitIns = nil,
weapons = {},
}
return _G.AddOutfitEquippedCache
end
local function cfg(resID)
if not resID or not CDataTable or not CDataTable.GetTableData then return nil end
return CDataTable.GetTableData("Item", resID)
end
local function subType(c)
return c and (c.ItemSubType or c.itemSubType) or nil
end
-- 403 = Package_Slot: تبويب البدلة (10) وتبويب التيشيرت (3) — نفس النوع، مختلف التبويب
local ST_TOP = (ENUM_ITEM_SUBTYPE and ENUM_ITEM_SUBTYPE.Package_Slot) or 403
local ST_PANTS = (ENUM_ITEM_SUBTYPE and ENUM_ITEM_SUBTYPE.Pants_Slot) or 404
local ST_SHOES = (ENUM_ITEM_SUBTYPE and ENUM_ITEM_SUBTYPE.Shoes_Slot) or 405
local ST_UNDER_T = (ENUM_ITEM_SUBTYPE and ENUM_ITEM_SUBTYPE.UnderCloth) or 450
local ST_UNDER_P = (ENUM_ITEM_SUBTYPE and ENUM_ITEM_SUBTYPE.UnderPants) or 451
local WARDROBE_TAB_SUIT, WARDROBE_TAB_CLOTHES = 10, 3
pcall(function()
local wm = require("client.slua.umg.Wardrobe.wardrobe_macro")
WARDROBE_TAB_SUIT = wm.ENUM_WardrobeSubTabString.ENUM_WardrobeSubTabString_suit
WARDROBE_TAB_CLOTHES = wm.ENUM_WardrobeSubTabString.ENUM_WardrobeSubTabString_clothes
end)
local FULL_SUIT_CLEAR_ST = {
[ST_TOP] = true, [ST_PANTS] = true, [ST_SHOES] = true,
[ST_UNDER_T] = true, [ST_UNDER_P] = true,
}
local function wardrobeTab(resID, depotData)
if depotData and depotData.subTabType then return tonumber(depotData.subTabType) end
local c = cfg(resID)
return c and tonumber(c.WardrobeTab or c.wardrobeTab) or nil
end
local function isFullSuitRes(resID, depotData)
resID = tonumber(resID)
if not resID or resID <= 0 then return false end
local ok, xs = pcall(function()
local LogicXSuit = require("client.slua.logic.XSuit.logic_xsuit")
return LogicXSuit.IsXSuit(resID)
end)
if ok and xs then return true end
local tab = wardrobeTab(resID, depotData)
if tab == WARDROBE_TAB_SUIT then return true end
if tab == WARDROBE_TAB_CLOTHES then return false end
for _, id in ipairs(ITEMS) do
if tonumber(id) == resID and subType(cfg(resID)) == ST_TOP then
return true
end
end
return false
end
local function getClothKind(resID, depotData)
resID = tonumber(resID)
if not resID then return nil end
local st = subType(cfg(resID))
if st == ST_TOP then
return isFullSuitRes(resID, depotData) and "full_suit" or "top"
end
if st == ST_PANTS then return "pants" end
if st == ST_SHOES then return "shoes" end
if st == ST_UNDER_T then return "under_top" end
if st == ST_UNDER_P then return "under_pants" end
return nil
end
local function subTypesToClearForKind(kind)
if kind == "full_suit" then return FULL_SUIT_CLEAR_ST end
if kind == "top" then return { [ST_TOP] = true } end
if kind == "pants" then return { [ST_PANTS] = true } end
if kind == "shoes" then return { [ST_SHOES] = true } end
if kind == "under_top" then return { [ST_UNDER_T] = true } end
if kind == "under_pants" then return { [ST_UNDER_P] = true } end
return nil
end
local function isBodyClothSubType(st)
st = tonumber(st)
return st == ST_TOP or st == ST_PANTS or st == ST_SHOES or st == ST_UNDER_T or st == ST_UNDER_P
end
local function weaponIdFromSkin(resID)
local m = CDataTable and CDataTable.GetTableData and CDataTable.GetTableData("WeaponSkinMapping", resID)
if not m then return nil end
return m.WeaponID or m.WeaponId
end
local function isInjectedIns(ins)
return ins and R.insToRes[tonumber(ins)] ~= nil
end
local function isInjectedRes(res)
return res and R.resToIns[tonumber(res)] ~= nil
end
local function invalidateSocialWearCache()
local s = _G.AddOutfitSocialState
if s then
s.wearPatchKey, s.snapshotKey, s.fullSnapshot, s.lastHandSkin = nil, nil, nil, nil
end
end
local function saveWeaponToCache(weaponID, resID, insID)
weaponID, resID, insID = tonumber(weaponID), tonumber(resID), tonumber(insID)
if not weaponID or not resID or resID <= 0 then return end
local cch = cache()
cch.weapons[weaponID] = { resID = resID, insID = insID or 0 }
_G.AddOutfitLastAppliedSkin = {}
_matchApplied = false
invalidateSocialWearCache()
log("ذاكرة سكن", weaponID, "→", resID)
end
-- حفظ سكن من الشنطة (أصلي أو محقون) عبر insID
local function cacheWeaponSkinFromIns(weaponID, insID)
weaponID, insID = tonumber(weaponID), tonumber(insID)
if not weaponID or not insID or insID <= 0 then return end
if isInjectedIns(insID) then
saveWeaponToCache(weaponID, R.insToRes[insID], insID)
return
end
pcall(function()
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local d = wd:GetValidHallDepotItemDataByInsID(insID) or wd:GetHallDepotItemDataByInsID(insID)
if d and d.resID and tonumber(d.resID) > 0 then
saveWeaponToCache(weaponID, tonumber(d.resID), insID)
end
end)
end
local function saveEquip(resID, insID)
resID, insID = tonumber(resID), tonumber(insID)
if not resID or not insID then return end
local c = cfg(resID)
local st = subType(c)
local cch = cache()
if getClothKind(resID) == "full_suit" then
cch.outfitRes, cch.outfitIns = resID, insID
_G.AddOutfitLastLobbyOutfitRes = resID
invalidateSocialWearCache()
elseif getClothKind(resID) == "top" then
if cch.outfitRes and isFullSuitRes(cch.outfitRes) then
cch.outfitRes, cch.outfitIns = nil, nil
invalidateSocialWearCache()
end
elseif GUN_SUB[st] then
local wid = weaponIdFromSkin(resID)
if wid then saveWeaponToCache(wid, resID, insID) end
elseif st == MELEE_ID then
saveWeaponToCache(MELEE_ID, resID, insID)
end
_matchApplied = false
end
-- يقرأ السكنات الملبوسة من الشنطة / الأرموري → يحفظها في الذاكرة (مثل البدلة)
local function syncWeaponCacheFromLobby()
local cch = cache()
pcall(function()
local fbd = require("client.slua.logic.wardrobe.fashionbag.fashionbag_data")
local bag = fbd.GetCurrentFashionBag and fbd:GetCurrentFashionBag()
if bag and bag.weapon_skin_list then
for weaponID, entry in pairs(bag.weapon_skin_list) do
weaponID = tonumber(weaponID)
local insID = tonumber(entry and (entry.skin_id or entry.skinId)) or 0
if weaponID and weaponID > 0 and insID > 0 then
if isInjectedIns(insID) then
local res = tonumber(R.insToRes[insID])
if res and res > 0 then
cch.weapons[weaponID] = { resID = res, insID = insID }
end
else
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local d = wd:GetValidHallDepotItemDataByInsID(insID)
or wd:GetHallDepotItemDataByInsID(insID)
if d and d.resID and tonumber(d.resID) > 0 then
cch.weapons[weaponID] = { resID = tonumber(d.resID), insID = insID }
end
end
end
end
end
end)
pcall(function()
local Arm = require("client.logic.armory.logic_armory")
if Arm.rsp_list and Arm.rsp_list.install_list then
for weaponID, entry in pairs(Arm.rsp_list.install_list) do
weaponID = tonumber(weaponID)
local insID = tonumber(entry and entry.skin_id) or 0
if weaponID and weaponID > 0 and insID > 0 then
if isInjectedIns(insID) then
local res = tonumber(R.insToRes[insID])
if res and res > 0 then
cch.weapons[weaponID] = { resID = res, insID = insID }
end
else
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local d = wd:GetValidHallDepotItemDataByInsID(insID)
or wd:GetHallDepotItemDataByInsID(insID)
if d and d.resID and tonumber(d.resID) > 0 then
cch.weapons[weaponID] = { resID = tonumber(d.resID), insID = insID }
end
end
end
end
end
end)
pcall(function()
local wgl = require("client.slua.logic.wardrobe.logic_wardrobe_gun")
if wgl.GetSkinIdByWeaponID then
local guns = { 101001, 101002, 101003, 101004, 101005, 101006, 101007, 101008, 101009, 101010, 101012, 102001, 102002, 102003, 102004, 102005, 102007, 103001, 103002, 103003, 103004, 103005, 103006, 103007, 103008, 103009, 103010, 103011, 103012, 104001, 104002, 104003, 104004, 105001, 105002, 106001, 106002, 106003, 106004, 106005, 106006, 106007, 106008, 106010 }
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
for _, wid in ipairs(guns) do
local insID = tonumber(wgl:GetSkinIdByWeaponID(wid)) or 0
if insID > 0 then
local d = wd:GetValidHallDepotItemDataByInsID(insID) or wd:GetHallDepotItemDataByInsID(insID)
if d and d.resID and tonumber(d.resID) > 0 then
cch.weapons[wid] = { resID = tonumber(d.resID), insID = insID }
end
end
end
end
end)
end
-- سكن السلاح للماتش: الذاكرة أولاً، ثم MATCH_CONFIG إن وُجد رقم > 0
local function getCachedWeaponSkin(weaponID)
weaponID = tonumber(weaponID) or 0
if weaponID <= 0 then return nil end
syncWeaponCacheFromLobby()
local w = cache().weapons[weaponID]
if w and w.resID and w.resID > 0 then return w.resID end
return nil
end
local function getMatchWeaponSkin(weaponID)
weaponID = tonumber(weaponID) or 0
local fromCache = getCachedWeaponSkin(weaponID)
if fromCache then return fromCache end
if MATCH_CONFIG.weaponSkins then
local fixed = tonumber(MATCH_CONFIG.weaponSkins[weaponID])
if fixed and fixed > 0 then return fixed end
end
return nil
end
local function findWornInsBySubType(st)
st = tonumber(st)
if not st then return nil end
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local AvatarData = require("client.logic.data.AvatarData")
for _, ins in pairs(AvatarData.GetRoleWear()) do
ins = tonumber(ins)
if ins and ins > 0 then
local d = wd:GetHallDepotItemDataByInsID(ins)
if d and tonumber(d.itemSubType) == st then
return ins, d.resID
end
end
end
return nil
end
local function removeRoleWearBySubTypes(stMap)
if not stMap then return end
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local AvatarData = require("client.logic.data.AvatarData")
for _, ins in pairs(AvatarData.GetRoleWear()) do
ins = tonumber(ins)
if ins and ins > 0 then
local d = wd:GetHallDepotItemDataByInsID(ins)
if d and stMap[tonumber(d.itemSubType)] then
AvatarData.RemoveRoleWearDataByValue(ins)
end
end
end
end
local function clearFashionBagSlots(stMap)
if not stMap then return end
pcall(function()
local fbd = require("client.slua.logic.wardrobe.fashionbag.fashionbag_data")
local wfu = require("client.slua.logic.wardrobe.fashionbag.wardrobe_fashion_utils")
local bag = fbd.GetCurrentFashionBag and fbd:GetCurrentFashionBag()
if not bag or not bag.rolewear_list then return end
for st, _ in pairs(stMap) do
local idx = wfu.GetRoleWearIndexBySubType and wfu:GetRoleWearIndexBySubType(st)
if idx then bag.rolewear_list[idx] = 0 end
end
end)
end
local function removeRoleWearBySubType(st)
if not st then return end
removeRoleWearBySubTypes({ [tonumber(st)] = true })
end
local function syncFashionBagRolewear()
pcall(function()
local fbd = require("client.slua.logic.wardrobe.fashionbag.fashionbag_data")
fbd:SaveRolewearToFashionBag(fbd:GetFashionBagUseIndex())
end)
end
-- ========== مؤقّت ==========
local _ticker
pcall(function() _ticker = require("common.time_ticker") end)
local function later(sec, fn)
if _G.SetTimer then pcall(_G.SetTimer, sec, fn) return end
if _ticker and _ticker.AddTimer then pcall(_ticker.AddTimer, sec, fn) end
end
-- ========== حقن في الخزانة (نفس AddData الأصلي) ==========
local function getEntity()
local ok, dc = pcall(require, "client.slua.logic.wardrobe.logic_wardrobe_data_center")
if not ok or not dc then return nil end
local ok2, e = pcall(dc.GetWardrobeData)
return ok2 and e or nil
end
local function alreadyHave(entity, resID)
local arr = entity.ResIDToIndexArrayMap and entity.ResIDToIndexArrayMap[resID]
if not arr then return false end
for _, idx in pairs(arr) do
local d = entity._data[idx]
if d and d.count and d.count > 0 then return true end
end
return false
end
local function injectOne(entity, resID, insID)
if alreadyHave(entity, resID) then
R.resToIns[resID] = R.resToIns[resID] or insID
R.insToRes[insID] = resID
return true
end
local row = {
instid = insID,
res_id = resID,
count = 1,
lock_cnt = 0,
isnew = 0,
valid_hours = 0,
expire_ts = 0,
}
entity:AddData(row)
pcall(function()
local data = entity.GetDataByInsID and entity:GetDataByInsID(insID)
if data and entity.LoadConfigForData and CDataTable.GetTableData then
entity:LoadConfigForData(data, CDataTable.GetTableData)
end
end)
R.insToRes[insID] = resID
R.resToIns[resID] = insID
log("حقن", resID, insID)
return true
end
local function injectArmory(resID, insID)
local wid = weaponIdFromSkin(resID)
if not wid then return end
local Arm = require("client.logic.armory.logic_armory")
Arm.rsp_list = Arm.rsp_list or { skin_list = {}, install_list = {} }
Arm.rsp_list.skin_list = Arm.rsp_list.skin_list or {}
Arm.rsp_list.install_list = Arm.rsp_list.install_list or {}
if not Arm.rsp_list.skin_list[wid] then Arm.rsp_list.skin_list[wid] = {} end
Arm.rsp_list.skin_list[wid][resID] = { is_open = 1 }
Arm.WardrobeInsList = Arm.WardrobeInsList or {}
Arm.WardrobeInsList[resID] = insID
end
local function injectAll(entity)
entity = entity or getEntity()
if not entity or not entity.bInit then return false end
local n = 0
for i, resID in ipairs(ITEMS) do
local insID = INS_BASE + i
if injectOne(entity, resID, insID) then
n = n + 1
local c = cfg(resID)
if GUN_SUB[subType(c)] or subType(c) == MELEE_ID then
injectArmory(resID, insID)
end
end
end
log("حقن", n, "/", #ITEMS)
return n > 0
end
local function refreshWardrobe()
pcall(function()
if EventSystem and EVENTTYPE_WARDROBE then
if EVENTID_WARDROBE_UPDATE_ITEM_LIST then
EventSystem:postEvent(EVENTTYPE_WARDROBE, EVENTID_WARDROBE_UPDATE_ITEM_LIST)
end
if EVENTID_WARDROBE_UPDATE_AVATAR_LIST then
EventSystem:postEvent(EVENTTYPE_WARDROBE, EVENTID_WARDROBE_UPDATE_AVATAR_LIST)
end
if EVENTID_WARDROBE_UPDATE_GUN_LIST then
EventSystem:postEvent(EVENTTYPE_WARDROBE, EVENTID_WARDROBE_UPDATE_GUN_LIST, -1)
end
end
end)
end
-- ========== لبس ملابس (ذكي: بدلة كاملة / تيشيرت / بنطلون / حذاء) ==========
local function putOnCloth(insID)
insID = tonumber(insID)
local resID = R.insToRes[insID]
if not resID then return end
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local d = wd:GetHallDepotItemDataByInsID(insID)
if not d then return end
local kind = getClothKind(resID, d)
if not kind then return end
local clearMap = subTypesToClearForKind(kind)
if not clearMap then return end
local itemSt = subType(cfg(resID)) or ST_TOP
local oldIns, oldRes = findWornInsBySubType(itemSt)
removeRoleWearBySubTypes(clearMap)
clearFashionBagSlots(clearMap)
saveEquip(resID, insID)
local slot = PKG_SLOT
pcall(function()
local wfu = require("client.slua.logic.wardrobe.fashionbag.wardrobe_fashion_utils")
local idx = wfu.GetRoleWearIndexBySubType and wfu:GetRoleWearIndexBySubType(itemSt)
if idx then slot = idx end
end)
local olditem
if oldIns and oldIns ~= insID then
olditem = { res_id = oldRes or R.insToRes[oldIns], count = 1, instid = oldIns }
end
local WRH = require("client.network.Protocol.WardRobeHandler")
local item = { res_id = resID, count = 1, instid = insID }
WRH.on_depot_put_on_rsp(NET_OK, item, olditem, slot, insID, oldIns or 0)
pcall(function()
local av = require("client.slua.logic.wardrobe.logic_wardrobe_avatar")
av:AddToWearInfo(itemSt, insID, resID, 0, 0)
local displayResID = resID
local LogicXSuit = require("client.slua.logic.XSuit.logic_xsuit")
if LogicXSuit.IsXSuit(displayResID) then
displayResID = LogicXSuit.GetItemShowID(insID) or displayResID
end
av:AvatarChange(displayResID, true, 0, 0)
av:ProcessTakeOff()
syncFashionBagRolewear()
end)
log("لبس", kind, resID)
end
local function putOnOutfit(insID)
putOnCloth(insID)
end
-- ========== تجهيز سكن سلاح (مسار اللعبة الكامل) ==========
local function equipWeaponSkin(weaponID, insID)
weaponID, insID = tonumber(weaponID), tonumber(insID)
if not weaponID or not insID or not isInjectedIns(insID) then return end
local resID = R.insToRes[insID]
saveEquip(resID, insID)
local Arm = require("client.logic.armory.logic_armory")
local fbd = require("client.slua.logic.wardrobe.fashionbag.fashionbag_data")
local HT = require("client.logic.lobby.hall_theme_utils")
local wgl = require("client.slua.logic.wardrobe.logic_wardrobe_gun")
injectArmory(resID, insID)
Arm.rsp_list.install_list[weaponID] = { skin_id = insID }
if fbd.UpdateCurrentFashionBagWeaponSkin then
fbd:UpdateCurrentFashionBagWeaponSkin(weaponID, insID)
end
local bagIdx = fbd:GetFashionBagUseIndex()
HT.proc_skin_list_chg("weapon_skin", weaponID, insID, bagIdx, {})
wgl:SetGunID(weaponID)
wgl:UpdateCurrentGunAvatar(weaponID, insID)
if EventSystem and EVENTTYPE_ARMORY and EVENTID_ARMORY_EQUIP_STAT_CHANGE then
EventSystem:postEvent(EVENTTYPE_ARMORY, EVENTID_ARMORY_EQUIP_STAT_CHANGE, resID)
end
if EventSystem and EVENTTYPE_WARDROBE and EVENTID_WARDROBE_UPDATE_CURRENT_PUT_ON_GUN then
EventSystem:postEvent(EVENTTYPE_WARDROBE, EVENTID_WARDROBE_UPDATE_CURRENT_PUT_ON_GUN, resID)
end
log("سكن سلاح", weaponID, resID, insID)
end
-- ========== سوشيال — مسار خفيف (بدون تعليق عند السحب) ==========
local SOCIAL = _G.AddOutfitSocialState or {}
_G.AddOutfitSocialState = SOCIAL
SOCIAL.debGen = SOCIAL.debGen or 0
SOCIAL.wearPatchKey = SOCIAL.wearPatchKey or nil
SOCIAL.snapshotKey = SOCIAL.snapshotKey or nil
SOCIAL.fullSnapshot = SOCIAL.fullSnapshot or nil
local function socialDebounce(sec, fn)
SOCIAL.debGen = (SOCIAL.debGen or 0) + 1
local gen = SOCIAL.debGen
later(sec, function()
if gen ~= SOCIAL.debGen then return end
pcall(fn)
end)
end
local function getLobbyCurPage()
local p = nil
pcall(function()
local LMC = require("client.slua.logic.lobby.Main.Lobby_Main_Control")
if LMC.GetCurPage then p = LMC.GetCurPage() end
end)
return p
end
local function getWeaponSkinResFast()
local cch = cache()
local wid = tonumber(DataMgr.Weapon_ID) or 0
local w = wid > 0 and cch.weapons[wid] or nil
if w and w.resID and w.resID > 0 then return w.resID end
for _, ww in pairs(cch.weapons) do
if ww.resID and ww.resID > 0 then return ww.resID end
end
return nil
end
-- كل مصادر السكن (ذاكرة + MATCH_CONFIG + أرموري + حقن)
local function resolveLobbyWeaponSkinRes()
local wid = tonumber(DataMgr.Weapon_ID) or 0
local skin = getWeaponSkinResFast()
if skin and skin > 0 then return skin end
if wid > 0 then
local fromMatch = getMatchWeaponSkin(wid)
if fromMatch and fromMatch > 0 then return fromMatch end
end
if MATCH_CONFIG.weaponSkins then
for _, s in pairs(MATCH_CONFIG.weaponSkins) do
s = tonumber(s)
if s and s > 0 then return s end
end
end
pcall(function()
local Arm = require("client.logic.armory.logic_armory")
local entry = Arm.rsp_list and Arm.rsp_list.install_list
and Arm.rsp_list.install_list[wid > 0 and wid or 101004]
local insID = tonumber(entry and entry.skin_id) or 0
if insID > 0 and isInjectedIns(insID) then
skin = tonumber(R.insToRes[insID])
elseif insID > 0 then
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local d = wd:GetHallDepotItemDataByInsID(insID)
if d and d.resID then skin = tonumber(d.resID) end
end
end)
if skin and skin > 0 then return skin end
pcall(function()
local wgl = require("client.slua.logic.wardrobe.logic_wardrobe_gun")
if wgl.GetSkinIdByWeaponID and wid > 0 then
local insID = tonumber(wgl:GetSkinIdByWeaponID(wid)) or 0
if insID > 0 and isInjectedIns(insID) then
skin = tonumber(R.insToRes[insID])
end
end
end)
return (skin and skin > 0) and skin or nil
end
local function rememberLobbyOutfitRes(resID)
resID = tonumber(resID)
if not resID or resID <= 0 or not isFullSuitRes(resID) then return end
_G.AddOutfitLastLobbyOutfitRes = resID
local cch = cache()
if not cch.outfitRes or cch.outfitRes <= 0 then
cch.outfitRes = resID
if isInjectedRes(resID) then cch.outfitIns = R.resToIns[resID] end
end
end
-- البدلة: ذاكرة + آخر بدلة في الوسط + MATCH_CONFIG + حقن + شنطة
local function resolveLobbyOutfitRes()
local cch = cache()
local outfitRes = tonumber(cch.outfitRes) or 0
if outfitRes > 0 then return outfitRes end
outfitRes = tonumber(_G.AddOutfitLastLobbyOutfitRes) or 0
if outfitRes > 0 then return outfitRes end
if MATCH_CONFIG.outfitRes and tonumber(MATCH_CONFIG.outfitRes) > 0 then
return tonumber(MATCH_CONFIG.outfitRes)
end
local injectedRes, anyRes
pcall(function()
local AvatarData = require("client.logic.data.AvatarData")
local wd = require("client.slua.logic.wardrobe.wardrobe_data")
local function resFromIns(ins)
ins = tonumber(ins)
if not ins or ins <= 0 then return nil end
if isInjectedIns(ins) then return tonumber(R.insToRes[ins]) end
local d = wd:GetHallDepotItemDataByInsID(ins)
return d and tonumber(d.resID) or nil
end
for _, ins in pairs(AvatarData.GetRoleWear()) do
local res = resFromIns(ins)
if res and isFullSuitRes(res) then
if isInjectedRes(res) then injectedRes = res end
anyRes = anyRes or res
end
end
local fbd = require("client.slua.logic.wardrobe.fashionbag.fashionbag_data")
local bag = fbd.GetCurrentFashionBag and fbd:GetCurrentFashionBag()
if bag and bag.rolewear_list then
for _, ins in pairs(bag.rolewear_list) do
local res = resFromIns(ins)
if res and isFullSuitRes(res) then
if isInjectedRes(res) then injectedRes = res end
anyRes = anyRes or res
end
end
end
end)
if injectedRes and injectedRes > 0 then return injectedRes end
if anyRes and anyRes > 0 then return anyRes end
return nil
end
local function wearPatchKey()
local outfit = resolveLobbyOutfitRes() or 0
local skin = resolveLobbyWeaponSkinRes() or 0
local openGun = 1
pcall(function()
local lds = require("client.slua.logic.wardrobe.logic_display_setting")
if lds.data and lds.data.OpenGun ~= nil then openGun = lds.data.OpenGun and 1 or 0 end
end)
return outfit .. "_" .. skin .. "_" .. openGun
end
local function syncDepotShowWeaponFlags(depot)
depot = depot or {}
pcall(function()
local lds = require("client.slua.logic.wardrobe.logic_display_setting")
if lds.data then
if lds.data.OpenGun ~= nil then depot.weapon = lds.data.OpenGun end
if lds.data.OpenSocialWeapon ~= nil then depot.social_weapon = lds.data.OpenSocialWeapon end
end
end)
return depot
end
-- تعديل pspace فقط (بدون مسح خزانة / بدون إعادة بناء كامل)
local function applyInjectedPspace(roleData)
if not roleData then return end
roleData.bshow = true
roleData.pspace_wear_ext = roleData.pspace_wear_ext or {}
local outfitRes = resolveLobbyOutfitRes()
if outfitRes and outfitRes > 0 then
roleData.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_CLOTH] = { outfitRes, 0, 0 }
end
local skinRes = resolveLobbyWeaponSkinRes()
if skinRes and skinRes > 0 then
roleData.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPON] = { 0, 0, 0 }
roleData.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPONSKIN] = { skinRes, 0, 0 }
roleData.depot_show_info = roleData.depot_show_info or {}
if roleData.depot_show_info.weapon == nil then
roleData.depot_show_info.weapon = true
end
end
roleData.depot_show_info = syncDepotShowWeaponFlags(roleData.depot_show_info)
end
local function patchSelfWearCache(force)
local key = wearPatchKey()
if not force and SOCIAL.wearPatchKey == key then return false end
SOCIAL.wearPatchKey = key
SOCIAL.snapshotKey = nil
SOCIAL.fullSnapshot = nil
local myUid = tonumber(DataMgr.roleData.uid)
if not myUid then return false end
local changed = false
pcall(function()
local BD = ModuleManager.GetModule(ModuleManager.DataModuleConfig.BasicDataAvatarWearInfo)
local d = BD:GetCacheData(myUid)
if not d then
BD:OnHandleMsgDataAndCallback(myUid, buildLocalRoleDataForCoupleAvatar())
return true
end
local oldCloth = d.pspace_wear_ext and d.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_CLOTH]
local oldSkin = d.pspace_wear_ext and d.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPONSKIN]
applyInjectedPspace(d)
local nc = d.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_CLOTH]
local ns = d.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPONSKIN]
if oldCloth ~= nc or oldSkin ~= ns or not d.bshow then changed = true end
end)
return force or changed
end
local function requestSocialAvatarRefresh()
pcall(function()
if EventSystem and EVENTTYPE_LOBBY_SOCIAL and EVENTID_SOCIAL_LOBBY_REFRESH_AVATAR then
EventSystem:postEvent(EVENTTYPE_LOBBY_SOCIAL, EVENTID_SOCIAL_LOBBY_REFRESH_AVATAR)
end
end)
end
local function onSocialWearDirty(forceRefresh)
SOCIAL.lastHandSkin = nil
if patchSelfWearCache(forceRefresh) then
requestSocialAvatarRefresh()
end
end
-- بيانات كاملة (مرة واحدة عند غياب الكاش)
local function buildLocalRoleDataForCoupleAvatar()
local key = wearPatchKey()
if SOCIAL.fullSnapshot and SOCIAL.snapshotKey == key then
return SOCIAL.fullSnapshot
end
syncWeaponCacheFromLobby()
local cch = cache()
local ad = DataMgr.avatarData or {}
local gender = tonumber(ad.gamegender) or 2
if gender < 1 then gender = 2 end
local data = {
uid = DataMgr.roleData.uid,
gender = gender,
bshow = true,
pspace_wear_ext = {
[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_HEAD] = { tonumber(ad.headid) or 401993, 0, 0 },
[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_HAIR] = { tonumber(ad.hairid) or 40601001, 0, 0 },
[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPON] = { 0, 0, 0 },
[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPONSKIN] = { 0, 0, 0 },
},
depot_show_info = {
weapon = true, social_weapon = true, idle = true,
helmet = true, bag = true, vehicle = true, hand = true,
},
}
local outfitRes = resolveLobbyOutfitRes()
if outfitRes and outfitRes > 0 then
data.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_CLOTH] = { outfitRes, 0, 0 }
end
local skinRes = resolveLobbyWeaponSkinRes()
if skinRes and skinRes > 0 then
data.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPON][1] = 0
data.pspace_wear_ext[ENUM_AVATAR_SHOW_TYPE.SHOW_POS_WEAPONSKIN][1] = skinRes
end
data.depot_show_info = syncDepotShowWeaponFlags(data.depot_show_info)
SOCIAL.fullSnapshot = data
SOCIAL.snapshotKey = wearPatchKey()
return data
end
local _myUidCached
local function isMyWearData(wearData)
if not wearData then return false end
if not _myUidCached then
pcall(function() _myUidCached = tonumber(DataMgr.roleData.uid) end)
end
return _myUidCached and tonumber(wearData.uid) == _myUidCached
end
-- سلاح في wearData (يد الشخصية — يجب weaponSkinId وليس السلاح الأساسي)
local function mergeInjectedWeaponIntoWearData(wearData)
if not isMyWearData(wearData) then return end
local skinRes = resolveLobbyWeaponSkinRes()
wearData.depot_show_info = syncDepotShowWeaponFlags(wearData.depot_show_info)
if not skinRes or skinRes <= 0 then return end
wearData.mainWeaponInfo = wearData.mainWeaponInfo or {
weaponResId = 0, weaponSkinId = 0,
diyInfo = { diyWeaponId = 0, diyDefaultScheme = false, diyScheme = nil },
}
if wearData.mainWeaponInfo.weaponSkinId == skinRes
and (tonumber(wearData.mainWeaponInfo.weaponResId) or 0) == 0 then
return
end
wearData.mainWeaponInfo.weaponSkinId = skinRes
wearData.mainWeaponInfo.weaponResId = 0
end
local function equipSocialHandWeapon(avatar, skinRes)
if not avatar or not skinRes or skinRes <= 0 then return end
if SOCIAL.lastHandSkin == skinRes then return end
SOCIAL.lastHandSkin = skinRes
pcall(function()
avatar:PutonEquipment(skinRes, nil, { bIsUse = true })
end)
end
local function shouldShowHandWeapon()
local show = true
pcall(function()
local lds = require("client.slua.logic.wardrobe.logic_display_setting")
if lds.data and lds.data.OpenGun ~= nil then
show = lds.data.OpenGun ~= false
end
end)
return show
end
-- استبدال البدلة الكاملة في WearInfoList — إزالة تيشيرت/بنطلون/حذاء المتداخلة
local function mergeInjectedOutfitIntoWearData(wearData)
if not isMyWearData(wearData) then return end
local outfitRes = resolveLobbyOutfitRes()
if not outfitRes or outfitRes <= 0 or not isFullSuitRes(outfitRes) then return end
rememberLobbyOutfitRes(outfitRes)
local AvatarData = require("client.logic.data.AvatarData")
local converted = AvatarData.ConvertToAvatarCustom({ outfitRes, 0, 0 })
if not converted then return end
local newList = {}
for _, e in ipairs(wearData.WearInfoList or {}) do
if e and e.ItemID and isBodyClothSubType(subType(cfg(e.ItemID))) then
-- حذف قطع الجسم المتعارضة مع البدلة
else
newList[#newList + 1] = e
end
end
newList[#newList + 1] = converted
wearData.WearInfoList = newList
end
local function mergeInjectedIntoWearData(wearData)
if not wearData then return end
mergeInjectedWeaponIntoWearData(wearData)
mergeInjectedOutfitIntoWearData(wearData)
end
local function reapplyLobbyEquipped()
if not GameStatus or not GameStatus.IsInLobbyOrMainCity or not GameStatus.IsInLobbyOrMainCity() then
return
end
syncWeaponCacheFromLobby()
local curPage = getLobbyCurPage()
if ENUM_LobbyPageType and curPage == ENUM_LobbyPageType.Left then
onSocialWearDirty(true)
return
end
local cch = cache()
if cch.outfitIns and isInjectedIns(cch.outfitIns) then
putOnOutfit(cch.outfitIns)
end
for wid, w in pairs(cch.weapons) do
wid = tonumber(wid)
if wid and w and w.resID and w.resID > 0 then
if w.insID and isInjectedIns(w.insID) then
equipWeaponSkin(wid, w.insID)
else
pcall(function() DataMgr.InitWeaponData(wid, w.resID, w.insID or 0) end)
end
end
end
pcall(function()
local uid = tostring(DataMgr.roleData.uid)
local LAM = require("client.logic.avatar.LobbyAvatarManager")
local TAM = require("client.logic.avatar.logic_team_avatar_manager")
local mainWid = tonumber(DataMgr.Weapon_ID) or 0
local mw = mainWid > 0 and cch.weapons[mainWid] or nil
if mw and mw.resID and mw.resID > 0 and TAM.GetAvatarByUid(uid) then
LAM.EquipWeapon(uid, { weaponId = mainWid, skinId = mw.resID }, nil, true)
end
end)
pcall(function()
if EventSystem and EVENTTYPE_WARDROBE and EVENTID_WARDROBE_UPDATE_AVATAR_LIST then
EventSystem:postEvent(EVENTTYPE_WARDROBE, EVENTID_WARDROBE_UPDATE_AVATAR_LIST)
end
end)
log("إعادة تطبيق لوبي")
end
local function hookLobbySwipePersistence()
pcall(function()
local BD = ModuleManager.GetModule(ModuleManager.DataModuleConfig.BasicDataAvatarWearInfo)
local oRsp = BD.on_get_avatar_show_rsp
BD.on_get_avatar_show_rsp = function(self, res, target_uid, data)
oRsp(self, res, target_uid, data)
if tonumber(target_uid) == tonumber(DataMgr.roleData.uid) then
patchSelfWearCache(true)
SOCIAL.forceAvatarRedraw = true
SOCIAL.lastHandSkin = nil
if ENUM_LobbyPageType and getLobbyCurPage() == ENUM_LobbyPageType.Left then
requestSocialAvatarRefresh()
end
end
end
end)
pcall(function()
local AC = require("client.slua.logic.avatar.avatar_common")
local oGetWear = AC.GetWearDataFromRoleData
AC.GetWearDataFromRoleData = function(roleData)
local wearData = oGetWear(roleData)
if wearData and roleData and tonumber(roleData.uid) == tonumber(DataMgr.roleData.uid) then
mergeInjectedIntoWearData(wearData)
end
return wearData
end
local oUp = AC.UpdateAvatar
AC.UpdateAvatar = function(avatar, wearData, isShowWeapon, isShowHelmet, isShowBag)
if isMyWearData(wearData) then
mergeInjectedIntoWearData(wearData)
end
local showGun = isShowWeapon and shouldShowHandWeapon()
if wearData and wearData.depot_show_info then
showGun = showGun and wearData.depot_show_info.weapon ~= false
end
if isMyWearData(wearData) then
for _, e in ipairs(wearData.WearInfoList or {}) do
if e and e.ItemID and isInjectedRes(e.ItemID) and isFullSuitRes(e.ItemID) then
rememberLobbyOutfitRes(e.ItemID)
break
end
end
end
local ret = oUp(avatar, wearData, showGun, isShowHelmet, isShowBag)
if showGun and isMyWearData(wearData) and avatar
and ENUM_LobbyPageType and getLobbyCurPage() == ENUM_LobbyPageType.Left then
local skin = tonumber(wearData.mainWeaponInfo and wearData.mainWeaponInfo.weaponSkinId) or 0
if skin <= 0 then skin = resolveLobbyWeaponSkinRes() or 0 end
if skin > 0 then equipSocialHandWeapon(avatar, skin) end
end
return ret
end
end)
pcall(function()
local CA = require("client.logic.avatar.CoupleAvatar")
local Cfg = require("client.slua.logic.lobby.Left.CoupleAvatarConfig")
local oMulti = CA._UpdateMultiAvatar
if oMulti then
CA._UpdateMultiAvatar = function(self, avatar, avatarType)
local isSelf = avatarType == Cfg.AvatarType.Self
and self.SelfUID and tostring(self.SelfUID) == tostring(DataMgr.roleData.uid)
if isSelf then
pcall(function()
local BD = ModuleManager.GetModule(ModuleManager.DataModuleConfig.BasicDataAvatarWearInfo)
local d = BD:GetCacheData(tonumber(self.SelfUID))
if d then applyInjectedPspace(d) end
end)
if SOCIAL.forceAvatarRedraw then
self.CompareDataCache[avatarType] = nil
SOCIAL.forceAvatarRedraw = nil
end
end
oMulti(self, avatar, avatarType)
if isSelf and self.isShowWeapon ~= false and shouldShowHandWeapon()