Skip to content

Commit

Permalink
Merge branch 'dev' into v5
Browse files Browse the repository at this point in the history
# Conflicts:
#	projects/Randomizer/CMakeLists.txt
#	projects/Randomizer/game/spawning_and_preloading.cpp
#	projects/Randomizer/randomizer.cpp
#	projects/Randomizer/randomizer.h
#	projects/Randomizer/seed/legacy_parser/parser.cpp
#	projects/Randomizer/seed/seed.cpp
#	projects/Randomizer/seed/seed.h
#	projects/Randomizer/ui/main_menu_seed_info.cpp
#	projects/Randomizer/ui/main_menu_seed_info.h
#	vcpkg.json
  • Loading branch information
timoschwarzer committed Aug 8, 2024
2 parents 30922b2 + d9ad36e commit d8ed0e2
Show file tree
Hide file tree
Showing 68 changed files with 1,560 additions and 488 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Load CMake and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: 3.29.0 # Pinned until https://github.com/microsoft/vcpkg/issues/37968 is fixed
cmakeVersion: 3.29.5
- name: Set up directories
run: "md -Path 'C:\\moon\\randomizer'"
- name: Extract tag
Expand All @@ -43,10 +43,7 @@ jobs:
run: |
$path = Resolve-Path .
New-Item -Path ${{ env.WORKDIR }} -ItemType SymbolicLink -Value $path
- uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64
toolset: 14.39 # Workaround for https://github.com/actions/runner-images/issues/9086
- uses: ilammy/msvc-dev-cmd@v1
- name: Update vcpkg repository
shell: cmd
run: |
Expand Down
16 changes: 15 additions & 1 deletion projects/Core/api/faderb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using namespace app::classes;

namespace core::api::faderb {
auto skip_black_screen_cleanup = false;

app::FaderB* get() {
static auto cache = types::UI::get_class()->static_fields->Fader;
return cache;
Expand All @@ -23,6 +25,18 @@ namespace core::api::faderb {
FaderB::FadeOut_2(get(), duration);
}

void set_skip_black_screen_cleanup(bool skip) {
skip_black_screen_cleanup = skip;
}

IL2CPP_INTERCEPT(FaderB, void, DoBlackScreenCleanup, (app::FaderB * this_ptr)) {
if (skip_black_screen_cleanup) {
return;
}

next::FaderB::DoBlackScreenCleanup(this_ptr);
}

IL2CPP_INTERCEPT(FaderB, void, OnFadeInFinished, (app::FaderB * this_ptr)) {
game::event_bus().trigger_event(GameEvent::FaderBFadeInFinished, EventTiming::Before);
next::FaderB::OnFadeInFinished(this_ptr);
Expand All @@ -34,4 +48,4 @@ namespace core::api::faderb {
next::FaderB::OnFadeOutFinished(this_ptr);
game::event_bus().trigger_event(GameEvent::FaderBFadeOutFinished, EventTiming::After);
}
} // namespace core::api::faderb
} // namespace core::api::faderb
3 changes: 2 additions & 1 deletion projects/Core/api/faderb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace core::api::faderb {
CORE_DLLEXPORT app::FaderB* get();
CORE_DLLEXPORT void fade_in(float duration);
CORE_DLLEXPORT void fade_out(float duration);
} // namespace core::api::faderb
CORE_DLLEXPORT void set_skip_black_screen_cleanup(bool do_cleanup);
} // namespace core::api::faderb
107 changes: 107 additions & 0 deletions projects/Core/api/game/debug_menu.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#include <Core/api/game/debug_menu.h>
#include <Core/api/graphics/textures.h>
#include <Modloader/app/methods/CheatsHandler.h>
#include <Modloader/app/methods/DebugMenu.h>
#include <Modloader/app/methods/HierarchyDebugMenu.h>
#include <Modloader/app/methods/UnityEngine/GUILayout.h>
#include <Modloader/app/methods/UnityEngine/GUIStyle.h>
#include <Modloader/app/methods/UnityEngine/GUIStyleState.h>
#include <Modloader/app/methods/UnityEngine/Texture.h>
#include <Modloader/app/methods/UnityEngine/Texture2D.h>
#include <Modloader/app/methods/Moon/UberStateVisualization/UberStateVisualizationView.h>
#include <Modloader/app/methods/Moon/UberStateVisualization/ListView.h>
#include <Modloader/app/types/CheatsHandler.h>
#include <Modloader/app/types/DebugValues.h>
#include <Modloader/app/types/Texture2D.h>
#include <Modloader/modloader.h>
#include <optional>

