Commit Graph

10620 Commits

Author SHA1 Message Date
Collecting
f6b8535bef fix(fs): prevent stack exhaustion in save mirroring recursion
- Moved the copy buffer to the heap via std::make_unique.

- Added explicit null-safety and system shutdown checks to mirroring logic.

- Hardened recursion guards during directory traversal to ensure stability.

Signed-off-by: Collecting <collecting@noreply.localhost>
2026-01-01 21:44:31 +00:00
Zephyron
d8c1cad245 fix(service/nvnflinger): implement GetBufferHistory to prevent game hangs
Return empty buffer history list instead of stubbing to allow games to
proceed past loading screens.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-31 16:58:05 +10:00
Collecting
678d6c095f feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:59:31 +00:00
Collecting
1ca62a0302 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:58:49 +00:00
Collecting
bbd74891fd feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:58:00 +00:00
Collecting
63e48d9191 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:57:15 +00:00
Collecting
4a81f4ff83 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:56:04 +00:00
Collecting
dee84bd8a3 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:55:03 +00:00
Collecting
4f4b3a9360 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:51:44 +00:00
Collecting
1820ed7815 feat(fs): Cross-Compatible Emulator Save Pathing w/ Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-31 03:50:58 +00:00
Collecting
2e8d5992a2 feat(fs): Implement Global Custom Save Path
Added a "Global Custom Save Path" configuration option in the Filesystem settings.

Implemented a prioritized save-loading hierarchy: Global Path (if enabled) > Per-Game Custom Path > Default NAND.

Introduced a non-destructive migration tool that allows users to consolidate their existing saves into the new global location.

The migration tool specifically prioritizes per-game custom saves over NAND saves to ensure the most up-to-date data is preserved during consolidation.

The migration process is copy-only; no data is deleted from the source directories, ensuring absolute user data safety.

Maintained compatibility with the existing "Backup Saves to NAND" feature, ensuring saves continue to be mirrored internally if configured.

Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-29 01:12:50 +00:00
Collecting
8506c7c394 fix: Strict Clang Rule
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-26 22:46:50 +00:00
Collecting
499a82d3fd fix: Strict Clang Rule
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-26 22:45:59 +00:00
Zephyron
cc60303b11 feat(core): Update HOS and NintendoSDK version constants
- Bumps HOS version from 20.1.5 to 21.0.0
- Updates the corresponding `VERSION_HASH`, `DISPLAY_VERSION`, and
  `DISPLAY_TITLE` strings.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-26 17:02:15 +10:00
Zephyron
aad942cf25 fix(network): revert to legacy packet format for emulator compatibility
Remove the 'reliable' boolean field from LDNPacket and ProxyPacket
structs and all associated serialization/deserialization logic.
All packets now use reliable delivery by default via ENet layer,
matching the legacy format for full backward compatibility.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-26 16:54:31 +10:00
Zephyron
14c97aebb7 fix(ldn): improve packet validation and debug logging
- Add size validation before memcpy for Connect/Disconnect packets
- Allow empty data for Scan packets (Type 0) which have no payload
- Add debug logging for ScanResp packets including BSSID and results
- Fix MacAddress indexing to use .raw[] instead of [] operator

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-26 16:53:26 +10:00
Zephyron
499b3c1a59 fix(fatal): handle unknown error module 359 gracefully
Handle error 2359-2618 (module 359, description 2618) gracefully
by logging a warning instead of crashing, similar to module 56.
This allows games like SSBU to continue execution when encountering
this error code.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-26 16:52:33 +10:00
Zephyron
38d4152021 fix(network): improve ZSTD compression/decompression error handling
- Add error checking after decompression to drop corrupted packets
- Add error checking after compression to prevent sending empty packets
- Allow ZSTD_CONTENTSIZE_UNKNOWN and use streaming decompression
- Only reject ZSTD_CONTENTSIZE_ERROR as a fatal error

