Skip to content

Commit 21f6673

Browse files
committed
simplify api, remove dependency
1 parent 1d1ad42 commit 21f6673

File tree

15 files changed

+302
-497
lines changed

15 files changed

+302
-497
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ project(WaveTrailDrawFix VERSION 1.1.0)
1212

1313
add_library(${PROJECT_NAME} SHARED
1414
src/hooks/HardStreak.cpp
15-
src/nodes/ColorDrawNode.cpp
1615
src/utilities.cpp
1716
src/main.cpp
17+
src/api.cpp
1818
)
19+
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND WIN32)
20+
target_sources(${PROJECT_NAME} PRIVATE src/debug-windows.cpp)
21+
endif()
22+
1923
include_directories(${PROJECT_NAME} PUBLIC include)
2024

25+
add_compile_definitions(NDEBUG _NDEBUG)
26+
2127
if (NOT DEFINED ENV{GEODE_SDK})
2228
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
2329
else()

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.1.3
2+
- simplify mod scope (to prevent issues with shaders)
3+
14
# v1.1.2
25
- macOS & iOS support (thank you, hiimjasmine00)
36

include/constants.hpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,8 @@
44
#include <Geode/Geode.hpp>
55
using namespace geode::prelude;
66

7-
const std::map<std::string, GLenum> blendEnumMap = {
8-
{"GL_ZERO", GL_ZERO},
9-
{"GL_ONE", GL_ONE},
10-
{"GL_SRC_COLOR", GL_SRC_COLOR},
11-
{"GL_ONE_MINUS_SRC_COLOR", GL_ONE_MINUS_SRC_COLOR},
12-
{"GL_DST_COLOR", GL_DST_COLOR},
13-
{"GL_ONE_MINUS_DST_COLOR", GL_ONE_MINUS_DST_COLOR},
14-
{"GL_SRC_ALPHA", GL_SRC_ALPHA},
15-
{"GL_ONE_MINUS_SRC_ALPHA", GL_ONE_MINUS_SRC_ALPHA},
16-
{"GL_DST_ALPHA", GL_DST_ALPHA},
17-
{"GL_ONE_MINUS_DST_ALPHA", GL_ONE_MINUS_DST_ALPHA},
18-
//{"GL_CONSTANT_COLOR", GL_CONSTANT_COLOR},
19-
//{"GL_ONE_MINUS_CONSTANT_COLOR", GL_ONE_MINUS_CONSTANT_COLOR},
20-
//{"GL_CONSTANT_ALPHA", GL_CONSTANT_ALPHA},
21-
//{"GL_ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA},
22-
{"GL_SRC_ALPHA_SATURATE", GL_SRC_ALPHA_SATURATE},
23-
//{"GL_SRC1_COLOR", GL_SRC1_COLOR},
24-
//{"GL_ONE_MINUS_SRC1_COLOR", GL_ONE_MINUS_SRC1_COLOR},
25-
//{"GL_SRC1_ALPHA", GL_SRC1_ALPHA},
26-
//{"GL_ONE_MINUS_SRC1_ALPHA", GL_ONE_MINUS_SRC1_ALPHA},
27-
};
28-
29-
const std::map<std::string, _ccBlendFunc> blendFuncMap = {
30-
{"additive", {GL_SRC_ALPHA, GL_ONE}},
31-
{"normal", {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}},
32-
};
33-
34-
const std::map<std::string, GLenum> blendEqMap = {
35-
{"GL_FUNC_ADD", GL_FUNC_ADD},
36-
{"GL_FUNC_SUBTRACT", GL_FUNC_SUBTRACT},
37-
{"GL_FUNC_REVERSE_SUBTRACT", GL_FUNC_REVERSE_SUBTRACT},
38-
{"GL_MIN", 0x8007},
39-
{"GL_MAX", 0x8008},
40-
41-
{"add", GL_FUNC_ADD},
42-
{"subtract", GL_FUNC_SUBTRACT},
43-
{"reverse-subtract", GL_FUNC_REVERSE_SUBTRACT},
44-
{"min", 0x8007},
45-
{"max", 0x8008},
46-
};
47-
487
const float epsilon = 10e-6f;
498

50-
519
using SetConfigurationEvent = geode::DispatchEvent<matjson::Value>;
5210
using SetConfigurationEventResult = geode::DispatchEvent<matjson::Value, std::optional<std::string>*>;
5311
using GetConfigurationEvent = geode::DispatchEvent<matjson::Value*>;
@@ -60,4 +18,3 @@ using GetSpecificConfigurationEvent = geode::DispatchEvent<HardStreak*, matjson:
6018
using UpdateConfigurationFilter = geode::DispatchFilter<HardStreak*, matjson::Value>;
6119
using UpdateConfigurationFilterResult = geode::DispatchFilter<HardStreak*, matjson::Value, std::optional<std::string>*>;
6220
using GetSpecificConfigurationFilter = geode::DispatchFilter<HardStreak*, matjson::Value*>;
63-