using namespace app::classes;
Expand Down Expand Up @@ -39,6 +51,36 @@ namespace core::api::game::debug_menu {
next::CheatsHandler::ActivateDebugMenu(this_ptr);
}

auto draw_gui_area_without_style = false;
IL2CPP_INTERCEPT(UnityEngine::GUILayout, void, BeginArea_4, (app::Rect screen_rect, app::GUIStyle* style)) {
if (draw_gui_area_without_style) {
UnityEngine::GUILayout::BeginArea_1(screen_rect);
return;
}

next::UnityEngine::GUILayout::BeginArea_4(screen_rect, style);
}

IL2CPP_INTERCEPT(HierarchyDebugMenu, bool, Draw, (app::HierarchyDebugMenu * this_ptr, app::Rect rect, bool is_selected)) {
modloader::ScopedSetter _(draw_gui_area_without_style, true);
return next::HierarchyDebugMenu::Draw(this_ptr, rect, is_selected);
}

IL2CPP_INTERCEPT(DebugMenu, void, Awake, (app::DebugMenu* this_ptr)) {
next::DebugMenu::Awake(this_ptr);

const auto texture = types::Texture2D::create();
UnityEngine::Texture2D::ctor_5(texture, 1, 1, app::TextureFormat__Enum::RGBA32, false);
UnityEngine::Texture2D::SetPixel(texture, 0, 0, app::Color{0.f, 0.f, 0.f, 0.4f});
UnityEngine::Texture2D::Compress(texture, false);
UnityEngine::Texture::set_wrapMode(reinterpret_cast<app::Texture*>(texture), app::TextureWrapMode__Enum::Repeat);
UnityEngine::Texture2D::Apply_1(texture, true, true);
graphics::textures::dont_unload_texture(reinterpret_cast<app::Texture*>(texture));

const auto normal = UnityEngine::GUIStyle::get_normal(this_ptr->fields.Skin->fields.m_CustomStyles->vector[9]);
UnityEngine::GUIStyleState::set_background(normal, texture);
}