Fixes network connectivity issues where corrupted/empty packets were
being processed, breaking the network protocol.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-26 16:51:33 +10:00
Collecting
3dee7e3015 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:40:51 +00:00
Collecting
9407a5ba94 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:40:29 +00:00
Collecting
625e1d3229 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:39:59 +00:00
Collecting
42c237dc4a fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:39:20 +00:00
Collecting
7ad7d8ada6 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:38:42 +00:00
Collecting
16f928df79 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:37:57 +00:00
Collecting
67bf3b53b7 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:37:21 +00:00
Collecting
ddddb28c54 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:36:49 +00:00
Collecting
f4d712d497 fs(feat): Add Backup Saves for Custom Save Paths
Signed-off-by: Collecting <collecting@noreply.localhost>
2025-12-22 08:35:57 +00:00
Zephyron
5eed2b221b fix(nvdrv): prevent infinite loop and improve error handling when SMMU address space is exhausted
Fix crash in PinHandle when SMMU allocation fails and unmap queue is empty.
Previously, the code would log an error and continue looping indefinitely,
causing log spam and eventual crash.

- Free multiple handles from unmap queue (up to 100) before giving up
- Add maximum attempt counter to prevent infinite loops
- Return 0 gracefully when no more handles can be freed
- Add error handling in callers (Remap, MapBufferEx, MapBuffer) to check for
  PinHandle failure and return NvResult::InsufficientMemory instead of using
  invalid addresses

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-16 16:44:13 +10:00
Zephyron
dadf9d270c fix(nvdrv): prevent infinite loop when SMMU address space is exhausted
Fix crash in PinHandle when SMMU allocation fails and unmap queue is empty.
Previously, the code would log an error and continue looping indefinitely,
causing log spam and eventual crash. Now it returns 0 to fail gracefully.

Also fix incorrect handle check on line 219 - should check freeHandleDesc
instead of handle_description.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-16 16:24:15 +10:00
Zephyron
34800248cc fix(video_core): Replace assertions with warnings in Fermi2D and BSD sockets
- Fermi2D: Log warnings for unsupported operations, layers, depth, and clip
- BSD sockets: Return INVAL for unimplemented getsockopt optnames instead of SUCCESS

Co-authored-by: JPikachu <jpikachu.eden@gmail.com>
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-12-08 17:03:51 +10:00
Zephyron
90eeee345c feat(filesystem): add custom save path support per game
- Add custom_save_paths map to Settings::Values
- Implement ReadCustomSavePathValues and SaveCustomSavePathValues in Config
- Update CreateSaveDataFactory to check for custom save paths
- Support per-game title ID save path overrides

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-28 16:11:07 +10:00
Zephyron
a1b317a15e fix: add Module 56 error support and improve error handling
- Add Module56 to ErrorModule enum for error code 2056-2306
- Add Module 56 error handling in fatal error reporting
- Define Module 56 error codes in ldn_results.h
- Improve error reporting for unknown modules

This allows the emulator to properly handle error code 2056-2306
reported by Minecraft and other games, preventing undefined
behavior when encountering unknown module errors.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-13 20:14:04 +10:00
Zephyron
19faff40cd fix: socket assertion crashes and add Nex service stub
- Replace socket option assertion failures with proper error returns
- Add WSAENOPROTOOPT/ENOPROTOOPT error handling
- Fix LINGER and option value size validation
- Add Network::Errno::OTHER translation
- Implement basic Nex service stub for error code 2306-0520

Fixes crashes in Minecraft and other games when encountering unsupported
socket operations or attempting to use Nintendo's online services.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-13 19:30:40 +10:00
Zephyron
69f3225fa8 fix: correct Little Nightmares 3 TitleID check for PC to LR recovery
The TitleID check was broken due to using || operator which evaluated
to 1 instead of a title ID value, preventing the recovery mechanism
from working.

- Fix title_ids.h: Replace incorrect || expression with proper
  LittleNightmares3Base constant (0x010066101A55A000)
- Update physical_core.cpp: Use GetBaseTitleID() to match both
  base and update title ID variants

