int CLuaFunctionDefs::TriggerServerEvent ( lua_State* luaVM ) { // bool triggerServerEvent ( string event, element theElement, [arguments...] ) SString strName; CClientEntity* pCallWithEntity; CLuaArguments Arguments; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pCallWithEntity ); argStream.ReadLuaArguments ( Arguments ); if ( !argStream.HasErrors () ) { // Trigger it if ( CStaticFunctionDefinitions::TriggerServerEvent ( strName, *pCallWithEntity, Arguments ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "triggerServerEvent", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::AddEvent ( lua_State* luaVM ) { // bool addEvent ( string eventName [, bool allowRemoteTrigger = false ] ) SString strName; bool bAllowRemoteTrigger; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadBool ( bAllowRemoteTrigger, false ); if ( !argStream.HasErrors () ) { // Grab our virtual machine CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Do it if ( CStaticFunctionDefinitions::AddEvent ( *pLuaMain, strName, bAllowRemoteTrigger ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "addEvent", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::TriggerEvent ( lua_State* luaVM ) { // bool triggerEvent ( string eventName, element baseElement, [ var argument1, ... ] ) SString strName; CClientEntity* pEntity; CLuaArguments Arguments; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pEntity ); argStream.ReadLuaArguments ( Arguments ); if ( !argStream.HasErrors () ) { // Trigger it bool bWasCancelled; if ( CStaticFunctionDefinitions::TriggerEvent ( strName, *pEntity, Arguments, bWasCancelled ) ) { lua_pushboolean ( luaVM, !bWasCancelled ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "triggerEvent", *argStream.GetErrorMessage () ) ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaPointLightDefs::SetLightColor ( lua_State* luaVM ) { // bool setLightColor ( light theLight, float r, float g, float b ) CClientPointLights* pLight; float fRed; float fGreen; float fBlue; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); argStream.ReadNumber ( fRed ); argStream.ReadNumber ( fGreen ); argStream.ReadNumber ( fBlue ); if ( !argStream.HasErrors () ) { SColorRGBA color ( fRed, fGreen, fBlue, 0 ); if ( CStaticFunctionDefinitions::SetLightColor ( pLight, color ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPointLightDefs::GetLightDirection ( lua_State* luaVM ) { // float, float, float getLightDirection ( light theLight ) CClientPointLights* pLight; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); if ( !argStream.HasErrors () ) { CVector vecDirection; if ( CStaticFunctionDefinitions::GetLightDirection ( pLight, vecDirection ) ) { lua_pushnumber ( luaVM, static_cast < lua_Number > ( vecDirection.fX ) ); lua_pushnumber ( luaVM, static_cast < lua_Number > ( vecDirection.fY ) ); lua_pushnumber ( luaVM, static_cast < lua_Number > ( vecDirection.fZ ) ); return 3; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPointLightDefs::GetLightColor ( lua_State* luaVM ) { // int, int, int getLightColor ( light theLight ) CClientPointLights* pLight; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pLight ); if ( !argStream.HasErrors () ) { SColor color; if ( CStaticFunctionDefinitions::GetLightColor ( pLight, color ) ) { lua_pushnumber ( luaVM, static_cast < lua_Number > ( color.R ) ); lua_pushnumber ( luaVM, static_cast < lua_Number > ( color.G ) ); lua_pushnumber ( luaVM, static_cast < lua_Number > ( color.B ) ); return 3; } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), *argStream.GetErrorMessage () ) ); lua_pushboolean ( luaVM, false ); return 1; }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckMetaSourceForIssues // // // /////////////////////////////////////////////////////////////// void CResourceChecker::CheckMetaSourceForIssues ( CXMLNode* pRootNode, const string& strFileName, const string& strResourceName, ECheckerModeType checkerMode, bool* pbOutHasChanged ) { // Check min_mta_version is correct if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml || m_strReqServerVersion > m_strMinServerReqFromMetaXml ) { // It's not right. What to do? if ( checkerMode == ECheckerMode::WARNINGS ) { SString strTemp = "<min_mta_version> section in the meta.xml is incorrect or missing (expected at least "; if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml ) strTemp += SString ( "client %s because of '%s')", *m_strReqClientVersion, *m_strReqClientReason ); else if ( m_strReqServerVersion > m_strMinServerReqFromMetaXml ) strTemp += SString ( "server %s because of '%s')", *m_strReqServerVersion, *m_strReqServerReason ); CLogger::LogPrint ( SString ( "WARNING: %s %s\n", strResourceName.c_str (), *strTemp ) ); } else if ( checkerMode == ECheckerMode::UPGRADE ) { // Create min_mta_version node if required CXMLNode* pNodeMinMtaVersion = pRootNode->FindSubNode("min_mta_version", 0); if ( !pNodeMinMtaVersion ) pNodeMinMtaVersion = pRootNode->CreateSubNode ( "min_mta_version" ); CXMLAttributes& attributes = pNodeMinMtaVersion->GetAttributes (); attributes.Delete ( "server" ); attributes.Delete ( "client" ); attributes.Delete ( "both" ); if ( !m_strReqServerVersion.empty () ) { CXMLAttribute* pAttr = attributes.Create ( "server" ); pAttr->SetValue ( m_strReqServerVersion ); } if ( !m_strReqClientVersion.empty () ) { CXMLAttribute* pAttr = attributes.Create ( "client" ); pAttr->SetValue ( m_strReqClientVersion ); } if ( pbOutHasChanged ) *pbOutHasChanged = true; } } }
std::string ASE::QueryLight ( void ) { std::stringstream reply; int iJoinedPlayers = m_pPlayerManager->CountJoined (); int iMaxPlayers = m_pMainConfig->GetMaxPlayers (); SString strPlayerCount = SString ( "%d/%d", iJoinedPlayers, iMaxPlayers ); reply << "EYE2"; // game reply << ( unsigned char ) 4; reply << "mta"; // port reply << ( unsigned char ) ( m_strPort.length() + 1 ); reply << m_strPort; // server name reply << ( unsigned char ) ( m_pMainConfig->GetServerName ().length() + 1 ); reply << m_pMainConfig->GetServerName (); // game type reply << ( unsigned char ) ( m_strGameType.length() + 1 ); reply << m_strGameType; // map name with backwardly compatible large player count reply << ( unsigned char ) ( m_strMapName.length() + 1 + strPlayerCount.length () + 1 ); reply << m_strMapName; reply << ( unsigned char ) 0; reply << strPlayerCount; // version std::string temp = MTA_DM_ASE_VERSION; reply << ( unsigned char ) ( temp.length() + 1 ); reply << temp; // passworded reply << ( unsigned char ) ( ( m_pMainConfig->HasPassword () ) ? 1 : 0 ); // serial verification? reply << ( unsigned char ) ( ( m_pMainConfig->GetSerialVerificationEnabled() ) ? 1 : 0 ); // players count reply << ( unsigned char ) Min ( iJoinedPlayers, 255 ); // players max reply << ( unsigned char ) Min ( iMaxPlayers, 255 ); // players CPlayer* pPlayer = NULL; list < CPlayer* > ::const_iterator pIter = m_pPlayerManager->IterBegin (); for ( ; pIter != m_pPlayerManager->IterEnd (); pIter++ ) { pPlayer = *pIter; if ( pPlayer->IsJoined () ) { // nick std::string strPlayerName = RemoveColorCode ( pPlayer->GetNick () ); if ( strPlayerName.length () == 0 ) strPlayerName = pPlayer->GetNick (); reply << ( unsigned char ) ( strPlayerName.length () + 1 ); reply << strPlayerName.c_str (); } } return reply.str(); }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckLuaDeobfuscateRequirements // // Updates version requirements and returns true if obfuscated // /////////////////////////////////////////////////////////////// bool CResourceChecker::CheckLuaDeobfuscateRequirements ( const string& strFileContents, const string& strFileName, const string& strResourceName, bool bClientScript ) { // Get embedded version requirements SScriptInfo scriptInfo; if ( !g_pRealNetServer->GetScriptInfo( strFileContents.c_str(), strFileContents.length(), &scriptInfo ) ) { if ( bClientScript && IsLuaCompiledScript( strFileContents.c_str(), strFileContents.length() ) ) { // Compiled client script with no version info #if MTA_DM_VERSION < 0x135 SString strMessage( "%s is invalid and will not work in future versions. Please re-compile at http://luac.mtasa.com/", strFileName.c_str() ); CLogger::LogPrint ( SString ( "WARNING: %s %s\n", strResourceName.c_str (), *strMessage ) ); #else SString strMessage( "%s is invalid. Please re-compile at http://luac.mtasa.com/", strFileName.c_str() ); CLogger::LogPrint ( SString ( "ERROR: %s %s\n", strResourceName.c_str (), *strMessage ) ); #endif } return false; } SString strMinServerHostVer = scriptInfo.szMinServerHostVer; SString strMinServerRunVer = scriptInfo.szMinServerRunVer; SString strMinClientRunVer = scriptInfo.szMinClientRunVer; // Check server host requirements if ( strMinServerHostVer > m_strReqServerVersion ) { m_strReqServerVersion = strMinServerHostVer; m_strReqServerReason = strFileName; } // Check run requirements if ( bClientScript && strMinClientRunVer > m_strReqClientVersion ) { m_strReqClientVersion = strMinClientRunVer; m_strReqClientReason = strFileName; } else if ( !bClientScript && strMinServerRunVer > m_strReqServerVersion ) { m_strReqServerVersion = strMinServerRunVer; m_strReqServerReason = strFileName; } return IsLuaObfuscatedScript( strFileContents.c_str(), strFileContents.length() ); }
/////////////////////////////////////////////////////////////// // // CCrashDumpWriter::UpdateCounters // // Static function. Called every so often, you know // /////////////////////////////////////////////////////////////// void CCrashDumpWriter::UpdateCounters( void ) { if ( ms_uiInvalidParameterCount > ms_uiInvalidParameterCountLogged && ms_uiInvalidParameterCountLogged < 10 ) { AddReportLog( 9206, SString( "InvalidParameterCount changed from %d to %d", ms_uiInvalidParameterCountLogged, ms_uiInvalidParameterCount ) ); ms_uiInvalidParameterCountLogged = ms_uiInvalidParameterCount; } }
SString SPackage::Data::LoadString(const SString& key, const SString& locale) { SString result; char* buf = NULL; if (locale == SString::EmptyString()) { // FIX ME! need to get the system locale //berr << "FIX ME! SPackage::LoadString() defaulting to enUS" << endl; SString where("enUS"); buf = get_buffer_for(where); } else { buf = get_buffer_for(locale); } if (buf != NULL) { const uint32_t COUNT = *((uint32_t*)buf); char* it = buf + sizeof(uint32_t); uint32_t* indices = (uint32_t*)it; char* keys = it + (sizeof(uint32_t) * COUNT * 2); bool found = false; int32_t low = 0; int32_t high = COUNT - 1; int32_t mid; while (low <= high) { mid = (low + high) / 2; char* tmp = buf + indices[mid]; int cmp = strcmp(tmp, key.String()); if (cmp > 0) { high = mid - 1; } else if (cmp < 0) { low = mid + 1; } else { found = true; break; } } if (found) { result = SString(buf + indices[mid + COUNT]); } } return result; }
bool CWebCore::UpdateListsFromMaster () { if ( !m_pXmlConfig ) return false; CXMLNode* pRootNode = m_pXmlConfig->GetRootNode (); if ( !pRootNode || !MakeSureXMLNodesExist () ) return false; // Fetch white- and blacklist revision from config CXMLNode* pWhiteRevNode = pRootNode->FindSubNode ( "whitelistrev" ); if ( !pWhiteRevNode || !pWhiteRevNode->GetTagContent ( m_iWhitelistRevision ) ) { m_iWhitelistRevision = 0; } CXMLNode* pBlackRevNode = pRootNode->FindSubNode ( "blacklistrev" ); if ( !pBlackRevNode || !pBlackRevNode->GetTagContent ( m_iBlacklistRevision ) ) { m_iBlacklistRevision = 0; } // Get last update timestamp and compare with current time CXMLNode* pLastUpdateNode = pRootNode->FindSubNode ( "lastupdate" ); if ( pLastUpdateNode ) { SString lastUpdateTime = pLastUpdateNode->GetTagContent (); time_t currentTime; time ( ¤tTime ); if ( lastUpdateTime < SString ( "%d", (long long)currentTime - BROWSER_LIST_UPDATE_INTERVAL ) ) { #ifdef MTA_DEBUG OutputDebugLine ( "Updating white- and blacklist..." ); #endif g_pCore->GetNetwork ()->GetHTTPDownloadManager ( EDownloadModeType::WEBBROWSER_LISTS )->QueueFile ( SString("%s?type=getrev", BROWSER_UPDATE_URL), NULL, 0, NULL, 0, false, this, &CWebCore::StaticFetchRevisionProgress, false, 3 ); pLastUpdateNode->SetTagContent ( SString ( "%d", (long long)currentTime ) ); m_pXmlConfig->Write (); } } return true; }
void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue ) { SString strText = ComposeErrorMessage( szPrePend, luaDebugInfo, szMessage ); // Create a different message if type is "INFO" if ( uiMinimumDebugLevel > 2 ) strText = SString ( "%s%s", szPrePend, szMessage ); if ( !m_bTriggeringOnClientDebugMessage ) { m_bTriggeringOnClientDebugMessage = true; // Prepare onClientDebugMessage CLuaArguments Arguments; Arguments.PushString ( szMessage ); Arguments.PushNumber ( uiMinimumDebugLevel ); // Push the file name (if any) if ( !luaDebugInfo.strFile.empty() ) Arguments.PushString ( luaDebugInfo.strFile ); else Arguments.PushNil ( ); // Push the line (if any) if ( luaDebugInfo.iLine != INVALID_LINE_NUMBER ) Arguments.PushNumber ( luaDebugInfo.iLine ); else Arguments.PushNil ( ); // Call onClientDebugMessage g_pClientGame->GetRootEntity ( )->CallEvent ( "onClientDebugMessage", Arguments, false ); m_bTriggeringOnClientDebugMessage = false; } // Log it to the file if enough level if ( m_uiLogFileLevel >= uiMinimumDebugLevel ) { PrintLog ( strText ); } switch ( uiMinimumDebugLevel ) { case 1: ucRed = 255, ucGreen = 0, ucBlue = 0; break; case 2: ucRed = 255, ucGreen = 128, ucBlue = 0; break; case 3: ucRed = 0, ucGreen = 255, ucBlue = 0; break; } #ifdef MTA_DEBUG if ( !g_pCore->IsDebugVisible () ) return; #endif g_pCore->DebugEchoColor ( strText, ucRed, ucGreen, ucBlue ); }
////////////////////////////////////////////////////////// // // CheckOnRestartCommand // // Changes current directory if required // ////////////////////////////////////////////////////////// SString CheckOnRestartCommand ( void ) { const SString strMTASAPath = GetMTASAPath (); SetCurrentDirectory ( strMTASAPath ); SetDllDirectory( strMTASAPath ); SString strOperation, strFile, strParameters, strDirectory, strShowCmd; if ( GetOnRestartCommand ( strOperation, strFile, strParameters, strDirectory, strShowCmd ) ) { if ( strOperation == "files" || strOperation == "silent" ) { // // Update // // Make temp path name and go there SString strArchivePath, strArchiveName; strFile.Split ( "\\", &strArchivePath, &strArchiveName, -1 ); SString strTempPath = MakeUniquePath ( strArchivePath + "\\_" + strArchiveName + "_tmp_" ); if ( !MkDir ( strTempPath ) ) return "FileError1"; if ( !SetCurrentDirectory ( strTempPath ) ) return "FileError2"; // Start progress bar if ( !strParameters.Contains( "hideprogress" ) ) StartPseudoProgress( g_hInstance, "MTA: San Andreas", _("Extracting files...") ); // Try to extract the files if ( !ExtractFiles ( strFile ) ) { // If extract failed and update file is an exe, try to run it if ( ExtractExtension ( strFile ).CompareI ( "exe" ) ) ShellExecuteBlocking ( "open", strFile, "-s" ); } // Stop progress bar StopPseudoProgress(); // If a new "Multi Theft Auto.exe" exists, let that complete the install if ( FileExists ( MTA_EXE_NAME_RELEASE ) ) return "install from far " + strOperation + " " + strParameters; // Otherwise use the current exe to install return "install from near " + strOperation + " " + strParameters; } else { AddReportLog ( 5052, SString ( "CheckOnRestartCommand: Unknown restart command %s", strOperation.c_str () ) ); } } return "no update"; }
void CPlayer::MovePlayerToNearList ( CPlayer* pOther ) { OutputDebugLine ( SString ( "[Sync] ++ %s: Move %s to nearlist", GetNick (), pOther->GetNick () ) ); dassert ( !MapContains ( m_NearPlayerList, pOther ) && MapContains ( m_FarPlayerList, pOther ) ); SViewerInfo* pInfo = MapFind ( m_FarPlayerList, pOther ); MapSet ( m_NearPlayerList, pOther, *pInfo ); MapRemove ( m_FarPlayerList, pOther ); }
//////////////////////////////////////////////// // // CreateDeviceSecondCallCheck // // Check for, and handle subsequent calls to create device // Know to occur with RTSSHooks.dll (EVGA Precision X on screen display) // //////////////////////////////////////////////// bool CreateDeviceSecondCallCheck( HRESULT& hOutResult, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface ) { static uint uiCreateCount = 0; if ( ++uiCreateCount == 1 ) return false; WriteDebugEvent ( SString ( " Passing through call #%d to CreateDevice", uiCreateCount ) ); hOutResult = pDirect3D->CreateDevice ( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface ); return true; }
// Proxy constructor and destructor. CProxyDirect3DDevice9::CProxyDirect3DDevice9(IDirect3DDevice9* pDevice) { WriteDebugEvent(SString("CProxyDirect3DDevice9::CProxyDirect3DDevice9 %08x", this)); // Set our wrapped device. m_pDevice = pDevice; // Get CDirect3DData pointer. m_pData = CDirect3DData::GetSingletonPtr(); g_pProxyDevice = this; g_pDeviceState = &DeviceState; pDevice->GetDeviceCaps(&g_pDeviceState->DeviceCaps); // // Get video card installed memory // D3DDEVICE_CREATION_PARAMETERS creationParameters; m_pDevice->GetCreationParameters(&creationParameters); int iAdapter = creationParameters.AdapterOrdinal; IDirect3D9* pD3D9 = CProxyDirect3D9::StaticGetDirect3D(); if (!pD3D9) m_pDevice->GetDirect3D(&pD3D9); D3DADAPTER_IDENTIFIER9 adaptIdent; ZeroMemory(&adaptIdent, sizeof(D3DADAPTER_IDENTIFIER9)); pD3D9->GetAdapterIdentifier(iAdapter, 0, &adaptIdent); int iVideoCardMemoryKBTotal = GetWMIVideoAdapterMemorySize(adaptIdent.DeviceName) / 1024; // Just incase, fallback to using texture memory stats if (iVideoCardMemoryKBTotal < 16) iVideoCardMemoryKBTotal = m_pDevice->GetAvailableTextureMem() / 1024; g_pDeviceState->AdapterState.InstalledMemoryKB = iVideoCardMemoryKBTotal; // // Get video card name // g_pDeviceState->AdapterState.Name = adaptIdent.Description; // // Get max anisotropic setting // g_pDeviceState->AdapterState.MaxAnisotropicSetting = 0; // Make sure device can do anisotropic minification and trilinear filtering if ((g_pDeviceState->DeviceCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) && (g_pDeviceState->DeviceCaps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)) { int iLevel = std::max<int>(1, g_pDeviceState->DeviceCaps.MaxAnisotropy); // Convert level 1/2/4/8/16 into setting 0/1/2/3/4 while (iLevel >>= 1) g_pDeviceState->AdapterState.MaxAnisotropicSetting++; }
/////////////////////////////////////////////////////////////// // // CGameEntityXRefManagerImpl::OnGameEntityDestruct // // Called when GTA is destroying a game entity // /////////////////////////////////////////////////////////////// void CGameEntityXRefManagerImpl::OnGameEntityDestruct ( CEntitySAInterface* pEntitySAInterface ) { if ( MapContains ( m_InterfaceToClientMap, pEntitySAInterface ) ) { BYTE* pInterface = (BYTE*)pEntitySAInterface; DWORD InterfaceVtbl = *(DWORD*)pInterface; ushort InterfaceModelId = *(ushort*)(pInterface + 34); CClientEntity* pClientEntity = MapFindRef ( m_InterfaceToClientMap, pEntitySAInterface ); bool bClientEntityValid = MapContains ( m_ValidClientEntityMap, pClientEntity ); SString strClientEntityInfo; if ( bClientEntityValid ) { CEntity* pGameEntity = NULL; if ( CClientPed* pPed = DynamicCast < CClientPed > ( pClientEntity ) ) pGameEntity = pPed->GetGameEntity (); if ( CClientVehicle* pVehicle = DynamicCast < CClientVehicle > ( pClientEntity ) ) pGameEntity = pVehicle->GetGameEntity (); if ( CClientObject* pObject = DynamicCast < CClientObject > ( pClientEntity ) ) pGameEntity = pObject->GetGameEntity (); if ( CClientProjectile* pProjectile = DynamicCast < CClientProjectile > ( pClientEntity ) ) pGameEntity = pProjectile->GetGameEntity (); if ( CClientPickup* pPickup = DynamicCast < CClientPickup > ( pClientEntity ) ) pGameEntity = pPickup->GetGameObject (); CEntity* pMappedGameEntity = MapFindRef ( m_ClientToGameMap, pClientEntity ); CClientEntity* pMappedClientEntity = MapFindRef ( m_GameToClientMap, pGameEntity ); strClientEntityInfo = SString ( "%s Id:%x GameEntity:%08x MappedGameEntity:%08x MappedClientEntity:%08x" , pClientEntity->GetClassName () , pClientEntity->GetID () , (int)pGameEntity , (int)pMappedGameEntity , (int)pMappedClientEntity ); } SString strMessage ( "EntitySAInterface:%08x Vtbl:%08x ModelId:%d ClientEntity:%08x [%s]" , (int)pEntitySAInterface , InterfaceVtbl , InterfaceModelId , (int)pClientEntity , *strClientEntityInfo ); g_pCore->LogEvent ( 8542, "XRefManager", "GameEntity Mismatch", strMessage ); AddReportLog ( 8542, strMessage ); dassert ( 0 ); } }
void DebugCreateCount ( const SString& strName ) { SDebugCountInfo& info = MapGet ( ms_DebugCountMap, strName ); info.iCount++; if ( info.iCount > info.iHigh ) { info.iHigh = info.iCount; OutputDebugLine ( SString ( "[InstanceCount] New high of %d for %s", info.iCount, *strName ) ); } }
SString operator+(const SString& str, const SString& str2) { string s = std::string(str.getCString()); string s2 = std::string(str2.getCString()); SString sstr = SString((s + s2).c_str()); return sstr; }
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing) { CFilePathTranslator FileTranslator; std::string WorkingDirectory; if ( dwReason == DLL_PROCESS_ATTACH ) { WriteDebugEvent( SString( "DLL_PROCESS_ATTACH %08x", pvNothing ) ); if ( IsRealDeal () ) { FileTranslator.GetGTARootDirectory ( WorkingDirectory ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // For dll searches, this call replaces the current directory entry and turns off 'SafeDllSearchMode' // Meaning it will search the supplied path before the system and windows directory. // http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx SetDllDirectory( CalcMTASAPath ( "MTA" ) ); g_pCore = new CCore; FileTranslator.GetGTARootDirectory ( WorkingDirectory ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); } } else if (dwReason == DLL_PROCESS_DETACH) { WriteDebugEvent( SString( "DLL_PROCESS_DETACH %08x", pvNothing ) ); if ( IsRealDeal () ) { // For now, TerminateProcess if any destruction is attempted (or we'll crash) TerminateProcess ( GetCurrentProcess (), 0 ); if ( g_pCore ) { delete g_pCore; g_pCore = NULL; } } } return TRUE; }
////////////////////////////////////////////////////////// // // CInstallManager::_ChangeFromAdmin // // Save the state of the sequencer and exit back to the user process // ////////////////////////////////////////////////////////// SString CInstallManager::_ChangeFromAdmin ( void ) { if ( IsUserAdmin () && IsBlockingUserProcess () ) { SendStringToUserProcess ( GetSequencerSnapshot () ); AddReportLog ( 1003, SString ( "CInstallManager::_ChangeToAdmin - exit(0) %s", "" ) ); ClearIsBlockingUserProcess (); ExitProcess ( 0 ); } return "fail"; }
// // Dynamically increase the interval between near sync updates depending on stuffs // bool CPlayer::IsTimeToReceiveNearSyncFrom ( CPlayer* pOther, SNearInfo& nearInfo ) { int iZone = GetSyncZone ( pOther ); int iUpdateInterval = g_pBandwidthSettings->ZoneUpdateIntervals [ iZone ]; #if MTA_DEBUG if ( m_iLastZoneDebug != iZone ) { // Calc direction from our camera to the other player const CVector& vecOtherPosition = pOther->GetPosition (); CVector vecDirToOther = pOther->GetPosition () - m_vecCamPosition; // Get distance float fDistSq = vecDirToOther.LengthSquared (); // Get angle between camera direction and direction to other vecDirToOther.Normalize (); float fDot = m_vecCamFwd.DotProduct ( &vecDirToOther ); OutputDebugLine ( SString ( "Dist:%1.0f Dot:%0.3f %s SyncTo %s zone changing: %d -> %d [Interval:%d] CamPos:%1.0f,%1.0f,%1.0f CamFwd:%1.2f,%1.2f,%1.2f " ,sqrtf ( fDistSq ) ,fDot ,pOther->GetNick () ,GetNick () ,m_iLastZoneDebug ,iZone ,iUpdateInterval ,m_vecCamPosition.fX ,m_vecCamPosition.fY ,m_vecCamPosition.fZ ,m_vecCamFwd.fX ,m_vecCamFwd.fY ,m_vecCamFwd.fZ ) ); m_iLastZoneDebug = iZone; } #endif long long llTimeNow = GetModuleTickCount64 (); long long llNextUpdateTime = nearInfo.llLastUpdateTime + iUpdateInterval; if ( llNextUpdateTime > llTimeNow ) { g_pStats->puresync.llSkippedPacketsByZone[ iZone ]++; return false; } nearInfo.llLastUpdateTime = llTimeNow; g_pStats->puresync.llSentPacketsByZone[ iZone ]++; return true; }
// // Returns true if dll has been loaded with GTA. // bool IsRealDeal ( void ) { // Get current module full path char szBuffer[64000]; GetModuleFileName ( NULL, szBuffer, sizeof(szBuffer) - 1 ); WriteDebugEvent( SString( "ModuleFileName: %s", szBuffer ) ); if ( SStringX( szBuffer ).EndsWithI( "gta_sa.exe" ) || SStringX( szBuffer ).EndsWithI( "proxy_sa.exe" ) ) return true; return false; }
CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction ) { m_VM = luaMain; m_iFunction = iFunction; arguments->WriteToJSONString ( m_strData, true ); m_strURL = SString ( "http://%s/%s/call/%s", szServerHost, szResourceName, szFunctionName ); MakeCall(); }
SString GetDebugMessage ( lua_State* luaVM ) { SString strDebugMessage = ""; lua_Debug debugInfo; if ( luaVM && lua_getstack ( luaVM, 1, &debugInfo ) ) { lua_getinfo ( luaVM, "nlS", &debugInfo ); if ( debugInfo.source[0] == '@' ) { SString strFile = ConformResourcePath ( debugInfo.source ); strDebugMessage = SString( "%s:%i", strFile.c_str (), debugInfo.currentline ); } else { SString strFile = debugInfo.short_src; strDebugMessage = SString( "%s:%i", strFile.c_str (), debugInfo.currentline ); } } return strDebugMessage; }
////////////////////////////////////////////////////////// // // HandleResetSettings // // // ////////////////////////////////////////////////////////// void HandleResetSettings ( void ) { if ( CheckAndShowFileOpenFailureMessage () ) return; CheckAndShowMissingFileMessage(); SString strSaveFilePath = PathJoin ( GetSystemPersonalPath(), "GTA San Andreas User Files" ); SString strSettingsFilename = PathJoin ( strSaveFilePath, "gta_sa.set" ); SString strSettingsFilenameBak = PathJoin ( strSaveFilePath, "gta_sa_old.set" ); if ( FileExists ( strSettingsFilename ) ) { int iResponse = MessageBoxUTF8 ( NULL, _("There seems to be a problem launching MTA:SA.\nResetting GTA settings can sometimes fix this problem.\n\nDo you want to reset GTA settings now?"), "MTA: San Andreas"+_E("CL08"), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST ); if ( iResponse == IDYES ) { FileDelete ( strSettingsFilenameBak ); FileRename ( strSettingsFilename, strSettingsFilenameBak ); FileDelete ( strSettingsFilename ); if ( !FileExists ( strSettingsFilename ) ) { AddReportLog ( 4053, "Deleted gta_sa.set" ); MessageBoxUTF8 ( NULL, _("GTA settings have been reset.\n\nPress OK to continue."), "MTA: San Andreas", MB_OK | MB_ICONINFORMATION | MB_TOPMOST ); } else { AddReportLog ( 5054, SString ( "Delete gta_sa.set failed with '%s'", *strSettingsFilename ) ); MessageBoxUTF8 ( NULL, SString ( _("File could not be deleted: '%s'"), *strSettingsFilename ), "Error"+_E("CL09"), MB_OK | MB_ICONWARNING | MB_TOPMOST ); } } } else { // No settings to delete, or can't find them int iResponse = MessageBoxUTF8 ( NULL, _("Are you having problems running MTA:SA?.\n\nDo you want to see some online help?"), "MTA: San Andreas", MB_YESNO | MB_ICONQUESTION | MB_TOPMOST ); if ( iResponse == IDYES ) { BrowseToSolution ( "crashing-before-gtalaunch", TERMINATE_PROCESS ); } } }
//////////////////////////////////////////////// // // Hook CCore::OnPreCreateDevice // // Modify paramters // //////////////////////////////////////////////// void CCore::OnPreCreateDevice(IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD& BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters) { assert(0); if (!UsingAltD3DSetup()) return; WriteDebugEvent("CCore::OnPreCreateDevice"); uint uiPrevResult = GetApplicationSettingInt("diagnostics", "last-create-device-result"); if (uiPrevResult) { // Failed last time, so as a test for logging, try a create device with no modifications WriteDebugEvent(SString("Previous CreateDevice failed with: %08x", uiPrevResult)); WriteDebugEvent(" Test unmodified:"); WriteDebugEvent(ToString(Adapter, DeviceType, hFocusWindow, BehaviorFlags, *pPresentationParameters)); IDirect3DDevice9* pReturnedDeviceInterface = NULL; HRESULT hResult = pDirect3D->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, &pReturnedDeviceInterface); SAFE_RELEASE(pReturnedDeviceInterface); WriteDebugEvent(SString(" Unmodified result is: %08x", hResult)); } // Save original values for later BehaviorFlagsOrig = BehaviorFlags; presentationParametersOrig = *pPresentationParameters; WriteDebugEvent(" Original paramters:"); WriteDebugEvent(ToString(Adapter, DeviceType, hFocusWindow, BehaviorFlags, *pPresentationParameters)); // Make sure DirectX Get...() calls will work BehaviorFlags &= ~D3DCREATE_PUREDEVICE; // Enable the auto depth stencil parameter pPresentationParameters->EnableAutoDepthStencil = true; GetVideoModeManager()->PreCreateDevice(pPresentationParameters); WriteDebugEvent(" Modified paramters:"); WriteDebugEvent(ToString(Adapter, DeviceType, hFocusWindow, BehaviorFlags, *pPresentationParameters)); }
int CLuaFileDefs::fileGetPath ( lua_State* luaVM ) { // string fileGetPath ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Grab our lua VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pThisResource = pLuaMain->GetResource (); CResource* pFileResource = pFile->GetResource (); SString strFilePath = pFile->GetFilePath (); // If the calling resource is not the resource the file resides in // we need to prepend :resourceName to the path if ( pThisResource != pFileResource ) { #ifdef MTA_CLIENT strFilePath = SString ( ":%s/%s", pFileResource->GetName (), *strFilePath ); #else strFilePath = SString ( ":%s/%s", *pFileResource->GetName (), *strFilePath ); #endif } lua_pushlstring ( luaVM, strFilePath, strFilePath.length () ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
//////////////////////////////////////////////////////////////// // // CRenderWareSA::OnDestroyTexInfo // // // //////////////////////////////////////////////////////////////// void CRenderWareSA::OnDestroyTexInfo ( STexInfo* pTexInfo ) { // Remove from lookup maps SString strUniqueKey ( "%d_%s", pTexInfo->usTxdId, *pTexInfo->strTextureName ); if ( !MapContains ( m_UniqueTexInfoMap, strUniqueKey ) ) AddReportLog ( 5133, SString ( "OnDestroyTexInfo missing %s", *strUniqueKey ) ); MapRemove ( m_UniqueTexInfoMap, strUniqueKey ); // This assert fails when using engine txd replace functions - TODO find out why //assert ( MapContains ( m_D3DDataTexInfoMap, pTexInfo->pD3DData ) ); MapRemove ( m_D3DDataTexInfoMap, pTexInfo->pD3DData ); }