Downgrade to C++20 & switch to fmtlib.

This commit is contained in:
Skyth 2024-12-13 18:54:05 +03:00
parent 1ab25d5b41
commit 4b728f4a2b
21 changed files with 70 additions and 69 deletions

View file

@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 3.20)
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
set(SWA_THIRDPARTY_ROOT ${CMAKE_SOURCE_DIR}/thirdparty) set(SWA_THIRDPARTY_ROOT ${CMAKE_SOURCE_DIR}/thirdparty)
set(SWA_TOOLS_ROOT ${CMAKE_SOURCE_DIR}/tools) set(SWA_TOOLS_ROOT ${CMAKE_SOURCE_DIR}/tools)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 20)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
# Enable Hot Reload for MSVC compilers if supported. # Enable Hot Reload for MSVC compilers if supported.

View file

@ -226,6 +226,7 @@ find_package(magic_enum CONFIG REQUIRED)
find_package(unofficial-tiny-aes-c CONFIG REQUIRED) find_package(unofficial-tiny-aes-c CONFIG REQUIRED)
find_package(nfd CONFIG REQUIRED) find_package(nfd CONFIG REQUIRED)
find_package(Vorbis CONFIG REQUIRED) find_package(Vorbis CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12)
add_custom_command(TARGET UnleashedRecomp POST_BUILD add_custom_command(TARGET UnleashedRecomp POST_BUILD
@ -266,6 +267,7 @@ target_link_libraries(UnleashedRecomp PRIVATE
nfd::nfd nfd::nfd
msdf-atlas-gen::msdf-atlas-gen msdf-atlas-gen::msdf-atlas-gen
Vorbis::vorbisfile Vorbis::vorbisfile
fmt::fmt
) )
target_include_directories(UnleashedRecomp PRIVATE target_include_directories(UnleashedRecomp PRIVATE

View file

@ -48,7 +48,7 @@ namespace Hedgehog::Base
do do
{ {
originalValue = RefCountAndLength.value; originalValue = RefCountAndLength.value;
incrementedValue = std::byteswap(std::byteswap(originalValue) + 1); incrementedValue = ByteSwap(ByteSwap(originalValue) + 1);
} while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&RefCountAndLength), incrementedValue, originalValue) != originalValue); } while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&RefCountAndLength), incrementedValue, originalValue) != originalValue);
} }
@ -58,7 +58,7 @@ namespace Hedgehog::Base
do do
{ {
originalValue = RefCountAndLength.value; originalValue = RefCountAndLength.value;
decrementedValue = std::byteswap(std::byteswap(originalValue) - 1); decrementedValue = ByteSwap(ByteSwap(originalValue) - 1);
} while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&RefCountAndLength), decrementedValue, originalValue) != originalValue); } while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&RefCountAndLength), decrementedValue, originalValue) != originalValue);
if (RefCountAndLength == 0) if (RefCountAndLength == 0)

View file

@ -69,7 +69,7 @@ namespace boost
uint32_t use_count() const uint32_t use_count() const
{ {
return std::byteswap(static_cast<uint32_t const volatile &>(use_count_.value)); return ByteSwap(static_cast<uint32_t const volatile &>(use_count_.value));
} }
bool unique() const bool unique() const

View file

@ -38,7 +38,7 @@ uint32_t XAudioSubmitRenderDriverFrame(uint32_t driver, void* samples)
{ {
for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++) for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++)
{ {
xaudioSamplesBuffer[i * XAUDIO_NUM_CHANNELS + j] = std::byteswap(((uint32_t *)samples)[j * XAUDIO_NUM_SAMPLES + i]); xaudioSamplesBuffer[i * XAUDIO_NUM_CHANNELS + j] = ByteSwap(((uint32_t *)samples)[j * XAUDIO_NUM_SAMPLES + i]);
} }
} }

View file

@ -48,6 +48,6 @@ void XAudioSubmitFrame(void* samples)
for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++) for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++)
{ {
for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++) for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++)
g_audioOutput[i * XAUDIO_NUM_CHANNELS + j] = std::byteswap(((uint32_t*)samples)[j * XAUDIO_NUM_SAMPLES + i]); g_audioOutput[i * XAUDIO_NUM_CHANNELS + j] = ByteSwap(((uint32_t*)samples)[j * XAUDIO_NUM_SAMPLES + i]);
} }
} }

View file

