Skip to content

Commit

Permalink
update for vguiext 009
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr.Abc committed Feb 6, 2025
1 parent e7e719a commit afb16c7
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 72 deletions.
36 changes: 35 additions & 1 deletion VGUI2/BaseUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <VGUI\ILocalize.h>
#include <VGUI\ISurface.h>
#include <VGUI\IInput.h>
#include <Controls.h>

#include <GameUI/BasePanel.h>
#include "vguilocal.h"

#include <IBaseUI.h>
#include <IEngineSurface.h>
Expand Down Expand Up @@ -43,7 +45,6 @@ class CVGUI2Extension_BaseUICallbacks : public IVGUI2Extension_BaseUICallbacks
g_pKeyValuesSystem = (IKeyValuesSystem*)fnVGUI2CreateInterface(KEYVALUESSYSTEM_INTERFACE_VERSION, NULL);
}
staticSurface = (IEngineSurface*)factories[0](ENGINE_SURFACE_VERSION, NULL);
BasePanel_InstallHook();
BasePanelInit();
#ifdef __HAS_NETEASE_API
CreateNeteaseMusicDialogCmd();
Expand Down Expand Up @@ -106,6 +107,39 @@ void BaseUI_UninstallHooks(void){
VGUI2Extension()->UnregisterBaseUICallbacks(&s_BaseUICallbacks);
}

class CVGUI2Extension_GameUIBasePanelCallbacks : public IVGUI2Extension_GameUIBasePanelCallbacks
{
virtual int GetAltitude() const override
{
return 0;
}
virtual void CBasePanel_ctor(IGameUIBasePanelCtorCallbackContext* CallbackContext) override
{
BasePanelSetHandle(CallbackContext->GetBasePanel());
vgui::scheme()->LoadSchemeFromFile(VGUI2_ROOT_DIR "gameui/OptionsAdvanceDialogScheme.res", "OptionsAdvanceDialogScheme");
vgui::scheme()->LoadSchemeFromFile(VGUI2_ROOT_DIR "gameui/VoteMenuDialogScheme.res", "VoteMenuDialogScheme");
}
virtual void CBasePanel_ApplySchemeSettings(void*& pPanel, void*& pScheme, VGUI2Extension_CallbackContext* CallbackContext) override
{

}
};

static CVGUI2Extension_GameUIBasePanelCallbacks s_BasePanelCallbacks;
void GameUIBasePanel_InstallHooks()
{
CreateInterfaceFn fnCreateInterface = g_pMetaHookAPI->GetEngineFactory();
if (!fnCreateInterface)
{
SYS_ERROR("Failed to get engine factory.");
return;
}
VGUI2Extension()->RegisterGameUIBasePanelCallbacks(&s_BasePanelCallbacks);
}
void GameUIBasePanel_UninstallHooks(void) {
VGUI2Extension()->UnregisterGameUIBasePanelCallbacks(&s_BasePanelCallbacks);
}

