Skip to content

Commit d1fa347

Browse files
committed
feat(save-data): Fix android crashing on mod launch
1 parent 15e119c commit d1fa347

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [3.0.1] - 2024-11-28
9+
10+
### Fixed
11+
12+
- Fixed Android crashing
13+
814
## [3.0.0-beta.1] - 2024-11-28
915

1016
### Changed

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"win": "2.2074",
55
"mac": "2.2074"
66
},
7-
"version": "v3.0.0-beta.1",
7+
"version": "v3.0.1",
88
"id": "spaghettdev.gd-roulette",
99
"name": "GD-Roulette",
1010
"developer": "SpaghettDev",

src/roulette/manager/DataManager.hpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,27 @@ namespace DataManager
2929
{
3030
namespace values
3131
{
32-
const std::unordered_map<DMArrayKey, std::string_view> ARRAY_KEY_TO_NAME{
33-
{ DMArrayKey::DIFFICULTY_ARRAY, "difficulty-array" },
34-
{ DMArrayKey::DEMON_DIFFICULTY_ARRAY, "demon-difficulty-array" },
35-
{ DMArrayKey::SELECTED_LIST_ARRAY, "selected-list-array" },
36-
};
32+
template <DMArrayKey key>
33+
std::string_view getKeyString()
34+
{
35+
if constexpr (key == DMArrayKey::DIFFICULTY_ARRAY)
36+
return "difficulty-array";
37+
else if constexpr (key == DMArrayKey::DEMON_DIFFICULTY_ARRAY)
38+
return "demon-difficulty-array";
39+
else if constexpr (key == DMArrayKey::SELECTED_LIST_ARRAY)
40+
return "selected-list-array";
41+
42+
std::unreachable();
43+
}
3744

38-
const std::unordered_map<DMMiscKey, std::string_view> MISC_KEY_TO_NAME{
39-
{ DMMiscKey::GD_LIST_ID, "gd-list-id" },
40-
};
45+
template <DMMiscKey key>
46+
std::string_view getKeyString()
47+
{
48+
if constexpr (key == DMMiscKey::GD_LIST_ID)
49+
return "gd-list-id";
50+
51+
std::unreachable();
52+
}
4153

4254
struct SavedArrayInfo
4355
{
@@ -180,7 +192,7 @@ namespace DataManager
180192
template <DMArrayKey key>
181193
void set(const std::vector<matjson::Value>& value)
182194
{
183-
geode::Mod::get()->setSavedValue(values::ARRAY_KEY_TO_NAME.at(key), value);
195+
geode::Mod::get()->setSavedValue(values::getKeyString<key>(), value);
184196
}
185197

186198
/**
@@ -194,7 +206,7 @@ namespace DataManager
194206
void set(std::size_t idx, bool value)
195207
{
196208
geode::Mod::get()->getSaveContainer().get(
197-
values::ARRAY_KEY_TO_NAME.at(key)
209+
values::getKeyString<key>()
198210
).unwrap().asArray().unwrap().at(idx) = value;
199211
}
200212

@@ -210,7 +222,7 @@ namespace DataManager
210222
if constexpr (key == DMMiscKey::SAVE_DATA)
211223
writeGameState(value);
212224
else
213-
geode::Mod::get()->setSavedValue(values::MISC_KEY_TO_NAME.at(key), value);
225+
geode::Mod::get()->setSavedValue(values::getKeyString<key>(), value);
214226
}
215227

216228

@@ -225,16 +237,16 @@ namespace DataManager
225237
{
226238
auto& container = geode::Mod::get()->getSaveContainer();
227239

228-
if (auto res = container.get(values::ARRAY_KEY_TO_NAME.at(key)); res.isOk())
240+
if (auto res = container.get(values::getKeyString<key>()); res.isOk())
229241
if (auto resv = res.unwrap().asArray(); resv.isOkAnd([](auto&& vec) {
230242
return vec.size() == values::ARRAY_TO_SAI.at(key).size &&
231243
std::all_of(vec.begin(), vec.end(), [](auto& v) { return v.asBool().isOk(); });
232244
}))
233245
return resv.unwrap();
234246

235-
container.set(values::ARRAY_KEY_TO_NAME.at(key), values::ARRAY_TO_SAI.at(key).default_value);
247+
container.set(values::getKeyString<key>(), values::ARRAY_TO_SAI.at(key).default_value);
236248

237-
return container.get(values::ARRAY_KEY_TO_NAME.at(key)).unwrap().asArray().unwrap();
249+
return container.get(values::getKeyString<key>()).unwrap().asArray().unwrap();
238250
}
239251

240252
/**
@@ -255,11 +267,11 @@ namespace DataManager
255267
{
256268
auto& container = geode::Mod::get()->getSaveContainer();
257269

258-
if (auto res = container.get(values::MISC_KEY_TO_NAME.at(key)); res.isOk())
259-
if (auto resv = res.unwrap().as<save_container_t>(); resv.isOk())
270+
if (auto res = container.get(values::getKeyString<key>()); res.isOk())
271+
if (auto resv = res.unwrap().template as<save_container_t>(); resv.isOk())
260272
return resv.unwrap();
261273

262-
container.set(values::MISC_KEY_TO_NAME.at(key), value_t{});
274+
container.set(values::getKeyString<key>(), value_t{});
263275

264276
return value_t{};
265277
}

src/roulette/manager/RouletteManager.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2+
23
#include <atomic>
3-
#include <matjson/stl_serialize.hpp>
44

55
#include <Geode/loader/Mod.hpp>
66
#include <Geode/Enums.hpp>
@@ -37,8 +37,6 @@ struct RouletteManager
3737
{
3838
if (!m_hasInitManager)
3939
{
40-
auto& saveContainer = Mod::get()->getSaveContainer();
41-
4240
static_cast<void>(DataManager::setDefaultSafe<DMArrayKey::DIFFICULTY_ARRAY>());
4341
static_cast<void>(DataManager::setDefaultSafe<DMArrayKey::DEMON_DIFFICULTY_ARRAY>());
4442
static_cast<void>(DataManager::setDefaultSafe<DMArrayKey::SELECTED_LIST_ARRAY>());

src/utils.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ namespace rl
202202

203203
~ScopedVar() { V = m_dtor_val; }
204204
};
205+
206+
template <typename T>
207+
bool verifyChecksum(const T& value, unsigned int checksum)
208+
{
209+
unsigned int sum = 0;
210+
211+
for (int i = 0; i < sizeof(T); i++)
212+
sum += reinterpret_cast<unsigned char*>(value)[i];
213+
214+
return sum == checksum;
215+
}
205216
}
206217

207218
namespace constants

0 commit comments

Comments
 (0)