-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathChat.cpp
More file actions
244 lines (203 loc) · 6.65 KB
/
Chat.cpp
File metadata and controls
244 lines (203 loc) · 6.65 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <CTRPluginFramework.hpp>
#include "Helpers/Chat.hpp"
#include "LibCtrpfExtras/OSDExtras.hpp"
namespace CTRPluginFramework {
u32 Chat::GetPlayerMessageData() {
u8 _pID = Game::GetActualPlayerIndex();
// swap your index with player 0 in order to get the correct pointer
if(_pID == Game::GetOnlinePlayerIndex()) {
_pID = 0;
}
else if(_pID == 0) {
_pID = Game::GetOnlinePlayerIndex();
}
u32 PTR = *(u32 *)Address(0x94FD84).addr; //0x94FD84
PTR += 0x464; //33078FA0
PTR += (0x530 * _pID);
return PTR;
}
std::string Chat::GetPlayerMessage() {
std::string pMessage;
Process::ReadString(GetPlayerMessageData() + 0x40C, pMessage, 0x64, StringFormat::Utf16);
return pMessage;
}
void Chat::ClearPlayerMessage() {
std::memset((void *)(GetPlayerMessageData() + 0x40C), 0, 0x64);
}
std::string Chat::GetPlayerName() {
std::string pName;
Process::ReadString(GetPlayerMessageData() + 0x3FA, pName, 0x16, StringFormat::Utf16);
return pName;
}
u8 Chat::GetPlayerIndex() {
return *(u8 *)(GetPlayerMessageData() + 0x3EC);
}
bool Chat::IsPlayerMessageOnScreen() {
u8 Short;
Process::Read8(GetPlayerMessageData() + 0x3F0, Short);
return (Short != 0);
}
void Chat::AnimationCommand() {
u32 x, y;
if(PlayerClass::GetInstance()->GetWorldCoords(&x, &y)) {
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), animID, {0, 0}, 0, 0, 0, 0, x, y, true);
Sleep(Seconds(2));
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 6, {0, 0}, 0, 0, 0, 0, x, y, true);
OSDExtras::Notify(Utils::Format(Language::getInstance()->get(TextID::CHAT_ANIMATION).c_str(), animID));
}
}
void Chat::EmotionCommand() {
u32 x, y;
if(PlayerClass::GetInstance()->GetWorldCoords(&x, &y)) {
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 0xAF, {0, 0}, emotionID, 0, 0, 0, x, y, true);
Sleep(Seconds(2));
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 6, {0, 0}, 0, 0, 0, 0, x, y, true);
OSDExtras::Notify(Utils::Format(Language::getInstance()->get(TextID::CHAT_EMOTION).c_str(), emotionID));
}
}
void Chat::SnakeCommand() {
u32 x, y;
if(PlayerClass::GetInstance()->GetWorldCoords(&x, &y)) {
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 0xC5, {0, 0}, 0, snakeID, 0, 0, x, y, true);
Sleep(Seconds(2));
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 6, {0, 0}, 0, 0, 0, 0, x, y, true);
OSDExtras::Notify(Utils::Format(Language::getInstance()->get(TextID::CHAT_SNAKE).c_str(), snakeID));
}
}
void Chat::MusicCommand() {
u32 x, y;
if(PlayerClass::GetInstance()->GetWorldCoords(&x, &y)) {
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 0xC4, {0, 0}, 0, 0, musicID, 0, x, y, true);
Sleep(Milliseconds(100));
Animation::ExecuteAnimationWrapper(GetPlayerIndex(), 6, {0, 0}, 0, 0, 0, 0, x, y, true);
OSDExtras::Notify(Utils::Format(Language::getInstance()->get(TextID::CHAT_MUSIC).c_str(), musicID));
}
}
void Chat::ItemCommand() {
u32 x, y;
if(PlayerClass::GetInstance()->GetWorldCoords(&x, &y)) {
Dropper::PlaceItemWrapper(0xA, ReplaceEverything, &itemID, &itemID, x, y, 0, 0, 0, 0, 0, 0x56, 0xA5, false);
OSDExtras::Notify(Utils::Format(Language::getInstance()->get(TextID::CHAT_ITEM).c_str(), *(u32*)&itemID));
}
}
void Chat::CommandLoop() {
//macro to clean up
#define CLEAR_RET \
ClearPlayerMessage(); \
return;
if(!IsPlayerMessageOnScreen()) {
return;
}
std::string PlayerText = GetPlayerMessage();
if(PlayerText.empty()) {
return;
}
PlayerText.resize(25, ' ');
//command
std::string Command = PlayerText.substr(0, 2);
UtilsExtras::ConvertToLowcase(Command);
//special case command (flag)
std::string SPCommand = PlayerText.substr(6, 2);
UtilsExtras::ConvertToLowcase(SPCommand);
//ID's
std::string ID_8Bit = PlayerText.substr(2, 2);
std::string ID_12Bit = PlayerText.substr(2, 3);
std::string ID_16Bit = PlayerText.substr(2, 4);
//special case ID (flag)
std::string SPID_16Bit = PlayerText.substr(8, 4);
//Item Name
std::string ItemName = PlayerText.substr(2, 23);
if(Command == "a:") {
animID = StringToHex<u8>(ID_8Bit, 6); //sets animation
if(IDList::AnimationValid(animID, GetPlayerIndex())) {
AnimationCommand();
}
else {
OSDExtras::Notify(TextID::CHAT_INVALID_ANIMATION, Color::Red);
CLEAR_RET
}
}
else if(Command == "e:") {
emotionID = StringToHex<u8>(ID_8Bit, 1); //sets emotion
if(IDList::EmotionValid(emotionID)) {
EmotionCommand();
}
else {
OSDExtras::Notify(TextID::CHAT_INVALID_EMOTION, Color::Red);
CLEAR_RET
}
}
else if(Command == "s:") {
snakeID = StringToHex<u16>(ID_12Bit, 1); //sets snake
if(IDList::SnakeValid(snakeID)) {
SnakeCommand();
}
else {
OSDExtras::Notify(TextID::CHAT_INVALID_SNAKE, Color::Red);
CLEAR_RET
}
}
else if(Command == "m:") {
musicID = StringToHex<u16>(ID_12Bit, 0x660); //sets music
if(IDList::MusicValid(musicID)) {
MusicCommand();
}
else {
OSDExtras::Notify(TextID::CHAT_INVALID_MUSIC, Color::Red);
CLEAR_RET
}
}
else if(Command == "i:") {
itemID.ID = StringToHex<u16>(ID_16Bit, 0x2001); //sets item
if(itemID.isValid()) {
if(SPCommand == "f:") {
itemID.Flags = StringToHex<u16>(SPID_16Bit, 0); //sets flag
}
ItemCommand();
}
else {
OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red);
CLEAR_RET
}
}
else if(Command == "n:") {
UtilsExtras::Trim(ItemName);
ItemNamePack match;
if (!Item::searchByKeyword(ItemName, match)) {
OSDExtras::Notify(TextID::CHAT_NO_ITEM_FOUND, Color::Red);
CLEAR_RET
}
itemID = Item(match.ID); //sets item
if(!itemID.isValid()) { //should always be true if orig file is used
OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red);
CLEAR_RET
}
ItemCommand();
}
else { // any other message
return;
}
ClearPlayerMessage();
}
void Chat::CommandCallback(void) {
if (!PlayerClass::GetInstance()->IsLoaded()) {
return;
}
Chat chat;
chat.CommandLoop();
}
void Chat::EnableCommands(void) {
PluginMenu *menu = PluginMenu::GetRunningInstance();
if (!menu) {
return;
}
*menu += CommandCallback;
}
void Chat::DisableCommands(void) {
PluginMenu *menu = PluginMenu::GetRunningInstance();
if (!menu) {
return;
}
*menu -= CommandCallback;
}
}