-
Notifications
You must be signed in to change notification settings - Fork 1
/
Item.h
100 lines (92 loc) · 4.69 KB
/
Item.h
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
#pragma once
#include "4dm.h"
#include "FontRenderer.h"
#include "QuadRenderer.h"
#include "Player.h"
namespace fdm
{
class FontRenderer;
class QuadRenderer;
class Player;
class Item
{
public:
inline static FontRenderer* fr = reinterpret_cast<FontRenderer*>((base + 0x2794A0));
inline static QuadRenderer* qr = reinterpret_cast<QuadRenderer*>((base + 0x278F18));
inline static nlohmann::json* blueprints = reinterpret_cast<nlohmann::json*>((base + 0x2BF098));
uint32_t count; // 0x8
inline static bool loadItemInfo()
{
return reinterpret_cast<bool (__fastcall*)()>(getFuncAddr((int)Func::Item::loadItemInfo))();
}
inline static void renderItem(std::unique_ptr<Item>& item, const glm::ivec2& pos)
{
return reinterpret_cast<void (__fastcall*)(std::unique_ptr<Item>& item, const glm::ivec2& pos)>(getFuncAddr((int)Func::Item::renderItem))(item, pos);
}
inline static void renderItemDescription(std::unique_ptr<Item>& item, const glm::ivec2& pos)
{
return reinterpret_cast<void (__fastcall*)(std::unique_ptr<Item>& item, const glm::ivec2& pos)>(getFuncAddr((int)Func::Item::renderItemDescription))(item, pos);
}
inline static std::unique_ptr<Item> createFromJson(nlohmann::json& j)
{
return reinterpret_cast<std::unique_ptr<Item> (__fastcall*)(nlohmann::json& j)>(getFuncAddr((int)Func::Item::createFromJson))(j);
}
inline static bool giveMax(std::unique_ptr<Item>& from, std::unique_ptr<Item>& to)
{
return reinterpret_cast<bool (__fastcall*)(std::unique_ptr<Item>& from, std::unique_ptr<Item>& to)>(getFuncAddr((int)Func::Item::giveMax))(from, to);
}
inline static bool giveOne(std::unique_ptr<Item>& from, std::unique_ptr<Item>& to)
{
return reinterpret_cast<bool (__fastcall*)(std::unique_ptr<Item>& from, std::unique_ptr<Item>& to)>(getFuncAddr((int)Func::Item::giveOne))(from, to);
}
inline static std::unique_ptr<Item> instantiateItem(const stl::string& itemName, uint32_t count, const stl::string& type, const nlohmann::json& attributes)
{
return reinterpret_cast<std::unique_ptr<Item> (__fastcall*)(const stl::string& itemName, uint32_t count, const stl::string& type, const nlohmann::json& attributes)>(getFuncAddr((int)Func::Item::instantiateItem))(itemName, count, type, attributes);
}
inline static std::unique_ptr<Item> create(const std::string& itemName, unsigned int count)
{
if (!(*blueprints).contains(itemName)) return NULL;
nlohmann::json itemJson = (*blueprints)[itemName];
std::string itemType = (std::string)itemJson["type"];
nlohmann::json itemBaseAttributes = itemJson["baseAttributes"];
return instantiateItem(itemName, count, itemType, itemBaseAttributes);
}
inline static nlohmann::json combineItemAttributes(const nlohmann::json& baseAttributes, const nlohmann::json& additions)
{
return reinterpret_cast<nlohmann::json (__fastcall*)(const nlohmann::json& baseAttributes, const nlohmann::json& additions)>(getFuncAddr((int)Func::Item::combineItemAttributes))(baseAttributes, additions);
}
nlohmann::json save()
{
nlohmann::json result;
return reinterpret_cast<nlohmann::json& (__thiscall*)(Item* self, nlohmann::json* result)>(getFuncAddr((int)Func::Item::save))(this, &result);
return result;
}
virtual ~Item()
{
reinterpret_cast<void(__thiscall*)(Item* self)>(getFuncAddr((int)Func::Item::destr_Item))(this);
}
bool takeMax(std::unique_ptr<Item>& other)
{
return reinterpret_cast<bool (__thiscall*)(Item* self, std::unique_ptr<Item>& other)>(getFuncAddr((int)Func::Item::takeMax))(this, other);
}
bool takeHalf(std::unique_ptr<Item>& other)
{
return reinterpret_cast<bool (__thiscall*)(Item* self, std::unique_ptr<Item>& other)>(getFuncAddr((int)Func::Item::takeHalf))(this, other);
}
// VIRTUAL FUNCS
virtual stl::string getName() { return ""; }
virtual void render(const glm::ivec2& pos) {}
virtual void renderEntity(const m4::Mat5& MV, bool inHand, const glm::vec4& lightDir) {}
virtual bool isDeadly() { return false; }
virtual bool isCompatible(const std::unique_ptr<Item>& other) { return false; }
virtual uint32_t getStackLimit() { return 4096; }
virtual bool action(World* world, Player* player, int action) { return false; }
virtual void postAction(World* world, Player* player, int action) {}
virtual bool breakBlock(World* world, Player* player, unsigned char block, const glm::ivec4& blockPos) { return false; }
virtual void postBreakBlock(World* world, Player* player) {}
virtual bool entityAction(World* world, Player* player, Entity* entity, int action) { return false; }
virtual void postEntityAction(World* world, Player* player, int action) {}
virtual std::unique_ptr<Item> clone() { return NULL; }
virtual nlohmann::json saveAttributes() { return NULL; }
};
}