Skip to content

Commit

Permalink
Do not load unnecessary VPPs in dedicated server mode
Browse files Browse the repository at this point in the history
Following VPPs will no longer be loaded:
- audio.vpp
- maps_*.vpp
- levels[123].vpp
- maps[1234].vpp
- music.vpp
- ui.vpp
- dashfaction.vpp

Also don't check if sound files exist in dedicated server mode.
This change may slightly speed up server startup and reduce number of
logged errors in minimal setups.
  • Loading branch information
rafalh committed Aug 18, 2024
1 parent f6951b0 commit 9bcfa83
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Version 1.8.1 (not released yet)
- Fix final level time left count-down in multi using wrong font (DF bug)
- Add Spawn Health/Armor settings for dedicated servers
- Add Kill Reward settings for dedicated servers
- Do not load unnecessary VPPs in dedicated server mode

Version 1.8.0 (released 2022-09-17)
-----------------------------------
Expand Down
12 changes: 7 additions & 5 deletions game_patch/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ CodeInjection after_level_render_hook{
CodeInjection after_frame_render_hook{
0x004B2DC2,
[]() {
// Draw on top (after scene)
frametime_render_ui();
multi_render_level_download_progress();
if (!rf::is_dedicated_server) {
// Draw on top (after scene)
frametime_render_ui();
multi_render_level_download_progress();
#if !defined(NDEBUG) && defined(HAS_EXPERIMENTAL)
experimental_render();
experimental_render();
#endif
debug_render_ui();
debug_render_ui();
}
},
};

Expand Down
51 changes: 31 additions & 20 deletions game_patch/misc/vpackfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../rf/file/file.h"
#include "../rf/file/packfile.h"
#include "../rf/crt.h"
#include "../rf/multi.h"
#include "../os/console.h"

#define CHECK_PACKFILE_CHECKSUM 0 // slow (1 second on SSD on first load after boot)
Expand Down Expand Up @@ -443,22 +444,26 @@ static void vpackfile_init_new()
g_loopup_table.reserve(10000);

if (get_installed_game_lang() == LANG_GR) {
rf::vpackfile_add("audiog.vpp", nullptr);
rf::vpackfile_add("maps_gr.vpp", nullptr);
rf::vpackfile_add("levels1g.vpp", nullptr);
rf::vpackfile_add("levels2g.vpp", nullptr);
rf::vpackfile_add("levels3g.vpp", nullptr);
if (!rf::is_dedicated_server) {
rf::vpackfile_add("audiog.vpp", nullptr);
rf::vpackfile_add("maps_gr.vpp", nullptr);
rf::vpackfile_add("levels1g.vpp", nullptr);
rf::vpackfile_add("levels2g.vpp", nullptr);
rf::vpackfile_add("levels3g.vpp", nullptr);
}
rf::vpackfile_add("ltables.vpp", nullptr);
}
else if (get_installed_game_lang() == LANG_FR) {
rf::vpackfile_add("audiof.vpp", nullptr);
rf::vpackfile_add("maps_fr.vpp", nullptr);
rf::vpackfile_add("levels1f.vpp", nullptr);
rf::vpackfile_add("levels2f.vpp", nullptr);
rf::vpackfile_add("levels3f.vpp", nullptr);
if (!rf::is_dedicated_server) {
rf::vpackfile_add("audiof.vpp", nullptr);
rf::vpackfile_add("maps_fr.vpp", nullptr);
rf::vpackfile_add("levels1f.vpp", nullptr);
rf::vpackfile_add("levels2f.vpp", nullptr);
rf::vpackfile_add("levels3f.vpp", nullptr);
}
rf::vpackfile_add("ltables.vpp", nullptr);
}
else {
else if (!rf::is_dedicated_server) {
rf::vpackfile_add("audio.vpp", nullptr);
rf::vpackfile_add("maps_en.vpp", nullptr);
rf::vpackfile_add("levels1.vpp", nullptr);
Expand All @@ -468,15 +473,19 @@ static void vpackfile_init_new()
rf::vpackfile_add("levelsm.vpp", nullptr);
// rf::vpackfile_add("levelseb.vpp", nullptr);
// rf::vpackfile_add("levelsbg.vpp", nullptr);
rf::vpackfile_add("maps1.vpp", nullptr);
rf::vpackfile_add("maps2.vpp", nullptr);
rf::vpackfile_add("maps3.vpp", nullptr);
rf::vpackfile_add("maps4.vpp", nullptr);
if (!rf::is_dedicated_server) {
rf::vpackfile_add("maps1.vpp", nullptr);
rf::vpackfile_add("maps2.vpp", nullptr);
rf::vpackfile_add("maps3.vpp", nullptr);
rf::vpackfile_add("maps4.vpp", nullptr);
}
rf::vpackfile_add("meshes.vpp", nullptr);
rf::vpackfile_add("motions.vpp", nullptr);
rf::vpackfile_add("music.vpp", nullptr);
rf::vpackfile_add("ui.vpp", nullptr);
load_dashfaction_vpp();
if (!rf::is_dedicated_server) {
rf::vpackfile_add("music.vpp", nullptr);
rf::vpackfile_add("ui.vpp", nullptr);
load_dashfaction_vpp();
}
rf::vpackfile_add("tables.vpp", nullptr);
addr_as_ref<int>(0x01BDB218) = 1; // VPackfilesLoaded
addr_as_ref<uint32_t>(0x01BDB210) = 10000; // NumFilesInVfs
Expand All @@ -499,8 +508,10 @@ static void vpackfile_init_new()
write_mem_ptr(0x004B082B + 1, "localized_strings.tbl");
}

// Allow modded strings.tbl in ui.vpp
force_file_from_packfile("strings.tbl", "ui.vpp");
if (!rf::is_dedicated_server) {
// Allow modded strings.tbl in ui.vpp
force_file_from_packfile("strings.tbl", "ui.vpp");
}

xlog::info("Packfiles initialization took %lums", GetTickCount() - start_ticks);
xlog::info("Packfile name collisions: %d", g_num_name_collisions);
Expand Down
13 changes: 13 additions & 0 deletions game_patch/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ FunHook<bool(const char*)> snd_pc_file_exists_hook{
}
};

FunHook<int(const char*, float, float, float)> snd_get_handle_hook{
0x005054B0,
[](const char* filename, float min_range, float base_volume, float rolloff) {
if (!rf::sound_enabled) {
return -1;
}
return snd_get_handle_hook.call_target(filename, min_range, base_volume, rolloff);
},
};

void snd_ds_apply_patch();

void apply_sound_patches()
Expand Down Expand Up @@ -483,6 +493,9 @@ void apply_sound_patches()

// Log when sound file cannot be found
snd_pc_file_exists_hook.install();

// Do not update sounds array in dedicated server mode
snd_get_handle_hook.install();
}

void register_sound_commands()
Expand Down

0 comments on commit 9bcfa83

Please sign in to comment.