Normalize all the line endings

This commit is contained in:
Arkshine
2015-03-10 16:51:45 +01:00
parent afc3cac54d
commit 48d6a3354a
64 changed files with 16240 additions and 16240 deletions

View File

@ -10,91 +10,91 @@
//
// Natural Selection Module
//
/* This file is a replacement for the engine call of ALLOC_STRING
* The main difference is that a string will not be allocated twice
* as to try to avoid wasting the HL zone space.
*
* NOTE: The lookup uses strcmp() in a linked list! It is not fast
* Its implementation in the NS module is on rarely used
* natives.
*/
#ifndef ALLOCSTRING_H
#define ALLOCSTRING_H
#include <am-string.h>
#include <am-linkedlist.h>
class StringManager
{
private:
ke::LinkedList<ke::AString *> m_StringList;
public:
/**
* sh_list.h does not delete objects put into
* the list, so I need to delete those and clear()
*/
inline void Clear(void)
{
ke::LinkedList<ke::AString *>::iterator end;
ke::LinkedList<ke::AString *>::iterator iter;
iter=m_StringList.begin();
end=m_StringList.end();
while (iter!=end)
{
delete (*iter++);
}
m_StringList.clear();
}
/**
* Iterate the list to see if the string exists
* This is slow and not very ideal, however
* this is *very* rarely used so it won't matter
*/
inline int Allocate(const char *str)
{
ke::LinkedList<ke::AString *>::iterator end;
ke::LinkedList<ke::AString *>::iterator iter;
iter=m_StringList.begin();
end=m_StringList.end();
while (iter!=end)
{
if (strcmp(str, (*iter)->chars()) == 0)
{
// String is already in the list, do not allocate it again
return MAKE_STRING((*iter)->chars());
}
++iter;
}
// Was not found in the linked list, allocate it and add it to the list
ke::AString *AllocStr = new ke::AString(str);
m_StringList.append(AllocStr);
return MAKE_STRING(AllocStr->chars());
};
};
extern StringManager AllocStringList;
/**
* Simple wrapper to make conversion easier
*/
inline int ALLOC_STRING2(const char *InputString)
{
return AllocStringList.Allocate(InputString);
}
#endif // ALLOCSTRING_H
/* This file is a replacement for the engine call of ALLOC_STRING
* The main difference is that a string will not be allocated twice
* as to try to avoid wasting the HL zone space.
*
* NOTE: The lookup uses strcmp() in a linked list! It is not fast
* Its implementation in the NS module is on rarely used
* natives.
*/
#ifndef ALLOCSTRING_H
#define ALLOCSTRING_H
#include <am-string.h>
#include <am-linkedlist.h>
class StringManager
{
private:
ke::LinkedList<ke::AString *> m_StringList;
public:
/**
* sh_list.h does not delete objects put into
* the list, so I need to delete those and clear()
*/
inline void Clear(void)
{
ke::LinkedList<ke::AString *>::iterator end;
ke::LinkedList<ke::AString *>::iterator iter;
iter=m_StringList.begin();
end=m_StringList.end();
while (iter!=end)
{
delete (*iter++);
}
m_StringList.clear();
}
/**
* Iterate the list to see if the string exists
* This is slow and not very ideal, however
* this is *very* rarely used so it won't matter
*/
inline int Allocate(const char *str)
{
ke::LinkedList<ke::AString *>::iterator end;
ke::LinkedList<ke::AString *>::iterator iter;
iter=m_StringList.begin();
end=m_StringList.end();
while (iter!=end)
{
if (strcmp(str, (*iter)->chars()) == 0)
{
// String is already in the list, do not allocate it again
return MAKE_STRING((*iter)->chars());
}
++iter;
}
// Was not found in the linked list, allocate it and add it to the list
ke::AString *AllocStr = new ke::AString(str);
m_StringList.append(AllocStr);
return MAKE_STRING(AllocStr->chars());
};
};
extern StringManager AllocStringList;
/**
* Simple wrapper to make conversion easier
*/
inline int ALLOC_STRING2(const char *InputString)
{
return AllocStringList.Allocate(InputString);
}
#endif // ALLOCSTRING_H

View File

