Skip to content

Commit

Permalink
Add more font and vector methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 23, 2024
1 parent 20d4468 commit 4e125a4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/cdc/math/Vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Vector.h"

void cdc::Vector::operator +=(Vector* b)
{
vec128 = _mm_add_ps(vec128, b->vec128);
}

void cdc::Vector::operator -=(Vector* b)
{
vec128 = _mm_sub_ps(vec128, b->vec128);
}

void cdc::Vector::operator *=(Vector* b)
{
vec128 = _mm_mul_ps(vec128, b->vec128);
}

void cdc::Vector::operator /=(Vector* b)
{
vec128 = _mm_div_ps(vec128, b->vec128);
}

void cdc::Vector::operator *=(float b)
{
vec128 = _mm_mul_ps(vec128, _mm_shuffle_ps(_mm_set_ss(b), _mm_set_ss(b), _MM_SHUFFLE(0, 0, 0, 0)));
}

void cdc::Vector::operator /=(float b)
{
vec128 = _mm_div_ps(vec128, _mm_shuffle_ps(_mm_set_ss(b), _mm_set_ss(b), _MM_SHUFFLE(0, 0, 0, 0)));
}
8 changes: 8 additions & 0 deletions src/cdc/math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ namespace cdc
float w;
};
};

void operator +=(Vector* b);
void operator -=(Vector* b);
void operator *=(Vector* b);
void operator /=(Vector* b);

void operator *=(float b);
void operator /=(float b);
};

class Vector2 : public Vector
Expand Down
27 changes: 27 additions & 0 deletions src/render/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ void Font::SetCursor(float x, float y)
Hooking::Call(0x433C70, x, y);
}

void Font::GetCursor(float* x, float* y)
{
Hooking::Call(0x433C90, x, y);
}

void Font::SetScale(float scaleX, float scaleY)
{
Hooking::Call(0x433E60, scaleX, scaleY);
Expand All @@ -45,11 +50,33 @@ void Font::Print(const char* fmt, ...)
PrintFormatted(s_formatted);
}

void Font::PrintCentered(const char* fmt, ...)
{
va_list va;

va_start(va, fmt);
vsprintf_s(s_formatted, fmt, va);
va_end(va);

float x, y;
GetCursor(&x, &y);

auto width = GetTextWidth(s_formatted);
SetCursor(x - width / 2, y);

PrintFormatted(s_formatted);
}

void Font::PrintFormatted(const char* formatted, int backdrop)
{
Hooking::ThisCall(0x434A70, this, formatted, backdrop);
}

float Font::GetTextWidth(const char* text)
{
return Hooking::ThisCallReturn<float>(0x434510, this, text);
}

void Font::OnFlush(std::function<void()> callback)
{
if (!s_callback)
Expand Down
4 changes: 4 additions & 0 deletions src/render/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class Font
static Font* GetMainFont();

static void SetCursor(float x, float y);
static void GetCursor(float* x, float* y);
static void SetScale(float scaleX, float scaleY);

void Print(const char* fmt, ...);
void PrintCentered(const char* fmt, ...);
void PrintFormatted(const char* formatted, int backdrop = 0);

float GetTextWidth(const char* text);

static void OnFlush(std::function<void()> callback);
};

0 comments on commit 4e125a4

Please sign in to comment.