Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
Fix crashing when items don't make sense
Fix trials not giving you items
Fix tasks taking extra time for no reason
  • Loading branch information
MunWolf committed Nov 25, 2023
1 parent 4301b19 commit ae82db8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.17.3 FATAL_ERROR)
project(temp)

set(CMAKE_SUPPRESS_REGENERATION true)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
2 changes: 1 addition & 1 deletion projects/Core/events/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace core::events {
++it;
}

tasks.insert(it.base(), Task{ timer + seconds, task });
tasks.insert(it.base(), Task{ seconds, task });
}
}

Expand Down
15 changes: 8 additions & 7 deletions projects/Randomizer/game/event_handlers/on_trial.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include <randomizer.h>

#include <Modloader/app/methods/RaceHandler.h>
#include <Modloader/interception_macros.h>
#include <Modloader/app/methods/RaceBaseState.h>
#include <Modloader/app/methods/RaceSystem.h>
#include <Modloader/app/types/RaceSystem.h>

bool is_in_trial = false;

namespace {
IL2CPP_INTERCEPT(RaceHandler, void, SetRaceInProgressState, (app::RaceHandler * this_ptr, bool in_progress)) {
is_in_trial = in_progress;
randomizer::game_seed().prevent_grants(is_in_trial);
next::RaceHandler::SetRaceInProgressState(this_ptr, in_progress);
}
auto on_ready = modloader::event_bus().register_handler(ModloaderEvent::GameReady, [](auto) {
randomizer::game_seed().prevent_grants([]() {
return RaceSystem::get_IsRunningRace(types::RaceSystem::get_class()->static_fields->_Instance_k__BackingField);
});
});
} // namespace
5 changes: 2 additions & 3 deletions projects/Randomizer/seed/legacy_parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ namespace randomizer::seed::legacy_parser {
return true;
}

ItemData parse_action(const std::string_view action) {
std::optional<ItemData> parse_action(const std::string_view action) {
Seed::Data data;
const location_type location{
{ },
Expand All @@ -1991,7 +1991,6 @@ namespace randomizer::seed::legacy_parser {
.should_add_default_messages = parts.back() != "mute"
};

parse_action(location, parts, parser_data);
return location_data;
return parse_action(location, parts, parser_data) ? std::optional(location_data) : std::nullopt;
}
} // namespace randomizer::seed::legacy_parser
2 changes: 1 addition & 1 deletion projects/Randomizer/seed/legacy_parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

namespace randomizer::seed::legacy_parser {
bool parse(std::string_view path, location_data::LocationCollection const& location_data, Seed::Data& data);
ItemData parse_action(std::string_view action);
std::optional<ItemData> parse_action(std::string_view action);
} // namespace randomizer::seed::legacy_parser
8 changes: 7 additions & 1 deletion projects/Randomizer/seed/seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ namespace randomizer::seed {
}

void Seed::grant(const location_entry location, const double previous_value) {
if (m_should_prevent_grants || !core::api::game::in_game()) {
if (!core::api::game::in_game()) {
return;
}

for (auto callback : m_prevent_grant_callbacks) {
if (callback()) {
return;
}
}

if (m_skip.contains(location)) {
m_skip.erase(location);
return;
Expand Down
5 changes: 3 additions & 2 deletions projects/Randomizer/seed/seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ namespace randomizer::seed {
SeedInfo const& info() const { return m_data.info; }
int total_pickups() const { return m_data.info.total_pickups; }

void prevent_grants(bool value) { m_should_prevent_grants = value; }
std::string path() const { return m_last_path; }

Relics const& relics() const { return m_data.relics; }

void prevent_grants(const std::function<bool()>& callback) { m_prevent_grant_callbacks.push_back(callback); }

private:
location_data::LocationCollection const& m_location_data;
seed_parser m_last_parser = nullptr;
std::string m_last_path;
Data m_data;
std::unordered_set<location_entry> m_skip;
bool m_should_prevent_grants = false;
std::vector<std::function<bool()>> m_prevent_grant_callbacks;
};
} // namespace randomizer::seed
2 changes: 1 addition & 1 deletion projects/Randomizer/text_processors/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace randomizer::text_processors {
auto value = func(base_processor, contents);
if (value.has_value()) {
text.replace(start, next - start, value.value());
next = start + value.value().size();
next = std::max(start + value.value().size(), 1ull) - 1;
}

start = text.find(pattern, next);
Expand Down
6 changes: 5 additions & 1 deletion projects/Randomizer/text_processors/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ namespace randomizer::text_processors {
std::optional<std::string> action(core::text::ITextProcessor const& base_processor, std::string_view content) {
std::string text;
auto item_data = seed::legacy_parser::parse_action(content);
for (auto const& name : item_data.names) {
if (!item_data.has_value()) {
return std::nullopt;
}

for (auto const& name : item_data->names) {
if (!text.empty()) {
text += "\n";
}
Expand Down

0 comments on commit ae82db8

Please sign in to comment.