void CClientRadarMarker::SetSprite ( unsigned long ulSprite ) { m_ulSprite = ulSprite; if ( m_pMarker ) { m_pMarker->SetSprite ( static_cast < eMarkerSprite > ( ulSprite ) ); } if ( ulSprite == 0 ) { if ( m_pMapMarkerImage ) { m_pMapMarkerImage->Release(); m_pMapMarkerImage = NULL; } SetMapMarkerState ( MAP_MARKER_SQUARE ); } else if ( ulSprite <= RADAR_MARKER_LIMIT ) { m_eMapMarkerState = MAP_MARKER_OTHER; if ( m_pMapMarkerImage ) { m_pMapMarkerImage->Release(); m_pMapMarkerImage = NULL; } SString strSprite ( "MTA\\cgui\\images\\radarset\\%02u.png", ulSprite ); m_pMapMarkerImage = g_pCore->GetGraphics()->LoadTexture ( CalcMTASAPath ( strSprite ) ); } }
void CModManager::DumpCoreLog ( CExceptionInformation* pExceptionInformation ) { // Write a log with the generic exception information FILE* pFile = fopen ( CalcMTASAPath ( "mta\\core.log" ), "a+" ); if ( pFile ) { // Header fprintf ( pFile, "%s", "** -- Unhandled exception -- **\n\n" ); // Write the mod name //fprintf ( pFile, "Mod name = %s\n", "TODO" ); // Write the time time_t timeTemp; time ( &timeTemp ); fprintf ( pFile, "Time = %s", ctime ( &timeTemp ) ); #define MAX_MODULE_PATH 512 char * szModulePath = new char[MAX_MODULE_PATH]; if ( pExceptionInformation->GetModule( szModulePath, MAX_MODULE_PATH ) ) { fprintf ( pFile, "Module = %s\n", szModulePath ); } delete [] szModulePath; #undef MAX_MODULE_PATH // Write the basic exception information fprintf ( pFile, "Code = 0x%08X\n", pExceptionInformation->GetCode () ); fprintf ( pFile, "Offset = 0x%08X\n\n", pExceptionInformation->GetOffset () ); //fprintf ( pFile, "Referencing offset = 0x%08X\n\n", pExceptionInformation->GetReferencingOffset () ); // Write the register info fprintf ( pFile, "EAX=%08X EBX=%08X ECX=%08X EDX=%08X ESI=%08X\n" \ "EDI=%08X EBP=%08X ESP=%08X EIP=%08X FLG=%08X\n" \ "CS=%04X DS=%04X SS=%04X ES=%04X " \ "FS=%04X GS=%04X\n\n", pExceptionInformation->GetEAX (), pExceptionInformation->GetEBX (), pExceptionInformation->GetECX (), pExceptionInformation->GetEDX (), pExceptionInformation->GetESI (), pExceptionInformation->GetEDI (), pExceptionInformation->GetEBP (), pExceptionInformation->GetESP (), pExceptionInformation->GetEIP (), pExceptionInformation->GetEFlags (), pExceptionInformation->GetCS (), pExceptionInformation->GetDS (), pExceptionInformation->GetSS (), pExceptionInformation->GetES (), pExceptionInformation->GetFS (), pExceptionInformation->GetGS () ); // End of unhandled exception fprintf ( pFile, "%s", "** -- End of unhandled exception -- **\n\n\n" ); // Close the file fclose ( pFile ); } }
void CCore::CreateXML ( ) { // Create function pointer type and variable. typedef CXML* (*pfnXMLInitializer) ( ); pfnXMLInitializer pfnXMLInit; CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Load approrpiate compilation-specific library. #ifdef MTA_DEBUG m_XMLModule.LoadModule ( "xmll_d.dll" ); #else m_XMLModule.LoadModule ( "xmll.dll" ); #endif // Get client initializer function from DLL's routine. pfnXMLInit = static_cast< pfnXMLInitializer > ( m_XMLModule.GetFunctionPointer ( "InitXMLInterface" ) ); // If we have a valid initializer, call it. if ( pfnXMLInit != NULL ) { WriteDebugEvent ( "XML loaded." ); m_pXML = pfnXMLInit ( ); } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "XML module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } SetCurrentDirectory ( szCurDir ); // Load config XML file m_pConfigFile = m_pXML->CreateXML ( CalcMTASAPath ( MTA_CONFIG_PATH ) ); if ( !m_pConfigFile ) { assert ( false ); return; } m_pConfigFile->Parse (); // Load the keybinds (loads defaults if the subnode doesn't exist) GetKeyBinds ()->LoadFromXML ( GetConfig ()->FindSubNode ( CONFIG_NODE_KEYBINDS ) ); // Load XML-dependant subsystems m_ClientVariables.Load ( ); }
void CCore::CreateGame ( ) { // Create function pointer type and variable. typedef CGame* (*pfnGameInitializer) ( ); pfnGameInitializer pfnGameInit; // Load approrpiate compilation-specific library. #ifdef MTA_DEBUG m_GameModule.LoadModule ( CalcMTASAPath ( "mta/game_sa_d.dll" ) ); # else m_GameModule.LoadModule ( CalcMTASAPath ( "mta/game_sa.dll" ) ); #endif // Get client initializer function from DLL's routine. pfnGameInit = static_cast< pfnGameInitializer > ( m_GameModule.GetFunctionPointer ( "GetGameInterface" ) ); // If we have a valid initializer, call it. if ( pfnGameInit != NULL ) { WriteDebugEvent ( "Game loaded." ); m_pGame = pfnGameInit ( ); if ( m_pGame->GetGameVersion () >= VERSION_11 ) { MessageBox ( 0, "Only GTA:SA version 1.0 is supported!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "Game module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } }
void CCore::CreateMultiplayer ( ) { // Check to see if our game has been created. if ( m_pGame == NULL ) { // Inform user that loading failed. return; } // Create function pointer type and variable. typedef CMultiplayer* (*pfnMultiplayerInitializer) ( CGame * ); pfnMultiplayerInitializer pfnMultiplayerInit; // Load appropriate compilation-specific library. #ifdef MTA_DEBUG m_MultiplayerModule.LoadModule ( CalcMTASAPath ( "mta/multiplayer_sa_d.dll" ) ); # else m_MultiplayerModule.LoadModule ( CalcMTASAPath ( "mta/multiplayer_sa.dll" ) ); #endif // Get client initializer function from DLL's routine. pfnMultiplayerInit = static_cast< pfnMultiplayerInitializer > ( m_MultiplayerModule.GetFunctionPointer ( "InitMultiplayerInterface" ) ); // If we have a valid initializer, call it. if ( pfnMultiplayerInit != NULL ) { WriteDebugEvent ( "Multiplayer loaded." ); m_pMultiplayer = pfnMultiplayerInit ( m_pGame ); } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "Multiplayer module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } }
CModManager::CModManager ( void ) { // Init m_hClientDLL = NULL; m_pClientBase = NULL; m_bUnloadRequested = false; // Default mod name defaults to "default" m_strDefaultModName = "default"; // Load the modlist from the folders in "mta/mods" InitializeModList ( CalcMTASAPath( "mods\\" ) ); // Set up our exception handler #ifndef MTA_DEBUG SetCrashHandlerFilter ( HandleExceptionGlobal ); #endif }
// // Precreate all the textures for the radar map markers // void CRadarMap::CreateMarkerTextures ( void ) { assert ( m_MarkerTextureList.empty () ); SString strRadarSetDirectory = CalcMTASAPath ( "MTA\\cgui\\images\\radarset\\" ); // Load the 3 shapes const char* shapeFileNames[] = { "square.png", "up.png", "down.png" }; for ( uint i = 0 ; i < NUMELMS( shapeFileNames ) ; i++ ) { CTextureItem* pTextureItem = g_pCore->GetGraphics()->GetRenderItemManager ()->CreateTexture ( PathJoin ( strRadarSetDirectory, shapeFileNames[i] ) ); m_MarkerTextureList.push_back ( pTextureItem ); } assert ( m_MarkerTextureList.size () == MARKER_FIRST_SPRITE_INDEX ); // Load the icons for ( uint i = 0 ; i < RADAR_MARKER_LIMIT ; i++ ) { CTextureItem* pTextureItem = g_pCore->GetGraphics()->GetRenderItemManager ()->CreateTexture ( PathJoin ( strRadarSetDirectory, SString ( "%02u.png", i + 1 ) ) ); m_MarkerTextureList.push_back ( pTextureItem ); } assert ( m_MarkerTextureList.size () == MARKER_LAST_SPRITE_INDEX + 1 ); }
void CModManager::DumpMiniDump ( _EXCEPTION_POINTERS* pException ) { // Try to load the DLL in our directory HMODULE hDll = NULL; char szDbgHelpPath [MAX_PATH]; if ( GetModuleFileName ( NULL, szDbgHelpPath, MAX_PATH ) ) { char* pSlash = _tcsrchr ( szDbgHelpPath, '\\' ); if ( pSlash ) { _tcscpy ( pSlash + 1, "DBGHELP.DLL" ); hDll = LoadLibrary ( szDbgHelpPath ); } } // If we couldn't load the one in our dir, load any version available if ( !hDll ) { hDll = LoadLibrary( "DBGHELP.DLL" ); } // We could load a dll? if ( hDll ) { // Grab the MiniDumpWriteDump proc address MINIDUMPWRITEDUMP pDump = reinterpret_cast < MINIDUMPWRITEDUMP > ( GetProcAddress( hDll, "MiniDumpWriteDump" ) ); if ( pDump ) { // Create the file HANDLE hFile = CreateFile ( CalcMTASAPath ( "mta\\core.dmp" ), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile != INVALID_HANDLE_VALUE ) { // Create an exception information struct _MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = GetCurrentThreadId (); ExInfo.ExceptionPointers = pException; ExInfo.ClientPointers = FALSE; // Write the dump pDump ( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL ); // Close the dumpfile CloseHandle ( hFile ); // Grab the current time // Ask windows for the system time. SYSTEMTIME SystemTime; GetLocalTime ( &SystemTime ); // Create the dump directory CreateDirectory ( CalcMTASAPath ( "mta\\dumps" ), 0 ); // Add a log entry. SString strFilename ( "mta\\dumps\\client_%s_%02d%02d%04d_%02d%02d.dmp", MTA_DM_BUILDTYPE, SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, SystemTime.wHour, SystemTime.wMinute ); // Copy the file CopyFile ( CalcMTASAPath ( "mta\\core.dmp" ), CalcMTASAPath ( strFilename ), false ); } } // Free the DLL again FreeLibrary ( hDll ); } }
void CModManager::RefreshMods ( void ) { // Clear the list, and load it again Clear (); InitializeModList ( CalcMTASAPath( "mods\\" ) ); }
CClientBase* CModManager::Load ( const char* szName, const char* szArguments ) { char szOriginalDirectory[255] = {'\0'}; SString strMTADirectory; // Make sure we haven't already loaded a mod Unload (); // Get the entry for the given name std::map < std::string, std::string >::iterator itMod = m_ModDLLFiles.find ( szName ); if ( itMod == m_ModDLLFiles.end () ) { CCore::GetSingleton ().GetConsole ()->Printf ( "Unable to load %s (unknown mod)", szName ); return NULL; } // Change the search path and current directory char szOrigPath [ 1024 ]; DWORD dwGetPathResult = GetEnvironmentVariable ( "Path", szOrigPath, sizeof(szOrigPath) ); if ( dwGetPathResult == 0 || dwGetPathResult >= sizeof(szOrigPath) ) { CCore::GetSingleton ().GetConsole ()->Print ( "Error getting Path environment variable" ); return NULL; } SString strPath ( "%s\\%s;%s", CalcMTASAPath("mods").c_str (), szName, szOrigPath ); SetEnvironmentVariable ( "Path", strPath ); GetCurrentDirectory ( sizeof(szOriginalDirectory), szOriginalDirectory ); strMTADirectory = CalcMTASAPath ( "mta" ); SetCurrentDirectory ( strMTADirectory ); // Load the library m_hClientDLL = LoadLibrary ( itMod->second.c_str () ); if ( !m_hClientDLL ) { DWORD dwError = GetLastError (); char szError [ 2048 ]; char* p; FormatMessage ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, dwError, LANG_NEUTRAL, szError, sizeof ( szError ), NULL ); // Remove newlines from the error message p = szError + strlen ( szError ) - 1; while ( p >= szError && (*p == '\r' || *p == '\n' ) ) { *p = '\0'; --p; } CCore::GetSingleton ().GetConsole ()->Printf ( "Unable to load %s's DLL (reason: %s)", szName, szError ); // Return the search path and current directory to its normal SetEnvironmentVariable ( "Path", szOrigPath ); SetCurrentDirectory ( szOriginalDirectory ); return NULL; } // Get the address of InitClient typedef CClientBase* (__cdecl pfnClientInitializer) ( void ); /* FIXME: Should probably not be here */ pfnClientInitializer* pClientInitializer = reinterpret_cast < pfnClientInitializer* > ( GetProcAddress ( m_hClientDLL, "InitClient" ) ); if ( pClientInitializer == NULL ) { CCore::GetSingleton ().GetConsole ()->Printf ( "Unable to load %s's DLL (unknown mod)", szName, GetLastError () ); FreeLibrary ( m_hClientDLL ); // Return the current directory to its normal SetCurrentDirectory ( szOriginalDirectory ); return NULL; } // Return the search path and current directory to its normal SetEnvironmentVariable ( "Path", szOrigPath ); SetCurrentDirectory ( szOriginalDirectory ); // Call InitClient and store the Client interface in m_pClientBase m_pClientBase = pClientInitializer (); // Call the client base initializer if ( !m_pClientBase || m_pClientBase->ClientInitialize ( szArguments, CCore::GetSingletonPtr () ) != 0 ) { CCore::GetSingleton ().GetConsole ()->Printf ( "Unable to load %s's DLL (unable to init, bad version?)", szName, GetLastError () ); FreeLibrary ( m_hClientDLL ); return NULL; } // HACK: make the console input active if its visible if ( CLocalGUI::GetSingleton ().IsConsoleVisible () ) CLocalGUI::GetSingleton ().GetConsole ()->ActivateInput (); // Return the interface return m_pClientBase; }
CRadarMap::CRadarMap ( CClientManager* pManager ) { // Setup our managers m_pManager = pManager; m_pRadarMarkerManager = pManager->GetRadarMarkerManager (); m_pRadarAreaManager = m_pManager->GetRadarAreaManager (); // Set the radar bools m_bIsRadarEnabled = false; m_bForcedState = false; m_bIsAttachedToLocal = false; m_bHideHelpText = false; // Set the movement bools m_bIsMovingNorth = false; m_bIsMovingSouth = false; m_bIsMovingEast = false; m_bIsMovingWest = false; m_bTextVisible = false; // Set the update time to the current time m_ulUpdateTime = GetTickCount32 (); // Get the window sizes and set the map variables to default zoom/movement m_uiHeight = g_pCore->GetGraphics ()->GetViewportHeight (); m_uiWidth = g_pCore->GetGraphics ()->GetViewportWidth (); m_fZoom = 1; m_iHorizontalMovement = 0; m_iVerticalMovement = 0; SetupMapVariables (); // Create the radar and local player blip images m_pRadarImage = g_pCore->GetGraphics()->GetRenderItemManager ()->CreateTexture ( CalcMTASAPath("MTA\\cgui\\images\\radar.jpg"), true, 1024, 1024, RFORMAT_DXT1 ); m_pLocalPlayerBlip = g_pCore->GetGraphics()->GetRenderItemManager ()->CreateTexture ( CalcMTASAPath("MTA\\cgui\\images\\radarset\\02.png") ); // Create the marker textures CreateMarkerTextures (); // Create the text displays for the help text struct { SColor color; float fPosY; float fScale; SString strMessage; } messageList [] = { { SColorRGBA ( 255, 255, 255, 200 ), 0.92f, 1.5f, "Current Mode: Kill all humans" }, { SColorRGBA ( 255, 255, 255, 255 ), 0.95f, 1.0f, SString ( "Press %s to change mode.", *GetBoundKeyName ( "radar_attach" ) ) }, { SColorRGBA ( 255, 255, 255, 255 ), 0.05f, 1.0f, SString ( "Press %s/%s to zoom in/out.", *GetBoundKeyName ( "radar_zoom_in" ), *GetBoundKeyName ( "radar_zoom_out" ) ) }, { SColorRGBA ( 255, 255, 255, 255 ), 0.08f, 1.0f, SString ( "Press %s, %s, %s, %s to navigate the map.", *GetBoundKeyName ( "radar_move_north" ), *GetBoundKeyName ( "radar_move_east" ), *GetBoundKeyName ( "radar_move_south" ), *GetBoundKeyName ( "radar_move_west" ) ) }, { SColorRGBA ( 255, 255, 255, 255 ), 0.11f, 1.0f, SString ( "Press %s/%s to change opacity.", *GetBoundKeyName ( "radar_opacity_down" ), *GetBoundKeyName ( "radar_opacity_up" ) ) }, { SColorRGBA ( 255, 255, 255, 255 ), 0.14f, 1.0f, SString ( "Press %s to hide the map.", *GetBoundKeyName ( "radar" ) ) }, { SColorRGBA ( 255, 255, 255, 255 ), 0.17f, 1.0f, SString ( "Press %s to hide this help text.", *GetBoundKeyName ( "radar_help" ) ) }, }; for ( uint i = 0 ; i < NUMELMS( messageList ) ; i++ ) { CClientTextDisplay* pTextDisplay = new CClientTextDisplay ( m_pManager->GetDisplayManager () ); pTextDisplay->SetCaption ( messageList[i].strMessage ); pTextDisplay->SetColor( messageList[i].color ); pTextDisplay->SetPosition ( CVector ( 0.50f, messageList[i].fPosY, 0 ) ); pTextDisplay->SetFormat ( DT_CENTER | DT_VCENTER ); pTextDisplay->SetScale ( messageList[i].fScale ); pTextDisplay->SetVisible ( false ); m_HelpTextList.push_back ( pTextDisplay ); } // Default to attached to player SetAttachedToLocalPlayer ( true ); }
void CCommunityRegistration::DoPulse ( void ) { if ( m_ulStartTime > 0 ) { CHTTPBuffer buffer; if ( m_HTTP.GetData ( buffer ) ) { char* szBuffer = buffer.GetData (); unsigned int uiBufferLength = buffer.GetSize (); // Succeed, deal with the response m_ulStartTime = 0; // ID eRegistrationResult Result = (eRegistrationResult)(szBuffer[0] - 48); if ( Result == REGISTRATION_ERROR_REQUEST ) { CGUI *pManager = g_pCore->GetGUI (); // Sure we have it all right? if ( uiBufferLength > 32 ) { // Get the hash m_strCommunityHash = std::string ( &szBuffer[1], 32 ); // TODO: Load it without a temp file // Create a temp file for the png FILE * fp = fopen ( CalcMTASAPath( REGISTRATION_TEMP_FILE ), "wb" ); if ( fp ) { fwrite ( &szBuffer[33], uiBufferLength, 1, fp ); fclose ( fp ); m_pImageCode->LoadFromFile ( "temp.png" ); m_pImageCode->SetSize ( CVector2D ( 65.0f, 20.0f ), false ); m_pWindow->SetVisible ( true ); m_pWindow->BringToFront (); // Delete the temp file remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) ); return; } } g_pCore->ShowMessageBox ( "Error", "Services currently unavaliable", MB_BUTTON_OK | MB_ICON_ERROR ); } else if ( Result == REGISTRATION_ERROR_SUCCESS ) { g_pCore->ShowMessageBox ( "Success", "Successfully registered!", MB_BUTTON_OK | MB_ICON_INFO ); m_pWindow->SetVisible ( false ); SetFrozen ( false ); m_strCommunityHash.clear (); m_pImageCode->Clear (); } else if ( Result == REGISTRATION_ERROR_ERROR ) { if ( strlen ( &szBuffer[1] ) > 0 ) g_pCore->ShowMessageBox ( "Error", &szBuffer[1], MB_BUTTON_OK | MB_ICON_ERROR ); else g_pCore->ShowMessageBox ( "Error", "Unexpected error", MB_BUTTON_OK | MB_ICON_ERROR ); SetFrozen ( false ); } else { g_pCore->ShowMessageBox ( "Error", "Services currently unavaliable", MB_BUTTON_OK | MB_ICON_ERROR ); SetFrozen ( false ); } } else if ( ( CClientTime::GetTime () - m_ulStartTime ) > REGISTRATION_DELAY ) { g_pCore->ShowMessageBox ( "Error", "Services currently unavaliable", MB_BUTTON_OK | MB_ICON_ERROR ); SetFrozen ( false ); // Timed out m_ulStartTime = 0; } } }