Skip to content

Commit c11164c

Browse files
FyrenpsychonicCopilot
authored
Add KeyValues.Merge (#2184)
* Add KeyValues.Merge * Disable for ep1 Co-authored-by: Copilot <copilot@github.com> --------- Co-authored-by: Nicholas Hastings <nshastings@gmail.com> Co-authored-by: Copilot <copilot@github.com>
1 parent 9569066 commit c11164c

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

core/smn_keyvalues.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,37 @@ static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
11131113
return 1;
11141114
}
11151115

1116+
static cell_t KeyValues_Merge(IPluginContext *pContext, const cell_t *params)
1117+
{
1118+
#if SOURCE_ENGINE == SE_EPISODEONE
1119+
return pContext->ThrowNativeError("KeyValues.Merge is not supported on this engine version");
1120+
#else
1121+
Handle_t hndl_this = static_cast<Handle_t>(params[1]);
1122+
Handle_t hndl_other = static_cast<Handle_t>(params[2]);
1123+
HandleError herr;
1124+
HandleSecurity sec;
1125+
KeyValueStack *pStk_this, *pStk_other;
1126+
1127+
sec.pOwner = NULL;
1128+
sec.pIdentity = g_pCoreIdent;
1129+
1130+
if ((herr=handlesys->ReadHandle(hndl_this, g_KeyValueType, &sec, (void **)&pStk_this))
1131+
!= HandleError_None)
1132+
{
1133+
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_this, herr);
1134+
}
1135+
if ((herr=handlesys->ReadHandle(hndl_other, g_KeyValueType, &sec, (void **)&pStk_other))
1136+
!= HandleError_None)
1137+
{
1138+
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_other, herr);
1139+
}
1140+
1141+
pStk_this->pCurRoot.front()->RecursiveMergeKeyValues(pStk_other->pCurRoot.front());
1142+
1143+
return 1;
1144+
#endif
1145+
}
1146+
11161147
static cell_t KeyValues_Import(IPluginContext *pContext, const cell_t *params)
11171148
{
11181149
// This version takes (dest, src). The original is (src, dest).
@@ -1256,6 +1287,7 @@ REGISTER_NATIVES(keyvaluenatives)
12561287
{"KeyValues.ExportToFile", smn_KeyValuesToFile},
12571288
{"KeyValues.ExportToString", smn_KeyValuesToString},
12581289
{"KeyValues.ExportLength.get", smn_KeyValuesExportLength},
1290+
{"KeyValues.Merge", KeyValues_Merge},
12591291

12601292
{NULL, NULL}
12611293
};

plugins/include/keyvalues.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ methodmap KeyValues < Handle
334334
// @param id Id of the current section.
335335
// @return True on success, false on failure.
336336
public native bool GetSectionSymbol(int &id);
337+
338+
// Merge from the current position of another KeyValues into the current
339+
// position of this one.
340+
//
341+
// @param other KeyValues Handle to merge from.
342+
// @error Invalid Handle or unsupported engine version.
343+
public native void Merge(KeyValues other);
337344
};
338345

339346
/**

0 commit comments

Comments
 (0)