@ -111,7 +111,7 @@ void XAudioSubmitFrame(void* samples)
for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++) for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++)
{ {
for (size_t j = 0; j < 6; j++) for (size_t j = 0; j < 6; j++)
audioFrame[i * XAUDIO_NUM_CHANNELS + j] = std::byteswap(((uint32_t*)samples)[j * XAUDIO_NUM_SAMPLES + i]); audioFrame[i * XAUDIO_NUM_CHANNELS + j] = ByteSwap(((uint32_t*)samples)[j * XAUDIO_NUM_SAMPLES + i]);
} }
XAUDIO2_BUFFER buffer{}; XAUDIO2_BUFFER buffer{};

View file

@ -22,12 +22,12 @@ GuestThreadContext::GuestThreadContext(uint32_t cpuNumber)
thread = (uint8_t*)g_userHeap.Alloc(TOTAL_SIZE); thread = (uint8_t*)g_userHeap.Alloc(TOTAL_SIZE);
memset(thread, 0, TOTAL_SIZE); memset(thread, 0, TOTAL_SIZE);
*(uint32_t*)thread = std::byteswap(g_memory.MapVirtual(thread + PCR_SIZE)); // tls pointer *(uint32_t*)thread = ByteSwap(g_memory.MapVirtual(thread + PCR_SIZE)); // tls pointer
*(uint32_t*)(thread + 0x100) = std::byteswap(g_memory.MapVirtual(thread + PCR_SIZE + TLS_SIZE)); // teb pointer *(uint32_t*)(thread + 0x100) = ByteSwap(g_memory.MapVirtual(thread + PCR_SIZE + TLS_SIZE)); // teb pointer
*(thread + 0x10C) = cpuNumber; *(thread + 0x10C) = cpuNumber;
*(uint32_t*)(thread + PCR_SIZE + 0x10) = 0xFFFFFFFF; // that one TLS entry that felt quirky *(uint32_t*)(thread + PCR_SIZE + 0x10) = 0xFFFFFFFF; // that one TLS entry that felt quirky
*(uint32_t*)(thread + PCR_SIZE + TLS_SIZE + 0x14C) = std::byteswap(GetCurrentThreadId()); // thread id *(uint32_t*)(thread + PCR_SIZE + TLS_SIZE + 0x14C) = ByteSwap(GetCurrentThreadId()); // thread id
ppcContext.fn = (uint8_t*)g_codeCache.bucket; ppcContext.fn = (uint8_t*)g_codeCache.bucket;
ppcContext.r1.u64 = g_memory.MapVirtual(thread + PCR_SIZE + TLS_SIZE + TEB_SIZE + STACK_SIZE); // stack pointer ppcContext.r1.u64 = g_memory.MapVirtual(thread + PCR_SIZE + TLS_SIZE + TEB_SIZE + STACK_SIZE); // stack pointer
@ -116,7 +116,7 @@ void GuestThread::SetLastError(DWORD error)
} }
// TEB + 0x160 : Win32LastError // TEB + 0x160 : Win32LastError
*(DWORD*)(thread + TEB_OFFSET + 0x160) = std::byteswap(error); *(DWORD*)(thread + TEB_OFFSET + 0x160) = ByteSwap(error);
} }
PPCContext* GuestThread::Invoke(uint32_t address) PPCContext* GuestThread::Invoke(uint32_t address)
@ -129,7 +129,7 @@ PPCContext* GuestThread::Invoke(uint32_t address)
void SetThreadNameImpl(uint32_t a1, uint32_t threadId, uint32_t* name) void SetThreadNameImpl(uint32_t a1, uint32_t threadId, uint32_t* name)
{ {
GuestThread::SetThreadName(threadId, (const char*)g_memory.Translate(std::byteswap(*name))); GuestThread::SetThreadName(threadId, (const char*)g_memory.Translate(ByteSwap(*name)));
} }
int GetThreadPriorityImpl(uint32_t hThread) int GetThreadPriorityImpl(uint32_t hThread)

View file

