Merge branch 'newui' of https://github.com/nullworks/cathook into newui

This commit is contained in:
LightCat 2018-07-30 20:08:46 +02:00
commit 365b2111ee
10 changed files with 187 additions and 10 deletions

View File

@ -128,6 +128,7 @@ public:
offset_t m_Collision; offset_t m_Collision;
offset_t res_iTeam; offset_t res_iTeam;
offset_t res_iScore; offset_t res_iScore;
offset_t res_bAlive;
offset_t m_nChargeResistType; offset_t m_nChargeResistType;
offset_t m_flChargeLevel; offset_t m_flChargeLevel;

View File

@ -19,6 +19,10 @@ public:
int GetTeam(int idx); int GetTeam(int idx);
int GetScore(int idx); int GetScore(int idx);
int getClass(int idx);
int getTeam(int idx);
bool isAlive(int idx);
int entity; int entity;
}; };

View File

@ -13,4 +13,6 @@ void init();
void draw(); void draw();
bool handleSdlEvent(SDL_Event *event); bool handleSdlEvent(SDL_Event *event);
void onLevelLoad();
} }

View File

@ -39,7 +39,9 @@ public:
*/ */
void updatePlayerName(int id, const char *name); void updatePlayerName(int id, const char *name);
void updatePlayerTeamClass(int id, int team, int classId); void updatePlayerTeam(int id, int team);
void updatePlayerClass(int id, int classId);
void updatePlayerLifeState(int id, bool dead); void updatePlayerLifeState(int id, bool dead);

View File

@ -43,6 +43,8 @@ void NetVars::Init()
{ {
res_iTeam = res_iTeam =
gNetvars.get_offset("DT_TFPlayerResource", "baseclass", "m_iTeam"); gNetvars.get_offset("DT_TFPlayerResource", "baseclass", "m_iTeam");
res_bAlive =
gNetvars.get_offset("DT_TFPlayerResource", "baseclass", "m_bAlive");
this->res_iMaxBuffedHealth = this->res_iMaxBuffedHealth =
gNetvars.get_offset("DT_TFPlayerResource", "m_iMaxBuffedHealth"); gNetvars.get_offset("DT_TFPlayerResource", "m_iMaxBuffedHealth");
m_angEyeAngles = gNetvars.get_offset("DT_TFPlayer", "tfnonlocaldata", m_angEyeAngles = gNetvars.get_offset("DT_TFPlayer", "tfnonlocaldata",

View File

@ -5,6 +5,7 @@
#include <hacks/hacklist.hpp> #include <hacks/hacklist.hpp>
#include <settings/Bool.hpp> #include <settings/Bool.hpp>
#include <menu/GuiInterface.hpp>
#include "HookedMethods.hpp" #include "HookedMethods.hpp"
#include "MiscTemporary.hpp" #include "MiscTemporary.hpp"
#if !LAGBOT_MODE #if !LAGBOT_MODE
@ -61,6 +62,10 @@ DEFINE_HOOKED_METHOD(LevelInit, void, void *this_, const char *name)
playerlist::Save(); playerlist::Save();
#endif #endif
#if ENABLE_VISUALS #if ENABLE_VISUALS
#if ENABLE_GUI
gui::onLevelLoad();
#endif
typedef bool (*LoadNamedSkys_Fn)(const char *); typedef bool (*LoadNamedSkys_Fn)(const char *);
uintptr_t addr = gSignatures.GetEngineSignature( uintptr_t addr = gSignatures.GetEngineSignature(
"55 89 E5 57 31 FF 56 8D B5 ? ? ? ? 53 81 EC 6C 01 00 00"); "55 89 E5 57 31 FF 56 8D B5 ? ? ? ? 53 81 EC 6C 01 00 00");

View File

@ -5,6 +5,8 @@
* Author: nullifiedcat * Author: nullifiedcat
*/ */
#include <playerresource.h>
#include "common.hpp" #include "common.hpp"
void TFPlayerResource::Update() void TFPlayerResource::Update()
@ -91,4 +93,34 @@ int TFPlayerResource::GetClass(CachedEntity *player)
return *(int *) ((unsigned) ent + netvar.res_iPlayerClass + 4 * idx); return *(int *) ((unsigned) ent + netvar.res_iPlayerClass + 4 * idx);
} }
TFPlayerResource *g_pPlayerResource = 0; bool TFPlayerResource::isAlive(int idx)
{
IClientEntity *ent = g_IEntityList->GetClientEntity(entity);
if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE)
return 0;
if (idx >= 64 || idx < 0)
return false;
return *(bool *) ((unsigned) ent + netvar.res_bAlive + idx);
}
int TFPlayerResource::getClass(int idx)
{
IClientEntity *ent = g_IEntityList->GetClientEntity(entity);
if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE)
return 0;
if (idx >= 64 || idx < 0)
return 0;
return *(int *) ((unsigned) ent + netvar.res_iPlayerClass + 4 * idx);
}
int TFPlayerResource::getTeam(int idx)
{
IClientEntity *ent = g_IEntityList->GetClientEntity(entity);
if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE)
return 0;
if (idx >= 64 || idx < 0)
return 0;
return *(int *) ((unsigned) ent + netvar.res_iTeam + 4 * idx);
}
TFPlayerResource *g_pPlayerResource{ nullptr };

