Notice
This does NOT support closed-beta dedicated server as in CS2D Dedicated Server Closed Beta.
Description
This patches the dedicated server to use LuaJIT instead of Lua 5.1. This also allows Lua C (external) modules to be loaded without memory errors. This works for Windows and Linux (patches for macOS are welcome).
So what's better with LuaJIT? This execute your scripts faster, I mean, faster. You can also use one of the best feature in LuaJIT which is FFI. This means you can use [LuaJIT/LuaFFI] Fix for os.clock (6) again.
CentOS 7 Users
Unfortunately CentOS 7 stuck with very old glibc. CentOS 7 users must compile from source and not download the prebuilt binaries from this site!
Motivation
You may hear LuaJIT before and yes, LuaJIT was used in CS2D Beta 0.1.2.6 but removed in CS2D Beta 0.1.2.7 due to stability issues. I believe the instability was caused by ancient BlitzMax (or whatever CS2D uses) so this method only patches the Lua API inside the dedicated server to use LuaJIT and nothing else.
From UnrealSoftware Discord:
MikuAuahDark has written
Is it possible to have custom build of CS2D dedicated server with LuaJIT instead of Lua 5.1 as an option?
DC has written
@ MikuAuahDark Last time we tried that everything exploded. Won't go through the pain of trying it again. Not worth it.
MikuAuahDark has written
Even by adding notice that "it's unstable"?
DC has written
I can't add it as an option. either broken shit or working shit. The decision has already been made.
So, CS2DJIT is born. It provides users an option to use LuaJIT for their server.
Installation
Windows: Extract
cs2djit.dll,
cs2djitwrapper.exe, and optionally
lua51.dll(notice below!) into your CS2D server root directory, beside
cs2d_dedicated.exe
Linux: Extract
cs2djit.shand
libcs2djit.sointo your CS2D server root directory, beside
cs2d_dedicatedexecutable. Make sure you have 32-bit LuaJIT library installed (
libluajit-5.1:i386for Debian and its derivatives)
If your Linux VPS supports Docker, you can use EngiN33R's Docker image which additionally support LuaRocks so you can install Lua C modules with ease.
Running
Windows: Run
cs2djitwrapper.exein your server directory.
Linux: Run
cs2djit.shin your CS2D server directory, example:
bash cs2djit.sh
Source Code
In case you think this steals stuff, it's not. You can compile it yourself if you really paranoid. Here's the source code: https://github.com/MikuAuahDark/cs2djit
Permission
This program is licensed under MIT license. In short:
You can use this.
Modify.
Redistribute modified version under same or different license.
Hold liable. This program is provided "as-is".
Notes
This guaranteed 100% to break when new CS2D is released. Please check this file archive for up-to-date version! GitHub releases are used for archival-purpose only.
Executables only tested in Debian 10 and Windows 10.
In Windows, the LuaJIT lua51.dll is bundled along with the downloads. If you have your own compiled lua51.dll which uses same compiler as your other Lua modules, prefer that. You have to be consistent in using compilers there as mixing DLLs between different (MSVC) compilers can cause problems.
Windows Defender may flag
cs2djitwrapper.exeas virus or unwanted software. This maybe caused by antivirus doesn't quite like MinGW-compiled binaries. Rest assured that binaries are compiled by GitHub Actions from Debian or if you really paranoid you can compile this program yourself from source above.
If you have any issues which directly related to this, please tell me.
If your script breaks after using this, please tell me in UnrealSoftware Discord server, #cs2d-scripting channel.
This only benefits server scripters. This is not a form of cheat/hack that can give players unintended/unfair advantage!
If you got LD_PRELOAD error, please see below.
Fix LD_PRELOAD Error
This is caused if your script uses
os.executeor
io.popen. Save this script as
sys/lua/autorun/ld_preload_unset.lua
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
if not jit then return end local ffi = require("ffi") ffi.cdef[[ int unsetenv(const char *name); ]] if os.getenv("LD_PRELOAD") then 	ffi.C.unsetenv("LD_PRELOAD") end
attempt to index global 'arg' (a nil value)
If you have code something like this:
1
2
3
2
3
function foo(...) 	print(arg[1], arg[2], arg[3]) end
argyourself:
1
2
3
4
2
3
4
function foo(...) 	local arg = {...} -- this 	print(arg[1], arg[2], arg[3]) end
Version History
20240726
CS2D v1.0.1.4 support.
Windows now has LuaJIT 2.1.1720049189 DLL bundled. This DLL is compiled under MinGW. Please see above for implications!
20211127
CS2D v1.0.1.3 support.
20210523
CS2D v1.0.1.2 support.
20200130
Error when starting cs2djit.sh somewhere else other than current server folder
Windows now has LuaJIT-2.1.0-beta3 DLL bundled. This DLL is compiled under MinGW. Please see above for implications!
cs2djit.sh and cs2djitwrapper.exe now pass all arguments to cs2d_dedicated/.exe.
libcs2djit.so is now compiled under Ubuntu 16.04 to improve compatibility with older distros.
20200111
Initial release.
edited 28×, last 26.07.24 05:18:42 am
Approved by Starkkz
Download
370 kb, 849 Downloads