From 7ed67debfc4d19b33912a01d4abd1170a704aa00 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 5 Sep 2016 19:55:47 +0200 Subject: [PATCH] Start working on issue --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/PlayerName.cpp | 33 +++++++++++++++++++++++++++ src/Components/Modules/PlayerName.hpp | 18 +++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/Components/Modules/PlayerName.cpp create mode 100644 src/Components/Modules/PlayerName.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index f1a8335c..90e40d33 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -56,6 +56,7 @@ namespace Components Loader::Register(new BitMessage()); #endif Loader::Register(new FileSystem()); + Loader::Register(new PlayerName()); Loader::Register(new QuickPatch()); Loader::Register(new ServerInfo()); Loader::Register(new ServerList()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index e5d1080b..00883999 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -69,6 +69,7 @@ namespace Components #include "Modules\Singleton.hpp" #include "Modules\BitMessage.hpp" #include "Modules\FileSystem.hpp" +#include "Modules\PlayerName.hpp" #include "Modules\QuickPatch.hpp" #include "Modules\ServerInfo.hpp" #include "Modules\ServerList.hpp" diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp new file mode 100644 index 00000000..90257b04 --- /dev/null +++ b/src/Components/Modules/PlayerName.cpp @@ -0,0 +1,33 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::string PlayerName::PlayerNames[18]; + + int PlayerName::GetClientName(int /*localClientNum*/, int index, char *buf, int size) + { + if (index < 0 || index >= 18) return 0; + return strncpy_s(buf, size, PlayerName::PlayerNames[index].data(), PlayerName::PlayerNames[index].size()) == 0; + } + + PlayerName::PlayerName() + { + if (0) + { + for (int i = 0; i < ARRAY_SIZE(PlayerName::PlayerNames); ++i) + { + PlayerName::PlayerNames[i] = "mumu"; + } + + Utils::Hook(Game::CL_GetClientName, PlayerName::GetClientName, HOOK_JUMP).Install()->Quick(); + } + } + + PlayerName::~PlayerName() + { + for (int i = 0; i < ARRAY_SIZE(PlayerName::PlayerNames); ++i) + { + PlayerName::PlayerNames[i].clear(); + } + } +} diff --git a/src/Components/Modules/PlayerName.hpp b/src/Components/Modules/PlayerName.hpp new file mode 100644 index 00000000..d9442ab3 --- /dev/null +++ b/src/Components/Modules/PlayerName.hpp @@ -0,0 +1,18 @@ +namespace Components +{ + class PlayerName : public Component + { + public: + PlayerName(); + ~PlayerName(); + +#ifdef DEBUG + const char* GetName() { return "PlayerName"; }; +#endif + + private: + static std::string PlayerNames[18]; + + static int GetClientName(int localClientNum, int index, char *buf, int size); + }; +}