Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
poweredbypie committed Oct 9, 2020
1 parent bdbbb71 commit 14dd540
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 46 deletions.
137 changes: 100 additions & 37 deletions src/classes/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void list::update() {

getLength();

if (m_displayedLength) {
if (m_displayedLength > 0) {
if (!m_entered) {
m_pArrListLabels[0] = label::create(m_listStrings[m_listOffset].c_str(), "bigFont.fnt");
node::setPos(m_pArrListLabels[0], m_x, m_y);
Expand Down Expand Up @@ -87,6 +87,43 @@ void list::exit() {
m_entered = false;
}

bool list::load(void* file) {
using namespace cocos::xml;

if (void* list = firstChildElement(file, m_titleStr)) {
if (queryAttribute(list, "offset", &m_listOffset))
return false;

for (void* i = firstChildElement(list, "entry"); i; i = nextSiblingElement(i, 0))
m_listStrings.push_back(getText(i));

if (m_maxDisplayedLength < (int)m_listStrings.size()) {
if (m_listOffset > (int)m_listStrings.size() - m_maxDisplayedLength)
m_listOffset = (int)m_listStrings.size() - m_maxDisplayedLength;
else if (m_listOffset < 0)
m_listOffset = 0;
}
else
m_listOffset = 0;

return true;
}
return false;
}

void list::save(void* file) {
using namespace cocos::xml;

void* list = newElement(file, m_titleStr);
setAttribute(list, "offset", m_listOffset);
insertEndChild(file, list);
for (std::string entry : m_listStrings) {
void* i = newElement(file, "entry");
insertEndChild(i, newText(file, entry.c_str()));
insertEndChild(list, i);
}
}

list::list(const char* title, int length) {
m_titleStr = title;

Expand Down Expand Up @@ -121,17 +158,8 @@ void list::removeIfNotFound(const std::vector<std::string>& other, bool isTarget
}
}
}

getLength();

//not tested, maybe do it later but the use case isnt functional in this instance
if (!m_listStrings.empty()) {
if (m_listOffset > (int)m_listStrings.size() - 1)
m_listOffset = (int)m_listStrings.size() - 1;
}
else {
m_listOffset = 0;
}
m_listOffset = 0;

update();
}
Expand Down Expand Up @@ -168,7 +196,7 @@ void listExt::navigate(bool up) {
--m_listOffset;
}
else {
if (m_moveIndex < m_displayedLength - 1)
if (m_moveIndex + 1 < m_displayedLength)
++m_moveIndex;
else if (m_listOffset < (int)m_listStrings.size() - m_maxDisplayedLength)
++m_listOffset;
Expand All @@ -185,7 +213,7 @@ void listExt::swap(bool up) {
}
}
else {
if (m_moveIndex < m_displayedLength - 1) {
if (m_moveIndex + 1 < m_displayedLength) {
std::iter_swap(m_listStrings.begin() + m_moveIndex + m_listOffset, m_listStrings.begin() + m_moveIndex + m_listOffset + 1);
++m_moveIndex;
}
Expand All @@ -198,8 +226,13 @@ void listExt::move() {
m_target->m_listStrings.insert(m_target->m_listStrings.begin(), m_listStrings[m_moveIndex + m_listOffset]);
m_listStrings.erase(m_listStrings.begin() + m_moveIndex + m_listOffset);

//moves the selector up if the index is the bottom one, so that "vector out of range" doesn't occur
if (m_listStrings.size() - m_listOffset == m_moveIndex && m_listStrings.size() - m_listOffset != 0)
getLength();

if ((int)m_listStrings.size() >= m_maxDisplayedLength &&
m_displayedLength < m_maxDisplayedLength)
--m_listOffset;
else if (m_displayedLength < m_moveIndex + 1 &&
m_displayedLength > 0)
--m_moveIndex;

update();
Expand Down Expand Up @@ -294,7 +327,6 @@ void listExt::updateSelector() {
node::setPos(m_swapDownBtn, m_x - 55.0f, m_y - 5.0f - 20.0f * m_moveIndex);
toggle(m_swapUpBtn, true);
toggle(m_swapDownBtn, true);

}
else {
node::setPos(m_moveBtn, m_x - 55.0f, m_y - 20.0f * m_moveIndex);
Expand Down Expand Up @@ -349,6 +381,52 @@ void listExt::exit() {
m_entered = false;
}

bool listExt::load(void* file) {
using namespace cocos::xml;

if (void* list = firstChildElement(file, m_titleStr)) {
if (queryAttribute(list, "offset", &m_listOffset) ||
queryAttribute(list, "index", &m_moveIndex))
return false;

for (void* i = firstChildElement(list, "entry"); i; i = nextSiblingElement(i, 0))
m_listStrings.push_back(getText(i));

if (m_maxDisplayedLength < (int)m_listStrings.size()) {
if (m_listOffset > (int)m_listStrings.size() - m_maxDisplayedLength)
m_listOffset = (int)m_listStrings.size() - m_maxDisplayedLength;
else if (m_listOffset < 0)
m_listOffset = 0;
}
else
m_listOffset = 0;

getLength();

if (m_moveIndex > m_displayedLength - 1)
m_moveIndex = m_displayedLength - 1;
else if (m_moveIndex < 0)
m_moveIndex = 0;

return true;
}
return false;
}

void listExt::save(void* file) {
using namespace cocos::xml;

void* list = newElement(file, m_titleStr);
setAttribute(list, "offset", m_listOffset);
setAttribute(list, "index", m_moveIndex);
insertEndChild(file, list);
for (std::string entry : m_listStrings) {
void* i = newElement(file, "entry");
insertEndChild(i, newText(file, entry.c_str()));
insertEndChild(list, i);
}
}

listExt::listExt(const char* title, int length, listExt* target) : list(title, length) {
m_moveFn = listManager::move;
m_swapFn = listManager::swap;
Expand All @@ -375,15 +453,10 @@ void listExt::removeIfNotFound(const std::vector<std::string>& other, bool isTar
}
}

getLength();

//make this better. if you move more than 10 items, it'll look weird. i dont think it breaks, but it just isn't very clean.
if (m_moveIndex + 1 > m_displayedLength) {
if (m_displayedLength > 1)
m_moveIndex = m_displayedLength - 1;
else
m_moveIndex = 0;
}
/*move to the start of the list, since you're probably going to refresh to
add new packs which will be added at the top*/
m_listOffset = 0;
m_moveIndex = 0;

update();
}
Expand Down Expand Up @@ -469,11 +542,7 @@ bool listManager::load() {
else
saveFile(m_saveFile, m_backupPath, false);
for (list* i : m_vec) {
if (void* node = firstChildElement(m_saveFile, i->m_titleStr)) {
for (void* element = firstChildElement(node, 0); element; element = nextSiblingElement(element, 0))
i->m_listStrings.push_back(getText(element));
}
else
if (!i->load(m_saveFile))
return false;
}
return true;
Expand All @@ -485,13 +554,7 @@ bool listManager::save() {
deleteChildren(m_saveFile);

for (list* i : m_vec) {
void* node = newElement(m_saveFile, i->m_titleStr);
insertEndChild(m_saveFile, node);
for (std::string pack : i->m_listStrings) {
void* element = newElement(m_saveFile, "pack");
insertEndChild(element, newText(m_saveFile, pack.c_str()));
insertEndChild(node, element);
}
i->save(m_saveFile);
}

if (!saveFile(m_saveFile, m_filePath, false))
Expand Down
6 changes: 6 additions & 0 deletions src/classes/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class list {
virtual void enter(void* scene);
virtual void exit();

virtual bool load(void* file);
virtual void save(void* file);

public:
list(const char* title, int length);
void setVector(const std::vector<std::string>& vec);
Expand Down Expand Up @@ -84,6 +87,9 @@ class listExt : public list {
virtual void enter(void* scene);
virtual void exit();

virtual bool load(void* file);
virtual void save(void* file);

public:
listExt(const char* title, int length, listExt* target);
virtual void removeIfNotFound(const std::vector<std::string>& other, bool isTarget);
Expand Down
4 changes: 4 additions & 0 deletions src/extern/cocos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace cocos {
void* (__thiscall* insertFirstChild)(void* XMLNode, void* addThis);
const char* (__thiscall* getText)(void* XMLElement);
void(__thiscall* setValue)(void* XMLElement, const char* str, bool staticMem);
void(__thiscall* setAttribute)(void* XMLElement, const char* name, int value);
int(__thiscall* queryAttribute)(void* XMLElement, const char* name, int* value);

void* create(bool processEntities, int whitespaceMode) {
//dont want to deal with tinyxml dependencies, so this will do
Expand All @@ -134,6 +136,8 @@ namespace cocos {
fcnPtrInfo.push_back({ (void*&)insertEndChild, "?InsertEndChild@XMLNode@tinyxml2@@QAEPAV12@PAV12@@Z" });
fcnPtrInfo.push_back({ (void*&)insertFirstChild, "?InsertFirstChild@XMLNode@tinyxml2@@QAEPAV12@PAV12@@Z" });
fcnPtrInfo.push_back({ (void*&)setValue, "?SetValue@XMLNode@tinyxml2@@QAEXPBD_N@Z" });
fcnPtrInfo.push_back({ (void*&)setAttribute, "?SetAttribute@XMLElement@tinyxml2@@QAEXPBDH@Z" });
fcnPtrInfo.push_back({ (void*&)queryAttribute, "?QueryIntAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAH@Z" });
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/extern/cocos.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace cocos {
extern void* (__thiscall* insertFirstChild)(void* XMLNode, void* addThis);
extern const char* (__thiscall* getText)(void* XMLElement);
extern void(__thiscall* setValue)(void* XMLElement, const char* str, bool staticMem);
extern void(__thiscall* setAttribute)(void* XMLElement, const char* name, int value);
extern int(__thiscall* queryAttribute)(void* XMLElement, const char* name, int* value);

void* create(bool processEntities, int whitespaceMode);
}
Expand Down
6 changes: 3 additions & 3 deletions src/extern/gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ namespace gd {
}
}
namespace gamemanager {
int* ptr;

int(__thiscall* reloadAll)(void* GameManager, bool bSwitch, bool bFullscreen, bool bReloadedInSession);

void* get() {
return *(void**)((char*)hmodule + 0x3222D0);
}
void addTo() {
fcnPtrInfo.push_back({ (void*&)reloadAll, 0xCE950 });
}
Expand Down Expand Up @@ -55,7 +56,6 @@ namespace gd {

//get offsets
hmodule = GetModuleHandle(0);
gamemanager::ptr = *(int**)((char*)hmodule + 0x3222D0);
menuLayer::pMoreGamesStr = (void**)((char*)hmodule + 0x190EF2);
menuLayer::szMoreGamesBtn = (void**)((char*)hmodule + 0x190F01);
menuLayer::pcbMoreGames = (void**)((char*)hmodule + 0x190F13);
Expand Down
4 changes: 2 additions & 2 deletions src/extern/gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace gd {
extern void(__thiscall* trySaveGame)(void* AppDelegate);
}
namespace gamemanager {
extern int* ptr;

extern int(__thiscall* reloadAll)(void* GameManager, bool bSwitch, bool bFullscreen, bool bReloadedInSession);

void* get();
}
namespace menuLayer {
extern void** pMoreGamesStr;
Expand Down
8 changes: 4 additions & 4 deletions src/ldr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ namespace ldr {

void* director = director::get();
director::updateScale(director, quality.getCurrentIndex() + 1);
*(gd::gamemanager::ptr + 0xB8) = quality.getCurrentIndex() + 1;
gamemanager::reloadAll(gd::gamemanager::ptr, 0, 0, 1);
*((char*)gd::gamemanager::get() + 0x2E0) = quality.getCurrentIndex() + 1;
gamemanager::reloadAll(gd::gamemanager::get(), 0, 0, 1);
}

bool init() {
Expand All @@ -166,8 +166,8 @@ namespace ldr {
quality.setVector({ "Low", "Medium", "High" });
}
quality.setPosition(0.0f, -130.0f);
all.setPosition(-90.0f, 95.0f);
applied.setPosition(90.0f, 95.0f);
all.setPosition(-120.0f, 95.0f);
applied.setPosition(120.0f, 95.0f);

return true;
}
Expand Down

0 comments on commit 14dd540

Please sign in to comment.