@ -10,88 +10,88 @@
//
// Natural Selection Module
//
/* This holds the functions which determine which hooks I need forwareded */
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "CPlayer.h"
void GameManager::HookPreThink(void)
{
// Only need to hook prethink if at least 1 plugins has any of these forwards:
// client_spawn, client_changeteam, client_changeclass
if (UTIL_CheckForPublic("client_spawn") ||
UTIL_CheckForPublic("client_changeteam") ||
UTIL_CheckForPublic("client_changeclass"))
{
g_pFunctionTable->pfnPlayerPreThink=PlayerPreThink;
return;
}
g_pFunctionTable->pfnPlayerPreThink=NULL;
};
void GameManager::HookPostThink_Post(void)
{
int i=0;
while (i++<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i)->NeedPostThink_Post())
{
g_pFunctionTable_Post->pfnPlayerPostThink=PlayerPostThink_Post;
return;
}
}
g_pFunctionTable_Post->pfnPlayerPostThink=NULL;
};
void GameManager::HookPreThink_Post(void)
{
int i=1;
while (i<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i++)->NeedPreThink_Post())
{
g_pFunctionTable_Post->pfnPlayerPreThink=PlayerPreThink_Post;
return;
}
}
g_pFunctionTable_Post->pfnPlayerPreThink=NULL;
};
void GameManager::HookUpdateClientData(void)
{
int i=1;
while (i<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i++)->NeedUpdateClientData())
{
g_pFunctionTable->pfnUpdateClientData=UpdateClientData;
return;
}
}
g_pFunctionTable->pfnUpdateClientData=NULL;
};
void GameManager::HookLogs()
{
// These forwards only are needed in classic NS
if (!IsCombat() && UTIL_CheckForPublic("client_built"))
{
// Only hook if this public exists (wasteful otherwise)
m_BuiltForward = MF_RegisterForward("client_built", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
g_pengfuncsTable_Post->pfnAlertMessage=AlertMessage_Post;
g_pengfuncsTable_Post->pfnCreateNamedEntity=CreateNamedEntity_Post;
}
else
{
// no need for these hooks in co
g_pengfuncsTable_Post->pfnAlertMessage=NULL;
g_pengfuncsTable_Post->pfnCreateNamedEntity=NULL;
}
};
/* This holds the functions which determine which hooks I need forwareded */
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "CPlayer.h"
void GameManager::HookPreThink(void)
{
// Only need to hook prethink if at least 1 plugins has any of these forwards:
// client_spawn, client_changeteam, client_changeclass
if (UTIL_CheckForPublic("client_spawn") ||
UTIL_CheckForPublic("client_changeteam") ||
UTIL_CheckForPublic("client_changeclass"))
{
g_pFunctionTable->pfnPlayerPreThink=PlayerPreThink;
return;
}
g_pFunctionTable->pfnPlayerPreThink=NULL;
};
void GameManager::HookPostThink_Post(void)
{
int i=0;
while (i++<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i)->NeedPostThink_Post())
{
g_pFunctionTable_Post->pfnPlayerPostThink=PlayerPostThink_Post;
return;
}
}
g_pFunctionTable_Post->pfnPlayerPostThink=NULL;
};
void GameManager::HookPreThink_Post(void)
{
int i=1;
while (i<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i++)->NeedPreThink_Post())
{
g_pFunctionTable_Post->pfnPlayerPreThink=PlayerPreThink_Post;
return;
}
}
g_pFunctionTable_Post->pfnPlayerPreThink=NULL;
};
void GameManager::HookUpdateClientData(void)
{
int i=1;
while (i<gpGlobals->maxClients)
{
if (GET_PLAYER_I(i++)->NeedUpdateClientData())
{
g_pFunctionTable->pfnUpdateClientData=UpdateClientData;
return;
}
}
g_pFunctionTable->pfnUpdateClientData=NULL;
};
void GameManager::HookLogs()
{
// These forwards only are needed in classic NS
if (!IsCombat() && UTIL_CheckForPublic("client_built"))
{
// Only hook if this public exists (wasteful otherwise)
m_BuiltForward = MF_RegisterForward("client_built", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
g_pengfuncsTable_Post->pfnAlertMessage=AlertMessage_Post;
g_pengfuncsTable_Post->pfnCreateNamedEntity=CreateNamedEntity_Post;
}
else
{
// no need for these hooks in co
g_pengfuncsTable_Post->pfnAlertMessage=NULL;
g_pengfuncsTable_Post->pfnCreateNamedEntity=NULL;
}
};

View File

@ -10,287 +10,287 @@
//
// Natural Selection Module
//
/* This file includes game-related stuff, such as message IDs
* and forwards
*/
#ifndef GAMEMANAGER_H
#define GAMEMANAGER_H
#include <am-string.h>
class GameManager
{
private:
// Basic game variables
int m_IsCombat;
int m_HudText2; // Message IDS
int m_SetFOV;
// Forwards
int m_ChangeclassForward;
int m_BuiltForward;
int m_SpawnForward;
int m_TeamForward;
int m_RoundStartForward;
int m_RoundEndForward;
int m_MapResetForward;
REAL m_fRoundStartTime; // Time the match should start
int m_RoundInProgress; // Whether or not there is a match in progress
edict_t *m_SavedEdict; // saved edict for client_built
int m_iTitlesMap;
bool m_SendMapReset;
public:
GameManager()
{
m_SendMapReset = true;
m_IsCombat=0;
m_HudText2=0;
m_SetFOV=0;
m_SavedEdict=NULL;
m_RoundInProgress=0;
ResetForwards();
};
inline void CheckMap(void)
{
ke::AString MapName;
MapName = UTIL_ToLowerCase(STRING(gpGlobals->mapname));
m_iTitlesMap=0;
if (MapName.compare("ns_bast")==0 ||
MapName.compare("ns_bast_classic") == 0 ||
MapName.compare("ns_hera") == 0 ||
MapName.compare("ns_nothing") == 0 ||
MapName.compare("ns_caged") == 0 ||
MapName.compare("ns_tanith") == 0 ||
MapName.compare("ns_eclipse") == 0 ||
MapName.compare("ns_veil") == 0 ||
MapName.compare("ns_nancy") == 0)
{
m_iTitlesMap=1;
}
};
inline int &TitleMap(void)
{
return m_iTitlesMap;
};
inline void SetCombat(int value)
{
m_IsCombat=value;
};
inline int &IsCombat(void)
{
return m_IsCombat;
};
inline void UpdateHudText2(void)
{
if (!m_HudText2)
{
GetMessageIDs();
}
};
inline void UpdateSetFOV(void)
{
if (!m_SetFOV)
{
GetMessageIDs();
}
};
inline int &GetHudText2(void)
{
return m_HudText2;
};
inline int &GetSetFOV(void)
{
return m_SetFOV;
};
inline void GetMessageIDs(void)
{
m_HudText2=GET_USER_MSG_ID(&Plugin_info,"HudText2",NULL);
m_SetFOV=GET_USER_MSG_ID(&Plugin_info,"SetFOV",NULL);
};
inline void EvaluateCombat(void)
{
const char *Map=STRING(gpGlobals->mapname);
// if map starts with co_ it is combat
// otherwise it is classic gameplay
if ((Map[0]=='c' || Map[0]=='C') &&
(Map[1]=='o' || Map[1]=='O') &&
(Map[2]=='_'))
{
SetCombat(1);
return;
}
SetCombat(0);
};
inline void ResetForwards(void)
{
m_ChangeclassForward=-1;
m_BuiltForward=-1;
m_SpawnForward=-1;
m_TeamForward=-1;
m_RoundStartForward=-1;
m_RoundEndForward=-1;
m_MapResetForward=-1;
};
inline void RegisterForwards(void)
{
ResetForwards();
m_SpawnForward = MF_RegisterForward("client_spawn",ET_IGNORE,FP_CELL/*id*/,FP_DONE);
m_TeamForward = MF_RegisterForward("client_changeteam",ET_IGNORE,FP_CELL/*id*/,FP_CELL/*new team*/,FP_CELL/*old team*/,FP_DONE);
m_ChangeclassForward = MF_RegisterForward("client_changeclass", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
m_RoundStartForward = MF_RegisterForward("round_start", ET_IGNORE, FP_DONE);
m_RoundEndForward = MF_RegisterForward("round_end", ET_IGNORE, FP_FLOAT, FP_DONE);
m_MapResetForward = MF_RegisterForward("map_reset", ET_IGNORE, FP_CELL, FP_DONE);
};
inline void StartFrame(void)
{
if (gpGlobals->time >= m_fRoundStartTime)
{
g_pFunctionTable->pfnStartFrame=NULL;
RoundStart();
}
};
/**
* This is called from MessageHandler's Countdown
* hook. It passes the only byte sent (time)
*/
inline void HandleCountdown(int &Time)
{
// Begin hooking start frame
g_pFunctionTable->pfnStartFrame=::StartFrame;
// set time of round start
m_fRoundStartTime=gpGlobals->time + Time;
m_SendMapReset = true;
};
/**
* This is called from MessageHandler's GameStatus
* hook. It passes the first byte sent.
* 2 = Round End
*/
inline void HandleGameStatus(int &FirstByte)
{
switch (FirstByte)
{
case 0:
if (m_SendMapReset)
{
MF_ExecuteForward(m_MapResetForward, 0);
}
m_SendMapReset = false;
break;
case 1:
MF_ExecuteForward(m_MapResetForward, 1);
break;
case 2:
RoundEnd();
break;
}
};
inline void RoundStart()
{
m_RoundInProgress=1;
MF_ExecuteForward(m_RoundStartForward);
};
inline void RoundEnd()
{
m_RoundInProgress=0;
MF_ExecuteForward(m_RoundEndForward,gpGlobals->time - m_fRoundStartTime);
};
inline int &RoundInProgress()
{
return m_RoundInProgress;
};
// no need to check -1 forwards in these
// amxmodx checks it anyway
inline void ExecuteClientBuilt(int &PlayerID, int StructureID, int &StructureType, int &Impulse)
{
MF_ExecuteForward(m_BuiltForward,PlayerID, StructureID, StructureType, Impulse);
};
inline void ExecuteClientSpawn(int &PlayerID)
{
MF_ExecuteForward(m_SpawnForward,PlayerID);
};
inline void ExecuteClientChangeTeam(int &PlayerID, int &NewTeam, int &OldTeam)
{
MF_ExecuteForward(m_TeamForward, PlayerID, NewTeam, OldTeam);
};
inline void ExecuteClientChangeClass(int &PlayerID, int &NewClass, int &OldClass)
{
MF_ExecuteForward(m_ChangeclassForward,PlayerID,NewClass,OldClass);
};
inline void ExecuteRoundStart(void)
{
MF_ExecuteForward(m_RoundStartForward);
};
inline void ExecuteRoundEnd(void)
{
MF_ExecuteForward(m_RoundEndForward);
};
/**
* The next few functions tell the module what metamod hooks
* i need. This tries to run-time optimize out what we
* do not need.
*/
void HookPreThink(void);
void HookPostThink_Post(void);
void HookPreThink_Post(void);
void HookUpdateClientData(void);
void HookLogs(void); // AlertMessage AND CreateNamedEntity
inline void CheckAllHooks(void)
{
HookPreThink();
HookPostThink_Post();
HookPreThink_Post();
HookUpdateClientData();
HookLogs();
};
inline void SetTemporaryEdict(edict_t *Edict)
{
m_SavedEdict=Edict;
};
inline edict_t *GetTemporaryEdict(void)
{
return m_SavedEdict;
};
};
extern GameManager GameMan;
#endif // GAMEMANAGER_H
/* This file includes game-related stuff, such as message IDs
* and forwards
*/
#ifndef GAMEMANAGER_H
#define GAMEMANAGER_H
#include <am-string.h>
class GameManager
{
private:
// Basic game variables
int m_IsCombat;
int m_HudText2; // Message IDS
int m_SetFOV;
// Forwards
int m_ChangeclassForward;
int m_BuiltForward;
int m_SpawnForward;
int m_TeamForward;
int m_RoundStartForward;
int m_RoundEndForward;
int m_MapResetForward;
REAL m_fRoundStartTime; // Time the match should start
int m_RoundInProgress; // Whether or not there is a match in progress
edict_t *m_SavedEdict; // saved edict for client_built
int m_iTitlesMap;
bool m_SendMapReset;
public:
GameManager()
{
m_SendMapReset = true;
m_IsCombat=0;
m_HudText2=0;
m_SetFOV=0;
m_SavedEdict=NULL;
m_RoundInProgress=0;
ResetForwards();
};
inline void CheckMap(void)
{
ke::AString MapName;
MapName = UTIL_ToLowerCase(STRING(gpGlobals->mapname));
m_iTitlesMap=0;
if (MapName.compare("ns_bast")==0 ||
MapName.compare("ns_bast_classic") == 0 ||
MapName.compare("ns_hera") == 0 ||
MapName.compare("ns_nothing") == 0 ||
MapName.compare("ns_caged") == 0 ||
MapName.compare("ns_tanith") == 0 ||
MapName.compare("ns_eclipse") == 0 ||
MapName.compare("ns_veil") == 0 ||
MapName.compare("ns_nancy") == 0)
{
m_iTitlesMap=1;
}
};
inline int &TitleMap(void)
{
return m_iTitlesMap;
};
inline void SetCombat(int value)
{
m_IsCombat=value;
};
inline int &IsCombat(void)
{
return m_IsCombat;
};
inline void UpdateHudText2(void)
{
if (!m_HudText2)
{
GetMessageIDs();
}
};
inline void UpdateSetFOV(void)
{
if (!m_SetFOV)
{
GetMessageIDs();
}
};
inline int &GetHudText2(void)
{
return m_HudText2;
};
inline int &GetSetFOV(void)
{
return m_SetFOV;
};
inline void GetMessageIDs(void)
{
m_HudText2=GET_USER_MSG_ID(&Plugin_info,"HudText2",NULL);
m_SetFOV=GET_USER_MSG_ID(&Plugin_info,"SetFOV",NULL);
};
inline void EvaluateCombat(void)
{
const char *Map=STRING(gpGlobals->mapname);
// if map starts with co_ it is combat
// otherwise it is classic gameplay
if ((Map[0]=='c' || Map[0]=='C') &&
(Map[1]=='o' || Map[1]=='O') &&
(Map[2]=='_'))
{
SetCombat(1);
return;
}
SetCombat(0);
};
inline void ResetForwards(void)
{
m_ChangeclassForward=-1;
m_BuiltForward=-1;
m_SpawnForward=-1;
m_TeamForward=-1;
m_RoundStartForward=-1;
m_RoundEndForward=-1;
m_MapResetForward=-1;
};
inline void RegisterForwards(void)
{
ResetForwards();
m_SpawnForward = MF_RegisterForward("client_spawn",ET_IGNORE,FP_CELL/*id*/,FP_DONE);
m_TeamForward = MF_RegisterForward("client_changeteam",ET_IGNORE,FP_CELL/*id*/,FP_CELL/*new team*/,FP_CELL/*old team*/,FP_DONE);
m_ChangeclassForward = MF_RegisterForward("client_changeclass", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
m_RoundStartForward = MF_RegisterForward("round_start", ET_IGNORE, FP_DONE);
m_RoundEndForward = MF_RegisterForward("round_end", ET_IGNORE, FP_FLOAT, FP_DONE);
m_MapResetForward = MF_RegisterForward("map_reset", ET_IGNORE, FP_CELL, FP_DONE);
};
inline void StartFrame(void)
{
if (gpGlobals->time >= m_fRoundStartTime)
{
g_pFunctionTable->pfnStartFrame=NULL;
RoundStart();
}
};
/**
* This is called from MessageHandler's Countdown
* hook. It passes the only byte sent (time)
*/
inline void HandleCountdown(int &Time)
{
// Begin hooking start frame
g_pFunctionTable->pfnStartFrame=::StartFrame;
// set time of round start
m_fRoundStartTime=gpGlobals->time + Time;
m_SendMapReset = true;
};
/**
* This is called from MessageHandler's GameStatus
* hook. It passes the first byte sent.
* 2 = Round End
*/
inline void HandleGameStatus(int &FirstByte)
{
switch (FirstByte)
{
case 0:
if (m_SendMapReset)
{
MF_ExecuteForward(m_MapResetForward, 0);
}
m_SendMapReset = false;
break;
case 1:
MF_ExecuteForward(m_MapResetForward, 1);
break;
case 2:
RoundEnd();
break;
}
};
inline void RoundStart()
{
m_RoundInProgress=1;
MF_ExecuteForward(m_RoundStartForward);
};
inline void RoundEnd()
{
m_RoundInProgress=0;
MF_ExecuteForward(m_RoundEndForward,gpGlobals->time - m_fRoundStartTime);
};
inline int &RoundInProgress()
{
return m_RoundInProgress;
};
// no need to check -1 forwards in these
// amxmodx checks it anyway
inline void ExecuteClientBuilt(int &PlayerID, int StructureID, int &StructureType, int &Impulse)
{
MF_ExecuteForward(m_BuiltForward,PlayerID, StructureID, StructureType, Impulse);
};
inline void ExecuteClientSpawn(int &PlayerID)
{
MF_ExecuteForward(m_SpawnForward,PlayerID);
};
inline void ExecuteClientChangeTeam(int &PlayerID, int &NewTeam, int &OldTeam)
{
MF_ExecuteForward(m_TeamForward, PlayerID, NewTeam, OldTeam);
};
inline void ExecuteClientChangeClass(int &PlayerID, int &NewClass, int &OldClass)
{
MF_ExecuteForward(m_ChangeclassForward,PlayerID,NewClass,OldClass);
};
inline void ExecuteRoundStart(void)
{
MF_ExecuteForward(m_RoundStartForward);
};
inline void ExecuteRoundEnd(void)
{
MF_ExecuteForward(m_RoundEndForward);
};
/**
* The next few functions tell the module what metamod hooks
* i need. This tries to run-time optimize out what we
* do not need.
*/
void HookPreThink(void);
void HookPostThink_Post(void);
void HookPreThink_Post(void);
void HookUpdateClientData(void);
void HookLogs(void); // AlertMessage AND CreateNamedEntity
inline void CheckAllHooks(void)
{
HookPreThink();
HookPostThink_Post();
HookPreThink_Post();
HookUpdateClientData();
HookLogs();
};
inline void SetTemporaryEdict(edict_t *Edict)
{
m_SavedEdict=Edict;
};
inline edict_t *GetTemporaryEdict(void)
{
return m_SavedEdict;
};
};
extern GameManager GameMan;
#endif // GAMEMANAGER_H

View File

@ -11,168 +11,168 @@
// Natural Selection Module
//
#ifndef _HASH_H_
#define _HASH_H_
#include <am-vector.h>
#include <am-string.h>
// Just a very simple hash map, no iteration or anything of the like (not needed)
inline int HashFunction(const ke::AString& name)
{
static const int kHashNumTable[128] =
{
0x1148FC3E, 0x0577C975, 0x3BED3AED, 0x62FBBD5F, 0x07DE2DA0, 0x6555C5E5, 0x24DB841A, 0x2AF3F568,
0x01EA1B65, 0x46F7D976, 0x18172B99, 0x394B2A58, 0x1ED39AA8, 0x1214E706, 0x5DD47295, 0x53574932,
0x2CE25D5C, 0x7A2E5BB4, 0x0F2F0153, 0x33888669, 0x729AC55F, 0x2A7BCA9E, 0x36C60816, 0x40F9A7E3,
0x2A37DF30, 0x3D81BB17, 0x6450B311, 0x75FA2DC9, 0x2A2678A5, 0x4C5E3675, 0x743F4486, 0x3B6F74E3,
0x51D5FFEA, 0x302C7F74, 0x1E6B3243, 0x59B42D8A, 0x15824559, 0x4346B65D, 0x04A822F2, 0x176C60BF,
0x0A3E8FD3, 0x1CBF4E8B, 0x50B78B17, 0x29122A7B, 0x2ED43591, 0x2E8BFDAC, 0x7C6973AE, 0x5BB692EE,
0x28BA5960, 0x0B987501, 0x0F3F1957, 0x1B551EBF, 0x36143F9F, 0x4605216D, 0x5C4EC6A2, 0x604C1ECF,
0x0386DC84, 0x409F79B4, 0x56464C99, 0x2DAD5529, 0x0CFDB029, 0x4A85911F, 0x691CCA0D, 0x5ED3B013,
0x7AB21093, 0x0787FC50, 0x3887DD9D, 0x103455ED, 0x4ACEB2AD, 0x3D30008F, 0x27A0B6AC, 0x550D4280,
0x59EF4F1B, 0x785841C3, 0x7E1F6CFC, 0x08C384AC, 0x26E43F70, 0x7A88E0AA, 0x647A179A, 0x4F9E98D0,
0x062155AB, 0x73B930F1, 0x6AF3B790, 0x3C35954B, 0x39BE525E, 0x47427E32, 0x1C81B41A, 0x3D452EE2,
0x07E1F7E6, 0x72C800B3, 0x6AF2840C, 0x14DFA80F, 0x3D4D91D3, 0x540F4E19, 0x73B35822, 0x37FFA266,
0x5B974A69, 0x2C3B35BF, 0x4833F853, 0x2665FD16, 0x696B364F, 0x6FD4AEFF, 0x7B733F96, 0x435A856A,
0x682CF0C3, 0x7992AC92, 0x4C1E0A16, 0x0F113033, 0x741B8D3C, 0x309821B1, 0x5EAFC903, 0x7A3CE2E8,
0x245152A2, 0x49A38093, 0x36727833, 0x5E0FA501, 0x10E5FEC6, 0x52F42C4D, 0x1B54D3E3, 0x18C7F6AC,
0x45BC2D01, 0x064757EF, 0x2DA79EBC, 0x0309BED4, 0x5A56A608, 0x215AF6DE, 0x3B09613A, 0x35EDF071
};
size_t size = name.length();
if (size == 0)
{
return 0;
}
int hasha = kHashNumTable[(*(name.chars() + (size - 1))) & 0x7F];
int hashb = kHashNumTable[size % 128];
unsigned char c = 0;
for (size_t i = 0; i < size; i++)
{
c = (*(name.chars() + (size - 1))) & 0x7F;
hasha = (hasha + hashb) ^ kHashNumTable[c];
hashb = hasha + hashb + c + (hasha << 8) + (hashb & 0xFF);
}
return hasha;
}
/**
* @param K Key type.
* @param D Data type.
* @param F Hash function.
* @param B Bucket count.
*/
template <typename K = ke::AString, typename D = ke::AString, int (*F)(const K&) = HashFunction, int B = 1024>
class Hash
{
protected:
ke::Vector<int> m_HashBuckets[B];
ke::Vector<K> m_KeyBuckets[B];
ke::Vector<D> m_DataBuckets[B];
inline int GetBucket(int hash)
{
return (*reinterpret_cast<unsigned int*>(&hash)) % B;
};
public:
// prints bucket distribution
inline void printbuckets() const
{
for (int i = 0; i < B; i++)
{
if (i % 32 == 0 && i != 0)
{
printf("\n");
}
printf("%d ", m_HashBuckets[i].size());
}
printf("\n");
}
inline void insert(const K& key, const D& value)
{
D* ptr;
if ((ptr = this->find(key)) != NULL)
{
*ptr = value;
return;
}
int hash = F(key);
int bucketnum = GetBucket(hash);
m_HashBuckets[bucketnum].append(hash);
m_KeyBuckets[bucketnum].append(key);
m_DataBuckets[bucketnum].append(value);
return;
}
inline D& lookup_or_add(const K& key)
{
D* ptr;
if ((ptr = this->find(key)) != NULL)
{
return *ptr;
}
int hash = F(key);
int bucketnum = GetBucket(hash);
m_HashBuckets[bucketnum].append(hash);
m_KeyBuckets[bucketnum].append(key);
m_DataBuckets[bucketnum].append(D());
return m_DataBuckets[bucketnum].at(m_DataBuckets[bucketnum].size() - 1);
}
inline bool exists(const K& key)
{
return this->find(key) != NULL;
}
inline D* find(const K& key)
{
int hash = F(key);
int bucketnum = GetBucket(hash);
// TODO: Possibly make this binary search?
// insertion would be annoying, don't think it is worth it
ke::Vector<int>* hashbucket = &m_HashBuckets[bucketnum];
ke::Vector<K>* keybucket = &m_KeyBuckets[bucketnum];
size_t bucketsize = hashbucket->length();
for (size_t i = 0; i < bucketsize; i++)
{
if (hashbucket->at(i) == hash)
{
if (key.compare(keybucket->at(i).chars()) == 0)
{
return &(m_DataBuckets[bucketnum].at(i));
}
}
}
return NULL;
};
};
#endif
#ifndef _HASH_H_
#define _HASH_H_
#include <am-vector.h>
#include <am-string.h>
// Just a very simple hash map, no iteration or anything of the like (not needed)
inline int HashFunction(const ke::AString& name)
{
static const int kHashNumTable[128] =
{
0x1148FC3E, 0x0577C975, 0x3BED3AED, 0x62FBBD5F, 0x07DE2DA0, 0x6555C5E5, 0x24DB841A, 0x2AF3F568,
0x01EA1B65, 0x46F7D976, 0x18172B99, 0x394B2A58, 0x1ED39AA8, 0x1214E706, 0x5DD47295, 0x53574932,
0x2CE25D5C, 0x7A2E5BB4, 0x0F2F0153, 0x33888669, 0x729AC55F, 0x2A7BCA9E, 0x36C60816, 0x40F9A7E3,
0x2A37DF30, 0x3D81BB17, 0x6450B311, 0x75FA2DC9, 0x2A2678A5, 0x4C5E3675, 0x743F4486, 0x3B6F74E3,
0x51D5FFEA, 0x302C7F74, 0x1E6B3243, 0x59B42D8A, 0x15824559, 0x4346B65D, 0x04A822F2, 0x176C60BF,
0x0A3E8FD3, 0x1CBF4E8B, 0x50B78B17, 0x29122A7B, 0x2ED43591, 0x2E8BFDAC, 0x7C6973AE, 0x5BB692EE,
0x28BA5960, 0x0B987501, 0x0F3F1957, 0x1B551EBF, 0x36143F9F, 0x4605216D, 0x5C4EC6A2, 0x604C1ECF,
0x0386DC84, 0x409F79B4, 0x56464C99, 0x2DAD5529, 0x0CFDB029, 0x4A85911F, 0x691CCA0D, 0x5ED3B013,
0x7AB21093, 0x0787FC50, 0x3887DD9D, 0x103455ED, 0x4ACEB2AD, 0x3D30008F, 0x27A0B6AC, 0x550D4280,
0x59EF4F1B, 0x785841C3, 0x7E1F6CFC, 0x08C384AC, 0x26E43F70, 0x7A88E0AA, 0x647A179A, 0x4F9E98D0,
0x062155AB, 0x73B930F1, 0x6AF3B790, 0x3C35954B, 0x39BE525E, 0x47427E32, 0x1C81B41A, 0x3D452EE2,
0x07E1F7E6, 0x72C800B3, 0x6AF2840C, 0x14DFA80F, 0x3D4D91D3, 0x540F4E19, 0x73B35822, 0x37FFA266,
0x5B974A69, 0x2C3B35BF, 0x4833F853, 0x2665FD16, 0x696B364F, 0x6FD4AEFF, 0x7B733F96, 0x435A856A,
0x682CF0C3, 0x7992AC92, 0x4C1E0A16, 0x0F113033, 0x741B8D3C, 0x309821B1, 0x5EAFC903, 0x7A3CE2E8,
0x245152A2, 0x49A38093, 0x36727833, 0x5E0FA501, 0x10E5FEC6, 0x52F42C4D, 0x1B54D3E3, 0x18C7F6AC,
0x45BC2D01, 0x064757EF, 0x2DA79EBC, 0x0309BED4, 0x5A56A608, 0x215AF6DE, 0x3B09613A, 0x35EDF071
};
size_t size = name.length();
if (size == 0)
{
return 0;
}
int hasha = kHashNumTable[(*(name.chars() + (size - 1))) & 0x7F];
int hashb = kHashNumTable[size % 128];
unsigned char c = 0;
for (size_t i = 0; i < size; i++)
{
c = (*(name.chars() + (size - 1))) & 0x7F;
hasha = (hasha + hashb) ^ kHashNumTable[c];
hashb = hasha + hashb + c + (hasha << 8) + (hashb & 0xFF);
}
return hasha;
}
/**
* @param K Key type.
* @param D Data type.
* @param F Hash function.
* @param B Bucket count.
*/
template <typename K = ke::AString, typename D = ke::AString, int (*F)(const K&) = HashFunction, int B = 1024>
class Hash
{
protected:
ke::Vector<int> m_HashBuckets[B];
ke::Vector<K> m_KeyBuckets[B];
ke::Vector<D> m_DataBuckets[B];
inline int GetBucket(int hash)
{
return (*reinterpret_cast<unsigned int*>(&hash)) % B;
};
public:
// prints bucket distribution
inline void printbuckets() const
{
for (int i = 0; i < B; i++)
{
if (i % 32 == 0 && i != 0)
{
printf("\n");
}
printf("%d ", m_HashBuckets[i].size());
}
printf("\n");
}
inline void insert(const K& key, const D& value)
{
D* ptr;
if ((ptr = this->find(key)) != NULL)
{
*ptr = value;
return;
}
int hash = F(key);
int bucketnum = GetBucket(hash);
m_HashBuckets[bucketnum].append(hash);
m_KeyBuckets[bucketnum].append(key);
m_DataBuckets[bucketnum].append(value);
return;
}
inline D& lookup_or_add(const K& key)
{
D* ptr;
if ((ptr = this->find(key)) != NULL)
{
return *ptr;
}
int hash = F(key);
int bucketnum = GetBucket(hash);
m_HashBuckets[bucketnum].append(hash);
m_KeyBuckets[bucketnum].append(key);
m_DataBuckets[bucketnum].append(D());
return m_DataBuckets[bucketnum].at(m_DataBuckets[bucketnum].size() - 1);
}
inline bool exists(const K& key)
{
return this->find(key) != NULL;
}
inline D* find(const K& key)
{
int hash = F(key);
int bucketnum = GetBucket(hash);
// TODO: Possibly make this binary search?
// insertion would be annoying, don't think it is worth it
ke::Vector<int>* hashbucket = &m_HashBuckets[bucketnum];
ke::Vector<K>* keybucket = &m_KeyBuckets[bucketnum];
size_t bucketsize = hashbucket->length();
for (size_t i = 0; i < bucketsize; i++)
{
if (hashbucket->at(i) == hash)
{
if (key.compare(keybucket->at(i).chars()) == 0)
{
return &(m_DataBuckets[bucketnum].at(i));
}
}
}
return NULL;
};
};
#endif

View File

@ -10,89 +10,89 @@
//
// Natural Selection Module
//
#ifndef LOCATIONMANAGER_H
#define LOCATIONMANAGER_H
#include <am-vector.h>
#include "GameManager.h"
#include "TitleManager.h"
typedef struct location_data_s
{
char name[128];
vec3_t mins;
vec3_t maxs;
const char *titlelookup;
} location_data_t;
class LocationManager
{
private:
ke::Vector<location_data_t> m_LocationList;
public:
LocationManager()
{
Clear();
};
inline void Clear(void)
{
m_LocationList.clear();
m_LocationList.ensure(32);
};
inline void Add(const char *Name, edict_t *Entity)
{
location_data_t Temp;
Temp.mins=Entity->v.mins;
Temp.maxs=Entity->v.maxs;
strncpy(Temp.name,Name,sizeof(Temp.name)-1);
ke::AString NameString(UTIL_ToLowerCase(Name));
Temp.titlelookup=TitleMan.Lookup(NameString);
m_LocationList.append(Temp);
};
inline const char *Lookup(vec3_t origin, cell titlelookup)
{
unsigned int i=0;
location_data_t Temp;
while (i<m_LocationList.length())
{
Temp=m_LocationList[i++];
if (origin.x <= Temp.maxs.x &&
origin.y <= Temp.maxs.y &&
origin.x >= Temp.mins.x &&
origin.y >= Temp.mins.y)
{
if (titlelookup==0)
{
return &(m_LocationList[i-1].name[0]);
}
else
{
if (m_LocationList[i-1].titlelookup!=NULL)
{
return m_LocationList[i-1].titlelookup;
}
return &(m_LocationList[i-1].name[0]);
}
}
}
return "";
};
};
extern LocationManager LocationMan;
#endif // LOCATIONMANAGER_H
#ifndef LOCATIONMANAGER_H
#define LOCATIONMANAGER_H
#include <am-vector.h>
#include "GameManager.h"
#include "TitleManager.h"
typedef struct location_data_s
{
char name[128];
vec3_t mins;
vec3_t maxs;
const char *titlelookup;
} location_data_t;
class LocationManager
{
private:
ke::Vector<location_data_t> m_LocationList;
public:
LocationManager()
{
Clear();
};
inline void Clear(void)
{
m_LocationList.clear();
m_LocationList.ensure(32);
};
inline void Add(const char *Name, edict_t *Entity)
{
location_data_t Temp;
Temp.mins=Entity->v.mins;
Temp.maxs=Entity->v.maxs;
strncpy(Temp.name,Name,sizeof(Temp.name)-1);
ke::AString NameString(UTIL_ToLowerCase(Name));
Temp.titlelookup=TitleMan.Lookup(NameString);
m_LocationList.append(Temp);
};
inline const char *Lookup(vec3_t origin, cell titlelookup)
{
unsigned int i=0;
location_data_t Temp;
while (i<m_LocationList.length())
{
Temp=m_LocationList[i++];
if (origin.x <= Temp.maxs.x &&
origin.y <= Temp.maxs.y &&
origin.x >= Temp.mins.x &&
origin.y >= Temp.mins.y)
{
if (titlelookup==0)
{
return &(m_LocationList[i-1].name[0]);
}
else
{
if (m_LocationList[i-1].titlelookup!=NULL)
{
return m_LocationList[i-1].titlelookup;
}
return &(m_LocationList[i-1].name[0]);
}
}
}
return "";
};
};
extern LocationManager LocationMan;
#endif // LOCATIONMANAGER_H

View File

@ -10,173 +10,173 @@
//
// Natural Selection Module
//
/* This file contains the initialization routine and message hooks
* for the message handler. Note that all of the message hooks
* except for MessageBegin_Post are NOT hooked unless the gameDLL
* is sending a message we care about.
*/
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "MessageHandler.h"
MessageHandler *MessageLists[256];
MessageHandler *HookedMessage;
bool MessageHandler_Initialized=false;
// This is called through ServerActivate_Post
void Initialize_MessageHandler(void)
{
if (MessageHandler_Initialized)
{
return;
}
MessageHandler_Initialized=true;
int i=0;
while (i<255)
{
MessageLists[i++]=NULL;
};
// Hook our messages
int index;
index=GET_USER_MSG_ID(&Plugin_info,"Countdown",NULL);
if (index)
{
MessageLists[index]=new MessageCountDown;
}
index=GET_USER_MSG_ID(&Plugin_info,"GameStatus",NULL);
if (index)
{
MessageLists[index]=new MessageGameStatus;
}
#if 0
index=GET_USER_MSG_ID(&Plugin_info,"Particles",NULL);
if (index)
{
MessageLists[index]=new MessageDebug;
}
#endif
// Start hooking messagebegin_post
g_pengfuncsTable_Post->pfnMessageBegin=MessageBegin_Post;
};
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
// Sanity check, should never matter
if (msg_type < 0 || msg_type > 255)
{
RETURN_META(MRES_IGNORED);
}
// Has a hooked message?
if (MessageLists[msg_type]!=NULL)
{
// Should this message be hooked?
if (MessageLists[msg_type]->Begin(msg_dest,msg_type,pOrigin,ed)==1)
{
// This message is going to all be hooked
// save pointer to our class
HookedMessage=MessageLists[msg_type];
// Tell metamod to forward
g_pengfuncsTable_Post->pfnWriteByte=WriteByte_Post;
g_pengfuncsTable_Post->pfnWriteChar=WriteChar_Post;
g_pengfuncsTable_Post->pfnWriteShort=WriteShort_Post;
g_pengfuncsTable_Post->pfnWriteLong=WriteLong_Post;
g_pengfuncsTable_Post->pfnWriteAngle=WriteAngle_Post;
g_pengfuncsTable_Post->pfnWriteCoord=WriteCoord_Post;
g_pengfuncsTable_Post->pfnWriteString=WriteString_Post;
g_pengfuncsTable_Post->pfnWriteEntity=WriteEntity_Post;
g_pengfuncsTable_Post->pfnMessageEnd=MessageEnd_Post;
}
}
RETURN_META(MRES_IGNORED);
}
void MessageEnd_Post(void)
{
HookedMessage->End();
HookedMessage=NULL;
// Stop metamod forwarding
g_pengfuncsTable_Post->pfnWriteByte=NULL;
g_pengfuncsTable_Post->pfnWriteChar=NULL;
g_pengfuncsTable_Post->pfnWriteShort=NULL;
g_pengfuncsTable_Post->pfnWriteLong=NULL;
g_pengfuncsTable_Post->pfnWriteAngle=NULL;
g_pengfuncsTable_Post->pfnWriteCoord=NULL;
g_pengfuncsTable_Post->pfnWriteString=NULL;
g_pengfuncsTable_Post->pfnWriteEntity=NULL;
g_pengfuncsTable_Post->pfnMessageEnd=NULL;
RETURN_META(MRES_IGNORED);
};
void WriteByte_Post(int iValue)
{
HookedMessage->WriteByte(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteChar_Post(int iValue)
{
HookedMessage->WriteChar(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteShort_Post(int iValue)
{
HookedMessage->WriteShort(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteLong_Post(int iValue)
{
HookedMessage->WriteLong(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteAngle_Post(float flValue)
{
HookedMessage->WriteAngle(flValue);
RETURN_META(MRES_IGNORED);
};
void WriteCoord_Post(float flValue)
{
HookedMessage->WriteCoord(flValue);
RETURN_META(MRES_IGNORED);
};
void WriteString_Post(const char *sz)
{
HookedMessage->WriteString(sz);
RETURN_META(MRES_IGNORED);
};
void WriteEntity_Post(int iValue)
{
HookedMessage->WriteEntity(iValue);
RETURN_META(MRES_IGNORED);
};
/* This file contains the initialization routine and message hooks
* for the message handler. Note that all of the message hooks
* except for MessageBegin_Post are NOT hooked unless the gameDLL
* is sending a message we care about.
*/
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "MessageHandler.h"
MessageHandler *MessageLists[256];
MessageHandler *HookedMessage;
bool MessageHandler_Initialized=false;
// This is called through ServerActivate_Post
void Initialize_MessageHandler(void)
{
if (MessageHandler_Initialized)
{
return;
}
MessageHandler_Initialized=true;
int i=0;
while (i<255)
{
MessageLists[i++]=NULL;
};
// Hook our messages
int index;
index=GET_USER_MSG_ID(&Plugin_info,"Countdown",NULL);
if (index)
{
MessageLists[index]=new MessageCountDown;
}
index=GET_USER_MSG_ID(&Plugin_info,"GameStatus",NULL);
if (index)
{
MessageLists[index]=new MessageGameStatus;
}
#if 0
index=GET_USER_MSG_ID(&Plugin_info,"Particles",NULL);
if (index)
{
MessageLists[index]=new MessageDebug;
}
#endif
// Start hooking messagebegin_post
g_pengfuncsTable_Post->pfnMessageBegin=MessageBegin_Post;
};
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
// Sanity check, should never matter
if (msg_type < 0 || msg_type > 255)
{
RETURN_META(MRES_IGNORED);
}
// Has a hooked message?
if (MessageLists[msg_type]!=NULL)
{
// Should this message be hooked?
if (MessageLists[msg_type]->Begin(msg_dest,msg_type,pOrigin,ed)==1)
{
// This message is going to all be hooked
// save pointer to our class
HookedMessage=MessageLists[msg_type];
// Tell metamod to forward
g_pengfuncsTable_Post->pfnWriteByte=WriteByte_Post;
g_pengfuncsTable_Post->pfnWriteChar=WriteChar_Post;
g_pengfuncsTable_Post->pfnWriteShort=WriteShort_Post;
g_pengfuncsTable_Post->pfnWriteLong=WriteLong_Post;
g_pengfuncsTable_Post->pfnWriteAngle=WriteAngle_Post;
g_pengfuncsTable_Post->pfnWriteCoord=WriteCoord_Post;
g_pengfuncsTable_Post->pfnWriteString=WriteString_Post;
g_pengfuncsTable_Post->pfnWriteEntity=WriteEntity_Post;
g_pengfuncsTable_Post->pfnMessageEnd=MessageEnd_Post;
}
}
RETURN_META(MRES_IGNORED);
}
void MessageEnd_Post(void)
{
HookedMessage->End();
HookedMessage=NULL;
// Stop metamod forwarding
g_pengfuncsTable_Post->pfnWriteByte=NULL;
g_pengfuncsTable_Post->pfnWriteChar=NULL;
g_pengfuncsTable_Post->pfnWriteShort=NULL;
g_pengfuncsTable_Post->pfnWriteLong=NULL;
g_pengfuncsTable_Post->pfnWriteAngle=NULL;
g_pengfuncsTable_Post->pfnWriteCoord=NULL;
g_pengfuncsTable_Post->pfnWriteString=NULL;
g_pengfuncsTable_Post->pfnWriteEntity=NULL;
g_pengfuncsTable_Post->pfnMessageEnd=NULL;
RETURN_META(MRES_IGNORED);
};
void WriteByte_Post(int iValue)
{
HookedMessage->WriteByte(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteChar_Post(int iValue)
{
HookedMessage->WriteChar(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteShort_Post(int iValue)
{
HookedMessage->WriteShort(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteLong_Post(int iValue)
{
HookedMessage->WriteLong(iValue);
RETURN_META(MRES_IGNORED);
};
void WriteAngle_Post(float flValue)
{
HookedMessage->WriteAngle(flValue);
RETURN_META(MRES_IGNORED);
};
void WriteCoord_Post(float flValue)
{
HookedMessage->WriteCoord(flValue);
RETURN_META(MRES_IGNORED);
};
void WriteString_Post(const char *sz)
{
HookedMessage->WriteString(sz);
RETURN_META(MRES_IGNORED);
};
void WriteEntity_Post(int iValue)
{
HookedMessage->WriteEntity(iValue);
RETURN_META(MRES_IGNORED);
};

View File

@ -10,149 +10,149 @@
//
// Natural Selection Module
//
/* Class with virtual members for easy message handling
* Don't forget to add new messages to "Initialize_MessageHandler()"
*/
#ifndef MESSAGEHANDLER_H
#define MESSAGEHANDLER_H
#include "utilfunctions.h"
class MessageHandler
{
public:
unsigned int m_Count;
int m_Target;
float m_Origin[3];
edict_t *m_Entity;
int m_Msg;
/**
* Return 1 to hook the rest of this message, 0 otherwise
*/
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
return 0;
};
virtual void End(void)
{
return;
};
virtual void WriteByte(int Data)
{
++m_Count;
};
virtual void WriteChar(int Data)
{
++m_Count;
};
virtual void WriteShort(int Data)
{
++m_Count;
};
virtual void WriteLong(int Data)
{
++m_Count;
};
virtual void WriteAngle(REAL Data)
{
++m_Count;
};
virtual void WriteCoord(REAL Data)
{
++m_Count;
};
virtual void WriteString(const char *Data)
{
++m_Count;
};
virtual void WriteEntity(int Data)
{
++m_Count;
};
};
class MessageCountDown : public MessageHandler
{
public:
int m_CountDownTime;
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
m_Count=0;
return 1;
};
virtual void End(void)
{
if (m_Count!=1) // invalid message?
{
MF_Log("[NS] Invalid Countdown message received! Got %d args, expected 1.",m_Count);
return;
}
GameMan.HandleCountdown(m_CountDownTime);
};
virtual void WriteByte(int Data)
{
++m_Count;
m_CountDownTime=Data;
};
};
class MessageGameStatus : public MessageHandler
{
public:
int FirstByte;
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
m_Count=0;
return 1;
};
virtual void End(void)
{
GameMan.HandleGameStatus(FirstByte);
};
virtual void WriteByte(int iValue)
{
if (m_Count==0)
{
FirstByte=iValue;
};
++m_Count;
};
};
void Initialize_MessageHandler(void);
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
void MessageEnd_Post(void);
void WriteByte_Post(int iValue);
void WriteChar_Post(int iValue);
void WriteShort_Post(int iValue);
void WriteLong_Post(int iValue);
void WriteAngle_Post(float flValue);
void WriteCoord_Post(float flValue);
void WriteString_Post(const char *sz);
void WriteEntity_Post(int iValue);
#endif // MESSAGEHANDLER_H
/* Class with virtual members for easy message handling
* Don't forget to add new messages to "Initialize_MessageHandler()"
*/
#ifndef MESSAGEHANDLER_H
#define MESSAGEHANDLER_H
#include "utilfunctions.h"
class MessageHandler
{
public:
unsigned int m_Count;
int m_Target;
float m_Origin[3];
edict_t *m_Entity;
int m_Msg;
/**
* Return 1 to hook the rest of this message, 0 otherwise
*/
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
return 0;
};
virtual void End(void)
{
return;
};
virtual void WriteByte(int Data)
{
++m_Count;
};
virtual void WriteChar(int Data)
{
++m_Count;
};
virtual void WriteShort(int Data)
{
++m_Count;
};
virtual void WriteLong(int Data)
{
++m_Count;
};
virtual void WriteAngle(REAL Data)
{
++m_Count;
};
virtual void WriteCoord(REAL Data)
{
++m_Count;
};
virtual void WriteString(const char *Data)
{
++m_Count;
};
virtual void WriteEntity(int Data)
{
++m_Count;
};
};
class MessageCountDown : public MessageHandler
{
public:
int m_CountDownTime;
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
m_Count=0;
return 1;
};
virtual void End(void)
{
if (m_Count!=1) // invalid message?
{
MF_Log("[NS] Invalid Countdown message received! Got %d args, expected 1.",m_Count);
return;
}
GameMan.HandleCountdown(m_CountDownTime);
};
virtual void WriteByte(int Data)
{
++m_Count;
m_CountDownTime=Data;
};
};
class MessageGameStatus : public MessageHandler
{
public:
int FirstByte;
virtual int Begin(int Target, int Msg, const float *Origin, edict_t *Entity)
{
m_Count=0;
return 1;
};
virtual void End(void)
{
GameMan.HandleGameStatus(FirstByte);
};
virtual void WriteByte(int iValue)
{
if (m_Count==0)
{
FirstByte=iValue;
};
++m_Count;
};
};
void Initialize_MessageHandler(void);
void MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
void MessageEnd_Post(void);
void WriteByte_Post(int iValue);
void WriteChar_Post(int iValue);
void WriteShort_Post(int iValue);
void WriteLong_Post(int iValue);
void WriteAngle_Post(float flValue);
void WriteCoord_Post(float flValue);
void WriteString_Post(const char *sz);
void WriteEntity_Post(int iValue);
#endif // MESSAGEHANDLER_H

View File

@ -10,71 +10,71 @@
//
// Natural Selection Module
//
/* Inlined replacements for INDEXENT/ENTINDEX
* It only really removes the overhead of the push/jump
* but since INDEXENT/ENTINDEX are used a lot with amxx
* it might be beneficial to include.
* NOTE: Bad stuff will happen if you call these before
* NEW_Initialize()
* NOTE: No bounds checking is done because natives
* should use their own bounds checking!
*/
#ifndef NEW_UTIL_H
#define NEW_UTIL_H
extern edict_t *NEW_FirstEdict;
extern bool NEW_Initialized;
/**
* This is called on the first Spawn() ever hooked. This would be worldspawn (index 0)
*/
inline void NEW_Initialize(edict_t *Entity)
{
// call the HL Engine ENTINDEX to make sure this is index 0
int index=ENTINDEX(Entity);
if (index==0)
{
NEW_FirstEdict=Entity;
NEW_Initialized=true;
return;
}
// This is not worldspawn?
// compensate
NEW_FirstEdict=Entity - index;
NEW_Initialized=true;
}
/**
* Converts an integer index into an edict pointer
*/
inline edict_t *INDEXENT_NEW(const int Index)
{
return (edict_t *)(NEW_FirstEdict + Index);
};
/**
* Converts an edict pointer into an integer index
*/
inline int ENTINDEX_NEW(const edict_t *Ent)
{
return (int)(Ent - NEW_FirstEdict);
};
// Inlined replacement of MF_GetAmxAddr
// straight from amxmodx's string.cpp; no need for this to be an api call
inline cell *MF_GetAmxAddr_NEW(AMX *amx, cell amx_addr)
{
return (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr));
};
#endif // NEW_UTIL_H
/* Inlined replacements for INDEXENT/ENTINDEX
* It only really removes the overhead of the push/jump
* but since INDEXENT/ENTINDEX are used a lot with amxx
* it might be beneficial to include.
* NOTE: Bad stuff will happen if you call these before
* NEW_Initialize()
* NOTE: No bounds checking is done because natives
* should use their own bounds checking!
*/
#ifndef NEW_UTIL_H
#define NEW_UTIL_H
extern edict_t *NEW_FirstEdict;
extern bool NEW_Initialized;
/**
* This is called on the first Spawn() ever hooked. This would be worldspawn (index 0)
*/
inline void NEW_Initialize(edict_t *Entity)
{
// call the HL Engine ENTINDEX to make sure this is index 0
int index=ENTINDEX(Entity);
if (index==0)
{
NEW_FirstEdict=Entity;
NEW_Initialized=true;
return;
}
// This is not worldspawn?
// compensate
NEW_FirstEdict=Entity - index;
NEW_Initialized=true;
}
/**
* Converts an integer index into an edict pointer
*/
inline edict_t *INDEXENT_NEW(const int Index)
{
return (edict_t *)(NEW_FirstEdict + Index);
};
/**
* Converts an edict pointer into an integer index
*/
inline int ENTINDEX_NEW(const edict_t *Ent)
{
return (int)(Ent - NEW_FirstEdict);
};
// Inlined replacement of MF_GetAmxAddr
// straight from amxmodx's string.cpp; no need for this to be an api call
inline cell *MF_GetAmxAddr_NEW(AMX *amx, cell amx_addr)
{
return (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr));
};
#endif // NEW_UTIL_H

View File

@ -11,119 +11,119 @@
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "ParticleManager.h"
void ParticleManager::ReadFile(void)
{
this->Prune();
if (m_iFileLoaded!=0)
{
return;
}
m_iFileLoaded=1;
char FileName[256];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname());
FILE *fp=fopen(FileName,"r");
if (!fp)
{
MF_Log("ParticleManager: Cannot open \"%s\" for reading!",FileName);
return;
}
// Since I don't care about the actual parameters of each
// particle system, just their order and name
// I only have to scan for "start pSystemName NAME"
char Buffer[1024];
char *Start;
char *End;
int Count=0;
memset(&Buffer[0],0x0,sizeof(Buffer));
while (!feof(fp))
{
Buffer[0]='\0';
fgets(Buffer,1023,fp);
Start=&Buffer[0];
// strip whitespace from the front
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
// if the first character is ' ignore it
if (*Start=='\'')
{
continue;
}
// if the first word is "start" then this is a line we want
if (strncmp("start ",Start,6)!=0)
{
continue;
}
// Move up past 2 space blocks
while (*Start!='\0' &&
*Start!=' ' &&
*Start!='\t')
{
++Start;
}
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
while (*Start!='\0' &&
*Start!=' ' &&
*Start!='\t')
{
++Start;
}
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
// now strip whitespace from the end
End=Start+strlen(Start)-1;
while (*End=='\n' ||
*End=='\r' ||
*End==' ' ||
*End=='\t')
{
*End--='\0';
}
// "Start" should now point to the name of this particle system
//printf("Particle system %d = \"%s\"\n",Count,Start);
this->Add(Start,1);
++Count;
}
fclose(fp);
};
#include "amxxmodule.h"
#include "ns.h"
#include "ParticleManager.h"
void ParticleManager::ReadFile(void)
{
this->Prune();
if (m_iFileLoaded!=0)
{
return;
}
m_iFileLoaded=1;
char FileName[256];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname());
FILE *fp=fopen(FileName,"r");
if (!fp)
{
MF_Log("ParticleManager: Cannot open \"%s\" for reading!",FileName);
return;
}
// Since I don't care about the actual parameters of each
// particle system, just their order and name
// I only have to scan for "start pSystemName NAME"
char Buffer[1024];
char *Start;
char *End;
int Count=0;
memset(&Buffer[0],0x0,sizeof(Buffer));
while (!feof(fp))
{
Buffer[0]='\0';
fgets(Buffer,1023,fp);
Start=&Buffer[0];
// strip whitespace from the front
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
// if the first character is ' ignore it
if (*Start=='\'')
{
continue;
}
// if the first word is "start" then this is a line we want
if (strncmp("start ",Start,6)!=0)
{
continue;
}
// Move up past 2 space blocks
while (*Start!='\0' &&
*Start!=' ' &&
*Start!='\t')
{
++Start;
}
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
while (*Start!='\0' &&
*Start!=' ' &&
*Start!='\t')
{
++Start;
}
while (*Start==' ' ||
*Start=='\t')
{
++Start;
}
// now strip whitespace from the end
End=Start+strlen(Start)-1;
while (*End=='\n' ||
*End=='\r' ||
*End==' ' ||
*End=='\t')
{
*End--='\0';
}
// "Start" should now point to the name of this particle system
//printf("Particle system %d = \"%s\"\n",Count,Start);
this->Add(Start,1);
++Count;
}
fclose(fp);
};

View File

@ -10,115 +10,115 @@
//
// Natural Selection Module
//
#ifndef PARTICLEMANAGER_H
#define PARTICLEMANAGER_H
#include <am-vector.h>
#include <am-string.h>
typedef struct psystem_s
{
ke::AString Name;
int id;
int IsStatic; // Set to 1 if the particle system is loaded from ns.ps
} ParticleSystem;
class ParticleManager
{
private:
ke::Vector<ParticleSystem *> Systems;
int m_iFileLoaded;
unsigned short m_iEventID;
public:
ParticleManager()
{
m_iFileLoaded=0;
m_iEventID=0;
Systems.ensure(64);
};
// Remove all non-static particle systems
inline void Prune()
{
for (size_t i = 0; i < Systems.length(); ++i)
{
if (Systems[i]->IsStatic)
{
break;
}
Systems.remove(i);
delete Systems.at(i);
if (!Systems.length())
{
break;
}
}
};
void ReadFile(void);
inline int Add(const char *Start, int Static)
{
ParticleSystem *ps=new ParticleSystem;
ps->id=Systems.length();
ps->IsStatic=Static;
ps->Name = Start;
Systems.append(ps);
return Systems.length()-1;
};
inline void FireSystem(int id, float *Origin, float *Angles, int flags)
{
PLAYBACK_EVENT_FULL(flags, /*flags*/
NULL, /*pInvoker*/
m_iEventID, /*eventid*/
0.0, /*delay*/
Origin, /*origin*/
Angles, /*angles*/
0.0, /*fparam1*/
0.0, /*fparam2*/
id, /*iparam1 - particle system id*/
0, /*iparam2*/
0, /*bparam1*/
0); /*bparam2*/
};
inline void PrecacheEvent(const char *file)
{
if (strcmp(file,"events/Particle.sc")==0)
{
if (META_RESULT_STATUS >= MRES_OVERRIDE)
{
m_iEventID=META_RESULT_OVERRIDE_RET(unsigned short);
}
else
{
m_iEventID=META_RESULT_ORIG_RET(unsigned short);
}
//printf("EVENT=%d\n",m_iEventID);
}
};
inline int Find(const char *Needle)
{
for (size_t i = 0; i < Systems.length(); ++i)
{
if (strcmp(Needle, Systems[i]->Name.chars()) == 0)
{
return Systems[i]->id;
}
}
return -1;
};
};
extern ParticleManager ParticleMan;
#endif // PARTICLEMANAGER_H
#ifndef PARTICLEMANAGER_H
#define PARTICLEMANAGER_H
#include <am-vector.h>
#include <am-string.h>
typedef struct psystem_s
{
ke::AString Name;
int id;
int IsStatic; // Set to 1 if the particle system is loaded from ns.ps
} ParticleSystem;
class ParticleManager
{
private:
ke::Vector<ParticleSystem *> Systems;
int m_iFileLoaded;
unsigned short m_iEventID;
public:
ParticleManager()
{
m_iFileLoaded=0;
m_iEventID=0;
Systems.ensure(64);
};
// Remove all non-static particle systems
inline void Prune()
{
for (size_t i = 0; i < Systems.length(); ++i)
{
if (Systems[i]->IsStatic)
{
break;
}
Systems.remove(i);
delete Systems.at(i);
if (!Systems.length())
{
break;
}
}
};
void ReadFile(void);
inline int Add(const char *Start, int Static)
{
ParticleSystem *ps=new ParticleSystem;
ps->id=Systems.length();
ps->IsStatic=Static;
ps->Name = Start;
Systems.append(ps);
return Systems.length()-1;
};
inline void FireSystem(int id, float *Origin, float *Angles, int flags)
{
PLAYBACK_EVENT_FULL(flags, /*flags*/
NULL, /*pInvoker*/
m_iEventID, /*eventid*/
0.0, /*delay*/
Origin, /*origin*/
Angles, /*angles*/
0.0, /*fparam1*/
0.0, /*fparam2*/
id, /*iparam1 - particle system id*/
0, /*iparam2*/
0, /*bparam1*/
0); /*bparam2*/
};
inline void PrecacheEvent(const char *file)
{
if (strcmp(file,"events/Particle.sc")==0)
{
if (META_RESULT_STATUS >= MRES_OVERRIDE)
{
m_iEventID=META_RESULT_OVERRIDE_RET(unsigned short);
}
else
{
m_iEventID=META_RESULT_ORIG_RET(unsigned short);
}
//printf("EVENT=%d\n",m_iEventID);
}
};
inline int Find(const char *Needle)
{
for (size_t i = 0; i < Systems.length(); ++i)
{
if (strcmp(Needle, Systems[i]->Name.chars()) == 0)
{
return Systems[i]->id;
}
}
return -1;
};
};
extern ParticleManager ParticleMan;
#endif // PARTICLEMANAGER_H

View File

@ -10,99 +10,99 @@
//
// Natural Selection Module
//
#ifndef SPAWNMANAGER_H
#define SPAWNMANAGER_H
#include <am-vector.h>
typedef struct spawndata_s
{
REAL Location[3];
REAL Angle[3];
} SpawnData;
class SpawnManager
{
private:
ke::Vector<SpawnData> TeamSpawns[5];
public:
SpawnManager()
{
this->Clear();
};
inline void Clear(void)
{
TeamSpawns[0].clear();
TeamSpawns[1].clear();
TeamSpawns[2].clear();
TeamSpawns[3].clear();
TeamSpawns[4].clear();
// Reserve data for a "typical" map layout
// makes data entry faster on map load
TeamSpawns[0].ensure(32);
TeamSpawns[1].ensure(16);
TeamSpawns[2].ensure(48);
};
inline void Insert(const edict_t *Entity)
{
// Bounds check team
if (Entity->v.team<0 || Entity->v.team > 4)
{
return;
}
SpawnData TemporaryData;
Entity->v.origin.CopyToArray(TemporaryData.Location);
Entity->v.angles.CopyToArray(TemporaryData.Angle);
TeamSpawns[Entity->v.team].append(TemporaryData);
};
inline void InsertReadyRoom(const edict_t *Entity)
{
SpawnData TemporaryData;
Entity->v.origin.CopyToArray(TemporaryData.Location);
Entity->v.angles.CopyToArray(TemporaryData.Angle);
TeamSpawns[0].append(TemporaryData);
};
// ns_get_spawn(team,number=0,Float:ret[3]);
inline cell Lookup(AMX *amx, cell *params)
{
if (params[1] < 0 || params[1] > 4)
{
return 0;
}
if (params[2]==0)
{
return static_cast<int>(TeamSpawns[params[1]].length());
}
if (params[2]>=(int)TeamSpawns[params[1]].length())
{
return 0;
}
cell *Return=MF_GetAmxAddr(amx,params[3]);
SpawnData SpawnRet=TeamSpawns[params[1]][params[2]];
Return[0]=amx_ftoc2(SpawnRet.Location[0]);
Return[1]=amx_ftoc2(SpawnRet.Location[1]);
Return[2]=amx_ftoc2(SpawnRet.Location[2]);
return 1;
};
};
extern SpawnManager SpawnMan;
#endif // SPAWNMANAGER_H
#ifndef SPAWNMANAGER_H
#define SPAWNMANAGER_H
#include <am-vector.h>
typedef struct spawndata_s
{
REAL Location[3];
REAL Angle[3];
} SpawnData;
class SpawnManager
{
private:
ke::Vector<SpawnData> TeamSpawns[5];
public:
SpawnManager()
{
this->Clear();
};
inline void Clear(void)
{
TeamSpawns[0].clear();
TeamSpawns[1].clear();
TeamSpawns[2].clear();
TeamSpawns[3].clear();
TeamSpawns[4].clear();
// Reserve data for a "typical" map layout
// makes data entry faster on map load
TeamSpawns[0].ensure(32);
TeamSpawns[1].ensure(16);
TeamSpawns[2].ensure(48);
};
inline void Insert(const edict_t *Entity)
{
// Bounds check team
if (Entity->v.team<0 || Entity->v.team > 4)
{
return;
}
SpawnData TemporaryData;
Entity->v.origin.CopyToArray(TemporaryData.Location);
Entity->v.angles.CopyToArray(TemporaryData.Angle);
TeamSpawns[Entity->v.team].append(TemporaryData);
};
inline void InsertReadyRoom(const edict_t *Entity)
{
SpawnData TemporaryData;
Entity->v.origin.CopyToArray(TemporaryData.Location);
Entity->v.angles.CopyToArray(TemporaryData.Angle);
TeamSpawns[0].append(TemporaryData);
};
// ns_get_spawn(team,number=0,Float:ret[3]);
inline cell Lookup(AMX *amx, cell *params)
{
if (params[1] < 0 || params[1] > 4)
{
return 0;
}
if (params[2]==0)
{
return static_cast<int>(TeamSpawns[params[1]].length());
}
if (params[2]>=(int)TeamSpawns[params[1]].length())
{
return 0;
}
cell *Return=MF_GetAmxAddr(amx,params[3]);
SpawnData SpawnRet=TeamSpawns[params[1]][params[2]];
Return[0]=amx_ftoc2(SpawnRet.Location[0]);
Return[1]=amx_ftoc2(SpawnRet.Location[1]);
Return[2]=amx_ftoc2(SpawnRet.Location[2]);
return 1;
};
};
extern SpawnManager SpawnMan;
#endif // SPAWNMANAGER_H

View File

@ -11,143 +11,143 @@
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "TitleManager.h"
#include "utilfunctions.h"
void TitleManager::LoadTitles(void)
{
if (m_Loaded!=0) // already loaded?
{
return;
}
m_Loaded=1;
char FileName[128];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname());
FILE *fp=fopen(FileName,"r");
if (!fp)
{
MF_Log("Unable to load \"%s\": TitleManager will not work!",FileName);
return;
};
//MF_Log("TitleManager Loading titles from \"%s\"",FileName);
char KeyName[512]; // last known good keyname
char Data[2048]; // data for the key
// does not support multi line data, but for
// location namesthat is acceptable.
char TempBuffer[2048]; // currently read data
char *TempPointer;
char *TempPointerEnd;
unsigned int Line=0;
scan_for_key:
KeyName[0]='\0';
while (!feof(fp))
{
Line++;
fgets(TempBuffer,2047,fp);
TempPointer=&TempBuffer[0];
// get rid of white space at the front
while (*TempPointer=='\0' || // terminator
*TempPointer==' ' || // space
*TempPointer=='\t') // tab
{
++TempPointer;
}
if (*TempPointer=='\0' || // terminator
*TempPointer=='/') // comment
{
continue;
}
// get rid of \r\n at the end
TempPointerEnd=TempPointer+strlen(TempPointer)-1;
while (*TempPointerEnd=='\r' ||
*TempPointerEnd=='\n' ||
*TempPointerEnd=='\t' ||
*TempPointerEnd==' ')
{
*TempPointerEnd--='\0';
}
if (*TempPointer=='{') // start of data
{
if (KeyName[0]!='\0') // do we have a keyname
{
goto scan_for_data;
}
else
{
MF_Log("TitleManager: titles.txt line %u: began a data section with no key name in use!",Line);
goto scan_for_key;
}
}
// have a valid key name here
strncpy(KeyName,TempBuffer,sizeof(KeyName)-1);
// keep looping (until we hit a '{')
};
// if we're out here then !feof() failed
goto end_of_file;
scan_for_data:
Data[0]='\0';
while (!feof(fp))
{
Line++;
fgets(TempBuffer,2047,fp);
TempPointer=&TempBuffer[0];
// get rid of white space at the front
while (*TempPointer=='\0' || // terminator
*TempPointer==' ' || // space
*TempPointer=='\t') // tab
{
++TempPointer;
}
if (*TempPointer=='\0' || // terminator
*TempPointer=='/') // comment
{
continue;
}
// get rid of trailing whitespace
TempPointerEnd=TempPointer+strlen(TempPointer)-1;
while (*TempPointerEnd=='\r' ||
*TempPointerEnd=='\n' ||
*TempPointerEnd=='\t' ||
*TempPointerEnd==' ')
{
*TempPointerEnd--='\0';
}
if (*TempPointer=='}') // end of data
{
// insert KeyName & Data into the hash
ke::AString key(UTIL_ToLowerCase(KeyName));
this->m_Hash.insert(key, new ke::AString(Data));
goto scan_for_key;
}
// have valid data here
strncpy(Data,TempBuffer,sizeof(Data)-1);
};
end_of_file:
fclose(fp);
//MF_Log("TitleManager loaded %u entries from titles.txt (%u lines parsed)",m_List.size(),Line);
};
#include "amxxmodule.h"
#include "ns.h"
#include "TitleManager.h"
#include "utilfunctions.h"
void TitleManager::LoadTitles(void)
{
if (m_Loaded!=0) // already loaded?
{
return;
}
m_Loaded=1;
char FileName[128];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname());
FILE *fp=fopen(FileName,"r");
if (!fp)
{
MF_Log("Unable to load \"%s\": TitleManager will not work!",FileName);
return;
};
//MF_Log("TitleManager Loading titles from \"%s\"",FileName);
char KeyName[512]; // last known good keyname
char Data[2048]; // data for the key
// does not support multi line data, but for
// location namesthat is acceptable.
char TempBuffer[2048]; // currently read data
char *TempPointer;
char *TempPointerEnd;
unsigned int Line=0;
scan_for_key:
KeyName[0]='\0';
while (!feof(fp))
{
Line++;
fgets(TempBuffer,2047,fp);
TempPointer=&TempBuffer[0];
// get rid of white space at the front
while (*TempPointer=='\0' || // terminator
*TempPointer==' ' || // space
*TempPointer=='\t') // tab
{
++TempPointer;
}
if (*TempPointer=='\0' || // terminator
*TempPointer=='/') // comment
{
continue;
}
// get rid of \r\n at the end
TempPointerEnd=TempPointer+strlen(TempPointer)-1;
while (*TempPointerEnd=='\r' ||
*TempPointerEnd=='\n' ||
*TempPointerEnd=='\t' ||
*TempPointerEnd==' ')
{
*TempPointerEnd--='\0';
}
if (*TempPointer=='{') // start of data
{
if (KeyName[0]!='\0') // do we have a keyname
{
goto scan_for_data;
}
else
{
MF_Log("TitleManager: titles.txt line %u: began a data section with no key name in use!",Line);
goto scan_for_key;
}
}
// have a valid key name here
strncpy(KeyName,TempBuffer,sizeof(KeyName)-1);
// keep looping (until we hit a '{')
};
// if we're out here then !feof() failed
goto end_of_file;
scan_for_data:
Data[0]='\0';
while (!feof(fp))
{
Line++;
fgets(TempBuffer,2047,fp);
TempPointer=&TempBuffer[0];
// get rid of white space at the front
while (*TempPointer=='\0' || // terminator
*TempPointer==' ' || // space
*TempPointer=='\t') // tab
{
++TempPointer;
}
if (*TempPointer=='\0' || // terminator
*TempPointer=='/') // comment
{
continue;
}
// get rid of trailing whitespace
TempPointerEnd=TempPointer+strlen(TempPointer)-1;
while (*TempPointerEnd=='\r' ||
*TempPointerEnd=='\n' ||
*TempPointerEnd=='\t' ||
*TempPointerEnd==' ')
{
*TempPointerEnd--='\0';
}
if (*TempPointer=='}') // end of data
{
// insert KeyName & Data into the hash
ke::AString key(UTIL_ToLowerCase(KeyName));
this->m_Hash.insert(key, new ke::AString(Data));
goto scan_for_key;
}
// have valid data here
strncpy(Data,TempBuffer,sizeof(Data)-1);
};
end_of_file:
fclose(fp);
//MF_Log("TitleManager loaded %u entries from titles.txt (%u lines parsed)",m_List.size(),Line);
};

View File

@ -10,49 +10,49 @@
//
// Natural Selection Module
//
#ifndef TITLEMANAGER_H
#define TITLEMANAGER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <am-string.h>
#include "Hash.h"
class TitleManager
{
private:
int m_Loaded;
// Use a string pointer for the data type because the location manager
// stores a direct pointer to the c_str() of the title
Hash<ke::AString, ke::AString*> m_Hash;
public:
TitleManager()
{
m_Loaded=0;
};
inline const char *Lookup(ke::AString &input)
{
ke::AString** ret = m_Hash.find(input);
if (ret == NULL || *ret == NULL)
{
// was not found
return NULL;
}
return (*ret)->chars();
};
void LoadTitles(void);
};
extern TitleManager TitleMan;
#endif // TITLEMANAGER_H
#ifndef TITLEMANAGER_H
#define TITLEMANAGER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <am-string.h>
#include "Hash.h"
class TitleManager
{
private:
int m_Loaded;
// Use a string pointer for the data type because the location manager
// stores a direct pointer to the c_str() of the title
Hash<ke::AString, ke::AString*> m_Hash;
public:
TitleManager()
{
m_Loaded=0;
};
inline const char *Lookup(ke::AString &input)
{
ke::AString** ret = m_Hash.find(input);
if (ret == NULL || *ret == NULL)
{
// was not found
return NULL;
}
return (*ret)->chars();
};
void LoadTitles(void);
};
extern TitleManager TitleMan;
#endif // TITLEMANAGER_H

View File

@ -10,82 +10,82 @@
//
// Natural Selection Module
//
/* Calls sent by AMX Mod X are handled here */
#include "sdk/amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "TitleManager.h"
#include "MessageHandler.h"
#include "ParticleManager.h"
#include "AllocString.h"
extern int gmsgHudText2;
extern BOOL iscombat;
TitleManager TitleMan;
ParticleManager ParticleMan;
void MFuncs_Initialize(void);
// Native register calls here
void AddNatives_MemberFunc();
void AddNatives_Particles();
void AddNatives_Player();
void AddNatives_PlayerMemory();
void AddNatives_Weapons();
void AddNatives_Structure();
void AddNatives_General();
// All plugins have loaded (called during spawning worldspawn)
void OnPluginsLoaded()
{
// This message is used for the ns_popup native
GameMan.GetMessageIDs();
// Check the map name and see if it's combat or not.
GameMan.EvaluateCombat();
GameMan.RegisterForwards();
GameMan.CheckAllHooks();
AllocStringList.Clear();
TitleMan.LoadTitles();
GameMan.CheckMap();
ParticleMan.ReadFile();
}
int AmxxCheckGame(const char *game)
{
if (strcasecmp(game, "ns") == 0 ||
strcasecmp(game, "nsp") == 0)
{
return AMXX_GAME_OK;
}
return AMXX_GAME_BAD;
}
// Module is attaching to AMXX
void OnAmxxAttach()
{
AddNatives_MemberFunc();
AddNatives_Particles();
AddNatives_Player();
AddNatives_PlayerMemory();
AddNatives_Weapons();
AddNatives_Structure();
AddNatives_General();
MFuncs_Initialize();
}
/* Calls sent by AMX Mod X are handled here */
#include "sdk/amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "TitleManager.h"
#include "MessageHandler.h"
#include "ParticleManager.h"
#include "AllocString.h"
extern int gmsgHudText2;
extern BOOL iscombat;
TitleManager TitleMan;
ParticleManager ParticleMan;
void MFuncs_Initialize(void);
// Native register calls here
void AddNatives_MemberFunc();
void AddNatives_Particles();
void AddNatives_Player();
void AddNatives_PlayerMemory();
void AddNatives_Weapons();
void AddNatives_Structure();
void AddNatives_General();
// All plugins have loaded (called during spawning worldspawn)
void OnPluginsLoaded()
{
// This message is used for the ns_popup native
GameMan.GetMessageIDs();
// Check the map name and see if it's combat or not.
GameMan.EvaluateCombat();
GameMan.RegisterForwards();
GameMan.CheckAllHooks();
AllocStringList.Clear();
TitleMan.LoadTitles();
GameMan.CheckMap();
ParticleMan.ReadFile();
}
int AmxxCheckGame(const char *game)
{
if (strcasecmp(game, "ns") == 0 ||
strcasecmp(game, "nsp") == 0)
{
return AMXX_GAME_OK;
}
return AMXX_GAME_BAD;
}
// Module is attaching to AMXX
void OnAmxxAttach()
{
AddNatives_MemberFunc();
AddNatives_Particles();
AddNatives_Player();
AddNatives_PlayerMemory();
AddNatives_Weapons();
AddNatives_Structure();
AddNatives_General();
MFuncs_Initialize();
}

View File

@ -10,205 +10,205 @@
//
// Natural Selection Module
//
/* Calls going from the engine to the game dll are handled here */
#ifndef HAVE_STDINT_H
#define HAVE_STDINT_H
#endif
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "SpawnManager.h"
#include "GameManager.h"
#include "CPlayer.h"
#include "MessageHandler.h"
#include "LocationManager.h"
#include "ParticleManager.h"
LocationManager LocationMan;
GameManager GameMan;
SpawnManager SpawnMan;
extern edict_t* avhgameplay;
CPlayer g_player[33];
extern void *GameRules;
bool NEW_Initialized=false;
edict_t *NEW_FirstEdict=NULL;
/**
* This is only called during the CountDown
* This call will unhook itself with Metamod
* when it is finished.
*/
void StartFrame()
{
GameMan.StartFrame();
RETURN_META(MRES_IGNORED);
}
/**
* Check spawning for:
* - Worldspawn
* - Initialize NEW_Utilities
* - Clear CPlayer / CSpawn data
* - info_team_start (team spawn point)
* - Save in list
* - info_player_start (ready room spawn point)
* - Save in list
*/
int DispatchSpawn(edict_t *pEntity)
{
if (!NEW_Initialized)
{
NEW_Initialize(pEntity);
}
if (ENTINDEX_NEW(pEntity)==0) // worldspawn
{
int i=0;
while (i<=32)
{
GET_PLAYER_I(i++)->Reset();
}
LocationMan.Clear();
SpawnMan.Clear();
}
else if (FStrEq(STRING(pEntity->v.classname),"info_player_start"))
{
// Mark down the ready room spawn point.
SpawnMan.InsertReadyRoom(pEntity);
}
else if (FStrEq(STRING(pEntity->v.classname),"info_team_start"))
{
// Mark down the team based spawn point.
SpawnMan.Insert(pEntity);
}
else if (FStrEq(STRING(pEntity->v.classname),"env_particles_custom"))
{
ParticleMan.Add(STRING(pEntity->v.targetname),0);
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
void DispatchKeyValue(edict_t *pEntity,KeyValueData *pkvd)
{
if (strcmp(pkvd->szKeyName,"locationname")==0)
{
if (pkvd->szClassName && strcmp(pkvd->szClassName,"info_location")==0)
{
// this is a BSP model, so calling SetModel
// will update the mins/maxs
SET_MODEL(pEntity,STRING(pEntity->v.model));
// Add it to our list
LocationMan.Add(pkvd->szValue,pEntity);
RETURN_META(MRES_IGNORED);
}
}
RETURN_META(MRES_IGNORED);
}
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
// Reset CPlayer classes (again?)
for(int i = 1; i <= gpGlobals->maxClients;i++)
{
CPlayer *player=GET_PLAYER_I(i);
player->FullReset();
player->SetEdict(pEdictList + i);
}
GameRules=NULL;
RETURN_META(MRES_IGNORED);
}
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
{
Initialize_MessageHandler();
g_pFunctionTable_Post->pfnServerActivate=NULL;
RETURN_META(MRES_IGNORED);
}
/**
* PlayerPreThink, PlayerPreThink_Post and PlayerPostThink_Post
* all disable their Metamod hook calls when they are no longer needed.
* (Actually it is disabled in the native calls)
*/
void PlayerPreThink(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PreThink();
RETURN_META(MRES_IGNORED);
}
void PlayerPreThink_Post(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PreThink_Post();
RETURN_META(MRES_IGNORED);
}
void PlayerPostThink_Post(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PostThink_Post();
RETURN_META(MRES_IGNORED);
}
// Map is changing/server is shutting down.
// We do all cleanup routines here, since, as noted in metamod's dllapi
// ServerDeactivate is the very last function called before the server loads up a new map.
void ServerDeactivate(void)
{
for (int i=1;i<=gpGlobals->maxClients;i++)
{
GET_PLAYER_I(i)->Disconnect();
}
GameRules = NULL;
avhgameplay = NULL;
RETURN_META(MRES_IGNORED);
}
// Reset player data here..
qboolean ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ])
{
// Client's connecting. Freshen up his save data, and mark him as being connected.
GET_PLAYER_E(pEntity)->Connect();
RETURN_META_VALUE(MRES_HANDLED,0);
}
void ClientDisconnect(edict_t *pEntity)
{
// Client is disconnecting, clear all his saved information.
GET_PLAYER_E(pEntity)->Disconnect(1);
RETURN_META(MRES_HANDLED);
}
/**
* NS resets pev->fov every single frame, but this is called right before the data is sent to the client.
* Reset FOV if we need to.
* -
* NOTE: This function is not called if no clients have FoV changed
*/
void UpdateClientData( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd )
{
GET_PLAYER_E(const_cast<edict_t *>(static_cast<const edict_t *>(ent)))->UpdateFOV();
RETURN_META(MRES_HANDLED);
}
/* Calls going from the engine to the game dll are handled here */
#ifndef HAVE_STDINT_H
#define HAVE_STDINT_H
#endif
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "SpawnManager.h"
#include "GameManager.h"
#include "CPlayer.h"
#include "MessageHandler.h"
#include "LocationManager.h"
#include "ParticleManager.h"
LocationManager LocationMan;
GameManager GameMan;
SpawnManager SpawnMan;
extern edict_t* avhgameplay;
CPlayer g_player[33];
extern void *GameRules;
bool NEW_Initialized=false;
edict_t *NEW_FirstEdict=NULL;
/**
* This is only called during the CountDown
* This call will unhook itself with Metamod
* when it is finished.
*/
void StartFrame()
{
GameMan.StartFrame();
RETURN_META(MRES_IGNORED);
}
/**
* Check spawning for:
* - Worldspawn
* - Initialize NEW_Utilities
* - Clear CPlayer / CSpawn data
* - info_team_start (team spawn point)
* - Save in list
* - info_player_start (ready room spawn point)
* - Save in list
*/
int DispatchSpawn(edict_t *pEntity)
{
if (!NEW_Initialized)
{
NEW_Initialize(pEntity);
}
if (ENTINDEX_NEW(pEntity)==0) // worldspawn
{
int i=0;
while (i<=32)
{
GET_PLAYER_I(i++)->Reset();
}
LocationMan.Clear();
SpawnMan.Clear();
}
else if (FStrEq(STRING(pEntity->v.classname),"info_player_start"))
{
// Mark down the ready room spawn point.
SpawnMan.InsertReadyRoom(pEntity);
}
else if (FStrEq(STRING(pEntity->v.classname),"info_team_start"))
{
// Mark down the team based spawn point.
SpawnMan.Insert(pEntity);
}
else if (FStrEq(STRING(pEntity->v.classname),"env_particles_custom"))
{
ParticleMan.Add(STRING(pEntity->v.targetname),0);
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
void DispatchKeyValue(edict_t *pEntity,KeyValueData *pkvd)
{
if (strcmp(pkvd->szKeyName,"locationname")==0)
{
if (pkvd->szClassName && strcmp(pkvd->szClassName,"info_location")==0)
{
// this is a BSP model, so calling SetModel
// will update the mins/maxs
SET_MODEL(pEntity,STRING(pEntity->v.model));
// Add it to our list
LocationMan.Add(pkvd->szValue,pEntity);
RETURN_META(MRES_IGNORED);
}
}
RETURN_META(MRES_IGNORED);
}
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
// Reset CPlayer classes (again?)
for(int i = 1; i <= gpGlobals->maxClients;i++)
{
CPlayer *player=GET_PLAYER_I(i);
player->FullReset();
player->SetEdict(pEdictList + i);
}
GameRules=NULL;
RETURN_META(MRES_IGNORED);
}
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
{
Initialize_MessageHandler();
g_pFunctionTable_Post->pfnServerActivate=NULL;
RETURN_META(MRES_IGNORED);
}
/**
* PlayerPreThink, PlayerPreThink_Post and PlayerPostThink_Post
* all disable their Metamod hook calls when they are no longer needed.
* (Actually it is disabled in the native calls)
*/
void PlayerPreThink(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PreThink();
RETURN_META(MRES_IGNORED);
}
void PlayerPreThink_Post(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PreThink_Post();
RETURN_META(MRES_IGNORED);
}
void PlayerPostThink_Post(edict_t *pEntity)
{
GET_PLAYER_E(pEntity)->PostThink_Post();
RETURN_META(MRES_IGNORED);
}
// Map is changing/server is shutting down.
// We do all cleanup routines here, since, as noted in metamod's dllapi
// ServerDeactivate is the very last function called before the server loads up a new map.
void ServerDeactivate(void)
{
for (int i=1;i<=gpGlobals->maxClients;i++)
{
GET_PLAYER_I(i)->Disconnect();
}
GameRules = NULL;
avhgameplay = NULL;
RETURN_META(MRES_IGNORED);
}
// Reset player data here..
qboolean ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ])
{
// Client's connecting. Freshen up his save data, and mark him as being connected.
GET_PLAYER_E(pEntity)->Connect();
RETURN_META_VALUE(MRES_HANDLED,0);
}
void ClientDisconnect(edict_t *pEntity)
{
// Client is disconnecting, clear all his saved information.
GET_PLAYER_E(pEntity)->Disconnect(1);
RETURN_META(MRES_HANDLED);
}
/**
* NS resets pev->fov every single frame, but this is called right before the data is sent to the client.
* Reset FOV if we need to.
* -
* NOTE: This function is not called if no clients have FoV changed
*/
void UpdateClientData( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd )
{
GET_PLAYER_E(const_cast<edict_t *>(static_cast<const edict_t *>(ent)))->UpdateFOV();
RETURN_META(MRES_HANDLED);
}

View File

@ -10,283 +10,283 @@
//
// Natural Selection Module
//
/* Calls going from the game dll to the engine are handled here */
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "ParticleManager.h"
#include "CPlayer.h"
// Parse log messages here for any desired information (structure_built, etc.)
// The following logs are needed:
// "sawce<1><STEAM_0:1:4560311><alien1team>" triggered "structure_built" (type "defensechamber")`
void AlertMessage_Post(ALERT_TYPE atype, const char *szFmt, ...)
{
if (atype != at_logged)
{
RETURN_META(MRES_IGNORED);
}
char *MessageStart; // original pointer to start of the message
char *TypePointer; // pointer to the structure type
char *CIDPointer; // pointer to the name text
int CID; // connection ID of the player
va_list LogArgs;
va_start(LogArgs,szFmt);
MessageStart=va_arg(LogArgs,char *);
va_end(LogArgs);
if (MessageStart==NULL) // Somehow got a null pointer, get out of here now
{
RETURN_META(MRES_IGNORED);
}
if ((TypePointer=strstr(MessageStart,"\"structure_built\""))==NULL) // was not found
{
RETURN_META(MRES_IGNORED);
}
if (*(TypePointer - 2) != 'd') // If this is not from a 'triggered "structure_built"', then ignore the message
{
RETURN_META(MRES_IGNORED);
}
// If we got here, then for all we can tell this message is good
// Move up a few spaces
TypePointer+=25; // strlen("\"structure_built\" (type \"")=25
// Now get the player's CID
CIDPointer=MessageStart+1; // skip over the very first quotation mark
while (*CIDPointer++ != '"') /*do nothing*/;
--CIDPointer;
// Move back past three <
while (*CIDPointer-- != '<') /* do nothing*/;
while (*CIDPointer-- != '<') /* do nothing*/;
while (*CIDPointer-- != '<') /* do nothing*/;
++CIDPointer;
// now skip past the <
++CIDPointer;
// We now point to the CID string, atoi will stop at the > so just atoi it for the CID
CID=atoi(CIDPointer);
CPlayer *Player;
if ((Player=UTIL_PlayerByCID(CID))==NULL)
{
RETURN_META(MRES_IGNORED);
}
// list of what impulses represent what type of structure building
// use
// 0 for unknown (shouldn't be used ever)
// 1 for marine
// 2 for alien
// I'm marking the upgrades as marine structures just incase
// they should never be used though!
static int StructureTypes[128] =
{
0, // 0 = unknown
0, // 1 = next weapon
0, // 2 = reload
0, // 3 = drop weapon
0, // 4 = unknown
0, // 5 = unknown
0, // 6 = unknown
0, // 7 = radio comm
0, // 8 = radio comm
0, // 9 = radio comm
0, // 10 = radio comm
0, // 11 = radio comm
0, // 12 = radio comm
0, // 13 = radio comm
0, // 14 = radio comm
0, // 15 = radio comm
0, // 16 = unknown
0, // 17 = unknown
0, // 18 = unknown
0, // 19 = unknown
1, // 20 = armor 1
1, // 21 = armor 2
1, // 22 = armor 3
1, // 23 = weapons 1
1, // 24 = weapons 2
1, // 25 = weapons 3
1, // 26 = siege upgrade
1, // 27 = drop catalyst
1, // 28 = research jp
1, // 29 = research ha
1, // 30 = distress beacon
1, // 31 = resupply (combat)
0, // 32 = unknown
1, // 33 = motion tracking
1, // 34 = phase gates upgrade
0, // 35 = unknown
1, // 36 = electricity upgrade
1, // 37 = handgrenades upgrade
1, // 38 = drop jetpack
1, // 39 = drop heavy armor
1, // 40 = infantry portal
1, // 41 = marine RT
0, // 42 = unused
1, // 43 = turret factory
0, // 44 = unused
1, // 45 = arms lab
1, // 46 = proto lab
1, // 47 = upgrade
1, // 48 = armory
1, // 49 = advanced armory
0, // 50 = unknown
1, // 51 = observatory
0, // 52 = unknown
1, // 53 = scanner sweep
0, // 54 = unknown
1, // 55 = build phase gate
1, // 56 = build turret
1, // 57 = build siege turret
1, // 58 = build command chair
1, // 59 = drop health pack
1, // 60 = drop ammo pack
1, // 61 = drop mine pack
1, // 62 = drop welder
0, // 63 = unknown
1, // 64 = drop shotgun
1, // 65 = drop heavymachinegun
1, // 66 = drop grenadelauncher
0, // 67 = unknown
0, // 68 = unknown
0, // 69 = unknown
0, // 70 = unknown
0, // 71 = unknown
0, // 72 = unknown
0, // 73 = unknown
0, // 74 = unknown
0, // 75 = unknown
0, // 76 = unknown
0, // 77 = unknown
0, // 78 = unknown
0, // 79 = unknown
0, // 80 = radio comm
0, // 81 = radio comm
1, // 82 = commander message
0, // 83 = commander message
0, // 84 = commander message
0, // 85 = unknown
0, // 86 = unknown
0, // 87 = unknown
0, // 88 = unknown
0, // 89 = unknown
2, // 90 = alienresourcetower
2, // 91 = offensechamber
2, // 92 = defensechamber
2, // 93 = sensorychamber
2, // 94 = movementchamber
2, // 95 = team_hive
0, // 96 = unknown
0, // 97 = unknown
0, // 98 = unknown
0, // 99 = unknown
0, // 100 = unknown
2, // 101 = carapace
2, // 102 = regeneration
2, // 103 = redemption
0, // 104 = unknown
1, // 105 = select all marines
0, // 106 = unknown
2, // 107 = celerity
2, // 108 = adrenaline
2, // 109 = silence
2, // 110 = cloaking
2, // 111 = focus
2, // 112 = scent of fear
2, // 113 = skulk
2, // 114 = gorge
2, // 115 = lerk
2, // 116 = fade
2, // 117 = onos
2, // 118 = unlock next ability (combat)
0, // 119 = unknown
0, // 120 = unknown
0, // 121 = unknown
0, // 122 = unknown
0, // 123 = unknown
0, // 124 = unknown
0, // 125 = unknown
2, // 126 = unlock next ability (combat)
0 // 127 = unknown
};
int impulse=Player->GetPev()->impulse;
if (impulse < 0 || impulse > 127)
{
RETURN_META(MRES_IGNORED);
}
if (impulse==95/*hive*/)
{
GameMan.ExecuteClientBuilt(Player->index(), UTIL_FindBuildingHive(), StructureTypes[impulse], impulse);
}
else
{
GameMan.ExecuteClientBuilt(Player->index(), ENTINDEX_NEW(GameMan.GetTemporaryEdict()), StructureTypes[impulse], impulse);
}
RETURN_META(MRES_IGNORED);
}
// We hook newly created entities here.
// This is where we check for client_built created entities.
edict_t* CreateNamedEntity_Post(int className)
{
if (GameMan.IsCombat()) // this shouldn't be called during co, just incase
{
RETURN_META_VALUE(MRES_IGNORED,0);
}
// Incase another plugin supercedes/overrides, use their returned value here.
// (Untested).
if (gpMetaGlobals->status >= MRES_OVERRIDE)
{
GameMan.SetTemporaryEdict(META_RESULT_OVERRIDE_RET(edict_t *));
}
else
{
GameMan.SetTemporaryEdict(META_RESULT_ORIG_RET(edict_t *));
}
RETURN_META_VALUE(MRES_IGNORED,0);
}
unsigned short PrecacheEvent_Post(int type, const char *psz)
{
ParticleMan.PrecacheEvent(psz);
RETURN_META_VALUE(MRES_IGNORED,0);
}
/* Calls going from the game dll to the engine are handled here */
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "GameManager.h"
#include "ParticleManager.h"
#include "CPlayer.h"
// Parse log messages here for any desired information (structure_built, etc.)
// The following logs are needed:
// "sawce<1><STEAM_0:1:4560311><alien1team>" triggered "structure_built" (type "defensechamber")`
void AlertMessage_Post(ALERT_TYPE atype, const char *szFmt, ...)
{
if (atype != at_logged)
{
RETURN_META(MRES_IGNORED);
}
char *MessageStart; // original pointer to start of the message
char *TypePointer; // pointer to the structure type
char *CIDPointer; // pointer to the name text
int CID; // connection ID of the player
va_list LogArgs;
va_start(LogArgs,szFmt);
MessageStart=va_arg(LogArgs,char *);
va_end(LogArgs);
if (MessageStart==NULL) // Somehow got a null pointer, get out of here now
{
RETURN_META(MRES_IGNORED);
}
if ((TypePointer=strstr(MessageStart,"\"structure_built\""))==NULL) // was not found
{
RETURN_META(MRES_IGNORED);
}
if (*(TypePointer - 2) != 'd') // If this is not from a 'triggered "structure_built"', then ignore the message
{
RETURN_META(MRES_IGNORED);
}
// If we got here, then for all we can tell this message is good
// Move up a few spaces
TypePointer+=25; // strlen("\"structure_built\" (type \"")=25
// Now get the player's CID
CIDPointer=MessageStart+1; // skip over the very first quotation mark
while (*CIDPointer++ != '"') /*do nothing*/;
--CIDPointer;
// Move back past three <
while (*CIDPointer-- != '<') /* do nothing*/;
while (*CIDPointer-- != '<') /* do nothing*/;
while (*CIDPointer-- != '<') /* do nothing*/;
++CIDPointer;
// now skip past the <
++CIDPointer;
// We now point to the CID string, atoi will stop at the > so just atoi it for the CID
CID=atoi(CIDPointer);
CPlayer *Player;
if ((Player=UTIL_PlayerByCID(CID))==NULL)
{
RETURN_META(MRES_IGNORED);
}
// list of what impulses represent what type of structure building
// use
// 0 for unknown (shouldn't be used ever)
// 1 for marine
// 2 for alien
// I'm marking the upgrades as marine structures just incase
// they should never be used though!
static int StructureTypes[128] =
{
0, // 0 = unknown
0, // 1 = next weapon
0, // 2 = reload
0, // 3 = drop weapon
0, // 4 = unknown
0, // 5 = unknown
0, // 6 = unknown
0, // 7 = radio comm
0, // 8 = radio comm
0, // 9 = radio comm
0, // 10 = radio comm
0, // 11 = radio comm
0, // 12 = radio comm
0, // 13 = radio comm
0, // 14 = radio comm
0, // 15 = radio comm
0, // 16 = unknown
0, // 17 = unknown
0, // 18 = unknown
0, // 19 = unknown
1, // 20 = armor 1
1, // 21 = armor 2
1, // 22 = armor 3
1, // 23 = weapons 1
1, // 24 = weapons 2
1, // 25 = weapons 3
1, // 26 = siege upgrade
1, // 27 = drop catalyst
1, // 28 = research jp
1, // 29 = research ha
1, // 30 = distress beacon
1, // 31 = resupply (combat)
0, // 32 = unknown
1, // 33 = motion tracking
1, // 34 = phase gates upgrade
0, // 35 = unknown
1, // 36 = electricity upgrade
1, // 37 = handgrenades upgrade
1, // 38 = drop jetpack
1, // 39 = drop heavy armor
1, // 40 = infantry portal
1, // 41 = marine RT
0, // 42 = unused
1, // 43 = turret factory
0, // 44 = unused
1, // 45 = arms lab
1, // 46 = proto lab
1, // 47 = upgrade
1, // 48 = armory
1, // 49 = advanced armory
0, // 50 = unknown
1, // 51 = observatory
0, // 52 = unknown
1, // 53 = scanner sweep
0, // 54 = unknown
1, // 55 = build phase gate
1, // 56 = build turret
1, // 57 = build siege turret
1, // 58 = build command chair
1, // 59 = drop health pack
1, // 60 = drop ammo pack
1, // 61 = drop mine pack
1, // 62 = drop welder
0, // 63 = unknown
1, // 64 = drop shotgun
1, // 65 = drop heavymachinegun
1, // 66 = drop grenadelauncher
0, // 67 = unknown
0, // 68 = unknown
0, // 69 = unknown
0, // 70 = unknown
0, // 71 = unknown
0, // 72 = unknown
0, // 73 = unknown
0, // 74 = unknown
0, // 75 = unknown
0, // 76 = unknown
0, // 77 = unknown
0, // 78 = unknown
0, // 79 = unknown
0, // 80 = radio comm
0, // 81 = radio comm
1, // 82 = commander message
0, // 83 = commander message
0, // 84 = commander message
0, // 85 = unknown
0, // 86 = unknown
0, // 87 = unknown
0, // 88 = unknown
0, // 89 = unknown
2, // 90 = alienresourcetower
2, // 91 = offensechamber
2, // 92 = defensechamber
2, // 93 = sensorychamber
2, // 94 = movementchamber
2, // 95 = team_hive
0, // 96 = unknown
0, // 97 = unknown
0, // 98 = unknown
0, // 99 = unknown
0, // 100 = unknown
2, // 101 = carapace
2, // 102 = regeneration
2, // 103 = redemption
0, // 104 = unknown
1, // 105 = select all marines
0, // 106 = unknown
2, // 107 = celerity
2, // 108 = adrenaline
2, // 109 = silence
2, // 110 = cloaking
2, // 111 = focus
2, // 112 = scent of fear
2, // 113 = skulk
2, // 114 = gorge
2, // 115 = lerk
2, // 116 = fade
2, // 117 = onos
2, // 118 = unlock next ability (combat)
0, // 119 = unknown
0, // 120 = unknown
0, // 121 = unknown
0, // 122 = unknown
0, // 123 = unknown
0, // 124 = unknown
0, // 125 = unknown
2, // 126 = unlock next ability (combat)
0 // 127 = unknown
};
int impulse=Player->GetPev()->impulse;
if (impulse < 0 || impulse > 127)
{
RETURN_META(MRES_IGNORED);
}
if (impulse==95/*hive*/)
{
GameMan.ExecuteClientBuilt(Player->index(), UTIL_FindBuildingHive(), StructureTypes[impulse], impulse);
}
else
{
GameMan.ExecuteClientBuilt(Player->index(), ENTINDEX_NEW(GameMan.GetTemporaryEdict()), StructureTypes[impulse], impulse);
}
RETURN_META(MRES_IGNORED);
}
// We hook newly created entities here.
// This is where we check for client_built created entities.
edict_t* CreateNamedEntity_Post(int className)
{
if (GameMan.IsCombat()) // this shouldn't be called during co, just incase
{
RETURN_META_VALUE(MRES_IGNORED,0);
}
// Incase another plugin supercedes/overrides, use their returned value here.
// (Untested).
if (gpMetaGlobals->status >= MRES_OVERRIDE)
{
GameMan.SetTemporaryEdict(META_RESULT_OVERRIDE_RET(edict_t *));
}
else
{
GameMan.SetTemporaryEdict(META_RESULT_ORIG_RET(edict_t *));
}
RETURN_META_VALUE(MRES_IGNORED,0);
}
unsigned short PrecacheEvent_Post(int type, const char *psz)
{
ParticleMan.PrecacheEvent(psz);
RETURN_META_VALUE(MRES_IGNORED,0);
}

File diff suppressed because it is too large Load Diff

View File

@ -11,278 +11,278 @@
// Natural Selection Module
//
#include <string.h>
#include "amxxmodule.h"
#include "ns.h"
#include "ns_const.h"
#include "utilfunctions.h"
#include "FastDelegate.h"
#include "GameManager.h"
extern int IsValidBuilding[AVH_USER3_MAX + 1];
using namespace fastdelegate::detail;
void *GameRules=NULL;
mBOOL dlclose_handle_invalid; // Linking errors with metamod
// void AvHBaseBuildable::StartRecycle()
static void (GenericClass::*MFP_Recycle)();
// void AvHWeldable::AddBuildTime(float)
static void (GenericClass::*MFP_WeldFinished)(float);
// AvHGameRules *GetGameRules(void)
static void *(*FP_GetGameRules)();
char *FuncBase;
/**
* sizeof(void (detail::GenericClass::*fptr)())
* is 8 in GCC. Add an empty void * pointer at
* the end to compensate.
* Layout in GCC:
* union {
* void *address; // When this is an address it will always be positive
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
* };
* int delta;
* -
* Delta is the adjustment to the this pointer
* For my implementations I will only need it to 0
*/
#ifdef __GNUC__
template <typename OutType>
inline void set_mfp(OutType &out, void *in)
{
union
{
void *in[2];
OutType out;
} mfpu;
mfpu.in[0]=in;
mfpu.in[1]=NULL;
out=mfpu.out;
};
#else
template <typename OutType>
inline void set_mfp(OutType &out, void *in)
{
out=horrible_cast<OutType>(in);
};
#endif
void MFuncs_Initialize(void)
{
char FileName[256];
DLHANDLE DLLBase;
#ifdef __linux__
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
#else
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
#endif
DLLBase=DLOPEN(FileName);
FuncBase=(char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
DLCLOSE(DLLBase);
#define MFP(Offs) (((void *)(((char *)FuncBase)+MAKE_OFFSET(Offs))))
set_mfp(MFP_Recycle,MFP(MEMBER_RECYCLE));
set_mfp(MFP_WeldFinished,MFP(MEMBER_TRIGGER_WELDABLE));
// This is not a member function pointer, but use MFP since it
// uses the same address conversion as MFPs do
FP_GetGameRules=horrible_cast<void *(*)()>(MFP(GETGAMERULES));
};
static cell AMX_NATIVE_CALL ns_recycle(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free || Entity->pvPrivateData==NULL)
{
return 0;
}
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
{
return 0;
}
if (IsValidBuilding[Entity->v.iuser3]!=1) // Not a marine structure?
{
return 0;
}
// Make sure it's a marine building, undefined stuff happens on alien structures
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_Recycle))();
return 1;
};
static cell AMX_NATIVE_CALL ns_finish_weldable(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free || Entity->pvPrivateData==NULL)
{
return 0;
}
// verify the classname since this will crash if it's the wrong class!
if (strcmp(STRING(Entity->v.classname),"avhweldable")!=0)
{
return 0;
}
// First need to set the weldable to 100% complete
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
// Now make NS think the weldable has been welded again
// This has to call AvHWeldable::AddBuildTime(float)
// because AvHWeldable::TriggerFinished() does not work properly
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_WeldFinished))(100.0);
return 1;
};
static cell AMX_NATIVE_CALL ns_get_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES));
}
case 2:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES));
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_get_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
static cell AMX_NATIVE_CALL ns_set_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)=amx_ctof2(params[2]);
return 1;
}
case 2:
{
*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)=amx_ctof2(params[2]);
return 1;
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_set_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
static cell AMX_NATIVE_CALL ns_add_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)+=amx_ctof2(params[2]));
}
case 2:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)+=amx_ctof2(params[2]));
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_add_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
#ifdef DEVELOPER_BUILD
static cell AMX_NATIVE_CALL findgameinfo(AMX *amx, cell *params)
{
void *Ret=(*(FP_GetGameRules))();
union
{
void *v;
int i;
}vi;
vi.v=Ret;
printf("GameRules=%d\n",vi.i);
return 1;
};
#endif
AMX_NATIVE_INFO memberfunc_natives[] = {
#ifdef DEVELOPER_BUILD
{ "getgameinfo", findgameinfo },
#endif
{ "ns_recycle", ns_recycle },
{ "ns_finish_weldable", ns_finish_weldable },
{ "ns_get_teamres", ns_get_teamres },
{ "ns_set_teamres", ns_set_teamres },
{ "ns_add_teamres", ns_add_teamres },
{ NULL, NULL }
};
void AddNatives_MemberFunc()
{
MF_AddNatives(memberfunc_natives);
};
#include <string.h>
#include "amxxmodule.h"
#include "ns.h"
#include "ns_const.h"
#include "utilfunctions.h"
#include "FastDelegate.h"
#include "GameManager.h"
extern int IsValidBuilding[AVH_USER3_MAX + 1];
using namespace fastdelegate::detail;
void *GameRules=NULL;
mBOOL dlclose_handle_invalid; // Linking errors with metamod
// void AvHBaseBuildable::StartRecycle()
static void (GenericClass::*MFP_Recycle)();
// void AvHWeldable::AddBuildTime(float)
static void (GenericClass::*MFP_WeldFinished)(float);
// AvHGameRules *GetGameRules(void)
static void *(*FP_GetGameRules)();
char *FuncBase;
/**
* sizeof(void (detail::GenericClass::*fptr)())
* is 8 in GCC. Add an empty void * pointer at
* the end to compensate.
* Layout in GCC:
* union {
* void *address; // When this is an address it will always be positive
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
* };
* int delta;
* -
* Delta is the adjustment to the this pointer
* For my implementations I will only need it to 0
*/
#ifdef __GNUC__
template <typename OutType>
inline void set_mfp(OutType &out, void *in)
{
union
{
void *in[2];
OutType out;
} mfpu;
mfpu.in[0]=in;
mfpu.in[1]=NULL;
out=mfpu.out;
};
#else
template <typename OutType>
inline void set_mfp(OutType &out, void *in)
{
out=horrible_cast<OutType>(in);
};
#endif
void MFuncs_Initialize(void)
{
char FileName[256];
DLHANDLE DLLBase;
#ifdef __linux__
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
#else
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
#endif
DLLBase=DLOPEN(FileName);
FuncBase=(char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
DLCLOSE(DLLBase);
#define MFP(Offs) (((void *)(((char *)FuncBase)+MAKE_OFFSET(Offs))))
set_mfp(MFP_Recycle,MFP(MEMBER_RECYCLE));
set_mfp(MFP_WeldFinished,MFP(MEMBER_TRIGGER_WELDABLE));
// This is not a member function pointer, but use MFP since it
// uses the same address conversion as MFPs do
FP_GetGameRules=horrible_cast<void *(*)()>(MFP(GETGAMERULES));
};
static cell AMX_NATIVE_CALL ns_recycle(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free || Entity->pvPrivateData==NULL)
{
return 0;
}
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
{
return 0;
}
if (IsValidBuilding[Entity->v.iuser3]!=1) // Not a marine structure?
{
return 0;
}
// Make sure it's a marine building, undefined stuff happens on alien structures
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_Recycle))();
return 1;
};
static cell AMX_NATIVE_CALL ns_finish_weldable(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free || Entity->pvPrivateData==NULL)
{
return 0;
}
// verify the classname since this will crash if it's the wrong class!
if (strcmp(STRING(Entity->v.classname),"avhweldable")!=0)
{
return 0;
}
// First need to set the weldable to 100% complete
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
// Now make NS think the weldable has been welded again
// This has to call AvHWeldable::AddBuildTime(float)
// because AvHWeldable::TriggerFinished() does not work properly
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_WeldFinished))(100.0);
return 1;
};
static cell AMX_NATIVE_CALL ns_get_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES));
}
case 2:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES));
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_get_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
static cell AMX_NATIVE_CALL ns_set_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)=amx_ctof2(params[2]);
return 1;
}
case 2:
{
*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)=amx_ctof2(params[2]);
return 1;
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_set_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
static cell AMX_NATIVE_CALL ns_add_teamres(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
if (GameRules==NULL) // GameRules not initialized yet
{
GameRules=(*(FP_GetGameRules))();
}
if (GameRules==NULL) // Still null? Get out of here
{
return 0;
}
switch(params[1])
{
case 1:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)+=amx_ctof2(params[2]));
}
case 2:
{
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)+=amx_ctof2(params[2]));
}
default:
{
MF_LogError(amx, AMX_ERR_NATIVE, "ns_add_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
return 0;
}
}
return 0;
}
#ifdef DEVELOPER_BUILD
static cell AMX_NATIVE_CALL findgameinfo(AMX *amx, cell *params)
{
void *Ret=(*(FP_GetGameRules))();
union
{
void *v;
int i;
}vi;
vi.v=Ret;
printf("GameRules=%d\n",vi.i);
return 1;
};
#endif
AMX_NATIVE_INFO memberfunc_natives[] = {
#ifdef DEVELOPER_BUILD
{ "getgameinfo", findgameinfo },
#endif
{ "ns_recycle", ns_recycle },
{ "ns_finish_weldable", ns_finish_weldable },
{ "ns_get_teamres", ns_get_teamres },
{ "ns_set_teamres", ns_set_teamres },
{ "ns_add_teamres", ns_add_teamres },
{ NULL, NULL }
};
void AddNatives_MemberFunc()
{
MF_AddNatives(memberfunc_natives);
};

