diff --git a/Makefile b/Makefile index 89b1436..078d170 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ##################################### PROJECT = maptool -OBJECTS = maptool.cpp signature.cpp +OBJECTS = maptool.cpp ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### diff --git a/maptool.cpp b/maptool.cpp index a902fed..0ff82cd 100644 --- a/maptool.cpp +++ b/maptool.cpp @@ -1,8 +1,8 @@ #include "maptool.h" #ifdef WIN32 -const char *mat_dll[] = {"matchmaking_ds.dll", "matchmaking.dll", 0}; +const char *mat_dll = "left4dead2\\bin\\matchmaking_ds.dll"; #else -const char *mat_dll[] = {"matchmaking_ds_srv.so", 0}; +const char *mat_dll = "left4dead2/bin/matchmaking_ds_srv.so"; #endif maptool g_maptool; @@ -11,40 +11,37 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR(maptool, IServerPluginCallbacks, INTERFACEVERS const char *mlist[] = {"coop", "realism", "versus", "survival", "scavenge"}; bool maptool::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory){ - mem_info base = {NULL, 0}; - find_base_from_list(mat_dll, &base); - auto inf = (void *(*)(const char *, int *))get_func(base.addr, "CreateInterface"); - if(inf){ - uint **match = (uint **)inf("IMATCHEXT_L4D_INTERFACE_001", NULL); - if(match){ - KeyValues *mis = ((KeyValues *(*)(void *))match[0][0])(match); - if(mis){ - Msg("[maptool] Dumping all missions..."); - KeyValues *map = mis->GetFirstSubKey(); - while(map){ - KeyValues *modes = map->FindKey("modes"); - if(modes){ - Msg("[%s] %s\n", map->GetName(), map->GetString("DisplayTitle")); - uint64 id = map->GetUint64("workshopid"); - if(id) Msg("url: http://steamcommunity.com/workshop/filedetails/?id=%llu\n", id); - else Msg("url: %s\n", map->GetString("Website")); - for(unsigned i = 0; iFindKey(mlist[i]); - if(!mode) continue; - Msg("mode: %s\n", mode->GetName()); - KeyValues *chap = mode->GetFirstSubKey(); - while(chap && !chap->IsEmpty("Map")){ - Msg("code: %s\n", chap->GetString("Map")); - Msg("name: %s\n", chap->GetString("DisplayName")); - chap = chap->GetNextKey(); - } + auto fn = Sys_GetFactory(mat_dll); + if(!fn) return false; + uint **match = (uint **)fn("IMATCHEXT_L4D_INTERFACE_001", NULL); + if(match){ + KeyValues *mis = ((KeyValues *(*)(void *))match[0][0])(match); + if(mis){ + Msg("[maptool] Dumping all missions...\n"); + KeyValues *map = mis->GetFirstSubKey(); + while(map){ + KeyValues *modes = map->FindKey("modes"); + if(modes && !map->GetInt("BuiltIn")){ + Msg("<%s> %s\n", map->GetName(), map->GetString("DisplayTitle")); + uint64 id = map->GetUint64("workshopid"); + if(id) Msg("url: https://steamcommunity.com/workshop/filedetails/?id=%llu\n", id); + else Msg("url: %s\n", map->GetString("Website")); + for(unsigned i = 0; iFindKey(mlist[i]); + if(!mode) continue; + Msg("[%s]\n", mode->GetName()); + KeyValues *chap = mode->GetFirstSubKey(); + for(int j = 1; chap && !chap->IsEmpty("Map"); j++){ + Msg("%2d: %s\n", j, chap->GetString("Map")); + Msg("name: %s\n", chap->GetString("DisplayName")); + chap = chap->GetNextKey(); } } - map = map->GetNextKey(); Msg("\n"); } - Msg("[maptool] done."); + map = map->GetNextKey(); } + Msg("[maptool] done.\n"); } } return false; diff --git a/maptool.h b/maptool.h index 59abfb3..08fae92 100644 --- a/maptool.h +++ b/maptool.h @@ -1,14 +1,12 @@ #include "eiface.h" -#include "signature.h" - class maptool:public IServerPluginCallbacks{ public: virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory); virtual void Unload(){ } virtual void Pause(){ } virtual void UnPause(){ } - virtual const char *GetPluginDescription(){ return "maptool v1.0.0, https://github.com/lakwsh/maptool"; } + virtual const char *GetPluginDescription(){ return "maptool v1.0.1, https://github.com/lakwsh/maptool"; } virtual void LevelInit(char const *pMapName){ } virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax){ } virtual void GameFrame(bool simulating){ } diff --git a/signature.cpp b/signature.cpp deleted file mode 100644 index 2c0c2cb..0000000 --- a/signature.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include "signature.h" - -#ifdef WIN32 -#include -#include -#else -#include -#include -#include -#endif - -void *get_func(void *addr, const char *func){ -#ifdef WIN32 - return GetProcAddress((HMODULE)addr, func); -#else - void *result = NULL; - Dl_info info; - if(dladdr(addr, &info)){ - void *handle = dlopen(info.dli_fname, RTLD_NOW); - if(handle){ - result = dlsym(handle, func); - dlclose(handle); - } - } - return result; -#endif -} - -#ifndef WIN32 -typedef struct{ - const char *name; - mem_info *base; -} v_data; - -static int callback(struct dl_phdr_info *info, size_t size, void *data){ - v_data *d = (v_data *)data; - if(!info->dlpi_name || !strstr(info->dlpi_name, d->name)) return 0; - d->base->addr = (void *)info->dlpi_addr; - d->base->len = info->dlpi_phdr[0].p_filesz; // p_type=1 p_offset=0 - return 1; -} -#endif - -static bool find_base(const char *name, mem_info *base){ -#ifdef WIN32 - HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0); - if(hModuleSnap==INVALID_HANDLE_VALUE) return false; - MODULEENTRY32 me32; - me32.dwSize = sizeof(MODULEENTRY32); - while(Module32Next(hModuleSnap, &me32)){ // srcds - if(!strcmp(me32.szModule, name)){ - base->addr = me32.modBaseAddr; - base->len = me32.modBaseSize; - CloseHandle(hModuleSnap); - return true; - } - } - CloseHandle(hModuleSnap); -#else - v_data vdata = {name, base}; - if(dl_iterate_phdr(callback, &vdata)) return true; -#endif - return false; -} - -void find_base_from_list(const char *name[], mem_info *base){ - base->addr = NULL; - base->len = 0; - if(!name) return; - int i = 0; - while(name[i] && !find_base(name[i], base)) i++; -} diff --git a/signature.h b/signature.h deleted file mode 100644 index 7b9d2bb..0000000 --- a/signature.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _INCLUDE_SIGNATURE_ -#define _INCLUDE_SIGNATURE_ - -#ifdef WIN32 -typedef unsigned int uint; -typedef unsigned long long uint64; -#endif -typedef struct{ - void *addr; - uint len; -} mem_info; - -void *get_func(void *addr, const char *func); -void find_base_from_list(const char *name[], mem_info *base); -#endif //_INCLUDE_SIGNATURE_