From 3f809d018ac6c28887007da2c8aebef055f2af39 Mon Sep 17 00:00:00 2001 From: Karaulov Date: Tue, 7 May 2019 15:52:00 +0300 Subject: [PATCH] Simple entity editor (#694) Ability to load entites from separate file instead of map content. Added sv_use_entity_file cvar to toggle entites loading source. --- README.md | 1 + rehlds/engine/sv_main.cpp | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/README.md b/README.md index f6406e0..1d3598f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Bugfixed version of rehlds contains an additional cvars:
  • sv_rehlds_userinfo_transmitted_fields // Userinfo fields only with these keys will be transmitted to clients via network. If not set then all fields will be transmitted (except prefixed with underscore). Each key must be prefixed by backslash, for example "\name\model\*sid\*hltv\bottomcolor\topcolor". See [wiki](https://github.com/dreamstalker/rehlds/wiki/Userinfo-keys) to collect sufficient set of keys for your server. Default: ""
  • sv_rehlds_attachedentities_playeranimationspeed_fix // Fixes bug with gait animation speed increase when player has some attached entities (aiments). Can cause animation lags when cl_updaterate is low. Default: 0
  • sv_rehlds_maxclients_from_single_ip // Limit number of connections from the single ip address. Default: 5 +
  • sv_use_entity_file // Use custom entity file for a map. Path to an entity file will be "maps/[map name].ent". Default: 0 ## Commands diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index f9e54a8..e004ce7 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -203,6 +203,7 @@ cvar_t sv_rehlds_attachedentities_playeranimationspeed_fix = {"sv_rehlds_attache cvar_t sv_rehlds_local_gametime = {"sv_rehlds_local_gametime", "0", 0, 0.0f, nullptr}; cvar_t sv_rehlds_send_mapcycle = { "sv_rehlds_send_mapcycle", "0", 0, 0.0f, nullptr }; cvar_t sv_rehlds_maxclients_from_single_ip = { "sv_rehlds_maxclients_from_single_ip", "5", 0, 5.0f, nullptr }; +cvar_t sv_use_entity_file = { "sv_use_entity_file", "0", 0, 0.0f, nullptr }; #endif delta_t *SV_LookupDelta(char *name) @@ -6126,6 +6127,49 @@ int SV_SpawnServer(qboolean bIsDemo, char *server, char *startspot) void SV_LoadEntities(void) { +#ifdef REHLDS_FIXES + if (sv_use_entity_file.value > 0.0f) + { + char name[MAX_PATH]; + Q_snprintf(name, sizeof(name), "maps/%s.ent", g_psv.name); + + if (!FS_FileExists(name)) + { + FILE *f = FS_Open(name, "wb"); + if (f) + { + FS_Write(g_psv.worldmodel->entities, Q_strlen(g_psv.worldmodel->entities), 1, f); + FS_Close(f); + } + } + else + { + FILE *f = FS_Open(name, "rb"); + if (f) + { + Con_Printf("Using custom entity file: %s\n", name); + + unsigned int nFileSize = FS_Size(f); + char *pszInputStream = (char *)Mem_Malloc(nFileSize + 1); + if (!pszInputStream) + { + Sys_Error("%s: Could not allocate space for entity file of %i bytes", __func__, nFileSize + 1); + } + + FS_Read(pszInputStream, nFileSize, 1, f); + pszInputStream[nFileSize] = '\0'; + + ED_LoadFromFile(pszInputStream); + Mem_Free(pszInputStream); + FS_Close(f); + return; + } + } + + Con_Printf("Using default entities...\n"); + } + +#endif // REHLDS_FIXES ED_LoadFromFile(g_psv.worldmodel->entities); } @@ -7863,6 +7907,7 @@ void SV_Init(void) Cvar_RegisterVariable(&sv_rollspeed); Cvar_RegisterVariable(&sv_rollangle); + Cvar_RegisterVariable(&sv_use_entity_file); #endif for (int i = 0; i < MAX_MODELS; i++)