This now correctly identifies Little Nightmares 3 and enables the
recovery mechanism that sets PC to LR when detecting null pointer
execution loops.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-11 20:05:07 +10:00
Zephyron
d59eb9a1a8 Add Firmware 20.0.0-21.0.0 IPC support and stubs
This commit implements comprehensive firmware 20.0.0 through 21.0.0
support for Citron, including:

- Updated firmware version constants to 21.0.0 in api_version.h
- Updated HID service firmware version string to 21.0.0
- Added IPC command stubs for firmware 20.0.0+ in:
  * ISystemSettingsServer (commands 263, 264, 282, 283, 289, 300, 301, 306, 307)
  * IFirmwareDebugSettingsServer (command 24)
  * IApplicationFunctions (command 330)
  * IOlscServiceForSystemService (command 914)
  * IRemoteStorageController (commands 28, 901)
  * IService (migration) (commands 2250, 2260)
  * IAudioController (command 10200)

- Created new service interfaces with proper stubs:
  * IContinuousRecorder (grcsrv) - command 5 [20.2.0+] with 0x20-byte input
  * IDownloadContext (news) - command 4 [20.0.0+]
  * INotifyService (pdm:ntfy) - commands 100, 101 [20.0.0+] returning outinterfaces

- Added all new source files to CMakeLists.txt build system
- Fixed logging tag usage (Service_Migration instead of Service_MIG)
- Added required CMIF serialization headers for proper template instantiation

All stubs return success explicitly, eliminating the need for auto-stubbing.
All implementations follow Switchbrew documentation as closely as possible.

Based on Switchbrew documentation:
- https://switchbrew.org/wiki/21.0.0
- https://switchbrew.org/wiki/20.5.0
- https://switchbrew.org/wiki/20.4.0
- https://switchbrew.org/wiki/20.3.0
- https://switchbrew.org/wiki/20.2.0
- https://switchbrew.org/wiki/20.1.5
- https://switchbrew.org/wiki/20.1.1
- https://switchbrew.org/wiki/20.1.0
- https://switchbrew.org/wiki/20.0.1
- https://switchbrew.org/wiki/20.0.0

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-11 18:52:10 +10:00
Zephyron
85a41cba46 Fix: Make PC return recovery title-specific for Little Nightmares 3
The PC < 0x1000 recovery mechanism introduced in commit fbb4f5c0
was causing issues for other games. This change restricts the recovery
to only apply when the title ID matches Little Nightmares 3.

- Add LittleNightmares3 title ID constant to title_ids.h
- Check program ID before applying PC return recovery in physical_core.cpp
- Recovery now only triggers for Little Nightmares 3 (010066101A55A800)
  to avoid affecting other games

Fixes issues caused by the general PC return recovery in other titles.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-10 20:00:55 +10:00
Zephyron
be5c2f772c fix: Multiplayer network fixes and airplane mode
- Auto-select network interface for direct connect/host room
- Always recreate ENet client on join for fresh bindings
- Add airplane mode toggle (Desktop & Android)
- Fix JWT verification with empty verify_uid
- Improve content-type handling for JWT endpoints

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-10 17:16:45 +10:00
Zephyron
09f8c3a643 feat(ui): add per-game cheat management tab with bulk toggle controls
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-07 19:17:07 +10:00
Zephyron
5117ff3702 feat: implement multiplayer networking improvements for reduced latency
Major networking enhancements to improve multiplayer performance and
reduce desync issues in games like Mario Kart 8 Deluxe:

Network Performance:
- Add socket connection pooling in BSD service to reduce overhead
- Implement unreliable packet delivery for latency-sensitive game data
- Add packet reliability control for both ProxyPacket and LDNPacket
- Use ENET_PACKET_FLAG_UNSEQUENCED for small UDP packets (<1200 bytes)

Monitoring & Debugging:
- Add PacketStatistics struct to track sent/received/dropped packets
- Enhanced logging for proxy packet handling and socket lifecycle
- Periodic stats logging every 100 packets for diagnostics

Configuration:
- Update lobby_api_url and web_api_url to https://api.ynet-fun.xyz
- Add lobby API URL configuration support

