Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lakwsh committed Aug 1, 2024
1 parent bc524e0 commit cbd7dee
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 174 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: maptool

on:
push:
branches:
- 'main'
paths-ignore:
- '**.md'
- '**.yml'
schedule:
- cron: '30 03 01 */3 *'
workflow_dispatch:

jobs:
build_linux:
runs-on: ubuntu-20.04
steps:
- name: Prepare env
run: |
echo "deb http://dk.archive.ubuntu.com/ubuntu/ xenial main" | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt install gcc-5-multilib g++-5-multilib
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 100
- uses: actions/checkout@v4
with:
repository: lakwsh/hl2sdk-l4d2
path: hl2sdk-l4d2
- uses: actions/checkout@v4
with:
submodules: 'true'
path: maptool
- name: Build maptool
working-directory: maptool
run: make all
- uses: actions/upload-artifact@v4
with:
name: maptool-${{github.run_id}}
path: maptool/Release/maptool.so
compression-level: 9
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sigtool"]
path = sigtool
url = git@github.com:lakwsh/sigtool.git
118 changes: 14 additions & 104 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,126 +1,37 @@
# (C)2004-2010 Metamod:Source Development Team
# Makefile written by David "BAILOPAN" Anderson

#####################################
### EDIT BELOW FOR OTHER PROJECTS ###
#####################################

PROJECT = maptool
OBJECTS = maptool.cpp

##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
##############################################
OBJECTS = maptool.cpp sigtool/sig.cpp sigtool/sym.cpp

OPT_FLAGS = -Ofast -pipe
GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden
DEBUG_FLAGS = -g -ggdb3 -D_DEBUG
CPP = gcc
CPP_OSX = clang

##########################
### SDK CONFIGURATIONS ###
##########################

ENGINE = left4dead2
HL2SDK = ../hl2sdk-l4d2
HL2PUB = $(HL2SDK)/public
INCLUDE += -I$(HL2SDK)/public/game/server


OS := $(shell uname -s)

ifeq "$(OS)" "Darwin"
LIB_EXT = dylib
HL2LIB = $(HL2SDK)/lib/mac
else
LIB_EXT = so
HL2LIB = $(HL2SDK)/lib/linux
endif


LIB_EXT = so
HL2LIB = $(HL2SDK)/lib/linux
LIB_PREFIX = lib
ifneq (,$(filter left4dead2,$(ENGINE)))
ifneq "$(OS)" "Darwin"
LIB_SUFFIX = _srv.$(LIB_EXT)
else
LIB_SUFFIX = .$(LIB_EXT)
endif
else
LIB_SUFFIX = .$(LIB_EXT)
endif


CFLAGS += -std=c++11 -DSE_LEFT4DEAD2=9 -DSOURCE_ENGINE=9 -DL4D2
LIB_SUFFIX = _srv.$(LIB_EXT)

LINK += $(HL2LIB)/tier1_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX)

INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
-I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I.

################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
################################################
INCLUDE += -I. -Isigtool -I$(HL2PUB)/engine -I$(HL2PUB)/game/server \
-I$(HL2PUB) -I$(HL2PUB)/vstdlib -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1

BINARY = $(PROJECT).$(LIB_EXT)
BIN_DIR = Release
LINK += -shared

ifeq "$(DEBUG)" "true"
BIN_DIR = Debug.$(ENGINE)
CFLAGS += $(DEBUG_FLAGS)
else
BIN_DIR = Release.$(ENGINE)
CFLAGS += $(OPT_FLAGS)
endif


ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX)
LIB_EXT = dylib
CFLAGS += -DOSX -D_OSX
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5
else
LIB_EXT = so
CFLAGS += -D_LINUX
LINK += -shared
endif

IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")

ifeq "$(IS_CLANG)" "1"
CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/")
CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/")
else
CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3)
endif

CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \
-Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \
-Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \
-Werror -fPIC -fno-exceptions -fno-rtti -msse -m32 -fno-strict-aliasing

# Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
CFLAGS += $(GCC4_FLAGS)
endif

# Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor
endif

# OS is Linux and not using clang
ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1"
LINK += -static-libgcc
endif
CFLAGS += -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -D_snprintf=snprintf \
-Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp \
-D_LINUX -std=c++11 -Wall -Werror -fPIC -fno-exceptions -fno-rtti -msse -m32 -Ofast -pipe \
-fvisibility=hidden -fvisibility-inlines-hidden -static-libgcc -fno-strict-aliasing

OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)

