Skip to content

Commit

Permalink
Merge branch 'xenia-canary:canary_experimental' into New_XMA
Browse files Browse the repository at this point in the history
  • Loading branch information
backgamon authored Oct 25, 2023
2 parents 7b155ab + ebdea6b commit a88a59f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
22 changes: 21 additions & 1 deletion src/xenia/kernel/achievement_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ DECLARE_int32(user_language);
namespace xe {
namespace kernel {

AchievementManager::AchievementManager(){};
AchievementManager::AchievementManager() { unlocked_achievements.clear(); };

void AchievementManager::EarnAchievement(uint64_t xuid, uint32_t title_id,
uint32_t achievement_id) {
if (IsAchievementUnlocked(achievement_id)) {
return;
}

const Emulator* emulator = kernel_state()->emulator();
ui::WindowedAppContext& app_context =
kernel_state()->emulator()->display_window()->app_context();
Expand All @@ -48,6 +52,7 @@ void AchievementManager::EarnAchievement(uint64_t xuid, uint32_t title_id,
const std::string description =
fmt::format("{}G - {}", entry.gamerscore, label);

unlocked_achievements[achievement_id] = Clock::QueryHostSystemTime();
// Even if we disable popup we still should store info that this
// achievement was earned.
if (!cvars::show_achievement_notification) {
Expand All @@ -63,5 +68,20 @@ void AchievementManager::EarnAchievement(uint64_t xuid, uint32_t title_id,
}
}

bool AchievementManager::IsAchievementUnlocked(uint32_t achievement_id) {
auto itr = unlocked_achievements.find(achievement_id);

return itr != unlocked_achievements.cend();
}

uint64_t AchievementManager::GetAchievementUnlockTime(uint32_t achievement_id) {
auto itr = unlocked_achievements.find(achievement_id);
if (itr == unlocked_achievements.cend()) {
return 0;
}

return itr->second;
}

} // namespace kernel
} // namespace xe
5 changes: 5 additions & 0 deletions src/xenia/kernel/achievement_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_ACHIEVEMENT_MANAGER_H_
#define XENIA_KERNEL_ACHIEVEMENT_MANAGER_H_

#include <map>
#include <string>
#include <vector>

Expand All @@ -25,7 +26,11 @@ class AchievementManager {
void EarnAchievement(uint64_t xuid, uint32_t title_id,
uint32_t achievement_id);

bool IsAchievementUnlocked(uint32_t achievement_id);
uint64_t GetAchievementUnlockTime(uint32_t achievement_id);

private:
std::map<uint32_t, uint64_t> unlocked_achievements;
// void Load();
// void Save();
};
Expand Down
12 changes: 10 additions & 2 deletions src/xenia/kernel/xam/xam_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,23 @@ dword_result_t XamUserCreateAchievementEnumerator_entry(
db.GetAchievements();

for (const util::XdbfAchievementTableEntry& entry : achievement_list) {
auto is_unlocked =
kernel_state()->achievement_manager()->IsAchievementUnlocked(
entry.id);
auto unlock_time =
kernel_state()->achievement_manager()->GetAchievementUnlockTime(
entry.id);

auto item = XStaticAchievementEnumerator::AchievementDetails{
entry.id,
xe::to_utf16(db.GetStringTableEntry(language, entry.label_id)),
xe::to_utf16(db.GetStringTableEntry(language, entry.description_id)),
xe::to_utf16(db.GetStringTableEntry(language, entry.unachieved_id)),
entry.image_id,
entry.gamerscore,
{0, 0},
entry.flags};
(uint32_t)(unlock_time << 31),
(uint32_t)unlock_time,
is_unlocked ? entry.flags | 0x20000 : entry.flags};

e->AppendItem(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void VdQueryVideoMode(X_VIDEO_MODE* video_mode) {
video_mode->is_interlaced = 0;
video_mode->is_widescreen =
((video_mode->display_width / 4) > (video_mode->display_height / 3));
video_mode->is_hi_def = 1;
video_mode->is_hi_def = video_mode->display_width >= 0x400;
video_mode->refresh_rate = 60.0f;
video_mode->video_standard = 1; // NTSC
video_mode->unknown_0x8a = 0x4A;
Expand Down

0 comments on commit a88a59f

Please sign in to comment.