Skip to content

Commit

Permalink
Expanded PaintTool paint size from 16 to 64
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed Feb 6, 2024
1 parent c0cec1f commit d4dd500
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Code/BetterPaintTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ BetterPaintTool::t_update_sig BetterPaintTool::o_update = nullptr;

bool BetterPaintTool::h_initialize(BetterPaintTool* self)
{
sizeof(std::deque<int>);

const bool v_out = BetterPaintTool::o_initialize(self);

if (self->m_pGuiInterface)
Expand Down
4 changes: 4 additions & 0 deletions Code/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "SmSdk/StaticValues.hpp"
#include "Utils/Console.hpp"

#include "BetterPaintToolGui.hpp"
Expand Down Expand Up @@ -36,6 +37,9 @@ void process_attach()
if (DEFINE_HOOK(0x3EE6D0, BetterPaintTool::h_update, BetterPaintTool::o_update) != MH_OK)
return;

StaticValues::sm_paintToolPaintLimiter = 64;
StaticValues::sm_paintToolEraseLimiter = 64;

ms_mhHooksAttached = MH_EnableHook(MH_ALL_HOOKS) == MH_OK;
}

Expand Down
15 changes: 15 additions & 0 deletions Dependencies/SmSdk/include/SmSdk/StaticValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "SmSdk/Util/StaticVariable.hpp"

class StaticValues
{
public:
using PaintToolPaintLimiterType = StaticVariable<std::uint32_t, 0x3F060D>;
using PaintToolEraseLimiterType = StaticVariable<std::uint32_t, 0x3F0D9B>;

//A limiter for paint tool paint function
static PaintToolPaintLimiterType sm_paintToolPaintLimiter;
//A limiter for paint tool erase function
static PaintToolEraseLimiterType sm_paintToolEraseLimiter;
};
35 changes: 35 additions & 0 deletions Dependencies/SmSdk/include/SmSdk/Util/Memory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>

#include <cstddef>
#include <cstdint>
#include <memory>

namespace Memory
{
template<typename T>
inline static T& ReadRef(std::uintptr_t offset)
{
return *reinterpret_cast<T*>(std::uintptr_t(GetModuleHandle(NULL)) + offset);
}

template<typename T>
inline static T* ReadPtr(std::uintptr_t offset)
{
return reinterpret_cast<T*>(std::uintptr_t(GetModuleHandle(NULL)) + offset);
}

template<typename T>
void WriteMemory(std::uintptr_t offset, const T& data)
{
void* v_global_ptr = ReadPtr<void>(offset);

DWORD v_old_protect;
VirtualProtect(v_global_ptr, sizeof(T), PAGE_EXECUTE_READWRITE, &v_old_protect);
std::memcpy(v_global_ptr, &data, sizeof(T));
VirtualProtect(v_global_ptr, sizeof(T), v_old_protect, &v_old_protect);
}
}
34 changes: 34 additions & 0 deletions Dependencies/SmSdk/include/SmSdk/Util/StaticVariable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "SmSdk/Util/Memory.hpp"

#include <cstddef>
#include <cstdint>

template<typename T, std::uintptr_t t_static_offset>
class StaticVariable
{
public:
StaticVariable() = default;

StaticVariable(const T& val)
{
Memory::WriteMemory<T>(t_static_offset, val);
}

inline void operator=(const T& val) noexcept
{
Memory::WriteMemory<T>(t_static_offset, val);
}

//Be careful when writing data to the pointer, the data might be protected
inline const T* operator&() noexcept
{
return Memory::ReadPtr<T>(t_static_offset);
}

inline operator T()
{
return *Memory::ReadPtr<T>(t_static_offset);
}
};
8 changes: 7 additions & 1 deletion Dependencies/SmSdk/src/PointerGetters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "SmSdk/PlayerManager.hpp"
#include "SmSdk/AudioManager.hpp"
#include "SmSdk/InputManager.hpp"
#include "SmSdk/StaticValues.hpp"
#include "SmSdk/MyPlayer.hpp"

#include "SmSdk/config.hpp"
Expand Down Expand Up @@ -39,4 +40,9 @@ GET_INSTANCE_DEFINE(MyPlayer, 0x128D658);

#if defined(SMSDK_ENABLE_PHYSICS)
GET_INSTANCE_DEFINE(Physics, 0x128D628);
#endif
#endif

//STATIC VARIABLE DEFINITIONS

StaticValues::PaintToolEraseLimiterType StaticValues::sm_paintToolEraseLimiter{};
StaticValues::PaintToolPaintLimiterType StaticValues::sm_paintToolPaintLimiter{};
3 changes: 3 additions & 0 deletions SM-BetterPaintTool.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\InputManager.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Player.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\PlayerManager.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\StaticValues.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Tool\ClientTool.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Tool\PaintTool.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Util\Color.hpp" />
Expand All @@ -188,6 +189,8 @@
<ClInclude Include="Code\Utils\Console.hpp" />
<ClInclude Include="Code\win_include.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\config.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Util\Memory.hpp" />
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Util\StaticVariable.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
9 changes: 9 additions & 0 deletions SM-BetterPaintTool.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,14 @@
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\InputManager.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Util\StaticVariable.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\Util\Memory.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dependencies\SmSdk\include\SmSdk\StaticValues.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit d4dd500

Please sign in to comment.