-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
286 lines (252 loc) · 7.21 KB
/
main.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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#include "main.h"
#include <stdlib.h>
#include "src/cwsdk-extension.h"
#include "src/mods/SeaExplorationMod/SeaExplorationMod.h"
#include "src/mods/LoreInteractionMod/LoreInteractionMod.h"
#include "src/mods/CombatUpdatesMod/CombatUpdateMod.h"
#include "src/mods/CreatureUpdatesMod/CreatureUpdatesMod.h"
#include "src/mods/ShopUpdateMod/ShopUpdateMod.h"
#include "src/mods/WorldGenMod/WorldGenMod.h"
#include "src/mods/BeginnerModeMod/BeginnerModeMod.h"
#include "src/mods/RegionLockUpdateMod/RegionLockUpdateMod.h"
#include "src/mods/WeaponUpgradeMod/WeaponUpgradeMod.h"
#include "src/mods/QuestMod/QuestMod.h"
#include "src/mods/PlayerUpdatesMod/PlayerUpdatesMod.h"
#include "src/mods/StackUpdatesMod/StackUpdatesMod.h"
#include "src/CubeMod.h"
GLOBAL std::vector<CubeMod*> g_Mods;
GLOBAL char* g_Base;
#include "src/hooks/ChestInteractionHandler.h"
#include "src/hooks/ShopInteractionHandler.h"
#include "src/hooks/ItemPriceHandler.h"
#include "src/hooks/lore_increase.h"
#include "src/hooks/ItemDropPatch.h"
#include "src/hooks/CreatureDeathHandler.h"
#include "src/hooks/CreatureTalkHandler.h"
// OLD
#define DEBUG 1
// OLD
int DisplayOnlyInDebugMessage()
{
cube::GetGame()->PrintMessage(L"[Error] This command is only available in debug mode.\n", 255, 127, 80);
return 1;
}
/* Mod class containing all the functions for the mod.
*/
class Mod : GenericMod {
std::vector<CubeMod*> modVector;
std::vector<hook::HookEventData> hookEvents;
/* Hook for the chat function. Triggers when a user sends something in the chat.
* @param {std::wstring*} message
* @return {int}
*/
virtual int OnChat(std::wstring* message) override {
const wchar_t* msg = message->c_str();
int ID, value;
if (swscanf_s(msg, L"/mod %d %d", &ID, &value) == 2)
{
for (CubeMod* mod : modVector)
{
if (mod->m_ID == ID)
{
mod->m_Enabled = value == 0 ? false : true;
if (mod->m_Enabled)
{
std::string tmp = "Enabled: ";
tmp += mod->m_Name;
Popup("Notice", tmp.c_str());
}
else
{
std::string tmp = "Disabled: ";
tmp += mod->m_Name;
Popup("Notice", tmp.c_str());
}
}
}
cube::SaveSettings(&modVector);
return 1;
}
if (swscanf_s(msg, L"/class %d", &ID) == 1)
{
cube::Creature* player = cube::GetGame()->GetPlayer();
cube::Creature* creature = cube::CreatureFactory::SpawnCreature(player->entity_data.position, player->entity_data.current_region,
304, (int)cube::Enums::EntityBehaviour::NPC, 1);
creature->entity_data.appearance.flags2 |= 1 << (int)cube::Enums::AppearanceModifiers::NeededForGemTrader;
creature->entity_data.classType = ID;
creature->entity_data.specialization = 1;
return 0;
}
int type, subtype;
if (swscanf_s(msg, L"/t %d", &type) == 1)
{
cube::Game* game = cube::GetGame();
cube::World* world = game->world;
cube::Creature::AnimationState* animationState = &game->GetPlayer()->animation_state;
animationState->current_animation_state_timer = 0.f;
animationState->current_animation_state_id = type;
return 1;
}
for (CubeMod* mod : g_Mods)
{
if (mod->OnChat(message))
{
return 1;
}
}
return 0;
}
/* Function hook that gets called every game tick.
* @param {cube::Game*} game
* @return {void}
*/
virtual void OnGameTick(cube::Game* game) override {
for (CubeMod* mod : g_Mods) {
mod->OnGameTick(game);
}
for (hook::HookEventData e : hookEvents)
{
switch (e.type)
{
case hook::HookEvent::LoreInteraction:
for (CubeMod* mod : g_Mods) {
mod->OnLoreIncrease(game, e.data);
}
default:
break;
}
}
hookEvents.clear();
return;
}
void OnGetKeyboardState(BYTE* diKeys) override {
for (CubeMod* mod : g_Mods)
{
mod->OnGetKeyboardState(diKeys);
}
}
/* Function hook that gets called on intialization of cubeworld.
* [Note]: cube::GetGame() is not yet available here!!
* @return {void}
*/
virtual void Initialize() override {
g_Base = (char*)CWBase();
modVector.push_back(new SeaExplorationMod());
modVector.push_back(new LoreInteractionMod());
modVector.push_back(new CombatUpdateMod());
modVector.push_back(new CreatureUpdatesMod());
modVector.push_back(new ShopUpdateMod());
modVector.push_back(new WorldGenMod());
modVector.push_back(new BeginnerModeMod());
modVector.push_back(new RegionLockUpdateMod());
modVector.push_back(new WeaponUpgradeMod());
modVector.push_back(new QuestMod());
modVector.push_back(new PlayerUpdatesMod());
modVector.push_back(new StackUpdatesMod());
cube::ApplySettings(&modVector);
cube::SaveSettings(&modVector);
// Add enabled mods to the global modlist.
for (int i = 0; i < modVector.size(); i++)
{
if (modVector.at(i)->m_Enabled)
{
g_Mods.push_back(modVector.at(i));
}
}
// Modified from https://github.com/ChrisMiuchiz/Cube-World-Mod-Launcher/blob/master/CubeModLoader/main.cpp.
std::string mods("CubeMegaMods Active:\n");
for (CubeMod* mod : g_Mods) {
mods += " - (ID: ";
mods += std::to_string(mod->m_ID);
mods += ") ";
mods += mod->m_Name;
mods += " [";
mods += mod->m_Version.ToString();
mods += "]\n";
}
if (g_Mods.size() == 0) {
mods += "<No mods>\n";
}
Popup("CubeMegaMods", mods.c_str());
// Setup handlers
SetupChestInteractionHandler();
SetupShopInteractionHandler();
SetupOnCreatureDeathHandler();
SetupItemPriceHandler();
IncreaseLoreInitialize(&hookEvents); // Todo: Rename handler
ItemDropPatchInitialize();
SetupCreatureInteraction();
for (CubeMod* mod : g_Mods)
{
mod->Initialize();
}
return;
}
void OnCreatureArmorCalculated(cube::Creature* creature, float* armor)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureArmorCalculated(creature, armor);
}
}
void OnCreatureCriticalCalculated(cube::Creature* creature, float* critical)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureCriticalCalculated(creature, critical);
}
}
void OnCreatureAttackPowerCalculated(cube::Creature* creature, float* power)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureAttackPowerCalculated(creature, power);
}
}
void OnCreatureSpellPowerCalculated(cube::Creature* creature, float* power)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureSpellPowerCalculated(creature, power);
}
}
void OnCreatureHasteCalculated(cube::Creature* creature, float* haste)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureHasteCalculated(creature, haste);
}
}
void OnCreatureHPCalculated(cube::Creature* creature, float* hp)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureHPCalculated(creature, hp);
}
}
void OnCreatureResistanceCalculated(cube::Creature* creature, float* resistance)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureResistanceCalculated(creature, resistance);
}
}
void OnCreatureRegenerationCalculated(cube::Creature* creature, float* regeneration)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureRegenerationCalculated(creature, regeneration);
}
}
void OnCreatureManaGenerationCalculated(cube::Creature* creature, float* manaGeneration)
{
for (CubeMod* mod : g_Mods)
{
mod->OnCreatureManaGenerationCalculated(creature, manaGeneration);
}
}
};
// Export of the mod created in this file, so that the modloader can see and use it.
EXPORT Mod* MakeMod() {
return new Mod();
}