View File

@ -178,7 +178,6 @@ void draw::InitGL()
void draw::BeginGL() void draw::BeginGL()
{ {
glColor3f(1, 1, 1); glColor3f(1, 1, 1);
glDisable(GL_FRAMEBUFFER_SRGB);
#if EXTERNAL_DRAWING #if EXTERNAL_DRAWING
xoverlay_draw_begin(); xoverlay_draw_begin();
{ {
@ -190,6 +189,7 @@ void draw::BeginGL()
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
PROF_SECTION(draw_begin__glez_begin); PROF_SECTION(draw_begin__glez_begin);
glez::begin(); glez::begin();
glDisable(GL_FRAMEBUFFER_SRGB);
PROF_SECTION(DRAWEX_draw_begin); PROF_SECTION(DRAWEX_draw_begin);
} }
} }
@ -199,6 +199,7 @@ void draw::EndGL()
PROF_SECTION(DRAWEX_draw_end); PROF_SECTION(DRAWEX_draw_end);
{ {
PROF_SECTION(draw_end__glez_end); PROF_SECTION(draw_end__glez_end);
glEnable(GL_FRAMEBUFFER_SRGB);
glez::end(); glez::end();
} }
#if EXTERNAL_DRAWING #if EXTERNAL_DRAWING

View File

