Quote:
Originally Posted by kolkoo
Well I couldn't figure it out either until I saw this thread -> Problems with Commanding Units which made me look into it and realise why my function calls were crashing and when I was trying to find the gamestate change function I saw where it changed the current gamestate. So it's basically Sheppard's credit that I found this in the first place :P
EDIT: Oh and it seems that TLS was introduced into warcraft III in patch 1.22
|
Warcraft 3 always used the Thread Local Storage, what makes you thinking it was introduced into Warcraft with the Patch 1.22?
/EDIT:
You can access other Threads Local Storage with this code:
Code:
__declspec(naked) DWORD GetCurrentTEB()
{
__asm
{
mov eax,fs:[0x18]
retn
}
}
DWORD WINAPI TestThread(LPVOID pParam)
{
printf("TEB of this Thread 0x%x\n", GetCurrentTEB());
bPrinted = TRUE;
while(TRUE)
Sleep(1000);
return TRUE;
}
INT main()
{
CreateThread(NULL, NULL, TestThread, 0,0,0);
while(!bPrinted)
Sleep(1);
// Enumerate all Threads in this Process ..!
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
THREADENTRY32 tEntry;
tEntry.dwSize = sizeof(tEntry);
if(Thread32First(hSnap, &tEntry))
do {
if(tEntry.th32OwnerProcessID != GetCurrentProcessId())
continue;
HANDLE hThreadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, tEntry.th32ThreadID);
if(hThreadHandle == INVALID_HANDLE_VALUE)
continue;
printf("Thread-Id 0x%x, TEB 0x%x\n", tEntry.th32ThreadID, GetTEBFromThread(hThreadHandle));
} while(Thread32Next(hSnap, &tEntry));
CloseHandle(hSnap);
return NULL;
}
TEB* GetTEBFromThread(HANDLE hThread)
{
pfnNtQueryInformationThread NtQueryInformationThread = (pfnNtQueryInformationThread) GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryInformationThread");
THREAD_BASIC_INFORMATION tbi;
THREAD_INFORMATION_CLASS tic = ThreadBasicInformation;
if (NtQueryInformationThread == NULL)
return NULL;
if (NtQueryInformationThread(hThread, tic, &tbi, sizeof(tbi), NULL) == NULL)
return (TEB*)tbi.TebBaseAddress;
return NULL;
}
Hope this helps