Merge pull request #1244 from emoose/bugfixes

[Kernel] Fixes for _snwprintf and xmp_app
This commit is contained in:
Rick Gibbed 2018-10-22 12:30:10 -05:00 committed by GitHub
commit 1ae9b8263d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 33 deletions

View File

@ -55,34 +55,41 @@ X_RESULT XmpApp::XMPCreateTitlePlaylist(uint32_t songs_ptr, uint32_t song_count,
playlist->handle = ++next_playlist_handle_; playlist->handle = ++next_playlist_handle_;
playlist->name = std::move(playlist_name); playlist->name = std::move(playlist_name);
playlist->flags = flags; playlist->flags = flags;
for (uint32_t i = 0; i < song_count; ++i) { if (songs_ptr) {
auto song = std::make_unique<Song>(); for (uint32_t i = 0; i < song_count; ++i) {
song->handle = ++next_song_handle_; auto song = std::make_unique<Song>();
uint8_t* song_base = memory_->TranslateVirtual(songs_ptr + (i * 36)); song->handle = ++next_song_handle_;
song->file_path = xe::load_and_swap<std::wstring>( uint8_t* song_base = memory_->TranslateVirtual(songs_ptr + (i * 36));
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 0))); song->file_path =
song->name = xe::load_and_swap<std::wstring>( xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 4))); xe::load_and_swap<uint32_t>(song_base + 0)));
song->artist = xe::load_and_swap<std::wstring>( song->name = xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 8))); xe::load_and_swap<uint32_t>(song_base + 4)));
song->album = xe::load_and_swap<std::wstring>( song->artist = xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 12))); xe::load_and_swap<uint32_t>(song_base + 8)));
song->album_artist = xe::load_and_swap<std::wstring>( song->album = xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 16))); xe::load_and_swap<uint32_t>(song_base + 12)));
song->genre = xe::load_and_swap<std::wstring>( song->album_artist =
memory_->TranslateVirtual(xe::load_and_swap<uint32_t>(song_base + 20))); xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
song->track_number = xe::load_and_swap<uint32_t>(song_base + 24); xe::load_and_swap<uint32_t>(song_base + 16)));
song->duration_ms = xe::load_and_swap<uint32_t>(song_base + 28); song->genre = xe::load_and_swap<std::wstring>(memory_->TranslateVirtual(
song->format = xe::load_and_swap<uint32_t>(song_base + 20)));
static_cast<Song::Format>(xe::load_and_swap<uint32_t>(song_base + 32)); song->track_number = xe::load_and_swap<uint32_t>(song_base + 24);
if (out_song_handles) { song->duration_ms = xe::load_and_swap<uint32_t>(song_base + 28);
xe::store_and_swap<uint32_t>( song->format = static_cast<Song::Format>(
memory_->TranslateVirtual(out_song_handles + (i * 4)), song->handle); xe::load_and_swap<uint32_t>(song_base + 32));
if (out_song_handles) {
xe::store_and_swap<uint32_t>(
memory_->TranslateVirtual(out_song_handles + (i * 4)),
song->handle);
}
playlist->songs.emplace_back(std::move(song));
} }
playlist->songs.emplace_back(std::move(song));
} }
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(out_playlist_handle), if (out_playlist_handle) {
playlist->handle); xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(out_playlist_handle),
playlist->handle);
}
auto global_lock = global_critical_region_.Acquire(); auto global_lock = global_critical_region_.Acquire();
playlists_.insert({playlist->handle, playlist.get()}); playlists_.insert({playlist->handle, playlist.get()});
@ -404,12 +411,19 @@ X_RESULT XmpApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr,
assert_true(xmp_client == 0x00000002); assert_true(xmp_client == 0x00000002);
XELOGD("XMPGetPlaybackBehavior(%.8X, %.8X, %.8X)", playback_mode_ptr, XELOGD("XMPGetPlaybackBehavior(%.8X, %.8X, %.8X)", playback_mode_ptr,
repeat_mode_ptr, unk3_ptr); repeat_mode_ptr, unk3_ptr);
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(playback_mode_ptr), if (playback_mode_ptr) {
static_cast<uint32_t>(playback_mode_)); xe::store_and_swap<uint32_t>(
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(repeat_mode_ptr), memory_->TranslateVirtual(playback_mode_ptr),
static_cast<uint32_t>(repeat_mode_)); static_cast<uint32_t>(playback_mode_));
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(unk3_ptr), }
unknown_flags_); if (repeat_mode_ptr) {
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(repeat_mode_ptr),
static_cast<uint32_t>(repeat_mode_));
}
if (unk3_ptr) {
xe::store_and_swap<uint32_t>(memory_->TranslateVirtual(unk3_ptr),
unknown_flags_);
}
return X_ERROR_SUCCESS; return X_ERROR_SUCCESS;
} }
case 0x0007002E: { case 0x0007002E: {

View File

@ -925,7 +925,7 @@ SHIM_CALL _snwprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
StackArgList args(ppc_context, 3); StackArgList args(ppc_context, 3);
WideStringFormatData data(format); WideStringFormatData data(format);
int32_t count = format_core(ppc_context, data, args, false); int32_t count = format_core(ppc_context, data, args, true);
if (count < 0) { if (count < 0) {
if (buffer_count > 0) { if (buffer_count > 0) {
buffer[0] = '\0'; // write a null, just to be safe buffer[0] = '\0'; // write a null, just to be safe