1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#include "DisplayListOverrides.h"
#include "utils/Decompressor.h"
#include "utils/TorchUtils.h"
#include "DisplayListFactory.h"
#include "spdlog/spdlog.h"
#include "Companion.h"
#include <string>
#ifdef STANDALONE
#include <gfxd.h>
#endif
namespace GFXDOverride {
std::unordered_map<uint32_t, std::tuple<std::string, YAML::Node>> mVtxOverlaps;
#ifdef STANDALONE
void Triangle2(const N64Gfx* gfx) {
auto w0 = gfx->words.w0;
auto w1 = gfx->words.w1;
auto v1 = std::to_string(((w0 >> 16) & 0xFF) / 2);
auto v2 = std::to_string(((w0 >> 8) & 0xFF) / 2);
auto v3 = std::to_string((w0 & 0xFF) / 2);
auto v4 = std::to_string(((w1 >> 16) & 0xFF) / 2);
auto v5 = std::to_string(((w1 >> 8) & 0xFF) / 2);
auto v6 = std::to_string((w1 & 0xFF) / 2);
auto flag = "0";
const auto str = v1 + ", " + v2 + ", " + v3 + ", " + flag + ", " + v4 + ", " + v5 + ", " + v6 + ", " + flag;
gfxd_puts("gsSP2Triangles(");
gfxd_puts(str.c_str());
gfxd_puts(")");
}
void Quadrangle(const N64Gfx* gfx) {
auto w1 = gfx->words.w1;
auto v1 = std::to_string(((w1 >> 16) & 0xFF) / 2);
auto v2 = std::to_string(((w1 >> 8) & 0xFF) / 2);
auto v3 = std::to_string((w1 & 0xFF) / 2);
auto v4 = std::to_string(((w1 >> 24) & 0xFF) / 2);
auto flag = "0";
const auto str = v1 + ", " + v2 + ", " + v3 + ", " + v4 + ", " + flag;
gfxd_puts("gsSP1Quadrangle(");
gfxd_puts(str.c_str());
gfxd_puts(")");
}
int Vtx(uint32_t ptr, int32_t num) {
ptr = Companion::Instance->PatchVirtualAddr(ptr);
auto vtx = GetVtxOverlap(ptr);
if (vtx.has_value()) {
auto symbol = std::get<0>(vtx.value());
auto node = std::get<1>(vtx.value());
auto offset = GetSafeNode<uint32_t>(node, "offset");
auto count = GetSafeNode<uint32_t>(node, "count");
auto idx = (ptr - offset) / sizeof(N64Vtx_t);
SPDLOG_INFO("Replaced Vtx Overlapped: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts("&");
gfxd_puts(symbol.c_str());
gfxd_puts("[");
gfxd_puts(std::to_string(idx).c_str());
gfxd_puts("]");
return 1;
}
if (IS_SEGMENTED(ptr) && Companion::Instance->GetCompressedSegmentOffset(&ptr)) {
vtx = GetVtxOverlap(ptr);
if (vtx.has_value()) {
auto symbol = std::get<0>(vtx.value());
auto node = std::get<1>(vtx.value());
auto offset = GetSafeNode<uint32_t>(node, "offset");
auto count = GetSafeNode<uint32_t>(node, "count");
auto idx = (ptr - offset) / sizeof(N64Vtx_t);
SPDLOG_INFO("Replaced Vtx Overlapped: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts("&");
gfxd_puts(symbol.c_str());
gfxd_puts("[");
gfxd_puts(std::to_string(idx).c_str());
gfxd_puts("]");
return 1;
}
}
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "VTX");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Vtx: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(symbol.c_str());
return 1;
}
SPDLOG_WARN("Could not find vtx at 0x{:X}", ptr);
return 0;
}
int Texture(uint32_t ptr, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "TEXTURE");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Texture: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(symbol.c_str());
return 1;
}
SPDLOG_WARN("Could not find texture at 0x{:X}", ptr);
return 0;
}
int Palette(uint32_t ptr, int32_t idx, int32_t count) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "TEXTURE");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found TLUT: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(symbol.c_str());
return 1;
}
SPDLOG_WARN("Could not find tlut at 0x{:X}", ptr);
return 0;
}
int Lights(uint32_t ptr, int32_t count) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "LIGHTS");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Lightsn: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(symbol.c_str());
return 1;
}
SPDLOG_WARN("Could not find lights at 0x{:X}", ptr);
return 0;
}
int Light(uint32_t ptr) {
auto res = Companion::Instance->GetSafeNodeByAddr(ptr, "LIGHTS");
if (res.has_value()) {
auto node = std::get<1>(res.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Light A Ptr: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(("&" + symbol + ".a").c_str());
return 1;
}
res = Companion::Instance->GetSafeNodeByAddr(ptr - 0x8, "LIGHTS");
if (res.has_value()) {
auto node = std::get<1>(res.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Light L Ptr: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(("&" + symbol + ".l").c_str());
return 1;
}
SPDLOG_WARN("Could not find light at 0x{:X}", ptr);
return 0;
}
int DisplayList(uint32_t ptr) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "GFX");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Display List: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(symbol.c_str());
return 1;
}
SPDLOG_WARN("Could not find display list to override at 0x{:X}", ptr);
return 0;
}
int Viewport(uint32_t ptr) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "VP");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Viewport: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(("&" + symbol).c_str());
return 1;
}
SPDLOG_TRACE("Could not find viewport to override at 0x{:X}", ptr);
return 0;
}
int Matrix(uint32_t ptr) {
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "MTX");
if (dec.has_value()) {
auto node = std::get<1>(dec.value());
auto symbol = GetSafeNode<std::string>(node, "symbol");
SPDLOG_INFO("Found Matrix: 0x{:X} Symbol: {}", ptr, symbol);
gfxd_puts(("&" + symbol).c_str());
return 1;
}
SPDLOG_TRACE("Could not find viewport to override at 0x{:X}", ptr);
return 0;
}
#endif
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr) {
if (Torch::contains(mVtxOverlaps, ptr)) {
SPDLOG_INFO("Found overlap for ptr 0x{:X}", ptr);
return mVtxOverlaps[ptr];
}
SPDLOG_TRACE("Failed to find overlap for ptr 0x{:X}", ptr);
return std::nullopt;
}
void RegisterVTXOverlap(uint32_t ptr, std::tuple<std::string, YAML::Node>& vtx) {
mVtxOverlaps[ptr] = vtx;
SPDLOG_INFO("Register overlap for ptr 0x{:X}", ptr);
}
void ClearVtx() {
mVtxOverlaps.clear();
}
} // namespace GFXDOverride
|