View File

@ -10,246 +10,246 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "ParticleManager.h"
#include <am-vector.h>
#include <am-string.h>
#define KVI(__KEY) PSKeyValueI(__KEY,amx,params)
#define KVF(__KEY) PSKeyValueF(__KEY,amx,params)
#define KVS(__KEY) PSKeyValueS(__KEY,amx,params)
#define NEXT params[__pcount++]
typedef enum partsystype_e
{
PSYS_TYPE_INT,
PSYS_TYPE_FLOAT,
PSYS_TYPE_STRING
}partsystype;
typedef struct partsyskey_s
{
const char *Name;
partsystype type;
}partsyskey;
cell PSKeyValueI(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]);
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=&StrData[0];
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
cell PSKeyValueF(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=&StrData[0];
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
cell PSKeyValueS(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=MF_GetAmxString(amx,params[2],0,NULL);
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
static cell AMX_NATIVE_CALL ns_set_ps_name(AMX *amx, cell *params)
{
return KVS("targetname");
}
static cell AMX_NATIVE_CALL ns_set_ps_sprite(AMX *amx, cell *params)
{
return KVS("pSprite");
}
static cell AMX_NATIVE_CALL ns_set_ps_genrate(AMX *amx, cell *params)
{
return KVI("pGenRate");
}
static cell AMX_NATIVE_CALL ns_set_ps_genshape(AMX *amx, cell *params)
{
return KVI("pGenShape");
}
static cell AMX_NATIVE_CALL ns_set_ps_genshape_params(AMX *amx, cell *params)
{
return KVS("pGenShapeParams");
}
static cell AMX_NATIVE_CALL ns_set_ps_spriteframes(AMX *amx, cell *params)
{
return KVI("pSpriteNumFrames");
}
static cell AMX_NATIVE_CALL ns_set_ps_numparticles(AMX *amx, cell *params)
{
return KVI("pNumParticles");
}
static cell AMX_NATIVE_CALL ns_set_ps_size(AMX *amx, cell *params)
{
return KVF("pSize");
}
static cell AMX_NATIVE_CALL ns_set_ps_vel_params(AMX *amx, cell *params)
{
return KVS("pVelParams");
}
static cell AMX_NATIVE_CALL ns_set_ps_vel_shape(AMX *amx, cell *params)
{
return KVI("pVelShape");
}
static cell AMX_NATIVE_CALL ns_set_ps_sys_life(AMX *amx, cell *params)
{
return KVF("pSystemLifetime");
}
static cell AMX_NATIVE_CALL ns_set_ps_particle_life(AMX *amx, cell *params)
{
return KVF("pLifetime");
}
static cell AMX_NATIVE_CALL ns_set_ps_rendermode(AMX *amx, cell *params)
{
return KVI("pRenderMode");
}
static cell AMX_NATIVE_CALL ns_set_ps_to_gen(AMX *amx, cell *params)
{
return KVS("pPSToGen");
}
static cell AMX_NATIVE_CALL ns_set_ps_anim_speed(AMX *amx, cell *params)
{
return KVI("pAnimationSpeed");
}
static cell AMX_NATIVE_CALL ns_set_ps_spawn_flags(AMX *amx, cell *params)
{
return KVI("spawnflags");
}
static cell AMX_NATIVE_CALL ns_set_ps_base_color(AMX *amx, cell *params)
{
return KVS("pBaseColor");
}
static cell AMX_NATIVE_CALL ns_set_ps_scale(AMX *amx, cell *params)
{
return KVF("pScale");
}
static cell AMX_NATIVE_CALL ns_set_ps_max_alpha(AMX *amx, cell *params)
{
return KVF("pMaxAlpha");
}
// ns_create_partsys(const name[], pGenShape, const pGenShapeParams[], pGenRate, const pSprite[],
// pSpriteFrames, pNumParticles, Float:pSize, const pVelParams[], pVelShape,
// Float:pSystemLifetime, Float:pParticleLifetime, pRenderMode, const pPSToGen[], pAnimationSpeed, pSpawnFlags)
static cell AMX_NATIVE_CALL ns_create_partsys(AMX *amx, cell *params)
{
return (cell)CREATE_NAMED_ENTITY(MAKE_STRING("env_particles_custom"));
};
static cell AMX_NATIVE_CALL ns_spawn_ps(AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid particle system handle");
return 0;
}
edict_t *Ent=reinterpret_cast<edict_t *>(params[1]);
MDLL_Spawn(Ent);
if (!Ent->free)
{
REMOVE_ENTITY(Ent);
}
return ParticleMan.Add(STRING(Ent->v.targetname),0);
}
// ns_fire_ps(Particle:id,Float:origin[3],Float:angles[3],flags=0)
static cell AMX_NATIVE_CALL ns_fire_partsys(AMX *amx, cell *params)
{
float *origin=(float*)MF_GetAmxAddr(amx,params[2]);
float *angles=(float*)MF_GetAmxAddr(amx,params[3]);
ParticleMan.FireSystem(static_cast<int>(params[1]),origin,angles,static_cast<int>(params[4]));
return 0;
};
static cell AMX_NATIVE_CALL ns_get_partsys_id(AMX *amx, cell *params)
{
return ParticleMan.Find(MF_GetAmxString(amx,params[1],0,NULL));;
};
AMX_NATIVE_INFO particle_natives[] = {
{ "ns_create_ps", ns_create_partsys },
{ "ns_set_ps_name", ns_set_ps_name },
{ "ns_set_ps_sprite", ns_set_ps_sprite },
{ "ns_set_ps_genrate", ns_set_ps_genrate },
{ "ns_set_ps_genshape", ns_set_ps_genshape },
{ "ns_set_ps_genshape_params", ns_set_ps_genshape_params },
{ "ns_set_ps_spriteframes", ns_set_ps_spriteframes },
{ "ns_set_ps_numparticles", ns_set_ps_numparticles },
{ "ns_set_ps_size", ns_set_ps_size },
{ "ns_set_ps_vel_params", ns_set_ps_vel_params },
{ "ns_set_ps_vel_shape", ns_set_ps_vel_shape },
{ "ns_set_ps_sys_life", ns_set_ps_sys_life },
{ "ns_set_ps_particle_life", ns_set_ps_particle_life },
{ "ns_set_ps_rendermode", ns_set_ps_rendermode },
{ "ns_set_ps_to_gen", ns_set_ps_to_gen },
{ "ns_set_ps_anim_speed", ns_set_ps_anim_speed },
{ "ns_set_ps_spawn_flags", ns_set_ps_spawn_flags },
{ "ns_set_ps_base_color", ns_set_ps_base_color },
{ "ns_set_ps_scale", ns_set_ps_scale },
{ "ns_set_ps_max_alpha", ns_set_ps_max_alpha },
{ "ns_spawn_ps", ns_spawn_ps },
{ "ns_fire_ps", ns_fire_partsys },
{ "ns_get_ps_id", ns_get_partsys_id },
{ NULL, NULL }
};
void AddNatives_Particles()
{
MF_AddNatives(particle_natives);
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "ParticleManager.h"
#include <am-vector.h>
#include <am-string.h>
#define KVI(__KEY) PSKeyValueI(__KEY,amx,params)
#define KVF(__KEY) PSKeyValueF(__KEY,amx,params)
#define KVS(__KEY) PSKeyValueS(__KEY,amx,params)
#define NEXT params[__pcount++]
typedef enum partsystype_e
{
PSYS_TYPE_INT,
PSYS_TYPE_FLOAT,
PSYS_TYPE_STRING
}partsystype;
typedef struct partsyskey_s
{
const char *Name;
partsystype type;
}partsyskey;
cell PSKeyValueI(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]);
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=&StrData[0];
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
cell PSKeyValueF(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=&StrData[0];
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
cell PSKeyValueS(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=MF_GetAmxString(amx,params[2],0,NULL);
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
static cell AMX_NATIVE_CALL ns_set_ps_name(AMX *amx, cell *params)
{
return KVS("targetname");
}
static cell AMX_NATIVE_CALL ns_set_ps_sprite(AMX *amx, cell *params)
{
return KVS("pSprite");
}
static cell AMX_NATIVE_CALL ns_set_ps_genrate(AMX *amx, cell *params)
{
return KVI("pGenRate");
}
static cell AMX_NATIVE_CALL ns_set_ps_genshape(AMX *amx, cell *params)
{
return KVI("pGenShape");
}
static cell AMX_NATIVE_CALL ns_set_ps_genshape_params(AMX *amx, cell *params)
{
return KVS("pGenShapeParams");
}
static cell AMX_NATIVE_CALL ns_set_ps_spriteframes(AMX *amx, cell *params)
{
return KVI("pSpriteNumFrames");
}
static cell AMX_NATIVE_CALL ns_set_ps_numparticles(AMX *amx, cell *params)
{
return KVI("pNumParticles");
}
static cell AMX_NATIVE_CALL ns_set_ps_size(AMX *amx, cell *params)
{
return KVF("pSize");
}
static cell AMX_NATIVE_CALL ns_set_ps_vel_params(AMX *amx, cell *params)
{
return KVS("pVelParams");
}
static cell AMX_NATIVE_CALL ns_set_ps_vel_shape(AMX *amx, cell *params)
{
return KVI("pVelShape");
}
static cell AMX_NATIVE_CALL ns_set_ps_sys_life(AMX *amx, cell *params)
{
return KVF("pSystemLifetime");
}
static cell AMX_NATIVE_CALL ns_set_ps_particle_life(AMX *amx, cell *params)
{
return KVF("pLifetime");
}
static cell AMX_NATIVE_CALL ns_set_ps_rendermode(AMX *amx, cell *params)
{
return KVI("pRenderMode");
}
static cell AMX_NATIVE_CALL ns_set_ps_to_gen(AMX *amx, cell *params)
{
return KVS("pPSToGen");
}
static cell AMX_NATIVE_CALL ns_set_ps_anim_speed(AMX *amx, cell *params)
{
return KVI("pAnimationSpeed");
}
static cell AMX_NATIVE_CALL ns_set_ps_spawn_flags(AMX *amx, cell *params)
{
return KVI("spawnflags");
}
static cell AMX_NATIVE_CALL ns_set_ps_base_color(AMX *amx, cell *params)
{
return KVS("pBaseColor");
}
static cell AMX_NATIVE_CALL ns_set_ps_scale(AMX *amx, cell *params)
{
return KVF("pScale");
}
static cell AMX_NATIVE_CALL ns_set_ps_max_alpha(AMX *amx, cell *params)
{
return KVF("pMaxAlpha");
}
// ns_create_partsys(const name[], pGenShape, const pGenShapeParams[], pGenRate, const pSprite[],
// pSpriteFrames, pNumParticles, Float:pSize, const pVelParams[], pVelShape,
// Float:pSystemLifetime, Float:pParticleLifetime, pRenderMode, const pPSToGen[], pAnimationSpeed, pSpawnFlags)
static cell AMX_NATIVE_CALL ns_create_partsys(AMX *amx, cell *params)
{
return (cell)CREATE_NAMED_ENTITY(MAKE_STRING("env_particles_custom"));
};
static cell AMX_NATIVE_CALL ns_spawn_ps(AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid particle system handle");
return 0;
}
edict_t *Ent=reinterpret_cast<edict_t *>(params[1]);
MDLL_Spawn(Ent);
if (!Ent->free)
{
REMOVE_ENTITY(Ent);
}
return ParticleMan.Add(STRING(Ent->v.targetname),0);
}
// ns_fire_ps(Particle:id,Float:origin[3],Float:angles[3],flags=0)
static cell AMX_NATIVE_CALL ns_fire_partsys(AMX *amx, cell *params)
{
float *origin=(float*)MF_GetAmxAddr(amx,params[2]);
float *angles=(float*)MF_GetAmxAddr(amx,params[3]);
ParticleMan.FireSystem(static_cast<int>(params[1]),origin,angles,static_cast<int>(params[4]));
return 0;
};
static cell AMX_NATIVE_CALL ns_get_partsys_id(AMX *amx, cell *params)
{
return ParticleMan.Find(MF_GetAmxString(amx,params[1],0,NULL));;
};
AMX_NATIVE_INFO particle_natives[] = {
{ "ns_create_ps", ns_create_partsys },
{ "ns_set_ps_name", ns_set_ps_name },
{ "ns_set_ps_sprite", ns_set_ps_sprite },
{ "ns_set_ps_genrate", ns_set_ps_genrate },
{ "ns_set_ps_genshape", ns_set_ps_genshape },
{ "ns_set_ps_genshape_params", ns_set_ps_genshape_params },
{ "ns_set_ps_spriteframes", ns_set_ps_spriteframes },
{ "ns_set_ps_numparticles", ns_set_ps_numparticles },
{ "ns_set_ps_size", ns_set_ps_size },
{ "ns_set_ps_vel_params", ns_set_ps_vel_params },
{ "ns_set_ps_vel_shape", ns_set_ps_vel_shape },
{ "ns_set_ps_sys_life", ns_set_ps_sys_life },
{ "ns_set_ps_particle_life", ns_set_ps_particle_life },
{ "ns_set_ps_rendermode", ns_set_ps_rendermode },
{ "ns_set_ps_to_gen", ns_set_ps_to_gen },
{ "ns_set_ps_anim_speed", ns_set_ps_anim_speed },
{ "ns_set_ps_spawn_flags", ns_set_ps_spawn_flags },
{ "ns_set_ps_base_color", ns_set_ps_base_color },
{ "ns_set_ps_scale", ns_set_ps_scale },
{ "ns_set_ps_max_alpha", ns_set_ps_max_alpha },
{ "ns_spawn_ps", ns_spawn_ps },
{ "ns_fire_ps", ns_fire_partsys },
{ "ns_get_ps_id", ns_get_partsys_id },
{ NULL, NULL }
};
void AddNatives_Particles()
{
MF_AddNatives(particle_natives);
}

View File

@ -10,261 +10,261 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
#include "AllocString.h"
StringManager AllocStringList;
// ns_set_player_model(id,const Model[]="")
static cell AMX_NATIVE_CALL ns_set_player_model(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetModel(MF_GetAmxString(amx,params[2],0,NULL));
GameMan.HookPostThink_Post();
return 1;
}
// ns_set_player_skin(id,skin=-1)
static cell AMX_NATIVE_CALL ns_set_player_skin(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetSkin(params[2]);
GameMan.HookPostThink_Post();
return 1;
}
// ns_set_player_body(id,body=-1)
static cell AMX_NATIVE_CALL ns_set_player_body(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetBody(params[2]);
GameMan.HookPostThink_Post();
return 1;
}
// ns_get_class(id)
static cell AMX_NATIVE_CALL ns_get_class(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetClass();
}
// ns_get_jpfuel(id)
static cell AMX_NATIVE_CALL ns_get_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL ret=(player->GetPev()->fuser3) / 10.0;
return amx_ftoc2(ret);
}
// ns_set_jpfuel(id,Float:fuelpercent)
static cell AMX_NATIVE_CALL ns_set_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL fuel = amx_ctof2(params[2]);
if (fuel > 100.0)
{
fuel = 100.0;
}
if (fuel < 0.0)
{
fuel = 0.0;
}
player->GetPev()->fuser3 = fuel * 10.0;
return 1;
}
static cell AMX_NATIVE_CALL ns_add_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL fuel = clamp(amx_ctof2(params[2]),0.0,100.0);
return amx_ftoc2(player->GetPev()->fuser3 = clamp(static_cast<float>(player->GetPev()->fuser3 + (fuel * 10.0)),static_cast<float>(0.0)));
};
// ns_get_speedchange(index)
static cell AMX_NATIVE_CALL ns_get_speedchange(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetSpeedChange();
}
// ns_set_speedchange(index,speedchange=0)
static cell AMX_NATIVE_CALL ns_set_speedchange(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetSpeedChange(params[2]);
// Update PreThink_Post if we need to
GameMan.HookPreThink_Post();
return 1;
}
// ns_get_maxspeed(index) (returns the max speed of the player BEFORE speed change is factored in.)
static cell AMX_NATIVE_CALL ns_get_maxspeed(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetMaxSpeed();
}
// ns_set_fov(id,Float:fov);
static cell AMX_NATIVE_CALL ns_set_fov(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->SetFOV(amx_ctof3(&params[2]));
}
// ns_giveiteM(id,"item");
static cell AMX_NATIVE_CALL ns_giveitem(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
char *classname = MF_GetAmxString(amx,params[2],0,NULL);
if (!player->IsConnected())
{
return 0;
}
if (player->GetPev()->deadflag > 0)
{
return 0;
}
edict_t *object=CREATE_NAMED_ENTITY(ALLOC_STRING2(classname));
if (!object)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Error creating entity \"%s\"", classname);
return 0;
}
SET_ORIGIN(object,player->GetPev()->origin); // move to player
gpGamedllFuncs->dllapi_table->pfnSpawn(object); // emulate spawn
object->v.flags |= FL_ONGROUND; // make it think it's touched the ground
gpGamedllFuncs->dllapi_table->pfnThink(object); //
gpGamedllFuncs->dllapi_table->pfnTouch(object,player->GetEdict()); // give it to the player
return 1;
}
static cell AMX_NATIVE_CALL ns_get_user_team(AMX* amx, cell* params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
int team = player->GetPev()->team;
if (team > 4 || team < 0)
{
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
return 0;
}
switch (team)
{
case 0:
{
// iuser1 means readyroom (I think!)
if (player->GetPev()->iuser1 == 0)
{
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
return 0;
}
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
return 0;
}
case 1:
{
MF_SetAmxString(amx, params[2], "marine1team", params[3]);
return 1;
}
case 2:
{
MF_SetAmxString(amx, params[2], "alien1team", params[3]);
return 2;
}
case 3:
{
MF_SetAmxString(amx, params[2], "marine2team", params[3]);
return 3;
}
case 4:
{
MF_SetAmxString(amx, params[2], "alien2team", params[3]);
return 4;
}
default:
{
break;
}
}
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
return 0;
}
AMX_NATIVE_INFO player_natives[] = {
{ "ns_set_player_model", ns_set_player_model },
{ "ns_set_player_skin", ns_set_player_skin },
{ "ns_set_player_body", ns_set_player_body },
{ "ns_get_class", ns_get_class },
{ "ns_get_jpfuel", ns_get_jpfuel },
{ "ns_set_jpfuel", ns_set_jpfuel },
{ "ns_add_jpfuel", ns_add_jpfuel },
{ "ns_get_energy", ns_get_jpfuel }, // They do the same thing...
{ "ns_set_energy", ns_set_jpfuel }, //
{ "ns_add_energy", ns_add_jpfuel },
{ "ns_get_speedchange", ns_get_speedchange },
{ "ns_set_speedchange", ns_set_speedchange },
{ "ns_get_maxspeed", ns_get_maxspeed },
{ "ns_set_fov", ns_set_fov },
{ "ns_give_item", ns_giveitem },
{ "ns_get_user_team", ns_get_user_team },
{ NULL, NULL }
};
void AddNatives_Player()
{
MF_AddNatives(player_natives);
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
#include "AllocString.h"
StringManager AllocStringList;
// ns_set_player_model(id,const Model[]="")
static cell AMX_NATIVE_CALL ns_set_player_model(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetModel(MF_GetAmxString(amx,params[2],0,NULL));
GameMan.HookPostThink_Post();
return 1;
}
// ns_set_player_skin(id,skin=-1)
static cell AMX_NATIVE_CALL ns_set_player_skin(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetSkin(params[2]);
GameMan.HookPostThink_Post();
return 1;
}
// ns_set_player_body(id,body=-1)
static cell AMX_NATIVE_CALL ns_set_player_body(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetBody(params[2]);
GameMan.HookPostThink_Post();
return 1;
}
// ns_get_class(id)
static cell AMX_NATIVE_CALL ns_get_class(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetClass();
}
// ns_get_jpfuel(id)
static cell AMX_NATIVE_CALL ns_get_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL ret=(player->GetPev()->fuser3) / 10.0;
return amx_ftoc2(ret);
}
// ns_set_jpfuel(id,Float:fuelpercent)
static cell AMX_NATIVE_CALL ns_set_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL fuel = amx_ctof2(params[2]);
if (fuel > 100.0)
{
fuel = 100.0;
}
if (fuel < 0.0)
{
fuel = 0.0;
}
player->GetPev()->fuser3 = fuel * 10.0;
return 1;
}
static cell AMX_NATIVE_CALL ns_add_jpfuel(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
REAL fuel = clamp(amx_ctof2(params[2]),0.0,100.0);
return amx_ftoc2(player->GetPev()->fuser3 = clamp(static_cast<float>(player->GetPev()->fuser3 + (fuel * 10.0)),static_cast<float>(0.0)));
};
// ns_get_speedchange(index)
static cell AMX_NATIVE_CALL ns_get_speedchange(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetSpeedChange();
}
// ns_set_speedchange(index,speedchange=0)
static cell AMX_NATIVE_CALL ns_set_speedchange(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
player->SetSpeedChange(params[2]);
// Update PreThink_Post if we need to
GameMan.HookPreThink_Post();
return 1;
}
// ns_get_maxspeed(index) (returns the max speed of the player BEFORE speed change is factored in.)
static cell AMX_NATIVE_CALL ns_get_maxspeed(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->GetMaxSpeed();
}
// ns_set_fov(id,Float:fov);
static cell AMX_NATIVE_CALL ns_set_fov(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
return player->SetFOV(amx_ctof3(&params[2]));
}
// ns_giveiteM(id,"item");
static cell AMX_NATIVE_CALL ns_giveitem(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
char *classname = MF_GetAmxString(amx,params[2],0,NULL);
if (!player->IsConnected())
{
return 0;
}
if (player->GetPev()->deadflag > 0)
{
return 0;
}
edict_t *object=CREATE_NAMED_ENTITY(ALLOC_STRING2(classname));
if (!object)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Error creating entity \"%s\"", classname);
return 0;
}
SET_ORIGIN(object,player->GetPev()->origin); // move to player
gpGamedllFuncs->dllapi_table->pfnSpawn(object); // emulate spawn
object->v.flags |= FL_ONGROUND; // make it think it's touched the ground
gpGamedllFuncs->dllapi_table->pfnThink(object); //
gpGamedllFuncs->dllapi_table->pfnTouch(object,player->GetEdict()); // give it to the player
return 1;
}
static cell AMX_NATIVE_CALL ns_get_user_team(AMX* amx, cell* params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
int team = player->GetPev()->team;
if (team > 4 || team < 0)
{
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
return 0;
}
switch (team)
{
case 0:
{
// iuser1 means readyroom (I think!)
if (player->GetPev()->iuser1 == 0)
{
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
return 0;
}
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
return 0;
}
case 1:
{
MF_SetAmxString(amx, params[2], "marine1team", params[3]);
return 1;
}
case 2:
{
MF_SetAmxString(amx, params[2], "alien1team", params[3]);
return 2;
}
case 3:
{
MF_SetAmxString(amx, params[2], "marine2team", params[3]);
return 3;
}
case 4:
{
MF_SetAmxString(amx, params[2], "alien2team", params[3]);
return 4;
}
default:
{
break;
}
}
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
return 0;
}
AMX_NATIVE_INFO player_natives[] = {
{ "ns_set_player_model", ns_set_player_model },
{ "ns_set_player_skin", ns_set_player_skin },
{ "ns_set_player_body", ns_set_player_body },
{ "ns_get_class", ns_get_class },
{ "ns_get_jpfuel", ns_get_jpfuel },
{ "ns_set_jpfuel", ns_set_jpfuel },
{ "ns_add_jpfuel", ns_add_jpfuel },
{ "ns_get_energy", ns_get_jpfuel }, // They do the same thing...
{ "ns_set_energy", ns_set_jpfuel }, //
{ "ns_add_energy", ns_add_jpfuel },
{ "ns_get_speedchange", ns_get_speedchange },
{ "ns_set_speedchange", ns_set_speedchange },
{ "ns_get_maxspeed", ns_get_maxspeed },
{ "ns_set_fov", ns_set_fov },
{ "ns_give_item", ns_giveitem },
{ "ns_get_user_team", ns_get_user_team },
{ NULL, NULL }
};
void AddNatives_Player()
{
MF_AddNatives(player_natives);
}

