SeanPesce / DXMD-Translations

Language translation framework for Deus Ex: Mankind Divided and Deus Ex: Breach
GNU General Public License v2.0
3 stars 1 forks source link

Dynamic memory allocation for custom fonts #11

Open SeanPesce opened 3 months ago

SeanPesce commented 3 months ago

For some reason, attempting to load custom fonts from a dynamically-allocated buffer fails. I'm currently using a hard-coded, pre-allocated 50MB buffer to hold custom font data (see here). This is obviously suboptimal, as most custom fonts are under 5MB, but the font with Chinese characters is ~45MB. Preferably, an appropriately-sized buffer should be allocated for the specific font file in use.

So far, I've tried the following methods of dynamic memory allocation, and although the memory appears to be allocated correctly, the game behaves as if no font was loaded (all characters are broken/missing):

ui_font_buf = new uint8_t[buf_sz]();
ui_font_buf = (uint8_t*)malloc(buf_sz);
ui_font_buf = (uint8_t*)CoTaskMemAlloc(buf_sz);
ui_font_buf = (uint8_t*)GlobalAlloc(GPTR, buf_sz);
ui_font_buf = (uint8_t*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buf_sz);
ui_font_buf = (uint8_t*)LocalAlloc(LPTR, buf_sz);

If I had to guess, the game might have some kind of custom memory allocator that's messing with my code/data. I've also confirmed that this issue exists on the Steam and GoG builds of the game, so it's probably not related to the weird packing behavior of the Steam release.