Skip to content

Commit

Permalink
server auto enable jit mode
Browse files Browse the repository at this point in the history
add install.bat/install_linux.sh
JitOpt config default true->false
  • Loading branch information
fesily committed Feb 8, 2025
1 parent 9ff45de commit aaf6b3c
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else ()
message(FATAL_ERROR "Not supported platform")
endif ()

project(DontStarveLuaJIT VERSION 0.5.12)
project(DontStarveLuaJIT VERSION 0.6.0)

set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/Mod)
if (UNIX AND APPLE)
Expand Down
7 changes: 7 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"description": "Build with Ninja/vcpkg (Release)",
"configuration": "Release"
},
{
"name": "ninja-vcpkg-release-dbg",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build (RelWithDebInfo)",
"description": "Build with Ninja/vcpkg (RelWithDebInfo)",
"configuration": "RelWithDebInfo"
},
{
"name": "ninja-vcpkg",
"configurePreset": "ninja-multi-vcpkg",
Expand Down
41 changes: 41 additions & 0 deletions Mod/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off
setlocal enabledelayedexpansion

set "processes=dontstarve_steam_x64.exe dontstarve_dedicated_server_nullrenderer_x64.exe"

for %%p in (%processes%) do (
tasklist /FI "IMAGENAME eq %%p" 2>NUL | find /I "%%p" >NUL
if !errorlevel! == 0 (
echo [INFO] kill processes: %%p
taskkill /F /IM "%%p" >NUL
timeout /t 1 /nobreak >NUL
)
)

set "source=.\bin64\windows"
set "destination=..\..\bin64"

if not exist "%source%" (
echo [ERROR] source directory not find: %source%
timeout /t 5
exit /b 1
)

if not exist "%destination%" (
echo [INFO] create directory: %destination%
mkdir "%destination%"
)

echo [INFO] moving files...
robocopy "%source%" "%destination%" /E /MOVE /NP /NFL /NDL >NUL

if errorlevel 8 (
echo [ERROR] moving files failed
timeout /t 5
exit /b 1
)


echo [INFO] install success
timeout /t 5
exit /b 0
78 changes: 78 additions & 0 deletions Mod/install_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# List of processes to check
processes=("dontstarve_steam_x64.exe" "dontstarve_dedicated_server_nullrenderer_x64.exe")

# Terminate running processes
for process in "${processes[@]}"; do
pid=$(pgrep -f "$process")
if [ -n "$pid" ]; then
echo "[INFO] Terminating process: $process (PID: $pid)"
kill -9 "$pid"
sleep 1 # Wait for the process to fully terminate
fi
done

# Set path variables
source="bin64/linux"
destination="../../bin64"

# Verify if the source directory exists
if [ ! -d "$source" ]; then
echo "[ERROR] Source directory does not exist: $source"
exit 1
fi

# Create the destination directory if it doesn't exist
if [ ! -d "$destination" ]; then
echo "[INFO] Creating destination directory: $destination"
mkdir -p "$destination"
fi

# Move files
echo "[INFO] Moving files..."
cp -r "$source"/* "$destination/"

# Check the result of the operation
if [ $? -eq 0 ]; then
echo "[INFO] Files moved successfully"
else
echo "[ERROR] An error occurred while moving files"
exit 1
fi

if [ -f dontstarve_steam_x64 ] && [ $(stat -c%s dontstarve_steam_x64) -gt 1048576 ]; then
mv dontstarve_steam_x64 dontstarve_steam_x64_1

cat > dontstarve_steam_x64 <<'EOF'
#!/bin/bash
export LD_LIBRARY_PATH=./lib64
export LD_PRELOAD=./lib64/libInjector.so
./dontstarve_steam_x64_1
EOF

chmod +x dontstarve_steam_x64
echo "rewrite dontstarve_steam_x64 success"
else
echo "skip rewrite dontstarve_steam_x64."
fi

if [ -f dontstarve_dedicated_server_nullrenderer_x64 ] && [ $(stat -c%s dontstarve_dedicated_server_nullrenderer_x64) -gt 1048576 ]; then
mv dontstarve_dedicated_server_nullrenderer_x64 dontstarve_dedicated_server_nullrenderer_x64_1

cat > dontstarve_dedicated_server_nullrenderer_x64 <<'EOF'
#!/bin/bash
export LD_LIBRARY_PATH=./lib64
export LD_PRELOAD=./lib64/libInjector.so
./dontstarve_dedicated_server_nullrenderer_x64_1
EOF

chmod +x dontstarve_dedicated_server_nullrenderer_x64
echo "rewrite dontstarve_dedicated_server_nullrenderer_x64 success"
else
echo "skip rewrite dontstarve_dedicated_server_nullrenderer_x64."
fi


echo "[INFO] Operation completed successfully"
exit 0
181 changes: 90 additions & 91 deletions Mod/modinfo.lua
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
local lc = locale

local function translate(t)
t.zhr = t.zh
t.zht = t.zht or t.zh
return t[lc] or t.en
end
name = "DontStarveLuaJit2"

description = translate(
{
zh = [[
替换游戏底层虚拟机为LUAJIT,加速整个游戏
务必备份你的存档,不保证没错误
]],
en = [[
Replacing the underlying VM with luajit speeds up the entire game.
Be sure to back up your archive, there is no guarantee that there are no bugs!
]]
}
)

author = "fesil"

version = "0.5.11"

forumthread = "https://github.com/fesily/DontStarveLuaJit2"

api_version = 10

dont_starve_compatible = true
reign_of_giants_compatible = true
dst_compatible = true

--TODO: need test compatible without the mod
client_only_mod = true
server_only_mod = true

-- Preview image
icon_atlas = "images/modicon.xml"
icon = "modicon.tex"

configuration_options = {
{
name = "EnabledJIT",
label = translate({ en = "EnabledJIT", zh = "开启JIT模式" }),
hover = translate({
en = "It is recommended to turn off if the lag is severe in the game",
zh = "在游戏中卡顿现象很严重的建议关闭"
}),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = true
},
{
name = "JitOpt",
label = translate({ en = "JitOpt", zh = "JIT优化选项" }),
hover = translate({
en = "maybe faster, maybe slower.",
zh = "可能更快, 可能更慢."
}),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = true,
},
{
name = "ModBlackList",
label = translate({ en = "ModJitBlackList", zh = "MODJit黑名单" }),
hover = translate({ en = "some mod is't not appropriate", zh = "有些mod可能写的特别,不合适jit模式" }),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = true
},
{
name = "DisableJITWhenServer",
label = translate({ en = "DisableJITWhenServer", zh = "服务器禁用luajit" }),
hover = translate({ en = "server process disable luajit mod", zh = "服务器进程禁用luajit" }),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = false
}
}
--restart_required = true
local lc = locale

local function translate(t)
t.zhr = t.zh
t.zht = t.zht or t.zh
return t[lc] or t.en
end
name = "DontStarveLuaJit2"

description = translate(
{
zh = [[
替换游戏底层虚拟机为LUAJIT,加速整个游戏
务必备份你的存档,不保证没错误
]],
en = [[
Replacing the underlying VM with luajit speeds up the entire game.
Be sure to back up your archive, there is no guarantee that there are no bugs!
]]
}
)

author = "fesil"

version = "0.6.0"

forumthread = "https://github.com/fesily/DontStarveLuaJit2"

api_version = 10

dont_starve_compatible = true
reign_of_giants_compatible = true
dst_compatible = true

--TODO: need test compatible without the mod
client_only_mod = true

-- Preview image
icon_atlas = "images/modicon.xml"
icon = "modicon.tex"

configuration_options = {
{
name = "EnabledJIT",
label = translate({ en = "EnabledJIT", zh = "开启JIT模式" }),
hover = translate({
en = "It is recommended to turn off if the lag is severe in the game",
zh = "在游戏中卡顿现象很严重的建议关闭"
}),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = true
},
{
name = "JitOpt",
label = translate({ en = "JitOpt", zh = "JIT优化选项" }),
hover = translate({
en = "maybe faster, maybe slower.",
zh = "可能更快, 可能更慢."
}),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = false,
},
{
name = "ModBlackList",
label = translate({ en = "ModJitBlackList", zh = "MODJit黑名单" }),
hover = translate({ en = "some mod is't not appropriate", zh = "有些mod可能写的特别,不合适jit模式" }),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = true
},
{
name = "DisableJITWhenServer",
label = translate({ en = "DisableJITWhenServer", zh = "服务器禁用luajit" }),
hover = translate({ en = "server process disable luajit mod", zh = "服务器进程禁用luajit" }),
options = {
{ description = "On", data = true },
{ description = "Off", data = false },
},
default = false
}
}
--restart_required = true
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## NOTICE

Be sure to back up your archives, there are no guarantees that there are no bugs!
With standalone server tools you need to be aware that the `disable luajit for servers` option in the settings is invalid, you should just remove the luajit to start the server.

# Roadload

Expand Down Expand Up @@ -35,6 +36,9 @@ Be sure to back up your archives, there are no guarantees that there are no bugs

1. Create a new folder in the mods folder in the root directory of the game with a name like luajit_mod.
2. Then copy all the files to that folder.
### Simaple Path
run `install.bat`(windows) or `install_linux.sh`
`install_linux.sh` maybe need exec `chmod +x ./install_linux.sh`

## 2.Injector:

Expand Down
4 changes: 4 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 注意

请务必备份您的存档,因为我们无法保证插件不会导致存档损坏!
使用独立开服工具需要注意,设置中`服务器禁用luajit`选项是无效的,你应该直接去除luajit启动服务器

# Roadload

Expand Down Expand Up @@ -33,6 +34,9 @@

1. 先在游戏根目录下的mods文件夹中创建一个新的文件夹,名字随意取,比如luajit_mod
2. 然后把所有的文件复制到该目录
### 此时的简单方法
直接运行`install.bat`(windows) `install_linux.sh`
`install_linux.sh`可能需要执行`chmod +x ./install_linux.sh`赋予权限

## 2.注入部分:

Expand Down
2 changes: 1 addition & 1 deletion luajit
Submodule luajit updated 207 files
3 changes: 3 additions & 0 deletions src/DontStarveInjector/DontStarveInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ static void ReplaceLuaModule(const std::string &mainPath, const Signatures &sign
init_luajit_io(hluajitModule);
#endif

extern void init_luajit_jit_opt(module_handler_t hluajitModule);
init_luajit_jit_opt(hluajitModule);

#if USE_LISTENER
listener = (GumInvocationListener *)g_object_new(EXAMPLE_TYPE_LISTENER, NULL);
gum_module_enumerate_exports(target_module_name, PrintCallCb, NULL);
Expand Down
9 changes: 9 additions & 0 deletions src/DontStarveInjector/gameio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ static int lj_need_transform_path() noexcept {
return has_lua_debug_flag;
}

static uint32_t lj_jit_default_flags() noexcept {
auto path = getExePath();
return path.string().contains("nullrenderer") ? 1 : 0;
}

void init_luajit_io(module_handler_t hluajitModule) {
#define INIT_LUAJIT_IO(name) \
{ \
Expand All @@ -248,5 +253,9 @@ void init_luajit_io(module_handler_t hluajitModule) {
INIT_LUAJIT_IO(lj_fwrite);
INIT_LUAJIT_IO(lj_clearerr);
INIT_LUAJIT_IO(lj_need_transform_path);
}

void init_luajit_jit_opt(module_handler_t hluajitModule) {
INIT_LUAJIT_IO(lj_jit_default_flags);
#undef INIT_LUAJIT_IO
}
Loading

0 comments on commit aaf6b3c

Please sign in to comment.