Introduce a JSON module (#379)

* Add JSON module

* Merge upstream changes

Fix memory leaks

* Add json include to PackageScript

* Merge upstream changes

Fix memory leaks and increase max nesting

* Fix documentation

* Use AutoPtr in managing JSON handles

* Merge upstream changes

Order of items in an array is preserved after removing an item.

* Merge upstream

* Fix crash

* Add VS projects files and fix mixed tab/spaces

* Remove erroring on "json_free"

* Add comments to "json.inc" file

* Remove overloaded operators

* Use of "override" keyword where needed

* Fix parameter's name
This commit is contained in:
Karol Szuster
2017-09-30 20:23:12 +02:00
committed by Vincent Herbet
parent f96cb9a3b6
commit 361a6cc9e0
18 changed files with 6725 additions and 20 deletions

24
modules/json/AMBuilder Normal file
View File

@ -0,0 +1,24 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
import os.path
binary = AMXX.MetaModule(builder, 'json')
binary.compiler.defines += [
'HAVE_STDINT_H',
]
binary.compiler.cxxincludes += [
os.path.join(builder.currentSourcePath, '..', '..', 'third_party', 'parson')
]
binary.sources = [
'../../public/sdk/amxxmodule.cpp',
'../../third_party/parson/parson.c',
'JsonMngr.cpp',
'JsonNatives.cpp',
]
if builder.target_platform == 'windows':
binary.sources += ['version.rc']
AMXX.modules += [builder.Add(binary)]

708
modules/json/IJsonMngr.h Normal file
View File

@ -0,0 +1,708 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// JSON Interface
//
//#include <InterfaceSys.h>
namespace AMXX
{
/**
* @brief Lists of possible handle types.
*/
enum JSONHandleType
{
Handle_Value = 0,
Handle_Array,
Handle_Object
};
/**
* @brief Lists of possible JSON types.
*/
enum JSONType
{
JSONTypeError = -1,
JSONTypeNull = 1,
JSONTypeString = 2,
JSONTypeNumber = 3,
JSONTypeObject = 4,
JSONTypeArray = 5,
JSONTypeBoolean = 6
};
/**
* @brief Represents a Handle ID.
*/
typedef size_t JS_Handle;
/**
* @brief Provides functions for managing JSON.
*/
class IJSONMngr/* : public AMXXInterface*/
{
public:
//virtual unsigned int GetInterfaceVersion() override final { return 1; }
//virtual const char *GetInterfaceName() override final { return "IJsonMngr"; }
virtual ~IJSONMngr() {};
/**
* @brief Checks if handle with specified type is valid.
*
* @param id JSON handle
* @param type Handle's type
*
* @return True if handle is valid, false otherwise
*/
virtual bool IsValidHandle(JS_Handle id, JSONHandleType type = Handle_Value) = 0;
/**
* @brief Frees handle.
*
* @param id JSON handle
*
* @noreturn
*/
virtual void Free(JS_Handle id) = 0;
/**
* @brief Gets JSON type of passed handle.
*
* @param value JSON handle
*
* @return JSON type or JSONTypeError if error occurred
*/
virtual JSONType GetHandleJSONType(JS_Handle value) = 0;
/**
* @brief Parses JSON string or a file that contains JSON.
*
* @note Handle needs to be freed using Free().
*
* @param string String to parse
* @param handle Address to variable where value's handle will be stored
* @param is_file True to treat string param as filename, false otherwise
* @param with_comments True if parsing JSON includes comments (it will ignore them), false otherwise
*
* @return True if succeed, false otherwise
*/
virtual bool Parse(const char *string, JS_Handle *handle, bool is_file = false, bool with_comments = false) = 0;
/**
* @brief Checks if the first value is the same as the second one.
*
* @param value1 JSON handle
* @param value2 JSON handle
*
* @return True if they are the same, false otherwise
*/
virtual bool AreValuesEquals(JS_Handle value1, JS_Handle value2) = 0;
/**
* @brief Validates json by checking if object have identically named
* fields with matching types.
*
* @note Schema {"name":"", "age":0} will validate
* {"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
* but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
*
* @note In case of arrays, only first value in schema is checked against
* all values in tested array.
*
* @note Empty objects ({}) validate all objects,
* empty arrays ([]) validate all arrays,
* null validates values of every type.
*
* @param schema JSON handle
* @param value JSON handle
*
* @return True if passed value is valid, false otherwise
*/
virtual bool IsValueValid(JS_Handle schema, JS_Handle value) = 0;
/**
* @brief Checks if value has parent and assigns it to variable (if provided).
*
* @note Parent's handle needs to be freed using Free().
*
* @param value JSON handle
* @param parent Address to variable where parent's handle will be stored
*
* @return True if value has parent, false otherwise
*/
virtual bool GetValueParent(JS_Handle value, JS_Handle *parent = nullptr) = 0;
/**
* @brief Inits an empty object.
*
* @note Handle needs to be freed using Free().
*
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitObject(JS_Handle *handle) = 0;
/**
* @brief Inits an empty array.
*
* @note Handle needs to be freed using Free().
*
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitArray(JS_Handle *handle) = 0;
/**
* @brief Inits string data.
*
* @note Handle needs to be freed using Free().
*
* @param string String that the handle will be initialized with
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitString(const char *string, JS_Handle *handle) = 0;
/**
* @brief Inits a number.
*
* @note Handle needs to be freed using Free().
*
* @param number Number that the handle will be initialized with
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitNum(double number, JS_Handle *handle) = 0;
/**
* @brief Inits a boolean value.
*
* @note Handle needs to be freed using Free().
*
* @param boolean Boolean value that the handle will be initialized with
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitBool(bool boolean, JS_Handle *handle) = 0;
/**
* @brief Inits a null.
*
* @note Handle needs to be freed using Free().
*
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool InitNull(JS_Handle *handle) = 0;
/**
* @brief Creates deep copy of passed value.
*
* @note Handle needs to be freed using Free().
*
* @param value JSON handle to be copied
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool DeepCopyValue(JS_Handle value, JS_Handle *handle) = 0;
/**
* @brief Gets a string data.
*
* @param value JSON handle
*
* @return String data
*/
virtual const char *ValueToString(JS_Handle value) = 0;
/**
* @brief Gets a number.
*
* @param value JSON handle
*
* @return Number
*/
virtual double ValueToNum(JS_Handle value) = 0;
/**
* @brief Gets a boolean value.
*
* @param value JSON handle
*
* @return Boolean value
*/
virtual bool ValueToBool(JS_Handle value) = 0;
//JSON Array API
//Get functions
/**
* @brief Gets a value from the array.
*
* @note Handle needs to be freed using Free().
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayGetValue(JS_Handle array, size_t index, JS_Handle *handle) = 0;
/**
* @brief Gets string data from the array.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
*
* @return String data
*/
virtual const char *ArrayGetString(JS_Handle array, size_t index) = 0;
/**
* @brief Gets a number from the array.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
*
* @return Number
*/
virtual double ArrayGetNum(JS_Handle array, size_t index) = 0;
/**
* @brief Gets a boolean value from the array.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
*
* @return Boolean value
*/
virtual bool ArrayGetBool(JS_Handle array, size_t index) = 0;
/**
* @brief Gets count of the elements in the array.
*
* @param array JSON handle
*
* @return Number of elements in the array
*/
virtual size_t ArrayGetCount(JS_Handle array) = 0;
//Set functions
/**
* @brief Replaces an element in the array with value.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
* @param value JSON handle to set
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayReplaceValue(JS_Handle array, size_t index, JS_Handle value) = 0;
/**
* @brief Replaces an element in the array with string.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
* @param string String to copy
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayReplaceString(JS_Handle array, size_t index, const char *string) = 0;
/**
* @brief Replaces an element in the array with number.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
* @param number Number to set
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayReplaceNum(JS_Handle array, size_t index, double number) = 0;
/**
* @brief Replaces an element in the array with boolean value.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
* @param boolean Boolean value to set
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayReplaceBool(JS_Handle array, size_t index, bool boolean) = 0;
/**
* @brief Replaces an element in the array with null.
*
* @param array JSON handle
* @param index Position in the array (starting from 0)
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayReplaceNull(JS_Handle array, size_t index) = 0;
/**
* @brief Appends a value in the array.
*
* @param array JSON handle
* @param value JSON handle
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayAppendValue(JS_Handle array, JS_Handle value) = 0;
/**
* @brief Appends string data in the array.
*
* @param array JSON handle
* @param string String to copy
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayAppendString(JS_Handle array, const char *string) = 0;
/**
* @brief Appends a number in the array.
*
* @param array JSON handle
* @param string Number to set
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayAppendNum(JS_Handle array, double number) = 0;
/**
* @brief Appends a boolean value in the array.
*
* @param array JSON handle
* @param boolean Boolean value to set
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayAppendBool(JS_Handle array, bool boolean) = 0;
/**
* @brief Appends a null in the array.
*
* @param array JSON handle
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayAppendNull(JS_Handle array) = 0;
//Remove functions
/**
* @brief Removes an element from the array.
*
* @note Order of values in array may change during execution.
*
* @param array JSON handle
* @param position Position in the array (starting from 0)
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayRemove(JS_Handle array, size_t index) = 0;
/**
* @brief Removes all elements from the array.
*
* @param array JSON handle
*
* @return True if succeed, false otherwise
*/
virtual bool ArrayClear(JS_Handle array) = 0;
//Wrappers for Object API
//Get functions
/**
* @brief Gets a value from the object.
*
* @note Handle needs to be freed using Free().
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
*
* @param object JSON handle
* @param name Key name
* @param handle Address to variable where value's handle will be stored
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectGetValue(JS_Handle object, const char *name, JS_Handle *handle, bool dotfunc = false) = 0;
/**
* @brief Gets string data from the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
*
* @param object JSON handle
* @param name Key name
* @param dotfunc True to use dot notation, false to not
*
* @return String data
*/
virtual const char *ObjectGetString(JS_Handle object, const char *name, bool dotfunc = false) = 0;
/**
* @brief Gets a number from the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
*
* @param object JSON handle
* @param name Key name
* @param dotfunc True to use dot notation, false to not
*
* @return Number
*/
virtual double ObjectGetNum(JS_Handle object, const char *name, bool dotfunc = false) = 0;
/**
* @brief Gets a boolean value from the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
*
* @param object JSON handle
* @param name Key name
* @param dotfunc True to use dot notation, false to not
*
* @return Boolean value
*/
virtual bool ObjectGetBool(JS_Handle object, const char *name, bool dotfunc = false) = 0;
/**
* @brief Gets count of the keys in the object.
*
* @param object JSON handle
*
* @return Keys count
*/
virtual size_t ObjectGetCount(JS_Handle object) = 0;
/**
* @brief Gets name of the object's key.
*
* @param object JSON handle
* @param index Position from which get key name
*
* @return Key name
*/
virtual const char *ObjectGetName(JS_Handle object, size_t index) = 0;
/**
* @brief Gets a value at the specified position from the object.
*
* @note Handle needs to be freed using Free().
*
* @param object JSON handle
* @param index Position from which get key name
* @param handle Address to variable where value's handle will be stored
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectGetValueAt(JS_Handle object, size_t index, JS_Handle *handle) = 0;
/**
* @brief Checks if object has a value with a specific name and type.
*
* @param object JSON handle
* @param name Key name
* @param type Type of value, if JSONTypeError type will not be checked
* @param dotfunc True to use dot notation, false to not
*
* @return True if has, false if not
*/
virtual bool ObjectHasValue(JS_Handle object, const char *name, JSONType type = JSONTypeError, bool dotfunc = false) = 0;
//Set functions
/**
* @brief Sets a value in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
* @note It also removes the old value if any.
*
* @param object JSON handle
* @param name Key name
* @param value JSON handle
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectSetValue(JS_Handle object, const char *name, JS_Handle value, bool dotfunc = false) = 0;
/**
* @brief Sets string data in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
* @note It also removes the old value if any.
*
* @param object JSON handle
* @param name Key name
* @param string String to copy
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectSetString(JS_Handle object, const char *name, const char *string, bool dotfunc = false) = 0;
/**
* @brief Sets a number in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
* @note It also removes the old value if any.
*
* @param object JSON handle
* @param name Key name
* @param number Number to set
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectSetNum(JS_Handle object, const char *name, double number, bool dotfunc = false) = 0;
/**
* @brief Sets a boolean value in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
* @note It also removes the old value if any.
*
* @param object JSON handle
* @param name Key name
* @param boolean Boolean value to set
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectSetBool(JS_Handle object, const char *name, bool boolean, bool dotfunc = false) = 0;
/**
* @brief Sets a null in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
* @note It also removes the old value if any.
*
* @param object JSON handle
* @param name Key name
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectSetNull(JS_Handle object, const char *name, bool dotfunc = false) = 0;
//Remove functions
/**
* @brief Removes a key and its value in the object.
*
* @note If dot notation is used some values may be inaccessible
* because valid names in JSON can contain dots.
*
* @param object JSON handle
* @param name Key name
* @param dotfunc True to use dot notation, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectRemove(JS_Handle object, const char *name, bool dotfunc = false) = 0;
/**
* @brief Removes all keys and their values in the object.
*
* @param object JSON handle
*
* @return True if succeed, false otherwise
*/
virtual bool ObjectClear(JS_Handle object) = 0;
//Serialization API
/**
* @brief Gets size of serialization.
*
* @param value JSON handle
* @param pretty True to count size for pretty format, false to not
*
* @return Size of serialized string
*/
virtual size_t SerialSize(JS_Handle value, bool pretty) = 0;
/**
* @brief Copies serialized string to the buffer.
*
* @note The buffer must be large enough or function will
* fail.
*
* @param value JSON handle
* @param buffer Buffer to copy string to
* @param size Size of the buffer
* @param pretty True to format pretty JSON string, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool SerialToBuffer(JS_Handle value, char *buffer, size_t size, bool pretty) = 0;
/**
* @brief Copies serialized string to the file.
*
* @param value JSON handle
* @param filepath Path to the file
* @param pretty True to format pretty JSON string, false to not
*
* @return True if succeed, false otherwise
*/
virtual bool SerialToFile(JS_Handle value, const char *filepath, bool pretty) = 0;
/**
* @brief Returns serialized string.
*
* @note Must be freed using FreeString().
*
* @param value JSON handle
* @param pretty True to format pretty JSON string, false to not
*
* @return Serialized string, nullptr if failed
*/
virtual char *SerialToString(JS_Handle value, bool pretty) = 0;
/**
* @brief Frees serialized string.
*
* @param string Pointer to serialized string
*
* @noreturn
*/
virtual void FreeString(char *string) = 0;
};
}

467
modules/json/JsonMngr.cpp Normal file
View File

@ -0,0 +1,467 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// JSON Class
//
#include "JsonMngr.h"
JSONMngr::~JSONMngr()
{
for (auto &i : m_Handles)
{
if (i)
{
_FreeHandle(i);
}
}
}
JS_Handle JSONMngr::_MakeHandle(void *value, JSONHandleType type, bool must_be_freed)
{
JS_Handle id;
if (!m_OldHandles.empty())
{
id = m_OldHandles.popFrontCopy();
m_Handles[id] = ke::AutoPtr<JSONHandle>(new JSONHandle);
}
else
{
m_Handles.append(ke::AutoPtr<JSONHandle>(new JSONHandle));
id = m_Handles.length() - 1;
}
switch (type)
{
case Handle_Value:
{
auto getHandleType = [this](JSON_Value *jsvalue, JS_Handle id)
{
if (!(m_Handles[id]->m_pArray = json_value_get_array(jsvalue)))
{
m_Handles[id]->m_pObject = json_value_get_object(jsvalue);
}
};
auto JSValue = m_Handles[id]->m_pValue = static_cast<JSON_Value *>(value);
getHandleType(JSValue, id);
break;
}
case Handle_Array:
{
auto JSArray = m_Handles[id]->m_pArray = static_cast<JSON_Array *>(value);
m_Handles[id]->m_pValue = json_array_get_wrapping_value(JSArray);
break;
}
case Handle_Object:
{
auto JSObject = m_Handles[id]->m_pObject = static_cast<JSON_Object *>(value);
m_Handles[id]->m_pValue = json_object_get_wrapping_value(JSObject);
break;
}
}
m_Handles[id]->m_bMustBeFreed = must_be_freed;
return id;
}
void JSONMngr::_FreeHandle(ke::AutoPtr<JSONHandle> &ptr)
{
if (ptr->m_bMustBeFreed && ptr->m_pValue)
{
json_value_free(ptr->m_pValue);
}
}
void JSONMngr::Free(JS_Handle id)
{
auto handle = ke::Move(m_Handles[id]);
if (!handle)
{
return;
}
_FreeHandle(handle);
m_OldHandles.append(id);
}
bool JSONMngr::IsValidHandle(JS_Handle handle, JSONHandleType type)
{
if (handle >= m_Handles.length() || !m_Handles[handle])
{
return false;
}
switch (type)
{
case Handle_Array: return m_Handles[handle]->m_pArray != nullptr;
case Handle_Object: return m_Handles[handle]->m_pObject != nullptr;
default: return true;
}
}
bool JSONMngr::GetValueParent(JS_Handle value, JS_Handle *parent)
{
auto JSParent = json_value_get_parent(m_Handles[value]->m_pValue);
if (!JSParent)
{
return false;
}
if (parent)
{
*parent = _MakeHandle(JSParent, Handle_Value);
}
return true;
}
bool JSONMngr::InitObject(JS_Handle *handle)
{
auto JSObject = json_value_get_object(json_value_init_object());
if (!JSObject)
{
return false;
}
*handle = _MakeHandle(JSObject, Handle_Object, true);
return true;
}
bool JSONMngr::InitArray(JS_Handle *handle)
{
auto JSArray = json_value_get_array(json_value_init_array());
if (!JSArray)
{
return false;
}
*handle = _MakeHandle(JSArray, Handle_Array, true);
return true;
}
bool JSONMngr::InitString(const char *string, JS_Handle *handle)
{
auto JSValue = json_value_init_string(string);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
bool JSONMngr::InitNum(double number, JS_Handle *handle)
{
auto JSValue = json_value_init_number(number);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
bool JSONMngr::InitBool(bool boolean, JS_Handle *handle)
{
auto JSValue = json_value_init_boolean(boolean);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
bool JSONMngr::InitNull(JS_Handle *handle)
{
auto JSValue = json_value_init_null();
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
bool JSONMngr::Parse(const char *string, JS_Handle *handle, bool is_file, bool with_comments)
{
auto jsonFunc = (!with_comments) ? json_parse_string : json_parse_string_with_comments;
if (is_file)
{
jsonFunc = (!with_comments) ? json_parse_file : json_parse_file_with_comments;
}
auto JSValue = jsonFunc(string);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
bool JSONMngr::DeepCopyValue(JS_Handle value, JS_Handle *handle)
{
auto JSValue = json_value_deep_copy(m_Handles[value]->m_pValue);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value, true);
return true;
}
const char *JSONMngr::ValueToString(JS_Handle value)
{
auto string = json_value_get_string(m_Handles[value]->m_pValue);
return (string) ? string : "";
}
bool JSONMngr::ArrayGetValue(JS_Handle array, size_t index, JS_Handle *handle)
{
auto JSValue = json_array_get_value(m_Handles[array]->m_pArray, index);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value);
return true;
}
const char *JSONMngr::ArrayGetString(JS_Handle array, size_t index)
{
auto string = json_array_get_string(m_Handles[array]->m_pArray, index);
return (string) ? string : "";
}
bool JSONMngr::ArrayReplaceValue(JS_Handle array, size_t index, JS_Handle value)
{
auto JSValue = m_Handles[value]->m_pValue;
//We cannot assign the same value to the different arrays or objects
//So if value is already assigned somewhere else let's create a copy of it
if (json_value_get_parent(JSValue))
{
JSValue = json_value_deep_copy(JSValue);
}
else
{
//Parson will take care of freeing child values
m_Handles[value]->m_bMustBeFreed = false;
}
return json_array_replace_value(m_Handles[array]->m_pArray, index, JSValue) == JSONSuccess;
}
bool JSONMngr::ArrayAppendValue(JS_Handle array, JS_Handle value)
{
auto JSValue = m_Handles[value]->m_pValue;
//We cannot assign the same value to the different arrays or objects
//So if value is already assigned somewhere else let's create a copy of it
if (json_value_get_parent(JSValue))
{
JSValue = json_value_deep_copy(JSValue);
}
else
{
//Parson will take care of freeing child values
m_Handles[value]->m_bMustBeFreed = false;
}
return json_array_append_value(m_Handles[array]->m_pArray, JSValue) == JSONSuccess;
}
bool JSONMngr::ObjectGetValue(JS_Handle object, const char *name, JS_Handle *handle, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSValue = (!dotfunc) ? json_object_get_value(JSObject, name) :
json_object_dotget_value(JSObject, name);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value);
return true;
}
const char *JSONMngr::ObjectGetString(JS_Handle object, const char *name, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto string = (!dotfunc) ? json_object_get_string(JSObject, name) :
json_object_dotget_string(JSObject, name);
return (string) ? string : "";
}
double JSONMngr::ObjectGetNum(JS_Handle object, const char *name, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
return (!dotfunc) ? json_object_get_number(JSObject, name) :
json_object_dotget_number(JSObject, name);
}
bool JSONMngr::ObjectGetBool(JS_Handle object, const char *name, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto result = (!dotfunc) ? json_object_get_boolean(JSObject, name) :
json_object_dotget_boolean(JSObject, name);
return result == 1;
}
const char *JSONMngr::ObjectGetName(JS_Handle object, size_t index)
{
auto string = json_object_get_name(m_Handles[object]->m_pObject, index);
return (string) ? string : "";
}
bool JSONMngr::ObjectGetValueAt(JS_Handle object, size_t index, JS_Handle *handle)
{
auto JSValue = json_object_get_value_at(m_Handles[object]->m_pObject, index);
if (!JSValue)
{
return false;
}
*handle = _MakeHandle(JSValue, Handle_Value);
return true;
}
bool JSONMngr::ObjectHasValue(JS_Handle object, const char *name, JSONType type, bool dotfunc)
{
int result;
auto JSObject = m_Handles[object]->m_pObject;
if (type == JSONTypeError)
{
result = (!dotfunc) ? json_object_has_value(JSObject, name) :
json_object_dothas_value(JSObject, name);
}
else
{
result = (!dotfunc) ? json_object_has_value_of_type(JSObject, name, type) :
json_object_dothas_value_of_type(JSObject, name, type);
}
return result == 1;
}
bool JSONMngr::ObjectSetValue(JS_Handle object, const char *name, JS_Handle value, bool dotfunc)
{
auto JSValue = m_Handles[value]->m_pValue;
//We cannot assign the same value to the different arrays or objects
//So if value is already assigned somewhere else let's create a copy of it
if (json_value_get_parent(JSValue))
{
JSValue = json_value_deep_copy(JSValue);
}
else
{
//Parson will take care of freeing child values
m_Handles[value]->m_bMustBeFreed = false;
}
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_set_value(JSObject, name, JSValue) :
json_object_dotset_value(JSObject, name, JSValue);
return JSResult == JSONSuccess;
}
bool JSONMngr::ObjectSetString(JS_Handle object, const char *name, const char *string, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_set_string(JSObject, name, string) :
json_object_dotset_string(JSObject, name, string);
return JSResult == JSONSuccess;
}
bool JSONMngr::ObjectSetNum(JS_Handle object, const char *name, double number, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_set_number(JSObject, name, number) :
json_object_dotset_number(JSObject, name, number);
return JSResult == JSONSuccess;
}
bool JSONMngr::ObjectSetBool(JS_Handle object, const char *name, bool boolean, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_set_boolean(JSObject, name, boolean) :
json_object_dotset_boolean(JSObject, name, boolean);
return JSResult == JSONSuccess;
}
bool JSONMngr::ObjectSetNull(JS_Handle object, const char *name, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_set_null(JSObject, name) :
json_object_dotset_null(JSObject, name);
return JSResult == JSONSuccess;
}
bool JSONMngr::ObjectRemove(JS_Handle object, const char *name, bool dotfunc)
{
auto JSObject = m_Handles[object]->m_pObject;
auto JSResult = (!dotfunc) ? json_object_remove(JSObject, name) :
json_object_dotremove(JSObject, name);
return JSResult == JSONSuccess;
}
size_t JSONMngr::SerialSize(JS_Handle value, bool pretty)
{
auto JSValue = m_Handles[value]->m_pValue;
return (!pretty) ? json_serialization_size(JSValue) :
json_serialization_size_pretty(JSValue);
}
bool JSONMngr::SerialToBuffer(JS_Handle value, char *buffer, size_t size, bool pretty)
{
auto JSValue = m_Handles[value]->m_pValue;
auto JSResult = (!pretty) ? json_serialize_to_buffer(JSValue, buffer, size) :
json_serialize_to_buffer_pretty(JSValue, buffer, size);
return JSResult == JSONSuccess;
}
bool JSONMngr::SerialToFile(JS_Handle value, const char *filepath, bool pretty)
{
auto JSValue = m_Handles[value]->m_pValue;
auto JSResult = (!pretty) ? json_serialize_to_file(JSValue, filepath) :
json_serialize_to_file_pretty(JSValue, filepath);
return JSResult == JSONSuccess;
}
char *JSONMngr::SerialToString(JS_Handle value, bool pretty)
{
auto JSValue = m_Handles[value]->m_pValue;
auto result = (!pretty) ? json_serialize_to_string(JSValue) :
json_serialize_to_string_pretty(JSValue);
return (result) ? result : nullptr;
}

196
modules/json/JsonMngr.h Normal file
View File

@ -0,0 +1,196 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// JSON Class
//
#include <amxxmodule.h>
#include <parson.h>
#include <amtl/am-vector.h>
#include <amtl/am-autoptr.h>
#include <amtl/am-uniqueptr.h>
#include <amtl/am-deque.h>
#include "IJsonMngr.h"
using namespace AMXX;
class JSONMngr : public IJSONMngr
{
public:
JSONMngr() = default;
virtual ~JSONMngr();
// Handles
bool IsValidHandle(JS_Handle id, JSONHandleType type = Handle_Value) override;
void Free(JS_Handle id) override;
inline JSONType GetHandleJSONType(JS_Handle value) override
{
return static_cast<JSONType>(json_value_get_type(m_Handles[value]->m_pValue));
}
// Parsing
bool Parse(const char *string, JS_Handle *handle, bool is_file, bool with_comments) override;
// Comapring
inline bool AreValuesEquals(JS_Handle value1, JS_Handle value2) override
{
// to avoid ms compiler warning
return json_value_equals(m_Handles[value1]->m_pValue, m_Handles[value2]->m_pValue) == 1;
}
// Validating
inline bool IsValueValid(JS_Handle schema, JS_Handle value) override
{
return json_validate(m_Handles[schema]->m_pValue, m_Handles[value]->m_pValue) == JSONSuccess;
}
// Accessing parent value
bool GetValueParent(JS_Handle value, JS_Handle *parent) override;
// Init functions
bool InitObject(JS_Handle *handle) override;
bool InitArray(JS_Handle *handle) override;
bool InitString(const char *string, JS_Handle *handle) override;
bool InitNum(double number, JS_Handle *handle) override;
bool InitBool(bool boolean, JS_Handle *handle) override;
bool InitNull(JS_Handle *handle) override;
// Copying
bool DeepCopyValue(JS_Handle value, JS_Handle *handle) override;
// Convert functions
const char *ValueToString(JS_Handle value) override;
inline double ValueToNum(JS_Handle value) override
{
return json_value_get_number(m_Handles[value]->m_pValue);
}
inline bool ValueToBool(JS_Handle value) override
{
return json_value_get_boolean(m_Handles[value]->m_pValue) == 1;
}
// Wrappers for Array API
bool ArrayGetValue(JS_Handle array, size_t index, JS_Handle *handle) override;
const char *ArrayGetString(JS_Handle array, size_t index) override;
inline bool ArrayGetBool(JS_Handle array, size_t index) override
{
return json_array_get_boolean(m_Handles[array]->m_pArray, index) == 1;
}
bool ArrayReplaceValue(JS_Handle array, size_t index, JS_Handle value) override;
bool ArrayAppendValue(JS_Handle array, JS_Handle value) override;
inline double ArrayGetNum(JS_Handle array, size_t index) override
{
return json_array_get_number(m_Handles[array]->m_pArray, index);
}
inline size_t ArrayGetCount(JS_Handle array) override
{
return json_array_get_count(m_Handles[array]->m_pArray);
}
inline bool ArrayReplaceString(JS_Handle array, size_t index, const char *string) override
{
return json_array_replace_string(m_Handles[array]->m_pArray, index, string) == JSONSuccess;
}
inline bool ArrayReplaceNum(JS_Handle array, size_t index, double number) override
{
return json_array_replace_number(m_Handles[array]->m_pArray, index, number) == JSONSuccess;
}
inline bool ArrayReplaceBool(JS_Handle array, size_t index, bool boolean) override
{
return json_array_replace_boolean(m_Handles[array]->m_pArray, index, boolean) == JSONSuccess;
}
inline bool ArrayReplaceNull(JS_Handle array, size_t index) override
{
return json_array_replace_null(m_Handles[array]->m_pArray, index) == JSONSuccess;
}
inline bool ArrayAppendString(JS_Handle array, const char *string) override
{
return json_array_append_string(m_Handles[array]->m_pArray, string) == JSONSuccess;
}
inline bool ArrayAppendNum(JS_Handle array, double number) override
{
return json_array_append_number(m_Handles[array]->m_pArray, number) == JSONSuccess;
}
inline bool ArrayAppendBool(JS_Handle array, bool boolean) override
{
return json_array_append_boolean(m_Handles[array]->m_pArray, boolean) == JSONSuccess;
}
inline bool ArrayAppendNull(JS_Handle array) override
{
return json_array_append_null(m_Handles[array]->m_pArray) == JSONSuccess;
}
inline bool ArrayRemove(JS_Handle array, size_t index) override
{
return json_array_remove(m_Handles[array]->m_pArray, index) == JSONSuccess;
}
inline bool ArrayClear(JS_Handle array) override
{
return json_array_clear(m_Handles[array]->m_pArray) == JSONSuccess;
}
// Wrappers for Object API
// Get functions
bool ObjectGetValue(JS_Handle object, const char *name, JS_Handle *handle, bool dotfunc) override;
const char *ObjectGetString(JS_Handle object, const char *name, bool dotfunc) override;
double ObjectGetNum(JS_Handle object, const char *name, bool dotfunc) override;
bool ObjectGetBool(JS_Handle object, const char *name, bool dotfunc) override;
inline size_t ObjectGetCount(JS_Handle object) override
{
return json_object_get_count(m_Handles[object]->m_pObject);
}
const char *ObjectGetName(JS_Handle object, size_t index) override;
bool ObjectGetValueAt(JS_Handle object, size_t index, JS_Handle *handle) override;
bool ObjectHasValue(JS_Handle object, const char *name, JSONType type, bool dotfunc) override;
// Set functions
bool ObjectSetValue(JS_Handle object, const char *name, JS_Handle value, bool dotfunc) override;
bool ObjectSetString(JS_Handle object, const char *name, const char *string, bool dotfunc) override;
bool ObjectSetNum(JS_Handle object, const char *name, double number, bool dotfunc) override;
bool ObjectSetBool(JS_Handle object, const char *name, bool boolean, bool dotfunc) override;
bool ObjectSetNull(JS_Handle object, const char *name, bool dotfunc) override;
// Remove functions
bool ObjectRemove(JS_Handle object, const char *name, bool dotfunc) override;
inline bool ObjectClear(JS_Handle object) override
{
return json_object_clear(m_Handles[object]->m_pObject) == JSONSuccess;
}
// Serialization API
size_t SerialSize(JS_Handle value, bool pretty) override;
bool SerialToBuffer(JS_Handle value, char *buffer, size_t size, bool pretty) override;
bool SerialToFile(JS_Handle value, const char *filepath, bool pretty) override;
char *SerialToString(JS_Handle value, bool pretty) override;
inline void FreeString(char *string) override
{
json_free_serialized_string(string);
}
private:
struct JSONHandle
{
JSON_Value *m_pValue; //Store an pointer to a value
JSON_Array *m_pArray; //Store an pointer to an array
JSON_Object *m_pObject; //Store an pointer to an object
bool m_bMustBeFreed; //Must be freed using json_value_free()?
};
JS_Handle _MakeHandle(void *value, JSONHandleType type, bool must_be_freed = false);
void _FreeHandle(ke::AutoPtr<JSONHandle> &ptr);
ke::Vector<ke::AutoPtr<JSONHandle>> m_Handles;
ke::Deque<JS_Handle> m_OldHandles;
};
extern ke::UniquePtr<JSONMngr> JsonMngr;

View File

@ -0,0 +1,937 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// JSON Natives
//
#include "JsonMngr.h"
ke::UniquePtr<JSONMngr> JsonMngr;
//native JSON:json_parse(const string[], bool:is_file = false, bool:with_comments = false);
static cell AMX_NATIVE_CALL amxx_json_parse(AMX *amx, cell *params)
{
int len;
auto string = MF_GetAmxString(amx, params[1], 0, &len);
auto is_file = params[2] != 0;
if (is_file)
{
char path[256];
string = MF_BuildPathnameR(path, sizeof(path), "%s", string);
}
JS_Handle handle;
auto result = JsonMngr->Parse(string, &handle, is_file, params[3] != 0);
return (result) ? handle : -1;
}
//native bool:json_equals(const JSON:value1, const JSON:value2);
static cell AMX_NATIVE_CALL amxx_json_equals(AMX *amx, cell *params)
{
auto value1 = params[1], value2 = params[2];
//For check against Invalid_JSON
if (value1 == -1 || value2 == -1)
{
return value1 == value2;
}
if (!JsonMngr->IsValidHandle(value1))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value1);
return 0;
}
if (!JsonMngr->IsValidHandle(value2))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value2);
return 0;
}
return JsonMngr->AreValuesEquals(value1, value2);
}
//native bool:json_validate(const JSON:schema, const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_validate(AMX *amx, cell *params)
{
auto schema = params[1], value = params[2];
if (!JsonMngr->IsValidHandle(schema))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON schema! %d", schema);
return 0;
}
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
return JsonMngr->IsValueValid(schema, value);
}
//native JSON:json_get_parent(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_get_parent(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return -1;
}
JS_Handle parent;
auto result = JsonMngr->GetValueParent(value, &parent);
return (result) ? parent : -1;
}
//native JSONType:json_get_type(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_get_type(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return static_cast<cell>(JSONTypeError);
}
return JsonMngr->GetHandleJSONType(value);
}
//native JSON:json_init_object();
static cell AMX_NATIVE_CALL amxx_json_init_object(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitObject(&handle);
return (result) ? handle : -1;
}
//native JSON:json_init_array();
static cell AMX_NATIVE_CALL amxx_json_init_array(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitArray(&handle);
return (result) ? handle : -1;
}
//native JSON:json_init_string(const value[]);
static cell AMX_NATIVE_CALL amxx_json_init_string(AMX *amx, cell *params)
{
int len;
JS_Handle handle;
auto result = JsonMngr->InitString(MF_GetAmxString(amx, params[1], 0, &len), &handle);
return (result) ? handle : -1;
}
//native JSON:json_init_number(value);
static cell AMX_NATIVE_CALL amxx_json_init_number(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitNum(params[1], &handle);
return (result) ? handle : -1;
}
//native JSON:json_init_real(Float:value);
static cell AMX_NATIVE_CALL amxx_json_init_real(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitNum(amx_ctof(params[1]), &handle);
return (result) ? handle : -1;
}
//native JSON:json_init_bool(bool:value);
static cell AMX_NATIVE_CALL amxx_json_init_bool(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitBool(params[1] != 0, &handle);
return (result) ? handle : -1;
}
//native JSON:json_init_null();
static cell AMX_NATIVE_CALL amxx_json_init_null(AMX *amx, cell *params)
{
JS_Handle handle;
auto result = JsonMngr->InitNull(&handle);
return (result) ? handle : -1;
}
//native JSON:json_deep_copy(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_deep_copy(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return -1;
}
JS_Handle clonedHandle;
auto result = JsonMngr->DeepCopyValue(value, &clonedHandle);
return (result) ? clonedHandle : -1;
}
//native bool:json_free(&JSON:value);
static cell AMX_NATIVE_CALL amxx_json_free(AMX *amx, cell *params)
{
auto value = MF_GetAmxAddr(amx, params[1]);
if (!JsonMngr->IsValidHandle(*value))
{
return 0;
}
JsonMngr->Free(*value);
*value = -1;
return 1;
}
//native json_get_string(const JSON:value, buffer[], maxlen);
static cell AMX_NATIVE_CALL amxx_json_get_string(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
auto string = JsonMngr->ValueToString(value);
return MF_SetAmxStringUTF8Char(amx, params[2], string, strlen(string), params[3]);
}
//native json_get_number(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_get_number(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
return static_cast<cell>(JsonMngr->ValueToNum(value));
}
//native Float:json_get_real(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_get_real(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
auto result = static_cast<float>(JsonMngr->ValueToNum(value));
return amx_ftoc(result);
}
//native bool:json_get_bool(const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_get_bool(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
return JsonMngr->ValueToBool(value);
}
//native JSON:json_array_get_value(const JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_get_value(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return -1;
}
JS_Handle handle;
auto result = JsonMngr->ArrayGetValue(array, params[2], &handle);
return (result) ? handle : -1;
}
//native json_array_get_string(const JSON:array, index, buffer[], maxlen);
static cell AMX_NATIVE_CALL amxx_json_array_get_string(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
auto string = JsonMngr->ArrayGetString(array, params[2]);
return MF_SetAmxStringUTF8Char(amx, params[3], string, strlen(string), params[4]);
}
//native json_array_get_number(const JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_get_number(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return static_cast<cell>(JsonMngr->ArrayGetNum(array, params[2]));
}
//native Float:json_array_get_real(const JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_get_real(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
auto result = static_cast<float>(JsonMngr->ArrayGetNum(array, params[2]));
return amx_ftoc(result);
}
//native bool:json_array_get_bool(const JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_get_bool(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayGetBool(array, params[2]);
}
//native json_array_get_count(const JSON:array);
static cell AMX_NATIVE_CALL amxx_json_array_get_count(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayGetCount(array);
}
//native bool:json_array_replace_value(JSON:array, index, const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_array_replace_value(AMX *amx, cell *params)
{
auto array = params[1], value = params[3];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
return JsonMngr->ArrayReplaceValue(array, params[2], value);
}
//native bool:json_array_replace_string(JSON:array, index, const string[]);
static cell AMX_NATIVE_CALL amxx_json_array_replace_string(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
int len;
auto string = MF_GetAmxString(amx, params[3], 0, &len);
return JsonMngr->ArrayReplaceString(array, params[2], string);
}
//native bool:json_array_replace_number(JSON:array, index, number);
static cell AMX_NATIVE_CALL amxx_json_array_replace_number(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayReplaceNum(array, params[2], params[3]);
}
//native bool:json_array_replace_real(JSON:array, index, Float:number);
static cell AMX_NATIVE_CALL amxx_json_array_replace_real(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayReplaceNum(array, params[2], amx_ctof(params[3]));
}
//native bool:json_array_replace_bool(JSON:array, index, bool:boolean);
static cell AMX_NATIVE_CALL amxx_json_array_replace_bool(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayReplaceBool(array, params[2], params[3] != 0);
}
//native bool:json_array_replace_null(JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_replace_null(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayReplaceNull(array, params[2]);
}
//native bool:json_array_append_value(JSON:array, const JSON:value);
static cell AMX_NATIVE_CALL amxx_json_array_append_value(AMX *amx, cell *params)
{
auto array = params[1], value = params[2];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
return JsonMngr->ArrayAppendValue(array, value);
}
//native bool:json_array_append_string(JSON:array, const string[]);
static cell AMX_NATIVE_CALL amxx_json_array_append_string(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
int len;
return JsonMngr->ArrayAppendString(array, MF_GetAmxString(amx, params[2], 0, &len));
}
//native bool:json_array_append_number(JSON:array, number);
static cell AMX_NATIVE_CALL amxx_json_array_append_number(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayAppendNum(array, params[2]);
}
//native bool:json_array_append_real(JSON:array, Float:number);
static cell AMX_NATIVE_CALL amxx_json_array_append_real(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayAppendNum(array, amx_ctof(params[2]));
}
//native bool:json_array_append_bool(JSON:array, bool:boolean);
static cell AMX_NATIVE_CALL amxx_json_array_append_bool(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayAppendBool(array, params[2] != 0);
}
//native bool:json_array_append_null(JSON:array);
static cell AMX_NATIVE_CALL amxx_json_array_append_null(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayAppendNull(array);
}
//native bool:json_array_remove(JSON:array, index);
static cell AMX_NATIVE_CALL amxx_json_array_remove(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayRemove(array, params[2]);
}
//native bool:json_array_clear(JSON:array);
static cell AMX_NATIVE_CALL amxx_json_array_clear(AMX *amx, cell *params)
{
auto array = params[1];
if (!JsonMngr->IsValidHandle(array, Handle_Array))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON array! %d", array);
return 0;
}
return JsonMngr->ArrayClear(array);
}
//native JSON:json_object_get_value(const JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_get_value(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return -1;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
JS_Handle handle;
auto result = JsonMngr->ObjectGetValue(object, name, &handle, params[3] != 0);
return (result) ? handle : -1;
}
//native json_object_get_string(const JSON:object, const name[], buffer[], maxlen, bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_get_string(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
auto string = JsonMngr->ObjectGetString(object, name, params[5] != 0);
return MF_SetAmxStringUTF8Char(amx, params[3], string, strlen(string), params[4]);
}
//native json_object_get_number(const JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_get_number(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return static_cast<cell>(JsonMngr->ObjectGetNum(object, name, params[3] != 0));
}
//native Float:json_object_get_real(const JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_get_real(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
auto result = static_cast<float>(JsonMngr->ObjectGetNum(object, name, params[3] != 0));
return amx_ftoc(result);
}
//native bool:json_object_get_bool(const JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_get_bool(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectGetBool(object, name, params[3] != 0);
}
//native json_object_get_count(const JSON:object);
static cell AMX_NATIVE_CALL amxx_json_object_get_count(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
return JsonMngr->ObjectGetCount(object);
}
//native json_object_get_name(const JSON:object, index, buffer[], maxlen);
static cell AMX_NATIVE_CALL amxx_json_object_get_name(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
auto name = JsonMngr->ObjectGetName(object, params[2]);
return MF_SetAmxStringUTF8Char(amx, params[3], name, strlen(name), params[4]);
}
//native JSON:amxx_json_object_get_value_at(const JSON:object, index);
static cell AMX_NATIVE_CALL amxx_json_object_get_value_at(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return -1;
}
JS_Handle valueHandle;
auto result = JsonMngr->ObjectGetValueAt(object, params[2], &valueHandle);
return (result) ? valueHandle : -1;
}
//native bool:json_object_has_value(const JSON:object, const name[], JSONType:type = JSONError, bool:dot_not = false);
static cell AMX_NATIVE_CALL amxx_json_object_has_value(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectHasValue(object, name, static_cast<JSONType>(params[3]), params[4] != 0);
}
//native bool:json_object_set_value(JSON:object, const name[], JSON:value, bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_value(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectSetValue(object, name, params[3], params[4] != 0);
}
//native bool:json_object_set_string(JSON:object, const name[], const string[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_string(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
auto string = MF_GetAmxString(amx, params[3], 1, &len);
return JsonMngr->ObjectSetString(object, name, string, params[4] != 0);
}
//native bool:json_object_set_number(JSON:object, const name[], number, bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_number(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectSetNum(object, name, params[3], params[4] != 0);
}
//native bool:json_object_set_real(JSON:object, const name[], Float:number, bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_real(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectSetNum(object, name, amx_ctof(params[3]), params[4] != 0);
}
//native bool:json_object_set_bool(JSON:object, const name[], bool:boolean, bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_bool(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectSetBool(object, name, params[3] != 0, params[4] != 0);
}
//native bool:json_object_set_null(JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_set_null(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectSetNull(object, name, params[3] != 0);
}
//native bool:json_object_remove(JSON:object, const name[], bool:dotfunc = false);
static cell AMX_NATIVE_CALL amxx_json_object_remove(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
int len;
auto name = MF_GetAmxString(amx, params[2], 0, &len);
return JsonMngr->ObjectRemove(object, name, params[3] != 0);
}
//native bool:json_object_clear(JSON:object);
static cell AMX_NATIVE_CALL amxx_json_object_clear(AMX *amx, cell *params)
{
auto object = params[1];
if (!JsonMngr->IsValidHandle(object, Handle_Object))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON object! %d", object);
return 0;
}
return JsonMngr->ObjectClear(object);
}
//native json_serial_size(const JSON:value, bool:pretty = false, bool:with_null_byte = false);
static cell AMX_NATIVE_CALL amxx_json_serial_size(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
auto size = JsonMngr->SerialSize(value, params[2] != 0);
return (params[3]) ? size : size - 1;
}
//native json_serial_to_string(const JSON:value, buffer[], maxlen, bool:pretty = false);
static cell AMX_NATIVE_CALL amxx_json_serial_to_string(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
auto result = JsonMngr->SerialToString(value, params[4] != 0);
auto written = (result) ? MF_SetAmxStringUTF8Char(amx, params[2], result, strlen(result), params[3]) : 0;
JsonMngr->FreeString(result);
return written;
}
//native bool:json_serial_to_file(const JSON:value, const file[], bool:pretty = false);
static cell AMX_NATIVE_CALL amxx_json_serial_to_file(AMX *amx, cell *params)
{
auto value = params[1];
if (!JsonMngr->IsValidHandle(value))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid JSON value! %d", value);
return 0;
}
int len;
auto file = MF_GetAmxString(amx, params[2], 0, &len);
char path[256];
MF_BuildPathnameR(path, sizeof(path), "%s", file);
return JsonMngr->SerialToFile(value, path, params[3] != 0);
}
AMX_NATIVE_INFO JsonNatives[] =
{
{ "json_parse", amxx_json_parse },
{ "json_equals", amxx_json_equals },
{ "json_validate", amxx_json_validate },
{ "json_get_parent", amxx_json_get_parent },
{ "json_get_type", amxx_json_get_type },
{ "json_init_object", amxx_json_init_object },
{ "json_init_array", amxx_json_init_array },
{ "json_init_string", amxx_json_init_string },
{ "json_init_number", amxx_json_init_number },
{ "json_init_real", amxx_json_init_real },
{ "json_init_bool", amxx_json_init_bool },
{ "json_init_null", amxx_json_init_null },
{ "json_deep_copy", amxx_json_deep_copy },
{ "json_free", amxx_json_free },
{ "json_get_string", amxx_json_get_string },
{ "json_get_number", amxx_json_get_number },
{ "json_get_real", amxx_json_get_real },
{ "json_get_bool", amxx_json_get_bool },
{ "json_array_get_value", amxx_json_array_get_value },
{ "json_array_get_string", amxx_json_array_get_string },
{ "json_array_get_count", amxx_json_array_get_count },
{ "json_array_get_number", amxx_json_array_get_number },
{ "json_array_get_real", amxx_json_array_get_real },
{ "json_array_get_bool", amxx_json_array_get_bool },
{ "json_array_replace_value", amxx_json_array_replace_value },
{ "json_array_replace_string", amxx_json_array_replace_string },
{ "json_array_replace_number", amxx_json_array_replace_number },
{ "json_array_replace_real", amxx_json_array_replace_real },
{ "json_array_replace_bool", amxx_json_array_replace_bool },
{ "json_array_replace_null", amxx_json_array_replace_null },
{ "json_array_append_value", amxx_json_array_append_value },
{ "json_array_append_string", amxx_json_array_append_string },
{ "json_array_append_number", amxx_json_array_append_number },
{ "json_array_append_real", amxx_json_array_append_real },
{ "json_array_append_bool", amxx_json_array_append_bool },
{ "json_array_append_null", amxx_json_array_append_null },
{ "json_array_remove", amxx_json_array_remove },
{ "json_array_clear", amxx_json_array_clear },
{ "json_object_get_value", amxx_json_object_get_value },
{ "json_object_get_string", amxx_json_object_get_string },
{ "json_object_get_number", amxx_json_object_get_number },
{ "json_object_get_real", amxx_json_object_get_real },
{ "json_object_get_bool", amxx_json_object_get_bool },
{ "json_object_get_count", amxx_json_object_get_count },
{ "json_object_get_name", amxx_json_object_get_name },
{ "json_object_get_value_at", amxx_json_object_get_value_at },
{ "json_object_has_value", amxx_json_object_has_value },
{ "json_object_set_value", amxx_json_object_set_value },
{ "json_object_set_string", amxx_json_object_set_string },
{ "json_object_set_number", amxx_json_object_set_number },
{ "json_object_set_real", amxx_json_object_set_real },
{ "json_object_set_bool", amxx_json_object_set_bool },
{ "json_object_set_null", amxx_json_object_set_null },
{ "json_object_remove", amxx_json_object_remove },
{ "json_object_clear", amxx_json_object_clear },
{ "json_serial_size", amxx_json_serial_size },
{ "json_serial_to_string", amxx_json_serial_to_string },
{ "json_serial_to_file", amxx_json_serial_to_file },
{ nullptr, nullptr }
};
void OnAmxxAttach()
{
JsonMngr = ke::MakeUnique<JSONMngr>();
MF_AddNatives(JsonNatives);
//MF_AddInterface(JsonMngr.get());
}

