diff --git a/CMakeModules/GenerateSCMRev.cmake b/CMakeModules/GenerateSCMRev.cmake index 5b0adad8dd..adc9902fcf 100644 --- a/CMakeModules/GenerateSCMRev.cmake +++ b/CMakeModules/GenerateSCMRev.cmake @@ -38,13 +38,13 @@ set(GIT_DESC ${BUILD_VERSION}) # Auto-updater metadata! Must somewhat mirror GitHub API endpoint if (NIGHTLY_BUILD) set(BUILD_AUTO_UPDATE_WEBSITE "https://github.com") - set(BUILD_AUTO_UPDATE_API "api.github.com") + set(BUILD_AUTO_UPDATE_API "https://api.github.com") set(BUILD_AUTO_UPDATE_API_PATH "/repos/") set(BUILD_AUTO_UPDATE_REPO "Eden-CI/Nightly") set(REPO_NAME "Eden Nightly") else() set(BUILD_AUTO_UPDATE_WEBSITE "https://git.eden-emu.dev") - set(BUILD_AUTO_UPDATE_API "git.eden-emu.dev") + set(BUILD_AUTO_UPDATE_API "https://git.eden-emu.dev") set(BUILD_AUTO_UPDATE_API_PATH "/api/v1/repos/") set(BUILD_AUTO_UPDATE_REPO "eden-emu/eden") set(REPO_NAME "Eden") diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ContentTypeSelectionDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ContentTypeSelectionDialogFragment.kt index c1d8b9ea5f..880c2ff3bf 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ContentTypeSelectionDialogFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ContentTypeSelectionDialogFragment.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -5,15 +8,18 @@ package org.yuzu.yuzu_emu.fragments import android.app.Dialog import android.content.DialogInterface +import android.net.Uri import android.os.Bundle +import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.DialogFragment import androidx.fragment.app.activityViewModels import androidx.preference.PreferenceManager import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.yuzu.yuzu_emu.NativeLibrary import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.YuzuApplication import org.yuzu.yuzu_emu.model.AddonViewModel -import org.yuzu.yuzu_emu.ui.main.MainActivity +import org.yuzu.yuzu_emu.utils.InstallableActions class ContentTypeSelectionDialogFragment : DialogFragment() { private val addonViewModel: AddonViewModel by activityViewModels() @@ -23,6 +29,52 @@ class ContentTypeSelectionDialogFragment : DialogFragment() { private var selectedItem = 0 + private val installGameUpdateLauncher = + registerForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { documents -> + if (documents.isEmpty()) { + return@registerForActivityResult + } + + val game = addonViewModel.game + if (game == null) { + installContent(documents) + return@registerForActivityResult + } + + ProgressDialogFragment.newInstance( + requireActivity(), + R.string.verifying_content, + false + ) { _, _ -> + var updatesMatchProgram = true + for (document in documents) { + val valid = NativeLibrary.doesUpdateMatchProgram( + game.programId, + document.toString() + ) + if (!valid) { + updatesMatchProgram = false + break + } + } + + requireActivity().runOnUiThread { + if (updatesMatchProgram) { + installContent(documents) + } else { + MessageDialogFragment.newInstance( + requireActivity(), + titleId = R.string.content_install_notice, + descriptionId = R.string.content_install_notice_description, + positiveAction = { installContent(documents) }, + negativeAction = {} + ).show(parentFragmentManager, MessageDialogFragment.TAG) + } + } + return@newInstance Any() + }.show(parentFragmentManager, ProgressDialogFragment.TAG) + } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val launchOptions = arrayOf(getString(R.string.updates_and_dlc), getString(R.string.mods_and_cheats)) @@ -31,12 +83,11 @@ class ContentTypeSelectionDialogFragment : DialogFragment() { selectedItem = savedInstanceState.getInt(SELECTED_ITEM) } - val mainActivity = requireActivity() as MainActivity return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.select_content_type) .setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int -> when (selectedItem) { - 0 -> mainActivity.installGameUpdate.launch(arrayOf("*/*")) + 0 -> installGameUpdateLauncher.launch(arrayOf("*/*")) else -> { if (!preferences.getBoolean(MOD_NOTICE_SEEN, false)) { preferences.edit().putBoolean(MOD_NOTICE_SEEN, true).apply() @@ -47,7 +98,7 @@ class ContentTypeSelectionDialogFragment : DialogFragment() { } } } - .setSingleChoiceItems(launchOptions, 0) { _: DialogInterface, i: Int -> + .setSingleChoiceItems(launchOptions, selectedItem) { _: DialogInterface, i: Int -> selectedItem = i } .setNegativeButton(android.R.string.cancel, null) @@ -65,4 +116,13 @@ class ContentTypeSelectionDialogFragment : DialogFragment() { private const val SELECTED_ITEM = "SelectedItem" private const val MOD_NOTICE_SEEN = "ModNoticeSeen" } + + private fun installContent(documents: List) { + InstallableActions.installContent( + activity = requireActivity(), + fragmentManager = parentFragmentManager, + addonViewModel = addonViewModel, + documents = documents + ) + } } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 5c2c77e10a..5c57df424c 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -6,7 +6,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include #include #include #include @@ -128,14 +127,83 @@ struct Memory::Impl { } } - [[nodiscard]] inline u8* GetPointerFromRasterizerCachedMemory(u64 vaddr) const { - auto const paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].addr; - return paddr ? system.DeviceMemory().GetPointer(paddr + vaddr) : nullptr; + [[nodiscard]] u8* GetPointerFromRasterizerCachedMemory(u64 vaddr) const { + Common::PhysicalAddress const paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].addr; + if (paddr) + return system.DeviceMemory().GetPointer(paddr + vaddr); + return {}; } - [[nodiscard]] inline u8* GetPointerFromDebugMemory(u64 vaddr) const { - auto const paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].addr; - return paddr ? system.DeviceMemory().GetPointer(paddr + vaddr) : nullptr; + [[nodiscard]] u8* GetPointerFromDebugMemory(u64 vaddr) const { + const Common::PhysicalAddress paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].addr; + if (paddr != 0) + return system.DeviceMemory().GetPointer(paddr + vaddr); + return {}; + } + + u8 Read8(const Common::ProcessAddress addr) { + return Read(addr); + } + + u16 Read16(const Common::ProcessAddress addr) { + if ((addr & 1) == 0) { + return Read(addr); + } else { + const u32 a{Read(addr)}; + const u32 b{Read(addr + sizeof(u8))}; + return static_cast((b << 8) | a); + } + } + + u32 Read32(const Common::ProcessAddress addr) { + if ((addr & 3) == 0) { + return Read(addr); + } else { + const u32 a{Read16(addr)}; + const u32 b{Read16(addr + sizeof(u16))}; + return (b << 16) | a; + } + } + + u64 Read64(const Common::ProcessAddress addr) { + if ((addr & 7) == 0) { + return Read(addr); + } else { + const u32 a{Read32(addr)}; + const u32 b{Read32(addr + sizeof(u32))}; + return (static_cast(b) << 32) | a; + } + } + + void Write8(const Common::ProcessAddress addr, const u8 data) { + Write(addr, data); + } + + void Write16(const Common::ProcessAddress addr, const u16 data) { + if ((addr & 1) == 0) { + Write(addr, data); + } else { + Write(addr, static_cast(data)); + Write(addr + sizeof(u8), static_cast(data >> 8)); + } + } + + void Write32(const Common::ProcessAddress addr, const u32 data) { + if ((addr & 3) == 0) { + Write(addr, data); + } else { + Write16(addr, static_cast(data)); + Write16(addr + sizeof(u16), static_cast(data >> 16)); + } + } + + void Write64(const Common::ProcessAddress addr, const u64 data) { + if ((addr & 7) == 0) { + Write(addr, data); + } else { + Write32(addr, static_cast(data)); + Write32(addr + sizeof(u32), static_cast(data >> 32)); + } } bool WriteExclusive8(const Common::ProcessAddress addr, const u8 data, const u8 expected) { @@ -590,7 +658,7 @@ struct Memory::Impl { } template - [[nodiscard]] inline u8* GetPointerImpl(u64 vaddr, F&& on_unmapped, G&& on_rasterizer) const { + [[nodiscard]] u8* GetPointerImpl(u64 vaddr, F&& on_unmapped, G&& on_rasterizer) const { // AARCH64 masks the upper 16 bit of all memory accesses vaddr &= 0xffffffffffffULL; if (AddressSpaceContains(*current_page_table, vaddr, 1)) [[likely]] { @@ -645,42 +713,18 @@ struct Memory::Impl { /// @returns The instance of T read from the specified virtual address. template inline T Read(Common::ProcessAddress vaddr) noexcept requires(std::is_trivially_copyable_v) { - auto const addr_c1 = GetInteger(vaddr); - if (!(sizeof(T) > 1 && (addr_c1 & 4095) + sizeof(T) > 4096)) { - if (auto const ptr_c1 = GetPointerImpl(addr_c1, [addr_c1] { - LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, addr_c1); - }, [&] { - HandleRasterizerDownload(addr_c1, sizeof(T)); - }); ptr_c1) { - // It may be tempting to rewrite this particular section to use "reinterpret_cast"; - // afterall, it's trivially copyable so surely it can be copied ov- Alignment. - // Remember, alignment. memcpy() will deal with all the alignment extremely fast. - T result{}; - std::memcpy(&result, ptr_c1, sizeof(T)); - return result; - } - } else { - auto const addr_c2 = (addr_c1 & (~0xfff)) + 0x1000; - // page crossing: say if sizeof(T) = 2, vaddr = 4095 - // 4095 + 2 mod 4096 = 1 => 2 - 1 = 1, thus c1=1, c2=1 - auto const count_c2 = (addr_c1 + sizeof(T)) & 4095; - auto const count_c1 = sizeof(T) - count_c2; - if (auto const ptr_c1 = GetPointerImpl(addr_c1, [addr_c1] { - LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, addr_c1); - }, [&] { - HandleRasterizerDownload(addr_c1, count_c1); - }); ptr_c1) { - if (auto const ptr_c2 = GetPointerImpl(addr_c2, [addr_c2] { - LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, addr_c2); - }, [&] { - HandleRasterizerDownload(addr_c2, count_c2); - }); ptr_c2) { - std::array result{}; - std::memcpy(result.data() + 0, ptr_c1, count_c1); - std::memcpy(result.data() + count_c1, ptr_c2, count_c2); - return std::bit_cast(result); - } - } + const u64 addr = GetInteger(vaddr); + if (auto const ptr = GetPointerImpl(addr, [addr]() { + LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, addr); + }, [&]() { + HandleRasterizerDownload(addr, sizeof(T)); + }); ptr) [[likely]] { + // It may be tempting to rewrite this particular section to use "reinterpret_cast"; + // afterall, it's trivially copyable so surely it can be copied ov- Alignment. + // Remember, alignment. memcpy() will deal with all the alignment extremely fast. + T result{}; + std::memcpy(&result, ptr, sizeof(T)); + return result; } return T{}; } @@ -690,37 +734,11 @@ struct Memory::Impl { /// @tparam T The data type to write to memory. template inline void Write(Common::ProcessAddress vaddr, const T data) noexcept requires(std::is_trivially_copyable_v) { - auto const addr_c1 = GetInteger(vaddr); - if (!(sizeof(T) > 1 && (addr_c1 & 4095) + sizeof(T) > 4096)) { - if (auto const ptr_c1 = GetPointerImpl(addr_c1, [addr_c1] { - LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, addr_c1); - }, [&] { - HandleRasterizerWrite(addr_c1, sizeof(T)); - }); ptr_c1) { - std::memcpy(ptr_c1, &data, sizeof(T)); - } - } else { - auto const addr_c2 = (addr_c1 & (~0xfff)) + 0x1000; - // page crossing: say if sizeof(T) = 2, vaddr = 4095 - // 4095 + 2 mod 4096 = 1 => 2 - 1 = 1, thus c1=1, c2=1 - auto const count_c2 = (addr_c1 + sizeof(T)) & 4095; - auto const count_c1 = sizeof(T) - count_c2; - if (auto const ptr_c1 = GetPointerImpl(addr_c1, [addr_c1] { - LOG_ERROR(HW_Memory, "Unmapped Write{} @ 0x{:016X}", sizeof(T) * 8, addr_c1); - }, [&] { - HandleRasterizerWrite(addr_c1, count_c1); - }); ptr_c1) { - if (auto const ptr_c2 = GetPointerImpl(addr_c2, [addr_c2] { - LOG_ERROR(HW_Memory, "Unmapped Write{} @ 0x{:016X}", sizeof(T) * 8, addr_c2); - }, [&] { - HandleRasterizerWrite(addr_c2, count_c2); - }); ptr_c2) { - std::array tmp = std::bit_cast>(data); - std::memcpy(ptr_c1, tmp.data() + 0, count_c1); - std::memcpy(ptr_c2, tmp.data() + count_c1, count_c2); - } - } - } + const u64 addr = GetInteger(vaddr); + if (auto const ptr = GetPointerImpl(addr, [addr, data]() { + LOG_ERROR(HW_Memory, "Unmapped Write{} @ 0x{:016X} = 0x{:016X}", sizeof(T) * 8, addr, u64(data)); + }, [&]() { HandleRasterizerWrite(addr, sizeof(T)); }); ptr) [[likely]] + std::memcpy(ptr, &data, sizeof(T)); } template @@ -924,35 +942,35 @@ const u8* Memory::GetPointer(Common::ProcessAddress vaddr) const { } u8 Memory::Read8(const Common::ProcessAddress addr) { - return impl->Read(addr); + return impl->Read8(addr); } u16 Memory::Read16(const Common::ProcessAddress addr) { - return impl->Read(addr); + return impl->Read16(addr); } u32 Memory::Read32(const Common::ProcessAddress addr) { - return impl->Read(addr); + return impl->Read32(addr); } u64 Memory::Read64(const Common::ProcessAddress addr) { - return impl->Read(addr); + return impl->Read64(addr); } void Memory::Write8(Common::ProcessAddress addr, u8 data) { - impl->Write(addr, data); + impl->Write8(addr, data); } void Memory::Write16(Common::ProcessAddress addr, u16 data) { - impl->Write(addr, data); + impl->Write16(addr, data); } void Memory::Write32(Common::ProcessAddress addr, u32 data) { - impl->Write(addr, data); + impl->Write32(addr, data); } void Memory::Write64(Common::ProcessAddress addr, u64 data) { - impl->Write(addr, data); + impl->Write64(addr, data); } bool Memory::WriteExclusive8(Common::ProcessAddress addr, u8 data, u8 expected) {