diff --git a/README.md b/README.md index 2b616290f..bbb8926a3 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4113. +This is the source code for early-access 4114. ## Legal Notice diff --git a/src/core/debugger/gdbstub_arch.cpp b/src/core/debugger/gdbstub_arch.cpp index 6ddaf14e1..7eb03664d 100755 --- a/src/core/debugger/gdbstub_arch.cpp +++ b/src/core/debugger/gdbstub_arch.cpp @@ -383,7 +383,7 @@ std::string GDBStubA32::RegRead(const Kernel::KThread* thread, size_t id) const } else if (id == CPSR_REGISTER) { return ValueToHex(context.pstate); } else if (id >= D0_REGISTER && id < Q0_REGISTER) { - return ValueToHex(fprs[id - D0_REGISTER][0]); + return ValueToHex(fprs[(id - D0_REGISTER) / 2][(id - D0_REGISTER) % 2]); } else if (id >= Q0_REGISTER && id < FPSCR_REGISTER) { return ValueToHex(fprs[id - Q0_REGISTER]); } else if (id == FPSCR_REGISTER) { @@ -406,7 +406,7 @@ void GDBStubA32::RegWrite(Kernel::KThread* thread, size_t id, std::string_view v } else if (id == CPSR_REGISTER) { context.pstate = HexToValue(value); } else if (id >= D0_REGISTER && id < Q0_REGISTER) { - fprs[id - D0_REGISTER] = {HexToValue(value), 0}; + fprs[(id - D0_REGISTER) / 2][(id - D0_REGISTER) % 2] = HexToValue(value); } else if (id >= Q0_REGISTER && id < FPSCR_REGISTER) { fprs[id - Q0_REGISTER] = HexToValue(value); } else if (id == FPSCR_REGISTER) { diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp index a883a021e..c48ed29bc 100755 --- a/src/core/hle/service/am/library_applet_creator.cpp +++ b/src/core/hle/service/am/library_applet_creator.cpp @@ -118,23 +118,17 @@ std::shared_ptr CreateGuestApplet(Core::System& system, switch (mode) { case LibraryAppletMode::AllForeground: case LibraryAppletMode::NoUi: - applet->focus_state = FocusState::InFocus; - applet->hid_registration.EnableAppletToGetInput(true); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); - break; - case LibraryAppletMode::AllForegroundInitiallyHidden: - applet->system_buffer_manager.SetWindowVisibility(false); - applet->focus_state = FocusState::NotInFocus; - applet->hid_registration.EnableAppletToGetInput(false); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); - break; case LibraryAppletMode::PartialForeground: case LibraryAppletMode::PartialForegroundIndirectDisplay: - default: - applet->focus_state = FocusState::Background; applet->hid_registration.EnableAppletToGetInput(true); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); + applet->focus_state = FocusState::InFocus; + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); + break; + case LibraryAppletMode::AllForegroundInitiallyHidden: + applet->hid_registration.EnableAppletToGetInput(false); + applet->focus_state = FocusState::NotInFocus; + applet->system_buffer_manager.SetWindowVisibility(false); + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground); break; } diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp index 7fb9e3a75..48923fe41 100755 --- a/src/core/hle/service/am/system_buffer_manager.cpp +++ b/src/core/hle/service/am/system_buffer_manager.cpp @@ -38,7 +38,8 @@ bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel: } Nvnflinger::LayerBlending blending = Nvnflinger::LayerBlending::None; - if (mode == LibraryAppletMode::PartialForeground) { + if (mode == LibraryAppletMode::PartialForeground || + mode == LibraryAppletMode::PartialForegroundIndirectDisplay) { blending = Nvnflinger::LayerBlending::Coverage; } diff --git a/src/core/hle/service/am/window_controller.cpp b/src/core/hle/service/am/window_controller.cpp index f00957f83..c07ef228b 100755 --- a/src/core/hle/service/am/window_controller.cpp +++ b/src/core/hle/service/am/window_controller.cpp @@ -62,12 +62,12 @@ void IWindowController::SetAppletWindowVisibility(HLERequestContext& ctx) { applet->hid_registration.EnableAppletToGetInput(visible); if (visible) { - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); applet->focus_state = FocusState::InFocus; + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); } else { applet->focus_state = FocusState::NotInFocus; + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground); } - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index 658a14ed0..1a34a392f 100755 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp @@ -9,6 +9,7 @@ #include "core/core_timing.h" #include "core/hle/kernel/k_page_table.h" #include "core/hle/kernel/k_process.h" +#include "core/hle/kernel/k_process_page_table.h" #include "core/hle/service/hid/hid_server.h" #include "core/hle/service/sm/sm.h" #include "core/memory.h" @@ -85,8 +86,12 @@ VAddr StandardVmCallbacks::SanitizeAddress(VAddr in) const { if ((in < metadata.main_nso_extents.base || in >= metadata.main_nso_extents.base + metadata.main_nso_extents.size) && (in < metadata.heap_extents.base || - in >= metadata.heap_extents.base + metadata.heap_extents.size)) { - LOG_ERROR(CheatEngine, + in >= metadata.heap_extents.base + metadata.heap_extents.size) && + (in < metadata.alias_extents.base || + in >= metadata.heap_extents.base + metadata.alias_extents.size) && + (in < metadata.aslr_extents.base || + in >= metadata.heap_extents.base + metadata.aslr_extents.size)) { + LOG_DEBUG(CheatEngine, "Cheat attempting to access memory at invalid address={:016X}, if this " "persists, " "the cheat may be incorrect. However, this may be normal early in execution if " @@ -211,16 +216,14 @@ void CheatEngine::Initialize() { .base = GetInteger(page_table.GetHeapRegionStart()), .size = page_table.GetHeapRegionSize(), }; - - metadata.address_space_extents = { - .base = GetInteger(page_table.GetAddressSpaceStart()), - .size = page_table.GetAddressSpaceSize(), - }; - - metadata.alias_extents = { + metadata.aslr_extents = { .base = GetInteger(page_table.GetAliasCodeRegionStart()), .size = page_table.GetAliasCodeRegionSize(), }; + metadata.alias_extents = { + .base = GetInteger(page_table.GetAliasRegionStart()), + .size = page_table.GetAliasRegionSize(), + }; is_pending_reload.exchange(true); } diff --git a/src/core/memory/cheat_engine.h b/src/core/memory/cheat_engine.h index d4ba1eb5e..bcedc38b5 100755 --- a/src/core/memory/cheat_engine.h +++ b/src/core/memory/cheat_engine.h @@ -37,7 +37,7 @@ private: VAddr SanitizeAddress(VAddr address) const; const CheatProcessMetadata& metadata; - System& system; + Core::System& system; }; // Intermediary class that parses a text file or other disk format for storing cheats into a diff --git a/src/core/memory/dmnt_cheat_types.h b/src/core/memory/dmnt_cheat_types.h index 6368cc497..8d78a242b 100755 --- a/src/core/memory/dmnt_cheat_types.h +++ b/src/core/memory/dmnt_cheat_types.h @@ -18,7 +18,7 @@ struct CheatProcessMetadata { MemoryRegionExtents main_nso_extents{}; MemoryRegionExtents heap_extents{}; MemoryRegionExtents alias_extents{}; - MemoryRegionExtents address_space_extents{}; + MemoryRegionExtents aslr_extents{}; std::array main_nso_build_id{}; }; diff --git a/src/core/memory/dmnt_cheat_vm.cpp b/src/core/memory/dmnt_cheat_vm.cpp index 508949239..54d1197a0 100755 --- a/src/core/memory/dmnt_cheat_vm.cpp +++ b/src/core/memory/dmnt_cheat_vm.cpp @@ -322,8 +322,9 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { } break; case CheatVmOpcodeType::EndConditionalBlock: { // 20000000 - // There's actually nothing left to process here! - opcode.opcode = EndConditionalOpcode{}; + opcode.opcode = EndConditionalOpcode{ + .is_else = ((first_dword >> 24) & 0xf) == 1, + }; } break; case CheatVmOpcodeType::ControlLoop: { // 300R0000 VVVVVVVV @@ -555,6 +556,18 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { .idx = first_dword & 0xF, }; } break; + case CheatVmOpcodeType::PauseProcess: { + /* FF0????? */ + /* FF0 = opcode 0xFF0 */ + /* Pauses the current process. */ + opcode.opcode = PauseProcessOpcode{}; + } break; + case CheatVmOpcodeType::ResumeProcess: { + /* FF0????? */ + /* FF0 = opcode 0xFF0 */ + /* Pauses the current process. */ + opcode.opcode = ResumeProcessOpcode{}; + } break; case CheatVmOpcodeType::DebugLog: { // FFFTIX## // FFFTI0Ma aaaaaaaa @@ -621,7 +634,7 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { return valid; } -void DmntCheatVm::SkipConditionalBlock() { +void DmntCheatVm::SkipConditionalBlock(bool is_if) { if (condition_depth > 0) { // We want to continue until we're out of the current block. const std::size_t desired_depth = condition_depth - 1; @@ -637,8 +650,12 @@ void DmntCheatVm::SkipConditionalBlock() { // We also support nesting of conditional blocks, and Gateway does not. if (skip_opcode.begin_conditional_block) { condition_depth++; - } else if (std::holds_alternative(skip_opcode.opcode)) { - condition_depth--; + } else if (auto end_cond = std::get_if(&skip_opcode.opcode)) { + if (!end_cond->is_else) { + condition_depth--; + } else if (is_if && condition_depth - 1 == desired_depth) { + break; + } } } } else { @@ -675,6 +692,10 @@ u64 DmntCheatVm::GetCheatProcessAddress(const CheatProcessMetadata& metadata, return metadata.main_nso_extents.base + rel_address; case MemoryAccessType::Heap: return metadata.heap_extents.base + rel_address; + case MemoryAccessType::Alias: + return metadata.alias_extents.base + rel_address; + case MemoryAccessType::Aslr: + return metadata.aslr_extents.base + rel_address; } } @@ -682,7 +703,6 @@ void DmntCheatVm::ResetState() { registers.fill(0); saved_values.fill(0); loop_tops.fill(0); - static_registers.fill(0); instruction_ptr = 0; condition_depth = 0; decode_success = true; @@ -794,13 +814,18 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) { } // Skip conditional block if condition not met. if (!cond_met) { - SkipConditionalBlock(); + SkipConditionalBlock(true); } - } else if (std::holds_alternative(cur_opcode.opcode)) { - // Decrement the condition depth. - // We will assume, graciously, that mismatched conditional block ends are a nop. - if (condition_depth > 0) { - condition_depth--; + } else if (auto end_cond = std::get_if(&cur_opcode.opcode)) { + if (end_cond->is_else) { + /* Skip to the end of the conditional block. */ + this->SkipConditionalBlock(false); + } else { + /* Decrement the condition depth. */ + /* We will assume, graciously, that mismatched conditional block ends are a nop. */ + if (condition_depth > 0) { + condition_depth--; + } } } else if (auto ctrl_loop = std::get_if(&cur_opcode.opcode)) { if (ctrl_loop->start_loop) { @@ -908,7 +933,7 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) { // Check for keypress. if ((begin_keypress_cond->key_mask & kDown) != begin_keypress_cond->key_mask) { // Keys not pressed. Skip conditional block. - SkipConditionalBlock(); + SkipConditionalBlock(true); } } else if (auto perform_math_reg = std::get_if(&cur_opcode.opcode)) { @@ -1116,7 +1141,7 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) { // Skip conditional block if condition not met. if (!cond_met) { - SkipConditionalBlock(); + SkipConditionalBlock(true); } } else if (auto save_restore_reg = std::get_if(&cur_opcode.opcode)) { @@ -1178,6 +1203,10 @@ void DmntCheatVm::Execute(const CheatProcessMetadata& metadata) { // Store a register to a static register. static_registers[rw_static_reg->static_idx] = registers[rw_static_reg->idx]; } + } else if (std::holds_alternative(cur_opcode.opcode)) { + // TODO: Pause cheat process + } else if (std::holds_alternative(cur_opcode.opcode)) { + // TODO: Resume cheat process } else if (auto debug_log = std::get_if(&cur_opcode.opcode)) { // Read value from memory. u64 log_value = 0; diff --git a/src/core/memory/dmnt_cheat_vm.h b/src/core/memory/dmnt_cheat_vm.h index e2cba37f4..667f02914 100755 --- a/src/core/memory/dmnt_cheat_vm.h +++ b/src/core/memory/dmnt_cheat_vm.h @@ -42,12 +42,16 @@ enum class CheatVmOpcodeType : u32 { DoubleExtendedWidth = 0xF0, // Double-extended width opcodes. + PauseProcess = 0xFF0, + ResumeProcess = 0xFF1, DebugLog = 0xFFF, }; enum class MemoryAccessType : u32 { MainNso = 0, Heap = 1, + Alias = 2, + Aslr = 3, }; enum class ConditionalComparisonType : u32 { @@ -131,7 +135,9 @@ struct BeginConditionalOpcode { VmInt value{}; }; -struct EndConditionalOpcode {}; +struct EndConditionalOpcode { + bool is_else; +}; struct ControlLoopOpcode { bool start_loop{}; @@ -222,6 +228,10 @@ struct ReadWriteStaticRegisterOpcode { u32 idx{}; }; +struct PauseProcessOpcode {}; + +struct ResumeProcessOpcode {}; + struct DebugLogOpcode { u32 bit_width{}; u32 log_id{}; @@ -244,8 +254,8 @@ struct CheatVmOpcode { PerformArithmeticStaticOpcode, BeginKeypressConditionalOpcode, PerformArithmeticRegisterOpcode, StoreRegisterToAddressOpcode, BeginRegisterConditionalOpcode, SaveRestoreRegisterOpcode, - SaveRestoreRegisterMaskOpcode, ReadWriteStaticRegisterOpcode, DebugLogOpcode, - UnrecognizedInstruction> + SaveRestoreRegisterMaskOpcode, ReadWriteStaticRegisterOpcode, PauseProcessOpcode, + ResumeProcessOpcode, DebugLogOpcode, UnrecognizedInstruction> opcode{}; }; @@ -296,7 +306,7 @@ private: std::array loop_tops{}; bool DecodeNextOpcode(CheatVmOpcode& out); - void SkipConditionalBlock(); + void SkipConditionalBlock(bool is_if); void ResetState(); // For implementing the DebugLog opcode.