mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-25 12:36:20 +00:00
refactor: convert DLC string data directly to UTF-8 w/ simdutf
This commit is contained in:
@@ -5,13 +5,14 @@
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "platform/renderer/renderer.h"
|
||||
#include "platform/storage/storage.h"
|
||||
#include "DLCManager.h"
|
||||
#include "app/common/DLC/DLCFile.h"
|
||||
#include "app/linux/LinuxGame.h"
|
||||
#include "platform/XboxStubs.h"
|
||||
#include "platform/renderer/renderer.h"
|
||||
#include "platform/storage/storage.h"
|
||||
#include "util/StringHelpers.h"
|
||||
|
||||
#if defined(_WINDOWS64)
|
||||
#include "app/windows/XML/ATGXmlParser.h"
|
||||
#include "app/windows/XML/xmlFilesCallback.h"
|
||||
@@ -20,26 +21,6 @@
|
||||
namespace {
|
||||
constexpr std::size_t AUDIO_DLC_WCHAR_BIN_SIZE = 2;
|
||||
|
||||
#if WCHAR_MAX > 0xFFFF
|
||||
static std::wstring ReadAudioDlcWString(const void* data) {
|
||||
const std::uint16_t* chars = static_cast<const std::uint16_t*>(data);
|
||||
const std::uint16_t* end = chars;
|
||||
while (*end != 0) {
|
||||
++end;
|
||||
}
|
||||
|
||||
std::wstring out(static_cast<std::size_t>(end - chars), 0);
|
||||
for (std::size_t i = 0; i < out.size(); ++i) {
|
||||
out[i] = static_cast<wchar_t>(chars[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#else
|
||||
static std::wstring ReadAudioDlcWString(const void* data) {
|
||||
return std::wstring(static_cast<const wchar_t*>(data));
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
T ReadAudioDlcValue(const std::uint8_t* data, unsigned int offset = 0) {
|
||||
T value;
|
||||
@@ -59,14 +40,15 @@ inline unsigned int AudioParamAdvance(unsigned int wcharCount) {
|
||||
}
|
||||
|
||||
inline unsigned int AudioDetailAdvance(unsigned int wcharCount) {
|
||||
return static_cast<unsigned int>(sizeof(IPlatformStorage::DLC_FILE_DETAILS) +
|
||||
wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE);
|
||||
return static_cast<unsigned int>(
|
||||
sizeof(IPlatformStorage::DLC_FILE_DETAILS) +
|
||||
wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE);
|
||||
}
|
||||
|
||||
inline std::wstring ReadAudioParamString(const std::uint8_t* data,
|
||||
unsigned int offset) {
|
||||
return ReadAudioDlcWString(data + offset +
|
||||
offsetof(IPlatformStorage::DLC_FILE_PARAM, wchData));
|
||||
inline std::string ReadAudioParamString(const std::uint8_t* data,
|
||||
unsigned int offset) {
|
||||
return dlc_read_wstring(
|
||||
data + offset + offsetof(IPlatformStorage::DLC_FILE_PARAM, wchData));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -88,12 +70,13 @@ std::uint8_t* DLCAudioFile::getData(std::uint32_t& dataBytes) {
|
||||
return m_pbData;
|
||||
}
|
||||
|
||||
const wchar_t* DLCAudioFile::wchTypeNamesA[] = {
|
||||
L"CUENAME",
|
||||
L"CREDIT",
|
||||
const char* DLCAudioFile::wchTypeNamesA[] = {
|
||||
"CUENAME",
|
||||
"CREDIT",
|
||||
};
|
||||
|
||||
DLCAudioFile::EAudioParameterType DLCAudioFile::getParameterType(const std::wstring& paramName) {
|
||||
DLCAudioFile::EAudioParameterType DLCAudioFile::getParameterType(
|
||||
const std::string& paramName) {
|
||||
EAudioParameterType type = e_AudioParamType_Invalid;
|
||||
|
||||
for (int i = 0; i < e_AudioParamType_Max; ++i) {
|
||||
@@ -122,8 +105,8 @@ void DLCAudioFile::addParameter(EAudioType type, EAudioParameterType ptype,
|
||||
|
||||
int maximumChars = 55;
|
||||
|
||||
bool bIsSDMode =
|
||||
!PlatformRenderer.IsHiDef() && !PlatformRenderer.IsWidescreen();
|
||||
bool bIsSDMode = !PlatformRenderer.IsHiDef() &&
|
||||
!PlatformRenderer.IsWidescreen();
|
||||
|
||||
if (bIsSDMode) {
|
||||
maximumChars = 45;
|
||||
@@ -202,8 +185,7 @@ bool DLCAudioFile::processDLCDataFile(std::uint8_t* pbData,
|
||||
for (unsigned int i = 0; i < uiParameterTypeCount; i++) {
|
||||
// Map DLC strings to application strings, then store the DLC index
|
||||
// mapping to application index
|
||||
std::wstring parameterName =
|
||||
ReadAudioParamString(pbData, uiCurrentByte);
|
||||
std::string parameterName = ReadAudioParamString(pbData, uiCurrentByte);
|
||||
EAudioParameterType type = getParameterType(parameterName);
|
||||
if (type != e_AudioParamType_Invalid) {
|
||||
parameterMapping[paramBuf.dwType] = type;
|
||||
@@ -238,7 +220,7 @@ bool DLCAudioFile::processDLCDataFile(std::uint8_t* pbData,
|
||||
|
||||
if (it != parameterMapping.end()) {
|
||||
addParameter(type, (EAudioParameterType)paramBuf.dwType,
|
||||
wstringtofilename(ReadAudioParamString(pbTemp, 0)));
|
||||
ReadAudioParamString(pbTemp, 0));
|
||||
}
|
||||
pbTemp += AudioParamAdvance(paramBuf.dwWchCount);
|
||||
ReadAudioDlcStruct(¶mBuf, pbTemp);
|
||||
|
||||
Reference in New Issue
Block a user