include/globals.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
#include <utilities.hpp>
44

5-
extern std::vector<utilities::Unit> configuration;
5+
extern std::vector<utilities::Part> configuration;

include/hooks/HardStreak.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ using namespace geode::prelude;
77

88
struct HookedHardStreak : Modify<HookedHardStreak, HardStreak> {
99
struct Fields {
10-
std::vector<utilities::Unit> m_configuration;
11-
// if this is true, the configuration is invalid, and the trail will not get drawn
12-
bool m_broken = false;
10+
std::vector<utilities::Part> m_configuration;
1311
};
1412

1513
static void onModify(auto& self);
@@ -19,13 +17,11 @@ struct HookedHardStreak : Modify<HookedHardStreak, HardStreak> {
1917

2018
void clearAllChildren();
2119

22-
void setConfiguration(std::vector<utilities::Unit>&);
20+
void setConfiguration(std::vector<utilities::Part>&);
2321

24-
$override
25-
void stopStroke();
22+
void drawTriangle(CCPoint const&, CCPoint const&, CCPoint const&, ccColor4B color);
2623

2724
$override
2825
void updateStroke(float);
2926

3027
};
31-

include/nodes/ColorDrawNode.hpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

include/utilities.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,29 @@ namespace utilities {
2424
// people who actually know how to generate proper offset polylines: please tell me what i am missing
2525
void fixPoints(std::vector<CCPoint>& trailPath, float offset, std::vector<CCPoint>& points, std::vector<bool>& labels, std::vector<CCPoint>& otherPoints);
2626

27-
struct Part {
28-
std::string type;
29-
matjson::Value data;
30-
float weight;
27+
struct Subpart {
28+
std::optional<ccColor3B> color;
29+
float weight, opacity;
30+
bool solidOnly, nonSolidOnly;
3131
};
3232

33-
struct Unit {
33+
struct Part {
3434
float start, end, startOffset, endOffset;
3535
std::optional<float> pulseOverride, sizeOverride;
36-
std::vector<Part> parts;
36+
std::vector<Subpart> subparts;
3737
};
3838

3939
}
4040

4141

4242
template <>
43-
struct matjson::Serialize<utilities::Part> {
44-
static Result<utilities::Part> fromJson(const matjson::Value& value);
45-
static matjson::Value toJson(const utilities::Part& part);
43+
struct matjson::Serialize<utilities::Subpart> {
44+
static Result<utilities::Subpart> fromJson(const matjson::Value& value);
45+
static matjson::Value toJson(const utilities::Subpart& subpart);
4646
};
4747

4848
template <>
49-
struct matjson::Serialize<utilities::Unit> {
50-
static Result<utilities::Unit> fromJson(const matjson::Value& value);
51-
static matjson::Value toJson(const utilities::Unit& unit);
49+
struct matjson::Serialize<utilities::Part> {
50+
static Result<utilities::Part> fromJson(const matjson::Value& value);
51+
static matjson::Value toJson(const utilities::Part& part);
5252
};
53-

mod.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
2-
"geode": "4.7.0",
2+
"geode": "4.8.0",
33
"gd": {"android": "2.2074", "win": "2.2074", "mac": "2.2074", "ios": "2.2074"},
4-
"version": "v1.1.2",
4+
"version": "v1.1.3",
55
"id": "nytelyte.wave_trail_draw_fix",
66
"name": "Wave Trail Draw Fix",
77
"developer": "NyteLyte",
88
"description": "Fix the wave trail drawing algorithm.",
99
"repository": "https://github.com/nytelytee/geode-wave-trail-draw-fix",
1010
"resources": {"files": ["resources/examples/with.png", "resources/examples/without.png", "resources/examples/with-trailfix.png"]},
1111
"tags": ["offline", "bugfix", "enhancement"],
12-
"incompatibilities": [{"id": "sabe.trailfix", "version": "*", "importance": "conflicting"}],
13-
"dependencies": [{"id": "nytelyte.wave_trail_drag_fix", "version": ">=v1.0.0", "importance": "suggested"}]
12+
"incompatibilities": [{"id": "sabe.trailfix", "version": "*", "importance": "conflicting"}]
1413
}

src/api.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <constants.hpp>
2+
#include <utilities.hpp>
3+
#include <globals.hpp>
4+
#include <hooks/HardStreak.hpp>
5+
6+
using namespace geode::prelude;
7+
8+
// there is no api header yet, there may be one in the future
9+
// interact with these events directly at your own risk, they can be changed at any time
10+
11+
$execute {
12+
13+
// set the global configuration, silently ignore config parsing errors
14+
new EventListener(+[](matjson::Value config) {
15+
Result<std::vector<utilities::Part>> newConfigResult = config.as<std::vector<utilities::Part>>();
16+
if (newConfigResult.isOk()) configuration = *newConfigResult.ok();
17+
return ListenerResult::Stop;
18+
}, SetConfigurationFilter("set-configuration"_spr));
19+
20+
// set the global configuration, put config parsing errors into second argument
21+
new EventListener(+[](matjson::Value config, std::optional<std::string>* error) {
22+
Result<std::vector<utilities::Part>> newConfigResult = config.as<std::vector<utilities::Part>>();
23+
if (newConfigResult.isOk()) configuration = *newConfigResult.ok();
24+
*error = newConfigResult.err();
25+
return ListenerResult::Stop;
26+
}, SetConfigurationFilterResult("set-configuration"_spr));
27+
28+
// get the global configuration
29+
new EventListener(+[](matjson::Value* config) {
30+
*config = configuration;
31+
return ListenerResult::Stop;
32+
}, GetConfigurationFilter("get-configuration"_spr));
33+
34+
// get the configuration of a specific HardStreak
35+
new EventListener(+[](HardStreak* streak, matjson::Value* config) {
36+
*config = static_cast<HookedHardStreak*>(streak)->m_fields->m_configuration;
37+
return ListenerResult::Stop;
38+
}, GetSpecificConfigurationFilter("get-configuration"_spr));
39+
40+
// these are named differently from set-configuration, as they actually update a streak's configuration explicitly
41+
// HardStreaks store their configurations after they're set, so subsequent updates to the global configuration will
42+
// not affect already existing HardStreaks, to explicitly change those configurations, you call these events
43+
44+
// update the configuration of a specific HardStreak, silently ignore config parsing errors
45+
new EventListener(+[](HardStreak* streak, matjson::Value config) {
46+
Result<std::vector<utilities::Part>> newConfigResult = config.as<std::vector<utilities::Part>>();
47+
if (newConfigResult.isOk()) static_cast<HookedHardStreak*>(streak)->setConfiguration(*newConfigResult);
48+
return ListenerResult::Stop;
49+
}, UpdateConfigurationFilter("update-configuration"_spr));
50+
51+
// update the configuration of a specific HardStreak, put config parsing errors into second argument
52+
new EventListener(+[](HardStreak* streak, matjson::Value config, std::optional<std::string>* error) {
53+
Result<std::vector<utilities::Part>> newConfigResult = config.as<std::vector<utilities::Part>>();
54+
if (newConfigResult.isOk()) static_cast<HookedHardStreak*>(streak)->setConfiguration(*newConfigResult);
55+
*error = newConfigResult.err();
56+
return ListenerResult::Stop;
57+
}, UpdateConfigurationFilterResult("update-configuration"_spr));
58+
59+
};
60+

src/debug-windows.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <Geode/Geode.hpp>
2+
using namespace geode::prelude;
3+
4+
inline Result<> withProtectedMemory(void* address, size_t size, auto&& callback) {
5+
DWORD oldProtect;
6+
7+
if (VirtualProtect(address, size, PAGE_READWRITE, &oldProtect)) {
8+
callback(address);
9+
VirtualProtect(address, size, oldProtect, &oldProtect);
10+
} else
11+
return Err(fmt::format("Failed to set memory protection: {}", GetLastError()));
12+
13+
return Ok();
14+
}
15+
16+
void inlHook(uintptr_t target, uintptr_t detour) {
17+
auto array = std::to_array<uint8_t>({
18+
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp [rip+0]
19+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // address
20+
});
21+
22+
std::memcpy(array.data() + 6, &detour, sizeof(uintptr_t));
23+
24+
auto res = withProtectedMemory(
25+
reinterpret_cast<void*>(target),
26+
array.size(),
27+
[&](void* mem){std::memcpy(mem, array.data(), array.size());}
28+
);
29+
30+
if (!res) log::error("{}", res.unwrapErr());
31+
32+
}
33+
$execute {
34+
inlHook(reinterpret_cast<uintptr_t>(&malloc), reinterpret_cast<uintptr_t>(&_malloc_base));
35+
inlHook(reinterpret_cast<uintptr_t>(&calloc), reinterpret_cast<uintptr_t>(&_calloc_base));
36+
inlHook(reinterpret_cast<uintptr_t>(&realloc), reinterpret_cast<uintptr_t>(&_realloc_base));
37+
inlHook(reinterpret_cast<uintptr_t>(&free), reinterpret_cast<uintptr_t>(&_free_base));
38+
}

0 commit comments

Comments
 (0)