-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathskinparser.cpp
213 lines (159 loc) · 6.08 KB
/
skinparser.cpp
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
#include "skinparser.h"
#include <algorithm>
#include <codecvt>
#include "offsets.h"
#include "interfaces.h"
namespace SkinParser
{
std::vector<std::pair<int, std::string>> k_skins;
std::vector<std::pair<int, std::string>> k_gloves;
std::vector<std::pair<int, std::string>> k_stickers;
class CCStrike15ItemSchema;
class CCStrike15ItemSystem;
template <typename Key, typename Value>
struct Node_t
{
int previous_id; //0x0000
int next_id; //0x0004
void* _unknown_ptr; //0x0008
int _unknown; //0x000C
Key key; //0x0010
Value value; //0x0014
};
template <typename Key, typename Value>
struct Head_t
{
Node_t<Key, Value>* memory; //0x0000
int allocation_count; //0x0004
int grow_size; //0x0008
int start_element; //0x000C
int next_available; //0x0010
int _unknown; //0x0014
int last_element; //0x0018
}; //Size=0x001C
// could use CUtlString but this is just easier and CUtlString isn't needed anywhere else
struct String_t
{
char* buffer; //0x0000
int capacity; //0x0004
int grow_size; //0x0008
int length; //0x000C
}; //Size=0x0010
struct CPaintKit
{
int id; //0x0000
String_t name; //0x0004
String_t description; //0x0014
String_t item_name; //0x0024
String_t material_name; //0x0034
String_t image_inventory; //0x0044
char pad_0x0054[0x8C]; //0x0054
}; //Size=0x00E0
struct CStickerKit
{
int id;
int item_rarity;
String_t name;
String_t description;
String_t item_name;
String_t material_name;
String_t image_inventory;
int tournament_event_id;
int tournament_team_id;
int tournament_player_id;
bool is_custom_sticker_material;
float rotate_end;
float rotate_start;
float scale_min;
float scale_max;
float wear_min;
float wear_max;
String_t image_inventory2;
String_t image_inventory_large;
uint32_t pad0[4];
};
void InitializeKits()
{
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
// Search the relative calls
// call ItemSystem
// push dword ptr [esi+0Ch]
// lea ecx, [eax+4]
// call CEconItemSchema::GetPaintKitDefinition
// Skip the opcode, read rel32 address
auto item_system_offset = *reinterpret_cast<int32_t*>(offsets.sigs.PaintkitSig + 1);
// Add the offset to the end of the instruction
auto item_system_fn = reinterpret_cast<CCStrike15ItemSystem* (*)()>(offsets.sigs.PaintkitSig + 5 + item_system_offset);
// Skip VTable, first member variable of ItemSystem is ItemSchema
auto item_schema = reinterpret_cast<CCStrike15ItemSchema*>(uintptr_t(item_system_fn()) + sizeof(void*));
// Dump paint kits
{
// Skip the instructions between, skip the opcode, read rel32 address
auto get_paint_kit_definition_offset = *reinterpret_cast<int32_t*>(offsets.sigs.PaintkitSig + 11 + 1);
// Add the offset to the end of the instruction
auto get_paint_kit_definition_fn = reinterpret_cast<CPaintKit* (__thiscall *)(CCStrike15ItemSchema*, int)>(offsets.sigs.PaintkitSig + 11 + 5 + get_paint_kit_definition_offset);
// The last offset is head_element, we need that
// push ebp
// mov ebp, esp
// sub esp, 0Ch
// mov eax, [ecx+298h]
// Skip instructions, skip opcode, read offset
auto start_element_offset = *reinterpret_cast<intptr_t*>(uintptr_t(get_paint_kit_definition_fn) + 8 + 2);
// Calculate head base from start_element's offset
auto head_offset = start_element_offset - 12;
auto map_head = reinterpret_cast<Head_t<int, CPaintKit*>*>(uintptr_t(item_schema) + head_offset);
for (int i = 0; i <= map_head->last_element; ++i)
{
auto paint_kit = map_head->memory[i].value;
if (paint_kit->id == 9001)
continue;
const wchar_t* wide_name = pLocalize->Find(paint_kit->item_name.buffer + 1);
auto name = converter.to_bytes(wide_name);
if (paint_kit->id < 10000)
k_skins.push_back({ paint_kit->id, name });
else
k_gloves.push_back({ paint_kit->id, name });
}
std::sort(k_skins.begin(), k_skins.end());
std::sort(k_gloves.begin(), k_gloves.end());
k_skins.at(0).second = "None";
}
// Dump sticker kits
{
// Skip the instructions between, skip the opcode, read rel32 address
auto get_sticker_kit_definition_offset = *reinterpret_cast<intptr_t*>(offsets.sigs.StickerSig + 1);
// Add the offset to the end of the instruction
auto get_sticker_kit_definition_fn = reinterpret_cast<CPaintKit* (__thiscall *)(CCStrike15ItemSchema*, int)>(offsets.sigs.StickerSig + 5 + get_sticker_kit_definition_offset);
// The last offset is head_element, we need that
// push ebp
// mov ebp, esp
// push ebx
// push esi
// push edi
// mov edi, ecx
// mov eax, [edi + 2BCh]
// Skip instructions, skip opcode, read offset
auto start_element_offset = *reinterpret_cast<intptr_t*>(uintptr_t(get_sticker_kit_definition_fn) + 8 + 2);
// Calculate head base from start_element's offset
auto head_offset = start_element_offset - 12;
auto map_head = reinterpret_cast<Head_t<int, CStickerKit*>*>(uintptr_t(item_schema) + head_offset);
for (int i = 0; i <= map_head->last_element; ++i)
{
auto sticker_kit = map_head->memory[i].value;
char sticker_name_if_valve_fucked_up_their_translations[64];
auto sticker_name_ptr = sticker_kit->item_name.buffer + 1;
if (strstr(sticker_name_ptr, "StickerKit_dhw2014_dignitas"))
{
strcpy_s(sticker_name_if_valve_fucked_up_their_translations, "StickerKit_dhw2014_teamdignitas");
strcat_s(sticker_name_if_valve_fucked_up_their_translations, sticker_name_ptr + 27);
sticker_name_ptr = sticker_name_if_valve_fucked_up_their_translations;
}
const wchar_t* wide_name = pLocalize->Find(sticker_name_ptr);
auto name = converter.to_bytes(wide_name);
k_stickers.push_back({ sticker_kit->id, name });
}
std::sort(k_stickers.begin(), k_stickers.end());
k_stickers.at(0).second = "None";
}
}
}