View File

@ -10,418 +10,418 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
// Float:ns_get_res(Player)
static cell AMX_NATIVE_CALL ns_get_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES)));
}
// ns_set_res(Player,Float:res)
static cell AMX_NATIVE_CALL ns_set_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]));
return 1;
}
// Float:ns_add_res(Player,Float:res)
static cell AMX_NATIVE_CALL ns_add_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]),0.0,100.0));
}
// Float:ns_get_exp(Player)
static cell AMX_NATIVE_CALL ns_get_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(EXP)));
}
// ns_set_exp(Player,Float:exp)
static cell AMX_NATIVE_CALL ns_set_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]));
return 1;
}
// Float:ns_add_exp(Player,Float:exp)
static cell AMX_NATIVE_CALL ns_add_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]),0.0));
}
// ns_get_points(Player)
static cell AMX_NATIVE_CALL ns_get_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(POINTS));
}
// ns_set_points(Player,points)
static cell AMX_NATIVE_CALL ns_set_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx, params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]));
return 1;
}
// ns_add_points(Player,points)
static cell AMX_NATIVE_CALL ns_add_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx, params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]),0,9);
}
static cell AMX_NATIVE_CALL ns_get_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(SCORE));
}
static cell AMX_NATIVE_CALL ns_set_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_add_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
}
static cell AMX_NATIVE_CALL ns_get_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(DEATHS));
}
static cell AMX_NATIVE_CALL ns_set_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_add_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
}
static cell AMX_NATIVE_CALL ns_get_hive_ability(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
int result = get_private(player->GetEdict(), MAKE_OFFSET(HIVEABILITY));
return (params[2] > 0) ? (result >= params[2] - 1) : result;
}
static cell AMX_NATIVE_CALL ns_remove_upgrade(AMX *amx, cell *params)
{
CreatePlayerPointer(amx, params[1]);
if (!GameMan.IsCombat())
{
return 0;
}
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
// Upgrades are stored in a std::vector<int> in the player's private data
// The integer value represents the impulse for the offset
// std::vector's memory layout is:
// void *start
// void *lastobject
// void *lastreserved
struct upgradevector
{
int *start;
int *end;
int *allocated;
inline int size() { return static_cast<int>((reinterpret_cast<unsigned int>(end) - reinterpret_cast<unsigned int>(start)) / sizeof(int)); }
inline int at(int which) { return start[which]; }
inline void set(int which, int val) { start[which] = val; }
inline bool remove(int val)
{
for (int i = 0; i < this->size(); i++)
{
if (this->at(i) == val)
{
int last = this->size() - 1;
while (i < last)
{
this->set(i, this->at(i + 1));
i++;
}
this->end--;
return true;
}
}
return false;
}
inline void print()
{
printf("size: %d values: ", this->size());
for (int i = 0; i < this->size(); i++)
{
if (i != 0)
printf(", ");
printf("%d", this->at(i));
}
printf("\n");
}
};
upgradevector *bought = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_BOUGHT));
upgradevector *active = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_ACTIVE));
//bought->print();
//active->print();
bool bfound = bought->remove(params[2]);
bool afound = active->remove(params[2]);
if (bfound)
{
if (afound)
{
return 2;
}
return 1;
}
if (afound)
{
// shouldn't happen, but just incase
return 3;
}
return 0;
}
AMX_NATIVE_INFO player_memory_natives[] = {
{ "ns_get_res", ns_get_res },
{ "ns_set_res", ns_set_res },
{ "ns_add_res", ns_add_res },
{ "ns_get_exp", ns_get_exp },
{ "ns_set_exp", ns_set_exp },
{ "ns_add_exp", ns_add_exp },
{ "ns_get_points", ns_get_points },
{ "ns_set_points", ns_set_points },
{ "ns_add_points", ns_add_points },
{ "ns_set_score", ns_set_score },
{ "ns_get_score", ns_get_score },
{ "ns_add_score", ns_add_score },
{ "ns_get_deaths", ns_get_deaths },
{ "ns_set_deaths", ns_set_deaths },
{ "ns_add_deaths", ns_add_deaths },
{ "ns_get_hive_ability", ns_get_hive_ability },
{ "ns_remove_upgrade", ns_remove_upgrade },
{ NULL, NULL }
};
void AddNatives_PlayerMemory()
{
MF_AddNatives(player_memory_natives);
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
// Float:ns_get_res(Player)
static cell AMX_NATIVE_CALL ns_get_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES)));
}
// ns_set_res(Player,Float:res)
static cell AMX_NATIVE_CALL ns_set_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]));
return 1;
}
// Float:ns_add_res(Player,Float:res)
static cell AMX_NATIVE_CALL ns_add_res(AMX *amx, cell *params)
{
if (GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]),0.0,100.0));
}
// Float:ns_get_exp(Player)
static cell AMX_NATIVE_CALL ns_get_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(EXP)));
}
// ns_set_exp(Player,Float:exp)
static cell AMX_NATIVE_CALL ns_set_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]));
return 1;
}
// Float:ns_add_exp(Player,Float:exp)
static cell AMX_NATIVE_CALL ns_add_exp(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]),0.0));
}
// ns_get_points(Player)
static cell AMX_NATIVE_CALL ns_get_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(POINTS));
}
// ns_set_points(Player,points)
static cell AMX_NATIVE_CALL ns_set_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx, params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]));
return 1;
}
// ns_add_points(Player,points)
static cell AMX_NATIVE_CALL ns_add_points(AMX *amx, cell *params)
{
if (!GameMan.IsCombat())
{
return 0;
}
CreatePlayerPointer(amx, params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]),0,9);
}
static cell AMX_NATIVE_CALL ns_get_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(SCORE));
}
static cell AMX_NATIVE_CALL ns_set_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_add_score(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
}
static cell AMX_NATIVE_CALL ns_get_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return get_private(player->GetEdict(),MAKE_OFFSET(DEATHS));
}
static cell AMX_NATIVE_CALL ns_set_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
set_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_add_deaths(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
return inc_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
}
static cell AMX_NATIVE_CALL ns_get_hive_ability(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
int result = get_private(player->GetEdict(), MAKE_OFFSET(HIVEABILITY));
return (params[2] > 0) ? (result >= params[2] - 1) : result;
}
static cell AMX_NATIVE_CALL ns_remove_upgrade(AMX *amx, cell *params)
{
CreatePlayerPointer(amx, params[1]);
if (!GameMan.IsCombat())
{
return 0;
}
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
// Upgrades are stored in a std::vector<int> in the player's private data
// The integer value represents the impulse for the offset
// std::vector's memory layout is:
// void *start
// void *lastobject
// void *lastreserved
struct upgradevector
{
int *start;
int *end;
int *allocated;
inline int size() { return static_cast<int>((reinterpret_cast<unsigned int>(end) - reinterpret_cast<unsigned int>(start)) / sizeof(int)); }
inline int at(int which) { return start[which]; }
inline void set(int which, int val) { start[which] = val; }
inline bool remove(int val)
{
for (int i = 0; i < this->size(); i++)
{
if (this->at(i) == val)
{
int last = this->size() - 1;
while (i < last)
{
this->set(i, this->at(i + 1));
i++;
}
this->end--;
return true;
}
}
return false;
}
inline void print()
{
printf("size: %d values: ", this->size());
for (int i = 0; i < this->size(); i++)
{
if (i != 0)
printf(", ");
printf("%d", this->at(i));
}
printf("\n");
}
};
upgradevector *bought = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_BOUGHT));
upgradevector *active = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_ACTIVE));
//bought->print();
//active->print();
bool bfound = bought->remove(params[2]);
bool afound = active->remove(params[2]);
if (bfound)
{
if (afound)
{
return 2;
}
return 1;
}
if (afound)
{
// shouldn't happen, but just incase
return 3;
}
return 0;
}
AMX_NATIVE_INFO player_memory_natives[] = {
{ "ns_get_res", ns_get_res },
{ "ns_set_res", ns_set_res },
{ "ns_add_res", ns_add_res },
{ "ns_get_exp", ns_get_exp },
{ "ns_set_exp", ns_set_exp },
{ "ns_add_exp", ns_add_exp },
{ "ns_get_points", ns_get_points },
{ "ns_set_points", ns_set_points },
{ "ns_add_points", ns_add_points },
{ "ns_set_score", ns_set_score },
{ "ns_get_score", ns_get_score },
{ "ns_add_score", ns_add_score },
{ "ns_get_deaths", ns_get_deaths },
{ "ns_set_deaths", ns_set_deaths },
{ "ns_add_deaths", ns_add_deaths },
{ "ns_get_hive_ability", ns_get_hive_ability },
{ "ns_remove_upgrade", ns_remove_upgrade },
{ NULL, NULL }
};
void AddNatives_PlayerMemory()
{
MF_AddNatives(player_memory_natives);
}

View File

@ -10,376 +10,376 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
int IsValidBuilding[AVH_USER3_MAX + 1] = {
0, // AVH_USER3_NONE = 0,
0, // AVH_USER3_MARINE_PLAYER,
0, // AVH_USER3_COMMANDER_PLAYER,
0, // AVH_USER3_ALIEN_PLAYER1,
0, // AVH_USER3_ALIEN_PLAYER2,
0, // AVH_USER3_ALIEN_PLAYER3,
0, // AVH_USER3_ALIEN_PLAYER4,
0, // AVH_USER3_ALIEN_PLAYER5,
0, // AVH_USER3_ALIEN_EMBRYO,
0, // AVH_USER3_SPAWN_TEAMONE,
0, // AVH_USER3_SPAWN_TEAMTWO,
0, // AVH_USER3_PARTICLE_ON, // only valid for AvHParticleEntity: entindex as int in fuser1, template index stored in fuser2
0, // AVH_USER3_PARTICLE_OFF, // only valid for AvHParticleEntity: particle system handle in fuser1
0, // AVH_USER3_WELD, // float progress (0 - 100) stored in fuser1
0, // AVH_USER3_ALPHA, // fuser1 indicates how much alpha this entity toggles to in commander mode, fuser2 for players
0, // AVH_USER3_MARINEITEM, // Something a friendly marine can pick up
0, // AVH_USER3_WAYPOINT,
2, // AVH_USER3_HIVE,
0, // AVH_USER3_NOBUILD,
0, // AVH_USER3_USEABLE,
0, // AVH_USER3_AUDIO_ON,
0, // AVH_USER3_AUDIO_OFF,
0, // AVH_USER3_FUNC_RESOURCE,
1, // AVH_USER3_COMMANDER_STATION,
1, // AVH_USER3_TURRET_FACTORY,
1, // AVH_USER3_ARMORY,
1, // AVH_USER3_ADVANCED_ARMORY,
1, // AVH_USER3_ARMSLAB,
1, // AVH_USER3_PROTOTYPE_LAB,
1, // AVH_USER3_OBSERVATORY,
0, // AVH_USER3_CHEMLAB,
0, // AVH_USER3_MEDLAB,
0, // AVH_USER3_NUKEPLANT,
1, // AVH_USER3_TURRET,
1, // AVH_USER3_SIEGETURRET,
1, // AVH_USER3_RESTOWER,
0, // AVH_USER3_PLACEHOLDER,
1, // AVH_USER3_INFANTRYPORTAL,
0, // AVH_USER3_NUKE,
0, // AVH_USER3_BREAKABLE,
0, // AVH_USER3_UMBRA,
1, // AVH_USER3_PHASEGATE,
2, // AVH_USER3_DEFENSE_CHAMBER,
2, // AVH_USER3_MOVEMENT_CHAMBER,
2, // AVH_USER3_OFFENSE_CHAMBER,
2, // AVH_USER3_SENSORY_CHAMBER,
2, // AVH_USER3_ALIENRESTOWER,
0, // AVH_USER3_HEAVY,
0, // AVH_USER3_JETPACK,
1, // AVH_USER3_ADVANCED_TURRET_FACTORY,
0, // AVH_USER3_SPAWN_READYROOM,
0, // AVH_USER3_CLIENT_COMMAND,
0, // AVH_USER3_FUNC_ILLUSIONARY,
0, // AVH_USER3_MENU_BUILD,
0, // AVH_USER3_MENU_BUILD_ADVANCED,
0, // AVH_USER3_MENU_ASSIST,
0, // AVH_USER3_MENU_EQUIP,
0, // AVH_USER3_MINE,
0 // AVH_USER3_MAX
};
// ns_build_structure(idStructure);
static cell AMX_NATIVE_CALL ns_build_structure(AMX *amx, cell *params)
{
// Trick NS into thinking that this structure is being spawned from the map
// set the "startbuilt" setting to 1, then remove it.
// "startbuilt" is set as "spawnflag" "1" in the ns.fgd
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free)
{
return 0;
};
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
{
return 0;
}
int StructureType=IsValidBuilding[Entity->v.iuser3];
if (StructureType==0)
{
return 0;
}
if (Entity->v.iuser3==AVH_USER3_HIVE)
{
return 0;
}
// Already set?
if (Entity->v.spawnflags & 1)
{
MDLL_Spawn(Entity);
goto undo_ghost;
}
Entity->v.spawnflags |= 1;
MDLL_Spawn(Entity);
Entity->v.spawnflags &= ~1;
undo_ghost:
if (StructureType==1) // marine, remove "ghost" appearance
{
if (get_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE))!=0)
{
set_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE),0);
Entity->v.rendermode=kRenderNormal;
Entity->v.renderamt=100.0;
}
}
return 1;
};
#define MASK_ELECTRICITY 8192
static cell AMX_NATIVE_CALL ns_get_build(AMX *amx, cell *params)
{
int iLength;
char *buildtype = MF_GetAmxString(amx,params[1],0,&iLength);
int iBuiltOnly = params[2];
int iNumber = params[3];
edict_t* pBuild = NULL;
int iCount=0;
while ((pBuild = UTIL_FindEntityByString(pBuild,"classname",buildtype)) != NULL)
{
if (iBuiltOnly > 0)
{
if (FStrEq("team_advarmory",buildtype) || FStrEq("team_advturretfactory",buildtype))
{
iCount++;
}
else
{
if (pBuild->v.fuser1 >= 1000 || pBuild->v.iuser4 & MASK_ELECTRICITY)
{
iCount++;
}
}
}
else
{
iCount++;
}
if (iNumber > 0 && iCount == iNumber)
return ENTINDEX_NEW(pBuild);
}
return iCount++;
}
static cell AMX_NATIVE_CALL ns_set_hive_trait(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(HIVE_TRAIT),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_get_hive_trait(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(HIVE_TRAIT));
}
static cell AMX_NATIVE_CALL ns_get_struct_owner(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(STRUCTOWNER));
}
// ns_set_struct_owner(idStructure,idPlayer) - -1 means no owner
static cell AMX_NATIVE_CALL ns_set_struct_owner(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (params[2] > gpGlobals->maxClients || params[2] < -1)
{
return 0;
}
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(STRUCTOWNER),params[2]);
return 1;
}
// Float:ns_get_obs_energy(id);
static cell AMX_NATIVE_CALL ns_get_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private(Entity,MAKE_OFFSET(OBS_ENERGY)));
};
// Float:ns_set_obs_energy(id,Float:energy);
static cell AMX_NATIVE_CALL ns_set_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_obs_energy(id,Float:energy);
static cell AMX_NATIVE_CALL ns_add_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]),0.0,100.0));
};
// Float:ns_get_weld_time(idWeldable);
static cell AMX_NATIVE_CALL ns_get_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
};
// ns_set_weld_time(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_set_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_weld_time(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_add_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]),0.0));
};
// Float:ns_get_weld_done(idWeldable);
static cell AMX_NATIVE_CALL ns_get_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_DONE)));
};
// ns_set_weld_done(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_set_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_weld_done(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_add_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]),0.0));
};
AMX_NATIVE_INFO structure_natives[] = {
{ "ns_build_structure", ns_build_structure },
{ "ns_get_build", ns_get_build },
{ "ns_get_hive_trait", ns_get_hive_trait },
{ "ns_set_hive_trait", ns_set_hive_trait },
{ "ns_get_struct_owner", ns_get_struct_owner },
{ "ns_set_struct_owner", ns_set_struct_owner },
{ "ns_get_obs_energy", ns_get_obs_energy },
{ "ns_set_obs_energy", ns_set_obs_energy },
{ "ns_add_obs_energy", ns_add_obs_energy },
{ "ns_get_weld_time", ns_get_weld_time },
{ "ns_set_weld_time", ns_set_weld_time },
{ "ns_add_weld_time", ns_add_weld_time },
{ "ns_get_weld_done", ns_get_weld_done },
{ "ns_set_weld_done", ns_set_weld_done },
{ "ns_add_weld_done", ns_add_weld_done },
/* prototypes for natives i have planned */
//{ "ns_get_phase_target", ns_get_phase_target },
//{ "ns_set_phase_target", ns_set_phase_target },
//{ "ns_set_phase_nextuse", ns_set_phase_nextuse },
//{ "ns_get_phase_nextuse", ns_get_phase_nextuse },
//{ "ns_add_phase_nextuse", ns_add_phase_nextuse },
{ NULL, NULL }
};
void AddNatives_Structure()
{
MF_AddNatives(structure_natives);
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
int IsValidBuilding[AVH_USER3_MAX + 1] = {
0, // AVH_USER3_NONE = 0,
0, // AVH_USER3_MARINE_PLAYER,
0, // AVH_USER3_COMMANDER_PLAYER,
0, // AVH_USER3_ALIEN_PLAYER1,
0, // AVH_USER3_ALIEN_PLAYER2,
0, // AVH_USER3_ALIEN_PLAYER3,
0, // AVH_USER3_ALIEN_PLAYER4,
0, // AVH_USER3_ALIEN_PLAYER5,
0, // AVH_USER3_ALIEN_EMBRYO,
0, // AVH_USER3_SPAWN_TEAMONE,
0, // AVH_USER3_SPAWN_TEAMTWO,
0, // AVH_USER3_PARTICLE_ON, // only valid for AvHParticleEntity: entindex as int in fuser1, template index stored in fuser2
0, // AVH_USER3_PARTICLE_OFF, // only valid for AvHParticleEntity: particle system handle in fuser1
0, // AVH_USER3_WELD, // float progress (0 - 100) stored in fuser1
0, // AVH_USER3_ALPHA, // fuser1 indicates how much alpha this entity toggles to in commander mode, fuser2 for players
0, // AVH_USER3_MARINEITEM, // Something a friendly marine can pick up
0, // AVH_USER3_WAYPOINT,
2, // AVH_USER3_HIVE,
0, // AVH_USER3_NOBUILD,
0, // AVH_USER3_USEABLE,
0, // AVH_USER3_AUDIO_ON,
0, // AVH_USER3_AUDIO_OFF,
0, // AVH_USER3_FUNC_RESOURCE,
1, // AVH_USER3_COMMANDER_STATION,
1, // AVH_USER3_TURRET_FACTORY,
1, // AVH_USER3_ARMORY,
1, // AVH_USER3_ADVANCED_ARMORY,
1, // AVH_USER3_ARMSLAB,
1, // AVH_USER3_PROTOTYPE_LAB,
1, // AVH_USER3_OBSERVATORY,
0, // AVH_USER3_CHEMLAB,
0, // AVH_USER3_MEDLAB,
0, // AVH_USER3_NUKEPLANT,
1, // AVH_USER3_TURRET,
1, // AVH_USER3_SIEGETURRET,
1, // AVH_USER3_RESTOWER,
0, // AVH_USER3_PLACEHOLDER,
1, // AVH_USER3_INFANTRYPORTAL,
0, // AVH_USER3_NUKE,
0, // AVH_USER3_BREAKABLE,
0, // AVH_USER3_UMBRA,
1, // AVH_USER3_PHASEGATE,
2, // AVH_USER3_DEFENSE_CHAMBER,
2, // AVH_USER3_MOVEMENT_CHAMBER,
2, // AVH_USER3_OFFENSE_CHAMBER,
2, // AVH_USER3_SENSORY_CHAMBER,
2, // AVH_USER3_ALIENRESTOWER,
0, // AVH_USER3_HEAVY,
0, // AVH_USER3_JETPACK,
1, // AVH_USER3_ADVANCED_TURRET_FACTORY,
0, // AVH_USER3_SPAWN_READYROOM,
0, // AVH_USER3_CLIENT_COMMAND,
0, // AVH_USER3_FUNC_ILLUSIONARY,
0, // AVH_USER3_MENU_BUILD,
0, // AVH_USER3_MENU_BUILD_ADVANCED,
0, // AVH_USER3_MENU_ASSIST,
0, // AVH_USER3_MENU_EQUIP,
0, // AVH_USER3_MINE,
0 // AVH_USER3_MAX
};
// ns_build_structure(idStructure);
static cell AMX_NATIVE_CALL ns_build_structure(AMX *amx, cell *params)
{
// Trick NS into thinking that this structure is being spawned from the map
// set the "startbuilt" setting to 1, then remove it.
// "startbuilt" is set as "spawnflag" "1" in the ns.fgd
CreateNonPlayerEdict(amx,params[1]);
if (Entity->free)
{
return 0;
};
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
{
return 0;
}
int StructureType=IsValidBuilding[Entity->v.iuser3];
if (StructureType==0)
{
return 0;
}
if (Entity->v.iuser3==AVH_USER3_HIVE)
{
return 0;
}
// Already set?
if (Entity->v.spawnflags & 1)
{
MDLL_Spawn(Entity);
goto undo_ghost;
}
Entity->v.spawnflags |= 1;
MDLL_Spawn(Entity);
Entity->v.spawnflags &= ~1;
undo_ghost:
if (StructureType==1) // marine, remove "ghost" appearance
{
if (get_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE))!=0)
{
set_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE),0);
Entity->v.rendermode=kRenderNormal;
Entity->v.renderamt=100.0;
}
}
return 1;
};
#define MASK_ELECTRICITY 8192
static cell AMX_NATIVE_CALL ns_get_build(AMX *amx, cell *params)
{
int iLength;
char *buildtype = MF_GetAmxString(amx,params[1],0,&iLength);
int iBuiltOnly = params[2];
int iNumber = params[3];
edict_t* pBuild = NULL;
int iCount=0;
while ((pBuild = UTIL_FindEntityByString(pBuild,"classname",buildtype)) != NULL)
{
if (iBuiltOnly > 0)
{
if (FStrEq("team_advarmory",buildtype) || FStrEq("team_advturretfactory",buildtype))
{
iCount++;
}
else
{
if (pBuild->v.fuser1 >= 1000 || pBuild->v.iuser4 & MASK_ELECTRICITY)
{
iCount++;
}
}
}
else
{
iCount++;
}
if (iNumber > 0 && iCount == iNumber)
return ENTINDEX_NEW(pBuild);
}
return iCount++;
}
static cell AMX_NATIVE_CALL ns_set_hive_trait(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(HIVE_TRAIT),static_cast<int>(params[2]));
return 1;
}
static cell AMX_NATIVE_CALL ns_get_hive_trait(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(HIVE_TRAIT));
}
static cell AMX_NATIVE_CALL ns_get_struct_owner(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(STRUCTOWNER));
}
// ns_set_struct_owner(idStructure,idPlayer) - -1 means no owner
static cell AMX_NATIVE_CALL ns_set_struct_owner(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (params[2] > gpGlobals->maxClients || params[2] < -1)
{
return 0;
}
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(STRUCTOWNER),params[2]);
return 1;
}
// Float:ns_get_obs_energy(id);
static cell AMX_NATIVE_CALL ns_get_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private(Entity,MAKE_OFFSET(OBS_ENERGY)));
};
// Float:ns_set_obs_energy(id,Float:energy);
static cell AMX_NATIVE_CALL ns_set_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_obs_energy(id,Float:energy);
static cell AMX_NATIVE_CALL ns_add_obs_energy(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]),0.0,100.0));
};
// Float:ns_get_weld_time(idWeldable);
static cell AMX_NATIVE_CALL ns_get_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
};
// ns_set_weld_time(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_set_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_weld_time(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_add_weld_time(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]),0.0));
};
// Float:ns_get_weld_done(idWeldable);
static cell AMX_NATIVE_CALL ns_get_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_DONE)));
};
// ns_set_weld_done(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_set_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]));
return 1;
};
// Float:ns_add_weld_done(idWeldable,Float:value);
static cell AMX_NATIVE_CALL ns_add_weld_done(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL)
{
return 0;
}
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]),0.0));
};
AMX_NATIVE_INFO structure_natives[] = {
{ "ns_build_structure", ns_build_structure },
{ "ns_get_build", ns_get_build },
{ "ns_get_hive_trait", ns_get_hive_trait },
{ "ns_set_hive_trait", ns_set_hive_trait },
{ "ns_get_struct_owner", ns_get_struct_owner },
{ "ns_set_struct_owner", ns_set_struct_owner },
{ "ns_get_obs_energy", ns_get_obs_energy },
{ "ns_set_obs_energy", ns_set_obs_energy },
{ "ns_add_obs_energy", ns_add_obs_energy },
{ "ns_get_weld_time", ns_get_weld_time },
{ "ns_set_weld_time", ns_set_weld_time },
{ "ns_add_weld_time", ns_add_weld_time },
{ "ns_get_weld_done", ns_get_weld_done },
{ "ns_set_weld_done", ns_set_weld_done },
{ "ns_add_weld_done", ns_add_weld_done },
/* prototypes for natives i have planned */
//{ "ns_get_phase_target", ns_get_phase_target },
//{ "ns_set_phase_target", ns_set_phase_target },
//{ "ns_set_phase_nextuse", ns_set_phase_nextuse },
//{ "ns_get_phase_nextuse", ns_get_phase_nextuse },
//{ "ns_add_phase_nextuse", ns_add_phase_nextuse },
{ NULL, NULL }
};
void AddNatives_Structure()
{
MF_AddNatives(structure_natives);
}

