1+ #include " cemu_hooks.h"
2+
3+ bool shouldAdjustArrowTarget = false ;
4+
5+ void CemuHooks::hook_LoadDynamicBool (PPCInterpreter_t* hCPU) {
6+ hCPU->instructionPointer = hCPU->sprNew .LR ;
7+ hCPU->sprNew .LR = hCPU->gpr [0 ];
8+
9+ InlineParamBool boolParam;
10+ readMemory (hCPU->gpr [30 ], &boolParam);
11+
12+ const char * paramString = (char *)(boolParam.keyPtr .getLE () + s_memoryBaseAddress);
13+ Log::print<PPC>(" [{:08X}] Loaded dynamic bool parameter for {}: {}" , hCPU->gpr [0 ], paramString, boolParam.value .getLE ());
14+
15+ if (std::string (paramString) == " IsShootByPlayer" && boolParam.value .getLE () == 1 ) {
16+ Log::print<PPC>(" Arrow is being shot by the player!" );
17+ shouldAdjustArrowTarget = true ;
18+ }
19+ }
20+
21+ void CemuHooks::hook_LoadDynamicVec3 (PPCInterpreter_t* hCPU) {
22+ hCPU->instructionPointer = 0x030EC844 ;
23+
24+ InlineParamVec3 vec3Param;
25+ readMemory (hCPU->gpr [31 ], &vec3Param);
26+
27+ // get LR from stack, using lwz r0, 0x1C(r1)
28+ BEType<uint32_t > addr;
29+ readMemory (hCPU->gpr [1 ] + 0x1C , &addr);
30+
31+ // we overwrote the .z setting instruction with the jump, so run the original code
32+ vec3Param.value .z = hCPU->fpr [0 ].fp0 ;
33+ writeMemory (hCPU->gpr [31 ], &vec3Param);
34+
35+ // // now hook the value if needed
36+ // const char* paramString = (char*)(vec3Param.keyPtr.getLE() + s_memoryBaseAddress);
37+ // Log::print<PPC>("[{:08X}] Original velocity parameter for {}: {}", addr.getLE(), paramString, vec3Param.value);
38+
39+ // only hook the arrow target position for now
40+ // if (std::string(paramString) == "TargetPos" && shouldAdjustArrowTarget) {
41+ // //Log::print<INFO>("Original target: {}", vec3Param.value.getLE());
42+ // s_lastScreenAimOriginalTarget = vec3Param.value.getLE();
43+ // s_lastScreenAimValid = false;
44+ // }
45+
46+ // velocityParam.value = glm::fvec3(0.0f, 0.0f, 0.0f);
47+ }
48+
49+ void CemuHooks::hook_SetRigidBodyVelocity (PPCInterpreter_t* hCPU) {
50+ hCPU->instructionPointer = 0x03489710 ;
51+ hCPU->gpr [0 ] = hCPU->sprNew .LR ;
52+ uint32_t lr = hCPU->sprNew .LR ;
53+
54+ // uint32_t rigidBodyAddr = hCPU->gpr[3];
55+ // BEVec3 velocity;
56+ // readMemory(hCPU->gpr[4], &velocity);
57+ // double timeDeltaMaybe = hCPU->fpr[1].fp0;
58+
59+ // float debugLineLength = glm::max(s_lastScreenAimDistance, 10.0f);
60+ // if (s_lastGameplayAimValid) {
61+ // DebugDraw::instance().Line(s_lastGameplayAimOrigin, s_lastGameplayAimOrigin + (s_lastGameplayAimDirection * debugLineLength), IM_COL32(0, 255, 255, 255), 2.0f);
62+ // }
63+ // if (s_lastRenderAimValid) {
64+ // DebugDraw::instance().Line(s_lastRenderAimOrigin, s_lastRenderAimOrigin + (s_lastRenderAimDirection * debugLineLength), IM_COL32(255, 0, 255, 255), 2.0f);
65+ // }
66+ // if (s_lastScreenAimValid) {
67+ // DebugDraw::instance().Line(s_lastScreenAimOrigin, s_lastScreenAimAdjustedTarget, IM_COL32(255, 255, 0, 255), 2.0f);
68+ // DebugDraw::instance().Line(s_lastScreenAimOriginalTarget, s_lastScreenAimOriginalTarget + glm::fvec3(0.0f, 0.5f, 0.0f), IM_COL32(255, 64, 64, 255), 1.0f);
69+ // DebugDraw::instance().Line(s_lastScreenAimAdjustedTarget, s_lastScreenAimAdjustedTarget + glm::fvec3(0.0f, 0.5f, 0.0f), IM_COL32(64, 255, 64, 255), 1.0f);
70+ // }
71+ //
72+
73+ // if (lr == 0x020E735C) {
74+ // Log::print<PPC>("[{:08X}] Set rigid body velocity of {:08X}: {} (timeDeltaMaybe = {})", hCPU->sprNew.LR, rigidBodyAddr, velocity, timeDeltaMaybe);
75+ // //velocity = glm::fvec3(0.0f, 0.0f, 0.0f);
76+ // //velocity.x = 0.0f;
77+ // writeMemory(hCPU->gpr[4], &velocity);
78+ // }
79+ }
80+
81+ void CemuHooks::hook_SetRigidBodyTransform (PPCInterpreter_t* hCPU) {
82+ hCPU->instructionPointer = 0x03486CD8 ;
83+ hCPU->gpr [0 ] = hCPU->sprNew .LR ;
84+ uint32_t lr = hCPU->sprNew .LR ;
85+
86+ // uint32_t rigidBodyAddr = hCPU->gpr[3];
87+ // BEMatrix34 transform;
88+ // readMemory(hCPU->gpr[4], &transform);
89+
90+ // DebugDraw::instance().Dot(transform.getPos().getLE(), 5.0f, IM_COL32(0, 0, 255, 255));
91+ //
92+ // Log::print<INFO>("[{:08X}] Set rigid body transform of {:08X}: pos = {}, rot = {}", lr, rigidBodyAddr, transform.getPos().getLE(), transform.getRotLE());
93+
94+ // if (lr == 0x020E3D0C || lr == 0x02C19A18) {
95+ // shouldAdjustArrowTarget = false;
96+
97+ // glm::fvec3 originalPos = transform.getPos().getLE();
98+ // glm::fquat originalRot = transform.getRotLE();
99+ // Log::print<INFO>("[ARROW TRANSFORM] Original pos = {}, rot = {}", originalPos, originalRot);
100+
101+ // auto renderer = VRManager::instance().XR->GetRenderer();
102+ // if (renderer != nullptr) {
103+ // auto rightPoseOpt = renderer->GetPose(EyeSide::RIGHT);
104+ // if (rightPoseOpt.has_value()) {
105+ // glm::fvec3 headsetPos = ToGLM(rightPoseOpt->position);
106+ // glm::fquat headsetRot = ToGLM(rightPoseOpt->orientation);
107+
108+ // auto [swing, baseYaw] = swingTwistY(s_wsCameraRotation);
109+ // glm::fvec3 headsetPosNoHeight = headsetPos;
110+ // //headsetPosNoHeight.y = 0.0f;
111+ // glm::fvec3 aimOrigin = s_wsCameraPosition + (baseYaw * headsetPosNoHeight);
112+ // glm::fquat aimRotation = baseYaw * headsetRot;
113+ // glm::fvec3 aimDirection = glm::normalize(aimRotation * glm::fvec3(0.0f, 0.0f, -1.0f));
114+
115+ // transform.setPos(aimOrigin);
116+ // transform.setRotLE(aimRotation);
117+ // //writeMemory(hCPU->gpr[4], &transform);
118+
119+ // s_lastScreenAimOrigin = aimOrigin;
120+ // s_lastScreenAimAdjustedTarget = aimOrigin + (aimDirection * s_lastScreenAimDistance);
121+ // s_lastScreenAimValid = true;
122+
123+ // Log::print<INFO>("[Arrow Stuff] New pos = {}, rot = {}, aimDir = {}", aimOrigin, aimRotation, aimDirection);
124+ // }
125+ // }
126+ // }
127+ }
128+
129+ void CemuHooks::hook_SetRigidBodyPosition (PPCInterpreter_t* hCPU) {
130+ hCPU->instructionPointer = 0x03486D84 ;
131+ hCPU->gpr [0 ] = hCPU->sprNew .LR ;
132+
133+ // uint32_t lr = hCPU->sprNew.LR;
134+ // uint32_t rigidBodyAddr = hCPU->gpr[3];
135+ // BEVec3 position;
136+ // readMemory(hCPU->gpr[4], &position);
137+ // //Log::print<INFO>("[{:08X}] Set rigid body position of {:08X}: pos = {}", lr, rigidBodyAddr, position);
138+
139+ // DebugDraw::instance().Dot(position.getLE(), 5.0f, IM_COL32(255, 0, 0, 255));
140+ }
141+
142+ void CemuHooks::hook_SetRigidBodyPositionAndRotation (PPCInterpreter_t* hCPU) {
143+ hCPU->instructionPointer = 0x03489A84 ;
144+ hCPU->gpr [11 ] = hCPU->gpr [1 ];
145+
146+ // uint32_t lr = hCPU->sprNew.LR;
147+ // uint32_t rigidBodyAddr = hCPU->gpr[3];
148+ // BEMatrix34 transform;
149+ // readMemory(hCPU->gpr[4], &transform);
150+
151+ // DebugDraw::instance().Dot(transform.getPos().getLE(), 5.0f, IM_COL32(255, 255, 0, 255));
152+ // Log::print<INFO>("[{:08X}] Set rigid body position and rotation of {:08X}: pos = {}, rotation = {}", lr, rigidBodyAddr, transform.getPos().getLE(), transform.getRotLE());
153+ }
154+
155+ void CemuHooks::hook_SetRigidBodyRotation (PPCInterpreter_t* hCPU) {
156+ hCPU->instructionPointer = 0x0348AB24 ;
157+ hCPU->gpr [0 ] = hCPU->sprNew .LR ;
158+
159+ // uint32_t lr = hCPU->sprNew.LR;
160+ // uint32_t rigidBodyAddr = hCPU->gpr[3];
161+ // BEMatrix34 transform;
162+ // readMemory(hCPU->gpr[4], &transform);
163+
164+ // Log::print<INFO>("[{:08X}] Set rigid body rotation of {:08X}: rotation = {}", lr, rigidBodyAddr, transform.getRotLE());
165+ }
0 commit comments