@ -6,11 +6,104 @@
#include <menu/menu/Menu.hpp> #include <menu/menu/Menu.hpp>
#include <drawing.hpp> #include <drawing.hpp>
#include <menu/menu/special/SettingsManagerList.hpp> #include <menu/menu/special/SettingsManagerList.hpp>
#include <menu/menu/special/PlayerListController.hpp>
#include <hack.hpp>
static settings::Button open_gui_button{ "visual.open-gui-button", "Insert" }; static settings::Button open_gui_button{ "visual.open-gui-button", "Insert" };
static bool init_done{ false }; static bool init_done{ false };
static std::unique_ptr<zerokernel::special::PlayerListController> controller{ nullptr };
static zerokernel::special::PlayerListData createPlayerListData(int userid)
{
zerokernel::special::PlayerListData data{};
auto idx = g_IEngine->GetPlayerForUserID(userid);
player_info_s info{};
g_IEngine->GetPlayerInfo(idx, &info);
data.classId = g_pPlayerResource->getClass(idx);
data.teamId = g_pPlayerResource->getTeam(idx) - 1;
data.dead = !g_pPlayerResource->isAlive(idx);
data.steam = info.friendsID;
logging::Info("Player name: %s", info.name);
snprintf(data.name, 31, "%s", info.name);
return data;
}
class PlayerListEventListener: public IGameEventListener
{
public:
void FireGameEvent(KeyValues *event) override
{
if (!controller)
return;
auto userid = event->GetInt("userid");
if (!userid)
return;
std::string name = event->GetName();
if (name == "player_connect_client")
{
logging::Info("addPlayer %d", userid);
controller->addPlayer(userid, createPlayerListData(userid));
}
else if (name == "player_disconnect")
{
logging::Info("removePlayer %d", userid);
controller->removePlayer(userid);
}
else if (name == "player_team")
{
logging::Info("updatePlayerTeam %d", userid);
controller->updatePlayerTeam(userid, event->GetInt("team") - 1);
}
else if (name == "player_changeclass")
{
logging::Info("updatePlayerClass %d", userid);
controller->updatePlayerClass(userid, event->GetInt("class"));
}
else if (name == "player_changename")
{
logging::Info("updatePlayerName %d", userid);
controller->updatePlayerName(userid, event->GetString("newname"));
}
else if (name == "player_death")
{
logging::Info("updatePlayerLifeState %d", userid);
controller->updatePlayerLifeState(userid, true);
}
else if (name == "player_spawn")
{
logging::Info("updatePlayerLifeState %d", userid);
controller->updatePlayerLifeState(userid, false);
}
}
};
static PlayerListEventListener listener{};
static void initPlayerlist()
{
auto pl = dynamic_cast<zerokernel::Table *>(zerokernel::Menu::instance->wm->getElementById("special-player-list"));
if (pl)
{
controller = std::make_unique<zerokernel::special::PlayerListController>(*pl);
controller->setKickButtonCallback([](int uid) {
hack::command_stack().push("callvote kick " + uid);
});
controller->setOpenSteamCallback([](unsigned steam) {
CSteamID id{};
id.SetFromUint64((0b1000100000000000000000001 << 32) | steam);
g_ISteamFriends->ActivateGameOverlayToUser("steamid", id);
});
}
else
{
logging::Info("PlayerList element not found\n");
}
}
static void load() static void load()
{ {
zerokernel::Menu::instance->loadFromFile(DATA_PATH "/menu", "menu.xml"); zerokernel::Menu::instance->loadFromFile(DATA_PATH "/menu", "menu.xml");
@ -22,7 +115,7 @@ static void load()
list.construct(); list.construct();
printf("SV found\n"); printf("SV found\n");
} }
// FIXME add playerlist initPlayerlist();
zerokernel::Menu::instance->update(); zerokernel::Menu::instance->update();
zerokernel::Menu::instance->setInGame(true); zerokernel::Menu::instance->setInGame(true);
@ -32,9 +125,12 @@ static CatCommand reload("gui_reload", "Reload", []() {
load(); load();
}); });
void gui::init() void gui::init()
{ {
zerokernel::Menu::init(draw::width, draw::height); zerokernel::Menu::init(draw::width, draw::height);
g_IGameEventManager->AddListener(&listener, false);
load(); load();
@ -54,7 +150,6 @@ bool gui::handleSdlEvent(SDL_Event *event)
{ {
if (event->type == SDL_KEYDOWN) if (event->type == SDL_KEYDOWN)
{ {
logging::Info("%d %d\n", event->key.keysym.scancode, (*open_gui_button).scan);
if (event->key.keysym.scancode == (*open_gui_button).scan) if (event->key.keysym.scancode == (*open_gui_button).scan)
{ {
logging::Info("GUI open button pressed"); logging::Info("GUI open button pressed");
@ -66,3 +161,19 @@ bool gui::handleSdlEvent(SDL_Event *event)
return zerokernel::Menu::instance->handleSdlEvent(event) && !zerokernel::Menu::instance->isInGame(); return zerokernel::Menu::instance->handleSdlEvent(event) && !zerokernel::Menu::instance->isInGame();
} }
void gui::onLevelLoad()
{
if (controller)
{
controller->removeAll();
for (auto i = 1; i < 32; ++i)
{
player_info_s info{};
if (g_IEngine->GetPlayerInfo(i, &info))
{
controller->addPlayer(info.userID, createPlayerListData(info.userID));
}
}
}
}

View File

@ -6,6 +6,8 @@
#include <settings/Registered.hpp> #include <settings/Registered.hpp>
#include <menu/object/container/TData.hpp> #include <menu/object/container/TData.hpp>
#include <menu/Message.hpp> #include <menu/Message.hpp>
#include <menu/menu/special/PlayerListController.hpp>
/* /*
Created on 26.07.18. Created on 26.07.18.
@ -120,11 +122,11 @@ void zerokernel::special::PlayerListController::updatePlayerLifeState(int id,
}); });
} }
void zerokernel::special::PlayerListController::updatePlayerTeamClass(int id,
int team, void
int classId) zerokernel::special::PlayerListController::updatePlayerTeam(int id, int team)
{ {
table.iterateObjects([this, id, team, classId](BaseMenuObject *a) { table.iterateObjects([this, id, team](BaseMenuObject *a) {
auto row = dynamic_cast<TRow *>(a); auto row = dynamic_cast<TRow *>(a);
// Shouldn't happen // Shouldn't happen
if (row == nullptr) if (row == nullptr)
@ -132,6 +134,21 @@ void zerokernel::special::PlayerListController::updatePlayerTeamClass(int id,
if ((int)row->kv["player_id"] == id) if ((int)row->kv["player_id"] == id)
{ {
row->kv["player_team"] = team; row->kv["player_team"] = team;
updateRow(row);
}
});
}
void zerokernel::special::PlayerListController::updatePlayerClass(int id, int classId)
{
table.iterateObjects([this, id, classId](BaseMenuObject *a) {
auto row = dynamic_cast<TRow *>(a);
// Shouldn't happen
if (row == nullptr)
return;
if ((int)row->kv["player_id"] == id)
{
row->kv["player_class"] = classId; row->kv["player_class"] = classId;
updateRow(row); updateRow(row);
} }
@ -227,4 +244,4 @@ void zerokernel::special::PlayerListController::updateRow(zerokernel::TRow *row)
{ {
el->set(class_names[classId]); el->set(class_names[classId]);
} }
} }