Skip to content

Commit

Permalink
fix(crash), update: Fixed integer input crash on Android, no longer t…
Browse files Browse the repository at this point in the history
…arget Android.

Because it keeps crashing for no reason
  • Loading branch information
SpaghettDev committed Nov 28, 2024
1 parent 7137ec7 commit 15e119c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 53 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- name: macOS
os: macos-latest

- name: Android32
os: ubuntu-latest
target: Android32
# - name: Android32
# os: ubuntu-latest
# target: Android32

- name: Android64
os: ubuntu-latest
target: Android64
# - name: Android64
# os: ubuntu-latest
# target: Android64

name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ 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/).

## [3.0.0-beta.1] - 2024-11-28

### Changed

- Target Windows and Mac only, until I find a fix for Android later
- Renamed GD List ID key to "gd-list-id"

### Fixed

- Integer input layer crash on android

## [3.0.0] - 2024-11-24

### Added
Expand Down
3 changes: 1 addition & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"geode": "4.0.1",
"gd": {
"win": "2.2074",
"android": "2.2074",
"mac": "2.2074"
},
"version": "v3.0.0",
"version": "v3.0.0-beta.1",
"id": "spaghettdev.gd-roulette",
"name": "GD-Roulette",
"developer": "SpaghettDev",
Expand Down
6 changes: 3 additions & 3 deletions src/custom_layers/RLIntegerInputLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void RLIntegerInputLayer::onClose(CCObject*)
{
try
{
m_integer = std::stoi(input_node->getString());
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value);
}
catch (...)
{
Expand All @@ -117,7 +117,7 @@ void RLIntegerInputLayer::onLeftButton(CCObject*)
{
try
{
m_integer = std::stoi(input_node->getString()) - 1;
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value) - 1;
}
catch (...)
{
Expand All @@ -135,7 +135,7 @@ void RLIntegerInputLayer::onRightButton(CCObject*)
{
try
{
m_integer = std::stoi(input_node->getString()) + 1;
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value) + 1;
}
catch (...)
{
Expand Down
90 changes: 49 additions & 41 deletions src/roulette/manager/DataManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace DataManager
};

const std::unordered_map<DMMiscKey, std::string_view> MISC_KEY_TO_NAME{
{ DMMiscKey::GD_LIST_ID, "gdListID" },
{ DMMiscKey::GD_LIST_ID, "gd-list-id" },
};

struct SavedArrayInfo
Expand All @@ -56,6 +56,52 @@ namespace DataManager
};
}

namespace
{
const auto saveDataPath = geode::Mod::get()->getSaveDir() / "save_data";

GameState readGameState()
{
GameState fromDisk;
std::ifstream saveDataFile(saveDataPath, std::ios::binary);
saveDataFile.read(reinterpret_cast<char*>(&fromDisk), sizeof(GameState));

// TODO: Add checksum and integrity check here or something

return fromDisk;
}

GameState writeGameStateSafe(bool force_clean = false)
{
std::ifstream saveDataFileIn(saveDataPath, std::ios::binary);
saveDataFileIn.seekg(0, std::ios::end);

if (force_clean || saveDataFileIn.fail() || saveDataFileIn.tellg() != sizeof(GameState))
{
GameState defaultValue;

std::ofstream saveDataFileOut(saveDataPath, std::ios::binary);
saveDataFileOut.write(reinterpret_cast<char*>(&defaultValue), sizeof(GameState));

return defaultValue;
}

GameState fromDisk;
saveDataFileIn.seekg(0);
saveDataFileIn.read(reinterpret_cast<char*>(&fromDisk), sizeof(GameState));

return fromDisk;
}

void writeGameState(const GameState& value)
{
std::ofstream(saveDataPath, std::ios::binary).write(
reinterpret_cast<const char*>(&value),
sizeof(GameState)
);
}
}

namespace traits
{
template <DMMiscKey K>
Expand Down Expand Up @@ -122,17 +168,6 @@ namespace DataManager
template <DMMiscKey key>
[[nodiscard]] traits::KeyTrait<key>::type get()
{
using value_t = typename traits::KeyTrait<key>::type;

if constexpr (key == DMMiscKey::SAVE_DATA)
{
value_t fromDisk;
std::ifstream saveDataFile(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
saveDataFile.read(reinterpret_cast<char*>(&fromDisk), sizeof(value_t));

return fromDisk;
}

return setDefaultSafe<key>();
}

Expand Down Expand Up @@ -173,17 +208,9 @@ namespace DataManager
void set(const typename traits::KeyTrait<key>::type& value)
{
if constexpr (key == DMMiscKey::SAVE_DATA)
{
std::ofstream saveDataFile(geode::Mod::get()->getSaveDir() / "save_data");
saveDataFile.write(
reinterpret_cast<const char*>(&value),
sizeof(typename traits::KeyTrait<key>::type)
);
}
writeGameState(value);
else
{
geode::Mod::get()->setSavedValue(values::MISC_KEY_TO_NAME.at(key), value);
}
}


Expand Down Expand Up @@ -223,26 +250,7 @@ namespace DataManager
using save_container_t = std::conditional_t<std::is_same_v<value_t, int>, uint64_t, value_t>;

if constexpr (key == DMMiscKey::SAVE_DATA)
{
std::ifstream saveDataFileIn(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
saveDataFileIn.seekg(0, std::ios::end);

if (saveDataFileIn.fail() || saveDataFileIn.tellg() != sizeof(value_t))
{
value_t defaultValue;

std::ofstream saveDataFileOut(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
saveDataFileOut.write(reinterpret_cast<char*>(&defaultValue), sizeof(value_t));

return defaultValue;
}

value_t fromDisk;
saveDataFileIn.seekg(0);
saveDataFileIn.read(reinterpret_cast<char*>(&fromDisk), sizeof(value_t));

return fromDisk;
}
return writeGameStateSafe();
else
{
auto& container = geode::Mod::get()->getSaveContainer();
Expand Down
4 changes: 3 additions & 1 deletion src/roulette/manager/GameState.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once

static_assert(true); // clangd bug fix

#pragma pack(push, 1)
struct GameState
{
int levelID = 0;
int levelID = 0;
int skipsUsed = 0;
int numLevels = 0;
int levelPercentage = 0;
Expand Down

0 comments on commit 15e119c

Please sign in to comment.