- added timeleft functionality to cstrike extension

- finalized timeleft api once again (i hope)
- added weapon slot definitions to cstrike.inc
- bumped timer API

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401465
This commit is contained in:
David Anderson
2007-09-23 19:33:19 +00:00
parent 980a8fba7b
commit 0f45f8b5ee
16 changed files with 400 additions and 49 deletions
+30 -1
View File
@@ -31,15 +31,20 @@
#include "extension.h"
#include "RegNatives.h"
#include "timeleft.h"
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
CStrike g_CStrike; /**< Global singleton for extension's main interface */
IBinTools *g_pBinTools = NULL;
IGameConfig *g_pGameConf = NULL;
IGameEventManager2 *gameevents = NULL;
bool hooked_everything = false;
SMEXT_LINK(&g_CStrike);
@@ -49,8 +54,13 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
sharesys->AddDependency(myself, "bintools.ext", true, true);
if (!gameconfs->LoadGameConfigFile("sm-cstrike.games", &g_pGameConf, error, maxlength))
char conf_error[255];
if (!gameconfs->LoadGameConfigFile("sm-cstrike.games", &g_pGameConf, conf_error, sizeof(conf_error)))
{
if (error)
{
snprintf(error, maxlength, "Could not read sm-cstrike.games.txt: %s", conf_error);
}
return false;
}
@@ -59,14 +69,33 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late)
return true;
}
bool CStrike::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
return true;
}
void CStrike::SDK_OnUnload()
{
if (hooked_everything)
{
gameevents->RemoveListener(&g_TimeLeftEvents);
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, &g_TimeLeftEvents, &TimeLeftEvents::LevelInit, true);
hooked_everything = false;
}
g_RegNatives.UnregisterAll();
gameconfs->CloseGameConfigFile(g_pGameConf);
}
void CStrike::SDK_OnAllLoaded()
{
gameevents->AddListener(&g_TimeLeftEvents, "round_start", true);
gameevents->AddListener(&g_TimeLeftEvents, "round_end", true);
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, &g_TimeLeftEvents, &TimeLeftEvents::LevelInit, true);
hooked_everything = true;
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
}
+1 -1
View File
@@ -94,7 +94,7 @@ public:
* @param late Whether or not Metamod considers this a late load.
* @return True to succeed, false to fail.
*/
//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
/**
* @brief Called when Metamod is detaching, after the extension version is called.
+14 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="cstrike"
ProjectGUID="{B3E797CF-4E77-4C9D-B8A8-7589B6902206}"
RootNamespace="cstrike"
@@ -40,7 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..;..\sdk;..\..\..\public;..\..\..\public\sourcepawn"
AdditionalIncludeDirectories="..;..\sdk;..\..\..\public;..\..\..\public\sourcepawn;..\..\..\public\extensions"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CSTRIKE_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -196,6 +196,10 @@
RelativePath="..\RegNatives.cpp"
>
</File>
<File
RelativePath="..\timeleft.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@@ -210,12 +214,20 @@
RelativePath="..\RegNatives.h"
>
</File>
<File
RelativePath="..\timeleft.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath="..\version.rc"
>
</File>
</Filter>
<Filter
Name="SourceMod SDK"
+4 -2
View File
@@ -37,10 +37,12 @@
* @brief Contains macros for configuring basic extension information.
*/
#include "svn_version.h"
/* Basic information exposed publicly */
#define SMEXT_CONF_NAME "CS:S Tools"
#define SMEXT_CONF_DESCRIPTION "CS:S extended functionality"
#define SMEXT_CONF_VERSION "99.0.0.0" //:TODO:
#define SMEXT_CONF_VERSION SVN_FULL_VERSION
#define SMEXT_CONF_AUTHOR "AlliedModders"
#define SMEXT_CONF_URL "http://www.sourcemod.net/"
#define SMEXT_CONF_LOGTAG "CSTRIKE"
@@ -66,7 +68,7 @@
#define SMEXT_ENABLE_GAMECONF
//#define SMEXT_ENABLE_MEMUTILS
//#define SMEXT_ENABLE_GAMEHELPERS
//#define SMEXT_ENABLE_TIMERSYS
#define SMEXT_ENABLE_TIMERSYS
//#define SMEXT_ENABLE_THREADER
//#define SMEXT_ENABLE_LIBSYS
+42
View File
@@ -0,0 +1,42 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod SDKTools Extension
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id: svn_version.h 1336 2007-08-15 06:19:30Z damagedsoul $
*/
/**
* Autogenerated by build scripts
*/
#ifndef _INCLUDE_SDKTOOLS_VERSION_H_
#define _INCLUDE_SDKTOOLS_VERSION_H_
#define SVN_FULL_VERSION "1.0.0.1336"
#define SVN_FILE_VERSION 1,0,0,1336
#endif //_INCLUDE_SDKTOOLS_VERSION_H_
+42
View File
@@ -0,0 +1,42 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod SDKTools Extension
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
/**
* Autogenerated by build scripts
*/
#ifndef _INCLUDE_SDKTOOLS_VERSION_H_
#define _INCLUDE_SDKTOOLS_VERSION_H_
#define SVN_FULL_VERSION "$PMAJOR$.$PMINOR$.$PREVISION$.$LOCAL_BUILD$"
#define SVN_FILE_VERSION $PMAJOR$,$PMINOR$,$PREVISION$,$LOCAL_BUILD$
#endif //_INCLUDE_SDKTOOLS_VERSION_H_
+43
View File
@@ -0,0 +1,43 @@
#include "extension.h"
#include "timeleft.h"
TimeLeftEvents g_TimeLeftEvents;
bool get_new_timeleft_offset = false;
bool round_end_found = false;
bool TimeLeftEvents::LevelInit(char const *pMapName,
char const *pMapEntities,
char const *pOldLevel,
char const *pLandmarkName,
bool loadGame,
bool background)
{
round_end_found = true;
get_new_timeleft_offset = false;
return true;
}
void TimeLeftEvents::FireGameEvent(IGameEvent *event)
{
const char *name = event->GetName();
if (strcmp(name, "round_start") == 0)
{
if (get_new_timeleft_offset || !round_end_found)
{
get_new_timeleft_offset = false;
timersys->NotifyOfGameStart();
timersys->MapTimeLeftChanged();
}
round_end_found = false;
}
else if (strcmp(name, "round_end") == 0)
{
if (event->GetInt("reason") == 16)
{
get_new_timeleft_offset = true;
}
round_end_found = true;
}
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef _INCLUDE_SOURCEMOD_CSTRIKE_EVENTS_H_
#define _INCLUDE_SOURCEMOD_CSTRIKE_EVENTS_H_
#include <edict.h>
#include <igameevents.h>
class TimeLeftEvents : public IGameEventListener2
{
public:
bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
virtual void FireGameEvent(IGameEvent *event);
};
extern TimeLeftEvents g_TimeLeftEvents;
#endif //_INCLUDE_SOURCEMOD_CSTRIKE_EVENTS_H_
+104
View File
@@ -0,0 +1,104 @@
// Microsoft Visual C++ generated resource script.
//
//#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
#include "svn_version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION SVN_FILE_VERSION
PRODUCTVERSION SVN_FILE_VERSION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "Comments", "SourceMod CS:S Extension"
VALUE "FileDescription", "SourceMod CS:S Extension"
VALUE "FileVersion", SVN_FULL_VERSION
VALUE "InternalName", "SourceMod CS:S Extension"
VALUE "LegalCopyright", "Copyright (c) 2004-2007, AlliedModders LLC"
VALUE "OriginalFilename", "game.cstrike.ext.dll"
VALUE "ProductName", "SourceMod CS:S Extension"
VALUE "ProductVersion", SVN_FULL_VERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED