From 9abe6cd8f6ab9c7447f00a887785cdd63948fa34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Mon, 30 Mar 2015 03:56:26 +0200 Subject: [PATCH] Add IsPackEnded native (IsPackReadable replacement) --- amxmodx/datapacks.cpp | 14 ++++++++++++++ plugins/include/datapack.inc | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/amxmodx/datapacks.cpp b/amxmodx/datapacks.cpp index 7e1de2e6..a61ec8d1 100644 --- a/amxmodx/datapacks.cpp +++ b/amxmodx/datapacks.cpp @@ -197,6 +197,19 @@ static cell AMX_NATIVE_CALL SetPackPosition(AMX* amx, cell* params) return 1; } +static cell AMX_NATIVE_CALL IsPackEnded(AMX* amx, cell* params) +{ + CDataPack *d = g_DataPackHandles.lookup(params[1]); + + if (d == NULL) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid datapack handle provided (%d)", params[1]); + return 0; + } + + return d->IsReadable(1) ? false : true; +} + static cell AMX_NATIVE_CALL DestroyDataPack(AMX* amx, cell* params) { cell *ptr = get_amxaddr(amx, params[1]); @@ -230,6 +243,7 @@ AMX_NATIVE_INFO g_DatapackNatives[] = { "ResetPack", ResetPack }, { "GetPackPosition", GetPackPosition }, { "SetPackPosition", SetPackPosition }, + { "IsPackEnded", IsPackEnded }, { "DestroyDataPack", DestroyDataPack }, {NULL, NULL} }; diff --git a/plugins/include/datapack.inc b/plugins/include/datapack.inc index fd2743b3..1b6894fd 100644 --- a/plugins/include/datapack.inc +++ b/plugins/include/datapack.inc @@ -141,6 +141,17 @@ native GetPackPosition(DataPack:pack); */ native SetPackPosition(DataPack:pack, position); +/** + * Returns if the datapack has reached its end and no more data can be read. + * + * @param pack Datapack handle + * + * @return True if datapack has reached the end, false otherwise + * @error If an invalid handle is provided, or the new position is + * out of datapack bounds, an error will be thrown. + */ + native bool:IsPackEnded(DataPack:pack); + /** * Destroys the datapack and frees its memory. *