-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathstickers.cpp
82 lines (59 loc) · 2.15 KB
/
stickers.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
#include "stickers.h"
#include "skinchanger.h"
typedef float(__fastcall *AttributeFunction)(void*, void*, int, Stickers::EStickerAttributeType, float);
typedef unsigned int(__fastcall *IndexFunction)(void*, void*, int, Stickers::EStickerAttributeType, unsigned fl);
AttributeFunction oAttribFn;
IndexFunction oIndexFn;
enum class EStickerAttributeType
{
Index,
Wear,
Scale,
Rotation
};
static uint16_t s_iwoff = 0;
static void* o_float_fn;
static float __fastcall hooked_float_fn(void* thisptr, void*, int slot, EStickerAttributeType attribute, float fl)
{
auto item = reinterpret_cast<C_BaseAttributableItem*>(uintptr_t(thisptr) - s_iwoff);
switch (attribute)
{
case EStickerAttributeType::Wear:
return FLT_MIN;
case EStickerAttributeType::Scale:
return 1.f;
case EStickerAttributeType::Rotation:
return 0.f;
}
return reinterpret_cast<decltype(hooked_float_fn)*>(o_float_fn)(thisptr, nullptr, slot, attribute, fl);
}
static void* o_uint_fn;
static unsigned int __fastcall hooked_uint_fn(void* thisptr, void*, int slot, EStickerAttributeType attribute, unsigned fl)
{
/*auto item = reinterpret_cast<C_BaseAttributableItem*>(uintptr_t(thisptr) - s_iwoff);*/
switch (attribute)
{
case EStickerAttributeType::Index:
return Settings::Skinchanger::Skins::sticker1;
}
return reinterpret_cast<decltype(hooked_uint_fn)*>(o_uint_fn)(thisptr, nullptr, slot, attribute, fl);
}
void Stickers::ApplyStickerHooks(C_BaseAttributableItem* item)
{
if (offsets.CEconEntity.m_Item == 0xC)
return;
void**& stickerInfo = *reinterpret_cast<void***>((uintptr_t)item + offsets.CEconEntity.m_Item);
static void** stickerInfoHook = nullptr;
if (!stickerInfoHook)
{
size_t length = 0;
for (; stickerInfo[length]; ++length);
stickerInfoHook = new void*[length];
memcpy(stickerInfoHook, stickerInfo, length * sizeof(void*));
oAttribFn = reinterpret_cast<AttributeFunction>(stickerInfoHook[4]);
stickerInfoHook[4] = &hooked_float_fn;
oIndexFn = reinterpret_cast<IndexFunction>(stickerInfoHook[5]);
stickerInfoHook[5] = &hooked_uint_fn;
}
stickerInfo = stickerInfoHook;
}