Skip to content

Commit

Permalink
Added a color picker animation
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed Feb 5, 2024
1 parent 867ebf4 commit 83021a6
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
13 changes: 13 additions & 0 deletions Code/BetterPaintTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ void BetterPaintTool::h_update(BetterPaintTool* self, float dt)
{
BetterPaintTool::o_update(self, dt);

//The game doesn't like it when multiple animations use the same animation file
if (self->m_fpAnims.current_anim != "color_picker" && self->m_fpAnims.current_anim != "color_picker_end")
{
self->m_fpAnims.removeAnimation("color_picker");
self->m_fpAnims.removeAnimation("color_picker_end");
}

if (self->is_equipped() && (GetAsyncKeyState(VK_MBUTTON) & 1))
{
Physics* v_pPhysics = Physics::GetInstance();
Expand Down Expand Up @@ -126,6 +133,12 @@ void BetterPaintTool::h_update(BetterPaintTool* self, float dt)

InGameGuiManager::DisplayAlertText(std::string(v_buffer, v_buffer_sz), 2.0f);
AudioManager::PlaySound("PaintTool - ColorPick");

self->m_fpAnims.resetAnimation("pick");
self->m_fpAnims.addNewAnimation("color_picker", "painttool_colorpick_idle", "color_picker_end", 0.0f, 1.0f, 5.0f);
self->m_fpAnims.addNewAnimation("color_picker_end", "painttool_colorpick", "idle", 0.0f, 0.7f, 1.0f);
self->setFpAndTpAnimation("color_picker");

self->setColor(v_obj_color);
}
}
Expand Down
105 changes: 97 additions & 8 deletions Dependencies/SmSdk/include/SmSdk/Tool/ClientTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@

class ClientTool;

enum AnimationFlag : std::uint32_t
{
AnimationFlag_None = 0,
AnimationFlag_Repeat = 1
};

struct ToolAnimationEntry
{
/* 0x0000 */ std::string full_anim_name;
/* 0x0020 */ std::string next_anim_name;
}; // Size: 0x40
/* 0x0000 */ std::string anim_name;
/* 0x0020 */ std::string next_anim;
/* 0x0040 */ float anim_begin;
/* 0x0044 */ float anim_end;
/* 0x0048 */ float anim_time;
/* 0x004C */ float weight;
/* 0x0050 */ float playback_speed;
/* 0x0054 */ std::uint32_t flags;

static_assert(sizeof(ToolAnimationEntry) == 0x40, "ToolAnimationEntry: Incorrect Size");
}; // Size: 0x58

static_assert(sizeof(ToolAnimationEntry) == 0x58, "ToolAnimationEntry: Incorrect Size");

struct ToolAnimationList
{
Expand All @@ -42,26 +55,102 @@ static_assert(sizeof(ToolAnimationList) == 0x220, "ToolAnimationList: Incorrect

struct ToolAnimationData
{
void setAnimation(const std::string& name)
{
auto v_iter = this->animation_data.find(name);
if (v_iter == this->animation_data.end())
return;

this->current_anim = name;
v_iter->second.anim_time = 0.0f;
this->anim_begin = 0.2f;
}

bool hasAnimation(const std::string& name) const
{
return this->animation_data.find(name) != this->animation_data.end();
}

void resetAnimation(const std::string& name)
{
auto v_iter = this->animation_data.find(name);
if (v_iter == this->animation_data.end())
return;

v_iter->second.anim_time = 0.0f;
v_iter->second.weight = 0.0f;
}

void addNewAnimation(
const std::string& name,
const std::string& start_anim,
const std::string& next_anim,
float anim_begin = 0.0f,
float anim_end = 1.0f,
float playback_speed = 1.0f,
std::uint32_t flags = 256)
{
ToolAnimationEntry v_new_entry;
v_new_entry.anim_name = start_anim;
v_new_entry.next_anim = next_anim;
v_new_entry.anim_time = 0.0f;
v_new_entry.anim_begin = anim_begin;
v_new_entry.anim_end = anim_end;
v_new_entry.weight = 0.0f;
v_new_entry.playback_speed = playback_speed;
v_new_entry.flags = flags;

this->animation_data.emplace(name, v_new_entry);
}

void removeAnimation(const std::string& name)
{
auto v_iter = this->animation_data.find(name);
if (v_iter != this->animation_data.end())
this->animation_data.erase(v_iter);
}

/* 0x0000 */ ClientTool* tool_ptr;
/* 0x0008 */ std::unordered_map<std::string, ToolAnimationEntry> animation_data;
/* 0x0048 */ std::string idle_anim;
/* 0x0048 */ std::string current_anim;
/* 0x0068 */ ToolAnimationList tool_anim_list;
/* 0x0288 */ char pad_0x288[0x8];
/* 0x0288 */ float anim_begin;
private:
/* 0x028C */ char pad_0x28C[0x4];

}; // Size: 0x290

static_assert(sizeof(ToolAnimationData) == 0x290, "ToolAnimationData: Incorrect Size");

class ClientTool : public IToolImpl
{
/* 0x0008 */ ToolAnimationData anim_data1;
/* 0x0298 */ ToolAnimationData anim_data2;
public:
inline void setTpAnimation(const std::string& name)
{
m_tpAnims.setAnimation(name);
}

inline void setFpAnimation(const std::string& name)
{
m_fpAnims.setAnimation(name);
}

inline void setFpAndTpAnimation(const std::string& name)
{
this->setFpAnimation(name);
this->setTpAnimation(name);
}

/* 0x0008 */ ToolAnimationData m_tpAnims;
/* 0x0298 */ ToolAnimationData m_fpAnims;
/* 0x0528 */ std::shared_ptr<Tool> tool;
/* 0x0538 */ bool block_sprint;
/* 0x0539 */ char pad_0x539[0x3];
/* 0x053C */ float dispersion_fraction;
/* 0x0540 */ float crosshair_alpha;
/* 0x0544 */ bool interaction_text_suppressed;
/* 0x0545 */ char pad_0x545[0x3];

}; // Size: 0x548

static_assert(sizeof(ClientTool) == 0x548, "ClientTool: Incorrect Size");

0 comments on commit 83021a6

Please sign in to comment.