515
modules/json/moduleconfig.h Normal file
View File

@ -0,0 +1,515 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
//
// Module Config
//
#ifndef __MODULECONFIG_H__
#define __MODULECONFIG_H__
#include <amxmodx_version.h>
// Module info
#define MODULE_NAME "JSON"
#define MODULE_VERSION AMXX_VERSION
#define MODULE_AUTHOR "AMX Mod X Dev Team"
#define MODULE_URL "http://www.amxmodx.org"
#define MODULE_LOGTAG "JSON"
#define MODULE_LIBRARY "json"
#define MODULE_LIBCLASS ""
// If you want the module not to be reloaded on mapchange, remove / comment out the next line
#define MODULE_RELOAD_ON_MAPCHANGE
#ifdef __DATE__
#define MODULE_DATE __DATE__
#else // __DATE__
#define MODULE_DATE "Unknown"
#endif // __DATE__
/**
* Add here any modules you want your module to depend on
* Terminate with a null pointer
*/
/*const char * const MODULE_DEPENDENCIES[] =
{
nullptr
};*/
// metamod plugin?
// #define USE_METAMOD
// use memory manager/tester?
// note that if you use this, you cannot construct/allocate
// anything before the module attached (OnAmxxAttach).
// be careful of default constructors using new/malloc!
// #define MEMORY_TEST
// Unless you use STL or exceptions, keep this commented.
// It allows you to compile without libstdc++.so as a dependency
// #define NO_ALLOC_OVERRIDES
// Uncomment this if you are using MSVC8 or greater and want to fix some of the compatibility issues yourself
// #define NO_MSVC8_AUTO_COMPAT
/**
* AMXX Init functions
* Also consider using FN_META_*
*/
/** AMXX query */
//#define FN_AMXX_QUERY OnAmxxQuery
/** AMXX attach
* Do native functions init here (MF_AddNatives)
*/
#define FN_AMXX_ATTACH OnAmxxAttach
/** AMXX Detach (unload) */
// #define FN_AMXX_DETACH OnAmxxDetach
/** All plugins loaded
* Do forward functions init here (MF_RegisterForward)
*/
// #define FN_AMXX_PLUGINSLOADED OnPluginsLoaded
/** All plugins are about to be unloaded */
//#define FN_AMXX_PLUGINSUNLOADING OnPluginsUnloading
/** All plugins are now unloaded */
//#define FN_AMXX_PLUGINSUNLOADED OnPluginsUnloaded
/**** METAMOD ****/
// If your module doesn't use metamod, you may close the file now :)
#ifdef USE_METAMOD
// ----
// Hook Functions
// Uncomment these to be called
// You can also change the function name
// - Metamod init functions
// Also consider using FN_AMXX_*
// Meta query
//#define FN_META_QUERY OnMetaQuery
// Meta attach
//#define FN_META_ATTACH OnMetaAttach
// Meta dettach
//#define FN_META_DETACH OnMetaDetach
// (wd) are Will Day's notes
// - GetEntityAPI2 functions
// #define FN_GameDLLInit GameDLLInit /* pfnGameInit() */
// #define FN_DispatchSpawn DispatchSpawn /* pfnSpawn() */
// #define FN_DispatchThink DispatchThink /* pfnThink() */
// #define FN_DispatchUse DispatchUse /* pfnUse() */
// #define FN_DispatchTouch DispatchTouch /* pfnTouch() */
// #define FN_DispatchBlocked DispatchBlocked /* pfnBlocked() */
// #define FN_DispatchKeyValue DispatchKeyValue /* pfnKeyValue() */
// #define FN_DispatchSave DispatchSave /* pfnSave() */
// #define FN_DispatchRestore DispatchRestore /* pfnRestore() */
// #define FN_DispatchObjectCollsionBox DispatchObjectCollsionBox /* pfnSetAbsBox() */
// #define FN_SaveWriteFields SaveWriteFields /* pfnSaveWriteFields() */
// #define FN_SaveReadFields SaveReadFields /* pfnSaveReadFields() */
// #define FN_SaveGlobalState SaveGlobalState /* pfnSaveGlobalState() */
// #define FN_RestoreGlobalState RestoreGlobalState /* pfnRestoreGlobalState() */
// #define FN_ResetGlobalState ResetGlobalState /* pfnResetGlobalState() */
// #define FN_ClientConnect ClientConnect /* pfnClientConnect() (wd) Client has connected */
// #define FN_ClientDisconnect ClientDisconnect /* pfnClientDisconnect() (wd) Player has left the game */
// #define FN_ClientKill ClientKill /* pfnClientKill() (wd) Player has typed "kill" */
// #define FN_ClientPutInServer ClientPutInServer /* pfnClientPutInServer() (wd) Client is entering the game */
// #define FN_ClientCommand ClientCommand /* pfnClientCommand() (wd) Player has sent a command (typed or from a bind) */
// #define FN_ClientUserInfoChanged ClientUserInfoChanged /* pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure */
// #define FN_ServerActivate ServerActivate /* pfnServerActivate() (wd) Server is starting a new map */
// #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */
// #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */
// #define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */
// #define FN_StartFrame StartFrame /* pfnStartFrame() */
// #define FN_ParmsNewLevel ParmsNewLevel /* pfnParmsNewLevel() */
// #define FN_ParmsChangeLevel ParmsChangeLevel /* pfnParmsChangeLevel() */
// #define FN_GetGameDescription GetGameDescription /* pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2" "Half-Life" */
// #define FN_PlayerCustomization PlayerCustomization /* pfnPlayerCustomization() Notifies .dll of new customization for player. */
// #define FN_SpectatorConnect SpectatorConnect /* pfnSpectatorConnect() Called when spectator joins server */
// #define FN_SpectatorDisconnect SpectatorDisconnect /* pfnSpectatorDisconnect() Called when spectator leaves the server */
// #define FN_SpectatorThink SpectatorThink /* pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t) */
// #define FN_Sys_Error Sys_Error /* pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2 */
// #define FN_PM_Move PM_Move /* pfnPM_Move() (wd) SDK2 */
// #define FN_PM_Init PM_Init /* pfnPM_Init() Server version of player movement initialization; (wd) SDK2 */
// #define FN_PM_FindTextureType PM_FindTextureType /* pfnPM_FindTextureType() (wd) SDK2 */
// #define FN_SetupVisibility SetupVisibility /* pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2 */
// #define FN_UpdateClientData UpdateClientData /* pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2 */
// #define FN_AddToFullPack AddToFullPack /* pfnAddToFullPack() (wd) SDK2 */
// #define FN_CreateBaseline CreateBaseline /* pfnCreateBaseline() Tweak entity baseline for network encoding allows setup of player baselines too.; (wd) SDK2 */
// #define FN_RegisterEncoders RegisterEncoders /* pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2 */
// #define FN_GetWeaponData GetWeaponData /* pfnGetWeaponData() (wd) SDK2 */
// #define FN_CmdStart CmdStart /* pfnCmdStart() (wd) SDK2 */
// #define FN_CmdEnd CmdEnd /* pfnCmdEnd() (wd) SDK2 */
// #define FN_ConnectionlessPacket ConnectionlessPacket /* pfnConnectionlessPacket() (wd) SDK2 */
// #define FN_GetHullBounds GetHullBounds /* pfnGetHullBounds() (wd) SDK2 */
// #define FN_CreateInstancedBaselines CreateInstancedBaselines /* pfnCreateInstancedBaselines() (wd) SDK2 */
// #define FN_InconsistentFile InconsistentFile /* pfnInconsistentFile() (wd) SDK2 */
// #define FN_AllowLagCompensation AllowLagCompensation /* pfnAllowLagCompensation() (wd) SDK2 */
// - GetEntityAPI2_Post functions
// #define FN_GameDLLInit_Post GameDLLInit_Post
// #define FN_DispatchSpawn_Post DispatchSpawn_Post
// #define FN_DispatchThink_Post DispatchThink_Post
// #define FN_DispatchUse_Post DispatchUse_Post
// #define FN_DispatchTouch_Post DispatchTouch_Post
// #define FN_DispatchBlocked_Post DispatchBlocked_Post
// #define FN_DispatchKeyValue_Post DispatchKeyValue_Post
// #define FN_DispatchSave_Post DispatchSave_Post
// #define FN_DispatchRestore_Post DispatchRestore_Post
// #define FN_DispatchObjectCollsionBox_Post DispatchObjectCollsionBox_Post
// #define FN_SaveWriteFields_Post SaveWriteFields_Post
// #define FN_SaveReadFields_Post SaveReadFields_Post
// #define FN_SaveGlobalState_Post SaveGlobalState_Post
// #define FN_RestoreGlobalState_Post RestoreGlobalState_Post
// #define FN_ResetGlobalState_Post ResetGlobalState_Post
// #define FN_ClientConnect_Post ClientConnect_Post
// #define FN_ClientDisconnect_Post ClientDisconnect_Post
// #define FN_ClientKill_Post ClientKill_Post
// #define FN_ClientPutInServer_Post ClientPutInServer_Post
// #define FN_ClientCommand_Post ClientCommand_Post
// #define FN_ClientUserInfoChanged_Post ClientUserInfoChanged_Post
// #define FN_ServerActivate_Post ServerActivate_Post
// #define FN_ServerDeactivate_Post ServerDeactivate_Post
// #define FN_PlayerPreThink_Post PlayerPreThink_Post
// #define FN_PlayerPostThink_Post PlayerPostThink_Post
// #define FN_StartFrame_Post StartFrame_Post
// #define FN_ParmsNewLevel_Post ParmsNewLevel_Post
// #define FN_ParmsChangeLevel_Post ParmsChangeLevel_Post
// #define FN_GetGameDescription_Post GetGameDescription_Post
// #define FN_PlayerCustomization_Post PlayerCustomization_Post
// #define FN_SpectatorConnect_Post SpectatorConnect_Post
// #define FN_SpectatorDisconnect_Post SpectatorDisconnect_Post
// #define FN_SpectatorThink_Post SpectatorThink_Post
// #define FN_Sys_Error_Post Sys_Error_Post
// #define FN_PM_Move_Post PM_Move_Post
// #define FN_PM_Init_Post PM_Init_Post
// #define FN_PM_FindTextureType_Post PM_FindTextureType_Post
// #define FN_SetupVisibility_Post SetupVisibility_Post
// #define FN_UpdateClientData_Post UpdateClientData_Post
// #define FN_AddToFullPack_Post AddToFullPack_Post
// #define FN_CreateBaseline_Post CreateBaseline_Post
// #define FN_RegisterEncoders_Post RegisterEncoders_Post
// #define FN_GetWeaponData_Post GetWeaponData_Post
// #define FN_CmdStart_Post CmdStart_Post
// #define FN_CmdEnd_Post CmdEnd_Post
// #define FN_ConnectionlessPacket_Post ConnectionlessPacket_Post
// #define FN_GetHullBounds_Post GetHullBounds_Post
// #define FN_CreateInstancedBaselines_Post CreateInstancedBaselines_Post
// #define FN_InconsistentFile_Post InconsistentFile_Post
// #define FN_AllowLagCompensation_Post AllowLagCompensation_Post
// - GetEngineAPI functions
// #define FN_PrecacheModel PrecacheModel
// #define FN_PrecacheSound PrecacheSound
// #define FN_SetModel SetModel
// #define FN_ModelIndex ModelIndex
// #define FN_ModelFrames ModelFrames
// #define FN_SetSize SetSize
// #define FN_ChangeLevel ChangeLevel
// #define FN_GetSpawnParms GetSpawnParms
// #define FN_SaveSpawnParms SaveSpawnParms
// #define FN_VecToYaw VecToYaw
// #define FN_VecToAngles VecToAngles
// #define FN_MoveToOrigin MoveToOrigin
// #define FN_ChangeYaw ChangeYaw
// #define FN_ChangePitch ChangePitch
// #define FN_FindEntityByString FindEntityByString
// #define FN_GetEntityIllum GetEntityIllum
// #define FN_FindEntityInSphere FindEntityInSphere
// #define FN_FindClientInPVS FindClientInPVS
// #define FN_EntitiesInPVS EntitiesInPVS
// #define FN_MakeVectors MakeVectors
// #define FN_AngleVectors AngleVectors
// #define FN_CreateEntity CreateEntity
// #define FN_RemoveEntity RemoveEntity
// #define FN_CreateNamedEntity CreateNamedEntity
// #define FN_MakeStatic MakeStatic
// #define FN_EntIsOnFloor EntIsOnFloor
// #define FN_DropToFloor DropToFloor
// #define FN_WalkMove WalkMove
// #define FN_SetOrigin SetOrigin
// #define FN_EmitSound EmitSound
// #define FN_EmitAmbientSound EmitAmbientSound
// #define FN_TraceLine TraceLine
// #define FN_TraceToss TraceToss
// #define FN_TraceMonsterHull TraceMonsterHull
// #define FN_TraceHull TraceHull
// #define FN_TraceModel TraceModel
// #define FN_TraceTexture TraceTexture
// #define FN_TraceSphere TraceSphere
// #define FN_GetAimVector GetAimVector
// #define FN_ServerCommand ServerCommand
// #define FN_ServerExecute ServerExecute
// #define FN_engClientCommand engClientCommand
// #define FN_ParticleEffect ParticleEffect
// #define FN_LightStyle LightStyle
// #define FN_DecalIndex DecalIndex
// #define FN_PointContents PointContents
// #define FN_MessageBegin MessageBegin
// #define FN_MessageEnd MessageEnd
// #define FN_WriteByte WriteByte
// #define FN_WriteChar WriteChar
// #define FN_WriteShort WriteShort
// #define FN_WriteLong WriteLong
// #define FN_WriteAngle WriteAngle
// #define FN_WriteCoord WriteCoord
// #define FN_WriteString WriteString
// #define FN_WriteEntity WriteEntity
// #define FN_CVarRegister CVarRegister
// #define FN_CVarGetFloat CVarGetFloat
// #define FN_CVarGetString CVarGetString
// #define FN_CVarSetFloat CVarSetFloat
// #define FN_CVarSetString CVarSetString
// #define FN_AlertMessage AlertMessage
// #define FN_EngineFprintf EngineFprintf
// #define FN_PvAllocEntPrivateData PvAllocEntPrivateData
// #define FN_PvEntPrivateData PvEntPrivateData
// #define FN_FreeEntPrivateData FreeEntPrivateData
// #define FN_SzFromIndex SzFromIndex
// #define FN_AllocString AllocString
// #define FN_GetVarsOfEnt GetVarsOfEnt
// #define FN_PEntityOfEntOffset PEntityOfEntOffset
// #define FN_EntOffsetOfPEntity EntOffsetOfPEntity
// #define FN_IndexOfEdict IndexOfEdict
// #define FN_PEntityOfEntIndex PEntityOfEntIndex
// #define FN_FindEntityByVars FindEntityByVars
// #define FN_GetModelPtr GetModelPtr
// #define FN_RegUserMsg RegUserMsg
// #define FN_AnimationAutomove AnimationAutomove
// #define FN_GetBonePosition GetBonePosition
// #define FN_FunctionFromName FunctionFromName
// #define FN_NameForFunction NameForFunction
// #define FN_ClientPrintf ClientPrintf
// #define FN_ServerPrint ServerPrint
// #define FN_Cmd_Args Cmd_Args
// #define FN_Cmd_Argv Cmd_Argv
// #define FN_Cmd_Argc Cmd_Argc
// #define FN_GetAttachment GetAttachment
// #define FN_CRC32_Init CRC32_Init
// #define FN_CRC32_ProcessBuffer CRC32_ProcessBuffer
// #define FN_CRC32_ProcessByte CRC32_ProcessByte
// #define FN_CRC32_Final CRC32_Final
// #define FN_RandomLong RandomLong
// #define FN_RandomFloat RandomFloat
// #define FN_SetView SetView
// #define FN_Time Time
// #define FN_CrosshairAngle CrosshairAngle
// #define FN_LoadFileForMe LoadFileForMe
// #define FN_FreeFile FreeFile
// #define FN_EndSection EndSection
// #define FN_CompareFileTime CompareFileTime
// #define FN_GetGameDir GetGameDir
// #define FN_Cvar_RegisterVariable Cvar_RegisterVariable
// #define FN_FadeClientVolume FadeClientVolume
// #define FN_SetClientMaxspeed SetClientMaxspeed
// #define FN_CreateFakeClient CreateFakeClient
// #define FN_RunPlayerMove RunPlayerMove
// #define FN_NumberOfEntities NumberOfEntities
// #define FN_GetInfoKeyBuffer GetInfoKeyBuffer
// #define FN_InfoKeyValue InfoKeyValue
// #define FN_SetKeyValue SetKeyValue
// #define FN_SetClientKeyValue SetClientKeyValue
// #define FN_IsMapValid IsMapValid
// #define FN_StaticDecal StaticDecal
// #define FN_PrecacheGeneric PrecacheGeneric
// #define FN_GetPlayerUserId GetPlayerUserId
// #define FN_BuildSoundMsg BuildSoundMsg
// #define FN_IsDedicatedServer IsDedicatedServer
// #define FN_CVarGetPointer CVarGetPointer
// #define FN_GetPlayerWONId GetPlayerWONId
// #define FN_Info_RemoveKey Info_RemoveKey
// #define FN_GetPhysicsKeyValue GetPhysicsKeyValue
// #define FN_SetPhysicsKeyValue SetPhysicsKeyValue
// #define FN_GetPhysicsInfoString GetPhysicsInfoString
// #define FN_PrecacheEvent PrecacheEvent
// #define FN_PlaybackEvent PlaybackEvent
// #define FN_SetFatPVS SetFatPVS
// #define FN_SetFatPAS SetFatPAS
// #define FN_CheckVisibility CheckVisibility
// #define FN_DeltaSetField DeltaSetField
// #define FN_DeltaUnsetField DeltaUnsetField
// #define FN_DeltaAddEncoder DeltaAddEncoder
// #define FN_GetCurrentPlayer GetCurrentPlayer
// #define FN_CanSkipPlayer CanSkipPlayer
// #define FN_DeltaFindField DeltaFindField
// #define FN_DeltaSetFieldByIndex DeltaSetFieldByIndex
// #define FN_DeltaUnsetFieldByIndex DeltaUnsetFieldByIndex
// #define FN_SetGroupMask SetGroupMask
// #define FN_engCreateInstancedBaseline engCreateInstancedBaseline
// #define FN_Cvar_DirectSet Cvar_DirectSet
// #define FN_ForceUnmodified ForceUnmodified
// #define FN_GetPlayerStats GetPlayerStats
// #define FN_AddServerCommand AddServerCommand
// #define FN_Voice_GetClientListening Voice_GetClientListening
// #define FN_Voice_SetClientListening Voice_SetClientListening
// #define FN_GetPlayerAuthId GetPlayerAuthId
// - GetEngineAPI_Post functions
// #define FN_PrecacheModel_Post PrecacheModel_Post
// #define FN_PrecacheSound_Post PrecacheSound_Post
// #define FN_SetModel_Post SetModel_Post
// #define FN_ModelIndex_Post ModelIndex_Post
// #define FN_ModelFrames_Post ModelFrames_Post
// #define FN_SetSize_Post SetSize_Post
// #define FN_ChangeLevel_Post ChangeLevel_Post
// #define FN_GetSpawnParms_Post GetSpawnParms_Post
// #define FN_SaveSpawnParms_Post SaveSpawnParms_Post
// #define FN_VecToYaw_Post VecToYaw_Post
// #define FN_VecToAngles_Post VecToAngles_Post
// #define FN_MoveToOrigin_Post MoveToOrigin_Post
// #define FN_ChangeYaw_Post ChangeYaw_Post
// #define FN_ChangePitch_Post ChangePitch_Post
// #define FN_FindEntityByString_Post FindEntityByString_Post
// #define FN_GetEntityIllum_Post GetEntityIllum_Post
// #define FN_FindEntityInSphere_Post FindEntityInSphere_Post
// #define FN_FindClientInPVS_Post FindClientInPVS_Post
// #define FN_EntitiesInPVS_Post EntitiesInPVS_Post
// #define FN_MakeVectors_Post MakeVectors_Post
// #define FN_AngleVectors_Post AngleVectors_Post
// #define FN_CreateEntity_Post CreateEntity_Post
// #define FN_RemoveEntity_Post RemoveEntity_Post
// #define FN_CreateNamedEntity_Post CreateNamedEntity_Post
// #define FN_MakeStatic_Post MakeStatic_Post
// #define FN_EntIsOnFloor_Post EntIsOnFloor_Post
// #define FN_DropToFloor_Post DropToFloor_Post
// #define FN_WalkMove_Post WalkMove_Post
// #define FN_SetOrigin_Post SetOrigin_Post
// #define FN_EmitSound_Post EmitSound_Post
// #define FN_EmitAmbientSound_Post EmitAmbientSound_Post
// #define FN_TraceLine_Post TraceLine_Post
// #define FN_TraceToss_Post TraceToss_Post
// #define FN_TraceMonsterHull_Post TraceMonsterHull_Post
// #define FN_TraceHull_Post TraceHull_Post
// #define FN_TraceModel_Post TraceModel_Post
// #define FN_TraceTexture_Post TraceTexture_Post
// #define FN_TraceSphere_Post TraceSphere_Post
// #define FN_GetAimVector_Post GetAimVector_Post
// #define FN_ServerCommand_Post ServerCommand_Post
// #define FN_ServerExecute_Post ServerExecute_Post
// #define FN_engClientCommand_Post engClientCommand_Post
// #define FN_ParticleEffect_Post ParticleEffect_Post
// #define FN_LightStyle_Post LightStyle_Post
// #define FN_DecalIndex_Post DecalIndex_Post
// #define FN_PointContents_Post PointContents_Post
// #define FN_MessageBegin_Post MessageBegin_Post
// #define FN_MessageEnd_Post MessageEnd_Post
// #define FN_WriteByte_Post WriteByte_Post
// #define FN_WriteChar_Post WriteChar_Post
// #define FN_WriteShort_Post WriteShort_Post
// #define FN_WriteLong_Post WriteLong_Post
// #define FN_WriteAngle_Post WriteAngle_Post
// #define FN_WriteCoord_Post WriteCoord_Post
// #define FN_WriteString_Post WriteString_Post
// #define FN_WriteEntity_Post WriteEntity_Post
// #define FN_CVarRegister_Post CVarRegister_Post
// #define FN_CVarGetFloat_Post CVarGetFloat_Post
// #define FN_CVarGetString_Post CVarGetString_Post
// #define FN_CVarSetFloat_Post CVarSetFloat_Post
// #define FN_CVarSetString_Post CVarSetString_Post
// #define FN_AlertMessage_Post AlertMessage_Post
// #define FN_EngineFprintf_Post EngineFprintf_Post
// #define FN_PvAllocEntPrivateData_Post PvAllocEntPrivateData_Post
// #define FN_PvEntPrivateData_Post PvEntPrivateData_Post
// #define FN_FreeEntPrivateData_Post FreeEntPrivateData_Post
// #define FN_SzFromIndex_Post SzFromIndex_Post
// #define FN_AllocString_Post AllocString_Post
// #define FN_GetVarsOfEnt_Post GetVarsOfEnt_Post
// #define FN_PEntityOfEntOffset_Post PEntityOfEntOffset_Post
// #define FN_EntOffsetOfPEntity_Post EntOffsetOfPEntity_Post
// #define FN_IndexOfEdict_Post IndexOfEdict_Post
// #define FN_PEntityOfEntIndex_Post PEntityOfEntIndex_Post
// #define FN_FindEntityByVars_Post FindEntityByVars_Post
// #define FN_GetModelPtr_Post GetModelPtr_Post
// #define FN_RegUserMsg_Post RegUserMsg_Post
// #define FN_AnimationAutomove_Post AnimationAutomove_Post
// #define FN_GetBonePosition_Post GetBonePosition_Post
// #define FN_FunctionFromName_Post FunctionFromName_Post
// #define FN_NameForFunction_Post NameForFunction_Post
// #define FN_ClientPrintf_Post ClientPrintf_Post
// #define FN_ServerPrint_Post ServerPrint_Post
// #define FN_Cmd_Args_Post Cmd_Args_Post
// #define FN_Cmd_Argv_Post Cmd_Argv_Post
// #define FN_Cmd_Argc_Post Cmd_Argc_Post
// #define FN_GetAttachment_Post GetAttachment_Post
// #define FN_CRC32_Init_Post CRC32_Init_Post
// #define FN_CRC32_ProcessBuffer_Post CRC32_ProcessBuffer_Post
// #define FN_CRC32_ProcessByte_Post CRC32_ProcessByte_Post
// #define FN_CRC32_Final_Post CRC32_Final_Post
// #define FN_RandomLong_Post RandomLong_Post
// #define FN_RandomFloat_Post RandomFloat_Post
// #define FN_SetView_Post SetView_Post
// #define FN_Time_Post Time_Post
// #define FN_CrosshairAngle_Post CrosshairAngle_Post
// #define FN_LoadFileForMe_Post LoadFileForMe_Post
// #define FN_FreeFile_Post FreeFile_Post
// #define FN_EndSection_Post EndSection_Post
// #define FN_CompareFileTime_Post CompareFileTime_Post
// #define FN_GetGameDir_Post GetGameDir_Post
// #define FN_Cvar_RegisterVariable_Post Cvar_RegisterVariable_Post
// #define FN_FadeClientVolume_Post FadeClientVolume_Post
// #define FN_SetClientMaxspeed_Post SetClientMaxspeed_Post
// #define FN_CreateFakeClient_Post CreateFakeClient_Post
// #define FN_RunPlayerMove_Post RunPlayerMove_Post
// #define FN_NumberOfEntities_Post NumberOfEntities_Post
// #define FN_GetInfoKeyBuffer_Post GetInfoKeyBuffer_Post
// #define FN_InfoKeyValue_Post InfoKeyValue_Post
// #define FN_SetKeyValue_Post SetKeyValue_Post
// #define FN_SetClientKeyValue_Post SetClientKeyValue_Post
// #define FN_IsMapValid_Post IsMapValid_Post
// #define FN_StaticDecal_Post StaticDecal_Post
// #define FN_PrecacheGeneric_Post PrecacheGeneric_Post
// #define FN_GetPlayerUserId_Post GetPlayerUserId_Post
// #define FN_BuildSoundMsg_Post BuildSoundMsg_Post
// #define FN_IsDedicatedServer_Post IsDedicatedServer_Post
// #define FN_CVarGetPointer_Post CVarGetPointer_Post
// #define FN_GetPlayerWONId_Post GetPlayerWONId_Post
// #define FN_Info_RemoveKey_Post Info_RemoveKey_Post
// #define FN_GetPhysicsKeyValue_Post GetPhysicsKeyValue_Post
// #define FN_SetPhysicsKeyValue_Post SetPhysicsKeyValue_Post
// #define FN_GetPhysicsInfoString_Post GetPhysicsInfoString_Post
// #define FN_PrecacheEvent_Post PrecacheEvent_Post
// #define FN_PlaybackEvent_Post PlaybackEvent_Post
// #define FN_SetFatPVS_Post SetFatPVS_Post
// #define FN_SetFatPAS_Post SetFatPAS_Post
// #define FN_CheckVisibility_Post CheckVisibility_Post
// #define FN_DeltaSetField_Post DeltaSetField_Post
// #define FN_DeltaUnsetField_Post DeltaUnsetField_Post
// #define FN_DeltaAddEncoder_Post DeltaAddEncoder_Post
// #define FN_GetCurrentPlayer_Post GetCurrentPlayer_Post
// #define FN_CanSkipPlayer_Post CanSkipPlayer_Post
// #define FN_DeltaFindField_Post DeltaFindField_Post
// #define FN_DeltaSetFieldByIndex_Post DeltaSetFieldByIndex_Post
// #define FN_DeltaUnsetFieldByIndex_Post DeltaUnsetFieldByIndex_Post
// #define FN_SetGroupMask_Post SetGroupMask_Post
// #define FN_engCreateInstancedBaseline_Post engCreateInstancedBaseline_Post
// #define FN_Cvar_DirectSet_Post Cvar_DirectSet_Post
// #define FN_ForceUnmodified_Post ForceUnmodified_Post
// #define FN_GetPlayerStats_Post GetPlayerStats_Post
// #define FN_AddServerCommand_Post AddServerCommand_Post
// #define FN_Voice_GetClientListening_Post Voice_GetClientListening_Post
// #define FN_Voice_SetClientListening_Post Voice_SetClientListening_Post
// #define FN_GetPlayerAuthId_Post GetPlayerAuthId_Post
// #define FN_OnFreeEntPrivateData OnFreeEntPrivateData
// #define FN_GameShutdown GameShutdown
// #define FN_ShouldCollide ShouldCollide
// #define FN_OnFreeEntPrivateData_Post OnFreeEntPrivateData_Post
// #define FN_GameShutdown_Post GameShutdown_Post
// #define FN_ShouldCollide_Post ShouldCollide_Post
#endif // USE_METAMOD
#endif // __MODULECONFIG_H__