Socket Management:
- Implement SocketPoolKey for efficient socket reuse
- Store domain/type/protocol info in FileDescriptor
- Max pool size limit (8 sockets per type) to prevent memory bloat
- Return closed sockets to pool when room is still connected

Protocol Updates:
- Add 'reliable' field to ProxyPacket and LDNPacket structures
- Update room.cpp packet handlers to respect reliability flags
- Maintain backward compatibility with default reliable=true

These changes significantly reduce packet latency for real-time game
traffic while maintaining reliability for control packets.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-05 18:52:06 +10:00
Zephyron
4211689683 fix(set): stub ISettingsServer function 12 to fix AVGN 8-bit crash
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-04 17:43:52 +10:00
Zephyron
a5024bb218 kernel: Use CheckMemoryStateContiguous in UnmapCodeMemory
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-03 16:19:46 +10:00
Zephyron
5af5ba2d0e chore(CMake): Remove
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-01 22:10:50 +10:00
Zephyron
3d0ccc1db1 Fix Windows auto updater with deferred update helper and TLS support
Windows auto updater failed due to:
1. File locking - can't overwrite running .exe files
2. Missing Qt 6 TLS plugins - can't connect via HTTPS

Solution:
- Implement helper batch script that applies updates after app exits
- Automate TLS plugin copying in CMake (qschannelbackend.dll, qopensslbackend.dll)
- Add enhanced SSL debugging and error messages

Windows updates now work. Linux continues to work as before.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-01 21:56:37 +10:00
Zephyron
ec670d881c hle: Improve network service implementations and add newer firmware stubs
AM (Application Manager):
- Implement GetPseudoDeviceId with deterministic UUID generation
- Generate persistent device ID based on program ID for online play

LDN (Local Network):
- Implement stub for Reject (cmd 205)
- Implement stub for ClearAcceptFilter (cmd 209)
- Implement stub for ConnectPrivate (cmd 303)

NIFM (Network Interface):
- Fix RequestState enum values (Invalid=0, Free=1) per switchbrew
- Add ConnectionConfirmationOption enum
- Update NotSubmitted references to Free state
- Implement 13 new stub functions for firmware 18.0.0-20.0.0+
- Reduce log verbosity for frequently-called functions

BSD (Sockets):
- Improve RegisterClient to parse LibraryConfigData structure
- Enhance socket operation logging (Socket, Bind, Connect)
- Add detailed error logging for bind/connect failures
- Implement stubs for Unknown36-38 (18.0.0+)
- Add firmware version comments for commands

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-01 18:47:15 +10:00
Zephyron
76e963bfe7 kernel: Implement code address offset for Skyline compatibility
Add support for the Skyline 32-bit modding framework by implementing
a code address offset and improving memory state verification.

Changes:
- Add CodeStartOffset constant (0x500000) applied to 32-bit code
  address space types (Is32Bit and Is32BitNoMap) in KProcess::LoadFromMetadata
- Add debug logging for 32-bit syscall argument tracking in
  SetProcessMemoryPermission, MapProcessCodeMemory, and
  UnmapProcessCodeMemory wrapper functions
- Replace CheckMemoryStateContiguous with CheckMemoryState in
  KPageTableBase::UnmapCodeMemory for more flexible memory state
  verification

This implementation enables compatibility with:
- Skyline 32-bit modding framework
- CTGP-DX (Mario Kart 8 Deluxe mod)
- Other homebrew using 32-bit Skyline

Based on similar fixes in Ryujinx (commit 5e9678c8fe) and Eden emulator.

Co-authored-by: JPikachu <jpikachu.eden@gmail.com>
Co-authored-by: JPikachu <jpikachu@eden-emu.dev>
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-11-01 15:44:21 +10:00
Zephyron
68a8b07f78 feat(ldn): Implement missing Account and LDN services from SwitchBrew documentation
Implements 150+ missing functions across Account (acc:*) and LDN (ldn:*, lp2p:*)
services based on official SwitchBrew documentation.

