This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
generated from camila314/cross-platform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectManager.cpp
401 lines (360 loc) · 12.1 KB
/
ObjectManager.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#include "GameObjectController.h"
//#include "ObjectManager_checkCollision.hpp"
CCNode* ObjectManager::hooks::parentForZLayer(GJBaseGameLayer* self, int zLayer, bool detailChannel, int batchLayer) {
if (batchLayer == -2) {
if (!self->m_unusedDict)
self->m_unusedDict = CCDictionary::create();
CCNode* ret;
Cacao::ccAsMap<int, CCNode*>(self->m_unusedDict, [&](auto mymap) {
if (mymap.size() == 0) {
mymap[-3] = CCNode::create();
mymap[-1] = CCNode::create();
mymap[1] = CCNode::create();
mymap[3] = CCNode::create();
mymap[5] = CCNode::create();
mymap[7] = CCNode::create();
mymap[9] = CCNode::create();
mymap[11] = CCNode::create(); //unsure if this is even correct
for (auto [k, v] : mymap)
self->m_objectLayer->addChild(v, k);
}
ret = mymap[zLayer];
});
return ret;
} else {
return ObjectManager::origs::parentForZLayer(self, zLayer, detailChannel, batchLayer);
}
}
void ObjectManager::hooks::playShineEffect(GameObject* self) {
if (self->m_activated || self->m_activatedByP2 || self->getOpacity() == 0 || PL==NULL)
return;
std::string shineFrame;
bool playCircle;
auto obj_uuid = GET_UUID(self);
GameObjectController* custom = nullptr;
if (ObjectManager::object_controllers.count(obj_uuid) > 0) {
custom = ObjectManager::object_controllers[obj_uuid];
if (!custom->m_shineInfo.shine)
return;
}
if (custom && !custom->m_shineInfo.texture_default) {
shineFrame = custom->m_shineInfo.shine_texture;
playCircle = custom->m_shineInfo.use_circle;
} else if (GET_ID(self) == 1331) {
shineFrame = "portal_16_shine_001.png";
playCircle = false;
} else if (GET_ID(self) < 204 || GET_ID(self) == 1334) {
shineFrame = StaticTools::replaceAll(self->m_textureName, "_001.png", "_shine_001.png");
playCircle = true;
} else {
shineFrame = StaticTools::replaceAll(self->m_textureName, "_front_001.png", "_shine_001.png");
playCircle = false;
}
auto circleColor = ccc3(255, 255, 0);
if (custom) {
circleColor = custom->m_shineInfo.circle_color;
} else switch (GET_ID(self)) {
case 201:
circleColor = ccc3(0, 150, 255);//0xff9600;
break;
case 202:
circleColor = ccc3(0, 255, 150);//0x96ff00;
break;
case 203:
circleColor = ccc3(255, 0, 255);//0xff00ff;
break;
case 1334:
circleColor = ccc3(255, 50, 50);//0x3232ff;
break;
default:
if (GET_ID(self) > 203) {
circleColor = ccc3(0, 150, 255);//0xff9600;
} else {
circleColor = ccc3(255, 255, 255);
}
}
auto shineSprite = CCSpritePlus::createWithSpriteFrameName(shineFrame.c_str());
if (shineSprite == 0)
return;
shineSprite->setPosition(self->getRealPosition());
shineSprite->setRotation(self->getRotation());
shineSprite->setFlipX(self->isFlipX());
shineSprite->setFlipY(self->isFlipY());
shineSprite->setScaleX(self->getScaleX());
shineSprite->setScaleY(self->getScaleY());
shineSprite->setOpacity(self->getOpacity());
shineSprite->followSprite(self);
shineSprite->setBlendFunc({700, 1});
if (self->getParent()) {
PL->m_objectLayer->addChild(shineSprite, self->getParent()->getZOrder() + 1);
}
auto sequence = CCSequence::create(
CCFadeIn::create(0.05),
CCFadeOut::create(0.3),
CCCallFunc::create(shineSprite, (SEL_CallFunc)&CCSpritePlus::stopFollow),
CCCallFunc::create(shineSprite, (SEL_CallFunc)&CCNode::removeMeAndCleanup),
nullptr
);
shineSprite->runAction(sequence);
if (playCircle) {
float duration = 70.0;
if (custom) {
duration = custom->m_shineInfo.shine_duration;
} else switch (self->_id()) {
case 200:
duration = 60.0;
break;
case 201:
duration = 65.0;
break;
case 203:
duration = 80.0;
break;
case 1334:
duration = 90.0;
break;
default:
duration = 70.0;
break;
}
auto circleWave = CCCircleWave::create(5.0, duration, 0.3, false);
circleWave->_color() = circleColor;
circleWave->setPosition(self->getPosition());
if (self->getParent()) {
PL->m_objectLayer->addChild(circleWave, self->getParent()->getZOrder() - 1);
}
//*(circleWave + 0x140) = 0x600000001; ill sort self out later, its just visual who cares
circleWave->followObject(self, true);
circleWave->_delegate() = PL;
PL->addCircle(circleWave);
}
}
GameObject* ObjectManager::hooks::objectFromString(gd::string str, bool idk) {
auto object = ObjectManager::origs::objectFromString(str, idk);
if (!object) return object;
std::string rstr = std::string(str);
auto obj_id = GET_UUID(object);
if (ObjectManager::object_controllers.count(obj_id)) {
object_map m;
std::string tmp;
std::string tmp2;
bool even = false;
std::stringstream pain;
pain << rstr;
while (std::getline(pain, tmp, ',')) {
if (!even)
tmp2 = std::move(tmp);
else {
int key = stoi(tmp2);
if (key > 1000) {
m[key-1000] = tmp;
}
}
even = !even;
}
ObjectManager::object_controllers[obj_id]->onImport(m);
}
return object;
}
gd::string ObjectManager::hooks::getSaveString(GameObject* self) {
std::string dat(ObjectManager::origs::getSaveString(self));
auto obj_id = GET_UUID(self);
if (ObjectManager::object_controllers.count(obj_id)) {
auto out = ObjectManager::object_controllers[obj_id]->onExport();
for (auto [k, v] : out) {
dat += "," + std::to_string(k+1000) + "," + v;
}
}
return gd::string(dat);
}
void ObjectManager::hooks::resetObject(GameObject* self) {
auto obj_id = GET_UUID(self);
if (ObjectManager::object_controllers.count(obj_id)) {
ObjectManager::object_controllers[obj_id]->onReset();
}
ObjectManager::origs::resetObject(self);
}
void ObjectManager::hooks::collidedWithObject(PlayerObject* self, GameObject* object) {
auto obj_id = GET_UUID(object);
if (ObjectManager::object_controllers.count(obj_id)) {
ObjectManager::object_controllers[obj_id]->onCollision(self, GJBL);
} else {
ObjectManager::origs::collidedWithObject(self, object);
}
}
void ObjectManager::hooks::triggerObject(GameObject* self, PlayLayer* layer) {
auto obj_id = GET_UUID(self);
if (ObjectManager::object_controllers.count(obj_id)) {
ObjectManager::object_controllers[obj_id]->onTrigger(layer);
}
float speed;
switch (GET_ID(self)) {
case 200:
speed = 0.70;
break;
case 201:
speed = 0.9;
break;
case 202:
speed = 1.10;
break;
case 203:
speed = 1.30;
break;
case 1334:
speed = 1.60;
default:
return;
}
layer->updateTimeMod(speed, false);
self->playShineEffect();
layer->addToSpeedObjects(self);
}
void ObjectManager::hooks::customSetup(GameObject* self) {
ObjectManager::origs::customSetup(self);
auto obj_id = GET_UUID(self);
if (ObjectManager::object_controllers.count(obj_id)) {
ObjectManager::object_controllers[obj_id]->onSetup();
}
}
__fastcall void ObjectManager::hooks::addGlow(GameObject* self) {
auto obj_id = GET_UUID(self);
if (ObjectManager::object_controllers.count(obj_id)) {
auto custom = ObjectManager::object_controllers[obj_id];
if (!custom->getGlowEnabled())
return;
}
ObjectManager::origs::addGlow(self);
}
#if _WIN32
__fastcall void ObjectManager::hooks::setDisplayFrame(CCSprite* self, void* dummy, CCSpriteFrame* frame)
#else
void ObjectManager::hooks::setDisplayFrame(CCSprite* self, CCSpriteFrame* frame)
#endif
{
if (frame == nullptr) {
//FLAlertLayer::create(NULL, "Problem", "Ok", NULL, "Sprite used for this object is invalid.")->show();
return;
}
self->m_obUnflippedOffsetPositionFromCenter = frame->getOffset();
CCTexture2D *pNewTexture = frame->getTexture();
// update texture before updating texture rect
if (pNewTexture != self->m_pobTexture)
{
self->setTexture(pNewTexture);
}
// update rect
self->m_bRectRotated = frame->isRotated();
self->setTextureRect(frame->getRect(), self->m_bRectRotated, frame->getOriginalSize());
}
GameObject* ObjectManager::hooks::createWithKey(int object_id) {
GameObject* ret = nullptr;
if (ObjectManager::object_methods.count(object_id)) {
auto controller = ObjectManager::object_methods[object_id](object_id);
ret = controller->getObject();
} else {
auto texture = ObjectToolbox::sharedState()->intKeyToFrame(object_id);
if (!texture || strlen(texture) < 3) {
return nullptr;
}
if (object_id < 1008 && object_id > 748) {
ret = LabelGameObject::create(texture);
} else if (object_id <= 1819 && object_id > 1704) {
ret = LabelGameObject::create(texture);
} else switch (object_id) {
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 32:
case 33:
case 55:
case 56:
case 57:
case 58:
case 59:
case 105:
case 1268:
case 1342:
case 1343:
case 1344:
case 1346:
case 1347:
case 1585:
case 1587:
case 1589:
case 1595:
case 1598:
case 1611:
case 1612:
case 1613:
case 1614:
case 1616:
case 899:
case 900:
case 901:
case 913:
case 744:
case 1049:
case 1520:
ret = LabelGameObject::create(texture);
break;
case 36:
case 84:
case 141:
case 1022:
case 1330:
case 1333:
case 1594:
case 1704:
case 1751:
ret = RingObject::create(texture);
break;
case 1327:
case 1328:
case 1584:
ret = AnimatedGameObject::create(object_id);
break;
case 1615:
ret = RingObject::create();
break;
case 31:
ret = StartPosObject::create();
break;
case 747:
ret = TeleportPortalObject::create(texture);
break;
case 914: {
#if __APPLE__
int efont = GM->_editorFont();
#else
#pragma error implement this pls
#endif
auto font = cocos2d::CCTextureCache::sharedTextureCache()->addImage(GM->getFontTexture(efont), false);
ret = new GameObject;
if (!ret->initWithTexture(font)) {
delete ret;
return nullptr;
}
ret->autorelease();
break;
}
default:
ret = GameObject::createWithFrame(texture);
break;
}
}
if (ret) {
#if __APPLE__
ret->_id() = object_id;
#else
ret->m_nObjectID = object_id;
#endif
}
return ret;
}