[XAM/User] Added descriptions and labels for achievements

Disclaimer: On old dash it causes memleak (slight),
newer dashboards allocates them only once which is solution for that.

Ps. If anyone have easy solution please implement it. Cheers
This commit is contained in:
Gliniak 2019-12-23 18:57:02 +01:00 committed by illusion
parent 13a019f637
commit 997d2eb7bd
3 changed files with 21 additions and 16 deletions

View File

@ -610,19 +610,6 @@ dword_result_t XamUserCreateAchievementEnumerator(dword_t title_id,
return X_ERROR_SUCCESS; return X_ERROR_SUCCESS;
} }
static uint32_t placeholder = 0;
if (!placeholder) {
const wchar_t* placeholder_val = L"<placeholder>";
placeholder = kernel_memory()->SystemHeapAlloc(
((uint32_t)wcslen(placeholder_val) + 1) * 2);
auto* place_addr = kernel_memory()->TranslateVirtual<wchar_t*>(placeholder);
memset(place_addr, 0, (wcslen(placeholder_val) + 1) * 2);
xe::copy_and_swap(place_addr, placeholder_val, wcslen(placeholder_val));
}
std::vector<xdbf::Achievement> achievements; std::vector<xdbf::Achievement> achievements;
game_gpd->GetAchievements(&achievements); game_gpd->GetAchievements(&achievements);
@ -638,9 +625,14 @@ dword_result_t XamUserCreateAchievementEnumerator(dword_t title_id,
// very bad... // very bad...
// maybe we could alloc these in guest when the title GPD is first loaded? // maybe we could alloc these in guest when the title GPD is first loaded?
details->label_ptr = placeholder; // Only the 1888 dashboard reallocates them every time
details->description_ptr = placeholder; // Newer dashes allocates this only once
details->unachieved_ptr = placeholder; details->label_ptr =
kernel_memory()->AllocSpaceForWStringInSystemHeap(ach.label);
details->description_ptr =
kernel_memory()->AllocSpaceForWStringInSystemHeap(ach.description);
details->unachieved_ptr =
kernel_memory()->AllocSpaceForWStringInSystemHeap(ach.unachieved_desc);
} }
XELOGD("XamUserCreateAchievementEnumerator: added %d items to enumerator", XELOGD("XamUserCreateAchievementEnumerator: added %d items to enumerator",

View File

@ -1828,4 +1828,14 @@ uint32_t PhysicalHeap::GetPhysicalAddress(uint32_t address) const {
return address; return address;
} }
uint32_t Memory::AllocSpaceForWStringInSystemHeap(std::wstring phrase) {
uint32_t address = SystemHeapAlloc((uint32_t)phrase.size());
auto* place_addr = TranslateVirtual<wchar_t*>(address);
memset(place_addr, 0, (uint32_t)phrase.size());
xe::copy_and_swap(place_addr, phrase.c_str(), (uint32_t)phrase.size());
return address;
}
} // namespace xe } // namespace xe

View File

@ -465,6 +465,9 @@ class Memory {
// Gets the physical base heap. // Gets the physical base heap.
VirtualHeap* GetPhysicalHeap(); VirtualHeap* GetPhysicalHeap();
// Allocate space for wstring in memory and returns its address
uint32_t AllocSpaceForWStringInSystemHeap(std::wstring phrase);
// Dumps a map of all allocated memory to the log. // Dumps a map of all allocated memory to the log.
void DumpMap(); void DumpMap();