/xliveless.cpp
https://bitbucket.org/zabb65/xliveless-dirt3 · C++ · 1303 lines · 932 code · 190 blank · 181 comment · 104 complexity · 0939c8ba7bb9df41c9cec7e4db0e86fb MD5 · raw file
- // -No Copyright- 2010 Stanislav "listener" Golovin
- // This file donated to the public domain
- #include "stdafx.h"
-
- typedef ULONGLONG XUID;
- typedef XUID *PXUID;
-
- typedef struct {
- WORD wActionId;
- WCHAR wszActionText[23];
- DWORD dwFlags;
- }XCUSTOMACTION;
-
- typedef
- VOID
- (WINAPI *PXOVERLAPPED_COMPLETION_ROUTINE)(
- __in DWORD dwErrorCode,
- __in DWORD dwNumberOfBytesTransfered,
- __inout struct _XOVERLAPPED* pOverlapped);
-
-
- typedef struct _XOVERLAPPED {
- ULONG_PTR InternalLow;
- ULONG_PTR InternalHigh;
- ULONG_PTR InternalContext;
- HANDLE hEvent;
- PXOVERLAPPED_COMPLETION_ROUTINE pCompletionRoutine;
- DWORD_PTR dwCompletionContext;
- DWORD dwExtendedError;
- }XOVERLAPPED, *PXOVERLAPPED;
-
- #ifndef NO_TRACE
- CRITICAL_SECTION d_lock;
- static FILE * logfile;
- XLIVELESS_API void trace (char * message, ...) {
- if (!logfile)
- return;
- EnterCriticalSection (&d_lock);
- if (!logfile)
- return;
- SYSTEMTIME t;
- GetLocalTime (&t);
- fprintf (logfile, "%02d/%02d/%04d %02d:%02d:%02d.%03d ", t.wDay, t.wMonth, t.wYear, t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
- va_list arg;
- va_start (arg, message);
- vfprintf (logfile, message, arg);
- fflush (logfile);
- va_end (arg);
- LeaveCriticalSection (&d_lock);
- }
- #else
- #undef trace
- #define trace(message, ...)
- #endif
-
- XLIVELESS_API GameVersion dwGameVersion = GvUnknown;
- XLIVELESS_API DWORD dwLoadOffset = 0x400000;
-
- // Delphi don't support importing variables from DLL
- XLIVELESS_API GameVersion getGameVersion () { return dwGameVersion; }
- XLIVELESS_API DWORD getLoadOffset () { return dwLoadOffset; }
-
- XLIVELESS_API void injectFunction (DWORD dwAddress, DWORD pfnReplacement) {
- dwAddress += dwLoadOffset;
- BYTE * patch = (BYTE *)dwAddress;
- *patch = 0xE9; // JMP
- *(DWORD *)(patch+1) = (pfnReplacement-(dwAddress+5));
- }
-
-
- // === Start of xlive functions ===
- // TODO: move all GfWL functions to the separate file
- // #1: XWSAStartup
- extern "C" int __stdcall XWSAStartup (WORD wVersionRequested, LPWSADATA lpWsaData) {
- lpWsaData->wVersion = 2;
- trace ("XWSAStartup \n");
- return 0;
- }
-
- // #2: XWSACleanup
- extern "C" void __stdcall XWSACleanup () { // XWSACleanup
- trace ("XWSACleanup\n");
- }
-
- // #3: XCreateSocket
- extern "C" SOCKET __stdcall XCreateSocket (int af, int type, int protocol) {
- trace ("XCreateSocket (%d, %d, %d)\n", af, type, protocol);
- return INVALID_SOCKET;
- }
-
- // #4: XSockeClose
- extern "C" int __stdcall XSockeClose (SOCKET s) {
- trace ("XSockeClose)\n");
- return 0;
- }
-
- // #5: XSocketShutdown
- extern "C" int __stdcall XSocketShutdown (SOCKET s, int how) {
- trace ("XSocketShutdown\n");
- return 0;
- }
-
- // #6: XSocketIOCTLSocket
- extern "C" int __stdcall XSocketIOCTLSocket (SOCKET s, long cmd, long * argp) {
- trace ("XSocketIOCTLSocket\n");
- return 0;
- }
-
- // #7: XSocketSetSockOpt
- extern "C" int __stdcall XSocketSetSockOpt (SOCKET s, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSocketSetSockOpt\n");
- return 0;
- }
-
- // #9: XSocketGetSockName
- extern "C" int __stdcall XSocketGetSockName (SOCKET s, sockaddr_in * name, int * namelen) {
- trace ("XSocketGetSockName\n");
- if (namelen && name && *namelen == sizeof (sockaddr_in))
- memset (name, 0, sizeof (sockaddr_in));
- return 0;
- }
-
- // #11: XSocketBind
- extern "C" SOCKET __stdcall XSocketBind (SOCKET s, sockaddr_in * addr, int * addrlen) {
- trace ("XSocketBind\n");
- return INVALID_SOCKET;
- }
-
- // #12: XSocketConnect
- extern "C" int __stdcall XSocketConnect (SOCKET s, sockaddr_in * addr, int * addrlen) {
- trace ("XSocketConnect\n");
- return 0;
- }
-
- // #13: XSocketListen
- extern "C" int __stdcall XSocketListen (SOCKET s, int backlog) {
- trace ("XSocketListen\n");
- return 0;
- }
-
- // #14: XSocketAccept
- extern "C" SOCKET __stdcall XSocketAccept (SOCKET s, sockaddr_in * addr, int * addrlen) {
- trace ("XSocketAccept\n");
- return INVALID_SOCKET;
- }
-
- // #15: XSocketSelect
- extern "C" int __stdcall XSocketSelect (int n, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, const struct timeval * timeout) {
- trace ("XSocketSelect\n");
- return 0;
- }
-
- // #18: XSocketRecv
- extern "C" int __stdcall XSocketRecv (SOCKET s, char * buf, int len, int flags) {
- return 0;
- }
-
- // #20: XSocketRecvFrom
- extern "C" int __stdcall XSocketRecvFrom (SOCKET s, char * buf, int len, int flags, sockaddr_in * from, int fromlen) {
- return 0;
- }
-
- // #22: XSocketSend
- extern "C" int __stdcall XSocketSend (SOCKET s, char * buf, int len, int flags) {
- return 0;
- }
-
- // #24: XSocketSendTo
- extern "C" int __stdcall XSocketSendTo (SOCKET s, char * buf, int len, int flags, sockaddr_in * to, int tolen) {
- return 0;
- }
-
- // #26: XSocketInet_Addr
- extern "C" int __stdcall XSocketInet_Addr (char *) {
- trace ("XSocketInet_Addr\n");
- return 0;
- }
-
- // #27: XWSAGetLastError
- extern "C" int __stdcall XWSAGetLastError () {
- return WSAENETDOWN; // 0 ?
- }
-
- // #37 XSocketHTONL
- extern "C" DWORD __stdcall XSocketHTONL (DWORD n) {
- return ((n&0xFF000000) >> 24)|((n & 0x00FF0000) >> 8)|((n&0x0000FF00) << 8)|((n & 0x000000FF) << 24);
- //return htonl(n);
- }
-
- // #38: XSocketNTOHS
- extern "C" WORD __stdcall XSocketNTOHS (WORD n) {
- //return ntohs(n);
- return ((n&0xFF00) >> 8)|((n&0xFF) << 8);
- }
-
- // #39: XSocketNTOHL
- extern "C" DWORD __stdcall XSocketNTOHL (DWORD n) {
- //return ntohl(n);
- return ((n&0xFF000000) >> 24)|((n & 0x00FF0000) >> 8)|((n&0x0000FF00) << 8)|((n & 0x000000FF) << 24);
- }
-
- // #40 XSocketHTONS
- extern "C" WORD __stdcall XSocketHTONS (WORD n) {
- return ((n&0xFF00) >> 8)|((n&0xFF) << 8);
- //return htons(n);
- }
-
- // #51: XNetStartup
- extern "C" int __stdcall XNetStartup (void *) { // XNetStartup(XNetStartupParams *)
- trace ("XNetStartup\n");
- return 0;
- }
-
- // #52: XNetCleanup
- extern "C" int __stdcall XNetCleanup () {
- trace ("xlive_52: XNetCleanup\n");
- return 0;
- }
-
- // #54: XNetCreateKey
- extern "C" int __stdcall XNetCreateKey (void * pxnkid, void * pxnkey) {
- trace ("XNetCreateKey\n");
- return 0;
- }
-
- // #55: XNetRegisterKey
- extern "C" int __stdcall XNetRegisterKey (DWORD, DWORD) {
- return 0;
- }
-
- // #56: XNetUnregisterKey
- extern "C" int __stdcall XNetUnregisterKey (DWORD) {
- return 0;
- }
-
- // #57: XNetXnAddrToInAddr
- extern "C" int __stdcall XNetXnAddrToInAddr (DWORD, DWORD, DWORD * p) {
- *p = 0;
- return 0;
- }
-
- // #58: XNetServerToInAddr
- extern "C" DWORD __stdcall XNetServerToInAddr (DWORD, DWORD, DWORD) {
- return 0;
- }
-
- // #60: XNetInAddrToXnAddr
- extern "C" DWORD __stdcall XNetInAddrToXnAddr (DWORD, DWORD, DWORD) {
- return 0;
- }
-
- // #63: XNetUnregisterInAddr
- extern "C" int __stdcall XNetUnregisterInAddr (DWORD) {
- return 0;
- }
-
- // #64: XNetXnAddrToMachineId
- extern "C" DWORD __stdcall XNetXnAddrToMachineId (DWORD, ULONGLONG* out) {
- *out = 0ULL;
- return 0;
- }
-
- // #65: XNetConnect
- extern "C" int __stdcall XNetConnect (DWORD) {
- return 0;
- }
-
- // #66: XNetGetConnectStatus
- extern "C" int __stdcall XNetGetConnectStatus (DWORD) {
- trace ("XNetGetConnectStatus\n");
- return 0;
- }
-
- // #69: XNetQosListen
- extern "C" DWORD __stdcall XNetQosListen (DWORD, DWORD, DWORD, DWORD, DWORD) {
- return 0;
- }
-
- // #70: XNetQosLookup
- extern "C" DWORD __stdcall XNetQosLookup (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- return 0;
- }
-
- // #71: XNetQosServiceLookup
- extern "C" DWORD __stdcall XNetQosServiceLookup (DWORD, DWORD, DWORD) {
- return 0;
- }
-
- // #72: XNetQosRelease
- extern "C" DWORD __stdcall XNetQosRelease (DWORD) {
- return 0;
- }
-
- // #73: XNetGetTitleXnAddr
- extern "C" DWORD __stdcall XNetGetTitleXnAddr (DWORD * pAddr) {
- *pAddr = 0x0100007F; // 127.0.0.1
- return 4;
- }
-
- // #75: XNetGetEthernetLinkStatus
- extern "C" DWORD __stdcall XNetGetEthernetLinkStatus () {
- return 1;
- }
-
- // #84: XNetSetSystemLinkPort
- extern "C" DWORD __stdcall XNetSetSystemLinkPort (DWORD) {
- return 0;
- }
-
- // #473: XCustomGetLastActionPress
- extern "C" int __stdcall XCustomGetLastActionPress (DWORD, DWORD, DWORD) {
- trace ("XCustomGetLastActionPress\n");
- return 0;
- }
- extern "C" DWORD __stdcall XCustomGetLastActionPressEx (DWORD*, DWORD*, XUID*, WORD*) {
- trace ("XCustomGetLastActionPressEx\n");
- return ERROR_NO_DATA;
- }
-
- // #651: XNotifyGetNext
- extern "C" int __stdcall XNotifyGetNext (HANDLE hNotification, DWORD dwMsgFilter, DWORD * pdwId, void * pParam) {
- return 0; // no notifications
- }
-
- // #652: XNotifyPositionUI
- extern "C" DWORD __stdcall XNotifyPositionUI (DWORD dwPosition) {
- trace ("XNotifyPositionUI (%d)\n", dwPosition);
- return 0;
- }
-
- // #1082: XGetOverlappedExtendedError
- extern "C" DWORD __stdcall XGetOverlappedExtendedError (void *) {
- trace ("XGetOverlappedExtendedError\n");
- return 0;
- }
-
- // #1083: XGetOverlappedResult
- extern "C" DWORD __stdcall XGetOverlappedResult (PXOVERLAPPED buffer, DWORD* pResult, DWORD bWait) {
- trace ("XGetOverlappedResult(%p, %p, %x)\n", buffer, pResult, bWait);
- if(!buffer)
- return ERROR_INVALID_PARAMETER;
-
- trace ("XGetOverlappedResult(): InternalLow: %x InternalHigh: %x InternalContext: %x, hEvent: %x CompletionRoutine: %p CompletionContext: %p ExtendedError: %x\n",
- buffer->InternalLow, buffer->InternalHigh, buffer->InternalContext, buffer->hEvent, buffer->pCompletionRoutine, buffer->dwCompletionContext, buffer->dwExtendedError);
- if(buffer->InternalLow == 0xC0DEBEEF)
- *pResult = buffer->InternalHigh;
- return 0;
- }
-
- // #5000: XLiveInitialize
- extern "C" int __stdcall XLiveInitialize (DWORD) { // XLiveInitialize(struct _XLIVE_INITIALIZE_INFO *)
- trace ("XLiveInitialize\n");
- return 0;
- }
-
- // #5001: XLiveInput
- extern "C" int __stdcall XLiveInput (DWORD * p) {
- // trace ("XLiveInput\n");
- p[5] = 0;
- return 1; // -1 ?
- }
-
-
- // #5002: XLiveRender
- extern "C" int __stdcall XLiveRender () {
- // trace ("XLiveRender\n");
- return 0;
- }
-
- // #5003: XLiveUninitialize
- extern "C" int __stdcall XLiveUninitialize () {
- trace ("XLiveUninitialize\n");
- return 0;
- }
-
- // #5005: XLiveOnCreateDevice
- extern "C" int __stdcall XLiveOnCreateDevice (DWORD, DWORD) {
- trace ("XLiveOnCreateDevice\n");
- return 0;
- }
-
- extern "C" DWORD __stdcall xlive_5006 () {
- trace ("xlive_5006\n");
- return 0;
- }
-
- // #5007: XLiveOnResetDevice
- extern "C" int __stdcall XLiveOnResetDevice (DWORD) {
- trace ("XLiveOnResetDevice\n");
- return 0;
- }
-
- // #5008: XHVCreateEngine
- extern "C" int __stdcall XHVCreateEngine (DWORD, DWORD, void ** ppEngine) {
- trace ("XHVCreateEngine\n");
- if (ppEngine)
- *ppEngine = NULL;
- return -1; // disable live voice
- }
-
- // #5022: XLiveGetUpdateInformation
- extern "C" int __stdcall XLiveGetUpdateInformation (DWORD) {
- trace ("XLiveGetUpdateInformation\n");
- return -1; // no update
- }
-
- // #5024: XLiveUpdateSystem
- extern "C" int __stdcall XLiveUpdateSystem (DWORD) {
- trace ("XLiveUpdateSystem\n");
- return -1; // no update
- }
-
- // #5028
- extern "C" DWORD __stdcall XLiveSecureLoadLibraryW (LPCWSTR path, HMODULE* handle, DWORD flags) {
- trace ("XLiveSecureLoadLibraryW\n");
- HMODULE module = LoadLibraryExW(path, NULL, flags);
- if(module)
- *handle = module;
- return GetLastError() | REASON_LEGACY_API;
- }
-
- // #5029
- extern "C" DWORD __stdcall XLiveSecureFreeLibrary(HMODULE module) {
- trace ("XLiveSecureFreeLibrary\n");
- FreeLibrary(module);
- return GetLastError() | REASON_LEGACY_API;
- }
-
- // #5030: XLivePreTranslateMessage
- extern "C" int __stdcall XLivePreTranslateMessage (DWORD) {
- return 0;
- }
-
- // #5031 XLiveSetDebugLevel
- extern "C" int __stdcall XLiveSetDebugLevel (DWORD xdlLevel, DWORD * pxdlOldLevel) {
- trace ("XLiveSetDebugLevel (%d)\n", xdlLevel);
- return 0;
- }
-
- // #5214: XShowPlayerReviewUI
- extern "C" int __stdcall XShowPlayerReviewUI (DWORD, DWORD, DWORD) {
- trace ("XShowPlayerReviewUI\n");
- return 0;
- }
-
- // #5215: XShowGuideUI
- extern "C" int __stdcall XShowGuideUI (DWORD) {
- trace ("XShowGuideUI\n");
- return 1;
- }
-
- // #5216: XShowKeyboardUI
- extern "C" int __stdcall XShowKeyboardUI (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XShowKeyboardUI\n");
- return 0;
- }
-
- // #5250
- extern "C" DWORD __stdcall xlive_5250 (DWORD) {
- trace ("xlive_5250\n");
- return 0;
- }
-
- // #5251: XCloseHandle
- extern "C" int __stdcall XCloseHandle (HANDLE handle) {
- trace ("XCloseHandle\n");
- if(!handle || handle == (HANDLE)-1)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
- }
- CloseHandle(handle);
- return 0;
- }
-
- // #5252: XShowGamerCardUI
- extern "C" int __stdcall XShowGamerCardUI (DWORD, DWORD, DWORD) {
- trace ("XShowGamerCardUI\n");
- return 0;
- }
-
- // #5254: XCancelOverlapped
- extern "C" int __stdcall XCancelOverlapped (DWORD* buffer) {
- trace ("XCancelOverlapped\n");
- if(buffer[0] == 0xDEADC0DE)
- {
- buffer[0] = 0;
- }
- return 0;
- }
-
- // #5256: XEnumerate
- extern "C" int __stdcall XEnumerate (HANDLE hEnum, void * pvBuffer, DWORD cbBuffer, DWORD * pcItemsReturned, void * pOverlapped) { // XEnumerate
- trace ("XEnumerate (buffer=> %p[%d])\n", pvBuffer, cbBuffer);
- // if (pvBuffer && cbBuffer)
- // memset (pvBuffer, 0, cbBuffer);
- if (pcItemsReturned)
- *pcItemsReturned = 0;
- return 0; // some error ?
- }
-
- // #5260: XShowSigninUI
- extern "C" int __stdcall XShowSigninUI (DWORD, DWORD) {
- trace ("XShowSigninUI\n");
- return 0;
- }
-
- // #5261: XUserGetXUID
- extern "C" int __stdcall XUserGetXUID (DWORD, DWORD * pXuid) {
- trace ("XUserGetXUID\n");
- pXuid[0] = 0xC0DEBEEF;
- pXuid[1] = 0x10001010;
- return 0; // ???
- }
-
-
- // #5262: XUserGetSigninState
- extern "C" int __stdcall XUserGetSigninState (DWORD dwUserIndex) {
- trace ("xlive_5262: XUserGetSigninState (%d)\n", dwUserIndex);
- if(dwUserIndex)
- return 0;
- return 2; // eXUserSigninState_SignedInLocally
- }
-
- // #5263: XUserGetName
- extern "C" int __stdcall XUserGetName (DWORD dwUserId, char * pBuffer, DWORD dwBufLen) {
- trace ("xlive_5263: XUserGetName (%d, .. , %d)\n", dwUserId, dwBufLen);
- if (dwBufLen < 8)
- return 1;
- memcpy (pBuffer, "Profile1", 8);
- return 0;
- }
-
- // #5264: XUserAreUsersFriends
- extern "C" int __stdcall XUserAreUsersFriends(DWORD dwUserIndex, DWORD * pXuids, DWORD dwXuidCount, DWORD * pResult, void * pOverlapped) {
- trace ("XUserAreUsersFriends\n");
- return ERROR_NOT_LOGGED_ON;
- }
-
- // #5265: XUserCheckPrivilege
- extern "C" int __stdcall XUserCheckPrivilege (DWORD user, DWORD priv, PBOOL b) {
- trace ("XUserCheckPrivilege (%d, %d, ..)\n", user, priv);
- *b = false;
- return ERROR_NOT_LOGGED_ON;
- }
-
- // #5266
- extern "C" DWORD __stdcall xlive_5266(DWORD p1, DWORD* p2, DWORD* p3, DWORD p4, DWORD p5, DWORD p6, DWORD p7, DWORD* p8, PXOVERLAPPED p9) {
- trace ("xlive_5266(%x, %p, %p, %x, %p, %x, %x, %p, %p)\n", p1, p2, p3, p4, p5, p6, p7, p8, p9);
- *p8 = 0;
- p9->InternalLow = 0xC0DEBEEF;
- p9->InternalHigh = 0;
- return 0;
- }
-
- struct XUSER_SIGNIN_INFO {
- DWORD xuidL; // 0
- DWORD xuidH; // 4
- DWORD dwInfoFlags; // 8
- DWORD UserSigninState; // 12
- DWORD dwGuestNumber; // 16
- DWORD dwSponsorUserIndex; // 20
- CHAR szUserName[16]; // 24
- };
-
- // #5267: XUserGetSigninInfo
- extern "C" int __stdcall XUserGetSigninInfo (DWORD dwUser, DWORD dwFlags, XUSER_SIGNIN_INFO * pInfo) {
- //trace ("XUserGetSigninInfo (%d, %d, ...)\n", dwUser, dwFlags);
- memset(pInfo, 0, sizeof(XUSER_SIGNIN_INFO));
- if(dwFlags & 2)
- {
- pInfo->UserSigninState = 2;
- }
- else
- {
- pInfo->UserSigninState = 1;
- }
- pInfo->xuidL = 0x10001010;
- pInfo->xuidH = 0xC0DEBEEF;
- pInfo->dwInfoFlags = 1;
- pInfo->dwGuestNumber = 0;
- pInfo->dwSponsorUserIndex = 254;
- strcpy(pInfo->szUserName, "Profile1");
- return 0;
- }
-
- // #5270: XNotifyCreateListener
- extern "C" HANDLE __stdcall XNotifyCreateListener (DWORD l, DWORD h) {
- trace ("xlive_5270: XNotifyCreateListener (0x%08x%08x)\n", h, l);
- return (HANDLE)1; // any non-zero value. (zero treated as fatal error)
- }
-
- // #5273: XUserReadGamerpictureByKey
- extern "C" int __stdcall XUserReadGamerpictureByKey (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XUserReadGamerpictureByKey\n");
- return 0;
- }
-
- // #5274: unknown friend api
- extern "C" DWORD __stdcall xlive_5274(DWORD, DWORD, DWORD, DWORD) {
- trace ("xlive_5274\n");
- return 0;
- }
-
- // #5275: XShowFriendsUI
- extern "C" int __stdcall XShowFriendsUI (DWORD) {
- trace ("XShowFriendsUI\n");
- return 0;
- }
-
- // #5276: XUserSetProperty
- extern "C" int __stdcall XUserSetProperty (DWORD, DWORD, DWORD, DWORD) {
- trace ("XUserSetProperty\n");
- return 0;
- }
-
- // #5277: XUserSetContext
- extern "C" int __stdcall XUserSetContext (DWORD, DWORD, DWORD) {
- trace ("XUserSetContext\n");
- return 0;
- }
-
- // #5278: XUserWriteAchievements
- extern "C" DWORD __stdcall XUserWriteAchievements (DWORD, DWORD, DWORD) {
- trace ("XUserWriteAchievements\n");
- return 0;
- }
-
- // #5280: XUserCreateAchievementEnumerator
- extern "C" DWORD __stdcall XUserCreateAchievementEnumerator (DWORD dwTitleId, DWORD dwUserIndex, DWORD xuidL, DWORD xuidHi, DWORD dwDetailFlags, DWORD dwStartingIndex, DWORD cItem, DWORD * pcbBuffer, HANDLE * phEnum) {
- trace ("XUserCreateAchievementEnumerator (dwStartingIndex=>%d, cItem=>%d \n", dwStartingIndex, cItem);
- if (pcbBuffer)
- *pcbBuffer = 0;
- if (phEnum)
- *phEnum = INVALID_HANDLE_VALUE;
- return 1; // return error (otherwise, 0-size buffer will be allocated)
- }
-
- // #5281: XUserReadStats
- extern "C" DWORD __stdcall XUserReadStats (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD * pcbResults, DWORD * pResults, void *) {
- trace ("XUserReadStats\n");
- if (pcbResults)
- *pcbResults = 4;
- if (pResults)
- *pResults = 0;
- return 0;
- }
-
- // #5284: XUserCreateStatsEnumeratorByRank
- extern "C" DWORD __stdcall XUserCreateStatsEnumeratorByRank (DWORD dwTitleId, DWORD dwRankStart, DWORD dwNumRows, DWORD dwNuStatSpec, void * pSpecs, DWORD * pcbBuffer, PHANDLE phEnum) {
- trace ("XUserCreateStatsEnumeratorByRank\n");
- if (pcbBuffer)
- *pcbBuffer = 0;
- *phEnum = INVALID_HANDLE_VALUE;
- return 1;
- }
-
- // #5286: XUserCreateStatsEnumeratorByXuid
- extern "C" DWORD __stdcall XUserCreateStatsEnumeratorByXuid (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD * pcbBuffer, PHANDLE phEnum) {
- trace ("XUserCreateStatsEnumeratorByXuid\n");
- if (pcbBuffer)
- pcbBuffer = 0;
- *phEnum = INVALID_HANDLE_VALUE;
- return 1;
- }
-
- // #5292: XUserSetContextEx
- extern "C" int __stdcall XUserSetContextEx (DWORD dwUserIndex, DWORD dwContextId, DWORD dwContextValue, void * pOverlapped) {
- trace ("XUserSetContextEx\n");
- return 0;
- }
-
- // #5293: XUserSetPropertyEx
- extern "C" int __stdcall XUserSetPropertyEx (DWORD dwUserIndex, DWORD dwPropertyId, DWORD cbValue, void * pvValue, void * pOverlapped) {
- trace ("XUserSetPropertyEx (%d, 0x%x, ...)\n", dwUserIndex, dwPropertyId);
- return 0;
- }
-
- // #5297: XLiveInitializeEx
- extern "C" int __stdcall XLiveInitializeEx (void * pXii, DWORD dwVersion) {
- trace ("XLiveInitializeEx\n");
- return 0;
- }
-
- // #5300: XSessionCreate
- extern "C" DWORD __stdcall XSessionCreate (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionCreate\n");
- return -1;
- }
-
- // #5303: XStringVerify
- extern "C" DWORD __stdcall XStringVerify (DWORD, DWORD, DWORD, DWORD, DWORD, WORD * pResult, DWORD) { // XStringVerify
- trace ("XStringVerify\n");
- *pResult = 0;
- return 0;
- }
-
- // #5305: XStorageUploadFromMemory
- extern "C" DWORD __stdcall XStorageUploadFromMemory (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XStorageUploadFromMemory\n");
- return 0;
- }
-
- // #5306: XStorageEnumerate
- extern "C" int __stdcall XStorageEnumerate (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) { // XStorageEnumerate
- trace ("XStorageEnumerate\n");
- return 0;
- }
-
- extern "C" DWORD __stdcall xlive_5309(DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("xlive_5309\n");
- return 0;
- }
-
- // #5310: XOnlineStartup
- extern "C" int __stdcall XOnlineStartup () {
- trace ("XOnlineStartup\n");
- return 0;
- }
-
- // #5311: XOnlineCleanup
- extern "C" int __stdcall XOnlineCleanup () {
- trace ("XOnlineCleanup\n");
- return 0;
- }
-
- // #5312: XFriendsCreateEnumerator
- extern "C" DWORD __stdcall XFriendsCreateEnumerator (DWORD, DWORD, DWORD, DWORD, HANDLE * phEnum) {
- trace ("XFriendsCreateEnumerator\n");
- *phEnum = INVALID_HANDLE_VALUE;
- return 0;
- }
-
- // #5314: XUserMuteListQuery
- extern "C" int __stdcall XUserMuteListQuery (DWORD, DWORD, DWORD, DWORD) {
- trace ("XUserMuteListQuery\n");
- return 0;
- }
-
- // #5315: XInviteGetAcceptedInfo
- extern "C" int __stdcall XInviteGetAcceptedInfo (DWORD, DWORD) {
- trace ("XInviteGetAcceptedInfo\n");
- return 1;
- }
-
- // #5316: XInviteSend
- extern "C" int __stdcall XInviteSend (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XInviteSend\n");
- return 0;
- }
-
- // #5317: XSessionWriteStats
- extern "C" DWORD __stdcall XSessionWriteStats (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionWriteStats\n");
- return 0;
- }
-
- // #5318
- extern "C" int __stdcall XSessionStart (DWORD, DWORD, DWORD) {
- trace ("XSessionStart\n");
- return 0;
- }
-
- // #5319: XSessionSearchEx
- extern "C" DWORD __stdcall XSessionSearchEx (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionSearchEx\n");
- return 0;
- }
-
- // #5320
- extern "C" DWORD __stdcall xlive_5320 (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("xlive_5320\n");
- return 0;
- }
-
- // #5321
- extern "C" DWORD __stdcall xlive_5321 (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD* p9, DWORD) {
- trace ("xlive_5321\n");
- if(p9)
- *p9 = 0;
- return 0;
- }
-
- // #5322: XSessionModify
- extern "C" DWORD __stdcall XSessionModify (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionModify\n");
- return 0;
- }
-
- // #5323: XSessionMigrateHost
- extern "C" DWORD __stdcall XSessionMigrateHost (DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionMigrateHost\n");
- return 0;
- }
-
- // #5324: XOnlineGetNatType
- extern "C" int __stdcall XOnlineGetNatType () {
- trace ("XOnlineGetNatType\n");
- return 0;
- }
-
- // #5325: XSessionLeaveLocal
- extern "C" DWORD __stdcall XSessionLeaveLocal (DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionLeaveLocal\n");
- return 0;
- }
-
- // #5326: XSessionJoinRemote
- extern "C" DWORD __stdcall XSessionJoinRemote (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionJoinRemote\n");
- return 0;
- }
-
- // #5327: XSessionJoinLocal
- extern "C" DWORD __stdcall XSessionJoinLocal (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionJoinLocal\n");
- return 0;
- }
-
- // #5328: XSessionGetDetails
- extern "C" DWORD __stdcall XSessionGetDetails (DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionGetDetails\n");
- return 0;
- }
-
- // #5329: XSessionFlushStats
- extern "C" int __stdcall XSessionFlushStats (DWORD, DWORD) {
- trace ("XSessionFlushStats\n");
- return 0;
- }
-
- // #5330: XSessionDelete
- extern "C" DWORD __stdcall XSessionDelete (DWORD, DWORD) {
- trace ("XSessionDelete\n");
- return 0;
- }
-
- struct XUSER_READ_PROFILE_SETTINGS {
- DWORD dwLength;
- BYTE * pSettings;
- };
-
- // #5331: XUserReadProfileSettings
- extern "C" DWORD __stdcall XUserReadProfileSettings (DWORD dwTitleId, DWORD dwUserIndex, DWORD dwNumSettingIds,
- DWORD * pdwSettingIds, DWORD * pcbResults, XUSER_READ_PROFILE_SETTINGS * pResults, DWORD pOverlapped) {
- trace ("XUserReadProfileSettings (%d, %d, %d, ..., %d, ...)\n", dwTitleId, dwUserIndex, dwNumSettingIds, *pcbResults);
- if (*pcbResults < 1036) {
- *pcbResults = 1036; // TODO: make correct calculation by IDs.
- return ERROR_INSUFFICIENT_BUFFER;
- }
- memset (pResults, 0, *pcbResults);
- pResults->dwLength = *pcbResults-sizeof (XUSER_READ_PROFILE_SETTINGS);
- pResults->pSettings = (BYTE *)pResults+sizeof (XUSER_READ_PROFILE_SETTINGS);
- return 0;
- }
-
- // #5332: XSessionEnd
- extern "C" int __stdcall XSessionEnd (DWORD, DWORD) {
- trace ("XSessionEnd\n");
- return 0;
- }
-
- // #5333: XSessionArbitrationRegister
- extern "C" DWORD __stdcall XSessionArbitrationRegister (DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionArbitrationRegister\n");
- return 0;
- }
-
- // #5335: XTitleServerCreateEnumerator
- extern "C" DWORD __stdcall XTitleServerCreateEnumerator (LPCSTR pszServerInfo, DWORD cItem, DWORD * pcbBuffer, PHANDLE phEnum) {
- trace ("XTitleServerCreateEnumerator (cItem=> %d)\n", cItem);
- if(pcbBuffer)
- *pcbBuffer = 0;
- *phEnum = INVALID_HANDLE_VALUE;
- return 1;
- }
-
- // #5336: XSessionLeaveRemote
- extern "C" DWORD __stdcall XSessionLeaveRemote (DWORD, DWORD, DWORD, DWORD) {
- trace ("XSessionLeaveRemote\n");
- return 0;
- }
-
- // #5337: XUserWriteProfileSettings
- extern "C" DWORD __stdcall XUserWriteProfileSettings (DWORD, DWORD, DWORD, DWORD) {
- trace ("XUserWriteProfileSettings\n");
- return 0;
- }
-
- // #5339: XUserReadProfileSettingsByXuid
- extern "C" DWORD __stdcall XUserReadProfileSettingsByXuid (DWORD, DWORD, DWORD, DWORD,DWORD, DWORD,DWORD, DWORD,DWORD) {
- trace ("XUserReadProfileSettingsByXuid\n");
- return 0;
- }
-
- // #5342
- extern "C" DWORD __stdcall xlive_5342(DWORD, DWORD, DWORD, DWORD) {
- trace ("xlive_5342\n");
- return 0;
- }
-
- // #5343: XLiveCalculateSkill
- extern "C" DWORD __stdcall XLiveCalculateSkill (DWORD, DWORD, DWORD, DWORD, DWORD) {
- trace ("XLiveCalculateSkill\n");
- return 0;
- }
-
- // #5344: XStorageBuildServerPath
- extern "C" DWORD __stdcall XStorageBuildServerPath (DWORD dwUserIndex, DWORD StorageFacility,
- void * pvStorageFacilityInfo, DWORD dwStorageFacilityInfoSize,
- void * pwszItemName, void * pwszServerPath, DWORD * pdwServerPathLength) {
- trace ("XStorageBuildServerPath\n");
- return 0;
- }
-
- // #5345: XStorageDownloadToMemory
- extern "C" DWORD __stdcall XStorageDownloadToMemory (DWORD dwUserIndex, DWORD, DWORD, DWORD, DWORD, DWORD, void * ) {
- trace ("XStorageDownloadToMemory\n");
- return 0;
- }
-
- // #5347 XLiveSecureLoadLibraryExW
-
- extern "C" DWORD __stdcall XLiveSecureLoadLibraryExW(DWORD a, DWORD, LPCWSTR lpModuleName, DWORD flags, HMODULE* handle) {
- trace ("XLiveSecureLoadLibraryExW\n");
- if(a)
- return E_INVALIDARG;
- return XLiveSecureLoadLibraryW(lpModuleName, handle, flags);
- }
-
- // #5348 XLiveSecureCreateFileW
- extern "C" DWORD __stdcall XLiveSecureCreateFileW (DWORD something, DWORD, LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD, DWORD dwFlagsAndAttributes, HANDLE* fileHandle)
- {
- trace ("XLiveSecureCreateFileW %S\n", lpFileName);
- if ( something )
- return E_INVALIDARG;
-
- *fileHandle = CreateFileW(
- lpFileName,
- dwDesiredAccess,
- dwShareMode,
- lpSecurityAttributes,
- 3u,
- dwFlagsAndAttributes,
- 0);
- return 0;
- }
-
- // #5349: XLiveProtectedVerifyFile
- extern "C" DWORD __stdcall XLiveProtectedVerifyFile (HANDLE hContentAccess, VOID * pvReserved, PCWSTR pszFilePath) {
- trace ("XLiveProtectedVerifyFile\n");
- return 0;
- }
-
- // #5350: XLiveContentCreateAccessHandle
- extern "C" DWORD __stdcall XLiveContentCreateAccessHandle (DWORD dwTitleId, void * pContentInfo,
- DWORD dwLicenseInfoVersion, void * xebBuffer, DWORD dwOffset, HANDLE * phAccess, void * pOverlapped) {
- trace ("XLiveContentCreateAccessHandle\n");
- if (phAccess)
- *phAccess = INVALID_HANDLE_VALUE;
- return E_OUTOFMEMORY; // TODO: fix it
- }
-
- // #5352: XLiveContentUninstall
- extern "C" DWORD __stdcall XLiveContentUninstall (void * pContentInfo, void * pxuidFor, void * pInstallCallbackParams) {
- trace ("XLiveContentUninstall\n");
- return 0;
- }
-
- // #5354
- extern "C" DWORD __stdcall xlive_5354(DWORD, DWORD) {
- trace ("xlive_5354\n");
- return 0;
- }
-
- // #5355: XLiveContentGetPath
- extern "C" DWORD __stdcall XLiveContentGetPath (DWORD dwUserIndex, void * pContentInfo, wchar_t * pszPath, DWORD * pcchPath) {
- trace ("XLiveContentGetPath\n");
- if (pcchPath)
- *pcchPath = 0;
- if (pszPath)
- *pszPath = 0;
- return 0;
- }
-
- // #5356
- extern "C" DWORD __stdcall xlive_5356 (DWORD, DWORD, DWORD, DWORD) {
- trace ("xlive_5356\n");
- return 0;
- }
-
- // #5360: XLiveContentCreateEnumerator
- extern "C" DWORD __stdcall XLiveContentCreateEnumerator (DWORD, void *, DWORD *pchBuffer, HANDLE * phContent) {
- trace ("XLiveContentCreateEnumerator\n");
- if (phContent)
- *phContent = 0;
- //*phContent = INVALID_HANDLE_VALUE;
- if (pchBuffer)
- *pchBuffer = 0;
- return 1;
- }
-
- // #5361: XLiveContentRetrieveOffersByDate
- extern "C" DWORD __stdcall XLiveContentRetrieveOffersByDate (DWORD dwUserIndex, DWORD dwOffserInfoVersion,
- SYSTEMTIME * pstStartDate, void * pOffserInfoArray, DWORD * pcOfferInfo, void * pOverlapped) {
- trace ("XLiveContentRetrieveOffersByDate\n");
- if (pcOfferInfo)
- *pcOfferInfo = 0;
- return 0;
- }
-
- // #5365: XShowMarketplaceUI
- extern "C" DWORD __stdcall XShowMarketplaceUI (DWORD dwUserIndex, DWORD dwEntryPoint, ULONGLONG dwOfferId, DWORD dwContentCategories) {
- return 1;
- }
-
- // === replacements ===
- struct FakeProtectedBuffer {
- DWORD dwMagick;
- DWORD dwSize;
- DWORD __fill[2]; // To match buffer size in Rick's wrapper
- BYTE bData[4];
- };
-
- // #5016: XLivePBufferAllocate
- extern "C" DWORD __stdcall XLivePBufferAllocate (int size, FakeProtectedBuffer ** pBuffer) {
- // trace ("xlive_5016: XLivePBufferAllocate (%d)\n", size);
- *pBuffer = (FakeProtectedBuffer *)malloc (size+16);
- if (!*pBuffer) {
- trace ("ERROR: XLivePBufferAllocate unable to allocate %d bytes\n", size);
- return E_OUTOFMEMORY;
- }
-
- (*pBuffer)->dwMagick = 0xDEADDEAD; // some arbitrary number
- (*pBuffer)->dwSize = size;
- return 0;
- }
-
- // #5017: XLivePBufferFree
- extern "C" DWORD __stdcall XLivePBufferFree (FakeProtectedBuffer * pBuffer) {
- // trace ("xlive_5017: XLivePBufferFree\n");
- if (pBuffer && pBuffer->dwMagick == 0xDEADDEAD)
- free (pBuffer);
- return 0;
- }
-
- // #5295: XLivePBufferSetByteArray
- extern "C" DWORD __stdcall XLivePBufferSetByteArray (FakeProtectedBuffer * pBuffer, DWORD offset, BYTE * source, DWORD size) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || !source || offset < 0 || offset+size > pBuffer->dwSize)
- return 0;
- memcpy (pBuffer->bData+offset, source, size);
- return 0;
- }
-
- // #5294: XLivePBufferGetByteArray
- extern "C" DWORD __stdcall XLivePBufferGetByteArray (FakeProtectedBuffer * pBuffer, DWORD offset, BYTE * destination, DWORD size) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || !destination || offset < 0 || offset+size > pBuffer->dwSize)
- return 0;
- memcpy (destination, pBuffer->bData+offset, size);
- return 0;
- }
-
- // #5019: XLivePBufferSetByte
- extern "C" DWORD __stdcall XLivePBufferSetByte (FakeProtectedBuffer * pBuffer, DWORD offset, BYTE value) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || offset < 0 || offset > pBuffer->dwSize)
- return 0;
- pBuffer->bData[offset] = value;
- return 0;
- }
-
- // #5018: XLivePBufferGetByte
- extern "C" DWORD __stdcall XLivePBufferGetByte (FakeProtectedBuffer * pBuffer, DWORD offset, BYTE * value) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || !value || offset < 0 || offset > pBuffer->dwSize)
- return 0;
- *value = pBuffer->bData[offset];
- return 0;
- }
-
- // #5020: XLivePBufferGetDWORD
- extern "C" DWORD __stdcall XLivePBufferGetDWORD (FakeProtectedBuffer * pBuffer, DWORD dwOffset, DWORD * pdwValue) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || dwOffset < 0 || dwOffset > pBuffer->dwSize-4 || !pdwValue)
- return 0;
- *pdwValue = *(DWORD *)(pBuffer->bData+dwOffset);
- return 0;
- }
-
- // #5021: XLivePBufferSetDWORD
- extern "C" DWORD __stdcall XLivePBufferSetDWORD (FakeProtectedBuffer * pBuffer, DWORD dwOffset, DWORD dwValue ) {
- if (!pBuffer || pBuffer->dwMagick != 0xDEADDEAD || dwOffset < 0 || dwOffset > pBuffer->dwSize-4)
- return 0;
- *(DWORD *)(pBuffer->bData+dwOffset) = dwValue;
- return 0;
- }
-
- // #5026: XLiveSetSponsorToken
- extern "C" DWORD __stdcall XLiveSetSponsorToken (LPCWSTR pwszToken, DWORD dwTitleId) {
- trace ("XLiveSetSponsorToken (, 0x%08x)\n", dwTitleId);
- return S_OK;
- }
-
- // #5036: XLiveCreateProtectedDataContext
- extern "C" DWORD __stdcall XLiveCreateProtectedDataContext (DWORD * dwType, PHANDLE pHandle) {
- trace ("XLiveCreateProtectedDataContext\n");
- if (pHandle)
- *pHandle = (HANDLE)1;
- return 0;
- }
-
- // #5037: XLiveQueryProtectedDataInformation
- extern "C" DWORD __stdcall XLiveQueryProtectedDataInformation (HANDLE h, DWORD * p) {
- trace ("XLiveQueryProtectedDataInformation\n");
- return 0;
- }
-
- // #5038: XLiveCloseProtectedDataContext
- extern "C" DWORD __stdcall XLiveCloseProtectedDataContext (HANDLE h) {
- trace ("XLiveCloseProtectedDataContext\n");
- return 0;
- }
-
- // #5035: XLiveUnprotectData
- extern "C" DWORD __stdcall XLiveUnprotectData (BYTE * pInBuffer, DWORD dwInDataSize, BYTE * pOutBuffer, DWORD * pDataSize, HANDLE * ph) {
- trace ("XLiveUnprotectData (..., %d, ..., %d, %d)\n", dwInDataSize, *pDataSize, *(DWORD*)ph);
- if (!pDataSize || !ph) // invalid parameter
- return E_FAIL;
- *ph = (HANDLE)1;
- if (!pOutBuffer || *pDataSize < dwInDataSize) {
- *pDataSize = dwInDataSize;
- return ERROR_INSUFFICIENT_BUFFER;
- }
- *pDataSize = dwInDataSize;
- memcpy (pOutBuffer, pInBuffer, dwInDataSize);
- return 0;
- }
-
- // #5034: XLiveProtectData
- extern "C" DWORD __stdcall XLiveProtectData (BYTE * pInBuffer, DWORD dwInDataSize, BYTE * pOutBuffer, DWORD * pDataSize, HANDLE h) {
- trace ("XLiveProtectData (..., %d, ..., %d, %d)\n", dwInDataSize, *pDataSize, (DWORD)h);
- *pDataSize = dwInDataSize;
- if (pOutBuffer)
- {
- memcpy (pOutBuffer, pInBuffer, dwInDataSize);
- }
- else
- {
- return 0x8007007A;
- }
- return 0;
- }
-
- // #5367
- extern "C" DWORD __stdcall xlive_5367 (HANDLE, DWORD, DWORD, BYTE *, DWORD) {
- trace ("xlive_5367\n");
- return 1;
- }
-
- // #5372
- extern "C" DWORD __stdcall xlive_5372 (HANDLE, DWORD, DWORD, DWORD, BYTE *, HANDLE) {
- trace ("xlive_5372\n");
- return 1;
- }
-
- // === end of xlive functions ===
-
- static char * pszPath = "";
-
- // change savefile path to "%USERPROFILE%\Documents\Rockstar Games\GTA IV\savegames\"
- void getSavefilePath (int __unused, char * pBuffer, char * pszSaveName) {
- strcpy_s (pBuffer, 256, pszPath);
- strcat_s (pBuffer, 256, "savegames");
-
- // check path and create directory if necessary
- DWORD attrs = GetFileAttributes (pBuffer);
- if (attrs == INVALID_FILE_ATTRIBUTES)
- CreateDirectory (pBuffer, NULL);
- else if (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
- trace ("ERROR: unable to create directory '%s', file '%s' already exists\n", pBuffer);
- strcpy_s (pBuffer, 256, pszSaveName);
- return;
- }
-
- if (pszSaveName) {
- strcat_s (pBuffer, 256, "\\");
- strcat_s (pBuffer, 256, pszSaveName);
- }
- trace ("[getSavefilePath]: '%s'\n", pBuffer);
- }
-
- void patchCode () {
- // get load address of the exe
- dwLoadOffset = (DWORD)GetModuleHandle (NULL);
- trace ("GetModuleHandle returns %08x\n", dwLoadOffset);
-
- // Unprotect image - make .text and .rdata section writeable
- BYTE * pImageBase = reinterpret_cast<BYTE *>(dwLoadOffset);
- PIMAGE_DOS_HEADER pDosHeader = reinterpret_cast<PIMAGE_DOS_HEADER> (dwLoadOffset);
- PIMAGE_NT_HEADERS pNtHeader = reinterpret_cast<PIMAGE_NT_HEADERS> (pImageBase+pDosHeader->e_lfanew);
- PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pNtHeader);
- // trace ("[EXE] NtHeader contains %d sections\n", pNtHeaders->FileHeader.NumberOfSections);
-
- for (int iSection = 0; iSection < pNtHeader->FileHeader.NumberOfSections; ++iSection, ++pSection) {
- char * pszSectionName = reinterpret_cast<char *>(pSection->Name);
- if (!strcmp (pszSectionName, ".text") || !strcmp (pszSectionName, ".rdata")) {
- DWORD dwPhysSize = (pSection->Misc.VirtualSize + 4095) & ~4095;
- trace ("[EXE] unprotecting section '%s': addr = 0x%08x, size = 0x%08x\n", pSection->Name, pSection->VirtualAddress, dwPhysSize);
-
- DWORD oldProtect;
- DWORD newProtect = (pSection->Characteristics & IMAGE_SCN_MEM_EXECUTE) ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
- if (!VirtualProtect (reinterpret_cast <VOID *>(dwLoadOffset+pSection->VirtualAddress), dwPhysSize, newProtect, &oldProtect)) {
- trace ("[EXE] Virtual protect error\n");
- ExitProcess (0);
- }
- }
- }
-
- dwLoadOffset -= 0x400000;
- // ExitProcess (0);
-
- // version check
- DWORD signature = *(DWORD *)(0x608C34+dwLoadOffset);
- switch (signature)
- {
- default:
- trace ("Unknown game version, skipping patches (signature = 0x%08x)\n", signature);
- break;
- }
- }
-
- // Plugin Loader
- void loadPlugins (char * pszMask) {
- if (!pszMask)
- return;
- char * pszType = strrchr (pszMask, '.');
- DWORD typeMask = pszType ? *(DWORD *)pszType : 0x6c6c642e; // '.dll'
-
- WIN32_FIND_DATA fd;
- char pathName[MAX_PATH]; // module name buffer
- char * p = strrchr (pszMask, '\\');
- char * namePtr = pathName;
- if (p) {
- strcpy_s (pathName, MAX_PATH, pszMask);
- pathName[p-pszMask+1] = '\0';
- namePtr = pathName + (p-pszMask+1);
- }
-
-
- HANDLE asiFile = FindFirstFile (pszMask, &fd);
- if (asiFile == INVALID_HANDLE_VALUE)
- return;
- do {
- if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
- int pos = 0;
- while (fd.cFileName[pos])
- pos++;
- DWORD type = *(DWORD *)(fd.cFileName+pos-4);
- type |= 0x20202020; // convert to lowercase
- if (type == typeMask) {
- strcpy (namePtr, fd.cFileName);
- if (!LoadLibrary (pathName))
- trace ("Error loading library %d\n", GetLastError ());
- trace ("plugin loader: loaded '%s'\n", pathName);
- }
-
- }
- } while (FindNextFile (asiFile, &fd));
- FindClose (asiFile);
- }
- //=============================================================================
- // Entry Point
- BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
- switch (ul_reason_for_call) {
- case DLL_PROCESS_ATTACH:
- #ifndef NO_TRACE
- logfile = fopen ("xlive_trace.log", "at"); // TODO: move log to the User\Documents or something
- if (logfile)
- InitializeCriticalSection (&d_lock);
- trace ("Log started (xliveless 1.0b1)\n");
- #endif
- patchCode ();
- loadPlugins ("*.asi");
- loadPlugins ("plugins\\*.asi");
- loadPlugins ("plugins\\*.dll");
- break;
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- #ifndef NO_TRACE
- if (logfile) {
- EnterCriticalSection (&d_lock);
- fflush (logfile);
- fclose (logfile);
- logfile = NULL;
- LeaveCriticalSection (&d_lock);
- DeleteCriticalSection (&d_lock);
- }
- #endif
- break;
- }
- return TRUE;
- }