Add branding component
This commit is contained in:
parent
0e5af0f514
commit
8a770985d6
@ -69,7 +69,6 @@ namespace Components
|
||||
Loader::Register(new Renderer());
|
||||
Loader::Register(new UIFeeder());
|
||||
Loader::Register(new UIScript());
|
||||
Loader::Register(new AntiCheat());
|
||||
Loader::Register(new Changelog());
|
||||
Loader::Register(new Dedicated());
|
||||
Loader::Register(new Discovery());
|
||||
@ -105,6 +104,7 @@ namespace Components
|
||||
Loader::Register(new Elevators());
|
||||
Loader::Register(new ClientCommand());
|
||||
Loader::Register(new ScriptExtension());
|
||||
Loader::Register(new Branding());
|
||||
|
||||
Loader::Pregame = false;
|
||||
}
|
||||
|
@ -99,7 +99,6 @@ namespace Components
|
||||
#include "Modules/RawFiles.hpp"
|
||||
#include "Modules/Renderer.hpp"
|
||||
#include "Modules/UIFeeder.hpp"
|
||||
#include "Modules/AntiCheat.hpp"
|
||||
#include "Modules/Changelog.hpp"
|
||||
#include "Modules/Dedicated.hpp"
|
||||
#include "Modules/Discovery.hpp"
|
||||
@ -134,6 +133,6 @@ namespace Components
|
||||
#include "Modules/Movement.hpp"
|
||||
#include "Modules/Elevators.hpp"
|
||||
#include "Modules/ClientCommand.hpp"
|
||||
|
||||
#include "Modules/Gamepad.hpp"
|
||||
#include "Modules/ScriptExtension.hpp"
|
||||
#include "Modules/Branding.hpp"
|
||||
|
118
src/Components/Modules/Branding.cpp
Normal file
118
src/Components/Modules/Branding.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include <STDInclude.hpp>
|
||||
|
||||
namespace Components
|
||||
{
|
||||
Dvar::Var Branding::CGDrawVersion;
|
||||
Dvar::Var Branding::CGDrawVersionX;
|
||||
Dvar::Var Branding::CGDrawVersionY;
|
||||
Game::dvar_t** Branding::Version = reinterpret_cast<Game::dvar_t**>(0x1AD7930);
|
||||
|
||||
void Branding::CG_DrawVersion()
|
||||
{
|
||||
// Default values
|
||||
constexpr auto fontScale = 0.25f;
|
||||
constexpr auto maxChars = std::numeric_limits<int>::max();
|
||||
// Default colours
|
||||
constexpr Game::vec4_t shadowColor = {0.0f, 0.0f, 0.0f, 0.7f};
|
||||
constexpr Game::vec4_t color = {0.4f, 0.7f, 1.0f, 0.7f};
|
||||
|
||||
auto* const placement = Game::ScrPlace_GetUnsafeFullPlacement();
|
||||
auto* const font = Game::UI_GetFontHandle(placement, 0, 0.5f);
|
||||
|
||||
const auto width = Game::UI_TextWidth((*Version)->current.string, 0, font, fontScale);
|
||||
const auto height = Game::UI_TextHeight(font, fontScale);
|
||||
|
||||
Game::UI_DrawText(placement, (*Version)->current.string, maxChars, font, 1.0f - (CGDrawVersionX.get<float>() + width),
|
||||
1.0f - (CGDrawVersionY.get<float>() + height), 3, 3, fontScale, shadowColor, 0);
|
||||
Game::UI_DrawText(placement, (*Version)->current.string, maxChars, font, (0.0f - width) - CGDrawVersionX.get<float>(),
|
||||
(0.0f - height) - CGDrawVersionY.get<float>(), 3, 3, fontScale, color, 0);
|
||||
}
|
||||
|
||||
void Branding::CG_DrawVersion_Hk(int localClientNum)
|
||||
{
|
||||
Utils::Hook::Call<void(int)>(0x4EFF80)(localClientNum);
|
||||
|
||||
if (Branding::CGDrawVersion.get<bool>())
|
||||
{
|
||||
Branding::CG_DrawVersion();
|
||||
}
|
||||
}
|
||||
|
||||
const char* Branding::GetBuildNumber()
|
||||
{
|
||||
static char buf[128]; // Length the game uses
|
||||
|
||||
const auto* data = "latest " __DATE__ " " __TIME__;
|
||||
sprintf_s(buf, sizeof(buf), "%s %s", SHORTVERSION, data);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Use IW4x Branding
|
||||
void Branding::Dvar_SetVersionString(const Game::dvar_t* dvar, const char* /*value*/)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
const auto* buildType = "IW4x_DEV MP";
|
||||
#else
|
||||
const auto* buildType = "IW4x MP";
|
||||
#endif
|
||||
|
||||
// IW4x is technically a beta
|
||||
const auto* result = Utils::String::VA("%s %s build %s %s",
|
||||
buildType, "(Beta)", Branding::GetBuildNumber(), reinterpret_cast<const char*>(0x7170A0));
|
||||
|
||||
Utils::Hook::Call<void(const Game::dvar_t*, const char*)>(0x4A9580)(dvar, result);
|
||||
}
|
||||
|
||||
Game::dvar_t* Branding::Dvar_RegisterUIBuildLocation(const char* dvarName,
|
||||
float /*x*/, float /*y*/, float min, float max, int /*flags*/, const char* description)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
constexpr auto flag = Game::dvar_flag::DVAR_NONE;
|
||||
#else
|
||||
constexpr auto flag = Game::dvar_flag::DVAR_READONLY;
|
||||
#endif
|
||||
return Game::Dvar_RegisterVec2(dvarName, -60.0f, 474.0f, min, max, flag, description);
|
||||
}
|
||||
|
||||
void Branding::RegisterBrandingDvars()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
constexpr auto value = true;
|
||||
#else
|
||||
constexpr auto value = false;
|
||||
#endif
|
||||
Branding::CGDrawVersion = Dvar::Register<bool>("cg_drawVersion", value,
|
||||
Game::dvar_flag::DVAR_NONE, "Draw the game version");
|
||||
Branding::CGDrawVersionX = Dvar::Register<float>("cg_drawVersionX", 50.0f,
|
||||
0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "X offset for the version string");
|
||||
Branding::CGDrawVersionY = Dvar::Register<float>("cg_drawVersionY", 18.0f,
|
||||
0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "Y offset for the version string");
|
||||
}
|
||||
|
||||
Branding::Branding()
|
||||
{
|
||||
Dvar::OnInit(Branding::RegisterBrandingDvars);
|
||||
|
||||
// UI version string
|
||||
Utils::Hook::Set<const char*>(0x43F73B, "IW4x: " VERSION);
|
||||
|
||||
// Short version dvar
|
||||
Utils::Hook::Set<const char*>(0x60BD91, SHORTVERSION);
|
||||
|
||||
// Console version string
|
||||
Utils::Hook::Set<const char*>(0x4B12BB, "IW4x " VERSION " (built " __DATE__ " " __TIME__ ")");
|
||||
|
||||
// Version string color
|
||||
static Game::vec4_t buildLocColor = {1.0f, 1.0f, 1.0f, 0.8f};
|
||||
Utils::Hook::Set<float*>(0x43F710, buildLocColor);
|
||||
|
||||
// Shift ui version string to the left (ui_buildlocation)
|
||||
Utils::Hook(0x6310A0, Branding::Dvar_RegisterUIBuildLocation, HOOK_CALL).install()->quick(); // Dvar_RegisterVec2
|
||||
|
||||
Utils::Hook(0x60BD81, Branding::Dvar_SetVersionString, HOOK_CALL).install()->quick();
|
||||
|
||||
// Hook CG_DrawFullScreenDebugOverlays so we may render the version when it's appropriate
|
||||
Utils::Hook(0x5AC975, Branding::CG_DrawVersion_Hk, HOOK_CALL).install()->quick();
|
||||
}
|
||||
}
|
26
src/Components/Modules/Branding.hpp
Normal file
26
src/Components/Modules/Branding.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
namespace Components
|
||||
{
|
||||
class Branding : public Component
|
||||
{
|
||||
public:
|
||||
Branding();
|
||||
|
||||
private:
|
||||
static Dvar::Var CGDrawVersion;
|
||||
static Dvar::Var CGDrawVersionX;
|
||||
static Dvar::Var CGDrawVersionY;
|
||||
static Game::dvar_t** Version;
|
||||
|
||||
static void CG_DrawVersion();
|
||||
static void CG_DrawVersion_Hk(int localClientNum);
|
||||
|
||||
static const char* GetBuildNumber();
|
||||
static void Dvar_SetVersionString(const Game::dvar_t* dvar, const char* value);
|
||||
|
||||
static Game::dvar_t* Dvar_RegisterUIBuildLocation(const char* dvarName, float x, float y, float min, float max, int flags, const char* description);
|
||||
|
||||
static void RegisterBrandingDvars();
|
||||
};
|
||||
}
|
@ -348,12 +348,6 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
Game::dvar_t* QuickPatch::Dvar_RegisterUIBuildLocation(const char* dvarName,
|
||||
float /*x*/, float /*y*/, float min, float max, int /*flags*/, const char* description)
|
||||
{
|
||||
return Game::Dvar_RegisterVec2(dvarName, -60.0f, 474.0f, min, max, Game::DVAR_READONLY, description);
|
||||
}
|
||||
|
||||
QuickPatch::QuickPatch()
|
||||
{
|
||||
// quitHard
|
||||
@ -426,22 +420,6 @@ namespace Components
|
||||
// fs_basegame
|
||||
Utils::Hook::Set<const char*>(0x6431D1, BASEGAME);
|
||||
|
||||
// UI version string
|
||||
Utils::Hook::Set<const char*>(0x43F73B, "IW4x: " VERSION);
|
||||
|
||||
// console version string
|
||||
Utils::Hook::Set<const char*>(0x4B12BB, "IW4x " VERSION " (built " __DATE__ " " __TIME__ ")");
|
||||
|
||||
// version string
|
||||
Utils::Hook::Set<const char*>(0x60BD56, "IW4x (" VERSION ")");
|
||||
|
||||
// version string color
|
||||
static Game::vec4_t buildLocColor = { 1.0f, 1.0f, 1.0f, 0.8f };
|
||||
Utils::Hook::Set<float*>(0x43F710, buildLocColor);
|
||||
|
||||
// Shift ui version string to the left (ui_buildlocation)
|
||||
Utils::Hook(0x6310A0, QuickPatch::Dvar_RegisterUIBuildLocation, HOOK_CALL).install()->quick();
|
||||
|
||||
// console title
|
||||
if (ZoneBuilder::IsEnabled())
|
||||
{
|
||||
@ -462,9 +440,6 @@ namespace Components
|
||||
// sv_hostname
|
||||
Utils::Hook::Set<const char*>(0x4D378B, "IW4Host");
|
||||
|
||||
// shortversion
|
||||
Utils::Hook::Set<const char*>(0x60BD91, SHORTVERSION);
|
||||
|
||||
// console logo
|
||||
Utils::Hook::Set<const char*>(0x428A66, BASEGAME "/images/logo.bmp");
|
||||
|
||||
|
@ -40,7 +40,5 @@ namespace Components
|
||||
|
||||
static void CL_KeyEvent_OnEscape();
|
||||
static void CL_KeyEvent_ConsoleEscape_Stub();
|
||||
|
||||
static Game::dvar_t* Dvar_RegisterUIBuildLocation(const char* dvarName, float x, float y, float min, float max, int flags, const char* description);
|
||||
};
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
void Window::DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material)
|
||||
void Window::DrawCursorStub(Game::ScreenPlacement* scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float* color, Game::Material* material)
|
||||
{
|
||||
if (Window::NativeCursor.get<bool>())
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace Components
|
||||
static BOOL WINAPI MessageHandler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
static int WINAPI ShowCursorHook(BOOL show);
|
||||
static void DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material);
|
||||
static void DrawCursorStub(Game::ScreenPlacement* scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float* color, Game::Material* material);
|
||||
|
||||
static void StyleHookStub();
|
||||
static HWND WINAPI CreateMainWindow(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
|
||||
|
@ -378,6 +378,7 @@ namespace Game
|
||||
UI_DrawHandlePic_t UI_DrawHandlePic = UI_DrawHandlePic_t(0x4D0EA0);
|
||||
ScrPlace_GetActivePlacement_t ScrPlace_GetActivePlacement = ScrPlace_GetActivePlacement_t(0x4F8940);
|
||||
UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0);
|
||||
UI_TextHeight_t UI_TextHeight = UI_TextHeight_t(0x4C8630);
|
||||
UI_DrawText_t UI_DrawText = UI_DrawText_t(0x49C0D0);
|
||||
UI_GetFontHandle_t UI_GetFontHandle = UI_GetFontHandle_t(0x4AEA60);
|
||||
ScrPlace_ApplyRect_t ScrPlace_ApplyRect = ScrPlace_ApplyRect_t(0x454E20);
|
||||
@ -460,10 +461,6 @@ namespace Game
|
||||
|
||||
gentity_t* g_entities = reinterpret_cast<gentity_t*>(0x18835D8);
|
||||
|
||||
int* level_num_entities = reinterpret_cast<int*>(0x1A831B0);
|
||||
int* level_time = reinterpret_cast<int*>(0x1A83554);
|
||||
int* level_scriptPrintChannel = reinterpret_cast<int*>(0x1A860FC);
|
||||
|
||||
netadr_t* connectedHost = reinterpret_cast<netadr_t*>(0xA1E888);
|
||||
|
||||
SOCKET* ip_socket = reinterpret_cast<SOCKET*>(0x64A3008);
|
||||
@ -534,9 +531,11 @@ namespace Game
|
||||
|
||||
XModel** cached_models = reinterpret_cast<XModel**>(0x1AA20C8);
|
||||
|
||||
vec3_t* CorrectSolidDeltas = reinterpret_cast<vec3_t*>(0x739BB8); // Count 26
|
||||
|
||||
FastCriticalSection* db_hashCritSect = reinterpret_cast<FastCriticalSection*>(0x16B8A54);
|
||||
|
||||
vec3_t* CorrectSolidDeltas = reinterpret_cast<vec3_t*>(0x739BB8); // Count 26
|
||||
ScreenPlacement* scrPlaceFullUnsafe = reinterpret_cast<ScreenPlacement*>(0x1084460);
|
||||
|
||||
void Sys_LockRead(FastCriticalSection* critSect)
|
||||
{
|
||||
@ -1102,6 +1101,11 @@ namespace Game
|
||||
return GraphGetValueFromFraction(graph->knotCount, graph->knots, fraction) * graph->scale;
|
||||
}
|
||||
|
||||
ScreenPlacement* ScrPlace_GetUnsafeFullPlacement()
|
||||
{
|
||||
return scrPlaceFullUnsafe;
|
||||
}
|
||||
|
||||
#pragma optimize("", off)
|
||||
__declspec(naked) float UI_GetScoreboardLeft(void* /*a1*/)
|
||||
{
|
||||
|
@ -912,7 +912,7 @@ namespace Game
|
||||
typedef void(__cdecl * UI_SortArenas_t)();
|
||||
extern UI_SortArenas_t UI_SortArenas;
|
||||
|
||||
typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material);
|
||||
typedef void(__cdecl * UI_DrawHandlePic_t)(ScreenPlacement* scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float* color, Material* material);
|
||||
extern UI_DrawHandlePic_t UI_DrawHandlePic;
|
||||
|
||||
typedef ScreenPlacement*(__cdecl * ScrPlace_GetActivePlacement_t)(int localClientNum);
|
||||
@ -921,6 +921,9 @@ namespace Game
|
||||
typedef int(__cdecl * UI_TextWidth_t)(const char* text, int maxChars, Font_s *font, float scale);
|
||||
extern UI_TextWidth_t UI_TextWidth;
|
||||
|
||||
typedef int(__cdecl * UI_TextHeight_t)(Font_s* font, float scale);
|
||||
extern UI_TextHeight_t UI_TextHeight;
|
||||
|
||||
typedef void(__cdecl * UI_DrawText_t)(const ScreenPlacement* scrPlace, const char* text, int maxChars, Font_s* font, float x, float y, int horzAlign, int vertAlign, float scale, const float* color, int style);
|
||||
extern UI_DrawText_t UI_DrawText;
|
||||
|
||||
@ -1036,10 +1039,6 @@ namespace Game
|
||||
constexpr auto ENTITYNUM_NONE = MAX_GENTITIES - 1;
|
||||
extern gentity_t* g_entities;
|
||||
|
||||
extern int* level_num_entities;
|
||||
extern int* level_time;
|
||||
extern int* level_scriptPrintChannel;
|
||||
|
||||
extern netadr_t* connectedHost;
|
||||
extern SOCKET* ip_socket;
|
||||
|
||||
@ -1117,11 +1116,17 @@ namespace Game
|
||||
|
||||
extern FastCriticalSection* db_hashCritSect;
|
||||
|
||||
extern ScreenPlacement* scrPlaceFullUnsafe;
|
||||
|
||||
extern level_locals_t* level;
|
||||
|
||||
void Sys_LockRead(FastCriticalSection* critSect);
|
||||
void Sys_UnlockRead(FastCriticalSection* critSect);
|
||||
|
||||
XModel* G_GetModel(int index);
|
||||
|
||||
ScreenPlacement* ScrPlace_GetUnsafeFullPlacement();
|
||||
|
||||
XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize);
|
||||
void Menu_FreeItemMemory(Game::itemDef_s* item);
|
||||
void Menu_SetNextCursorItem(Game::UiContext* ctx, Game::menuDef_t* currentMenu, int unk = 1);
|
||||
|
Loading…
Reference in New Issue
Block a user