Account Services (acc:su, acc:e, acc:u0, acc:u1, acc:e:u1, acc:e:u2, dauth:0):
- Add 70+ missing functions including notifiers, async operations, and OAuth procedures
- Implement GetUserRegistrationNotifier, GetUserStateChangeNotifier, GetProfileUpdateNotifier
- Add thumbnail management (LoadSaveDataThumbnail, GetSaveDataThumbnailExistence)
- Implement user management (DeleteUser, SetUserPosition, CancelUserRegistration)
- Add Nintendo Account procedures (CreateFloatingRegistrationRequest, etc.)
- Implement device migration functions (19.0.0+, 20.0.0+)
- Add debug functions for user qualification and token cache management

IManagerForApplication/SystemService (19.0.0+ compatibility):
- Rename LoadIdTokenCache (cmd 3) to LoadIdTokenCacheDeprecated
- Add new LoadIdTokenCache (cmd 4) with updated signature
- Add GetNintendoAccountUserResourceCache (cmd 136)

LDN Services (ldn:m, ldn:s, ldn:u):
- Add 80+ missing functions across all LDN interfaces
- Implement CreateClientProcessMonitor (cmd 1) for ldn:s and ldn:u (18.0.0+)
- Create IClientProcessMonitor service with RegisterClient function
- Implement IMonitorService functions (GetNetworkInfoForMonitor, GetIpv4AddressForMonitor, etc.)
- Implement ISystemLocalCommunicationService (GetState, Scan, Connect, Initialize, etc.)

LP2P Services (lp2p:app, lp2p:sys, lp2p:m):
- Implement ISfService functions (Initialize, Scan, CreateGroup, etc.)
- Implement ISfServiceMonitor (GetGroupInfo, GetMembers, AttachJoinEvent, etc.)
- Implement ISfMonitorService (GetLinkLevel)

Technical Changes:
- Change non-domain (C<>) to domain (D<>) functions in LDN to fix crashes
- Add enhanced error messaging to cmif_serialization.h for debugging
- Create client_process_monitor.cpp/.h for IClientProcessMonitor
- Add concrete async context implementations (EnsureSignedDeviceIdentifierCacheAsyncInterface, etc.)
- Add Kernel::KReadableEvent forward declarations

All functions properly stubbed with appropriate logging for future implementation.

References:
- https://switchbrew.org/wiki/Account_services
- https://switchbrew.org/wiki/LDN_services

Fixes 'Pokemon: Legends Z-A' LDN initialization crashes and improves compatibility
with games using Account and Local Network services.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-10-30 19:32:07 +10:00
Zephyron
20250c3e31 fix: add missing NCA encryption type support and patch handling
Changes:
- Add missing encryption type cases to all switch statements
- Only call CreatePatchMetaStorage() when both tables are present
- Update assertions to allow partial table combinations

Fixes loading for Hades II, Pokémon Legends: Z-A, and other games
with newer NCA structures.

Reported-by: Dr.Stug@citron-emu.org
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-10-24 16:25:38 +10:00
Zephyron
4c7ee4ac3b fix: BSD socket assertion failure in PollImpl
Initialize PollFD.revents field to prevent assertion failures when
copying from read buffer. The assertion was failing because revents
contained uninitialized data from the buffer.

Thanks to Dr.Stug for providing the logs that identified this issue.

Fixes assertion failure at core\hle\service\sockets\bsd.cpp:564

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-10-22 20:47:24 +10:00
Zephyron
9c13799b49 kernel: Add 12 GiB heap support
- Increased heap region from 8 GiB to 12 GiB
- Fixed memory manager page reference count allocation
- Made resource region sizing dynamic for >8GB DRAM
- Increased physical address space bits to support 16GB

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-10-22 15:06:47 +10:00
Zephyron
8cc5aa143f fix: implement DeleteCacheStorage stub to prevent TOTK crashes
- Add stubbed DeleteCacheStorage function to FSP_SRV service
- Return success instead of causing assertion failure
- Prevents userspace PANIC when games attempt to delete cache storage

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-10-22 13:25:16 +10:00