View File

@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json", "json.vcxproj", "{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}.Debug|Win32.ActiveCfg = Debug|Win32
{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}.Debug|Win32.Build.0 = Debug|Win32
{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}.Release|Win32.ActiveCfg = Release|Win32
{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89382960-2F97-4398-AE0F-812780760B7E}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4CF9D220-F318-4D1C-81DF-E2377A2D8FFE}</ProjectGuid>
<RootNamespace>json</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)_amxx</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectName)_amxx</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk;..\..\..\public\amtl;..\..\..\third_party;..\..\..\third_party\parson;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;DEBUG;_WINDOWS;_USRDLL;JSON_EXPORTS;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)json.pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(OutDir)json.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<IgnoreSpecificDefaultLibraries>LIBCMT;</IgnoreSpecificDefaultLibraries>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk;..\..\..\public\amtl;..\..\..\third_party;..\..\..\third_party\parson;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;JSON_EXPORTS;HAVE_STDINT_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<ImportLibrary>$(OutDir)json.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuildStep Include="pev.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" />
<ClCompile Include="..\..\..\third_party\parson\parson.c" />
<ClCompile Include="..\JsonMngr.cpp" />
<ClCompile Include="..\JsonNatives.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h" />
<ClInclude Include="..\..\..\third_party\parson\parson.h" />
<ClInclude Include="..\IJsonMngr.h" />
<ClInclude Include="..\JsonMngr.h" />
<ClInclude Include="..\moduleconfig.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\plugins\include\json.inc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{959a9831-eb53-4faa-b073-dad6790bc123}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{72ab2480-daa0-43cc-9fe5-5710998b27b0}</UniqueIdentifier>
</Filter>
<Filter Include="Module SDK">
<UniqueIdentifier>{c1f7d9b4-ea37-4980-b17f-f4ff55cb1990}</UniqueIdentifier>
</Filter>
<Filter Include="Module SDK\SDK Base">
<UniqueIdentifier>{259f5990-1378-4291-9f8e-d6e0ad89173a}</UniqueIdentifier>
</Filter>
<Filter Include="Third Party">
<UniqueIdentifier>{ad24e0a6-afc1-4eb3-9c2d-2aaac86aa36c}</UniqueIdentifier>
</Filter>
<Filter Include="Third Party\Parson">
<UniqueIdentifier>{dc99c702-9fc8-4e8c-ba44-959a066cdbe2}</UniqueIdentifier>
</Filter>
<Filter Include="Pawn Includes">
<UniqueIdentifier>{aaebd544-6579-4a7e-9c6b-2ccc3c0280be}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\JsonMngr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\JsonNatives.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp">
<Filter>Module SDK\SDK Base</Filter>
</ClCompile>
<ClCompile Include="..\..\..\third_party\parson\parson.c">
<Filter>Third Party\Parson</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\IJsonMngr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\JsonMngr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\moduleconfig.h">
<Filter>Module SDK</Filter>
</ClInclude>
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h">
<Filter>Module SDK\SDK Base</Filter>
</ClInclude>
<ClInclude Include="..\..\..\third_party\parson\parson.h">
<Filter>Third Party\Parson</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\plugins\include\json.inc">
<Filter>Pawn Includes</Filter>
</None>
</ItemGroup>
</Project>

101
modules/json/version.rc Normal file
View File

@ -0,0 +1,101 @@
// Microsoft Visual C++ generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <winresrc.h>
#include <moduleconfig.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION AMXX_VERSION_FILE
PRODUCTVERSION AMXX_VERSION_FILE
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "Comments", "AMX Mod X"
VALUE "FileDescription", "AMX Mod X"
VALUE "FileVersion", AMXX_VERSION
VALUE "InternalName", MODULE_LIBRARY
VALUE "LegalCopyright", "Copyright (c) AMX Mod X Dev Team"
VALUE "OriginalFilename", MODULE_LIBRARY "_amxx.dll"
VALUE "ProductName", MODULE_NAME
VALUE "ProductVersion", AMXX_VERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED