Rendering and material components.

This commit is contained in:
momo5502 2015-12-23 16:56:02 +01:00
parent 0bbdba60f3
commit 602d4ac61d
10 changed files with 155 additions and 17 deletions

View File

@ -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<bool>() && (0xF & (int)Colors::NewColors.Get<bool>()) != 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<bool>();
}
else if (!Colors::NewColors.Get<bool>() && (0xF & (int)Colors::NewColors.Get<bool>()) != LastState)
{
memcpy(gColorTable, DefaultTable, sizeof(DefaultTable));
LastState = Colors::NewColors.Get<bool>();
}
}
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<bool>("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare˛ color code style.");
}
}

View File

@ -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);
};
}

View File

@ -1,6 +1,3 @@
#define Q_IsColorString( p ) ( ( p ) && *( p ) == '^' && *( ( p ) + 1 ) && isdigit( *( ( p ) + 1 ) ) ) // ^[0-9]
namespace Components
{
class Command : public Component

View File

@ -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());
}

View File

@ -26,4 +26,6 @@ namespace Components
#include "Command.hpp"
#include "Console.hpp"
#include "RawFiles.hpp"
#include "Renderer.hpp"
#include "Materials.hpp"
#include "QuickPatch.hpp"

View File

@ -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();
}
}

View File

@ -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();
};
}

View File

@ -1,6 +1,3 @@
#define Q_IsColorString( p ) ( ( p ) && *( p ) == '^' && *( ( p ) + 1 ) && isdigit( *( ( p ) + 1 ) ) ) // ^[0-9]
namespace Components
{
class RawFiles : public Component

View File

@ -0,0 +1,41 @@
#include "..\STDInclude.hpp"
namespace Components
{
Utils::Hook Renderer::DrawFrameHook;
std::vector<Renderer::Callback> 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();
}
}

View File

@ -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<Callback> FrameCallbacks;
static Utils::Hook DrawFrameHook;
};
}