void set_should_prevent_cheats(bool prevent) {
if (!was_debug_enabled_initially.has_value()) {
was_debug_enabled_initially = is_debug_enabled();
Expand Down Expand Up @@ -83,4 +125,69 @@ namespace core::api::game::debug_menu {
bool was_debug_active_this_session() {
return debug_was_active_this_session;
}

namespace better_uber_state_menu {
auto is_building_list = false;
auto selected_group_index = 0;
std::unordered_map<int, int> last_selected_state_index_per_group;

void restore_state_selection(const app::UberStateVisualizationView* view) {
Moon::UberStateVisualization::ListView::SelectItem_1(view->fields.m_statesListView, last_selected_state_index_per_group[selected_group_index]);
}

void restore_group_selection(const app::UberStateVisualizationView* view) {
Moon::UberStateVisualization::ListView::SelectItem_1(view->fields.m_groupsListView, selected_group_index);
restore_state_selection(view);
}

IL2CPP_INTERCEPT(Moon::UberStateVisualization::UberStateVisualizationView, void, UpdateWithModel, (app::UberStateVisualizationView * this_ptr, app::UberStateValueStore* uber_state_value_store)) {
{
modloader::ScopedSetter _(is_building_list, true);
next::Moon::UberStateVisualization::UberStateVisualizationView::UpdateWithModel(this_ptr, uber_state_value_store);
}

restore_group_selection(this_ptr);
}

IL2CPP_INTERCEPT(Moon::UberStateVisualization::UberStateVisualizationView, void, OnGroupsListViewSelectionChanged, (app::UberStateVisualizationView * this_ptr, app::ListViewItem* selected_item)) {
{
modloader::ScopedSetter _(is_building_list, true);
next::Moon::UberStateVisualization::UberStateVisualizationView::OnGroupsListViewSelectionChanged(this_ptr, selected_item);
}

if (is_building_list) {
return;
}

auto index = 0;
for (const auto& item: il2cpp::ListIterator(this_ptr->fields.m_groupsListView->fields.m_items)) {
if (item == selected_item) {
selected_group_index = index;
break;
}

++index;
}

restore_state_selection(this_ptr);
}

IL2CPP_INTERCEPT(Moon::UberStateVisualization::UberStateVisualizationView, void, OnStatesListViewSelectionChanged, (app::UberStateVisualizationView * this_ptr, app::ListViewItem* selected_item)) {
next::Moon::UberStateVisualization::UberStateVisualizationView::OnStatesListViewSelectionChanged(this_ptr, selected_item);

if (is_building_list) {
return;
}

auto index = 0;
for (const auto& item: il2cpp::ListIterator(this_ptr->fields.m_statesListView->fields.m_items)) {
if (item == selected_item) {
last_selected_state_index_per_group[selected_group_index] = index;
break;
}

++index;
}
}
}
}
3 changes: 3 additions & 0 deletions projects/Core/api/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ namespace core::api::game {
IL2CPP_INTERCEPT(GameController, void, OnApplicationFocus, (app::GameController * this_ptr, bool focus_status)) {
if (focus_status) {
core::settings::reload();

// Update settings
modloader::cursor_lock(core::settings::cursor_locked());
}

auto evt = focus_status ? GameEvent::GainedFocus : GameEvent::LostFocus;
Expand Down
9 changes: 3 additions & 6 deletions projects/Core/api/game/in_game_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace core::api::game::in_game_timer {
* - Moon Delta Time = deltaTime after it got overridden by Moon
*/

auto minimum_teleportation_time = 7.f; // 7.f constant from SavePedestalController_FixedUpdate, can be overridden in rando
auto unity_delta_time = 0.f;
auto loading_finished_condition_is_blocking = false;
auto title_screen_startup_waiting = true;
Expand Down Expand Up @@ -112,7 +111,9 @@ namespace core::api::game::in_game_timer {

if (
save_pedestal_controller->fields.m_isTeleporting &&
(save_pedestal_controller->fields.m_startTime + 7.f) < UnityEngine::Time::get_time() // 7.f seconds is the hardcoded default in vanilla
(save_pedestal_controller->fields.m_startTime + 7.f) < UnityEngine::Time::get_time()
// The 7.f constant here is correct despite rando shortening the TP time
// because in rando we just offset m_startTime
) {
return AsyncLoadingState::SavePedestalControllerWaiting;
}
Expand Down Expand Up @@ -234,10 +235,6 @@ namespace core::api::game::in_game_timer {
return _time_step_event_bus;
}

void set_minimum_teleportation_time(float time) {
minimum_teleportation_time = time;
}

AsyncLoadingState get_last_async_loading_state() {
return last_async_loading_state;
}
Expand Down
1 change: 0 additions & 1 deletion projects/Core/api/game/in_game_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ namespace core::api::game::in_game_timer {

CORE_DLLEXPORT common::EventBus<TimeStep>& time_step_event_bus();
CORE_DLLEXPORT AsyncLoadingState get_last_async_loading_state();
CORE_DLLEXPORT void set_minimum_teleportation_time(float time);
}
8 changes: 7 additions & 1 deletion projects/Core/api/game/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ namespace core::api::game::player {
Property<int> shard_slots_property(set_shard_slots, get_shard_slots);
} // namespace

app::SeinCharacter* sein() { return types::Characters::get_class()->static_fields->m_sein; }
app::SeinCharacter* sein() {
if (!types::Characters::get_class()->static_fields->HasSein) {
return nullptr;
}

return types::Characters::get_class()->static_fields->m_sein;
}

std::optional<app::EquipmentType__Enum> ability_to_equip_type(const app::AbilityType__Enum ability) {
const auto it = ability_to_equip_map.find(ability);
Expand Down
1 change: 1 addition & 0 deletions projects/Core/api/graphics/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ namespace core::api::graphics::textures {
CORE_DLLEXPORT std::shared_ptr<TextureData> create_texture();
CORE_DLLEXPORT std::shared_ptr<TextureData> get_texture(std::string_view path);
CORE_DLLEXPORT void apply_default(app::Renderer* renderer);
CORE_DLLEXPORT void dont_unload_texture(app::Texture* texture);
} // namespace core::textures
30 changes: 23 additions & 7 deletions projects/Core/api/scenes/scene_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
#include <Modloader/app/methods/SceneManagerScene.h>
#include <Modloader/app/methods/ScenesManager.h>
#include <Modloader/app/methods/UnityEngine/GameObject.h>
#include <Modloader/app/methods/UnityEngine/Rect.h>
#include <Modloader/app/methods/RuntimeSceneMetaData.h>
#include <Modloader/app/types/GameController.h>
#include <Modloader/app/types/GameStateMachine.h>
#include <Modloader/app/types/SceneRoot.h>
#include <Modloader/app/types/Scenes.h>
#include <Modloader/app/types/Rect.h>
#include <Modloader/app/types/ScenesManager.h>
#include <Modloader/interception_macros.h>
#include <Modloader/modloader.h>
#include <Modloader/windows_api/console.h>
Expand Down Expand Up @@ -207,7 +206,7 @@ namespace core::api::scenes {
callback(&metadata);
}
} else if (!ScenesManager::SceneIsLoading(scenes_manager, scene_meta->fields.SceneMoonGuid)) {
ScenesManager::RequestAdditivelyLoadScene(scenes_manager, scene_meta, async, true, true, true, false);
ScenesManager::RequestAdditivelyLoadScene(scenes_manager, scene_meta, async, true, true, true, true);
}
}

Expand Down Expand Up @@ -241,11 +240,28 @@ namespace core::api::scenes {

std::set<int> get_scene_ids_at_position(app::Vector3 position) {
const auto scenes_manager = get_scenes_manager();
auto scenes = ScenesManager::ListAllScenesAtPosition(scenes_manager, position);
ScenesManager::QueryQuadTreeFast_1(scenes_manager, position, types::ScenesManager::get_class()->static_fields->m_tempHashList);
std::set<int> scene_ids;

for (const auto scene_metadata: il2cpp::ListIterator(scenes)) {
scene_ids.emplace(scene_metadata->fields.LinearId);
constexpr float RECT_WIDTH = 80.f;
constexpr float RECT_HEIGHT = 80.f;
const app::Rect rect {
position.x - RECT_WIDTH / 2.f,
position.x + RECT_WIDTH / 2.f,
position.y - RECT_HEIGHT / 2.f,
position.y + RECT_HEIGHT / 2.f,
};

for (const auto id: il2cpp::ListIterator(types::ScenesManager::get_class()->static_fields->m_tempHashList)) {
const auto scene_meta = ScenesManager::GetSceneFromLinearArray(scenes_manager, id);

if (
RuntimeSceneMetaData::IsInsideSceneBounds_3(scene_meta, rect) ||
RuntimeSceneMetaData::IsInsideScenePaddingBounds_5(scene_meta, rect) ||
RuntimeSceneMetaData::IsInsideSceneLoadingZone_2(scene_meta, rect)
) {
scene_ids.emplace(id);
}
}

return scene_ids;
Expand Down
1 change: 1 addition & 0 deletions projects/Core/enums/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
enum class SoundEventID : uint32_t {
// Randomizer
LeagueSubmitted = 2697705149,
KnockKnockWellspring = 965810158,
};

NLOHMANN_JSON_SERIALIZE_ENUM(SoundEventID, {
Expand Down
4 changes: 2 additions & 2 deletions projects/Core/events/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace core::events {
}
}

CustomAction<app::Action> create_action(std::function<void(int)> function) {
CustomAction create_action(std::function<void(int)> function) {
const auto id = next_id++;
auto stored_function = std::make_shared<ActionStore<void(int)>>();
stored_function->function = std::move(function);
Expand All @@ -49,7 +49,7 @@ namespace core::events {
auto action = il2cpp::create_object<app::Action>(app::classes::types::Action::get_class());
app::classes::System::Action::ctor(action, reinterpret_cast<app::Object*>(stored_function.get()), reinterpret_cast<void*>(&stored_function->info));
stored_functions[id] = std::move(stored_function);
return { id, action };
return { id, il2cpp::GCRef(action) };
}

void destroy(int id) {
Expand Down
10 changes: 5 additions & 5 deletions projects/Core/events/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include <Modloader/app/structs/Action.h>

#include <functional>
#include <span>
#include <Core/macros.h>
#include <Modloader/il2cpp_helpers.h>

namespace core::events {
template <typename T>
struct CustomAction {
int id;
T* action;
il2cpp::GCRef<app::Action> action;
};

// First parameter to the function is the id in CustomAction.
CustomAction<app::Action> create_action(std::function<void(int)> function);
CORE_DLLEXPORT CustomAction create_action(std::function<void(int)> function);

void destroy(int id);
CORE_DLLEXPORT void destroy(int id);
} // namespace core::events
20 changes: 14 additions & 6 deletions projects/Core/save_meta/save_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Modloader/app/methods/SaveGameController.h>
#include <Modloader/app/methods/SaveSlotsManager.h>
#include <Modloader/app/methods/System/IO/File.h>
#include <Modloader/app/methods/Grdk/Wrapper.h>
#include <Modloader/app/types/Byte.h>
#include <Modloader/interception_macros.h>
#include <Modloader/modloader.h>
Expand Down Expand Up @@ -264,13 +265,20 @@ namespace core::save_meta {
// Load the backup...
auto return_value = next::SaveGameController::PerformLoad(this_ptr);

// ...and then load SaveMeta with the ThroughDeathsAndBackup persistence
// level from the main save file if we're on a new/different save slot
// ...and then load SaveMeta with the ThroughDeathsAndQTMsAndBackups persistence
// level from the backup save file if we're on a new/different save slot
if (current_save_guid != previous_save_guid) {
auto save_info = SaveGameController::GetSaveFileInfo(this_ptr, save_slot_index, backup_slot);
auto path = save_info->fields.m_FullSaveFilePath;
auto path_str = il2cpp::convert_csstring(path);
auto bytes = System::IO::File::ReadAllBytes(path);
app::Byte__Array* bytes;

if (Grdk::Wrapper::get_InitializedOk()) { // Handle GRDK (Xbox Account) saves
bytes = Grdk::Wrapper::Load_1(save_slot_index, backup_slot);
} else {
auto save_info = SaveGameController::GetSaveFileInfo(this_ptr, save_slot_index, backup_slot);
auto path = save_info->fields.m_FullBackupSaveFilePath;
auto path_str = il2cpp::convert_csstring(path);
bytes = System::IO::File::ReadAllBytes(path);
}

read_save_meta_from_byte_array(bytes, true, SaveMetaSlotPersistence::ThroughDeathsAndQTMsAndBackups);
}

Expand Down
Loading

0 comments on commit d8ed0e2

Please sign in to comment.