Compiling and running a C++ Valve Server Plugin.... in 2024 ???

Introduction

So, some days ago, me and and a friend were trying to bring back our old CS:S surf server. So we were finding everything relevant to our last backup we could find, however, there were some obscure C++ sources we really needed to compile, and those would compile to a Valve Server Plugin (VSP).

I’ve been in the source engine modding scene for some time, and VSPs were always something “less talked about”, and today I could the reason why. SourceMod is a great alternative yes, but in this specific case, I really needed to compile these VSP plugins.

  • My goal: Compile a C++ VSP that requires steam-runtime linking and such..
  • My experience: have to deal with horrible/incomplete valve docs, pain in the ass to setup, trial and error…

So, in this blog post, I’ll try to show you a quick sample of how you can compile your own VSP for a CS:S server.

Problems

I’ve used this guide: https://developer.valvesoftware.com/wiki/Source_SDK_2013 and https://github.com/XutaxKamay/ValveServerPlugin for my first attempts. Ended up in a situation where I could not compile my plugin code (that requires C++17) because steam-runtime’s g++ is like 10 years old, and the runtime is very old as well. Also found out that you have to run the runtime??? They implemented containerization off all of this? “sniper”, “scout” or “soldier” different SDK builds?

Setup

Prerequisites:

Compiling

So

  • Clone steam-runtime repo, we’ll need a script from there.
  • Install a recent snapshot of steam-runtime sysroot sniper SDK, you can find them here.
    git clone https://github.com/ValveSoftware/steam-runtime
    wget https://repo.steampowered.com/steamrt-images-sniper/snapshots/0.20220119.0/com.valvesoftware.SteamRuntime.Sdk-amd64%2Ci386-sniper-sysroot.tar.gz
    

Now, you can just run this to create a chroot environment:

steam-runtime/setup_chroot.sh --amd64 --tarball com.valvesoftware.SteamRuntime.Sdk-amd64,i386-sniper-sysroot.tar.gz

Compile the plugin:

git clone https://github.com/roby2014/ValveServerPlugin
cd ValveServerPlugin
schroot --chroot steamrt_scout_amd64 -- g++ -std=c++17 -m32 -Ofast -static-libstdc++ -static-libgcc -shared -o sample_plugin.so main.cpp

After this step, you should have a new object file named sample_plugin.so. This is your plugin. Now just move it alongside with it’s .vdf to cstrike/addons.

Restart server and boom (it should work):

plugin_print
Loaded plugins:
---------------------
0:      "ValveServerPlugin Blog post roby."
---------------------

If it crashes or logs something like:

server_srv.so loaded for "Counter-Strike: Source"
 failed to dlopen /home/container/cstrike/../cstrike/addons/sample_plugin.so error=/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/container/cstrike/../cstrike/addons/sample_plugin.so)
 failed to dlopen /home/container/hl2/../cstrike/addons/sample_plugin.so error=/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/container/hl2/../cstrike/addons/sample_plugin.so)
 failed to dlopen /home/container/bin/../cstrike/addons/sample_plugin.so error=/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/container/bin/../cstrike/addons/sample_plugin.so)
Unable to load plugin "../cstrike/addons/sample_plugin"
 failed to dlopen /home/container/cstrike/addons/metamod/bin/linux64/server.so error=/home/container/cstrike/addons/metamod/bin/linux64/server.so: wrong ELF class: ELFCLASS64
Unable to load plugin "addons/metamod/bin/linux64/server"

It probably means that you skipped a step.

Conclusion

Seriously, if you want to mod source engine games, take a look at SourceMod or MetaMod first, VSPs are hard to setup and you will work with stuff that is (probably) easily implemented in SourceMod.

References

updated_at 14-02-2023