blob: 4238fccf9f2dc8dcbfd433febfd8a611d5034912 (
plain)
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
|
#include <libultraship.h>
#include "Engine.h"
#include "fast/resource/type/DisplayList.h"
#include "fast/resource/ResourceType.h"
#include "resource/type/ResourceType.h"
#include "resource/type/Array.h"
extern "C" {
#include <align_asset_macro.h>
}
extern "C" void gSPDisplayList(Gfx* pkt, Gfx* dl) {
char* imgData = (char*) dl;
if (GameEngine_OTRSigCheck(imgData)) {
auto resource = Ship::Context::GetRawInstance()->GetResourceManager()->LoadResource(imgData);
auto res = std::static_pointer_cast<Fast::DisplayList>(resource);
dl = &res->Instructions[0];
}
__gSPDisplayList(pkt, dl);
}
extern "C" void gSPVertex(Gfx* pkt, uintptr_t v, int n, int v0) {
if (GameEngine_OTRSigCheck((char*) v)) {
v = (uintptr_t) ResourceGetDataByName((char*) v);
}
__gSPVertex(pkt, v, n, v0);
}
extern "C" void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr) {
#ifdef __SWITCH__
// TODO: This kills performance on the Switch, we need to limit the amount of times we call this
return;
#endif
auto data = reinterpret_cast<char*>(texAddr);
if (texAddr != 0 && GameEngine_OTRSigCheck(data)) {
const auto res = Ship::Context::GetRawInstance()->GetResourceManager()->LoadResource(data);
const auto type = static_cast<Fast::ResourceType>(res->GetInitData()->Type);
if (res->GetInitData()->Type == static_cast<uint32_t>(Fast::ResourceType::DisplayList)) {
texAddr = reinterpret_cast<uintptr_t>(&std::static_pointer_cast<Fast::DisplayList>(res)->Instructions[0]);
} else if (res->GetInitData()->Type == static_cast<uint32_t>(MK64::ResourceType::MK_Array)) {
texAddr = reinterpret_cast<uintptr_t>(std::static_pointer_cast<MK64::Array>(res)->Vertices.data());
} else {
texAddr = reinterpret_cast<uintptr_t>(res->GetRawPointer());
}
}
__gSPInvalidateTexCache(pkt, texAddr);
}
|