SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
|
02-11-2010
, 01:42
Re: Concept: Project base
|
#5
|
Code:
/*
* ============================================================================
*
* Red Rover
*
* File: gamedata.inc
* Type: Module
* Description: Handles virtual offsets and signatures.
*
* Copyright (C) 2009-2010 Greyscale
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
/**
* General module defines.
*/
#define GAMEDATA_FILE "plugin.redrover"
/**
* This module's identifier.
*/
//new Module:g_moduleGameData;
/**
* Gamedata handles.
*/
new Handle:g_hGameConfig;
new Handle:g_hTerminateRound;
/**
* Register this module.
*/
GameData_Register()
{
// Define all the module's data as layed out by enum ModuleData in project.inc.
new moduledata[ModuleData];
moduledata[ModuleData_Disabled] = false;
moduledata[ModuleData_Hidden] = true;
strcopy(moduledata[ModuleData_FullName], CM_DATA_FULLNAME, "GameData");
strcopy(moduledata[ModuleData_ShortName], CM_DATA_SHORTNAME, "gamedata");
strcopy(moduledata[ModuleData_Description], CM_DATA_DESCRIPTION, "Handles virtual offsets and signatures.");
// Send this array of data to the module manager.
/*g_moduleGameData = */
ModuleMgr_Register(moduledata);
// Register all the events needed for this module.
//EventMgr_RegisterEvent(g_moduleModule, Event_OnAllPluginsLoaded, "_OnAllPluginsLoaded");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnPluginEnd, "_OnPluginEnd");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnMapStart, "_OnMapStart");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnMapEnd, "_OnMapEnd");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnAutoConfigsBuffered, "_OnAutoConfigsBuffered");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnConfigsExecuted, "_OnConfigsExecuted");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnClientPutInServer, "_OnClientPutInServer");
//EventMgr_RegisterEvent(g_moduleModule, Event_OnClientDisconnect, "_OnClientDisconnect");
//EventMgr_RegisterEvent(g_moduleModule, Event_RoundStart, "_RoundStart");
//EventMgr_RegisterEvent(g_moduleModule, Event_RoundFreezeEnd, "_RoundFreezeEnd");
//EventMgr_RegisterEvent(g_moduleModule, Event_RoundEnd, "_RoundEnd");
//EventMgr_RegisterEvent(g_moduleModule, Event_PlayerTeam, "_PlayerTeam");
//EventMgr_RegisterEvent(g_moduleModule, Event_PlayerSpawn, "_PlayerSpawn");
//EventMgr_RegisterEvent(g_moduleModule, Event_PlayerHurt, "_PlayerHurt");
//EventMgr_RegisterEvent(g_moduleModule, Event_PlayerDeath, "_PlayerDeath");
//EventMgr_RegisterEvent(g_moduleModule, Event_PlayerJump, "_PlayerJump");
//EventMgr_RegisterEvent(g_moduleModule, Event_WeaponFire, "_WeaponFire");
}
/**
* Plugin is loading.
*/
GameData_OnPluginStart()
{
// Register the module.
GameData_Register();
// Load game config file.
g_hGameConfig = LoadGameConfigFile(GAMEDATA_FILE);
// If gamedata file can't be loaded, then stop the plugin.
if (g_hGameConfig == INVALID_HANDLE)
{
SetFailState("Can't load game config file (%s) from the \"gamedata\" directory.", GAMEDATA_FILE);
}
// Prep the SDKCall for "TerminateRound."
StartPrepSDKCall(SDKCall_GameRules);
PrepSDKCall_SetFromConf(g_hGameConfig, SDKConf_Signature, "TerminateRound");
PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
g_hTerminateRound = EndPrepSDKCall();
// If offset "TerminateRound" can't be found, then stop the plugin.
if(g_hTerminateRound == INVALID_HANDLE)
{
SetFailState("Signature \"CGameRules::TerminateRound\" was not found.");
}
}
/**
* All round end reasons.
* Used an enum instead of defines so the include order doesn't matter.
*/
enum RoundEndReasons
{
ROUNDEND_TARGET_BOMBED = 1, /** Target Successfully Bombed! */
ROUNDEND_VIP_ESCAPED = 2, /** The VIP has escaped! */
ROUNDEND_VIP_ASSASSINATED = 3, /** VIP has been assassinated! */
ROUNDEND_TERRORISTS_ESCAPED = 4, /** The terrorists have escaped! */
ROUNDEND_CTS_PREVENTESCAPE = 5, /** The CT's have prevented most of the terrorists from escaping! */
ROUNDEND_ESC_TS_NEUTRALIZED = 6, /** Escaping terrorists have all been neutralized! */
ROUNDEND_BOMB_DEFUSED = 7, /** The bomb has been defused! */
ROUNDEND_CTS_WIN = 8, /** Counter-Terrorists Win! */
ROUNDEND_TERRORISTS_WIN = 9, /** Terrorists Win! */
ROUNDEND_ROUND_DRAW = 10, /** Round Draw! */
ROUNDEND_ALL_HOSTAGES_RESCUED = 11, /** All Hostages have been rescued! */
ROUNDEND_TARGET_SAVED = 12, /** Target has been saved! */
ROUNDEND_HOSTAGES_NOT_RESCUED = 13, /** Hostages have not been rescued! */
ROUNDEND_TERRORISTS_NOT_ESCAPED = 14, /** Terrorists have not escaped! */
ROUNDEND_VIP_NOT_ESCAPED = 15, /** VIP has not escaped! */
ROUNDEND_GAME_COMMENCING = 16 /** Game Commencing! */
}
/**
* Terminates the round.
*
* @param delay The time between ending the round, and the new round beginning.
* @param reason The reason for the round ending. See enum RoundEndReasons.
*/
stock GameData_TerminateRound(Float:delay, RoundEndReasons:reason)
{
SDKCall(g_hTerminateRound, delay, _:reason);
}
/**
* Takes a winning team index and returns its corresponding round end reason.
* Ex: Takes index '2' and returns the Terrorists_Win round end reason.
*
* @param teamindex The team index that won the round.
*
* @return The round end reason. ROUNDEND_GAME_COMMENCING if invalid teamindex.
*/
stock RoundEndReasons:Util_TeamToReason(teamindex)
{
if (teamindex == CS_TEAM_T)
return ROUNDEND_TERRORISTS_WIN;
else if (teamindex == CS_TEAM_CT)
return ROUNDEND_CTS_WIN;
return ROUNDEND_GAME_COMMENCING;
}
Here's an example of a module that can easily be ported between plugins using the project base.
This module can be developed as a separate entity and then the file can be copied into a project base and easily be compiled into the plugin. This specific module requires nothing but the modulemanager.inc (and of course project.inc which is just a plethora of defines)
I hope once it's out of development others can find use in this for their projects. I plan on making several more useful modules like this that can be used in any variety of plugins.
For example:
Usermessage module: Just a library of usermsgs wrapped in functions with defined parameters.
No objectives module: Creates a cvar (the prefix of the cvar will even change automatically between different projects) that strips all objectives from the map.
Also, as it stands now, this will be the module template.
Code:
/*
* ============================================================================
*
* <Project Name>
*
* File: .inc
* Type: Module
* Description:
*
* Copyright (C) 2009-2010 <Author>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
/**
* Template instructions:
*
* All module-specific text has been replaced with text enclosed in <>
* This is to make preparing this file to become the module you need easier.
* Simply search-and-replace (usually CTRL+H) each of the tags below and replace it with the module specifics.
*
* Tags:
* <Project Name> The name of the project. (PROJECT_FULLNAME)
* <Author> The author(s) of the project. (PROJECT_AUTHOR)
* <FuncPrefix> The prefix of your module's functions. Usually the module's full name with no whitespaces.
* <ModuleVarName> Usually the same as <FuncPrefix>. Names the global variable that stores this module's identifier.
*/
/**
* This module's identifier.
*/
new Module:g_module<ModuleVarName>;
/**
* Register this module.
*/
<FuncPrefix>_Register()
{
// Define all the module's data as layed out by enum ModuleData in project.inc.
new moduledata[ModuleData];
moduledata[ModuleData_Disabled] = ;
moduledata[ModuleData_Hidden] = ;
strcopy(moduledata[ModuleData_FullName], CM_DATA_FULLNAME, "");
strcopy(moduledata[ModuleData_ShortName], CM_DATA_SHORTNAME, "");
strcopy(moduledata[ModuleData_Description], CM_DATA_DESCRIPTION, "");
// Send this array of data to the module manager.
g_module<ModuleVarName> = ModuleMgr_Register(moduledata);
// Register all the events needed for this module.
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnAllPluginsLoaded, "<FuncPrefix>_OnAllPluginsLoaded");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnPluginEnd, "<FuncPrefix>_OnPluginEnd");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnMapStart, "<FuncPrefix>_OnMapStart");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnMapEnd, "<FuncPrefix>_OnMapEnd");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnAutoConfigsBuffered, "<FuncPrefix>_OnAutoConfigsBuffered");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnConfigsExecuted, "<FuncPrefix>_OnConfigsExecuted");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnClientPutInServer, "<FuncPrefix>_OnClientPutInServer");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_OnClientDisconnect, "<FuncPrefix>_OnClientDisconnect");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_RoundStart, "<FuncPrefix>_RoundStart");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_RoundFreezeEnd, "<FuncPrefix>_RoundFreezeEnd");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_RoundEnd, "<FuncPrefix>_RoundEnd");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_PlayerTeam, "<FuncPrefix>_PlayerTeam");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_PlayerSpawn, "<FuncPrefix>_PlayerSpawn");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_PlayerHurt, "<FuncPrefix>_PlayerHurt");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_PlayerDeath, "<FuncPrefix>_PlayerDeath");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_PlayerJump, "<FuncPrefix>_PlayerJump");
//EventMgr_RegisterEvent(g_module<ModuleVarName>, Event_WeaponFire, "<FuncPrefix>_WeaponFire");
// Register config file(s) that this module will use.
// ConfigMgr_Register(g_module<ModuleVarName>, "<FuncPrefix>_OnConfigReload", "configs/<projectshortname>/<config>.txt");
}
/**
* Plugin is loading.
*/
<FuncPrefix>_OnPluginStart()
{
// Register the module.
<FuncPrefix>_Register();
}
/**
* All plugins have loaded.
*/
public <FuncPrefix>_OnAllPluginsLoaded()
{
}
/**
* Plugin is ending.
*/
public <FuncPrefix>_OnPluginEnd()
{
}
/**
* The map has started.
*/
public <FuncPrefix>_OnMapStart()
{
}
/**
* The map has ended.
*/
public <FuncPrefix>_OnMapEnd()
{
}
/**
* This is called before OnConfigsExecuted but any time after OnMapStart.
* Per-map settings should be set here.
*/
public <FuncPrefix>_OnAutoConfigsBuffered()
{
}
/**
* All convars are set, cvar-dependent code should use this.
*/
public <FuncPrefix>_OnConfigsExecuted()
{
}
/**
* Called when a registered config file (by this module) is manually.
*/
public <FuncPrefix>_OnConfigReload(configindex)
{
}
/**
* Client has joined the server.
*
* @param client The client index.
*/
public <FuncPrefix>_OnClientPutInServer(client)
{
}
/**
* Client is disconnecting from the server.
*
* @param client The client index.
*/
public <FuncPrefix>_OnClientDisconnect(client)
{
}
/**
* Round has started.
*/
public <FuncPrefix>_RoundStart()
{
}
/**
* Pre-round has freezetime has finished.
*/
public <FuncPrefix>_RoundFreezeEnd()
{
}
/**
* Round has ended.
*/
public <FuncPrefix>_RoundEnd()
{
}
/**
* Client has joined a team.
*
* @param client The client index.
* @param team The client's new team.
* @param oldteam The team the client is switching from.
* @param disconnect True if the client is disconnecting, false if switching to a team.
*/
public <FuncPrefix>_PlayerTeam(client, team, oldteam, bool:disconnect)
{
}
/**
* Client has spawned.
*
* @param client The client index.
*
*/
public <FuncPrefix>_PlayerSpawn(client)
{
}
/**
* Client has been damaged.
*
* @param victim The index of the hurt client.
* @param attacker The index of the attacking client.
* @param health How much health the client has after the damage.
* @param armor How much armor the client has after the damage.
* @param weapon The weapon classname used to hurt the victim. (No weapon_ prefix)
* @param dmg_health The amount of health the victim lost.
* @param dmg_armor The amount of armor the victim lost.
* @param hitgroup The hitgroup index of the victim that was damaged.
*/
public <FuncPrefix>_PlayerHurt(victim, attacker, health, armor, const String:weapon[], dmg_health, dmg_armor, hitgroup)
{
}
/**
* Client has been killed.
*
* @param victim The index of the killed client.
* @param attacker The killer of the victim.
* @param weapon The weapon classname used to kill the victim. (No weapon_ prefix)
* @param headshot True if the death was by headshot, false if not.
*/
public <FuncPrefix>_PlayerDeath(victim, attacker, const String:weapon[], bool:headshot)
{
}
/**
* Client has jumped.
*
* @param client The client index.
*/
public <FuncPrefix>_PlayerJump(client)
{
}
/**
* Client has fired a weapon.
*
* @param client The client index.
* @param weapon The weapon classname fired. (No weapon_ prefix)
*/
public <FuncPrefix>_WeaponFire(client, const String:weapon[])
{
}
__________________
Last edited by Greyscale; 02-11-2010 at 01:46.
|
|