1.1 --- a/core/ConVarManager.cpp Fri Nov 14 03:38:59 2008 -0600
1.2 +++ b/core/ConVarManager.cpp Fri Nov 14 09:18:30 2008 -0600
1.3 @@ -41,16 +41,18 @@
1.4
1.5 ConVarManager g_ConVarManager;
1.6
1.7 -#if !defined ORANGEBOX_BUILD
1.8 +#if SOURCE_ENGINE == SE_EPISODEONE
1.9 #define CallGlobalChangeCallbacks CallGlobalChangeCallback
1.10 #endif
1.11
1.12 -#if defined ORANGEBOX_BUILD
1.13 +#if SOURCE_ENGINE >= SE_ORANGEBOX
1.14 SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float);
1.15 #else
1.16 SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *);
1.17 #endif
1.18
1.19 +SH_DECL_HOOK1_void(ICvar, InstallGlobalChangeCallback, SH_NOATTRIB, false, FnChangeCallback_t);
1.20 +
1.21 SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
1.22 SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *);
1.23
1.24 @@ -79,12 +81,41 @@
1.25 m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL);
1.26 }
1.27
1.28 +bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
1.29 +{
1.30 +#if defined WIN32 || defined _WIN32
1.31 + MEMORY_BASIC_INFORMATION mem;
1.32 + if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
1.33 + return false;
1.34 + if (mem.AllocationBase == NULL)
1.35 + return false;
1.36 + HMODULE dll = (HMODULE)mem.AllocationBase;
1.37 + GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
1.38 +#elif defined __linux__
1.39 + Dl_info info;
1.40 + if (!dladdr(pAddr, &info))
1.41 + return false;
1.42 + if (!info.dli_fbase || !info.dli_fname)
1.43 + return false;
1.44 + const char *dllpath = info.dli_fname;
1.45 + snprintf(buffer, maxlength, "%s", dllpath);
1.46 +#endif
1.47 + return true;
1.48 +}
1.49 +
1.50 +void InstallCallback(FnChangeCallback_t callback)
1.51 +{
1.52 + char path[MAX_PATH];
1.53 + GetFileOfAddress((void *)callback, path, sizeof(path));
1.54 + printf("Yo: %s\n", path);
1.55 +}
1.56 +
1.57 void ConVarManager::OnSourceModAllInitialized()
1.58 {
1.59 /**
1.60 * Episode 2 has this function by default, but the older versions do not.
1.61 */
1.62 -#if !defined ORANGEBOX_BUILD
1.63 +#if SOURCE_ENGINE == SE_EPISODEONE
1.64 if (g_SMAPI->GetGameDLLVersion() >= 6)
1.65 {
1.66 SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false);
1.67 @@ -93,6 +124,7 @@
1.68 #endif
1.69
1.70 SH_ADD_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false);
1.71 + SH_ADD_HOOK_STATICFUNC(ICvar, InstallGlobalChangeCallback, icvar, InstallCallback, false);
1.72
1.73 /* Add the 'convars' option to the 'sm' console command */
1.74 g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this);
1.75 @@ -359,17 +391,10 @@
1.76 }
1.77 }
1.78
1.79 - /* To prevent creating a convar that has the same name as a console command... ugh */
1.80 - ConCommandBase *pBase = icvar->GetCommands();
1.81 -
1.82 - while (pBase)
1.83 + /* Prevent creating a convar that has the same name as a console command */
1.84 + if (FindCommand(name))
1.85 {
1.86 - if (pBase->IsCommand() && strcmp(pBase->GetName(), name) == 0)
1.87 - {
1.88 - return BAD_HANDLE;
1.89 - }
1.90 -
1.91 - pBase = const_cast<ConCommandBase *>(pBase->GetNext());
1.92 + return BAD_HANDLE;
1.93 }
1.94
1.95 /* Create and initialize ConVarInfo structure */
1.96 @@ -595,7 +620,7 @@
1.97 }
1.98 }
1.99
1.100 -#if defined ORANGEBOX_BUILD
1.101 +#if SOURCE_ENGINE >= SE_ORANGEBOX
1.102 void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
1.103 #else
1.104 void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
1.105 @@ -623,7 +648,7 @@
1.106 i != pInfo->changeListeners.end();
1.107 i++)
1.108 {
1.109 -#if defined ORANGEBOX_BUILD
1.110 +#if SOURCE_ENGINE >= SE_ORANGEBOX
1.111 (*i)->OnConVarChanged(pConVar, oldValue, flOldValue);
1.112 #else
1.113 (*i)->OnConVarChanged(pConVar, oldValue, atof(oldValue));
1.114 @@ -668,7 +693,7 @@
1.115 cell_t ret;
1.116
1.117 pCallback->PushCell(cookie);
1.118 - pCallback->PushCell(engine->IndexOfEdict(pPlayer));
1.119 + pCallback->PushCell(IndexOfEdict(pPlayer));
1.120 pCallback->PushCell(result);
1.121 pCallback->PushString(cvarName);
1.122