@ -367,7 +367,7 @@ struct UploadAllocator
for (size_t i = 0; i < size; i += sizeof(T)) for (size_t i = 0; i < size; i += sizeof(T))
{ {
*destination = std::byteswap(*memory); *destination = ByteSwap(*memory);
++destination; ++destination;
++memory; ++memory;
} }
@ -1732,7 +1732,7 @@ static void UnlockBuffer(GuestBuffer* buffer, bool useCopyQueue)
for (size_t i = 0; i < buffer->dataSize; i += sizeof(T)) for (size_t i = 0; i < buffer->dataSize; i += sizeof(T))
{ {
*dest = std::byteswap(*src); *dest = ByteSwap(*src);
++dest; ++dest;
++src; ++src;
} }
@ -2251,7 +2251,7 @@ static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t dep
g_textureDescriptorSet->setTexture(texture->descriptorIndex, texture->texture, RenderTextureLayout::SHADER_READ, texture->textureView.get()); g_textureDescriptorSet->setTexture(texture->descriptorIndex, texture->texture, RenderTextureLayout::SHADER_READ, texture->textureView.get());
#ifdef _DEBUG #ifdef _DEBUG
texture->texture->setName(std::format("Texture {:X}", g_memory.MapVirtual(texture))); texture->texture->setName(fmt::format("Texture {:X}", g_memory.MapVirtual(texture)));
#endif #endif
return texture; return texture;
@ -2263,7 +2263,7 @@ static GuestBuffer* CreateVertexBuffer(uint32_t length)
buffer->buffer = g_device->createBuffer(RenderBufferDesc::VertexBuffer(length, RenderHeapType::DEFAULT, RenderBufferFlag::INDEX)); buffer->buffer = g_device->createBuffer(RenderBufferDesc::VertexBuffer(length, RenderHeapType::DEFAULT, RenderBufferFlag::INDEX));
buffer->dataSize = length; buffer->dataSize = length;
#ifdef _DEBUG #ifdef _DEBUG
buffer->buffer->setName(std::format("Vertex Buffer {:X}", g_memory.MapVirtual(buffer))); buffer->buffer->setName(fmt::format("Vertex Buffer {:X}", g_memory.MapVirtual(buffer)));
#endif #endif
return buffer; return buffer;
} }
@ -2276,7 +2276,7 @@ static GuestBuffer* CreateIndexBuffer(uint32_t length, uint32_t, uint32_t format
buffer->format = ConvertFormat(format); buffer->format = ConvertFormat(format);
buffer->guestFormat = format; buffer->guestFormat = format;
#ifdef _DEBUG #ifdef _DEBUG
buffer->buffer->setName(std::format("Index Buffer {:X}", g_memory.MapVirtual(buffer))); buffer->buffer->setName(fmt::format("Index Buffer {:X}", g_memory.MapVirtual(buffer)));
#endif #endif
return buffer; return buffer;
} }
@ -2317,7 +2317,7 @@ static GuestSurface* CreateSurface(uint32_t width, uint32_t height, uint32_t for
} }
#ifdef _DEBUG #ifdef _DEBUG
surface->texture->setName(std::format("{} {:X}", desc.flags & RenderTextureFlag::RENDER_TARGET ? "Render Target" : "Depth Stencil", g_memory.MapVirtual(surface))); surface->texture->setName(fmt::format("{} {:X}", desc.flags & RenderTextureFlag::RENDER_TARGET ? "Render Target" : "Depth Stencil", g_memory.MapVirtual(surface)));
#endif #endif
return surface; return surface;
@ -3055,13 +3055,13 @@ static RenderPipeline* CreateGraphicsPipelineInRenderThread(PipelineState pipeli
else else
++g_pipelinesCreatedInRenderThread; ++g_pipelinesCreatedInRenderThread;
pipeline->setName(std::format("{} {} {} {:X}", loading ? "ASYNC" : "", pipeline->setName(fmt::format("{} {} {} {:X}", loading ? "ASYNC" : "",
pipelineState.vertexShader->name, pipelineState.pixelShader != nullptr ? pipelineState.pixelShader->name : "<none>", hash)); pipelineState.vertexShader->name, pipelineState.pixelShader != nullptr ? pipelineState.pixelShader->name : "<none>", hash));
if (!loading) if (!loading)
{ {
std::lock_guard lock(g_debugMutex); std::lock_guard lock(g_debugMutex);
g_pipelineDebugText = std::format( g_pipelineDebugText = fmt::format(
"PipelineState {:X}:\n" "PipelineState {:X}:\n"
" vertexShader: {}\n" " vertexShader: {}\n"
" pixelShader: {}\n" " pixelShader: {}\n"
@ -4912,7 +4912,7 @@ static void EnqueueGraphicsPipelineCompilation(const PipelineState& pipelineStat
queueItem.pipelineState = pipelineState; queueItem.pipelineState = pipelineState;
queueItem.databaseDataHolder = databaseDataHolderPair.counter; queueItem.databaseDataHolder = databaseDataHolderPair.counter;
#ifdef ASYNC_PSO_DEBUG #ifdef ASYNC_PSO_DEBUG
queueItem.pipelineName = std::format("ASYNC {} {:X}", name, hash); queueItem.pipelineName = fmt::format("ASYNC {} {:X}", name, hash);
#endif #endif
g_pipelineStateQueue.enqueue(queueItem); g_pipelineStateQueue.enqueue(queueItem);
} }
@ -5743,18 +5743,18 @@ public:
for (auto vertexDeclaration : vertexDeclarations) for (auto vertexDeclaration : vertexDeclarations)
{ {
std::print(f, "static uint8_t g_vertexElements_{:016X}[] = {{", vertexDeclaration->hash); fmt::print(f, "static uint8_t g_vertexElements_{:016X}[] = {{", vertexDeclaration->hash);
auto bytes = reinterpret_cast<uint8_t*>(vertexDeclaration->vertexElements.get()); auto bytes = reinterpret_cast<uint8_t*>(vertexDeclaration->vertexElements.get());
for (size_t i = 0; i < vertexDeclaration->vertexElementCount * sizeof(GuestVertexElement); i++) for (size_t i = 0; i < vertexDeclaration->vertexElementCount * sizeof(GuestVertexElement); i++)
std::print(f, "0x{:X},", bytes[i]); fmt::print(f, "0x{:X},", bytes[i]);
std::println(f, "}};"); fmt::println(f, "}};");
} }
for (auto& [pipelineHash, pipelineState] : pipelineStatesToCache) for (auto& [pipelineHash, pipelineState] : pipelineStatesToCache)
{ {
std::println(f, "{{ " fmt::println(f, "{{ "
"reinterpret_cast<GuestShader*>(0x{:X})," "reinterpret_cast<GuestShader*>(0x{:X}),"
"reinterpret_cast<GuestShader*>(0x{:X})," "reinterpret_cast<GuestShader*>(0x{:X}),"
"reinterpret_cast<GuestVertexDeclaration*>(0x{:X})," "reinterpret_cast<GuestVertexDeclaration*>(0x{:X}),"

View file

@ -88,7 +88,7 @@ struct GuestResource
do do
{ {
originalValue = refCount.value; originalValue = refCount.value;
incrementedValue = std::byteswap(std::byteswap(originalValue) + 1); incrementedValue = ByteSwap(ByteSwap(originalValue) + 1);
} while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&refCount), incrementedValue, originalValue) != originalValue); } while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&refCount), incrementedValue, originalValue) != originalValue);
} }
@ -98,7 +98,7 @@ struct GuestResource
do do
{ {
originalValue = refCount.value; originalValue = refCount.value;
decrementedValue = std::byteswap(std::byteswap(originalValue) - 1); decrementedValue = ByteSwap(ByteSwap(originalValue) - 1);
} while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&refCount), decrementedValue, originalValue) != originalValue); } while (InterlockedCompareExchange(reinterpret_cast<LONG*>(&refCount), decrementedValue, originalValue) != originalValue);
// Normally we are supposed to release here, so only use this // Normally we are supposed to release here, so only use this

