Skip to content

Commit d215d3a

Browse files
committed
add natives
L4D2_IsFirstMapInScenario L4D_ReplaceTank
1 parent be00a0f commit d215d3a

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

AMBuildScript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ BuildScripts = [
468468

469469
if builder.backend == 'amb2':
470470
BuildScripts += [
471-
#'scripting/AMBuilder',
471+
'scripting/AMBuilder',
472472
'PackageScript',
473473
]
474474

gamedata/left4downtown.games/engine.l4d.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
"library" "server"
124124
"linux" "@_ZN8Director18EndVersusModeRoundEb"
125125
}
126+
"GetMissionFirstMap"
127+
{
128+
"library" "server"
129+
"linux" "@_ZN16CTerrorGameRules18GetMissionFirstMapEPP9KeyValues"
130+
}
126131
}
127132
}
128133
}

gamedata/left4downtown.games/engine.l4d2.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@
138138
"library" "server"
139139
"linux" "@_ZN19CDirectorVersusMode18EndVersusModeRoundEb"
140140
}
141+
"IsFirstMapInScenario"
142+
{
143+
"library" "server"
144+
"linux" "@_ZNK9CDirector20IsFirstMapInScenarioEv"
145+
}
146+
"GetMissionFirstMap"
147+
{
148+
"library" "server"
149+
"linux" "@_ZN16CTerrorGameRules18GetMissionFirstMapEPP9KeyValues"
150+
}
141151
}
142152
}
143153
}

l4d2/natives.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@ static cell_t L4D2_ResetMobTimer(IPluginContext *pContext, const cell_t *params)
4343
return 1;
4444
}
4545

46+
/* CDirector::IsFirstMapInScenario() const */
47+
CALL_DECL_MEMBER(IsFirstMapInScenario, bool, (void));
48+
static cell_t L4D2_IsFirstMapInScenario(IPluginContext *pContext, const cell_t *params) {
49+
if (!g_pDirector)
50+
return pContext->ThrowNativeError("Error detected in native call (see error logs)");
51+
if (!CALL_JOIN_MEMBER(IsFirstMapInScenario, "IsFirstMapInScenario"))
52+
return pContext->ThrowNativeError("Error detected in native call (see error logs)");
53+
54+
return CALL_INVOKE_MEMBER(g_pDirector, IsFirstMapInScenario)();
55+
}
56+
4657
sp_nativeinfo_t g_L4D2Natives[] = {
4758
{"L4D2_GetCampaignScores", L4D2_GetCampaignScores},
4859
{"L4D2_ScavengeBeginRoundSetupTime", L4D2_ScavengeBeginRoundSetupTime},
4960
{"L4D2_GetVersusMaxCompletionScore", L4D2_GetVersusMaxCompletionScore},
5061
{"L4D2_SetVersusMaxCompletionScore", L4D2_SetVersusMaxCompletionScore},
5162
{"L4D2_ResetMobTimer", L4D2_ResetMobTimer},
63+
{"L4D2_IsFirstMapInScenario", L4D2_IsFirstMapInScenario},
5264
{nullptr, nullptr}
5365
};

scripting/include/left4downtown.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ native void L4D_TakeOverBot(int client, bool flag=true);
4343
native void L4D_TakeOverZombieBot(int client, int bot);
4444
native void L4D_ReplaceWithBot(int client, bool flag=true);
4545
native void L4D_SetHumanSpectator(int bot, int client);
46+
native void L4D_ReplaceTank(int oldTank, int newTank);
4647

4748
/***
4849
* __ __ __ ____ ___
@@ -60,6 +61,7 @@ native void L4D2_ScavengeBeginRoundSetupTime();
6061
native int L4D2_GetVersusMaxCompletionScore();
6162
native void L4D2_SetVersusMaxCompletionScore(int score);
6263
native void L4D2_ResetMobTimer();
64+
native bool L4D2_IsFirstMapInScenario();
6365

6466
/*
6567
public SharedPlugin __pl_left4downtown = {

shared/natives.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ static cell_t L4D_SetHumanSpectator(IPluginContext *pContext, const cell_t *para
173173
return CALL_INVOKE_MEMBER(pBot, SetHumanSpectator)(pPlayer);
174174
}
175175

176+
CALL_DECL_MEMBER(ReplaceTank, bool, (CTerrorPlayer *, CTerrorPlayer *))
177+
static cell_t L4D_ReplaceTank(IPluginContext *pContext, const cell_t *params) {
178+
if (!g_pZombieManager)
179+
return pContext->ThrowNativeError("Error detected in native call (see error logs)");
180+
if (!CALL_JOIN_MEMBER(ReplaceTank, "ReplaceTank"))
181+
return pContext->ThrowNativeError("Error detected in native call (see error logs)");
182+
183+
CTerrorPlayer *pOldTank = reinterpret_cast<CTerrorPlayer *>(UTIL_GetCBaseEntity(params[1], true));
184+
CTerrorPlayer *pNewTank = reinterpret_cast<CTerrorPlayer *>(UTIL_GetCBaseEntity(params[2], true));
185+
186+
if (pOldTank == nullptr)
187+
return pContext->ThrowNativeError("Invalid oldTank client index %d", params[1]);
188+
if (pNewTank == nullptr)
189+
return pContext->ThrowNativeError("Invalid newTank client index %d", params[2]);
190+
191+
return CALL_INVOKE_MEMBER(g_pZombieManager, ReplaceTank)(pOldTank, pNewTank);
192+
}
193+
176194
sp_nativeinfo_t g_SharedNatives[] = {
177195
{"L4D_SpawnTank", L4D_SpawnTank},
178196
{"L4D_SpawnWitch", L4D_SpawnWitch},
@@ -185,5 +203,14 @@ sp_nativeinfo_t g_SharedNatives[] = {
185203
{"L4D_TakeOverZombieBot", L4D_TakeOverZombieBot},
186204
{"L4D_ReplaceWithBot", L4D_ReplaceWithBot},
187205
{"L4D_SetHumanSpectator", L4D_SetHumanSpectator},
206+
// {"L4D_StaggerPlayer", L4D_StaggerPlayer},
207+
// {"L4D_GetMobSpawnTimerRemaining", L4D_GetMobSpawnTimerRemaining},
208+
// {"L4D_GetMobSpawnTimerDuration", L4D_GetMobSpawnTimerDuration},
209+
// {"L4D_GetPlayerSpawnTime", L4D_GetPlayerSpawnTime},
210+
{"L4D_ReplaceTank", L4D_ReplaceTank},
211+
// {"L4D2_SendInRescueVehicle", L4D2_SendInRescueVehicle},
212+
// {"L4D2_ChangeFinaleStage", L4D2_ChangeFinaleStage},
213+
// {"L4D2_SpawnSpecial", L4D2_SpawnSpecial},
214+
// {"L4D2_SpawnWitchBride", L4D2_SpawnWitchBride},
188215
{nullptr, nullptr}
189216
};

0 commit comments

Comments
 (0)