View File

@ -10,450 +10,450 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
// ns_has_weapon(idPlayer,NsWeapon,set=0)
static cell AMX_NATIVE_CALL ns_has_weapon(AMX *amx,cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (params[3] == -1)
{
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
{
return 1;
}
}
else
{
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
{
if (params[3] == 0)
{
player->GetPev()->weapons &= ~(1<<params[2]);
return 1;
}
return 0;
}
else
{
if (params[3] == 1)
{
player->GetPev()->weapons |= (1<<params[2]);
return 1;
}
}
return 0;
}
return 0;
}
// ns_set_weap_dmg(WeaponID,Float:damage)
static cell AMX_NATIVE_CALL ns_set_weapon_dmg(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WEAPDMG),amx_ctof2(params[2]));
return 1;
}
// Float:ns_get_weap_dmg(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_dmg(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPDMG));
return amx_ftoc2(ret);
}
// ns_set_weap_range(WeaponID,Float:range)
static cell AMX_NATIVE_CALL ns_set_weapon_range(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WEAPRANGE),amx_ctof2(params[2]));
return 1;
}
// Float:ns_get_weap_range(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_range(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPRANGE));
return amx_ftoc2(ret);
}
// ns_get_weap_ammo(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(WEAPCLIP));
}
// ns_set_weap_ammo(WeaponID,ammo)
static cell AMX_NATIVE_CALL ns_set_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(WEAPCLIP),params[2]);
return 1;
}
static cell AMX_NATIVE_CALL ns_add_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
return inc_private(Entity,MAKE_OFFSET(WEAPCLIP),static_cast<int>(params[2]),0);
}
// ns_get_weap_reserve(PlayerID,WeaponType)
static cell AMX_NATIVE_CALL ns_get_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL));
case WEAPON_LMG:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG));
case WEAPON_SHOTGUN:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN));
case WEAPON_HMG:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG));
case WEAPON_GRENADE_GUN:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL));
case WEAPON_GRENADE:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG));
default:
return 0;
}
return 0;
}
static cell AMX_NATIVE_CALL ns_set_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3]);
return 1;
case WEAPON_LMG:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3]);
return 1;
case WEAPON_SHOTGUN:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3]);
return 1;
case WEAPON_HMG:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3]);
return 1;
case WEAPON_GRENADE_GUN:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3]);
return 1;
case WEAPON_GRENADE:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3]);
return 1;
default:
return 0;
}
return 0;
}
static cell AMX_NATIVE_CALL ns_add_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3],0);
case WEAPON_LMG:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3],0);
case WEAPON_SHOTGUN:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3],0);
case WEAPON_HMG:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3],0);
case WEAPON_GRENADE_GUN:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3],0);
case WEAPON_GRENADE:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3],0);
default:
return 0;
}
return 0;
}
// ns_get_weapon(idPlayer,weaponid,&weapontype=0)
static cell AMX_NATIVE_CALL ns_get_weapon(AMX *amx, cell *params)
{
// Peachy did it like this:
// if weapontype is 0, return the primary weapon index of the player
// if weapontype is < 0, return the last inventory weapon index of the player
// otherwise, scan the player's inventory and look for a weapon of the given type
// such as WEAPON_KNIFE, etc, etc
// I added the last parameter, which will byref the weapontype of the weapon found
// returns 0 on failure
// last param default value added to not conflict with his version
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
if (params[2]<0) // find lastinv weapon
{
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(LAST_WEAPON)));
if (Weapon==NULL) // no weapon
{
return 0;
}
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
{
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
}
return ENTINDEX_NEW(Weapon);
}
if (params[2]==0) // find current weapon
{
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(CURRENT_WEAPON)));
if (Weapon==NULL) // no weapon
{
return 0;
}
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
{
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
}
return ENTINDEX_NEW(Weapon);
}
// Finding weapon by ID
char **pPlayerItems = reinterpret_cast<char**>(static_cast<char*>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(PLAYER_ITEMS));
char *pItem;
int weapon=params[2];
for (int i = 0; i < 6; i++)
{
pItem = pPlayerItems[i];
while (pItem)
{
if (*(int *)(pItem + MAKE_OFFSET(WEAPID)) == weapon)
{
return ENTINDEX_NEW(private_to_edict(pItem));
}
else
{
pItem = *(char **)(pItem + MAKE_OFFSET(WEAP_NEXT));
}
}
}
return 0;
}
#ifdef DEVELOPER_BUILD
// ns_find_weapon_offset(idPlayer,"primweapon","lastinvweapon")
static cell AMX_NATIVE_CALL ns_find_weapon_offset(AMX *amx, cell *params)
{
char *SPrimWeapon=MF_GetAmxString(amx,params[2],0,NULL);
char *SLastInv=MF_GetAmxString(amx,params[3],1,NULL);
edict_t *ePlayer=INDEXENT_NEW(params[1]);
// Locate entities by name
edict_t *PrimWeapon=NULL;
edict_t *LastInv=NULL;
edict_t *Temp=NULL;
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SPrimWeapon))!=NULL)
{
if (Temp->v.owner==ePlayer)
{
PrimWeapon=Temp;
break;
}
}
Temp=NULL;
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SLastInv))!=NULL)
{
if (Temp->v.owner==ePlayer)
{
LastInv=Temp;
break;
}
}
if (LastInv == NULL || PrimWeapon == NULL)
{
if (LastInv==NULL)
{
MF_Log("LastInv==NULL");
}
if (PrimWeapon==NULL)
{
MF_Log("PrimWeapon=NULL");
}
return 0;
}
// now iterate through the client's private data until we find the pointer to PrimWeapon/LastInv's offset
unsigned int *Ptr=(unsigned int*)ePlayer->pvPrivateData;
int FoundLastInv=0;
int FoundPrim=0;
size_t count=0;
unsigned int iPrim;
unsigned int iLast;
// so nasty D: this is basically horrible_cast
union bleh
{
void *ptr;
unsigned int ival;
}blah;
blah.ptr=PrimWeapon->pvPrivateData;
iPrim=blah.ival;
blah.ptr=LastInv->pvPrivateData;
iLast=blah.ival;
while (count<4000)
{
if (*Ptr==iLast)
{
MF_Log("Found LastInv: %d",count);
FoundLastInv=1;
}
if (*Ptr==iPrim)
{
MF_Log("Found Primary: %d",count);
FoundPrim=1;
}
if (FoundLastInv && FoundPrim)
{
//break;
}
count+=4;
Ptr++;
}
return 1;
}
#endif
AMX_NATIVE_INFO weapon_natives[] = {
{ "ns_has_weapon", ns_has_weapon },
{ "ns_set_weap_dmg", ns_set_weapon_dmg },
{ "ns_get_weap_dmg", ns_get_weapon_dmg },
{ "ns_set_weap_range", ns_set_weapon_range },
{ "ns_get_weap_range", ns_get_weapon_range },
{ "ns_set_weap_clip", ns_set_weapon_clip },
{ "ns_get_weap_clip", ns_get_weapon_clip },
{ "ns_add_weap_clip", ns_add_weapon_clip },
{ "ns_set_weap_reserve", ns_set_weap_reserve },
{ "ns_get_weap_reserve", ns_get_weap_reserve },
{ "ns_add_weap_reserve", ns_add_weap_reserve },
{ "ns_get_weapon", ns_get_weapon},
#ifdef DEVELOPER_BUILD
{ "ns_find_weapon_offset", ns_find_weapon_offset},
#endif
{ NULL, NULL }
};
void AddNatives_Weapons()
{
MF_AddNatives(weapon_natives);
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "NEW_Util.h"
#include "GameManager.h"
#include "CPlayer.h"
// ns_has_weapon(idPlayer,NsWeapon,set=0)
static cell AMX_NATIVE_CALL ns_has_weapon(AMX *amx,cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (params[3] == -1)
{
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
{
return 1;
}
}
else
{
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
{
if (params[3] == 0)
{
player->GetPev()->weapons &= ~(1<<params[2]);
return 1;
}
return 0;
}
else
{
if (params[3] == 1)
{
player->GetPev()->weapons |= (1<<params[2]);
return 1;
}
}
return 0;
}
return 0;
}
// ns_set_weap_dmg(WeaponID,Float:damage)
static cell AMX_NATIVE_CALL ns_set_weapon_dmg(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WEAPDMG),amx_ctof2(params[2]));
return 1;
}
// Float:ns_get_weap_dmg(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_dmg(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPDMG));
return amx_ftoc2(ret);
}
// ns_set_weap_range(WeaponID,Float:range)
static cell AMX_NATIVE_CALL ns_set_weapon_range(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private_f(Entity,MAKE_OFFSET(WEAPRANGE),amx_ctof2(params[2]));
return 1;
}
// Float:ns_get_weap_range(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_range(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPRANGE));
return amx_ftoc2(ret);
}
// ns_get_weap_ammo(WeaponID)
static cell AMX_NATIVE_CALL ns_get_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
return get_private(Entity,MAKE_OFFSET(WEAPCLIP));
}
// ns_set_weap_ammo(WeaponID,ammo)
static cell AMX_NATIVE_CALL ns_set_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
set_private(Entity,MAKE_OFFSET(WEAPCLIP),params[2]);
return 1;
}
static cell AMX_NATIVE_CALL ns_add_weapon_clip(AMX *amx, cell *params)
{
CreateNonPlayerEdict(amx,params[1]);
if (Entity->pvPrivateData == NULL || Entity->free)
{
return 0;
}
return inc_private(Entity,MAKE_OFFSET(WEAPCLIP),static_cast<int>(params[2]),0);
}
// ns_get_weap_reserve(PlayerID,WeaponType)
static cell AMX_NATIVE_CALL ns_get_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL));
case WEAPON_LMG:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG));
case WEAPON_SHOTGUN:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN));
case WEAPON_HMG:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG));
case WEAPON_GRENADE_GUN:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL));
case WEAPON_GRENADE:
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG));
default:
return 0;
}
return 0;
}
static cell AMX_NATIVE_CALL ns_set_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3]);
return 1;
case WEAPON_LMG:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3]);
return 1;
case WEAPON_SHOTGUN:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3]);
return 1;
case WEAPON_HMG:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3]);
return 1;
case WEAPON_GRENADE_GUN:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3]);
return 1;
case WEAPON_GRENADE:
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3]);
return 1;
default:
return 0;
}
return 0;
}
static cell AMX_NATIVE_CALL ns_add_weap_reserve(AMX *amx, cell *params)
{
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected() || !player->HasPrivateData())
{
return 0;
}
switch (params[2])
{
case WEAPON_PISTOL:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3],0);
case WEAPON_LMG:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3],0);
case WEAPON_SHOTGUN:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3],0);
case WEAPON_HMG:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3],0);
case WEAPON_GRENADE_GUN:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3],0);
case WEAPON_GRENADE:
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3],0);
default:
return 0;
}
return 0;
}
// ns_get_weapon(idPlayer,weaponid,&weapontype=0)
static cell AMX_NATIVE_CALL ns_get_weapon(AMX *amx, cell *params)
{
// Peachy did it like this:
// if weapontype is 0, return the primary weapon index of the player
// if weapontype is < 0, return the last inventory weapon index of the player
// otherwise, scan the player's inventory and look for a weapon of the given type
// such as WEAPON_KNIFE, etc, etc
// I added the last parameter, which will byref the weapontype of the weapon found
// returns 0 on failure
// last param default value added to not conflict with his version
CreatePlayerPointer(amx,params[1]);
if (!player->IsConnected())
{
return 0;
}
if (!player->HasPrivateData())
{
return 0;
}
if (params[2]<0) // find lastinv weapon
{
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(LAST_WEAPON)));
if (Weapon==NULL) // no weapon
{
return 0;
}
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
{
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
}
return ENTINDEX_NEW(Weapon);
}
if (params[2]==0) // find current weapon
{
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(CURRENT_WEAPON)));
if (Weapon==NULL) // no weapon
{
return 0;
}
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
{
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
}
return ENTINDEX_NEW(Weapon);
}
// Finding weapon by ID
char **pPlayerItems = reinterpret_cast<char**>(static_cast<char*>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(PLAYER_ITEMS));
char *pItem;
int weapon=params[2];
for (int i = 0; i < 6; i++)
{
pItem = pPlayerItems[i];
while (pItem)
{
if (*(int *)(pItem + MAKE_OFFSET(WEAPID)) == weapon)
{
return ENTINDEX_NEW(private_to_edict(pItem));
}
else
{
pItem = *(char **)(pItem + MAKE_OFFSET(WEAP_NEXT));
}
}
}
return 0;
}
#ifdef DEVELOPER_BUILD
// ns_find_weapon_offset(idPlayer,"primweapon","lastinvweapon")
static cell AMX_NATIVE_CALL ns_find_weapon_offset(AMX *amx, cell *params)
{
char *SPrimWeapon=MF_GetAmxString(amx,params[2],0,NULL);
char *SLastInv=MF_GetAmxString(amx,params[3],1,NULL);
edict_t *ePlayer=INDEXENT_NEW(params[1]);
// Locate entities by name
edict_t *PrimWeapon=NULL;
edict_t *LastInv=NULL;
edict_t *Temp=NULL;
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SPrimWeapon))!=NULL)
{
if (Temp->v.owner==ePlayer)
{
PrimWeapon=Temp;
break;
}
}
Temp=NULL;
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SLastInv))!=NULL)
{
if (Temp->v.owner==ePlayer)
{
LastInv=Temp;
break;
}
}
if (LastInv == NULL || PrimWeapon == NULL)
{
if (LastInv==NULL)
{
MF_Log("LastInv==NULL");
}
if (PrimWeapon==NULL)
{
MF_Log("PrimWeapon=NULL");
}
return 0;
}
// now iterate through the client's private data until we find the pointer to PrimWeapon/LastInv's offset
unsigned int *Ptr=(unsigned int*)ePlayer->pvPrivateData;
int FoundLastInv=0;
int FoundPrim=0;
size_t count=0;
unsigned int iPrim;
unsigned int iLast;
// so nasty D: this is basically horrible_cast
union bleh
{
void *ptr;
unsigned int ival;
}blah;
blah.ptr=PrimWeapon->pvPrivateData;
iPrim=blah.ival;
blah.ptr=LastInv->pvPrivateData;
iLast=blah.ival;
while (count<4000)
{
if (*Ptr==iLast)
{
MF_Log("Found LastInv: %d",count);
FoundLastInv=1;
}
if (*Ptr==iPrim)
{
MF_Log("Found Primary: %d",count);
FoundPrim=1;
}
if (FoundLastInv && FoundPrim)
{
//break;
}
count+=4;
Ptr++;
}
return 1;
}
#endif
AMX_NATIVE_INFO weapon_natives[] = {
{ "ns_has_weapon", ns_has_weapon },
{ "ns_set_weap_dmg", ns_set_weapon_dmg },
{ "ns_get_weap_dmg", ns_get_weapon_dmg },
{ "ns_set_weap_range", ns_set_weapon_range },
{ "ns_get_weap_range", ns_get_weapon_range },
{ "ns_set_weap_clip", ns_set_weapon_clip },
{ "ns_get_weap_clip", ns_get_weapon_clip },
{ "ns_add_weap_clip", ns_add_weapon_clip },
{ "ns_set_weap_reserve", ns_set_weap_reserve },
{ "ns_get_weap_reserve", ns_get_weap_reserve },
{ "ns_add_weap_reserve", ns_add_weap_reserve },
{ "ns_get_weapon", ns_get_weapon},
#ifdef DEVELOPER_BUILD
{ "ns_find_weapon_offset", ns_find_weapon_offset},
#endif
{ NULL, NULL }
};
void AddNatives_Weapons()
{
MF_AddNatives(weapon_natives);
}

