Skip to content

Commit

Permalink
Merge remote-tracking branch 'Half-LifeUpdated/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	dlls/game.cpp
  • Loading branch information
SamVanheer committed Oct 29, 2023
2 parents 3d3695e + 19d94e4 commit 3a0edf3
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 6 deletions.
21 changes: 15 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,26 @@ Can't be fixed:

# Half-Life Updated changelog

## Changes in V1.0.0 Release Candidate 002
## Changes in V1.0.0 Release Candidate 003

> Note: this release candidate has not been released yet.
### Bug fixes

* Fixed save game system not saving arrays of EHANDLEs if the first half of the array contains null handles (mainly affected Nihilanth's spheres) [#224](https://github.com/SamVanheer/halflife-updated/issues/224) (Thanks Ronin4862)
* Fixed player gaining health when drowning with god mode enabled and recovering health after surfacing (Thanks malortie)
* Fixed human grunts continuing to fire for a few seconds after killing the last enemy in an area [Opposing Force Updated #100](https://github.com/SamVanheer/halflife-op4-updated/issues/100) (Thanks Ronin4862 and malortie)
* Fixed crash when +USEing NPCs that have just exited a scripted sequence (Thanks malortie)
* Fixed talk monsters resetting other talk monsters' dying schedule if they are both killed at the same time (Thanks FreeSlave)

### Features

* Added sv_load_all_maps & sv_stop_loading_all_maps to help automate node graph generation

## Changes in V1.0.0 Release Candidate 002

### Bug fixes

* Fixed hand grenade animations not playing correctly [#209](https://github.com/SamVanheer/halflife-updated/pull/209) (Thanks Toodles2You)
* Fixed out of bounds access in studiomodel renderer bone setup code (halflife issue [#3360](https://github.com/ValveSoftware/halflife/issues/3360))
* Fixed mouse cursor being invisible in VGUI1 menus when raw input is enabled [#211](https://github.com/SamVanheer/halflife-updated/issues/211) (Thanks RykahKnight)
Expand All @@ -256,11 +270,6 @@ Can't be fixed:
* Reset current history icon slot when resetting item history HUD [#223](https://github.com/SamVanheer/halflife-updated/issues/223) (Thanks malortie)
* Fixed Gauss gun dealing full damage when saving and loading right after starting a charged shot (Thanks Oxofemple.)
* Prevent breakables from spawning multiple items when destroyed by gunfire and explosives at the same time (Thanks Oxofemple.)
* Fixed save game system not saving arrays of EHANDLEs if the first half of the array contains null handles (mainly affected Nihilanth's spheres) [#224](https://github.com/SamVanheer/halflife-updated/issues/224) (Thanks Ronin4862)
* Fixed player gaining health when drowning with god mode enabled and recovering health after surfacing (Thanks malortie)
* Fixed human grunts continuing to fire for a few seconds after killing the last enemy in an area [Opposing Force Updated #100](https://github.com/SamVanheer/halflife-op4-updated/issues/100) (Thanks Ronin4862 and malortie)
* Fixed crash when +USEing NPCs that have just exited a scripted sequence (Thanks malortie)
* Fixed talk monsters resetting other talk monsters' dying schedule if they are both killed at the same time (Thanks FreeSlave)

### Features

Expand Down
108 changes: 108 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
*/

#include <algorithm>
#include <string>
#include <vector>

#include "extdll.h"
#include "util.h"
#include "filesystem_utils.h"
#include "cbase.h"
#include "com_model.h"
#include "saverestore.h"
Expand All @@ -40,6 +45,7 @@
#include "usercmd.h"
#include "netadr.h"
#include "pm_shared.h"
#include "pm_defs.h"
#include "UserMessages.h"

#include "ctf/CTFGoal.h"
Expand Down Expand Up @@ -858,6 +864,101 @@ void ParmsChangeLevel()
pSaveData->connectionCount = BuildChangeList(pSaveData->levelList, MAX_LEVEL_CONNECTIONS);
}

static std::vector<std::string> g_MapsToLoad;

static void LoadNextMap()
{
const std::string mapName = std::move(g_MapsToLoad.back());
g_MapsToLoad.pop_back();

pmove->Con_Printf("Loading map \"%s\" automatically (%d left)\n",
mapName.c_str(), static_cast<int>(g_MapsToLoad.size() + 1));

if (g_MapsToLoad.empty())
{
pmove->Con_Printf("Loading last map\n");
g_MapsToLoad.shrink_to_fit();
}

SERVER_COMMAND(UTIL_VarArgs("map \"%s\"\n", mapName.c_str()));
}

static void LoadAllMaps()
{
if (!g_MapsToLoad.empty())
{
pmove->Con_Printf("Already loading all maps (%d remaining)\nUse sv_stop_loading_all_maps to stop\n",
static_cast<int>(g_MapsToLoad.size()));
return;
}

FileFindHandle_t handle = FILESYSTEM_INVALID_FIND_HANDLE;

const char* fileName = g_pFileSystem->FindFirst("maps/*.bsp", &handle);

if (fileName != nullptr)
{
do
{
std::string mapName = fileName;
mapName.resize(mapName.size() - 4);

if (std::find_if(g_MapsToLoad.begin(), g_MapsToLoad.end(), [=](const auto& candidate)
{ return 0 == stricmp(candidate.c_str(), mapName.c_str()); }) == g_MapsToLoad.end())
{
g_MapsToLoad.push_back(std::move(mapName));
}
} while ((fileName = g_pFileSystem->FindNext(handle)) != nullptr);

g_pFileSystem->FindClose(handle);

// Sort in reverse order so the first map in alphabetic order is loaded first.
std::sort(g_MapsToLoad.begin(), g_MapsToLoad.end(), [](const auto& lhs, const auto& rhs)
{ return rhs < lhs; });
}

if (!g_MapsToLoad.empty())
{
if (CMD_ARGC() == 2)
{
const char* firstMapToLoad = CMD_ARGV(1);

// Clear out all maps that would have been loaded before this one.
if (auto it = std::find(g_MapsToLoad.begin(), g_MapsToLoad.end(), firstMapToLoad);
it != g_MapsToLoad.end())
{
const std::size_t numberOfMapsToSkip = g_MapsToLoad.size() - (it - g_MapsToLoad.begin());

g_MapsToLoad.erase(it + 1, g_MapsToLoad.end());

pmove->Con_Printf("Skipping %d maps to start with \"%s\"\n",
static_cast<int>(numberOfMapsToSkip), g_MapsToLoad.back().c_str());
}
else
{
pmove->Con_Printf("Unknown map \"%s\", starting from beginning\n", firstMapToLoad);
}
}

pmove->Con_Printf("Loading %d maps one at a time to generate files\n", static_cast<int>(g_MapsToLoad.size()));

// Load the first map right now.
LoadNextMap();
}
else
{
pmove->Con_Printf("No maps to load\n");
}
}

void InitMapLoadingUtils()
{
g_engfuncs.pfnAddServerCommand("sv_load_all_maps", &LoadAllMaps);
// Escape hatch in case the command is executed in error.
g_engfuncs.pfnAddServerCommand("sv_stop_loading_all_maps", []()
{ g_MapsToLoad.clear(); });
}

static bool g_LastAllowBunnyHoppingState = false;

//
Expand Down Expand Up @@ -892,6 +993,13 @@ void StartFrame()
g_engfuncs.pfnSetPhysicsKeyValue(player->edict(), "bj", UTIL_dtos1(allowBunnyHopping ? 1 : 0));
}
}

// If we're loading all maps then change maps after 3 seconds (time starts at 1)
// to give the game time to generate files.
if (!g_MapsToLoad.empty() && gpGlobals->time > 4)
{
LoadNextMap();
}
}


Expand Down
1 change: 1 addition & 0 deletions dlls/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern void ClientCommand(edict_t* pEntity);
extern void ClientUserInfoChanged(edict_t* pEntity, char* infobuffer);
extern void ServerActivate(edict_t* pEdictList, int edictCount, int clientMax);
extern void ServerDeactivate();
void InitMapLoadingUtils();
extern void StartFrame();
extern void PlayerPostThink(edict_t* pEntity);
extern void PlayerPreThink(edict_t* pEntity);
Expand Down
3 changes: 3 additions & 0 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "extdll.h"
#include "eiface.h"
#include "util.h"
#include "client.h"
#include "game.h"
#include "filesystem_utils.h"

Expand Down Expand Up @@ -1177,6 +1178,8 @@ void GameDLLInit()

// END REGISTER CVARS FOR OPPOSING FORCE

InitMapLoadingUtils();

SERVER_COMMAND("exec skill.cfg\n");
SERVER_COMMAND("exec skillopfor.cfg\n");
}
Expand Down

0 comments on commit 3a0edf3

Please sign in to comment.