fixed
amb1164, SM was crashing due to interface changes from valve (this change is just to make the build update using the latest sdk)
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #if defined CRAZY_DEBUG
33 #include "sm_globals.h"
34 #include "sourcemm_api.h"
36 #include "LibrarySys.h"
45 IN MINIDUMP_TYPE DumpType,
46 IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
47 IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL
48 IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
51 DumpType = (MINIDUMP_TYPE)((int)DumpType|MiniDumpWithFullMemory|MiniDumpWithHandleData);
52 return MiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
55 FARPROC WINAPI GetProcAddress2(HMODULE hModule, LPCSTR lpProcName)
57 if (strcmp(lpProcName, "MiniDumpWriteDump") == 0)
59 return (FARPROC)MiniDumpWriteDump2;
62 return GetProcAddress(hModule, lpProcName);
65 class CrazyWindowsDebugger : public SMGlobalClass
68 void OnSourceModAllInitialized()
70 HANDLE hModuleList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
73 me32.dwSize = sizeof(MODULEENTRY32);
75 if (!Module32First(hModuleList, &me32))
77 Error("Could not initialize crazy debugger!");
84 if (strcasecmp(me32.szModule, "steam.dll") == 0)
86 IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)me32.modBaseAddr;
87 if (dos->e_magic != IMAGE_DOS_SIGNATURE)
89 Error("[SM] Could not detect steam.dll with valid DOS signature");
91 char *base = (char *)dos;
92 IMAGE_NT_HEADERS *nt = (IMAGE_NT_HEADERS *)(base + dos->e_lfanew);
93 if (nt->Signature != IMAGE_NT_SIGNATURE)
95 Error("[SM] Could not detect steam.dll with valid NT signature");
97 IMAGE_IMPORT_DESCRIPTOR *desc =
98 (IMAGE_IMPORT_DESCRIPTOR *)
99 (base + nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
100 if (base == (char *)desc)
102 Error("[SM] Could not find the steam.dll IAT");
106 if (desc->FirstThunk != 0)
108 IMAGE_THUNK_DATA *data = (IMAGE_THUNK_DATA *)(base + desc->OriginalFirstThunk);
109 DWORD *iat = (DWORD *)(base + desc->FirstThunk);
110 while (data->u1.Function)
112 if ((data->u1.Ordinal & IMAGE_ORDINAL_FLAG32) != IMAGE_ORDINAL_FLAG32)
114 IMAGE_IMPORT_BY_NAME *import = (IMAGE_IMPORT_BY_NAME *)(base + data->u1.AddressOfData);
115 if (strcmp((char *)import->Name, "GetProcAddress") == 0)
117 DWORD oldprot, oldprot2;
118 VirtualProtect(iat, 4, PAGE_READWRITE, &oldprot);
119 *iat = (DWORD)GetProcAddress2;
120 VirtualProtect(iat, 4, oldprot, &oldprot2);
133 } while (Module32Next(hModuleList, &me32));
139 Error("Could not find steam.dll's GetProcAddress IAT entry");
142 CloseHandle(hModuleList);