From 602d4ac61d3f0811ec34e0676173338e3025bf1f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 23 Dec 2015 16:56:02 +0100 Subject: [PATCH] Rendering and material components. --- iw4/Components/Colors.cpp | 49 ++++++++++++++++++++++++++++-------- iw4/Components/Colors.hpp | 5 +++- iw4/Components/Command.hpp | 3 --- iw4/Components/Loader.cpp | 2 ++ iw4/Components/Loader.hpp | 2 ++ iw4/Components/Materials.cpp | 33 ++++++++++++++++++++++++ iw4/Components/Materials.hpp | 13 ++++++++++ iw4/Components/RawFiles.hpp | 3 --- iw4/Components/Renderer.cpp | 41 ++++++++++++++++++++++++++++++ iw4/Components/Renderer.hpp | 21 ++++++++++++++++ 10 files changed, 155 insertions(+), 17 deletions(-) create mode 100644 iw4/Components/Materials.cpp create mode 100644 iw4/Components/Materials.hpp create mode 100644 iw4/Components/Renderer.cpp create mode 100644 iw4/Components/Renderer.hpp diff --git a/iw4/Components/Colors.cpp b/iw4/Components/Colors.cpp index ad0aedb7..ae6e535a 100644 --- a/iw4/Components/Colors.cpp +++ b/iw4/Components/Colors.cpp @@ -2,6 +2,8 @@ namespace Components { + Dvar::Var Colors::NewColors; + void Colors::Strip(const char* in, char* out, int max) { max--; @@ -62,22 +64,49 @@ namespace Components return buffer; } + void Colors::UpdateColorTable() + { + static int LastState = 2; + static DWORD DefaultTable[8] = { 0 }; + DWORD* gColorTable = (DWORD*)0x78DC70; + + if (LastState == 2) + { + memcpy(DefaultTable, gColorTable, sizeof(DefaultTable)); + } + + if (Colors::NewColors.Get() && (0xF & (int)Colors::NewColors.Get()) != LastState) + { + // Apply NTA's W² colors :3 (slightly modified though^^) + gColorTable[1] = RGB(255, 49, 49); + gColorTable[2] = RGB(134, 192, 0); + gColorTable[3] = RGB(255, 173, 34); + gColorTable[4] = RGB(0, 135, 193); + gColorTable[5] = RGB(32, 197, 255); + gColorTable[6] = RGB(151, 80, 221); + + LastState = Colors::NewColors.Get(); + } + else if (!Colors::NewColors.Get() && (0xF & (int)Colors::NewColors.Get()) != LastState) + { + memcpy(gColorTable, DefaultTable, sizeof(DefaultTable)); + + LastState = Colors::NewColors.Get(); + } + } + Colors::Colors() { - DWORD* color_table = (DWORD*)0x78DC70; - - // Apply NTA's W² colors :3 (slightly modified though^^) - color_table[1] = RGB(255, 49, 49); - color_table[2] = RGB(134, 192, 0); - color_table[3] = RGB(255, 173, 34); - color_table[4] = RGB(0, 135, 193); - color_table[5] = RGB(32, 197, 255); - color_table[6] = RGB(151, 80, 221); - // Allow colored names ingame Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).Install()->Quick(); // Though, don't apply that to overhead names. Utils::Hook(0x581932, Colors::CL_GetClientName, HOOK_CALL).Install()->Quick(); + + // Set frame handler + Renderer::OnFrame(Colors::UpdateColorTable); + + // Register dvar + Colors::NewColors = Dvar::Var::Register("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare² color code style."); } } diff --git a/iw4/Components/Colors.hpp b/iw4/Components/Colors.hpp index 5a61cecc..54392ac4 100644 --- a/iw4/Components/Colors.hpp +++ b/iw4/Components/Colors.hpp @@ -1,6 +1,5 @@ #define Q_IsColorString( p ) ( ( p ) && *( p ) == '^' && *( ( p ) + 1 ) && isdigit( *( ( p ) + 1 ) ) ) // ^[0-9] - namespace Components { class Colors : public Component @@ -9,9 +8,13 @@ namespace Components Colors(); const char* GetName() { return "Colors"; }; + static Dvar::Var NewColors; + static void ClientUserinfoChanged(int length); static char* CL_GetClientName(int a1, int a2, char* buffer, size_t _length); + static void UpdateColorTable(); + static void Strip(const char* in, char* out, int max); }; } diff --git a/iw4/Components/Command.hpp b/iw4/Components/Command.hpp index 3110dc12..2059da3c 100644 --- a/iw4/Components/Command.hpp +++ b/iw4/Components/Command.hpp @@ -1,6 +1,3 @@ -#define Q_IsColorString( p ) ( ( p ) && *( p ) == '^' && *( ( p ) + 1 ) && isdigit( *( ( p ) + 1 ) ) ) // ^[0-9] - - namespace Components { class Command : public Component diff --git a/iw4/Components/Loader.cpp b/iw4/Components/Loader.cpp index 75b1a570..5b8af67a 100644 --- a/iw4/Components/Loader.cpp +++ b/iw4/Components/Loader.cpp @@ -12,6 +12,8 @@ namespace Components Loader::Register(new Command()); Loader::Register(new Console()); Loader::Register(new RawFiles()); + Loader::Register(new Renderer()); + Loader::Register(new Materials()); Loader::Register(new QuickPatch()); } diff --git a/iw4/Components/Loader.hpp b/iw4/Components/Loader.hpp index 7e40b4df..f986ae71 100644 --- a/iw4/Components/Loader.hpp +++ b/iw4/Components/Loader.hpp @@ -26,4 +26,6 @@ namespace Components #include "Command.hpp" #include "Console.hpp" #include "RawFiles.hpp" +#include "Renderer.hpp" +#include "Materials.hpp" #include "QuickPatch.hpp" diff --git a/iw4/Components/Materials.cpp b/iw4/Components/Materials.cpp new file mode 100644 index 00000000..082cef0c --- /dev/null +++ b/iw4/Components/Materials.cpp @@ -0,0 +1,33 @@ +#include "..\STDInclude.hpp" + +namespace Components +{ + Utils::Hook Materials::ImageVersionCheckHook; + + void __declspec(naked) Materials::ImageVersionCheck() + { + __asm + { + cmp eax, 9 + je returnSafely + + jmp Materials::ImageVersionCheckHook.Original + + returnSafely: + mov al, 1 + add esp, 18h + retn + } + } + + Materials::Materials() + { + // Allow codo images + Materials::ImageVersionCheckHook.Initialize(0x53A456, Materials::ImageVersionCheck, HOOK_CALL)->Install(); + } + + Materials::~Materials() + { + Materials::ImageVersionCheckHook.Uninstall(); + } +} diff --git a/iw4/Components/Materials.hpp b/iw4/Components/Materials.hpp new file mode 100644 index 00000000..0cb374ed --- /dev/null +++ b/iw4/Components/Materials.hpp @@ -0,0 +1,13 @@ +namespace Components +{ + class Materials : public Component + { + public: + Materials(); + ~Materials(); + const char* GetName() { return "Materials"; }; + + static Utils::Hook ImageVersionCheckHook; + static void ImageVersionCheck(); + }; +} diff --git a/iw4/Components/RawFiles.hpp b/iw4/Components/RawFiles.hpp index 73b162a3..ab0540cd 100644 --- a/iw4/Components/RawFiles.hpp +++ b/iw4/Components/RawFiles.hpp @@ -1,6 +1,3 @@ -#define Q_IsColorString( p ) ( ( p ) && *( p ) == '^' && *( ( p ) + 1 ) && isdigit( *( ( p ) + 1 ) ) ) // ^[0-9] - - namespace Components { class RawFiles : public Component diff --git a/iw4/Components/Renderer.cpp b/iw4/Components/Renderer.cpp new file mode 100644 index 00000000..7ab7167f --- /dev/null +++ b/iw4/Components/Renderer.cpp @@ -0,0 +1,41 @@ +#include "..\STDInclude.hpp" + +namespace Components +{ + Utils::Hook Renderer::DrawFrameHook; + std::vector Renderer::FrameCallbacks; + + void __declspec(naked) Renderer::FrameHook() + { + __asm + { + call Renderer::FrameHandler + jmp Renderer::DrawFrameHook.Original + } + } + + void Renderer::FrameHandler() + { + for (auto callback : Renderer::FrameCallbacks) + { + callback(); + } + } + + void Renderer::OnFrame(Renderer::Callback callback) + { + Renderer::FrameCallbacks.push_back(callback); + } + + Renderer::Renderer() + { + // Frame hook + Renderer::DrawFrameHook.Initialize(0x5ACB99, Renderer::FrameHook, HOOK_CALL)->Install(); + } + + Renderer::~Renderer() + { + Renderer::DrawFrameHook.Uninstall(); + Renderer::FrameCallbacks.clear(); + } +} diff --git a/iw4/Components/Renderer.hpp b/iw4/Components/Renderer.hpp new file mode 100644 index 00000000..7e07261d --- /dev/null +++ b/iw4/Components/Renderer.hpp @@ -0,0 +1,21 @@ +namespace Components +{ + class Renderer : public Component + { + public: + typedef void(*Callback)(); + + Renderer(); + ~Renderer(); + const char* GetName() { return "Renderer"; }; + + static void OnFrame(Callback callback); + + private: + static void FrameHook(); + static void FrameHandler(); + + static std::vector FrameCallbacks; + static Utils::Hook DrawFrameHook; + }; +}