IGameUIFuncs* GameUIFuncs() {
return gameuifuncs;
}
Expand Down
25 changes: 3 additions & 22 deletions VGUI2/GameUI/BasePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ static void SetBasePanelState(bool state) {
EngineClientCmd("mp3 loop media/gamestartup.mp3 ui");
}
}
void BasePanelSetHandle(void* ptr){
s_pBasePanel = reinterpret_cast<vgui::IClientPanel*>(ptr);
}
void BasePanelInit() {
gCVars.pDynamicBackground = CREATE_CVAR("hud_dynamic_background", "1", FCVAR_VALUE, [](cvar_t* cvar) {
SetBasePanelState(cvar->value > 0);
Expand Down Expand Up @@ -145,26 +148,4 @@ void SetAdvanceOptPanelVisible(bool state) {
else
s_hAdvanceOptPanel->Close();
}
}
static void* __fastcall CBasePanel_ctor(void* pthis, int dummy) {
s_pBasePanel = static_cast<vgui::IClientPanel*>(gHookFuncs.CBasePanel_ctor(pthis, dummy));
vgui::scheme()->LoadSchemeFromFile(VGUI2_ROOT_DIR "gameui/OptionsAdvanceDialogScheme.res", "OptionsAdvanceDialogScheme");
vgui::scheme()->LoadSchemeFromFile(VGUI2_ROOT_DIR "gameui/VoteMenuDialogScheme.res", "VoteMenuDialogScheme");
return s_pBasePanel;
}
void BasePanel_InstallHook(void){
HINTERFACEMODULE hGameUI = (HINTERFACEMODULE)GetModuleHandle("GameUI.dll");
if (!hGameUI) {
SYS_ERROR("Failed to locate GameUI.dll");
return;
}
auto GameUIBase = g_pMetaHookAPI->GetModuleBase(hGameUI);
auto GameUISize = g_pMetaHookAPI->GetModuleSize(hGameUI);

#define SC_CBASEPANEL_CTOR_SIG "\x55\x8B\xEC\x51\x56\x68\x2A\x2A\x2A\x2A\x8B\xF1\x6A\x00\x89\x75\xFC\xE8\x2A\x2A\x2A\x2A\xC7"
Fill_Sig(SC_CBASEPANEL_CTOR_SIG, GameUIBase, GameUISize, CBasePanel_ctor);
Install_InlineHook(CBasePanel_ctor);
//#define SC_CBASEPANEL_PAINTBACKGROUNDIMAGE_SIG "\x55\x8B\xEC\x83\xEC\x38\x53\x8D\x45\xCC\x8B\xD9\x50\x8D\x45\xC8\x89\x5D\xD0\x50\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x8D\x4D\xD4\x51"
//Fill_Sig(SC_CBASEPANEL_PAINTBACKGROUNDIMAGE_SIG, GameUIBase, GameUISize, CBasePanel_PaintBackground);
//Install_InlineHook(CBasePanel_PaintBackground);
}
12 changes: 6 additions & 6 deletions VGUI2/GameUI/BasePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ enum EBackgroundState{
BACKGROUND_EXITING,
};

void BasePanel_InstallHook();
void BackGroundOnCommand(void*& pPanel, const char*& cmd);
void BasePanelInit();
void BasePanelPostInit();
void BasePanelConnectServer();
void BasePanelDiconnectServer();
extern void BackGroundOnCommand(void*& pPanel, const char*& cmd);
extern void BasePanelInit();
extern void BasePanelSetHandle(void* ptr);
extern void BasePanelPostInit();
extern void BasePanelConnectServer();
extern void BasePanelDiconnectServer();

namespace vgui {
class IClientPanel;
Expand Down
8 changes: 2 additions & 6 deletions src/Header/Utility/httpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class CHttpClientItem : IUtilHTTPCallbacks {

CHttpClientItem* SetFeild(const char* key, const char* var);
HTTPCLIENT_STATE GetState() const;

UtilHTTPRequestId_t GetId();
bool Interrupt();
protected:
virtual void Destroy();
Expand All @@ -95,9 +93,7 @@ class CHttpClientItem : IUtilHTTPCallbacks {
std::vector<byte> m_aryReciveData = {};

bool m_bAsync = false;
UtilHTTPRequestId_t m_pId = 0;
//Only for sync
IUtilHTTPRequest* m_pSyncReq = nullptr;
IUtilHTTPRequest* m_pRequest = nullptr;

httpContext_s m_hContext;
HTTPCLIENT_STATE m_iStatue;
Expand All @@ -113,7 +109,7 @@ class CHttpClient {
void ClearAll();
CHttpClientItem* Fetch(const char* url, UtilHTTPMethod method);
CHttpClientItem* Fetch(httpContext_s* ctx);
bool Interrupt(UtilHTTPRequestId_t id);
bool Interrupt(CHttpClientItem* pDestory);
private:
std::vector<CHttpClientItem*> m_aryItems;
};
Expand Down
19 changes: 10 additions & 9 deletions src/Source/HUD/vgui/scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class CPlayerImage : public IImage
ClearFrame();
}
void Reset() {
if (m_bRequestId > 0)
GetHttpClient()->Interrupt(m_bRequestId);
m_bRequestId = 0;
if (m_pRequest.has_value() && m_pRequest.value() != nullptr)
GetHttpClient()->Interrupt(m_pRequest.value());
m_pRequest.reset();
m_bRequsetedAnimatedAvatars = false;
m_bDrawFriend = false;
ClearFrame();
Expand Down Expand Up @@ -126,9 +126,9 @@ class CPlayerImage : public IImage
if (arg->m_eResult == EResult::k_EResultOK && arg->m_bHasAnimatedAvatar) {
const char* url = SteamFriends()->GetProfileItemPropertyString(arg->m_steamID, k_ECommunityProfileItemType_AnimatedAvatar, k_ECommunityProfileItemProperty_ImageSmall);
if (url && V_strlen(url) > 0) {
if (m_bRequestId == 0) {
if (!m_pRequest.has_value()) {
ClearFrame();
m_bRequestId = GetHttpClient()->Fetch(url, UtilHTTPMethod::Get)->OnRespond([](IUtilHTTPResponse* rep, CPlayerImage* pthis) {
m_pRequest = GetHttpClient()->Fetch(url, UtilHTTPMethod::Get)->OnRespond([](IUtilHTTPResponse* rep, CPlayerImage* pthis) {
using gif = struct {
byte* bgra;
size_t w;
Expand Down Expand Up @@ -188,9 +188,9 @@ class CPlayerImage : public IImage
}
gifdata.reset();
}, pthis)->Start();
pthis->m_bRequestId = -1;
}, this)->Create(true)->Start()->GetId();
m_bIsAnimate = true;
pthis->m_pRequest = nullptr;
}, this)->Create(true)->Start();
m_bIsAnimate = true;
}
m_bRequsetedAnimatedAvatars = true;
}
Expand Down Expand Up @@ -324,8 +324,9 @@ class CPlayerImage : public IImage
bool m_bDrawFriend;

bool m_bIsAnimate = false;
int m_bRequestId = 0;
bool m_bRequsetedAnimatedAvatars = false;
std::optional<CHttpClientItem*> m_pRequest = nullptr;

std::vector<IImage_HL25*> m_aryAnimatedAvatars;
size_t m_iCurrentImage;
float m_flAnimateTime;
Expand Down
45 changes: 18 additions & 27 deletions src/Source/Utility/httpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ CHttpClientItem* CHttpClient::Fetch(httpContext_s* ctx){
m_aryItems.push_back(item);
return item;
}
bool CHttpClient::Interrupt(UtilHTTPRequestId_t id){
bool CHttpClient::Interrupt(CHttpClientItem* pDestory){
for (auto iter = m_aryItems.begin(); iter != m_aryItems.end();) {
auto item = *iter;
if (item->GetId() == id) {
if (item == pDestory) {
bool state = item->Interrupt();
if (state) {
delete item;
Expand All @@ -96,7 +96,7 @@ bool CHttpClient::Interrupt(UtilHTTPRequestId_t id){
else
iter++;
}
return g_pUtilHTTPClient->DestroyRequestById(id);
return false;
}

CHttpClientItem::CHttpClientItem(httpContext_s* ctx) : IUtilHTTPCallbacks(){
Expand All @@ -107,33 +107,27 @@ CHttpClientItem::CHttpClientItem(httpContext_s* ctx) : IUtilHTTPCallbacks(){
}
CHttpClientItem* CHttpClientItem::Create(bool async){
m_iStatue = HTTPCLIENT_STATE::PENDING;
if (async) {
auto req = g_pUtilHTTPClient->CreateAsyncRequest(m_hContext.url.c_str(), m_hContext.method, this);
m_pId = req->GetRequestId();
if (m_pCookieJar)
req->SetField("Set-Cookie", m_pCookieJar->Get().c_str());
}
else {
m_pSyncReq = g_pUtilHTTPClient->CreateSyncRequest(m_hContext.url.c_str(), m_hContext.method, this);
if (m_pCookieJar)
m_pSyncReq->SetField("Set-Cookie", m_pCookieJar->Get().c_str());
}
if (async)
m_pRequest = g_pUtilHTTPClient->CreateAsyncRequest(m_hContext.url.c_str(), m_hContext.method, this);
else
m_pRequest = g_pUtilHTTPClient->CreateSyncRequest(m_hContext.url.c_str(), m_hContext.method, this);
if (m_pCookieJar)
m_pRequest->SetField("Set-Cookie", m_pCookieJar->Get().c_str());
m_bAsync = async;
return this;
}
CHttpClientItem* CHttpClientItem::Start(){
if (m_bAsync) {
auto req = g_pUtilHTTPClient->GetRequestById(m_pId);
if (req)
req->Send();
if (m_pRequest)
m_pRequest->Send();
}
return this;
}
IUtilHTTPResponse* CHttpClientItem::StartSync(){
if (!m_bAsync) {
m_pSyncReq->Send();
m_pSyncReq->WaitForComplete();
auto reb = m_pSyncReq->GetResponse();
m_pRequest->Send();
m_pRequest->WaitForComplete();
auto reb = m_pRequest->GetResponse();
if (m_pCookieJar) {
char cookiebuf[MAX_COOKIE_LENGTH];
reb->GetHeader("Set-Cookie", cookiebuf, MAX_COOKIE_LENGTH);
Expand All @@ -144,20 +138,17 @@ IUtilHTTPResponse* CHttpClientItem::StartSync(){
return nullptr;
}
CHttpClientItem* CHttpClientItem::SetFeild(const char* key, const char* var){
auto req = m_bAsync ? g_pUtilHTTPClient->GetRequestById(m_pId) : m_pSyncReq;
if (req)
req->SetField(key, var);
if (m_pRequest)
m_pRequest->SetField(key, var);
return this;
}

HTTPCLIENT_STATE CHttpClientItem::GetState() const{
return m_iStatue;
}
UtilHTTPRequestId_t CHttpClientItem::GetId(){
return m_pId;
}
bool CHttpClientItem::Interrupt(){
return g_pUtilHTTPClient->DestroyRequestById(m_pId);
m_pRequest->Destroy();
return true;
}
void CHttpClientItem::Destroy() {
m_iStatue = HTTPCLIENT_STATE::DESTORYED;
Expand Down
2 changes: 2 additions & 0 deletions src/Source/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void IPluginsV4::LoadEngine(cl_enginefunc_t *pEngfuncs){
ClientVGUI_InstallHooks();
BaseUI_InstallHooks();
GameUI_InstallHooks();
GameUIBasePanel_InstallHooks();
GameConsole_InstallHook();
}
void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc){
Expand Down Expand Up @@ -117,6 +118,7 @@ void IPluginsV4::ExitGame(int iResult){
UninstallEngineHook();

GameConsole_UninstallHook();
GameUIBasePanel_UninstallHooks();
GameUI_UninstallHooks();
BaseUI_UninstallHooks();
ClientVGUI_UninstallHooks();
Expand Down
5 changes: 4 additions & 1 deletion vgui2/VGUI2ExtensionImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ extern void VGUI2Extension_Shutdown();
extern void BaseUI_InstallHooks(void);
extern void BaseUI_UninstallHooks(void);

extern void GameUIBasePanel_InstallHooks();
extern void GameUIBasePanel_UninstallHooks();

extern void GameUI_InstallHooks(void);
extern void GameUI_UninstallHooks(void);

extern void ClientVGUI_InstallHooks(void);
extern void ClientVGUI_UninstallHooks(void);

extern void GameConsole_InstallHook();
extern void GameConsole_UninstallHook();
extern void GameConsole_UninstallHook();

0 comments on commit afb16c7

Please sign in to comment.