[String]: Use ARRAY_COUNT (#656)
This commit is contained in:
parent
54aabee08d
commit
24ccd9af3b
@ -688,7 +688,7 @@ namespace Components
|
||||
|
||||
ServerRunning = true;
|
||||
Terminate = false;
|
||||
ServerThread = std::thread([]
|
||||
ServerThread = Utils::Thread::CreateNamedThread("Mongoose", []
|
||||
{
|
||||
while (!Terminate)
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ namespace Components
|
||||
|
||||
Scheduler::Scheduler()
|
||||
{
|
||||
Thread = Utils::Thread::createNamedThread("Async Scheduler", []
|
||||
Thread = Utils::Thread::CreateNamedThread("Async Scheduler", []
|
||||
{
|
||||
while (!Kill)
|
||||
{
|
||||
|
@ -154,6 +154,9 @@ namespace Components
|
||||
// dvar setting function, unknown stuff related to server thread sync
|
||||
Utils::Hook::Set<std::uint8_t>(0x647781, 0xEB);
|
||||
|
||||
// make VA thread safe
|
||||
Utils::Hook(0x4785B0, Utils::String::VA, HOOK_JUMP).install()->quick();
|
||||
|
||||
Utils::Hook(0x627695, 0x627040, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x43D1C7, PacketEventStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x6272E3, FrameEpilogueStub, HOOK_JUMP).install()->quick();
|
||||
|
@ -10307,6 +10307,32 @@ namespace Game
|
||||
GfxLight sceneLights[253];
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
THREAD_VALUE_PROF_STACK = 0x0,
|
||||
THREAD_VALUE_VA = 0x1,
|
||||
THREAD_VALUE_COM_ERROR = 0x2,
|
||||
THREAD_VALUE_TRACE = 0x3,
|
||||
THREAD_VALUE_COUNT = 0x4,
|
||||
};
|
||||
|
||||
struct va_info_t
|
||||
{
|
||||
char va_string[2][1024];
|
||||
int index;
|
||||
};
|
||||
|
||||
struct TraceCheckCount
|
||||
{
|
||||
int global;
|
||||
int* partitions;
|
||||
};
|
||||
|
||||
struct TraceThreadInfo
|
||||
{
|
||||
TraceCheckCount checkcount;
|
||||
};
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#ifndef IDA
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
template <class Type, std::size_t n>
|
||||
constexpr auto ARRAY_COUNT(Type(&)[n]) { return n; }
|
||||
|
||||
namespace Utils::String
|
||||
{
|
||||
template <std::size_t Buffers, std::size_t MinBufferSize>
|
||||
@ -13,7 +16,7 @@ namespace Utils::String
|
||||
|
||||
[[nodiscard]] const char* get(const char* format, va_list ap)
|
||||
{
|
||||
++this->currentBuffer %= ARRAYSIZE(this->stringPool);
|
||||
++this->currentBuffer %= ARRAY_COUNT(this->stringPool);
|
||||
auto entry = &this->stringPool[this->currentBuffer];
|
||||
|
||||
if (!entry->size || !entry->buffer)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Utils::Thread
|
||||
{
|
||||
bool setName(const HANDLE t, const std::string& name)
|
||||
bool SetName(const HANDLE t, const std::string& name)
|
||||
{
|
||||
const Library kernel32("kernel32.dll");
|
||||
if (!kernel32)
|
||||
@ -19,7 +19,7 @@ namespace Utils::Thread
|
||||
return SUCCEEDED(setDescription(t, String::Convert(name).data()));
|
||||
}
|
||||
|
||||
bool setName(const DWORD id, const std::string& name)
|
||||
bool SetName(const DWORD id, const std::string& name)
|
||||
{
|
||||
auto* const t = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, id);
|
||||
if (!t) return false;
|
||||
@ -29,20 +29,20 @@ namespace Utils::Thread
|
||||
CloseHandle(t);
|
||||
});
|
||||
|
||||
return setName(t, name);
|
||||
return SetName(t, name);
|
||||
}
|
||||
|
||||
bool setName(std::thread& t, const std::string& name)
|
||||
bool SetName(std::thread& t, const std::string& name)
|
||||
{
|
||||
return setName(t.native_handle(), name);
|
||||
return SetName(t.native_handle(), name);
|
||||
}
|
||||
|
||||
bool setName(const std::string& name)
|
||||
bool SetName(const std::string& name)
|
||||
{
|
||||
return setName(GetCurrentThread(), name);
|
||||
return SetName(GetCurrentThread(), name);
|
||||
}
|
||||
|
||||
std::vector<DWORD> getThreadIds()
|
||||
std::vector<DWORD> GetThreadIds()
|
||||
{
|
||||
auto* const h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
@ -79,9 +79,9 @@ namespace Utils::Thread
|
||||
return ids;
|
||||
}
|
||||
|
||||
void forEachThread(const std::function<void(HANDLE)>& callback)
|
||||
void ForEachThread(const std::function<void(HANDLE)>& callback)
|
||||
{
|
||||
const auto ids = getThreadIds();
|
||||
const auto ids = GetThreadIds();
|
||||
|
||||
for (const auto& id : ids)
|
||||
{
|
||||
@ -98,9 +98,9 @@ namespace Utils::Thread
|
||||
}
|
||||
}
|
||||
|
||||
void suspendOtherThreads()
|
||||
void SuspendOtherThreads()
|
||||
{
|
||||
forEachThread([](const HANDLE thread)
|
||||
ForEachThread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
@ -109,9 +109,9 @@ namespace Utils::Thread
|
||||
});
|
||||
}
|
||||
|
||||
void resumeOtherThreads()
|
||||
void ResumeOtherThreads()
|
||||
{
|
||||
forEachThread([](const HANDLE thread)
|
||||
ForEachThread([](const HANDLE thread)
|
||||
{
|
||||
if (GetThreadId(thread) != GetCurrentThreadId())
|
||||
{
|
||||
|
@ -2,22 +2,22 @@
|
||||
|
||||
namespace Utils::Thread
|
||||
{
|
||||
bool setName(HANDLE t, const std::string& name);
|
||||
bool setName(DWORD id, const std::string& name);
|
||||
bool setName(std::thread& t, const std::string& name);
|
||||
bool setName(const std::string& name);
|
||||
bool SetName(HANDLE t, const std::string& name);
|
||||
bool SetName(DWORD id, const std::string& name);
|
||||
bool SetName(std::thread& t, const std::string& name);
|
||||
bool SetName(const std::string& name);
|
||||
|
||||
template <typename ...Args>
|
||||
std::thread createNamedThread(const std::string& name, Args&&... args)
|
||||
std::thread CreateNamedThread(const std::string& name, Args&&... args)
|
||||
{
|
||||
auto t = std::thread(std::forward<Args>(args)...);
|
||||
setName(t, name);
|
||||
SetName(t, name);
|
||||
return t;
|
||||
}
|
||||
|
||||
std::vector<DWORD> getThreadIds();
|
||||
void forEachThread(const std::function<void(HANDLE)>& callback);
|
||||
std::vector<DWORD> GetThreadIds();
|
||||
void ForEachThread(const std::function<void(HANDLE)>& callback);
|
||||
|
||||
void suspendOtherThreads();
|
||||
void resumeOtherThreads();
|
||||
void SuspendOtherThreads();
|
||||
void ResumeOtherThreads();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user