Add GameData methodmap (#766)

This commit is contained in:
peace-maker
2018-10-11 20:27:56 -07:00
committed by Michael Flaherty
parent ccfd2ffe38
commit 1b795a70b0
4 changed files with 91 additions and 51 deletions
+36 -36
View File
@@ -206,9 +206,9 @@ stock MoveType GetEntityMoveType(int entity)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_MoveType", datamap, sizeof(datamap));
delete gc;
if (!exists)
{
@@ -235,9 +235,9 @@ stock void SetEntityMoveType(int entity, MoveType mt)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_MoveType", datamap, sizeof(datamap));
delete gc;
if (!exists)
{
@@ -264,9 +264,9 @@ stock RenderMode GetEntityRenderMode(int entity)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_nRenderMode", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -293,9 +293,9 @@ stock void SetEntityRenderMode(int entity, RenderMode mode)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_nRenderMode", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -322,9 +322,9 @@ stock RenderFx GetEntityRenderFx(int entity)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_nRenderFX", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -351,9 +351,9 @@ stock void SetEntityRenderFx(int entity, RenderFx fx)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_nRenderFX", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -383,9 +383,9 @@ stock void GetEntityRenderColor(int entity, int &r, int &g, int &b, int &a)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_clrRender", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -425,9 +425,9 @@ stock void SetEntityRenderColor(int entity, int r=255, int g=255, int b=255, int
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_clrRender", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -464,9 +464,9 @@ stock float GetEntityGravity(int entity)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_flGravity", datamap, sizeof(datamap));
delete gc;
if (!exists)
{
@@ -493,9 +493,9 @@ stock void SetEntityGravity(int entity, float amount)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_flGravity", datamap, sizeof(datamap));
delete gc;
if (!exists)
{
@@ -522,9 +522,9 @@ stock void SetEntityHealth(int entity, int amount)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_iHealth", prop, sizeof(prop));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_iHealth", prop, sizeof(prop));
delete gc;
if (!exists)
{
@@ -578,9 +578,9 @@ stock int GetClientButtons(int client)
if (!gotconfig)
{
Handle gc = LoadGameConfigFile("core.games");
bool exists = GameConfGetKeyValue(gc, "m_nButtons", datamap, sizeof(datamap));
CloseHandle(gc);
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_nButtons", datamap, sizeof(datamap));
delete gc;
if (!exists)
{
+34 -3
View File
@@ -84,6 +84,37 @@ enum APLRes
APLRes_SilentFailure /**< Plugin shouldn't load but do so silently */
};
methodmap GameData < Handle
{
// Loads a game config file.
//
// @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
// and the extension should be omitted.
// @return A handle to the game config file or null on failure.
public native GameData(const char[] file);
// Returns an offset value.
//
// @param key Key to retrieve from the offset section.
// @return An offset, or -1 on failure.
public native int GetOffset(const char[] key);
// Gets the value of a key from the "Keys" section.
//
// @param key Key to retrieve from the Keys section.
// @param buffer Destination string buffer.
// @param maxlen Maximum length of output string buffer.
// @return True if key existed, false otherwise.
public native bool GetKeyValue(const char[] key, char[] buffer, int maxlen);
// Finds an address calculation in a GameConfig file,
// performs LoadFromAddress on it as appropriate, then returns the final address.
//
// @param name Name of the property to find.
// @return An address calculated on success, or 0 on failure.
public native Address GetAddress(const char[] name);
};
/**
* Called when the plugin is fully initialized and all known external references
* are resolved. This is only called once in the lifetime of the plugin, and is
@@ -353,9 +384,9 @@ native void FormatTime(char[] buffer, int maxlength, const char[] format, int st
*
* @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
* and the extension should be omitted.
* @return A handle to the game config file or INVALID_HANDLE in failure.
* @return A handle to the game config file or INVALID_HANDLE on failure.
*/
native Handle LoadGameConfigFile(const char[] file);
native GameData LoadGameConfigFile(const char[] file);
/**
* Returns an offset value.
@@ -381,7 +412,7 @@ native bool GameConfGetKeyValue(Handle gc, const char[] key, char[] buffer, int
* Finds an address calculation in a GameConfig file,
* performs LoadFromAddress on it as appropriate, then returns the final address.
*
* @param gameconf GameConfig Handle, or INVALID_HANDLE to use sdktools.games.txt.
* @param gameconf Game config handle.
* @param name Name of the property to find.
* @return An address calculated on success, or 0 on failure.
*/