Skip to content

Commit

Permalink
Update to 1.2.0. Full changelog in CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettDev committed Dec 7, 2023
1 parent 9147eb9 commit 3ef4aa8
Show file tree
Hide file tree
Showing 25 changed files with 763 additions and 422 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GD-Roulette Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.0] - 2023-12-06

### Added
- Added a json manager (to save options)
- Added a percentage goal besides the LevelInfoLayer percentage text
- Added a percentage goal in the PauseLayer

### Changed

- Separated the layers contained in the RouletteLayer.cpp file into sub-files

### Fixed

- Fixed RouletteManager not managing data correctly after JSON saving was added
- Fixed demonDiffArr resetting everything to false when RouletteLayer::onClose is called

## [1.1.7] - 2023-10-29

### Added
- Added a DEV_CONSOLE macro enabled only when compiling RelWithDebInfo
- Added a check for MegaHack v7 to change the roulette button's position

<!-- maybe add the other versions here too -->
2 changes: 1 addition & 1 deletion src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace
HANDLE mainThread;
DWORD threadID;

std::string_view version = "1.1.7";
std::string_view version = "1.2.0";
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "layers/CreatorLayer.hpp"
#include "layers/LevelInfoLayer.hpp"
#include "layers/PlayLayer.hpp"
#include "layers/PauseLayer.hpp"
#include "json_manager/JsonManager.hpp"

#include "utils.hpp"

Expand Down Expand Up @@ -31,6 +33,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
#endif

MH_Initialize();
JsonManager();

Sleep(utils::randomInt(250, 1000));

Expand Down Expand Up @@ -61,11 +64,20 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
reinterpret_cast<void**>(&PlayLayer::levelComplete)
);

MH_CreateHook(
reinterpret_cast<void*>(gd::base + 0x175DF0), LevelInfoLayer::initHook,
reinterpret_cast<void**>(&LevelInfoLayer::init)
);
MH_CreateHook(
reinterpret_cast<void*>(gd::base + 0x17C110), LevelInfoLayer::onBackHook,
reinterpret_cast<void**>(&LevelInfoLayer::onBack)
);

MH_CreateHook(
reinterpret_cast<void*>(gd::base + 0x1E4570), PauseLayer::createHook,
reinterpret_cast<void**>(&PauseLayer::create)
);


MH_EnableHook(MH_ALL_HOOKS);

Expand Down
64 changes: 64 additions & 0 deletions src/json_manager/JsonManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "JsonManager.hpp"
#define DECLAREROULETTEMANAGER
#include "../roulette/manager/RouletteManager.hpp"

nlohmann::ordered_json JsonManager::m_default_savedata;
nlohmann::ordered_json JsonManager::m_savedata;

// maybe change to saving the std::array instead of its elements individually

JsonManager::JsonManager()
{
m_default_savedata["normalList"] = static_cast<bool>(RouletteManager.selectedListArr[0]);
m_default_savedata["demonList"] = static_cast<bool>(RouletteManager.selectedListArr[1]);
m_default_savedata["challengeList"] = static_cast<bool>(RouletteManager.selectedListArr[2]);
m_default_savedata["maxSkips"] = static_cast<int>(RouletteManager.maxSkips);

if (!std::filesystem::exists(m_savefile))
{
if (!std::filesystem::exists(m_savefile_directory))
std::filesystem::create_directory(m_savefile_directory);

std::ofstream file(m_savefile, std::ios::out | std::ios::trunc);
file << m_default_savedata.dump(4);
file.close();

m_savedata.update(m_default_savedata);
}

std::ifstream file(m_savefile);
try
{
file >> m_savedata;

if (m_savedata["normalList"].get<bool>() == m_savedata["demonList"].get<bool>() == m_savedata["challengeList"].get<bool>() == false)
m_savedata["normalList"] = true;

RouletteManager.selectedListArr[0].assignNoSave(m_savedata["normalList"]);
RouletteManager.selectedListArr[1].assignNoSave(m_savedata["demonList"]);
RouletteManager.selectedListArr[2].assignNoSave(m_savedata["challengeList"]);
RouletteManager.maxSkips.assignNoSave(m_savedata["maxSkips"]);
}
catch (...)
{
file.close();
RouletteManager.isJsonCorrupted = true;
std::ofstream openedFile(m_savefile, std::ios::out | std::ios::trunc);
openedFile << m_default_savedata.dump(4);
openedFile.close();
}

file.close();
}

void JsonManager::save()
{
m_savedata["normalList"] = static_cast<bool>(RouletteManager.selectedListArr[0]);
m_savedata["demonList"] = static_cast<bool>(RouletteManager.selectedListArr[1]);
m_savedata["challengeList"] = static_cast<bool>(RouletteManager.selectedListArr[2]);
m_savedata["maxSkips"] = static_cast<int>(RouletteManager.maxSkips);

std::ofstream file(m_savefile, std::ios::out | std::ios::trunc);
file << m_savedata.dump(4);
file.close();
}
19 changes: 19 additions & 0 deletions src/json_manager/JsonManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "../pch.hpp"
#include <nlohmann/json.hpp>

class JsonManager
{
public:
JsonManager();
~JsonManager() = default;

static void save();

private:
inline static std::filesystem::path m_savefile_directory = std::filesystem::path(std::getenv("appdata")) / "GD-Roulette";
inline static std::filesystem::path m_savefile = m_savefile_directory / "options.json";

static nlohmann::ordered_json m_default_savedata;
static nlohmann::ordered_json m_savedata;
};
48 changes: 48 additions & 0 deletions src/json_manager/WriteInvokingType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
#include "../pch.hpp"
#include "JsonManager.hpp"