$(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<

all:
mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/sigtool
ln -sf $(HL2LIB)/$(LIB_PREFIX)vstdlib$(LIB_SUFFIX)
ln -sf $(HL2LIB)/$(LIB_PREFIX)tier0$(LIB_SUFFIX)
$(MAKE) -f Makefile maptool
Expand All @@ -132,5 +43,4 @@ default: all

clean:
rm -rf $(BIN_DIR)
rm *$(LIB_SUFFIX)

rm -f *$(LIB_SUFFIX)
102 changes: 51 additions & 51 deletions maptool.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
#include <fstream>

#include "maptool.h"
#include "matchmaking/l4d2/imatchext_l4d.h"
#include "filesystem.h"
#include <fstream>
#ifdef WIN32
const char *mat_dll = "matchmaking_ds.dll";
const char *path = "left4dead2\\addons\\maplist.txt";
#else
const char *mat_dll = "matchmaking_ds_srv.so";
const char *path = "left4dead2/addons/maplist.txt";
#endif
#include "sigtool.h"

static const char *path = "left4dead2/addons/maplist.txt";

maptool g_maptool;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(maptool, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_maptool);

const char *mlist[] = {"coop", "realism", "versus", "survival", "scavenge"};

bool maptool::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory){
auto fs = (IFileSystem *)interfaceFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
auto fn = Sys_GetFactory(fs->LoadModule(mat_dll, "GAMEBIN", true));
if(!fn) return false;
auto match = (IMatchExtL4D *)fn(IMATCHEXT_L4D_INTERFACE, NULL);
if(match){
KeyValues *mis = match->GetAllMissions();
if(mis){
Msg("[maptool] Dumping all missions...\n");
std::ofstream fs;
fs.open(path, std::ios::out|std::ios::trunc);
KeyValues *map = mis->GetFirstSubKey();
while(map){
KeyValues *modes = map->FindKey("modes");
if(modes && !map->GetInt("BuiltIn")){
fs<<"<"<<map->GetName()<<"> "<<map->GetString("DisplayTitle")<<std::endl;
uint64 id = map->GetUint64("workshopid");
if(id) fs<<"url: https://steamcommunity.com/workshop/filedetails/?id="<<id<<std::endl;
else fs<<"url: "<<map->GetString("Website")<<std::endl;
for(unsigned i = 0; i<sizeof(mlist)/sizeof(mlist[0]); i++){
KeyValues *mode = modes->FindKey(mlist[i]);
if(!mode) continue;
fs<<"["<<mode->GetName()<<"]"<<std::endl;
KeyValues *chap = mode->GetFirstSubKey();
for(int j = 1; chap && !chap->IsEmpty("Map"); j++){
fs.width(2);
fs<<j<<": "<<chap->GetString("Map")<<std::endl;
fs<<"name: "<<chap->GetString("DisplayName")<<std::endl;
chap = chap->GetNextKey();
}
}
fs<<std::endl;
}
map = map->GetNextKey();
}
fs.close();
Msg("[maptool] done.\n");
}
}
return false;
static const char *mlist[] = {"coop", "realism", "versus", "survival", "scavenge"};

bool maptool::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) {
mem_info info = {"matchmaking_ds_srv.so"};
if (!find_base(&info)) return false;
auto match = (IMatchExtL4D *)get_sym(base, "_ZL13g_MatchExtL4D");
if (!match) return false;

KeyValues *mis = match->GetAllMissions();
if (!mis) return false;
Msg("[maptool] Dumping all missions...\n");

std::ofstream fs;
fs.open(path, std::ios::out | std::ios::trunc);

KeyValues *map = mis->GetFirstSubKey();
while (map) {
KeyValues *modes = map->FindKey("modes");
if (modes && !map->GetInt("BuiltIn")) {
fs << "<" << map->GetName() << "> " << map->GetString("DisplayTitle") << std::endl;
uint64 id = map->GetUint64("workshopid");
if (id) fs << "url: https://steamcommunity.com/workshop/filedetails/?id=" << id << std::endl;
else fs << "url: " << map->GetString("Website") << std::endl;

for (unsigned i = 0; i < sizeof(mlist) / sizeof(mlist[0]); i++) {
KeyValues *mode = modes->FindKey(mlist[i]);
if (!mode) continue;

fs << "[" << mode->GetName() << "]" << std::endl;
KeyValues *chap = mode->GetFirstSubKey();
for (int j = 1; chap && !chap->IsEmpty("Map"); j++) {
fs.width(2);
fs << j << ": " << chap->GetString("Map") << std::endl;
fs << "name: " << chap->GetString("DisplayName") << std::endl;
chap = chap->GetNextKey();
}
}
fs << std::endl;
}
map = map->GetNextKey();
}

fs.close();

Msg("[maptool] done.\n");
return false;
}
38 changes: 19 additions & 19 deletions maptool.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "eiface.h"

class maptool:public IServerPluginCallbacks{
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.3, 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){ }
virtual void LevelShutdown(){ }
virtual void ClientActive(edict_t *pEntity){ }
virtual void ClientDisconnect(edict_t *pEntity){ }
virtual void ClientPutInServer(edict_t *pEntity, char const *playername){ }
virtual void SetCommandClient(int index){ }
virtual void ClientSettingsChanged(edict_t *pEdict){ }
virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen){ return PLUGIN_CONTINUE; }
virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand &args){ return PLUGIN_CONTINUE; }
virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID){ return PLUGIN_CONTINUE; }
virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue){ }
virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory);
virtual void Unload() { }
virtual void Pause() { }
virtual void UnPause() { }
virtual const char *GetPluginDescription() { return "MapTool v1.1.0, 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) { }
virtual void LevelShutdown() { }
virtual void ClientActive(edict_t *pEntity) { }
virtual void ClientDisconnect(edict_t *pEntity) { }
virtual void ClientPutInServer(edict_t *pEntity, char const *playername) { }
virtual void SetCommandClient(int index) { }
virtual void ClientSettingsChanged(edict_t *pEdict) { }
virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) { return PLUGIN_CONTINUE; }
virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand &args) { return PLUGIN_CONTINUE; }
virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID) { return PLUGIN_CONTINUE; }
virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue) { }
};
extern maptool g_maptool;
1 change: 1 addition & 0 deletions sigtool
Submodule sigtool added at 2105b1

0 comments on commit cbd7dee

Please sign in to comment.