-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed.cpp
213 lines (176 loc) · 6.22 KB
/
speed.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
#include <Cacao.hpp>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
template <typename T>
std::string to_string(T val)
{
std::stringstream stream;
stream << val;
return stream.str();
}
using namespace cocos2d;
namespace CocoXIB {
template <typename T, typename F>
void renderCustomUI(T self, F mainLayer);
}
ModContainer* m;
#define DREF(exp) (*((uint64_t*)(exp)))
class SetupSpeedPopup : public FLAlertLayer {
public:
SetupSpeedPopup() :
FLAlertLayer() {
m_controlConnected = -1;
m_joystickConnected = -1;
m_ZOrder = 0;
m_noElasticity = true;
m_touchT = nullptr;
m_spawnT = nullptr;
m_effectObject = nullptr;
}
static SetupSpeedPopup* create(EffectGameObject* ego) {
SetupSpeedPopup* ret = new SetupSpeedPopup();
uint64_t ok1 = *((uint64_t*)ret);
uint64_t ok2 = DREF(ok1-8)+16;
uint64_t n_typinfo = getBase()+0x65d870;
MemoryContainer(ok2, 8, reinterpret_cast<char*>(&n_typinfo)).enable();
if (ret && ret->init(ego)) {
ret->m_scene = NULL;
ret->autorelease();
} else {
CC_SAFE_DELETE(ret);
}
return ret;
}
void onClose(CCObject* callback) {
auto speed = std::strtod(m_mainInput->getString_s(), nullptr);
m_effectObject->_spawnDelay() = speed;
m_helper->keyBackClicked();
setKeypadEnabled(false);
setTouchEnabled(false);
removeFromParentAndCleanup(true);
}
virtual void keyBackClicked() {
onClose(NULL);
}
void onTouch(CCObject*) {m_effectObject->_touchTriggered() = !m_effectObject->_touchTriggered();}
void onSpawn(CCObject*) {m_effectObject->_spawnTriggered() = !m_effectObject->_spawnTriggered();}
void restoreDefaults() {
std::string s = to_string(m_effectObject->_spawnDelay());
if (s.length()>0 && m_effectObject->_spawnDelay() != 0.0f)
m_mainInput->setString(s);
if (m_touchT && m_spawnT) {
m_touchT->toggle(m_effectObject->_touchTriggered());
m_spawnT->toggle(m_effectObject->_spawnTriggered());
}
}
bool init(EffectGameObject* ego) {
if (CCLayerColor::initWithColor(ccc4(0,0,0,150))) {
m_effectObject = ego;
m_helper = FLAlertLayer::create("","","");
m_helper->m_buttonMenu->setVisible(false);
m_helper->m_noElasticity = true;
m_helper->show();
registerWithTouchDispatcher();
CCDirector::sharedDirector()->getTouchDispatcher()->incrementForcePrio(2);
setTouchEnabled(true);
setKeypadEnabled(true);
m_mainLayer = CCLayer::create();
addChild(m_mainLayer);
//CCLayerColor* mycolor = CCLayerColor::create(ccc4(0,0,0,150), getContentSize().width, getContentSize().height);
//m_mainLayer->addChild(mycolor, -3);
auto scale9 = extension::CCScale9Sprite::create("GJ_square01.png");
scale9->setContentSize(CCSizeMake(300, 280));
scale9->setPosition(Cacao::relativePosition(50,50));
m_mainLayer->addChild(scale9, -2);
CocoXIB::renderCustomUI(this, m_mainLayer);
restoreDefaults();
}
return true;
}
protected:
template <typename T, typename F>
friend void CocoXIB::renderCustomUI(T, F);
EffectGameObject* m_effectObject;
CCTextInputNode* m_mainInput;
FLAlertLayer* m_helper;
CCMenuItemToggler* m_touchT;
CCMenuItemToggler* m_spawnT;
};
#include "cocoxib.h"
std::string mySaveString(EffectGameObject* ego) {
std::string out = ORIG(mySaveString, 0xcd7e0)(ego);
if (ego->_id()==3142 && ego->_spawnDelay() > 0) {
out += ",63," + to_string(ego->_spawnDelay());
}
std::cout << out << "\n\n";
return out;
}
bool g_lock;
std::string myGSaveString(EffectGameObject* ego) {
if (ego->_id()==3142) {
if (!g_lock) {
g_lock = true;
return mySaveString(ego);
}
g_lock = false;
}
return ORIG(myGSaveString, 0x33d3d0)(ego);
}
GameObject* obFromString(std::string st, bool idk) {
auto go = ORIG(obFromString, 0x33b720)(st, idk);
printf("%p ob id %d\n", go, go ? go->_id() : -1);
auto mymap = GameToolbox::stringSetupToMap(st, ",");
if (go && go->_id() == 3142) {
auto ego = reinterpret_cast<EffectGameObject*>(go);
for (auto const& pair: mymap) {
std::cout << "{" << pair.first << ": " << pair.second << "}\n";
}
if (mymap.count("63")) {
ego->_spawnDelay() = std::strtod(mymap["63"].c_str(), nullptr);
}
if (mymap.count("11") && mymap["11"]=="1") {
ego->_touchTriggered() = true;
}
if (mymap.count("62") && mymap["62"]=="1") {
ego->_spawnTriggered() = true;
}
}
return go;
}
void inject() {
g_lock = false;
setupTypeinfos();
m = new ModContainer("Swag");
auto editor = Cacao::EditorUIEditor::create(m);
constexpr int myObjectID = 3142;
Cacao::addGDObject("checkpoint_01_001.png", myObjectID);
editor
->bar(11)
->addIndex(12, myObjectID)
->addObjectsToGameSheet02(myObjectID)
->addEffectObjects(myObjectID);
editor->addTriggerCallback(myObjectID, +[](GameObject* self, GJBaseGameLayer* gameLayer) {
double newsp = (double)(reinterpret_cast<EffectGameObject*>(self)->_spawnDelay());
double multiplier = 5.7700018882751465;
gameLayer->_player1()->_speed() = newsp * multiplier;
});
editor->applyAll();
void(*lam)(EditorUI*) = +[](EditorUI* self) {
auto obs = self->getSelectedObjects();
if (obs->count() == 1) {
auto o = reinterpret_cast<EffectGameObject*>(obs->objectAtIndex(0));
if (o->_id() == 3142) {
SetupSpeedPopup::create(o)->show();
return;
}
}
ORIG(*lam, 0x195a0)(self);
};
m->registerHook(getBase()+0x195a0, lam);
m->registerHook(getBase()+0xcd7e0, mySaveString);
m->registerHook(getBase()+0x33b720, obFromString);
m->registerHook(getBase()+0x33d3d0, myGSaveString);
m->enable();
}