void CoreConfig::Initialize() { SMCError err; char filePath[PLATFORM_MAX_PATH]; /* Try to get command line value of core config convar */ const char *corecfg = icvar->GetCommandLineValue("sm_corecfgfile"); /* If sm_corecfgfile not specified on command line, use default value */ if (!corecfg) { corecfg = sm_corecfgfile.GetDefault(); } /* Format path to config file */ g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg); /* Reset cached key values */ m_KeyValues.clear(); m_Strings.Reset(); /* Parse config file */ if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay) { /* :TODO: This won't actually log or print anything :( - So fix that somehow */ const char *error = textparsers->GetSMCErrorString(err); g_Logger.LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : ""); } }
/* Function: void HackThread(void) Purpose: The main function for our hack, here is where we have our code Arguments: - Returns: - */ void HackThread(void) { HMODULE hEngineModule, hClientModule; //module handles CreateInterfaceFn pEngineFactory, pClientFactory; //CreateInterface function pointers while(!IsGameReady()) //while the game isn't ready Sleep(1000); //wait for a second before checking again //Here the game is ready, so we get handles to the dlls hEngineModule = GetModuleHandle("engine.dll"); //Get a handle to the engine dll hClientModule = GetModuleHandle("client.dll"); //Get a handle to the client dll //Get the function pointers to the CreateInterface functions pEngineFactory = (CreateInterfaceFn)GetProcAddress(hEngineModule, "CreateInterface"); //Get the address of the CreateInterface function in engine.dll pClientFactory = (CreateInterfaceFn)GetProcAddress(hClientModule, "CreateInterface"); //Get the address of the CreateInterface function in client.dll //Nullpointer checks if(pEngineFactory == NULL || pClientFactory == NULL) //if any of the two function pointers is NULL { MessageBox(0, "A CreateInterface pointer was NULL, shutting down!", "Failure", MB_OK); //Warn us about it exit(0); //and exit the game } //Get pointers to the existing interfaces in client.dll pBaseClient = (IBaseClientDLL*)pClientFactory(CLIENT_DLL_INTERFACE_VERSION, 0); //CLIENT_DLL_INTERFACE_VERSION is defined as "VClient013" pClientEntityList = (IClientEntityList*)pClientFactory(VCLIENTENTITYLIST_INTERFACE_VERSION, 0); //VCLIENTENTITYLIST_INTERFACE_VERSION is defined as "VClientEntityList003" //Get pointers to the existing interfaces in engine.dll pEngineClient = (IVEngineClient*)pEngineFactory(VENGINE_CLIENT_INTERFACE_VERSION, 0); //VENGINE_CLIENT_INTERFACE_VERSION is defined as "VEngineClient012" pCvar = (ICvar*)pEngineFactory(VENGINE_CVAR_INTERFACE_VERSION, 0); //VENGINE_CVAR_INTERFACE_VERSION is defined as "VEngineCvar003" if(pBaseClient == NULL || pClientEntityList == NULL || pEngineClient == NULL || pCvar == NULL) //if any of the pointers is NULL { MessageBox(0, "One of the interface pointers is NULL, shutting down!", "Failure", MB_OK); //Warn us about it exit(0); //and exit the game } while(1) //We passed all the checks, so we can enter an infinite loop { if(GetAsyncKeyState(VK_NUMPAD1)&1) //if the first bit for numpad1 is set(initial press & repeats) { pEngineClient->ClientCmd("monster_attack_bonus_ratio -80"); //enable godmode using ClientCmd } if(GetAsyncKeyState(VK_NUMPAD3)&1) //if the first bit for numpad3 is set(initial press & repeats) { //Disable godmode using ConVars ConVar *pGodmode = pCvar->FindVar("monster_attack_bonus_ratio"); //get a pointer to the ConVar if(pGodmode != NULL) //make sure it isn't a NULL pointer! pGodmode->SetValue(pGodmode->GetDefault()); //Set the convar back to the default value } Sleep(100); //Sleep(pause) the thread for 100 miliseconds } }
static cell_t GetConVarDefault(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError err; ConVar *pConVar; if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar)) != HandleError_None) { return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); } size_t bytes; pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetDefault(), &bytes); return bytes; }
void CVersionWarnPanel::OnTick() { BaseClass::OnTick(); if (Q_strcmp(cl_showversionwarnpanel.GetString(), cl_showversionwarnpanel.GetDefault()) != 0) { SetVisible(true); HFont m_hfReleaseFont = m_pReleaseText->GetFont(); char m_cReleaseText[225]; m_pReleaseText->GetText(m_cReleaseText, sizeof(m_cReleaseText)); char m_cReleaseF[225]; Q_snprintf(m_cReleaseF, 225, m_cReleaseText, MOM_CURRENT_VERSION, cl_showversionwarnpanel.GetString()); cl_showversionwarnpanel.Revert(); m_pReleaseText->SetText(m_cReleaseF); m_pReleaseText->SetURL("https://github.com/momentum-mod/game/releases"); SetSize(UTIL_ComputeStringWidth(m_hfReleaseFont, m_cReleaseF) + m_pReleaseText->GetXPos() * 2, GetTall()); m_pReleaseText->SetPos(m_pReleaseText->GetXPos(), GetTall() / 2); } }
void CoreConfig::Initialize() { SMCError err; char filePath[PLATFORM_MAX_PATH]; /* Try to get command line value of core config convar */ const char *corecfg = icvar->GetCommandLineValue("sm_corecfgfile"); /* If sm_corecfgfile is on the command line, use that * If sm_corecfgfile isn't there, check sm_basepath on the command line and build the path off that * If sm_basepath isn't there, just use the default path for the cfg */ if (corecfg) { ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg); } else { const char *basepath = icvar->GetCommandLineValue("sm_basepath"); /* Format path to config file */ if (basepath) { ke::path::Format(filePath, sizeof(filePath), "%s/%s/%s", g_SourceMod.GetGamePath(), basepath, "configs/core.cfg"); } else { ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), sm_corecfgfile.GetDefault()); } } /* Reset cached key values */ m_KeyValues.clear(); /* Parse config file */ if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay) { /* :TODO: This won't actually log or print anything :( - So fix that somehow */ const char *error = textparsers->GetSMCErrorString(err); logger->LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : ""); } }
void ConCommandBase::RevertFlaggedCvars( int flag ) { for (const ConCommandBase *var= GetCommands() ; var ; var=var->GetNext()) { if ( var->IsCommand() ) continue; ConVar *cvar = ( ConVar * )var; if ( !cvar->IsBitSet( flag ) ) continue; // It's == to the default value, don't count if ( !Q_strcasecmp( cvar->GetDefault(), cvar->GetString() ) ) continue; cvar->Revert(); // DevMsg( "%s = \"%s\" (reverted)\n", cvar->GetName(), cvar->GetString() ); } }
bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late) { const char *gamepath = g_SMAPI->GetBaseDir(); /* Store full path to game */ g_BaseDir.assign(gamepath); /* Store name of game directory by itself */ size_t len = strlen(gamepath); for (size_t i = len - 1; i < len; i--) { if (gamepath[i] == PLATFORM_SEP_CHAR) { strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir)); break; } } const char *basepath = icvar->GetCommandLineValue("sm_basepath"); /* Set a custom base path if there is one. */ if (basepath != NULL && basepath[0] != '\0') { m_GotBasePath = true; } /* Otherwise, use a default and keep the m_GotBasePath unlocked. */ else { basepath = sm_basepath.GetDefault(); } g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); if (!StartLogicBridge(error, maxlength)) { return false; } /* There will always be a path by this point, since it was force-set above. */ m_GotBasePath = true; /* Attempt to load the JIT! */ char file[PLATFORM_MAX_PATH]; char myerror[255]; g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s", GetSourceModPath(), PLATFORM_LIB_EXT ); g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror)); if (!g_pJIT) { if (error && maxlength) { UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", myerror, PLATFORM_LIB_EXT); } return false; } GetSourcePawnFactoryFn factoryFn = (GetSourcePawnFactoryFn)g_pJIT->GetSymbolAddress("GetSourcePawnFactory"); if (!factoryFn) { if (error && maxlength) snprintf(error, maxlength, "SourcePawn library is out of date"); ShutdownJIT(); return false; } ISourcePawnFactory *factory = factoryFn(SOURCEPAWN_API_VERSION); if (!factory) { if (error && maxlength) snprintf(error, maxlength, "SourcePawn library is out of date"); ShutdownJIT(); return false; } g_pPawnEnv = factory->NewEnvironment(); if (!g_pPawnEnv) { if (error && maxlength) snprintf(error, maxlength, "Could not create a SourcePawn environment!"); ShutdownJIT(); return false; } g_pSourcePawn = g_pPawnEnv->APIv1(); g_pSourcePawn2 = g_pPawnEnv->APIv2(); g_pSourcePawn2->SetDebugListener(logicore.debugger); if (sm_disable_jit) g_pSourcePawn2->SetJitEnabled(!sm_disable_jit); sSourceModInitialized = true; /* Hook this now so we can detect startup without calling StartSourceMod() */ SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false); /* Only load if we're not late */ if (!late) { StartSourceMod(false); } return true; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void ConVar_PrintDescription( const ConCommandBase *pVar ) { bool bMin, bMax; float fMin, fMax; const char *pStr; assert( pVar ); Color clr; clr.SetColor( 255, 100, 100, 255 ); if ( !pVar->IsCommand() ) { ConVar *var = ( ConVar * )pVar; const ConVar_ServerBounded *pBounded = dynamic_cast<const ConVar_ServerBounded*>( var ); bMin = var->GetMin( fMin ); bMax = var->GetMax( fMax ); const char *value = NULL; char tempVal[ 32 ]; if ( pBounded || var->IsFlagSet( FCVAR_NEVER_AS_STRING ) ) { value = tempVal; int intVal = pBounded ? pBounded->GetInt() : var->GetInt(); float floatVal = pBounded ? pBounded->GetFloat() : var->GetFloat(); if ( fabs( (float)intVal - floatVal ) < 0.000001 ) { Q_snprintf( tempVal, sizeof( tempVal ), "%d", intVal ); } else { Q_snprintf( tempVal, sizeof( tempVal ), "%f", floatVal ); } } else { value = var->GetString(); } if ( value ) { ConColorMsg( clr, "\"%s\" = \"%s\"", var->GetName(), value ); if ( stricmp( value, var->GetDefault() ) ) { ConMsg( " ( def. \"%s\" )", var->GetDefault() ); } } if ( bMin ) { ConMsg( " min. %f", fMin ); } if ( bMax ) { ConMsg( " max. %f", fMax ); } ConMsg( "\n" ); // Handled virtualized cvars. if ( pBounded && fabs( pBounded->GetFloat() - var->GetFloat() ) > 0.0001f ) { ConColorMsg( clr, "** NOTE: The real value is %.3f but the server has temporarily restricted it to %.3f **\n", var->GetFloat(), pBounded->GetFloat() ); } } else { ConCommand *var = ( ConCommand * )pVar; ConColorMsg( clr, "\"%s\"\n", var->GetName() ); } ConVar_PrintFlags( pVar ); pStr = pVar->GetHelpText(); if ( pStr && pStr[0] ) { ConMsg( " - %s\n", pStr ); } }
bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late) { const char *gamepath = g_SMAPI->GetBaseDir(); /* Store full path to game */ g_BaseDir.assign(gamepath); /* Store name of game directory by itself */ size_t len = strlen(gamepath); for (size_t i = len - 1; i < len; i--) { if (gamepath[i] == PLATFORM_SEP_CHAR) { strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir)); break; } } const char *basepath = icvar->GetCommandLineValue("sm_basepath"); /* Set a custom base path if there is one. */ if (basepath != NULL && basepath[0] != '\0') { m_GotBasePath = true; } /* Otherwise, use a default and keep the m_GotBasePath unlocked. */ else { basepath = sm_basepath.GetDefault(); } g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); if (!StartLogicBridge(error, maxlength)) { return false; } /* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */ g_CoreConfig.Initialize(); /* There will always be a path by this point, since it was force-set above. */ m_GotBasePath = true; /* Attempt to load the JIT! */ char file[PLATFORM_MAX_PATH]; char myerror[255]; g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s", GetSourceModPath(), PLATFORM_LIB_EXT ); g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror)); if (!g_pJIT) { if (error && maxlength) { UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", myerror, PLATFORM_LIB_EXT); } return false; } GET_SP_V1 getv1 = (GET_SP_V1)g_pJIT->GetSymbolAddress("GetSourcePawnEngine1"); GET_SP_V2 getv2 = (GET_SP_V2)g_pJIT->GetSymbolAddress("GetSourcePawnEngine2"); if (getv1 == NULL) { if (error && maxlength) { snprintf(error, maxlength, "JIT is too old; upgrade SourceMod"); } ShutdownJIT(); return false; } else if (getv2 == NULL) { if (error && maxlength) { snprintf(error, maxlength, "JIT is too old; upgrade SourceMod"); } ShutdownJIT(); return false; } g_pSourcePawn = getv1(); g_pSourcePawn2 = getv2(); if (g_pSourcePawn2->GetAPIVersion() < 3) { g_pSourcePawn2 = NULL; if (error && maxlength) { snprintf(error, maxlength, "JIT version is out of date"); } return false; } if (!g_pSourcePawn2->Initialize()) { g_pSourcePawn2 = NULL; if (error && maxlength) { snprintf(error, maxlength, "JIT could not be initialized"); } return false; } g_pSourcePawn2->SetDebugListener(logicore.debugger); if (sm_disable_jit) g_pSourcePawn2->SetJitEnabled(!sm_disable_jit); sSourceModInitialized = true; /* Hook this now so we can detect startup without calling StartSourceMod() */ SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false); /* Only load if we're not late */ if (!late) { StartSourceMod(false); } return true; }