mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
Implemented cross-platform logger framework (and clean-up)
This commit is contained in:
parent
b9bd137659
commit
0813be2acf
17 changed files with 453 additions and 416 deletions
|
|
@ -67,6 +67,7 @@ set(SWA_KERNEL_CXX_SOURCES
|
|||
)
|
||||
|
||||
set(SWA_OS_CXX_SOURCES
|
||||
"os/logger.cpp"
|
||||
"os/media.cpp"
|
||||
"os/process.cpp"
|
||||
"os/version.cpp"
|
||||
|
|
@ -74,6 +75,7 @@ set(SWA_OS_CXX_SOURCES
|
|||
|
||||
if (WIN32)
|
||||
list(APPEND SWA_OS_CXX_SOURCES
|
||||
"os/win32/logger_win32.cpp"
|
||||
"os/win32/media_win32.cpp"
|
||||
"os/win32/process_win32.cpp"
|
||||
"os/win32/version_win32.cpp"
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,7 @@
|
|||
#include <kernel/xdm.h>
|
||||
#include <kernel/function.h>
|
||||
#include <cpu/guest_thread.h>
|
||||
#include <os/logger.h>
|
||||
|
||||
bool FindHandleCloser(void* handle)
|
||||
{
|
||||
|
|
@ -11,13 +12,15 @@ bool FindHandleCloser(void* handle)
|
|||
return false;
|
||||
}
|
||||
|
||||
SWA_API uint32_t XCreateFileA(
|
||||
SWA_API uint32_t XCreateFileA
|
||||
(
|
||||
LPCSTR lpFileName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes)
|
||||
DWORD dwFlagsAndAttributes
|
||||
)
|
||||
{
|
||||
const auto handle = (uint32_t)CreateFileA(
|
||||
FileSystem::TransformPath(lpFileName),
|
||||
|
|
@ -29,49 +32,53 @@ SWA_API uint32_t XCreateFileA(
|
|||
nullptr);
|
||||
|
||||
GuestThread::SetLastError(GetLastError());
|
||||
printf("CreateFileA(%s, %lx, %lx, %p, %lx, %lx): %x\n", lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, handle);
|
||||
|
||||
LOGF_UTILITY("\"{}\", 0x{:X}, 0x{:X}, 0x{:X}, 0x{:X}, 0x{:X} -> 0x{:X}",
|
||||
lpFileName, dwDesiredAccess, dwShareMode, (intptr_t)lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, handle);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
static DWORD XGetFileSizeA(
|
||||
uint32_t hFile,
|
||||
LPDWORD lpFileSizeHigh)
|
||||
static DWORD XGetFileSizeA(uint32_t hFile, LPDWORD lpFileSizeHigh)
|
||||
{
|
||||
DWORD fileSize = GetFileSize((HANDLE)hFile, lpFileSizeHigh);
|
||||
|
||||
if (lpFileSizeHigh != nullptr)
|
||||
*lpFileSizeHigh = std::byteswap(*lpFileSizeHigh);
|
||||
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
BOOL XGetFileSizeExA(
|
||||
uint32_t hFile,
|
||||
PLARGE_INTEGER lpFileSize)
|
||||
BOOL XGetFileSizeExA(uint32_t hFile, PLARGE_INTEGER lpFileSize)
|
||||
{
|
||||
BOOL result = GetFileSizeEx((HANDLE)hFile, lpFileSize);
|
||||
|
||||
if (result)
|
||||
lpFileSize->QuadPart = std::byteswap(lpFileSize->QuadPart);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL XReadFile(
|
||||
BOOL XReadFile
|
||||
(
|
||||
uint32_t hFile,
|
||||
LPVOID lpBuffer,
|
||||
DWORD nNumberOfBytesToRead,
|
||||
XLPDWORD lpNumberOfBytesRead,
|
||||
XOVERLAPPED* lpOverlapped)
|
||||
XOVERLAPPED* lpOverlapped
|
||||
)
|
||||
{
|
||||
if (lpOverlapped != nullptr)
|
||||
{
|
||||
LONG distanceToMoveHigh = lpOverlapped->OffsetHigh;
|
||||
|
||||
if (SetFilePointer((HANDLE)hFile, lpOverlapped->Offset, &distanceToMoveHigh, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD numberOfBytesRead;
|
||||
BOOL result = ReadFile((HANDLE)hFile, lpBuffer, nNumberOfBytesToRead, &numberOfBytesRead, nullptr);
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (lpOverlapped != nullptr)
|
||||
|
|
@ -88,52 +95,44 @@ BOOL XReadFile(
|
|||
}
|
||||
}
|
||||
|
||||
//printf("ReadFile(): %x %x %x %x %x %x\n", hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped, result);
|
||||
// printf("ReadFile(): %x %x %x %x %x %x\n", hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
DWORD result = SetFilePointer((HANDLE)hFile, lDistanceToMove, lpDistanceToMoveHigh ? &distanceToMoveHigh : nullptr, dwMoveMethod);
|
||||
|
||||
if (lpDistanceToMoveHigh != nullptr)
|
||||
*lpDistanceToMoveHigh = std::byteswap(distanceToMoveHigh);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL XSetFilePointerEx(
|
||||
uint32_t hFile,
|
||||
LONG lDistanceToMove,
|
||||
PLARGE_INTEGER lpNewFilePointer,
|
||||
DWORD dwMoveMethod)
|
||||
BOOL XSetFilePointerEx(uint32_t hFile, LONG lDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
|
||||
{
|
||||
LARGE_INTEGER distanceToMove;
|
||||
distanceToMove.QuadPart = lDistanceToMove;
|
||||
|
||||
DWORD result = SetFilePointerEx((HANDLE)hFile, distanceToMove, lpNewFilePointer, dwMoveMethod);
|
||||
|
||||
if (lpNewFilePointer != nullptr)
|
||||
lpNewFilePointer->QuadPart = std::byteswap(lpNewFilePointer->QuadPart);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t XFindFirstFileA(
|
||||
LPCSTR lpFileName,
|
||||
LPWIN32_FIND_DATAA lpFindFileData)
|
||||
uint32_t XFindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
|
||||
{
|
||||
auto& data = *lpFindFileData;
|
||||
const auto handle = FindFirstFileA(FileSystem::TransformPath(lpFileName), &data);
|
||||
|
||||
GuestThread::SetLastError(GetLastError());
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
ByteSwap(data.dwFileAttributes);
|
||||
ByteSwap(*(uint64_t*)&data.ftCreationTime);
|
||||
|
|
@ -159,19 +158,16 @@ uint32_t XFindNextFileA(uint32_t Handle, LPWIN32_FIND_DATAA lpFindFileData)
|
|||
return result;
|
||||
}
|
||||
|
||||
BOOL XReadFileEx(
|
||||
uint32_t hFile,
|
||||
LPVOID lpBuffer,
|
||||
DWORD nNumberOfBytesToRead,
|
||||
XOVERLAPPED* lpOverlapped,
|
||||
uint32_t lpCompletionRoutine)
|
||||
BOOL XReadFileEx(uint32_t hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, XOVERLAPPED* lpOverlapped, uint32_t lpCompletionRoutine)
|
||||
{
|
||||
LONG distanceToMoveHigh = lpOverlapped->OffsetHigh;
|
||||
|
||||
if (SetFilePointer((HANDLE)hFile, lpOverlapped->Offset, &distanceToMoveHigh, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||
return FALSE;
|
||||
|
||||
DWORD numberOfBytesRead;
|
||||
BOOL result = ReadFile((HANDLE)hFile, lpBuffer, nNumberOfBytesToRead, &numberOfBytesRead, nullptr);
|
||||
|
||||
if (result)
|
||||
{
|
||||
lpOverlapped->Internal = 0;
|
||||
|
|
@ -181,7 +177,7 @@ BOOL XReadFileEx(
|
|||
SetEvent((HANDLE)lpOverlapped->hEvent.get());
|
||||
}
|
||||
|
||||
//printf("ReadFileEx(): %x %x %x %x %x %x\n", hFile, lpBuffer, nNumberOfBytesToRead, lpOverlapped, lpCompletionRoutine, result);
|
||||
// printf("ReadFileEx(): %x %x %x %x %x %x\n", hFile, lpBuffer, nNumberOfBytesToRead, lpOverlapped, lpCompletionRoutine, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -191,16 +187,12 @@ DWORD XGetFileAttributesA(LPCSTR lpFileName)
|
|||
return GetFileAttributesA(FileSystem::TransformPath(lpFileName));
|
||||
}
|
||||
|
||||
BOOL XWriteFile(
|
||||
uint32_t hFile,
|
||||
LPCVOID lpBuffer,
|
||||
DWORD nNumberOfBytesToWrite,
|
||||
LPDWORD lpNumberOfBytesWritten,
|
||||
LPOVERLAPPED lpOverlapped)
|
||||
BOOL XWriteFile(uint32_t hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
|
||||
{
|
||||
assert(lpOverlapped == nullptr);
|
||||
|
||||
BOOL result = WriteFile((HANDLE)hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, nullptr);
|
||||
|
||||
if (result && lpNumberOfBytesWritten != nullptr)
|
||||
ByteSwap(*lpNumberOfBytesWritten);
|
||||
|
||||
|
|
@ -211,6 +203,7 @@ const char* FileSystem::TransformPath(const char* path)
|
|||
{
|
||||
thread_local char builtPath[2048]{};
|
||||
const char* relativePath = strstr(path, ":\\");
|
||||
|
||||
if (relativePath != nullptr)
|
||||
{
|
||||
// rooted folder, handle direction
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ xxHashMap<std::string> gRootMap;
|
|||
std::string_view XamGetRootPath(const std::string_view& root)
|
||||
{
|
||||
const auto result = gRootMap.find(StringHash(root));
|
||||
|
||||
if (result == gRootMap.end())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return result->second;
|
||||
}
|
||||
|
|
@ -46,6 +45,7 @@ XamListener::~XamListener()
|
|||
XCONTENT_DATA XamMakeContent(DWORD type, const std::string_view& name)
|
||||
{
|
||||
XCONTENT_DATA data{ 1, type };
|
||||
|
||||
strncpy(data.szFileName, name.data(), sizeof(data.szFileName));
|
||||
|
||||
return data;
|
||||
|
|
@ -54,12 +54,14 @@ XCONTENT_DATA XamMakeContent(DWORD type, const std::string_view& name)
|
|||
void XamRegisterContent(const XCONTENT_DATA& data, const std::string_view& root)
|
||||
{
|
||||
const auto idx = data.dwContentType - 1;
|
||||
|
||||
gContentRegistry[idx].emplace(StringHash(data.szFileName), XHOSTCONTENT_DATA{ data }).first->second.szRoot = root;
|
||||
}
|
||||
|
||||
void XamRegisterContent(DWORD type, const std::string_view name, const std::string_view& root)
|
||||
{
|
||||
XCONTENT_DATA data{ 1, type, {}, "" };
|
||||
|
||||
strncpy(data.szFileName, name.data(), sizeof(data.szFileName));
|
||||
|
||||
XamRegisterContent(data, root);
|
||||
|
|
@ -69,6 +71,7 @@ SWA_API DWORD XamNotifyCreateListener(uint64_t qwAreas)
|
|||
{
|
||||
int handle;
|
||||
auto* listener = ObCreateObject<XamListener>(handle);
|
||||
|
||||
listener->areas = qwAreas;
|
||||
|
||||
return GUEST_HANDLE(handle);
|
||||
|
|
@ -79,9 +82,7 @@ SWA_API void XamNotifyEnqueueEvent(DWORD dwId, DWORD dwParam)
|
|||
for (const auto& listener : gListeners)
|
||||
{
|
||||
if (((1 << MSG_AREA(dwId)) & listener->areas) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
listener->notifications.emplace_back(dwId, dwParam);
|
||||
}
|
||||
|
|
@ -90,6 +91,7 @@ SWA_API void XamNotifyEnqueueEvent(DWORD dwId, DWORD dwParam)
|
|||
SWA_API bool XNotifyGetNext(DWORD hNotification, DWORD dwMsgFilter, XDWORD* pdwId, XDWORD* pParam)
|
||||
{
|
||||
auto& listener = *ObTryQueryObject<XamListener>(HOST_HANDLE(hNotification));
|
||||
|
||||
if (dwMsgFilter)
|
||||
{
|
||||
for (size_t i = 0; i < listener.notifications.size(); i++)
|
||||
|
|
@ -97,16 +99,13 @@ SWA_API bool XNotifyGetNext(DWORD hNotification, DWORD dwMsgFilter, XDWORD* pdwI
|
|||
if (std::get<0>(listener.notifications[i]) == dwMsgFilter)
|
||||
{
|
||||
if (pdwId)
|
||||
{
|
||||
*pdwId = std::get<0>(listener.notifications[i]);
|
||||
}
|
||||
|
||||
if (pParam)
|
||||
{
|
||||
*pParam = std::get<1>(listener.notifications[i]);
|
||||
}
|
||||
|
||||
listener.notifications.erase(listener.notifications.begin() + i);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,53 +113,42 @@ SWA_API bool XNotifyGetNext(DWORD hNotification, DWORD dwMsgFilter, XDWORD* pdwI
|
|||
else
|
||||
{
|
||||
if (listener.notifications.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pdwId)
|
||||
{
|
||||
*pdwId = std::get<0>(listener.notifications[0]);
|
||||
}
|
||||
|
||||
if (pParam)
|
||||
{
|
||||
*pParam = std::get<1>(listener.notifications[0]);
|
||||
}
|
||||
|
||||
listener.notifications.erase(listener.notifications.begin());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SWA_API uint32_t XamShowMessageBoxUI(DWORD dwUserIndex, XWORD* wszTitle, XWORD* wszText, DWORD cButtons,
|
||||
xpointer<XWORD>* pwszButtons, DWORD dwFocusButton, DWORD dwFlags, XLPDWORD pResult, XXOVERLAPPED* pOverlapped)
|
||||
{
|
||||
// printf("!!! STUB !!! XamShowMessageBoxUI\n");
|
||||
|
||||
std::vector<std::wstring> texts{};
|
||||
std::vector<TASKDIALOG_BUTTON> buttons{};
|
||||
|
||||
texts.emplace_back(reinterpret_cast<wchar_t*>(wszTitle));
|
||||
texts.emplace_back(reinterpret_cast<wchar_t*>(wszText));
|
||||
|
||||
for (size_t i = 0; i < cButtons; i++)
|
||||
{
|
||||
texts.emplace_back(reinterpret_cast<wchar_t*>(pwszButtons[i].get()));
|
||||
}
|
||||
|
||||
for (auto& text : texts)
|
||||
{
|
||||
for (size_t i = 0; i < text.size(); i++)
|
||||
{
|
||||
ByteSwap(text[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cButtons; i++)
|
||||
{
|
||||
buttons.emplace_back(i, texts[2 + i].c_str());
|
||||
}
|
||||
|
||||
XamNotifyEnqueueEvent(9, 1);
|
||||
|
||||
|
|
@ -176,6 +164,7 @@ SWA_API uint32_t XamShowMessageBoxUI(DWORD dwUserIndex, XWORD* wszTitle, XWORD*
|
|||
TaskDialogIndirect(&config, &button, nullptr, nullptr);
|
||||
|
||||
*pResult = button;
|
||||
|
||||
if (pOverlapped)
|
||||
{
|
||||
pOverlapped->dwCompletionContext = GetCurrentThreadId();
|
||||
|
|
@ -202,11 +191,10 @@ SWA_API uint32_t XamContentCreateEnumerator(DWORD dwUserIndex, DWORD DeviceID, D
|
|||
const int handle = ObInsertObject(new XamEnumerator(cItem, sizeof(_XCONTENT_DATA), values.begin(), values.end()));
|
||||
|
||||
if (pcbBuffer)
|
||||
{
|
||||
*pcbBuffer = sizeof(_XCONTENT_DATA) * cItem;
|
||||
}
|
||||
|
||||
*phEnum = GUEST_HANDLE(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -214,15 +202,13 @@ SWA_API uint32_t XamEnumerate(uint32_t hEnum, DWORD dwFlags, PVOID pvBuffer, DWO
|
|||
{
|
||||
auto* enumerator = ObTryQueryObject<XamEnumeratorBase>(HOST_HANDLE(hEnum));
|
||||
const auto count = enumerator->Next(pvBuffer);
|
||||
|
||||
if (count == -1)
|
||||
{
|
||||
return ERROR_NO_MORE_FILES;
|
||||
}
|
||||
|
||||
if (pcItemsReturned)
|
||||
{
|
||||
*pcItemsReturned = count;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -230,15 +216,14 @@ SWA_API uint32_t XamContentCreateEx(DWORD dwUserIndex, LPCSTR szRootName, const
|
|||
DWORD dwContentFlags, XLPDWORD pdwDisposition, XLPDWORD pdwLicenseMask,
|
||||
DWORD dwFileCacheSize, uint64_t uliContentSize, PXXOVERLAPPED pOverlapped)
|
||||
{
|
||||
// printf("!!! STUB !!! XamContentCreateEx\n");
|
||||
|
||||
const auto& registry = gContentRegistry[pContentData->dwContentType - 1];
|
||||
const auto exists = registry.contains(StringHash(pContentData->szFileName));
|
||||
const auto mode = dwContentFlags & 0xF;
|
||||
|
||||
if (mode == CREATE_ALWAYS)
|
||||
{
|
||||
if (pdwDisposition) *pdwDisposition = XCONTENT_NEW;
|
||||
if (pdwDisposition)
|
||||
*pdwDisposition = XCONTENT_NEW;
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
|
|
@ -268,18 +253,23 @@ SWA_API uint32_t XamContentCreateEx(DWORD dwUserIndex, LPCSTR szRootName, const
|
|||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
if (mode == OPEN_EXISTING)
|
||||
{
|
||||
if (exists)
|
||||
{
|
||||
if (pdwDisposition) *pdwDisposition = XCONTENT_EXISTING;
|
||||
if (pdwDisposition)
|
||||
*pdwDisposition = XCONTENT_EXISTING;
|
||||
|
||||
XamRootCreate(szRootName, registry.find(StringHash(pContentData->szFileName))->second.szRoot);
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pdwDisposition) *pdwDisposition = XCONTENT_NEW;
|
||||
if (pdwDisposition)
|
||||
*pdwDisposition = XCONTENT_NEW;
|
||||
|
||||
return ERROR_PATH_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
|
@ -289,15 +279,12 @@ SWA_API uint32_t XamContentCreateEx(DWORD dwUserIndex, LPCSTR szRootName, const
|
|||
|
||||
SWA_API uint32_t XamContentClose(LPCSTR szRootName, XXOVERLAPPED* pOverlapped)
|
||||
{
|
||||
// printf("!!! STUB !!! XamContentClose %s\n", szRootName);
|
||||
gRootMap.erase(StringHash(szRootName));
|
||||
return 0;
|
||||
}
|
||||
|
||||
SWA_API uint32_t XamContentGetDeviceData(DWORD DeviceID, XDEVICE_DATA* pDeviceData)
|
||||
{
|
||||
// printf("!!! STUB !!! XamContentGetDeviceData\n");
|
||||
|
||||
pDeviceData->DeviceID = DeviceID;
|
||||
pDeviceData->DeviceType = XCONTENTDEVICETYPE_HDD;
|
||||
pDeviceData->ulDeviceBytes = 0x10000000;
|
||||
|
|
@ -314,8 +301,8 @@ SWA_API uint32_t XamContentGetDeviceData(DWORD DeviceID, XDEVICE_DATA* pDeviceDa
|
|||
|
||||
SWA_API uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint32_t flags, XAMINPUT_CAPABILITIES* caps)
|
||||
{
|
||||
//printf("!!! STUB !!! XamInputGetCapabilities\n");
|
||||
uint32_t result = hid::GetCapabilities(userIndex, caps);
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
ByteSwap(caps->Flags);
|
||||
|
|
@ -327,13 +314,12 @@ SWA_API uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint3
|
|||
ByteSwap(caps->Vibration.wLeftMotorSpeed);
|
||||
ByteSwap(caps->Vibration.wRightMotorSpeed);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_STATE* state)
|
||||
{
|
||||
//printf("!!! STUB !!! XamInputGetState\n");
|
||||
|
||||
uint32_t result = hid::GetState(userIndex, state);
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
|
|
@ -405,8 +391,8 @@ SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_S
|
|||
|
||||
SWA_API uint32_t XamInputSetState(uint32_t userIndex, uint32_t flags, XAMINPUT_VIBRATION* vibration)
|
||||
{
|
||||
//printf("!!! STUB !!! XamInputSetState\n");
|
||||
ByteSwap(vibration->wLeftMotorSpeed);
|
||||
ByteSwap(vibration->wRightMotorSpeed);
|
||||
|
||||
return hid::SetState(userIndex, vibration);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdafx.h>
|
||||
#include "xdm.h"
|
||||
#include "FreeList.h"
|
||||
#include "freelist.h"
|
||||
|
||||
FreeList<std::tuple<std::unique_ptr<char>, TypeDestructor_t>> gKernelObjects;
|
||||
Mutex gKernelLock;
|
||||
|
|
@ -10,9 +10,7 @@ void* ObQueryObject(size_t handle)
|
|||
std::lock_guard guard{ gKernelLock };
|
||||
|
||||
if (handle >= gKernelObjects.items.size())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::get<0>(gKernelObjects[handle]).get();
|
||||
}
|
||||
|
|
@ -36,6 +34,7 @@ void ObCloseHandle(uint32_t handle)
|
|||
std::lock_guard guard{ gKernelLock };
|
||||
|
||||
auto& obj = gKernelObjects[handle];
|
||||
|
||||
if (std::get<1>(obj)(std::get<0>(obj).get()))
|
||||
{
|
||||
std::get<0>(obj).reset();
|
||||
|
|
@ -46,4 +45,4 @@ void ObCloseHandle(uint32_t handle)
|
|||
}
|
||||
|
||||
gKernelObjects.Free(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
UnleashedRecomp/os/logger.cpp
Normal file
7
UnleashedRecomp/os/logger.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <os/logger.h>
|
||||
#include <os/logger_detail.h>
|
||||
|
||||
void os::logger::Log(const std::string& str, detail::ELogType type, const char* func)
|
||||
{
|
||||
detail::Log(str, type, func);
|
||||
}
|
||||
35
UnleashedRecomp/os/logger.h
Normal file
35
UnleashedRecomp/os/logger.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <os/logger_detail.h>
|
||||
|
||||
#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)
|
||||
|
||||
// Function-specific logging.
|
||||
|
||||
#define LOG(str) LOG_IMPL(None, __func__, str)
|
||||
#define LOG_UTILITY(str) LOG_IMPL(Utility, __func__, str)
|
||||
#define LOG_WARNING(str) LOG_IMPL(Warning, __func__, str)
|
||||
#define LOG_ERROR(str) LOG_IMPL(Error, __func__, str)
|
||||
|
||||
#define LOGF(str, ...) LOGF_IMPL(None, __func__, str, __VA_ARGS__)
|
||||
#define LOGF_UTILITY(str, ...) LOGF_IMPL(Utility, __func__, str, __VA_ARGS__)
|
||||
#define LOGF_WARNING(str, ...) LOGF_IMPL(Warning, __func__, str, __VA_ARGS__)
|
||||
#define LOGF_ERROR(str, ...) LOGF_IMPL(Error, __func__, str, __VA_ARGS__)
|
||||
|
||||
// Non-function-specific logging.
|
||||
|
||||
#define LOGN(str) LOG_IMPL(None, "*", str)
|
||||
#define LOGN_UTILITY(str) LOG_IMPL(Utility, "*", str)
|
||||
#define LOGN_WARNING(str) LOG_IMPL(Warning, "*", str)
|
||||
#define LOGN_ERROR(str) LOG_IMPL(Error, "*", str)
|
||||
|
||||
#define LOGFN(str, ...) LOGF_IMPL(None, "*", str, __VA_ARGS__)
|
||||
#define LOGFN_UTILITY(str, ...) LOGF_IMPL(Utility, "*", str, __VA_ARGS__)
|
||||
#define LOGFN_WARNING(str, ...) LOGF_IMPL(Warning, "*", str, __VA_ARGS__)
|
||||
#define LOGFN_ERROR(str, ...) LOGF_IMPL(Error, "*", str, __VA_ARGS__)
|
||||
|
||||
namespace os::logger
|
||||
{
|
||||
void Log(const std::string& str, detail::ELogType type = detail::ELogType::None, const char* func = nullptr);
|
||||
}
|
||||
16
UnleashedRecomp/os/logger_detail.h
Normal file
16
UnleashedRecomp/os/logger_detail.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <source_location>
|
||||
|
||||
namespace os::logger::detail
|
||||
{
|
||||
enum class ELogType
|
||||
{
|
||||
None,
|
||||
Utility,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
void Log(const std::string& str, ELogType type = ELogType::None, const char* func = nullptr);
|
||||
}
|
||||
47
UnleashedRecomp/os/win32/logger_win32.cpp
Normal file
47
UnleashedRecomp/os/win32/logger_win32.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include <os/logger_detail.h>
|
||||
|
||||
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
|
||||
|
||||
HANDLE g_hStandardOutput = nullptr;
|
||||
|
||||
void os::logger::detail::Log(const std::string& str, detail::ELogType type, const char* func)
|
||||
{
|
||||
#if !_DEBUG
|
||||
if (type == ELogType::Utility)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!g_hStandardOutput)
|
||||
g_hStandardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ELogType::Utility:
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
||||
break;
|
||||
|
||||
case ELogType::Warning:
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_YELLOW | FOREGROUND_INTENSITY);
|
||||
break;
|
||||
|
||||
case ELogType::Error:
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
break;
|
||||
|
||||
default:
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (func)
|
||||
{
|
||||
printf("[%s] %s\n", func, str.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", str.c_str());
|
||||
}
|
||||
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include <os/media_detail.h>
|
||||
#include <os/logger.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Media.Control.h>
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ static GlobalSystemMediaTransportControlsSessionManager GetSessionManager()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve GSMTC session manager: 0x%08X\n", to_hresult().value);
|
||||
LOGF_ERROR("Failed to retrieve GSMTC session manager: 0x{:X}", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +39,7 @@ static GlobalSystemMediaTransportControlsSession GetCurrentSession()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve current GSMTC session: 0x%08X\n", to_hresult().value);
|
||||
LOGF_ERROR("Failed to retrieve current GSMTC session: 0x{:X}", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +57,7 @@ static GlobalSystemMediaTransportControlsSessionPlaybackInfo GetPlaybackInfo()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve GSMTC playback info: 0x%08X\n", to_hresult().value);
|
||||
LOGF_ERROR("Failed to retrieve GSMTC playback info: 0x{:X}", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
@ -74,7 +75,7 @@ bool os::media::detail::IsExternalMediaPlaying()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve GSMTC playback status: 0x%08X\n", to_hresult().value);
|
||||
LOGF_ERROR("Failed to retrieve GSMTC playback status: 0x{:X}", to_hresult().value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <ui/window.h>
|
||||
#include <ui/window_events.h>
|
||||
#include <user/config.h>
|
||||
#include <os/logger.h>
|
||||
|
||||
uint32_t m_lastCheckpointScore = 0;
|
||||
float m_lastDarkGaiaEnergy = 0.0f;
|
||||
|
|
@ -25,7 +26,7 @@ PPC_FUNC(sub_82624308)
|
|||
|
||||
m_lastCheckpointScore = pGameDocument->m_pMember->m_Score;
|
||||
|
||||
printf("[*] Score: %d\n", m_lastCheckpointScore);
|
||||
LOGFN("Score: {}", m_lastCheckpointScore);
|
||||
}
|
||||
|
||||
/* Hook function that resets the score
|
||||
|
|
@ -43,7 +44,7 @@ PPC_FUNC(sub_8245F048)
|
|||
if (!pGameDocument)
|
||||
return;
|
||||
|
||||
printf("[*] Score: %d\n", m_lastCheckpointScore);
|
||||
LOGFN("Score: {}", m_lastCheckpointScore);
|
||||
|
||||
pGameDocument->m_pMember->m_Score = m_lastCheckpointScore;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <user/achievement_data.h>
|
||||
#include <user/config.h>
|
||||
#include <api/SWA.h>
|
||||
#include <os/logger.h>
|
||||
|
||||
const char* m_pStageID;
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ PPC_FUNC(sub_824E5170)
|
|||
{
|
||||
if (!m_isSavedAchievementData)
|
||||
{
|
||||
printf("[*] Saving achievements...\n");
|
||||
LOGN("Saving achievements...");
|
||||
|
||||
AchievementData::Save();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "kernel/memory.h"
|
||||
#include "ui/sdl_listener.h"
|
||||
#include "ui/options_menu.h"
|
||||
#include <kernel/memory.h>
|
||||
#include <ui/sdl_listener.h>
|
||||
#include <ui/options_menu.h>
|
||||
#include <os/logger.h>
|
||||
|
||||
class FrontendListener : public SDLEventListener
|
||||
{
|
||||
|
|
@ -26,7 +27,7 @@ public:
|
|||
|
||||
*ms_IsRenderHud = !*ms_IsRenderHud;
|
||||
|
||||
printf("[*] HUD %s\n", *ms_IsRenderHud ? "On" : "Off");
|
||||
LOGFN("HUD {}", *ms_IsRenderHud ? "ON" : "OFF");
|
||||
|
||||
m_isF8KeyDown = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <res/images/game_icon.bmp.h>
|
||||
#include <res/images/game_icon_night.bmp.h>
|
||||
#include <os/logger.h>
|
||||
#include <os/version.h>
|
||||
#include <ui/window_events.h>
|
||||
#include <user/config.h>
|
||||
|
|
@ -35,7 +36,7 @@ public:
|
|||
auto surface = SDL_LoadBMP_RW(rw, 1);
|
||||
|
||||
if (!surface)
|
||||
printf("Failed to load icon: %s\n", SDL_GetError());
|
||||
LOGF_ERROR("Failed to load icon: {}", SDL_GetError());
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
|
@ -190,7 +191,7 @@ public:
|
|||
|
||||
if (displayCount <= 0)
|
||||
{
|
||||
printf("Failed to validate window position: %s\n", SDL_GetError());
|
||||
LOGF_ERROR("Failed to validate window position: {}", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "achievement_data.h"
|
||||
#include <ui/achievement_overlay.h>
|
||||
#include <user/config.h>
|
||||
#include <os/logger.h>
|
||||
|
||||
#define NUM_RECORDS sizeof(Data.Records) / sizeof(Record)
|
||||
|
||||
|
|
@ -112,7 +113,7 @@ void AchievementData::Load()
|
|||
|
||||
if (!file)
|
||||
{
|
||||
printf("[*] ERROR: failed to read achievement data.\n");
|
||||
LOGN_ERROR("Failed to read achievement data.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ void AchievementData::Load()
|
|||
|
||||
if (!VerifySignature())
|
||||
{
|
||||
printf("[*] ERROR: invalid achievement data signature.\n");
|
||||
LOGN_ERROR("Invalid achievement data signature.");
|
||||
|
||||
char sig[4] = ACH_SIGNATURE;
|
||||
|
||||
|
|
@ -138,7 +139,7 @@ void AchievementData::Load()
|
|||
|
||||
if (!VerifyVersion())
|
||||
{
|
||||
printf("[*] ERROR: unsupported achievement data version.\n");
|
||||
LOGN_ERROR("Unsupported achievement data version.");
|
||||
Data.Version = ACH_VERSION;
|
||||
file.close();
|
||||
return;
|
||||
|
|
@ -150,7 +151,7 @@ void AchievementData::Load()
|
|||
// TODO: display error message to user before wiping data?
|
||||
if (!VerifyChecksum())
|
||||
{
|
||||
printf("[*] ERROR: achievement data checksum mismatch.\n");
|
||||
LOGN_ERROR("Achievement data checksum mismatch.");
|
||||
memset(&Data.Records, 0, sizeof(Data.Records));
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +164,7 @@ void AchievementData::Save()
|
|||
|
||||
if (!file)
|
||||
{
|
||||
printf("[*] ERROR: failed to write achievement data.\n");
|
||||
LOGN_ERROR("Failed to write achievement data.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "config.h"
|
||||
#include <os/logger.h>
|
||||
|
||||
void Config::Load()
|
||||
{
|
||||
|
|
@ -18,13 +19,13 @@ void Config::Load()
|
|||
{
|
||||
def->ReadValue(toml);
|
||||
#if _DEBUG
|
||||
printf("%s (0x%p)\n", def->GetDefinition().c_str(), def->GetValue());
|
||||
LOGFN_UTILITY("{} (0x{:X})", def->GetDefinition().c_str(), (intptr_t)def->GetValue());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
catch (toml::parse_error& err)
|
||||
{
|
||||
printf("[*] Failed to parse configuration: %s\n", err.what());
|
||||
LOGFN_ERROR("Failed to parse configuration: {}", err.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,6 +63,6 @@ void Config::Save()
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("[*] Failed to write configuration.\n");
|
||||
LOGN_ERROR("Failed to write configuration.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue