mirror of
https://github.com/ApfelTeeSaft/UniversalSlashingSimulator.git
synced 2026-08-27 03:43:34 +00:00
152 lines
4.8 KiB
C++
152 lines
4.8 KiB
C++
/**
|
|
* UniversalSlashingSimulator - Common Types and Definitions
|
|
*
|
|
* This file contains common type definitions, macros, and includes
|
|
* used throughout the project. All platform-specific definitions
|
|
* are centralized here.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#define NOMINMAX
|
|
#include <Windows.h>
|
|
|
|
namespace USS
|
|
{
|
|
// ========================================================================
|
|
// CRITICAL_SECTION RAII Wrapper
|
|
// ========================================================================
|
|
|
|
/**
|
|
* RAII wrapper for Windows CRITICAL_SECTION
|
|
* Safer than std::mutex when injected into processes - doesn't depend on CRT initialization
|
|
*/
|
|
class FCriticalSection
|
|
{
|
|
public:
|
|
FCriticalSection() { InitializeCriticalSection(&m_CS); }
|
|
~FCriticalSection() { DeleteCriticalSection(&m_CS); }
|
|
|
|
FCriticalSection(const FCriticalSection&) = delete;
|
|
FCriticalSection& operator=(const FCriticalSection&) = delete;
|
|
|
|
void Lock() { EnterCriticalSection(&m_CS); }
|
|
void Unlock() { LeaveCriticalSection(&m_CS); }
|
|
bool TryLock() { return TryEnterCriticalSection(&m_CS) != 0; }
|
|
|
|
private:
|
|
CRITICAL_SECTION m_CS;
|
|
};
|
|
|
|
/**
|
|
* RAII lock guard for FCriticalSection
|
|
*/
|
|
class FScopedLock
|
|
{
|
|
public:
|
|
explicit FScopedLock(FCriticalSection& CS) : m_CS(CS) { m_CS.Lock(); }
|
|
~FScopedLock() { m_CS.Unlock(); }
|
|
|
|
FScopedLock(const FScopedLock&) = delete;
|
|
FScopedLock& operator=(const FScopedLock&) = delete;
|
|
|
|
private:
|
|
FCriticalSection& m_CS;
|
|
};
|
|
|
|
using int8 = int8_t;
|
|
using int16 = int16_t;
|
|
using int32 = int32_t;
|
|
using int64 = int64_t;
|
|
using uint8 = uint8_t;
|
|
using uint16 = uint16_t;
|
|
using uint32 = uint32_t;
|
|
using uint64 = uint64_t;
|
|
|
|
using uintptr = uintptr_t;
|
|
using intptr = intptr_t;
|
|
|
|
enum class EResult : uint8
|
|
{
|
|
Success = 0,
|
|
Failed,
|
|
NotSupported,
|
|
InvalidVersion,
|
|
PatternNotFound,
|
|
HookFailed,
|
|
AlreadyInitialized,
|
|
NotInitialized,
|
|
|
|
InvalidState,
|
|
InvalidParameter,
|
|
|
|
InsufficientResources,
|
|
InventoryFull,
|
|
ItemNotFound,
|
|
|
|
BuildingNotFound,
|
|
BuildLimitReached,
|
|
InvalidPlacement,
|
|
|
|
TrapNotFound,
|
|
TrapNotReady
|
|
};
|
|
|
|
inline const char* ResultToString(EResult Result)
|
|
{
|
|
switch (Result)
|
|
{
|
|
case EResult::Success: return "Success";
|
|
case EResult::Failed: return "Failed";
|
|
case EResult::NotSupported: return "NotSupported";
|
|
case EResult::InvalidVersion: return "InvalidVersion";
|
|
case EResult::PatternNotFound: return "PatternNotFound";
|
|
case EResult::HookFailed: return "HookFailed";
|
|
case EResult::AlreadyInitialized: return "AlreadyInitialized";
|
|
case EResult::NotInitialized: return "NotInitialized";
|
|
case EResult::InvalidState: return "InvalidState";
|
|
case EResult::InvalidParameter: return "InvalidParameter";
|
|
case EResult::InsufficientResources:return "InsufficientResources";
|
|
case EResult::InventoryFull: return "InventoryFull";
|
|
case EResult::ItemNotFound: return "ItemNotFound";
|
|
case EResult::BuildingNotFound: return "BuildingNotFound";
|
|
case EResult::BuildLimitReached: return "BuildLimitReached";
|
|
case EResult::InvalidPlacement: return "InvalidPlacement";
|
|
case EResult::TrapNotFound: return "TrapNotFound";
|
|
case EResult::TrapNotReady: return "TrapNotReady";
|
|
default: return "Unknown";
|
|
}
|
|
}
|
|
|
|
#define USS_INTERFACE class
|
|
|
|
#define USS_NON_COPYABLE(ClassName) \
|
|
ClassName(const ClassName&) = delete; \
|
|
ClassName& operator=(const ClassName&) = delete;
|
|
|
|
#define USS_NON_MOVABLE(ClassName) \
|
|
ClassName(ClassName&&) = delete; \
|
|
ClassName& operator=(ClassName&&) = delete;
|
|
|
|
#ifdef USS_DEBUG
|
|
#define USS_LOG(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Info, fmt, ##__VA_ARGS__)
|
|
#define USS_WARN(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Warning, fmt, ##__VA_ARGS__)
|
|
#define USS_ERROR(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Error, fmt, ##__VA_ARGS__)
|
|
#else
|
|
#define USS_LOG(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Info, fmt, ##__VA_ARGS__)
|
|
#define USS_WARN(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Warning, fmt, ##__VA_ARGS__)
|
|
#define USS_ERROR(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Error, fmt, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
#define USS_FATAL(fmt, ...) ::USS::Log::Write(::USS::ELogLevel::Fatal, fmt, ##__VA_ARGS__)
|
|
|
|
} |