-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemList.lua
189 lines (144 loc) · 5.98 KB
/
ItemList.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
-- Most of this script is borrowed from an example item adding script I got from some REF examples.
-- Except for the part that creates the GUI, that is.
-- Add statics since it isn't used elsewhere
local statics = {}
function statics.generate(typename, double_ended)
local double_ended = double_ended or false
local t = sdk.find_type_definition(typename)
if not t then return {} end
local fields = t:get_fields()
local enum = {}
for i, field in ipairs(fields) do
if field:is_static() then
local name = field:get_name()
local raw_value = field:get_data(nil)
enum[name] = raw_value
if double_ended then
enum[raw_value] = name
end
end
end
return enum
end
-- END statics
local ItemID = statics.generate(sdk.game_namespace("gamemastering.Item.ID"))
local WeaponID = statics.generate(sdk.game_namespace("EquipmentDefine.WeaponType"))
local item_id_table = {}
local weapon_id_table = {}
local friendly_item_id_table = {}
local friendly_item_id_to_internal_id_table = {}
local friendly_weapon_id_table = {}
local friendly_weapon_id_to_internal_id_table = {}
local internal_id_to_friendly_item_id_table = {}
local internal_id_to_friendly_weapon_id_table = {}
local invalid_item_id_name = ""
local invalid_weapon_id_name = ""
for k, v in pairs(ItemID) do
if type(k) == "string" then
table.insert(item_id_table, k)
end
end
table.sort(item_id_table, function(a, b)
return ItemID[a] < ItemID[b]
end)
for k, v in pairs(WeaponID) do
if type(k) == "string" then
table.insert(weapon_id_table, k)
end
end
table.sort(weapon_id_table, function(a, b)
return WeaponID[a] < WeaponID[b]
end)
local wanted_slot_number = 1
local wanted_amount = 1
local wanted_item_id = 0
local wanted_weapon_id = 0
local generated_friendly_names = false
re.on_draw_ui(function()
if not generated_friendly_names then return end
if reframework:is_drawing_ui() then
imgui.begin_window("Item and Weapon List", nil,
8 -- NoScrollbar
| 64 -- AlwaysAutoResize
)
local font = imgui.load_font("BebasNeue-Regular.ttf", 24)
if (font ~= nil) then
imgui.push_font(font)
end
imgui.text_colored("Item IDs and Names", -14710248) -- green
for i, v in ipairs(friendly_item_id_table) do
local lower_name = string.lower(v)
if not string.find(lower_name, 'rejected') and not string.find(lower_name, 'invalid') then
imgui.text(tostring(i) .. ": " .. tostring(v))
end
end
imgui.new_line()
imgui.text_colored("Weapon IDs and Names", -14710248) -- green
for i, v in ipairs(friendly_weapon_id_table) do
local lower_name = string.lower(v)
if not string.find(lower_name, 'rejected') and not string.find(lower_name, 'invalid') then
imgui.text(tostring(i) .. ": " .. tostring(v))
end
end
imgui.pop_font()
imgui.end_window()
end
end)
re.on_pre_application_entry("UpdateBehavior", function()
if not generated_friendly_names then
local item_data_type = sdk.find_type_definition(sdk.game_namespace("gamemastering.InventoryManager.PrimitiveItem"))
for i, internal_name in ipairs(item_id_table) do
local fake_item = item_data_type:create_instance()
fake_item:set_field("ItemId", ItemID[internal_name])
friendly_item_id_table[i] = fake_item:call("get_Label")
friendly_item_id_to_internal_id_table[friendly_item_id_table[i]] = internal_name
internal_id_to_friendly_item_id_table[internal_name] = friendly_item_id_table[i]
end
for i, internal_name in ipairs(weapon_id_table) do
local fake_item = item_data_type:create_instance()
fake_item:set_field("WeaponId", WeaponID[internal_name])
friendly_weapon_id_table[i] = fake_item:call("get_Label") .. " (" .. internal_name .. ")"
friendly_weapon_id_to_internal_id_table[friendly_weapon_id_table[i]] = internal_name
internal_id_to_friendly_weapon_id_table[internal_name] = friendly_weapon_id_table[i]
end
invalid_item_id_name = friendly_item_id_table[1]
invalid_weapon_id_name = friendly_weapon_id_table[1]
-- The 7 corresponds to the end of the "Item: " string
table.sort(friendly_item_id_table, function(a, b)
if string.find(a, "Invalid") and not string.find(b, "Invalid") then
return false
end
if not string.find(a, "Invalid") and string.find(b, "Invalid") then
return true
end
if #a >= 7 and #b >= 7 then
if string.sub(a, 7, 7) ~= '<' and string.sub(b, 7, 7) == '<' then
return true
end
if string.sub(a, 7, 7) == '<' and string.sub(b, 7, 7) ~= '<' then
return false
end
end
return a < b
end)
-- Start it at the "Weapon: " now
table.sort(friendly_weapon_id_table, function(a, b)
if string.find(a, "Invalid") and not string.find(b, "Invalid") then
return false
end
if not string.find(a, "Invalid") and string.find(b, "Invalid") then
return true
end
if #a >= 9 and #b >= 9 then
if string.sub(a, 9, 9) ~= '<' and string.sub(b, 9, 9) == '<' then
return true
end
if string.sub(a, 9, 9) == '<' and string.sub(b, 9, 9) ~= '<' then
return false
end
end
return a < b
end)
generated_friendly_names = true
end
end)