Skip to content

Commit

Permalink
Improve some code and stop vibration outside of the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Apr 13, 2020
1 parent ef4b148 commit f2c0404
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
41 changes: 22 additions & 19 deletions Core/CwCheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ std::string gameTitle;
std::string activeCheatFile;
static CWCheatEngine *cheatEngine;
static bool cheatsEnabled;
SceCtrl vibrationCheat;
using namespace SceCtrl;

void hleCheat(u64 userdata, int cyclesLate);

static inline std::string TrimString(const std::string &s) {
Expand Down Expand Up @@ -440,10 +441,6 @@ struct CheatOperation {
uint32_t addr;
int sz;
uint32_t val;
uint16_t vibrL;
uint16_t vibrR;
uint8_t vibrLTime;
uint8_t vibrRTime;

union {
struct {
Expand All @@ -467,6 +464,12 @@ struct CheatOperation {
int count;
int type;
} pointerCommands;
struct {
uint16_t vibrL;
uint16_t vibrR;
uint8_t vibrLTime;
uint8_t vibrRTime;
} vibrationValues;
};
};

Expand Down Expand Up @@ -605,10 +608,10 @@ CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_
return { CheatOp::VibrationFromMemory, addr };
} else { // 0xA0 sets vibration by cheat parameters
CheatOperation op = { CheatOp::Vibration };
op.vibrL = line1.part1 & 0x0000FFFF;
op.vibrR = line1.part2 & 0x0000FFFF;
op.vibrLTime = (line1.part1 >> 16) & 0x000000FF;
op.vibrRTime = (line1.part2 >> 16) & 0x000000FF;
op.vibrationValues.vibrL = line1.part1 & 0x0000FFFF;
op.vibrationValues.vibrR = line1.part2 & 0x0000FFFF;
op.vibrationValues.vibrLTime = (line1.part1 >> 16) & 0x000000FF;
op.vibrationValues.vibrRTime = (line1.part2 >> 16) & 0x000000FF;
return op;
}
return { CheatOp::Invalid };
Expand Down Expand Up @@ -882,13 +885,13 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat,
break;

case CheatOp::Vibration:
if (op.vibrL > 0) {
vibrationCheat.SetLeftVibration(op.vibrL);
vibrationCheat.SetVibrationLeftDropout(op.vibrLTime);
if (op.vibrationValues.vibrL > 0) {
SetLeftVibration(op.vibrationValues.vibrL);
SetVibrationLeftDropout(op.vibrationValues.vibrLTime);
}
if (op.vibrR > 0) {
vibrationCheat.SetRightVibration(op.vibrR);
vibrationCheat.SetVibrationRightDropout(op.vibrRTime);
if (op.vibrationValues.vibrR > 0) {
SetRightVibration(op.vibrationValues.vibrR);
SetVibrationRightDropout(op.vibrationValues.vibrRTime);
}
break;

Expand All @@ -897,12 +900,12 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat,
uint16_t checkLeftVibration = Memory::Read_U16(op.addr);
uint16_t checkRightVibration = Memory::Read_U16(op.addr + 0x2);
if (checkLeftVibration > 0) {
vibrationCheat.SetLeftVibration(checkLeftVibration);
vibrationCheat.SetVibrationLeftDropout(Memory::Read_U8(op.addr + 0x4));
SetLeftVibration(checkLeftVibration);
SetVibrationLeftDropout(Memory::Read_U8(op.addr + 0x4));
}
if (checkRightVibration > 0) {
vibrationCheat.SetRightVibration(checkRightVibration);
vibrationCheat.SetVibrationRightDropout(Memory::Read_U8(op.addr + 0x6));
SetRightVibration(checkRightVibration);
SetVibrationRightDropout(Memory::Read_U8(op.addr + 0x6));
}
}
break;
Expand Down
28 changes: 15 additions & 13 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,24 +574,26 @@ void Register_sceCtrl_driver()
RegisterModule("sceCtrl_driver", ARRAY_SIZE(sceCtrl), sceCtrl);
}

u16 GetRightVibration() {
u16 sceCtrlGetRightVibration() {
return rightVibration;
}

u16 GetLeftVibration() {
u16 sceCtrlGetLeftVibration() {
return leftVibration;
}

void SceCtrl::SetRightVibration(u16 rVibration) {
rightVibration = rVibration;
}
void SceCtrl::SetLeftVibration(u16 lVibration) {
leftVibration = lVibration;
}
void SceCtrl::SetVibrationRightDropout(u8 vibrationRDropout) {
vibrationRightDropout = vibrationRDropout;
namespace SceCtrl {
void SetRightVibration(u16 rVibration) {
rightVibration = rVibration;
}
void SetLeftVibration(u16 lVibration) {
leftVibration = lVibration;
}
void SetVibrationRightDropout(u8 vibrationRDropout) {
vibrationRightDropout = vibrationRDropout;

}
void SceCtrl::SetVibrationLeftDropout(u8 vibrationLDropout) {
vibrationLeftDropout = vibrationLDropout;
}
void SetVibrationLeftDropout(u8 vibrationLDropout) {
vibrationLeftDropout = vibrationLDropout;
}
}
7 changes: 3 additions & 4 deletions Core/HLE/sceCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ u32 __CtrlReadLatch();

void Register_sceCtrl_driver();

u16 GetRightVibration();
u16 GetLeftVibration();
u16 sceCtrlGetRightVibration();
u16 sceCtrlGetLeftVibration();

class SceCtrl {
public:
namespace SceCtrl {
void SetLeftVibration(u16 lVibration);
void SetRightVibration(u16 rVibration);
void SetVibrationLeftDropout(u8 vibrationLDropout);
Expand Down
10 changes: 8 additions & 2 deletions Windows/XinputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,14 @@ void XinputDevice::ApplyButtons(int pad, const XINPUT_STATE &state) {

void XinputDevice::ApplyVibration(int pad, XINPUT_VIBRATION &vibration) {
if (PSP_IsInited()) {
vibration.wLeftMotorSpeed = GetLeftVibration(); // use any value between 0-65535 here
vibration.wRightMotorSpeed = GetRightVibration(); // use any value between 0-65535 here
if (GetUIState() == UISTATE_INGAME) {
vibration.wLeftMotorSpeed = sceCtrlGetLeftVibration(); // use any value between 0-65535 here
vibration.wRightMotorSpeed = sceCtrlGetRightVibration(); // use any value between 0-65535 here
} else {
vibration.wLeftMotorSpeed = 0;
vibration.wRightMotorSpeed = 0;
}

if (prevVibration[pad].wLeftMotorSpeed != vibration.wLeftMotorSpeed || prevVibration[pad].wRightMotorSpeed != vibration.wRightMotorSpeed) {
PPSSPP_XInputSetState(pad, &vibration);
prevVibration[pad] = vibration;
Expand Down

0 comments on commit f2c0404

Please sign in to comment.