-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "WaypointFileManager.h" | ||
#include "Util.h" | ||
#include <metamod/ISmmAPI.h> | ||
#include <metamod/sourcehook.h> | ||
#include <windows.h> | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
#define FILE_DIR "tf/addons/pongbot/waypoints/" | ||
#define FILE_EXTENSION "pbw" | ||
|
||
using namespace std; | ||
|
||
extern IServerGameDLL *Server; | ||
extern SourceHook::ISourceHook *g_SHPtr; | ||
extern PluginId g_PLID; | ||
|
||
WaypointFileManager *_WaypointFileManager; | ||
|
||
char _CurrentMapName[32]; | ||
|
||
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, | ||
char const *, char const *, bool, bool); | ||
|
||
void WaypointFileManager::Init() { | ||
Assert(!_WaypointFileManager); | ||
_WaypointFileManager = new WaypointFileManager(); | ||
SH_ADD_HOOK(IServerGameDLL, LevelInit, Server, | ||
SH_MEMBER(_WaypointFileManager, &WaypointFileManager::_OnLevelInit), true); | ||
} | ||
|
||
void WaypointFileManager::Destroy() { | ||
Assert(_WaypointFileManager); | ||
SH_REMOVE_HOOK(IServerGameDLL, LevelInit, Server, | ||
SH_MEMBER(_WaypointFileManager, &WaypointFileManager::_OnLevelInit), true); | ||
delete _WaypointFileManager; | ||
} | ||
|
||
WaypointFileManager::WaypointFileManager() {} | ||
|
||
void WaypointFileManager::Read() { | ||
if (_CheckFile()) | ||
Util::Log("Waypoint loaded! (STUB!)"); | ||
} | ||
|
||
void WaypointFileManager::Write() { | ||
if (_CheckFile()) | ||
Util::Log("Waypoint saved! (STUB!)"); | ||
} | ||
|
||
bool WaypointFileManager::_CheckFile() { | ||
// Check for dir first | ||
struct stat info; | ||
stat(FILE_DIR, &info); | ||
if (~info.st_mode & S_IFDIR) { | ||
// Create dir | ||
bool created = CreateDirectory(FILE_DIR, nullptr); | ||
if (!created) { | ||
Util::Log("Error while creating directory!"); | ||
return false; | ||
} | ||
} | ||
|
||
// Now check for file | ||
char fileName[64]; | ||
sprintf_s(fileName, "%s%s.%s", FILE_DIR, _CurrentMapName, FILE_EXTENSION); | ||
ofstream file(fileName); | ||
file.close(); | ||
|
||
return true; | ||
} | ||
|
||
bool WaypointFileManager::_OnLevelInit(const char *pMapName, char const *pMapEntities, | ||
char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) { | ||
strcpy(_CurrentMapName, pMapName); | ||
return true; | ||
} | ||
|
||
CON_COMMAND(pongbot_savewaypoint, "Saves current waypoint to file") { | ||
_WaypointFileManager->Write(); | ||
} | ||
|
||
CON_COMMAND(pongbot_loadwaypoint, "Loads waypoint from file") { | ||
_WaypointFileManager->Read(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include "ConVarBase.h" | ||
|
||
class WaypointFileManager : public ConVarBase { | ||
public: | ||
static void Init(); | ||
static void Destroy(); | ||
private: | ||
WaypointFileManager(); | ||
public: | ||
void Read(); | ||
void Write(); | ||
private: | ||
char _CurrentMapName[32]; | ||
private: | ||
bool _CheckFile(); | ||
// Hooks | ||
private: | ||
bool _OnLevelInit(const char *pMapName, char const *pMapEntities, char const *pOldLevel, | ||
char const *pLandmarkName, bool loadGame, bool background); | ||
}; | ||
|
||
extern WaypointFileManager *_WaypointFileManager; |