Skip to content

Commit 01eebc4

Browse files
authored
Merge pull request #316 from crymp-net/feature/item-system-xml-ssm
fix: Use XML weapon and ammo definitions when in server mode
2 parents 5d34fa2 + 5b60e1e commit 01eebc4

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

Code/CryGame/Game.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ bool CGame::Init(IGameFramework* pFramework)
190190

191191
string itemFolder = "scripts/entities/items/xml";
192192
pFramework->GetIItemSystem()->Scan(itemFolder.c_str());
193-
m_pWeaponSystem->RegisterXMLData();
193+
if (!gEnv->bClient) {
194+
CryLogAlways("[CryMP] Loading XML weapon definitions");
195+
m_pWeaponSystem->Scan(itemFolder.c_str());
196+
} else {
197+
CryLogAlways("[CryMP] Loading pre-compiled weapon definitions");
198+
m_pWeaponSystem->RegisterXMLData();
199+
}
194200

195201
m_pOptionsManager = COptionsManager::CreateOptionsManager();
196202

Code/CryGame/Items/Weapons/WeaponSystem.cpp

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ void CWeaponSystem::Reload()
208208

209209
m_tracerManager.Reset();
210210

211-
this->RegisterXMLData();
211+
if (!gEnv->bClient) {
212+
CryLogAlways("[CryMP] Reloading XML weapon definitions");
213+
for (TFolderList::iterator it = m_folders.begin(); it != m_folders.end(); ++it)
214+
Scan(it->c_str());
215+
} else {
216+
CryLogAlways("[CryMP] Reloading pre-compiled weapon definitions");
217+
this->RegisterXMLData();
218+
}
212219

213220
m_reloading = false;
214221
}
@@ -456,6 +463,133 @@ int CWeaponSystem::QueryProjectiles(SProjectileQuery& q)
456463
return q.nCount;
457464
}
458465