View file

@ -72,14 +72,14 @@ static bool copyFile(const FilePair &pair, const uint64_t *fileHashes, VirtualFi
if (!sourceVfs.exists(filename)) if (!sourceVfs.exists(filename))
{ {
journal.lastResult = Journal::Result::FileMissing; journal.lastResult = Journal::Result::FileMissing;
journal.lastErrorMessage = std::format("File {} does not exist in the file system.", filename); journal.lastErrorMessage = fmt::format("File {} does not exist in the file system.", filename);
return false; return false;
} }
if (!sourceVfs.load(filename, fileData)) if (!sourceVfs.load(filename, fileData))
{ {
journal.lastResult = Journal::Result::FileReadFailed; journal.lastResult = Journal::Result::FileReadFailed;
journal.lastErrorMessage = std::format("Failed to read file {} from the file system.", filename); journal.lastErrorMessage = fmt::format("Failed to read file {} from the file system.", filename);
return false; return false;
} }
@ -95,7 +95,7 @@ static bool copyFile(const FilePair &pair, const uint64_t *fileHashes, VirtualFi
if (!fileHashFound) if (!fileHashFound)
{ {
journal.lastResult = Journal::Result::FileHashFailed; journal.lastResult = Journal::Result::FileHashFailed;
journal.lastErrorMessage = std::format("File {} from the file system did not match any of the known hashes.", filename); journal.lastErrorMessage = fmt::format("File {} from the file system did not match any of the known hashes.", filename);
return false; return false;
} }
} }
@ -122,7 +122,7 @@ static bool copyFile(const FilePair &pair, const uint64_t *fileHashes, VirtualFi
if (!outStream.is_open()) if (!outStream.is_open())
{ {
journal.lastResult = Journal::Result::FileCreationFailed; journal.lastResult = Journal::Result::FileCreationFailed;
journal.lastErrorMessage = std::format("Failed to create file at {}.", targetPath.string()); journal.lastErrorMessage = fmt::format("Failed to create file at {}.", targetPath.string());
return false; return false;
} }
@ -132,7 +132,7 @@ static bool copyFile(const FilePair &pair, const uint64_t *fileHashes, VirtualFi
if (outStream.bad()) if (outStream.bad())
{ {
journal.lastResult = Journal::Result::FileWriteFailed; journal.lastResult = Journal::Result::FileWriteFailed;
journal.lastErrorMessage = std::format("Failed to create file at {}.", targetPath.string()); journal.lastErrorMessage = fmt::format("Failed to create file at {}.", targetPath.string());
return false; return false;
} }
@ -148,7 +148,7 @@ static DLC detectDLC(const std::filesystem::path &sourcePath, VirtualFileSystem
if (!sourceVfs.load(DLCValidationFile, dlcXmlBytes)) if (!sourceVfs.load(DLCValidationFile, dlcXmlBytes))
{ {
journal.lastResult = Journal::Result::FileMissing; journal.lastResult = Journal::Result::FileMissing;
journal.lastErrorMessage = std::format("File {} does not exist in the file system.", DLCValidationFile); journal.lastErrorMessage = fmt::format("File {} does not exist in the file system.", DLCValidationFile);
return DLC::Unknown; return DLC::Unknown;
} }
@ -243,7 +243,7 @@ bool Installer::computeTotalSize(std::span<const FilePair> filePairs, const uint
if (!sourceVfs.exists(filename)) if (!sourceVfs.exists(filename))
{ {
journal.lastResult = Journal::Result::FileMissing; journal.lastResult = Journal::Result::FileMissing;
journal.lastErrorMessage = std::format("File {} does not exist in the file system.", filename); journal.lastErrorMessage = fmt::format("File {} does not exist in the file system.", filename);
return false; return false;
} }
@ -296,7 +296,7 @@ bool Installer::copyFiles(std::span<const FilePair> filePairs, const uint64_t *f
else else
{ {
journal.lastResult = Journal::Result::ValidationFileMissing; journal.lastResult = Journal::Result::ValidationFileMissing;
journal.lastErrorMessage = std::format("Unable to find validation file {} in file system.", validationFile); journal.lastErrorMessage = fmt::format("Unable to find validation file {} in file system.", validationFile);
return false; return false;
} }

View file

@ -635,7 +635,7 @@ bool XContentFileSystem::check(const std::filesystem::path &contentPath)
uint32_t packageTypeUint = 0; uint32_t packageTypeUint = 0;
contentStream.read((char *)(&packageTypeUint), sizeof(uint32_t)); contentStream.read((char *)(&packageTypeUint), sizeof(uint32_t));
packageTypeUint = std::byteswap(packageTypeUint); packageTypeUint = ByteSwap(packageTypeUint);
XContentPackageType packageType = XContentPackageType(packageTypeUint); XContentPackageType packageType = XContentPackageType(packageTypeUint);
return packageType == XContentPackageType::CON || packageType == XContentPackageType::LIVE || packageType == XContentPackageType::PIRS; return packageType == XContentPackageType::CON || packageType == XContentPackageType::LIVE || packageType == XContentPackageType::PIRS;
} }

View file

@ -293,7 +293,7 @@ uint32_t ExGetXConfigSetting(uint16_t Category, uint16_t Setting, void* Buffer,
{ {
// XCONFIG_SECURED_AV_REGION // XCONFIG_SECURED_AV_REGION
case 0x0002: case 0x0002:
data[0] = std::byteswap(0x00001000); // USA/Canada data[0] = ByteSwap(0x00001000); // USA/Canada
break; break;
default: default:
@ -317,22 +317,22 @@ uint32_t ExGetXConfigSetting(uint16_t Category, uint16_t Setting, void* Buffer,
// XCONFIG_USER_LANGUAGE // XCONFIG_USER_LANGUAGE
case 0x0009: case 0x0009:
data[0] = std::byteswap((uint32_t)Config::Language.Value); data[0] = ByteSwap((uint32_t)Config::Language.Value);
break; break;
// XCONFIG_USER_VIDEO_FLAGS // XCONFIG_USER_VIDEO_FLAGS
case 0x000A: case 0x000A:
data[0] = std::byteswap(0x00040000); data[0] = ByteSwap(0x00040000);
break; break;
// XCONFIG_USER_RETAIL_FLAGS // XCONFIG_USER_RETAIL_FLAGS
case 0x000C: case 0x000C:
data[0] = std::byteswap(1); data[0] = ByteSwap(1);
break; break;
// XCONFIG_USER_COUNTRY // XCONFIG_USER_COUNTRY
case 0x000E: case 0x000E:
data[0] = std::byteswap(103); data[0] = ByteSwap(103);
break; break;
default: default:
@ -359,7 +359,7 @@ void MmQueryStatistics()
uint32_t NtCreateEvent(uint32_t* handle, void* objAttributes, uint32_t eventType, uint32_t initialState) uint32_t NtCreateEvent(uint32_t* handle, void* objAttributes, uint32_t eventType, uint32_t initialState)
{ {
*handle = std::byteswap((uint32_t)CreateEventA(nullptr, !eventType, !!initialState, nullptr)); *handle = ByteSwap((uint32_t)CreateEventA(nullptr, !eventType, !!initialState, nullptr));
return 0; return 0;
} }
@ -405,7 +405,7 @@ NTSTATUS RtlUnicodeToMultiByteN(PCHAR MultiByteString, DWORD MaxBytesInMultiByte
for (size_t i = 0; i < reqSize; i++) for (size_t i = 0; i < reqSize; i++)
{ {
const auto c = std::byteswap(UnicodeString[i]); const auto c = ByteSwap(UnicodeString[i]);
MultiByteString[i] = c < 256 ? c : '?'; MultiByteString[i] = c < 256 ? c : '?';
} }
@ -518,7 +518,7 @@ uint32_t NtSuspendThread(uint32_t hThread, uint32_t* suspendCount)
return E_FAIL; return E_FAIL;
if (suspendCount != nullptr) if (suspendCount != nullptr)
*suspendCount = std::byteswap(count); *suspendCount = ByteSwap(count);
return S_OK; return S_OK;
} }
@ -646,7 +646,7 @@ void KfAcquireSpinLock(uint32_t* spinLock)
{ {
const auto ctx = GetPPCContext(); const auto ctx = GetPPCContext();
while (InterlockedCompareExchange((volatile long*)spinLock, std::byteswap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0) while (InterlockedCompareExchange((volatile long*)spinLock, ByteSwap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0)
Sleep(0); Sleep(0);
} }
@ -686,7 +686,7 @@ void KeAcquireSpinLockAtRaisedIrql(uint32_t* spinLock)
{ {
const auto ctx = GetPPCContext(); const auto ctx = GetPPCContext();
while (InterlockedCompareExchange((volatile long*)spinLock, std::byteswap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0) while (InterlockedCompareExchange((volatile long*)spinLock, ByteSwap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0)
Sleep(0); Sleep(0);
} }
@ -1127,7 +1127,7 @@ NTSTATUS RtlMultiByteToUnicodeN(PWCH UnicodeString, ULONG MaxBytesInUnicodeStrin
if (n) if (n)
{ {
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
UnicodeString[i] = std::byteswap(UnicodeString[i]); UnicodeString[i] = ByteSwap(UnicodeString[i]);
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -1156,7 +1156,7 @@ uint32_t NtResumeThread(uint32_t hThread, uint32_t* suspendCount)
return E_FAIL; return E_FAIL;
if (suspendCount != nullptr) if (suspendCount != nullptr)
*suspendCount = std::byteswap(count); *suspendCount = ByteSwap(count);
return S_OK; return S_OK;
} }
@ -1177,7 +1177,7 @@ NTSTATUS NtReleaseSemaphore(uint32_t Handle, DWORD ReleaseCount, LONG* PreviousC
ReleaseSemaphore((HANDLE)Handle, ReleaseCount, PreviousCount); ReleaseSemaphore((HANDLE)Handle, ReleaseCount, PreviousCount);
if (PreviousCount) if (PreviousCount)
*PreviousCount = std::byteswap(*PreviousCount); *PreviousCount = ByteSwap(*PreviousCount);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -1216,7 +1216,7 @@ void KeQuerySystemTime(uint64_t* time)
{ {
FILETIME t; FILETIME t;
GetSystemTimeAsFileTime(&t); GetSystemTimeAsFileTime(&t);
*time = std::byteswap((uint64_t(t.dwHighDateTime) << 32) | t.dwLowDateTime); *time = ByteSwap((uint64_t(t.dwHighDateTime) << 32) | t.dwLowDateTime);
} }
void RtlTimeToTimeFields() void RtlTimeToTimeFields()

View file

@ -44,7 +44,7 @@ static DWORD XGetFileSizeA(uint32_t hFile, LPDWORD lpFileSizeHigh)
DWORD fileSize = GetFileSize((HANDLE)hFile, lpFileSizeHigh); DWORD fileSize = GetFileSize((HANDLE)hFile, lpFileSizeHigh);
if (lpFileSizeHigh != nullptr) if (lpFileSizeHigh != nullptr)
*lpFileSizeHigh = std::byteswap(*lpFileSizeHigh); *lpFileSizeHigh = ByteSwap(*lpFileSizeHigh);
return fileSize; return fileSize;
} }
@ -54,7 +54,7 @@ BOOL XGetFileSizeExA(uint32_t hFile, PLARGE_INTEGER lpFileSize)
BOOL result = GetFileSizeEx((HANDLE)hFile, lpFileSize); BOOL result = GetFileSizeEx((HANDLE)hFile, lpFileSize);
if (result) if (result)
lpFileSize->QuadPart = std::byteswap(lpFileSize->QuadPart); lpFileSize->QuadPart = ByteSwap(lpFileSize->QuadPart);
return result; return result;
} }
@ -102,11 +102,11 @@ BOOL XReadFile
DWORD XSetFilePointer(uint32_t hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) DWORD XSetFilePointer(uint32_t hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
{ {
LONG distanceToMoveHigh = lpDistanceToMoveHigh ? std::byteswap(*lpDistanceToMoveHigh) : 0; LONG distanceToMoveHigh = lpDistanceToMoveHigh ? ByteSwap(*lpDistanceToMoveHigh) : 0;
DWORD result = SetFilePointer((HANDLE)hFile, lDistanceToMove, lpDistanceToMoveHigh ? &distanceToMoveHigh : nullptr, dwMoveMethod); DWORD result = SetFilePointer((HANDLE)hFile, lDistanceToMove, lpDistanceToMoveHigh ? &distanceToMoveHigh : nullptr, dwMoveMethod);
if (lpDistanceToMoveHigh != nullptr) if (lpDistanceToMoveHigh != nullptr)
*lpDistanceToMoveHigh = std::byteswap(distanceToMoveHigh); *lpDistanceToMoveHigh = ByteSwap(distanceToMoveHigh);
return result; return result;
} }
@ -119,7 +119,7 @@ BOOL XSetFilePointerEx(uint32_t hFile, LONG lDistanceToMove, PLARGE_INTEGER lpNe
DWORD result = SetFilePointerEx((HANDLE)hFile, distanceToMove, lpNewFilePointer, dwMoveMethod); DWORD result = SetFilePointerEx((HANDLE)hFile, distanceToMove, lpNewFilePointer, dwMoveMethod);
if (lpNewFilePointer != nullptr) if (lpNewFilePointer != nullptr)
lpNewFilePointer->QuadPart = std::byteswap(lpNewFilePointer->QuadPart); lpNewFilePointer->QuadPart = ByteSwap(lpNewFilePointer->QuadPart);
return result; return result;
} }

View file

@ -3,7 +3,7 @@
#include <os/logger_detail.h> #include <os/logger_detail.h>
#define LOG_IMPL(type, func, str) os::logger::Log(str, os::logger::detail::ELogType::type, func) #define LOG_IMPL(type, func, str) os::logger::Log(str, os::logger::detail::ELogType::type, func)
#define LOGF_IMPL(type, func, str, ...) os::logger::Log(std::format(str, __VA_ARGS__), os::logger::detail::ELogType::type, func) #define LOGF_IMPL(type, func, str, ...) os::logger::Log(fmt::format(str, __VA_ARGS__), os::logger::detail::ELogType::type, func)
// Function-specific logging. // Function-specific logging.

View file

@ -34,11 +34,11 @@ void os::logger::detail::Log(const std::string_view str, detail::ELogType type,
if (func) if (func)
{ {
std::println("[{}] {}", func, str); fmt::println("[{}] {}", func, str);
} }
else else
{ {
std::println("{}", str); fmt::println("{}", str);
} }
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE); SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);

View file

@ -9,7 +9,6 @@
#include <mutex> #include <mutex>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <format>
#include <vector> #include <vector>
#include <string> #include <string>
#include <cassert> #include <cassert>
@ -32,10 +31,10 @@
#include <cstddef> #include <cstddef>
#include <wrl/client.h> #include <wrl/client.h>
#include <smolv.h> #include <smolv.h>
#include <print>
#include <set> #include <set>
#include <miniaudio.h> #include <miniaudio.h>
#include <extras/miniaudio_libvorbis.h> #include <extras/miniaudio_libvorbis.h>
#include <fmt/core.h>
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;

View file

@ -521,7 +521,7 @@ static void DrawAchievementTotal(ImVec2 min, ImVec2 max)
if (records >= recordsHalfTotal || records >= ACH_RECORDS) if (records >= recordsHalfTotal || records >= ACH_RECORDS)
DrawTrophySparkles(imageMin, imageMax, records, frameIndex); DrawTrophySparkles(imageMin, imageMax, records, frameIndex);
auto str = std::format("{} / {}", records, ACH_RECORDS); auto str = fmt::format("{} / {}", records, ACH_RECORDS);
auto fontSize = Scale(20); auto fontSize = Scale(20);
auto textSize = g_fntNewRodinDB->CalcTextSizeA(fontSize, FLT_MAX, 0, str.c_str()); auto textSize = g_fntNewRodinDB->CalcTextSizeA(fontSize, FLT_MAX, 0, str.c_str());

View file

@ -739,11 +739,11 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
std::string valueText; std::string valueText;
if constexpr (std::is_same_v<T, float>) if constexpr (std::is_same_v<T, float>)
{ {
valueText = std::format("{}%", int32_t(round(config->Value * 100.0f))); valueText = fmt::format("{}%", int32_t(round(config->Value * 100.0f)));
} }
else if constexpr (std::is_same_v<T, int32_t>) else if constexpr (std::is_same_v<T, int32_t>)
{ {
valueText = config->Value >= valueMax ? Localise("Options_Value_Max") : std::format("{}", config->Value); valueText = config->Value >= valueMax ? Localise("Options_Value_Max") : fmt::format("{}", config->Value);
} }
else else
{ {

View file

@ -105,7 +105,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
m_isResizing = true; m_isResizing = true;
Window::s_width = event->window.data1; Window::s_width = event->window.data1;
Window::s_height = event->window.data2; Window::s_height = event->window.data2;
Window::SetTitle(std::format("{} - [{}x{}]", Window::GetTitle(), Window::s_width, Window::s_height).c_str()); Window::SetTitle(fmt::format("{} - [{}x{}]", Window::GetTitle(), Window::s_width, Window::s_height).c_str());
break; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:

View file

@ -387,24 +387,24 @@ public:
if constexpr (std::is_same_v<T, std::string>) if constexpr (std::is_same_v<T, std::string>)
{ {
result = std::format("{}", Value); result = fmt::format("{}", Value);
if (strWithQuotes) if (strWithQuotes)
result = std::format("\"{}\"", result); result = fmt::format("\"{}\"", result);
} }
else if constexpr (std::is_enum_v<T>) else if constexpr (std::is_enum_v<T>)
{ {
auto it = EnumTemplateReverse.find(Value); auto it = EnumTemplateReverse.find(Value);
if (it != EnumTemplateReverse.end()) if (it != EnumTemplateReverse.end())
result = std::format("{}", it->second); result = fmt::format("{}", it->second);
if (strWithQuotes) if (strWithQuotes)
result = std::format("\"{}\"", result); result = fmt::format("\"{}\"", result);
} }
else else
{ {
result = std::format("{}", Value); result = fmt::format("{}", Value);
} }
return result; return result;