View File

@ -10,174 +10,174 @@
//
// Natural Selection Module
//
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "CPlayer.h"
/**
* Scans through all hives and finds the one currently building
*/
int UTIL_FindBuildingHive(void)
{
edict_t *Entity=NULL;
while ((Entity = UTIL_FindEntityByString(Entity,"classname","team_hive")))
{
// is alive active not fully built
if (Entity->v.health > 0 && Entity->v.solid > 0 && Entity->v.fuser1 < 1000)
{
return ENTINDEX_NEW(Entity);
}
}
return 0;
}
edict_t *UTIL_FindEntityByString(edict_t *Start, const char *Keyword, const char *Value)
{
edict_t *Entity;
Entity=FIND_ENTITY_BY_STRING(Start, Keyword, Value);
if(!FNullEnt(Entity))
{
return Entity;
}
return NULL;
}
/**
* Returns TRUE if the provided native is used in a loaded plugin
* FALSE otherwise.
*/
BOOL UTIL_CheckForNative(const char *NativeName)
{
AMX *amx;
char blah[64];
int FunctionIndex;
int i=0;
strncpy(blah,NativeName,63);
// Loop through all running scripts
while((amx=MF_GetScriptAmx(i++))!=NULL)
{
// Scan for native
if (MF_AmxFindNative(amx, blah, &FunctionIndex) == AMX_ERR_NONE)
{
// Native was found.
return TRUE;
}
}
return FALSE; // no native found in any loaded script
}
/**
* Scans an amxx plugin for a public
* returns whether or not that public exists
*/
BOOL UTIL_CheckForPublic(const char *publicname)
{
AMX *amx;
char blah[64];
int FunctionIndex;
int i=0;
strncpy(blah,publicname,63);
// Loop through all running scripts
while((amx=MF_GetScriptAmx(i++))!=NULL)
{
// Scan for public
if (MF_AmxFindPublic(amx, blah, &FunctionIndex) == AMX_ERR_NONE)
{
// Public was found.
return TRUE;
}
}
return FALSE; // no public found in any loaded script
}
CPlayer *UTIL_PlayerByCID(int CID)
{
int i=0;
while (i++<gpGlobals->maxClients)
{
if (GETPLAYERUSERID(g_player[i].GetEdict())==CID)
{
return &g_player[i];
}
}
return NULL;
}
/**
* Converts a log string (eg: "sawce<1><STEAM_0:1:4560311><marine1team>")
* into a player index
*/
int UTIL_LogToIndex(const char *LogLine)
{
char NameBuffer[33] ; // Temporary buffer to store the CID String
char *StrLocation; // Location in the LogLine pointer
unsigned int Count=0; // Count for how many <'s we've passed
size_t Length; // Length of LogLine
Length=strlen(LogLine);
StrLocation=const_cast<char *>(LogLine) + Length; // Should now point to the last >
while (Length--)
{
if (*StrLocation--=='<')
{
if (++Count==3) // 3rd match is end of CID
{
break;
}
}
}
if (Count!=3) // Invalid name somehow??
{
return 0;
}
if (Length > 32) // The name is too long somehow? stop here...
{
return 0;
}
strncpy(NameBuffer,LogLine,Length);
Count=0;
while ((int)Count++<gpGlobals->maxClients)
{
if (strcmp(NameBuffer,STRING(INDEXENT_NEW(Count)->v.netname))==0)
{
return Count;
}
}
return 0;
}
char *UTIL_ToLowerCase(const char *str)
{
size_t len = strlen(str);
char *buffer = new char[len + 1];
for (size_t i = 0; i < len; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
buffer[i] = tolower(str[i]);
else
buffer[i] = str[i];
}
buffer[len] = '\0';
return buffer;
}
#include "amxxmodule.h"
#include "ns.h"
#include "utilfunctions.h"
#include "CPlayer.h"
/**
* Scans through all hives and finds the one currently building
*/
int UTIL_FindBuildingHive(void)
{
edict_t *Entity=NULL;
while ((Entity = UTIL_FindEntityByString(Entity,"classname","team_hive")))
{
// is alive active not fully built
if (Entity->v.health > 0 && Entity->v.solid > 0 && Entity->v.fuser1 < 1000)
{
return ENTINDEX_NEW(Entity);
}
}
return 0;
}
edict_t *UTIL_FindEntityByString(edict_t *Start, const char *Keyword, const char *Value)
{
edict_t *Entity;
Entity=FIND_ENTITY_BY_STRING(Start, Keyword, Value);
if(!FNullEnt(Entity))
{
return Entity;
}
return NULL;
}
/**
* Returns TRUE if the provided native is used in a loaded plugin
* FALSE otherwise.
*/
BOOL UTIL_CheckForNative(const char *NativeName)
{
AMX *amx;
char blah[64];
int FunctionIndex;
int i=0;
strncpy(blah,NativeName,63);
// Loop through all running scripts
while((amx=MF_GetScriptAmx(i++))!=NULL)
{
// Scan for native
if (MF_AmxFindNative(amx, blah, &FunctionIndex) == AMX_ERR_NONE)
{
// Native was found.
return TRUE;
}
}
return FALSE; // no native found in any loaded script
}
/**
* Scans an amxx plugin for a public
* returns whether or not that public exists
*/
BOOL UTIL_CheckForPublic(const char *publicname)
{
AMX *amx;
char blah[64];
int FunctionIndex;
int i=0;
strncpy(blah,publicname,63);
// Loop through all running scripts
while((amx=MF_GetScriptAmx(i++))!=NULL)
{
// Scan for public
if (MF_AmxFindPublic(amx, blah, &FunctionIndex) == AMX_ERR_NONE)
{
// Public was found.
return TRUE;
}
}
return FALSE; // no public found in any loaded script
}
CPlayer *UTIL_PlayerByCID(int CID)
{
int i=0;
while (i++<gpGlobals->maxClients)
{
if (GETPLAYERUSERID(g_player[i].GetEdict())==CID)
{
return &g_player[i];
}
}
return NULL;
}
/**
* Converts a log string (eg: "sawce<1><STEAM_0:1:4560311><marine1team>")
* into a player index
*/
int UTIL_LogToIndex(const char *LogLine)
{
char NameBuffer[33] ; // Temporary buffer to store the CID String
char *StrLocation; // Location in the LogLine pointer
unsigned int Count=0; // Count for how many <'s we've passed
size_t Length; // Length of LogLine
Length=strlen(LogLine);
StrLocation=const_cast<char *>(LogLine) + Length; // Should now point to the last >
while (Length--)
{
if (*StrLocation--=='<')
{
if (++Count==3) // 3rd match is end of CID
{
break;
}
}
}
if (Count!=3) // Invalid name somehow??
{
return 0;
}
if (Length > 32) // The name is too long somehow? stop here...
{
return 0;
}
strncpy(NameBuffer,LogLine,Length);
Count=0;
while ((int)Count++<gpGlobals->maxClients)
{
if (strcmp(NameBuffer,STRING(INDEXENT_NEW(Count)->v.netname))==0)
{
return Count;
}
}
return 0;
}
char *UTIL_ToLowerCase(const char *str)
{
size_t len = strlen(str);
char *buffer = new char[len + 1];
for (size_t i = 0; i < len; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
buffer[i] = tolower(str[i]);
else
buffer[i] = str[i];
}
buffer[len] = '\0';
return buffer;
}