Skip to content

Commit

Permalink
Merge branch 'dev' into v5
Browse files Browse the repository at this point in the history
# Conflicts:
#	projects/Core/messages/message_controller.h
#	projects/Randomizer/randomizer.cpp
#	projects/Randomizer/seed/legacy_parser/parser.cpp
  • Loading branch information
timoschwarzer committed Nov 10, 2024
2 parents 9773d01 + a30190a commit 8c3d793
Show file tree
Hide file tree
Showing 29 changed files with 2,519 additions and 63 deletions.
4 changes: 3 additions & 1 deletion projects/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ set(
"api/messages/text_style.cpp"
"api/moon_animator_events.cpp"
"api/scenes/create_objects.cpp"
"api/scenes/scene_load.cpp"
"api/scenes/polygon.cpp"
"api/scenes/scene_load.cpp"
"api/system/save_files.cpp"
"api/audio.cpp"
"api/screen_position.cpp"
"api/uber_states/uber_state.cpp"
Expand Down Expand Up @@ -108,6 +109,7 @@ set(
"api/scenes/scene_load.h"
"api/scenes/polygon.h"
"api/system/message_provider.h"
"api/system/save_files.h"
"api/audio.h"
"api/screen_position.h"
"api/uber_states/uber_state.h"
Expand Down
29 changes: 29 additions & 0 deletions projects/Core/api/system/save_files.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <Core/api/game/game.h>
#include <Core/api/system/save_files.h>
#include <Core/utils/byte_stream.h>
#include <Modloader/app/methods/Grdk/Wrapper.h>
#include <Modloader/app/methods/SaveGameController.h>
#include <Modloader/app/methods/System/IO/File.h>

using namespace app::classes;

namespace core::api::save_files {
app::Byte__Array* get_byte_array(int slot_index, int backup_index) {
if (Grdk::Wrapper::get_InitializedOk()) { // Handle GRDK (Xbox Account) saves
return Grdk::Wrapper::Load_1(slot_index, backup_index);
}

auto save_info = SaveGameController::GetSaveFileInfo(game::save_controller(), slot_index, backup_index);

return System::IO::File::ReadAllBytes(
backup_index >= 0
? save_info->fields.m_FullBackupSaveFilePath
: save_info->fields.m_FullSaveFilePath
);
}

std::vector<std::byte> get_bytes(int slot_index, int backup_index) {
return utils::ByteStream(get_byte_array(slot_index, backup_index)).peek_to_end();
}
}

21 changes: 21 additions & 0 deletions projects/Core/api/system/save_files.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <vector>

namespace core::api::save_files {
/**
* Get the on-disk save data for a save file.
* @param slot_index Save slot index
* @param backup_index Backup slot index. Set this to -1 to request the current game save file.
* @return Pointer to an il2cpp array of System.Byte.
*/
CORE_DLLEXPORT app::Byte__Array* get_byte_array(int slot_index, int backup_index = -1);

/**
* Get the on-disk save data for a save file.
* @param slot_index Save slot index
* @param backup_index Backup slot index. Set this to -1 to request the current game save file.
* @return Byte vector containing the on-disk save data
*/
CORE_DLLEXPORT std::vector<std::byte> get_bytes(int slot_index, int backup_index = -1);
}
4 changes: 2 additions & 2 deletions projects/Core/api/uber_states/uber_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ namespace core::api::uber_states {
if (settings::dev_mode()) {
if (prev != value) {
const auto text = std::format("uber state ({}|{}) set to {} from {}", static_cast<int>(m_group), m_state, value, prev);
info("uber_state", text);
debug("uber_state", text);
} else if (has_volatile_value()) {
const auto text = std::format(
"uber state ({}|{}) set to {} because it had a volatile value set", static_cast<int>(m_group), m_state, value
);
info("uber_state", text);
debug("uber_state", text);
}
}

Expand Down
4 changes: 4 additions & 0 deletions projects/Core/messages/message_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ namespace core::messages {
}
}

void MessageController::clear_recent_messages() {
m_recent_messages.clear();
}

void MessageController::clear_central() {
m_central_display.clear();
m_recent_display.clear();
Expand Down
1 change: 1 addition & 0 deletions projects/Core/messages/message_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace core::messages {
// Handles showing / hiding the given messagebox based on info provided.
message_handle_ptr_t queue(std::shared_ptr<api::messages::MessageBox> message, IndependentMessageInfo info);
message_handle_ptr_t queue_central(MessageInfo info, bool add_to_recent = false);
void clear_recent_messages();
void show_recent_messages();
void update(float delta_time);
void clear_central();
Expand Down
1 change: 1 addition & 0 deletions projects/Core/property/reactivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <Core/macros.h>

#include <Core/api/uber_states/uber_state.h>
#include <Core/enums/static_text_entries.h>

#include <Common/event_bus.h>
Expand Down
20 changes: 7 additions & 13 deletions projects/Core/save_meta/save_meta.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <Core/api/game/game.h>
#include <Core/api/system/save_files.h>
#include <Core/save_meta/save_meta.h>
#include <Core/utils/byte_stream.h>
#include <Modloader/app/methods/DeathUberStateManager.h>
#include <Modloader/app/methods/Grdk/Wrapper.h>
#include <Modloader/app/methods/Moon/UberStateValueStore.h>
#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 @@ -268,18 +269,11 @@ namespace core::save_meta {
// ...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) {
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);
read_save_meta_from_byte_array(
api::save_files::get_byte_array(save_slot_index, backup_slot),
true,
SaveMetaSlotPersistence::ThroughDeathsAndQTMsAndBackups
);
}

return return_value;
Expand Down
2 changes: 1 addition & 1 deletion projects/Core/utils/byte_stream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string_view>
#include <string>
#include <vector>
#include <Core/macros.h>

Expand Down
2 changes: 2 additions & 0 deletions projects/Modloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(
"windows_api/modloader.cpp"
"windows_api/sleep.cpp"
"app/il2cpp_init.cpp"
"console_logging_handler.cpp"
"file_logging_handler.cpp"
"modloader.cpp"
"il2cpp_helpers.cpp"
Expand All @@ -35,6 +36,7 @@ set(
"windows_api/memory.h"
"windows_api/sleep.h"
"windows_api/windows.h"
"console_logging_handler.h"
"file_logging_handler.h"
"modloader.h"
"constants.h"
Expand Down
26 changes: 26 additions & 0 deletions projects/Modloader/console_logging_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Modloader/console_logging_handler.h>

#include "windows_api/console.h"

namespace modloader {
std::string get_message_type_prefix(MessageType type) {
switch (type) {
case MessageType::Error:
return "\033[91mERROR\033[0m";
case MessageType::Warning:
return "\033[93mWARN \033[0m";
case MessageType::Info:
return "\033[92mINFO \033[0m";
case MessageType::Debug:
return "\033[97mDEBUG\033[0m";
}

return "UNKWN";
}

void ConsoleLoggingHandler::write(MessageType type, std::string const& group, std::string const& message) {
modloader::win::console::console_send(
std::format("{} \033[95m{}\033[0m: {}", get_message_type_prefix(type), group, message)
);
}
}
16 changes: 16 additions & 0 deletions projects/Modloader/console_logging_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <Modloader/modloader.h>

#include <filesystem>
#include <fstream>
#include <mutex>

namespace modloader {
class ConsoleLoggingHandler final : public ILoggingHandler {
public:
explicit ConsoleLoggingHandler() {};

void write(MessageType type, std::string const& group, std::string const& message) override;
};
}
7 changes: 5 additions & 2 deletions projects/Modloader/il2cpp_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
#include <Modloader/modloader.h>
#include <Modloader/windows_api/console.h>
#include <Modloader/windows_api/memory.h>
#include <Modloader/app/il2cpp_api.h>

#include <Common/ext.h>

#include <codecvt>
#include <locale>
#include <vector>
#include <xstring>

Expand Down Expand Up @@ -930,6 +929,10 @@ namespace il2cpp {

std::string get_class_namespace(Il2CppClass* klass) { return {il2cpp_class_get_namespace(klass)}; }

void attach_thread() {
il2cpp_thread_attach(il2cpp_domain_get());
}

/**
* Converts a C# string to std::string by truncating characters.
* May lose special characters.
Expand Down
6 changes: 3 additions & 3 deletions projects/Modloader/il2cpp_helpers.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include <Modloader/app/il2cpp_api.h>
#include <Modloader/app/structs/Component_1.h>
#include <Modloader/app/structs/GameObject.h>
#include <Modloader/app/structs/List_1_System_Int32_.h>
#include <Modloader/app/structs/Scene.h>
#include <Modloader/app/structs/ScriptableObject.h>
Expand All @@ -13,7 +11,7 @@
#include <Modloader/windows_api/memory.h>
#include <memory>

#include <string_view>
#include <string>
#include <vector>

using GCHandleId = uint32_t;
Expand Down Expand Up @@ -190,6 +188,8 @@ namespace il2cpp {

IL2CPP_MODLOADER_DLLEXPORT std::string get_class_namespace(Il2CppClass* klass);

IL2CPP_MODLOADER_DLLEXPORT void attach_thread();

template<typename Return = Il2CppClass>
Return* get_class(std::string_view namezpace, std::string_view name) {
return reinterpret_cast<Return*>(untyped::get_class(namezpace, name));
Expand Down
7 changes: 5 additions & 2 deletions projects/Modloader/modloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#include <Modloader/windows_api/common.h>
#include <Modloader/windows_api/console.h>
#include <Modloader/file_logging_handler.h>
#include <Modloader/console_logging_handler.h>

#include <Common/settings.h>
#include <filesystem>
#include <functional>
#include <semaphore>

#include <Common/settings.h>

//---------------------------------------------------Globals-----------------------------------------------------

Expand Down Expand Up @@ -89,7 +90,7 @@ namespace modloader {
}

void debug(std::string const& group, std::string const& message) {
trace(MessageType::Info, group, message);
trace(MessageType::Debug, group, message);
}

void info(std::string const& group, std::string const& message) {
Expand All @@ -108,13 +109,15 @@ namespace modloader {

std::shared_ptr<ILoggingHandler> buffer_logging_handler;
std::shared_ptr<ILoggingHandler> file_logging_handler;
std::shared_ptr<ILoggingHandler> console_logging_handler;

std::binary_semaphore wait_for_exit(0);
IL2CPP_MODLOADER_C_DLLEXPORT void injection_entry(const std::filesystem::path& path, const std::function<void()>& on_initialization_complete, const std::function<void(std::string_view)>& on_error) {
inner_base_path = path;

buffer_logging_handler = register_logging_handler(std::make_shared<BufferLoggingHandler>());
file_logging_handler = register_logging_handler(std::make_shared<FileLoggingHandler>(base_path() / csv_path));
console_logging_handler = register_logging_handler(std::make_shared<ConsoleLoggingHandler>());

trace(MessageType::Info, "initialize", "Loading settings.");

Expand Down
4 changes: 2 additions & 2 deletions projects/Modloader/udp_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <functional>
#include <memory>
#include <span>
#include <string_view>
#include <string>
#include <vector>

namespace modloader {
Expand Down Expand Up @@ -50,4 +50,4 @@ namespace modloader {
std::string server;
int port;
};
} // namespace modloader
} // namespace modloader
16 changes: 11 additions & 5 deletions projects/Modloader/windows_api/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace modloader::win::console {

Command root;

bool initialzed = false;
bool initialized = false;
bool failed = false;
FILE* console_file;
std::future<std::string> console_input;
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace modloader::win::console {

void console_initialize() {
console_file = nullptr;
initialzed = false;
initialized = false;
failed = true;
if (!AllocConsole()) {
return;
Expand Down Expand Up @@ -247,13 +247,19 @@ namespace modloader::win::console {
SetConsoleCP(GetACP());
SetConsoleOutputCP(GetACP());

HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD console_mode = 0;
GetConsoleMode(console_handle, &console_mode);
console_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(console_handle, console_mode);

console_input = std::async(read_command);
initialzed = true;
initialized = true;
failed = false;
}

void console_free() {
if (!initialzed) {
if (!initialized) {
return;
}

Expand Down Expand Up @@ -302,7 +308,7 @@ namespace modloader::win::console {
void console_poll() {
std::this_thread::sleep_for(std::chrono::milliseconds(100));

if (initialzed && console_input.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
if (initialized && console_input.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
const auto command = console_input.get();
if (command.rfind("echo ", 0) != std::string::npos) {
std::cout << command.substr(5, command.length()) << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions projects/Randomizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(
"features/scenes/modifications/marsh_burrow_fight_arena_allow_teleportation.cpp"
"features/scenes/modifications/meeting_kwolok_cutscene_trigger_underwater_fix.cpp"
"features/scenes/modifications/reactive_bone_bridge_state.cpp"
"features/scenes/modifications/ruins_escape_allow_teleportation.cpp"
"features/scenes/modifications/sandless_feeding_grounds_to_elevator.cpp"
"features/scenes/modifications/sandless_shriek_escape.cpp"
"features/secrets.cpp"
Expand All @@ -83,6 +84,7 @@ set(
"game/behaviour_changes/fix_straight_grenades.cpp"
"game/behaviour_changes/flap_without_glide.cpp"
"game/behaviour_changes/instant_tp_activation.cpp"
"game/behaviour_changes/keep_shriek_health_bar_visible.cpp"
"game/behaviour_changes/kwolok_boss_rubberbanding_fix.cpp"
"game/behaviour_changes/luma_contact_switch_door_jank_fix.cpp"
"game/behaviour_changes/patch2_kickback.cpp"
Expand All @@ -93,6 +95,7 @@ set(
"game/behaviour_changes/teleporter_glades_identifier.cpp"
"game/behaviour_changes/teleporter_map_activation.cpp"
"game/behaviour_changes/teleporting_oob_fix.cpp"
"game/behaviour_changes/luma_trial_bubbles.cpp"
"game/behaviour_changes/trials_leaderboards.cpp"
"game/behaviour_changes/triple_jump_shockwave.cpp"
"game/condition_intercepts/day_night_logic.cpp"
Expand Down
Loading

0 comments on commit 8c3d793

Please sign in to comment.