// this class just writes the savedata after each assignment
// because 1: there is no main loop
// and 2: there aren't that many options to save, so i cba'd to hook the render loop or similar
template<typename T>
class WriteInvoking
{
public:
WriteInvoking<T>& operator=(const T& t)
{
m_data = t;

JsonManager::save();

return *this;
}

constexpr bool operator==(const T t)
{
return t == m_data;
}

constexpr operator T()
{
return m_data;
}

WriteInvoking(T t)
: m_data(t) {}

WriteInvoking()
: m_data{} {}

void assignNoSave(T t)
{
m_data = t;
}

private:
T m_data;
};

template<typename T, std::size_t S>
class WriteInvoking<std::array<T, S>> : public std::array<WriteInvoking<T>, S>
{};
12 changes: 11 additions & 1 deletion src/layers/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ class ButtonsClass final : public gd::FLAlertLayer, public CCTextFieldDelegate,
if (!RouletteManager.rouletteResourcesFound)
{
FLAlertLayer::create(
nullptr, "Resources", "Ok", nullptr,
nullptr, "Resources", "OK", nullptr,
"The <cg>roulette's resources</c> were not loaded.\nThis may be due to an <cr>incorrect installation</c>.\nPlease check the Github for more information."
)->show();
RouletteManager.rouletteResourcesFound = true;
}

if (RouletteManager.isJsonCorrupted)
{
FLAlertLayer::create(
nullptr, "JSON file", "OK", nullptr,
"The <cg>roulette's save file</c> was corrupted.\nAs such, the options have been <cr>reset to their default values</c>."
)->show();

RouletteManager.isJsonCorrupted = false;
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/layers/CreatorLayer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../pch.hpp"
#include "../roulette/layer/RouletteLayer.hpp"
#include "../roulette/layers/RouletteLayer.hpp"

namespace CreatorLayer
{
Expand Down
75 changes: 75 additions & 0 deletions src/layers/CustomLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "CustomLayer.hpp"

bool CustomLayer::createBasics(CCPoint contentSize, SEL_MenuHandler onClose, float closeBtnScale, const ccColor4B& color)
{
if (!CCLayerColor::initWithColor(color)) return false;

alertSize = contentSize;

CCDirector* director = CCDirector::sharedDirector();
director->getTouchDispatcher()->incrementForcePrio(2);

setTouchEnabled(true);
setKeypadEnabled(true);

m_pLayer = CCLayer::create();

this->addChild(m_pLayer);

CCSize winSize = director->getWinSize();
extension::CCScale9Sprite* bg = extension::CCScale9Sprite::create("GJ_square01.png", { .0f, .0f, 80.0f, 80.0f });
bg->setContentSize(alertSize);
m_pLayer->addChild(bg, -1);
bg->setPosition({ winSize.width / 2, winSize.height / 2 });

m_pButtonMenu = CCMenu::create();
m_pLayer->addChild(m_pButtonMenu, 10);

closeBtn = createButton("GJ_closeBtn_001.png", { -((alertSize.x) / 2) + 9.5f, (alertSize.y / 2) - 10 }, onClose, -1, closeBtnScale);

return true;
}

void CustomLayer::createTitle(std::string text, float separatorScale, float usernameScale)
{
auto userName = CCLabelBMFont::create(text.c_str(), "bigFont.fnt");
userName->setPosition({ 0, (alertSize.y / 2) - 22 });
userName->setScale(usernameScale);
m_pButtonMenu->addChild(userName);

auto separator = CCSprite::createWithSpriteFrameName("floorLine_001.png");
separator->setPosition({ 0, (alertSize.y / 2) - 46 });
separator->setScaleX(separatorScale);
separator->setOpacity(100);
m_pButtonMenu->addChild(separator);
}

gd::CCMenuItemSpriteExtra* CustomLayer::createButton(const char* texture, CCPoint position, SEL_MenuHandler callback, int tag, float textureScale, float sizeMult)
{
auto buttonSprite = CCSprite::createWithSpriteFrameName(texture);
buttonSprite->setScale(textureScale);
auto button = gd::CCMenuItemSpriteExtra::create(
buttonSprite,
this,
callback
);
button->setPosition(position);
button->setSizeMult(sizeMult);
if (tag != -1)
button->setTag(tag);
m_pButtonMenu->addChild(button);

return button;
}

// overriden because clicking space crashes the game
void CustomLayer::keyDown(enumKeyCodes key)
{
if (key == enumKeyCodes::KEY_Escape)
onClose(nullptr);
}

void CustomLayer::keyBackClicked()
{
onClose(nullptr);
}
16 changes: 16 additions & 0 deletions src/layers/CustomLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "../pch.hpp"

class CustomLayer : public gd::FLAlertLayer
{
public:
CCPoint alertSize{};
gd::CCMenuItemSpriteExtra* closeBtn{};

bool createBasics(CCPoint, SEL_MenuHandler, float = 1, const ccColor4B & = { 0x00, 0x00, 0x00, 0x4B });
void createTitle(std::string, float = .75f, float = 1);
gd::CCMenuItemSpriteExtra* createButton(const char*, CCPoint, SEL_MenuHandler, int = -1, float = 1.0f, float = 1.2f);
virtual void onClose(CCObject*) = 0;
void keyDown(enumKeyCodes);
void keyBackClicked();
};
Loading

0 comments on commit 3ef4aa8

Please sign in to comment.