-
Notifications
You must be signed in to change notification settings - Fork 7
/
Menus.cpp
168 lines (130 loc) · 4.71 KB
/
Menus.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
#include "Menus.h"
#include "PatternScanner.h"
namespace Tralala
{
uintptr_t g_menuManagerAddr = 0;
uintptr_t g_uiManagerAddr = 0;
uintptr_t g_addMessageAddr = 0;
uintptr_t g_isMenuOpenAddr = 0;
uintptr_t g_registerAddr = 0;
uintptr_t g_isInMenuMode1Addr = 0;
uintptr_t g_isInMenuMode2Addr = 0;
uintptr_t g_crc64Addr = 0;
uintptr_t g_menuCtorAddr = 0;
uintptr_t g_menuDtorAddr = 0;
uintptr_t g_stringHoldAddr = 0;
void MenusGetAddresses(void)
{
const std::array<BYTE, 9> menuMgpattern = { 0x48, 0x8B, 0xD1, 0x41, 0xB0, 0x01, 0x49, 0x8B, 0xCA };
g_menuManagerAddr = (uintptr_t)scan_memory_data(menuMgpattern, 0x34, false, 0x3, 0x7);
const std::array<BYTE, 6> menuOppattern = { 0x33, 0xD2, 0x41, 0x0F, 0xB6, 0xCE };
g_isMenuOpenAddr = (uintptr_t)scan_memory_data(menuOppattern, 0x4D, false, 0x1, 0x5);
const std::array<BYTE, 10> regpattern = { 0x48, 0x8B, 0xC4, 0x53, 0x56, 0x57, 0x48, 0x83, 0xEC, 0x50 };
g_registerAddr = (uintptr_t)scan_memory(regpattern, 0, true);
const std::array<BYTE, 5> menu1pattern = { 0x0F, 0x57, 0xF6, 0xA8, 0x20 };
g_isInMenuMode1Addr = (uintptr_t)scan_memory_data(menu1pattern, 0x7, true, 0x2, 0x6);
const std::array<BYTE, 5> menu2pattern = { 0x0F, 0x57, 0xF6, 0xA8, 0x20 };
g_isInMenuMode2Addr = (uintptr_t)scan_memory_data(menu2pattern, 0xF, true, 0x2, 0x6);
const std::array<BYTE, 8> uipattern = { 0xC6, 0x43, 0x50, 0x00, 0xC6, 0x43, 0x3D, 0x01 };
g_uiManagerAddr = (uintptr_t)scan_memory_data(uipattern, 0xAB, true, 0x3, 0x7);
const std::array<BYTE, 8> addpattern = { 0xC6, 0x43, 0x50, 0x00, 0xC6, 0x43, 0x3D, 0x01 };
g_addMessageAddr = (uintptr_t)scan_memory_data(addpattern, 0xB2, true, 0x1, 0x5);
const std::array<BYTE, 8> crcpattern = { 0x49, 0xC1, 0xE8, 0x08, 0x41, 0x0F, 0xB6, 0xC2 };
g_crc64Addr = (uintptr_t)scan_memory(crcpattern, 0xAF, false);
const std::array<BYTE, 7> ctorpattern = { 0x89, 0x41, 0x1C, 0xC6, 0x41, 0x18, 0x03 };
g_menuCtorAddr = (uintptr_t)scan_memory(ctorpattern, 0x21, false);
const std::array<BYTE, 7> dtorpattern = { 0x4C, 0x8B, 0x86, 0x50, 0x05, 0x03, 0x00 };
g_menuDtorAddr = (uintptr_t)scan_memory_data(dtorpattern, 0xE1, true, 0x1, 0x5);
const std::array<BYTE, 7> strpattern = { 0x48, 0x8B, 0xF8, 0xC6, 0x47, 0x20, 0x01 };
g_stringHoldAddr = (uintptr_t)scan_memory_data(strpattern, 0x7, true, 0x3, 0x7);
}
IMenu::IMenu()
{
typedef IMenu*(*IMenu_ctor_t)(IMenu*);
IMenu_ctor_t IMenu_ctor = (IMenu_ctor_t)g_menuCtorAddr;
IMenu_ctor(this);
}
IMenu::~IMenu()
{
typedef void(*IMenu_dtor_t)(IMenu*);
IMenu_dtor_t IMenu_dtor = (IMenu_dtor_t)g_menuDtorAddr;
IMenu_dtor(this);
}
UInt32 IMenu::ProcessMessage(UIMessage* message)
{
if (message->message == 6){
if (view && message->objData){
BSUIScaleformData *scaleformData = static_cast<BSUIScaleformData*>(message->objData);
view->HandleEvent(&scaleformData->event);
return 0;
}
}
return 2;
}
void IMenu::Render()
{
if (view)
view->Render();
}
UInt32 MenuTableItem::GetHash(BSFixedString * key)
{
typedef void(*CalculateCRC32_64_t)(UInt32 * out, UInt64 data);
CalculateCRC32_64_t CalculateCRC32_64 = (CalculateCRC32_64_t)g_crc64Addr;
UInt32 hash;
CalculateCRC32_64(&hash, (UInt64)key->data);
return hash;
}
MenuManager * MenuManager::GetSingleton()
{
return *(MenuManager**)g_menuManagerAddr;
}
bool MenuManager::IsMenuOpen(BSFixedString * menuName)
{
typedef bool(*IsMenuOpen_t)(MenuManager *, BSFixedString *);
IsMenuOpen_t IsMenuOpen = (IsMenuOpen_t)g_isMenuOpenAddr;
return IsMenuOpen(this, menuName);
}
bool MenuManager::IsInMenuMode()
{
return (*(bool*)g_isInMenuMode1Addr || *(bool*)g_isInMenuMode2Addr);
}
IMenu * MenuManager::GetMenu(BSFixedString * menuName)
{
if (!menuName->data)
return nullptr;
MenuTableItem * item = menuTable.Find(menuName);
if (!item)
return nullptr;
IMenu * menu = item->menuInstance;
if (!menu)
return nullptr;
return menu;
}
GFxMovieView * MenuManager::GetMovieView(BSFixedString * menuName)
{
IMenu * menu = GetMenu(menuName);
if (!menu)
return nullptr;
return menu->view;
}
void MenuManager::Register(const char* name, CreatorFunc creator)
{
typedef void(*Register_t)(MenuManager*, const char*, CreatorFunc);
Register_t Register = (Register_t)g_registerAddr;
Register(this, name, creator);
}
UIManager * UIManager::GetSingleton()
{
return *(UIManager**)g_uiManagerAddr;
}
void UIManager::AddMessage(StringCache::Ref * strData, UInt32 msgID, void * objData)
{
typedef void(*AddMessage_t)(UIManager*, StringCache::Ref *, UInt32, void*);
AddMessage_t AddMessage = (AddMessage_t)g_addMessageAddr;
AddMessage(this, strData, msgID, objData);
}
UIStringHolder * UIStringHolder::GetSingleton()
{
return *(UIStringHolder**)g_stringHoldAddr;
}
}