466+
//------------------------------------------------------------------------
467+
void CWeaponSystem::Scan(const char* folderName)
468+
{
469+
string folder = folderName;
470+
string search = folder;
471+
search += "/*.*";
472+
473+
if (!m_recursing)
474+
CryLog("Loading ammo XML definitions from '%s'!", folderName);
475+
476+
for (auto& entry : CryFind(search.c_str()))
477+
{
478+
if (entry.IsDirectory())
479+
{
480+
string subName = folder + "/" + entry.name;
481+
if (m_recursing)
482+
{
483+
Scan(subName.c_str());
484+
}
485+
else
486+
{
487+
m_recursing=true;
488+
Scan(subName.c_str());
489+
m_recursing=false;
490+
}
491+
continue;
492+
}
493+
494+
if (_stricmp(CryPath::GetExt(entry.name), "xml"))
495+
{
496+
continue;
497+
}
498+
499+
string xmlFile = folder + string("/") + string(entry.name);
500+
XmlNodeRef rootNode = m_pSystem->LoadXmlFile(xmlFile.c_str());
501+
502+
if (!rootNode)
503+
{
504+
CryLogWarning("Invalid XML file '%s'! Skipping...", xmlFile.c_str());
505+
continue;
506+
}
507+
508+
ScanXML(rootNode, xmlFile.c_str());
509+
}
510+
511+
if (!m_recursing)
512+
CryLog("Finished loading ammo XML definitions from '%s'!", folderName);
513+
514+
if (!m_reloading && !m_recursing)
515+
m_folders.push_back(folderName);
516+
}
517+
518+
//------------------------------------------------------------------------
519+
bool CWeaponSystem::ScanXML(XmlNodeRef& root, const char* xmlFile)
520+
{
521+
if (strcmpi(root->getTag(), "ammo"))
522+
return false;
523+
524+
const char* name = root->getAttr("name");
525+
if (!name)
526+
{
527+
CryLogWarningAlways("Missing ammo name in XML '%s'! Skipping...", xmlFile);
528+
return false;
529+
}
530+
531+
const char* className = root->getAttr("class");
532+
533+
if (!className)
534+
{
535+
CryLogWarningAlways("Missing ammo class in XML '%s'! Skipping...", xmlFile);
536+
return false;
537+
}
538+
539+
TProjectileRegistry::iterator it = m_projectileregistry.find(CONST_TEMP_STRING(className));
540+
if (it == m_projectileregistry.end())
541+
{
542+
CryLogWarningAlways("Unknown ammo class '%s' specified in XML '%s'! Skipping...", className, xmlFile);
543+
return false;
544+
}
545+
546+
const char* scriptName = root->getAttr("script");
547+
IEntityClassRegistry::SEntityClassDesc classDesc;
548+
classDesc.sName = name;
549+
classDesc.sScriptFile = scriptName ? scriptName : "";
550+
//classDesc.pUserProxyData = (void *)it->second;
551+
//classDesc.pUserProxyCreateFunc = &CreateProxy<CProjectile>;
552+
classDesc.flags |= ECLF_INVISIBLE;
553+
554+
IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name);
555+
556+
if (!m_reloading && !pClass)
557+
{
558+
m_pGame->GetIGameFramework()->GetIGameObjectSystem()->RegisterExtension(name, it->second, &classDesc);
559+
pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name);
560+
assert(pClass);
561+
}
562+
563+
564+
TAmmoTypeParams::iterator ait = m_ammoparams.find(pClass);
565+
if (ait == m_ammoparams.end())
566+
{
567+
std::pair<TAmmoTypeParams::iterator, bool> result = m_ammoparams.insert(TAmmoTypeParams::value_type(pClass, SAmmoTypeDesc()));
568+
ait = result.first;
569+
}
570+
571+
const char* configName = root->getAttr("configuration");
572+
573+
IItemParamsNode* params = m_pItemSystem->CreateParams();
574+
params->ConvertFromXML(root);
575+
576+
SAmmoParams* pAmmoParams = new SAmmoParams(params, pClass);
577+
578+
SAmmoTypeDesc& desc = ait->second;
579+
580+
if (!configName || !configName[0])
581+
{
582+
if (desc.params)
583+
delete desc.params;
584+
desc.params = pAmmoParams;
585+
}
586+
else
587+
desc.configurations.insert(std::make_pair<string, const SAmmoParams*>(configName, static_cast<const SAmmoParams*>(pAmmoParams)));
588+
589+
return true;
590+
}
591+
592+
459593
//------------------------------------------------------------------------
460594
void CWeaponSystem::RegisterAmmo(const char* name, const char* className, const char* script, const char* config, IItemParamsNode* params)
461595
{

Code/CryGame/Items/Weapons/WeaponSystem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ class CWeaponSystem : public ILevelSystemListener
102102

103103
CTracerManager &GetTracerManager() { return m_tracerManager; };
104104

105-
void RegisterAmmo(const char* name, const char* className, const char* script, const char* config, IItemParamsNode* params);
105+
void Scan(const char* folderName);
106+
bool ScanXML(XmlNodeRef& root, const char* xmlFile);
106107

108+
// CryMP:
109+
void RegisterAmmo(const char* name, const char* className, const char* script, const char* config, IItemParamsNode* params);
107110
// WeaponSystem_XMLData.cpp
108111
void RegisterXMLData();
112+
// ~CryMP
109113

110114
static void DebugGun(IConsoleCmdArgs *args = 0);
111115
static void RefGun(IConsoleCmdArgs *args = 0);
@@ -150,7 +154,9 @@ class CWeaponSystem : public ILevelSystemListener
150154
TAmmoTypeParams m_ammoparams;
151155
TProjectileMap m_projectiles;
152156

157+
TFolderList m_folders;
153158
bool m_reloading;
159+
bool m_recursing;
154160

155161
string m_config;
156162

Code/Launcher/Launcher.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,11 @@ void Launcher::PatchEngine()
11191119

11201120
void Launcher::StartEngine()
11211121
{
1122+
#ifdef SERVER_LAUNCHER
1123+
const bool oldAction = true;
1124+
#else
11221125
const bool oldAction = WinAPI::CmdLine::HasArg("-oldaction");
1126+
#endif
11231127

11241128
IGameFramework* pGameFramework = nullptr;
11251129

@@ -1195,6 +1199,13 @@ void Launcher::StartEngine()
11951199

11961200
StartupTime::Finish();
11971201
CryLogAlways("Startup finished in %.3f seconds", StartupTime::GetSeconds());
1202+
#ifdef SERVER_LAUNCHER
1203+
if (oldAction) {
1204+
CryLogAlways("[CryMP] Using old CryAction");
1205+
} else {
1206+
CryLogAlways("[CryMP] Using new CryAction");
1207+
}
1208+
#endif
11981209

11991210
gEnv->pSystem->ExecuteCommandLine();
12001211
}
@@ -1308,10 +1319,12 @@ void Launcher::Run()
13081319
throw StringTools::ErrorFormat("Invalid name of the executable!");
13091320
}
13101321

1322+
#ifdef CLIENT_LAUNCHER
13111323
if (WinAPI::CmdLine::HasArg("-mod"))
13121324
{
13131325
throw StringTools::ErrorFormat("Mods are not supported!");
13141326
}
1327+
#endif
13151328

13161329
this->InitWorkingDirectory();
13171330

0 commit comments

Comments
 (0)