Added Struct Abstraction extension (bug 2666 and bug 2663)

--HG--
rename : extensions/structs/structs.txt => gamedata/structs.gamedata.txt
rename : extensions/structs/structs.inc => plugins/include/structs.inc
rename : extensions/structs/structtest.sp => plugins/testsuite/structtest.sp
This commit is contained in:
Matt Woodrow
2008-09-18 15:32:22 +12:00
parent 8680d07e0a
commit 5687a7ba90
4 changed files with 9 additions and 0 deletions
-178
View File
@@ -1,178 +0,0 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _structs_included
#endinput
#endif
#define _structs_included
/**
* Struct Gamedata Notes:
*
* Types: Sizes:
* int/int* 1/2/4
* float/float* Not required
* char/char* Length of char array
* Vector/Vector* Not required
* ent/ent* Not required
*/
/**
* Retrieves an integer value from a struct.
*
* @param strct Struct Handle.
* @param member Member name to retrieve.
* @return Integer value.
* @error Undefined member, or member type mismatch.
*/
native GetStructInt(Handle:strct, const String:member[]);
/**
* Sets an integer value in a struct.
*
* @param strct Struct Handle.
* @param member Member name to set.
* @param value Value to set.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native SetStructInt(Handle:strct, const String:member[], value);
/**
* Retrieves a float value from a struct.
*
* @param strct Struct Handle.
* @param member Member name to retrieve.
* @return Float value.
* @error Undefined member, or member type mismatch.
*/
native Float:GetStructFloat(Handle:strct, const String:member[]);
/**
* Sets a float value in a struct.
*
* @param strct Struct Handle.
* @param member Member name to set.
* @param value Value to set.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native SetStructFloat(Handle:strct, const String:member[], Float:value);
/**
* Retrieves an integer value from a struct.
*
* @param strct Struct Handle.
* @param member Member name to retrieve.
* @param vec Buffer for the retrieved vector.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native GetStructVector(Handle:strct, const String:member[], Float:vec[3]);
/**
* Sets a Vector value in a struct.
*
* @param strct Struct Handle.
* @param member Member name to set.
* @param vec Value to set.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native SetStructVector(Handle:strct, const String:member[], Float:vec[3]);
/**
* Retrieves a string from a struct.
*
* @param strct Struct Handle.
* @param member Member name to retrieve.
* @param value Buffer for the retrieved string.
* @param maxlen Max length of the buffer
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native GetStructString(Handle:strct, const String:member[], const String:value[], maxlen);
/**
* Sets a string value in a struct.
*
* @param strct Struct Handle.
* @param member Member name to set.
* @param value Value to set.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native SetStructString(Handle:strct, const String:member[], String:value[]);
/**
* Retrieves an entity handle from a struct.
*
* @param strct Struct Handle.
* @param member Member name to retrieve.
* @return Entity index.
* @error Undefined member, or member type mismatch.
*/
native GetStructEnt(Handle:strct, const String:member[]);
/**
* Sets an entity handle value in a struct.
*
* @param strct Struct Handle.
* @param member Member name to set.
* @param entity Entity index to set.
* @noreturn
* @error Undefined member, or member type mismatch.
*/
native SetStructEnt(Handle:strct, const String:member[], entity);
/**
* Retrieves a struct handle to a FileWeaponInfo_t for the given weapon name.
*
* @param weapon Weapon name to retrieve.
* @return Struct handle or INVALID_HANDLE on failure.
*/
native Handle:GetWeaponStruct(const String:weapon[]);
/**
* Do not edit below this line!
*/
public Extension:__ext_struct =
{
name = "Struct Abstraction Extension",
file = "structs.ext",
autoload = 1,
#if defined REQUIRE_EXTENSIONS
required = 1,
#else
required = 0,
#endif
};
-610
View File
@@ -1,610 +0,0 @@
"Games"
{
"#default"
{
"Signatures"
{
"LookupWeaponInfoSlot"
{
"library" "server"
"linux" "@_Z20LookupWeaponInfoSlotPKc"
/* This is actually ReadWeaponDataFromFileForSlot - We get find using an offset from here */
"windows" "\x81\xEC\x80\x00\x00\x00\x57\x8B\xBC\x24\x90\x00\x00\x00\x85\xFF\x75\x0A"
}
"GetFileWeaponInfoFromHandle"
{
"library" "server"
"linux" "@_Z27GetFileWeaponInfoFromHandlet"
"windows" "\x66\x8B\x44\x24\x04\x66\x3B\x05\x2A\x2A\x2A\x2A\x73\x17"
}
}
"Offsets"
{
"m_WeaponInfoDatabase"
{
"windows" "38"
}
}
"Structs"
{
"TestStruct"
{
"size" "155"
"seven"
{
"type" "float"
"windows" "0"
"linux" "0"
}
"eight"
{
"type" "float*"
"windows" "4"
"linux" "4"
}
"nine"
{
"type" "Vector"
"windows" "8"
"linux" "8"
}
"ten"
{
"type" "Vector*"
"windows" "20"
"linux" "20"
}
"eleven"
{
"type" "char"
"size" "100"
"windows" "24"
"linux" "24"
}
"twelve"
{
"type" "char*"
"size" "100"
"windows" "124"
"linux" "124"
}
"thirteen"
{
"type" "ent"
"windows" "128"
"linux" "128"
}
"fourteen"
{
"type" "ent*"
"windows" "132"
"linux" "132"
}
"one"
{
"type" "int"
"size" "1"
"windows" "136"
"linux" "136"
}
"two"
{
"type" "int"
"size" "2"
"windows" "137"
"linux" "137"
}
"three"
{
"type" "int"
"size" "4"
"windows" "139"
"linux" "139"
}
"four"
{
"type" "int*"
"size" "1"
"windows" "143"
"linux" "143"
}
"five"
{
"type" "int*"
"size" "2"
"windows" "147"
"linux" "147"
}
"six"
{
"type" "int*"
"size" "4"
"windows" "151"
"linux" "151"
}
}
}
}
"tf"
{
"Structs"
{
"FileWeaponInfo_t"
{
"bParsedScript"
{
"type" "int"
"size" "1"
"windows" "4"
"linux" "4"
}
"bLoadedHudElements"
{
"type" "int"
"size" "1"
"windows" "5"
"linux" "5"
}
"szClassName"
{
"type" "char"
"size" "80"
"windows" "6"
"linux" "6"
}
"szPrintName"
{
"type" "char"
"size" "80"
"windows" "86"
"linux" "86"
}
"szViewModel"
{
"type" "char"
"size" "80"
"windows" "166"
"linux" "166"
}
"szWorldModel"
{
"type" "char"
"size" "80"
"windows" "246"
"linux" "246"
}
"szAnimationPrefix"
{
"type" "char"
"size" "16"
"windows" "326"
"linux" "326"
}
"iSlot"
{
"type" "int"
"size" "4"
"windows" "344"
"linux" "344"
}
"iPosition"
{
"type" "int"
"size" "4"
"windows" "348"
"linux" "348"
}
"iMaxClip1"
{
"type" "int"
"size" "4"
"windows" "352"
"linux" "352"
}
"iMaxClip2"
{
"type" "int"
"size" "4"
"windows" "356"
"linux" "356"
}
"iDefaultClip1"
{
"type" "int"
"size" "4"
"windows" "360"
"linux" "360"
}
"iDefaultClip2"
{
"type" "int"
"size" "4"
"windows" "364"
"linux" "364"
}
"iWeight"
{
"type" "int"
"size" "4"
"windows" "368"
"linux" "368"
}
"iRumbleEffect"
{
"type" "int"
"size" "4"
"windows" "372"
"linux" "372"
}
"bAutoSwitchFrom"
{
"type" "int"
"size" "1"
"windows" "376"
"linux" "376"
}
"bAutoSwitchTo"
{
"type" "int"
"size" "1"
"windows" "377"
"linux" "377"
}
"iFlags"
{
"type" "int"
"size" "4"
"windows" "380"
"linux" "380"
}
"szAmmo1"
{
"type" "char"
"size" "32"
"windows" "384"
"linux" "384"
}
"szAmmo2"
{
"type" "char"
"size" "32"
"windows" "416"
"linux" "416"
}
/* I could split this up into 15 strings of length 80 */
"aShootSounds"
{
"type" "char"
"size" "1200"
"windows" "448"
"linux" "448"
}
"iAmmoType"
{
"type" "int"
"size" "4"
"windows" "1648"
"linux" "1648"
}
"iAmmo2Type"
{
"type" "int"
"size" "4"
"windows" "1652"
"linux" "1652"
}
"m_bMeleeWeapon"
{
"type" "int"
"size" "1"
"windows" "1656"
"linux" "1656"
}
"m_bBuiltRightHanded"
{
"type" "int"
"size" "1"
"windows" "1657"
"linux" "1657"
}
"m_bAllowFlipping"
{
"type" "int"
"size" "1"
"windows" "1658"
"linux" "1658"
}
"iDamage"
{
"type" "int"
"size" "4"
"linux" "1704"
"windows" "1704"
}
"iBulletsPerShot"
{
"type" "int"
"size" "4"
"windows" "1708"
"linux" "1708"
}
"fRange"
{
"type" "float"
"linux" "1712"
"windows" "1712"
}
"fSpread"
{
"type" "float"
"windows" "1716"
"linux" "1716"
}
"fPunchAngle"
{
"type" "float"
"windows" "1720"
"linux" "1720"
}
"fTimeFireDelay"
{
"type" "float"
"windows" "1724"
"linux" "1724"
}
"fTimeIdle"
{
"type" "float"
"windows" "1728"
"linux" "1728"
}
"fTimeIdleEmpty"
{
"type" "float"
"windows" "1732"
"linux" "1732"
}
"fTimeReloadStart"
{
"type" "float"
"windows" "1736"
"linux" "1736"
}
"fTimeReload"
{
"type" "float"
"windows" "1740"
"linux" "1740"
}
"bDrawCrosshair"
{
"type" "int"
"size" "1"
"windows" "1744"
"linux" "1744"
}
"iAmmoPerShot"
{
"type" "int"
"size" "4"
"windows" "1752"
"linux" "1752"
}
"bUseRapidFireCrits"
{
"type" "int"
"size" "1"
"windows" "1764"
"linux" "1764"
}
"iProjectileType"
{
"type" "int"
"size" "1"
"windows" "1748"
"linux" "1748"
}
"fProjectileSpeed"
{
"type" "float"
"windows" "1756"
"linux" "1756"
}
"fSmackDelay"
{
"type" "float"
"windows" "1760"
"linux" "1760"
}
"bDoInstantEjectBrass"
{
"type" "int"
"size" "1"
"windows" "2240"
"linux" "2240"
}
"szBrassModel"
{
"type" "char"
"size" "128"
"windows" "2241"
"linux" "2241"
}
"bGrenade"
{
"type" "int"
"size" "1"
"windows" "1836"
"linux" "1836"
}
"fDamageRadius"
{
"type" "float"
"windows" "1840"
"linux" "1840"
}
"fPrimerTime"
{
"type" "float"
"windows" "1844"
"linux" "1844"
}
"bPlayGrenTimer"
{
"type" "int"
"size" "1"
"windows" "1849"
"linux" "1849"
}
"bLowerMainWeapon"
{
"type" "int"
"size" "1"
"windows" "1848"
"linux" "1848"
}
"bHasTeamSkins_Viewmodel"
{
"type" "int"
"size" "1"
"windows" "1850"
"linux" "1850"
}
"bHasTeamSkins_Worldmodel"
{
"type" "int"
"size" "1"
"windows" "1851"
"linux" "1851"
}
"szMuzzleFlashModel"
{
"type" "char"
"size" "128"
"windows" "1852"
"linux" "1852"
}
"fMuzzleFlashModelDuration"
{
"type" "float"
"windows" "1980"
"linux" "1980"
}
"szMuzzleFlashParticleEffect"
{
"type" "char"
"size" "128"
"windows" "1984"
"linux" "1984"
}
"szTracerEffect"
{
"type" "char"
"size" "128"
"windows" "2112"
"linux" "2112"
}
"szExplosionSound"
{
"type" "char"
"size" "128"
"windows" "2369"
"linux" "2369"
}
"szExplosionEffect"
{
"type" "char"
"size" "128"
"windows" "2497"
"linux" "2497"
}
"szExplosionPlayerEffect"
{
"type" "char"
"size" "128"
"windows" "2625"
"linux" "2625"
}
"szExplosionWaterEffect"
{
"type" "char"
"size" "128"
"windows" "2753"
"linux" "2753"
}
"bDontDrop"
{
"type" "int"
"size" "1"
"windows" "2881"
"linux" "2881"
}
}
}
}
}
-156
View File
@@ -1,156 +0,0 @@
#include <sourcemod>
#include "structs.inc"
public Plugin:myinfo =
{
name = "Struct Abstraction Test",
author = "pRED*",
description = "",
version = "1.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("sm_getstructstring", Command_GetString);
RegServerCmd("sm_setstructstring", Command_SetString);
RegServerCmd("sm_getstructint", Command_GetInt);
RegServerCmd("sm_setstructint", Command_SetInt);
RegServerCmd("sm_getstructfloat", Command_GetFloat);
RegServerCmd("sm_setstructfloat", Command_SetFloat);
}
public Action:Command_GetString(args)
{
if (args != 2)
{
ReplyToCommand(0, "[SM] Usage: sm_getstructstring <struct> <string>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32], String:value[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
new Handle:strct = GetWeaponStruct(arg1);
GetStructString(strct, arg2, value, sizeof(value));
LogMessage("Value of %s: %s", arg2, value);
CloseHandle(strct);
return Plugin_Handled;
}
public Action:Command_SetString(args)
{
if (args != 3)
{
ReplyToCommand(0, "[SM] Usage: sm_setstructstring <struct> <string> <value>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32], String:value[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
GetCmdArg(3, value, sizeof(value));
new Handle:strct = GetWeaponStruct(arg1);
SetStructString(strct, arg2, value);
CloseHandle(strct);
return Plugin_Handled;
}
public Action:Command_GetInt(args)
{
if (args != 2)
{
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
new Handle:strct = GetWeaponStruct(arg1);
new value = GetStructInt(strct, arg2);
LogMessage("Value of %s: %i", arg2, value);
CloseHandle(strct);
return Plugin_Handled;
}
public Action:Command_SetInt(args)
{
if (args != 3)
{
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32], String:value[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
GetCmdArg(3, value, sizeof(value));
new Handle:strct = GetWeaponStruct(arg1);
SetStructInt(strct, arg2, StringToInt(value));
CloseHandle(strct);
return Plugin_Handled;
}
public Action:Command_GetFloat(args)
{
if (args != 2)
{
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
new Handle:strct = GetWeaponStruct(arg1);
new Float:value = GetStructFloat(strct, arg2);
LogMessage("Value of %s: %f", arg2, value);
CloseHandle(strct);
return Plugin_Handled;
}
public Action:Command_SetFloat(args)
{
if (args != 3)
{
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
return Plugin_Handled;
}
decl String:arg1[32], String:arg2[32], String:value[32];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));
GetCmdArg(3, value, sizeof(value));
new Handle:strct = GetWeaponStruct(arg1);
SetStructFloat(strct, arg2, StringToFloat(value));
CloseHandle(strct);
return Plugin_Handled;
}