mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-16 12:24:45 -04:00
Merge branch 'main' of ssh://github.com/TwilitRealm/dusklight into jpn
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
#include "Z2AudioLib/Z2Audience.h"
|
||||
#include "Z2AudioLib/Z2SoundInfo.h"
|
||||
#if TARGET_PC
|
||||
#include "dusk/audio/DuskDsp.hpp"
|
||||
#include "dusk/settings.h"
|
||||
#include <cmath>
|
||||
#endif
|
||||
#include "Z2AudioLib/Z2Calc.h"
|
||||
#include "Z2AudioLib/Z2Param.h"
|
||||
#include "JSystem/JAudio2/JAISound.h"
|
||||
@@ -701,6 +706,11 @@ f32 Z2Audience::calcRelPosVolume(const Vec& param_0, f32 param_1, int camID) {
|
||||
f32 Z2Audience::calcRelPosPan(const Vec& param_0, int camID) {
|
||||
Vec local_54 = param_0;
|
||||
local_54.y = 0.0f;
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
local_54.x = -local_54.x;
|
||||
}
|
||||
#endif
|
||||
|
||||
f32 dVar6 = VECMag(&local_54);
|
||||
if (dVar6 < 0.1f) {
|
||||
@@ -734,9 +744,22 @@ f32 Z2Audience::calcRelPosPan(const Vec& param_0, int camID) {
|
||||
|
||||
f32 Z2Audience::calcRelPosDolby(const Vec& param_0, int camID) {
|
||||
f32 fVar1 = param_0.z + mAudioCamera[camID].getDolbyCenterZ();
|
||||
#if TARGET_PC
|
||||
if (dusk::audio::EnableHrtf) {
|
||||
// Normalize the direction so result is purely front/back orientation,
|
||||
// independent of how far away the sound is
|
||||
f32 lenSq = param_0.x * param_0.x + param_0.y * param_0.y + param_0.z * param_0.z;
|
||||
if (lenSq < 0.0001f) {
|
||||
return 0.5f;
|
||||
}
|
||||
f32 zNorm = param_0.z / sqrtf(lenSq);
|
||||
f32 t = (zNorm + 1.0f) * 0.5f;
|
||||
return 0.5f - 0.5f * cosf(t * static_cast<f32>(M_PI));
|
||||
}
|
||||
#endif
|
||||
if (fVar1 > mSetting.field_0x48) {
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (fVar1 < mSetting.field_0x44) {
|
||||
return 0.0f;
|
||||
|
||||
+87
-15
@@ -51,9 +51,13 @@
|
||||
#include "d/actor/d_a_ni.h"
|
||||
#include "d/d_s_play.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/action_bindings.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
#include "res/Object/Alink.h"
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
static int daAlink_Create(fopAc_ac_c* i_this);
|
||||
static int daAlink_Delete(daAlink_c* i_this);
|
||||
@@ -4962,13 +4966,16 @@ int daAlink_c::create() {
|
||||
|
||||
setArcName(checkWolf());
|
||||
setOriginalHeap(&mpArcHeap, 0xA2800);
|
||||
JKRHEAP_NAME(mpArcHeap, "Alink ArcHeap");
|
||||
if (dComIfG_resLoad(&mPhaseReq, mArcName, mpArcHeap) != cPhs_COMPLEATE_e) {
|
||||
return cPhs_INIT_e;
|
||||
}
|
||||
|
||||
setShieldArcName();
|
||||
setOriginalHeap(&mpShieldArcHeap, 0x7000);
|
||||
if (dComIfG_resLoad(&mShieldPhaseReq, mShieldArcName, mpShieldArcHeap) != cPhs_COMPLEATE_e) {
|
||||
JKRHEAP_NAME(mpShieldArcHeap, "Alink ShieldArcHeap");
|
||||
if (dComIfG_resLoad(&mShieldPhaseReq, mShieldArcName, mpShieldArcHeap) != cPhs_COMPLEATE_e)
|
||||
{
|
||||
return cPhs_INIT_e;
|
||||
}
|
||||
|
||||
@@ -7555,12 +7562,7 @@ void daAlink_c::setBlendMoveAnime(f32 i_morf) {
|
||||
f32 sp2C;
|
||||
f32 sp28 = mpHIO->mMove.m.mFootPositionRatio;
|
||||
BOOL sp24 = checkEventRun();
|
||||
BOOL sp20 = checkBootsMoveAnime(1);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFastIronBoots) {
|
||||
sp20 = FALSE;
|
||||
}
|
||||
#endif
|
||||
BOOL sp20 = checkBootsMoveAnime(1) IF_DUSK(&& !dusk::getSettings().game.enableFastIronBoots);
|
||||
|
||||
f32 var_f29;
|
||||
|
||||
@@ -8073,7 +8075,7 @@ void daAlink_c::setBlendAtnBackMoveAnime(f32 i_morf) {
|
||||
daAlink_ANM var_r27;
|
||||
daAlink_ANM var_r29;
|
||||
|
||||
if (checkBootsMoveAnime(1)) {
|
||||
if (checkBootsMoveAnime(1) IF_DUSK(&& !dusk::getSettings().game.enableFastIronBoots)) {
|
||||
mMaxSpeed = mpHIO->mAtnMove.m.mMaxBackwardsSpeed;
|
||||
var_f27 = mpHIO->mAtnMove.m.mMinBackWalkFrame;
|
||||
var_f31 = mpHIO->mAtnMove.m.mBackWalkChangeRate;
|
||||
@@ -9359,6 +9361,12 @@ BOOL daAlink_c::spActionTrigger() {
|
||||
}
|
||||
|
||||
BOOL daAlink_c::midnaTalkTrigger() const {
|
||||
#if TARGET_PC
|
||||
// If we have a custom bind for Midna, check that instead
|
||||
if (dusk::isActionBound(dusk::ActionBinds::CALL_MIDNA, 0)) {
|
||||
return dusk::getActionBindTrig(dusk::ActionBinds::CALL_MIDNA, 0);
|
||||
}
|
||||
#endif
|
||||
return mItemTrigger & BTN_Z;
|
||||
}
|
||||
|
||||
@@ -14784,6 +14792,10 @@ void daAlink_c::deleteEquipItem(BOOL i_isPlaySound, BOOL i_isDeleteKantera) {
|
||||
mIronBallChainPos = NULL;
|
||||
mIronBallChainAngle = NULL;
|
||||
field_0x3848 = NULL;
|
||||
#if TARGET_PC
|
||||
mIBChainInterpPrevValid = false;
|
||||
mIBChainInterpCurrValid = false;
|
||||
#endif
|
||||
field_0x0774 = NULL;
|
||||
field_0x0778 = NULL;
|
||||
mpHookshotLinChk = NULL;
|
||||
@@ -16106,6 +16118,9 @@ int daAlink_c::procSlideLand() {
|
||||
|
||||
int daAlink_c::procFrontRollInit() {
|
||||
BOOL is_guard_anime = checkUpperGuardAnime();
|
||||
#ifdef TARGET_PC
|
||||
const f32 fastRollMultiplier = dusk::getSettings().game.fastRoll ? 2.0f : 1.0f;
|
||||
#endif
|
||||
|
||||
if (mProcID == PROC_FRONT_ROLL && mDemo.getDemoMode() == daPy_demo_c::DEMO_FRONT_ROLL_e) {
|
||||
return 0;
|
||||
@@ -16121,10 +16136,16 @@ int daAlink_c::procFrontRollInit() {
|
||||
roll_anm_speed = mpHIO->mFrontRoll.m.mRollAnm.mStartFrame;
|
||||
}
|
||||
|
||||
setSingleAnime(ANM_FRONT_ROLL, mpHIO->mFrontRoll.m.mRollAnm.mSpeed, roll_anm_speed,
|
||||
setSingleAnime(ANM_FRONT_ROLL,
|
||||
#ifdef TARGET_PC
|
||||
mpHIO->mFrontRoll.m.mRollAnm.mSpeed * fastRollMultiplier,
|
||||
#else
|
||||
mpHIO->mFrontRoll.m.mRollAnm.mSpeed,
|
||||
#endif
|
||||
roll_anm_speed,
|
||||
mpHIO->mFrontRoll.m.mRollAnm.mEndFrame,
|
||||
mpHIO->mFrontRoll.m.mRollAnm.mInterpolation);
|
||||
|
||||
|
||||
mNormalSpeed = speedF * mpHIO->mFrontRoll.m.mSpeedRate + mpHIO->mFrontRoll.m.mInitSpeed;
|
||||
|
||||
f32 max_speed = mpHIO->mFrontRoll.m.mInitSpeed + mpHIO->mMove.m.mMaxSpeed * mpHIO->mFrontRoll.m.mSpeedRate;
|
||||
@@ -16137,11 +16158,20 @@ int daAlink_c::procFrontRollInit() {
|
||||
}
|
||||
|
||||
if (checkNoResetFlg0(FLG0_WATER_IN_MOVE)) {
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
#if TARGET_PC
|
||||
if (!(dusk::getSettings().game.enableFastIronBoots))
|
||||
#endif
|
||||
{
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
}
|
||||
} else if (checkHeavyStateOn(TRUE, TRUE)) {
|
||||
mNormalSpeed *= mHeavySpeedMultiplier;
|
||||
}
|
||||
|
||||
#ifdef TARGET_PC
|
||||
mNormalSpeed *= fastRollMultiplier;
|
||||
#endif
|
||||
|
||||
current.angle.y = shape_angle.y;
|
||||
voiceStart(Z2SE_AL_V_BACKTEN);
|
||||
mProcVar2.field_0x300c = 0;
|
||||
@@ -16272,8 +16302,13 @@ int daAlink_c::procFrontRollCrashInit() {
|
||||
speed.y = mpHIO->mFrontRoll.m.mCrashSpeedV;
|
||||
|
||||
if (checkNoResetFlg0(FLG0_WATER_IN_MOVE)) {
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
speed.y *= mpHIO->mItem.mIronBoots.m.mWaterVelocityY;
|
||||
#if TARGET_PC
|
||||
if (!(dusk::getSettings().game.enableFastIronBoots))
|
||||
#endif
|
||||
{
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
speed.y *= mpHIO->mItem.mIronBoots.m.mWaterVelocityY;
|
||||
}
|
||||
}
|
||||
|
||||
ANGLE_ADD_2(current.angle.y, 0x8000);
|
||||
@@ -16367,6 +16402,9 @@ int daAlink_c::procFrontRollSuccess() {
|
||||
|
||||
int daAlink_c::procSideRollInit(int param_0) {
|
||||
BOOL is_prev_guardAnm = checkUpperGuardAnime();
|
||||
#ifdef TARGET_PC
|
||||
const f32 fastRollMultiplier = dusk::getSettings().game.fastRoll ? 2.0f : 1.0f;
|
||||
#endif
|
||||
|
||||
if (!commonProcInitNotSameProc(PROC_SIDE_ROLL)) {
|
||||
return 0;
|
||||
@@ -16383,17 +16421,30 @@ int daAlink_c::procSideRollInit(int param_0) {
|
||||
current.angle.y = shape_angle.y + -0x4000;
|
||||
}
|
||||
|
||||
setSingleAnime(anmID, mpHIO->mGuard.mTurnMove.m.mSideRollAnmSpeed,
|
||||
setSingleAnime(anmID,
|
||||
#ifdef TARGET_PC
|
||||
mpHIO->mGuard.mTurnMove.m.mSideRollAnmSpeed * fastRollMultiplier,
|
||||
#else
|
||||
mpHIO->mGuard.mTurnMove.m.mSideRollAnmSpeed,
|
||||
#endif
|
||||
mpHIO->mGuard.mTurnMove.m.mTurnAnm.mStartFrame,
|
||||
mpHIO->mGuard.mTurnMove.m.mTurnAnm.mEndFrame,
|
||||
mpHIO->mGuard.mTurnMove.m.mTurnAnm.mInterpolation);
|
||||
mNormalSpeed = mpHIO->mGuard.mTurnMove.m.mSideRollSpeed;
|
||||
|
||||
if (checkNoResetFlg0(FLG0_WATER_IN_MOVE)) {
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
#if TARGET_PC
|
||||
if (!(dusk::getSettings().game.enableFastIronBoots))
|
||||
#endif
|
||||
{
|
||||
mNormalSpeed *= mpHIO->mItem.mIronBoots.m.mWaterVelocityX;
|
||||
}
|
||||
} else if (checkHeavyStateOn(TRUE, TRUE)) {
|
||||
mNormalSpeed *= mHeavySpeedMultiplier;
|
||||
}
|
||||
#ifdef TARGET_PC
|
||||
mNormalSpeed *= fastRollMultiplier;
|
||||
#endif
|
||||
|
||||
setFootEffectProcType(0);
|
||||
field_0x2f9d = 4;
|
||||
@@ -19714,6 +19765,27 @@ int daAlink_c::draw() {
|
||||
)
|
||||
{
|
||||
dComIfGd_getOpaListDark()->entryImm(mpHookChain, 0);
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation &&
|
||||
mEquipItem == dItemNo_IRONBALL_e &&
|
||||
mIronBallChainPos != NULL && mIronBallChainAngle != NULL)
|
||||
{
|
||||
if (mIBChainInterpCurrValid) {
|
||||
memcpy(mIBChainInterpPrevPos, mIBChainInterpCurrPos, IRON_BALL_CHAIN_COUNT * sizeof(cXyz));
|
||||
memcpy(mIBChainInterpPrevAngle, mIBChainInterpCurrAngle, IRON_BALL_CHAIN_COUNT * sizeof(csXyz));
|
||||
mIBChainInterpPrevHandRoot = mIBChainInterpCurrHandRoot;
|
||||
mIBChainInterpPrevValid = true;
|
||||
}
|
||||
|
||||
memcpy(mIBChainInterpCurrPos, mIronBallChainPos, IRON_BALL_CHAIN_COUNT * sizeof(cXyz));
|
||||
memcpy(mIBChainInterpCurrAngle, mIronBallChainAngle, IRON_BALL_CHAIN_COUNT * sizeof(csXyz));
|
||||
mIBChainInterpCurrHandRoot = mHookshotTopPos;
|
||||
mIBChainInterpCurrValid = true;
|
||||
|
||||
dusk::frame_interp::add_interpolation_callback(&ironBallChainInterpCallback, this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "d/actor/d_a_horse.h"
|
||||
#include "d/actor/d_a_crod.h"
|
||||
#include "d/d_msg_object.h"
|
||||
#ifdef TARGET_PC
|
||||
#include "d/actor/d_a_obj_carry.h"
|
||||
#include "dusk/achievements.h"
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
#include "d/d_s_menu.h"
|
||||
@@ -201,6 +205,9 @@ int daAlink_c::setDamagePoint(int i_dmgAmount, BOOL i_checkZoraMag, BOOL i_setDm
|
||||
dComIfGp_setItemLifeCount(-i_dmgAmount, 0);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
dusk::AchievementSystem::get().signal("player_damaged");
|
||||
#endif
|
||||
onResetFlg1(RFLG1_DAMAGE_IMPACT);
|
||||
mSwordUpTimer = 0;
|
||||
|
||||
@@ -677,6 +684,15 @@ BOOL daAlink_c::checkDamageAction() {
|
||||
}
|
||||
|
||||
setDamagePoint(dmg, at_mtrl == dCcD_MTRL_FIRE || at_mtrl == dCcD_MTRL_ICE, TRUE, 0);
|
||||
|
||||
#ifdef TARGET_PC
|
||||
if (tghit_ac_name == fpcNm_Obj_Carry_e) {
|
||||
auto* carry = static_cast<daObjCarry_c*>(tghit_ac);
|
||||
if (carry->prm_chk_type_ironball() && carry->checkCannon()) {
|
||||
dusk::AchievementSystem::get().signal("iron_ball_hit_player");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (armor_no_dmg && at_mtrl != dCcD_MTRL_ELECTRIC && at_mtrl != dCcD_MTRL_ICE) {
|
||||
setGuardSe(var_r29);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "dusk/imgui/ImGuiConsole.hpp"
|
||||
#include "dusk/settings.h"
|
||||
#include "dusk/speedrun.h"
|
||||
|
||||
BOOL daAlink_c::checkEventRun() const {
|
||||
return dComIfGp_event_runCheck() || checkPlayerDemoMode();
|
||||
|
||||
@@ -44,16 +44,14 @@ void daAlink_c::handleWolfHowl() {
|
||||
bool canHowl = false;
|
||||
|
||||
if (mLinkAcch.ChkGroundHit() && !checkModeFlg(MODE_PLAYER_FLY) && !checkMagneBootsOn()) {
|
||||
if (!checkForestOldCentury()) {
|
||||
if (checkMidnaRide()) {
|
||||
if ((checkWolf() &&
|
||||
(checkModeFlg(MODE_UNK_1000) || dComIfGp_checkPlayerStatus0(0, 0x10))) ||
|
||||
(!checkWolf() &&
|
||||
(checkEventRun() || getMidnaActor()->checkMetamorphoseEnable()) &&
|
||||
(checkModeFlg(4) || dComIfGp_checkPlayerStatus0(0, 0x10))))
|
||||
{
|
||||
canHowl = true;
|
||||
}
|
||||
if (checkMidnaRide()) {
|
||||
if ((checkWolf() &&
|
||||
(checkModeFlg(MODE_UNK_1000) || dComIfGp_checkPlayerStatus0(0, 0x10))) ||
|
||||
(!checkWolf() &&
|
||||
(checkEventRun() || getMidnaActor()->checkMetamorphoseEnable()) &&
|
||||
(checkModeFlg(4) || dComIfGp_checkPlayerStatus0(0, 0x10))))
|
||||
{
|
||||
canHowl = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,16 +122,14 @@ void daAlink_c::handleQuickTransform() {
|
||||
bool canTransform = false;
|
||||
|
||||
if (mLinkAcch.ChkGroundHit() && !checkModeFlg(MODE_PLAYER_FLY) && !checkMagneBootsOn()) {
|
||||
if (!checkForestOldCentury()) {
|
||||
if (checkMidnaRide()) {
|
||||
if ((checkWolf() &&
|
||||
(checkModeFlg(MODE_UNK_1000) || dComIfGp_checkPlayerStatus0(0, 0x10))) ||
|
||||
(!checkWolf() &&
|
||||
(checkEventRun() || getMidnaActor()->checkMetamorphoseEnable()) &&
|
||||
(checkModeFlg(4) || dComIfGp_checkPlayerStatus0(0, 0x10))))
|
||||
{
|
||||
canTransform = true;
|
||||
}
|
||||
if (checkMidnaRide()) {
|
||||
if ((checkWolf() &&
|
||||
(checkModeFlg(MODE_UNK_1000) || dComIfGp_checkPlayerStatus0(0, 0x10))) ||
|
||||
(!checkWolf() &&
|
||||
(checkEventRun() || getMidnaActor()->checkMetamorphoseEnable()) &&
|
||||
(checkModeFlg(4) || dComIfGp_checkPlayerStatus0(0, 0x10))))
|
||||
{
|
||||
canTransform = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "d/actor/d_a_obj_swhang.h"
|
||||
#include "d/actor/d_a_obj_chandelier.h"
|
||||
#include "JSystem/J3DGraphBase/J3DMaterial.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
|
||||
enum {
|
||||
HS_MODE_NONE_e,
|
||||
@@ -17,6 +19,10 @@ enum {
|
||||
HS_MODE_RETURN_e = 6,
|
||||
};
|
||||
|
||||
#if TARGET_PC
|
||||
static const int HS_CHAIN_MAX_LINKS = 600;
|
||||
#endif
|
||||
|
||||
void daAlink_c::hsChainShape_c::draw() {
|
||||
static const int dummy = 0;
|
||||
|
||||
@@ -161,7 +167,11 @@ void daAlink_c::hsChainShape_c::draw() {
|
||||
}
|
||||
(void)0;
|
||||
|
||||
while (maxDistanceF > var_f30) {
|
||||
#if TARGET_PC
|
||||
int chainLinks = 0;
|
||||
#endif
|
||||
|
||||
while (maxDistanceF > var_f30 IF_DUSK(&&chainLinks < HS_CHAIN_MAX_LINKS)) {
|
||||
temp_f27 = var_f28 * cM_fsin(sp34 * var_f30);
|
||||
s16 spC = cM_atan2s(temp_f27 - var_f26, 5.0f);
|
||||
sp64.x = sp6C.x + spC;
|
||||
@@ -183,6 +193,10 @@ void daAlink_c::hsChainShape_c::draw() {
|
||||
|
||||
var_f26 = temp_f27;
|
||||
var_f30 += fabsf(cM_scos(spC)) * 5.0f;
|
||||
|
||||
#if TARGET_PC
|
||||
chainLinks++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +212,11 @@ void daAlink_c::hsChainShape_c::draw() {
|
||||
sp98 = subChainTopPos;
|
||||
sp6C.set(maxDistance.atan2sY_XZ(), maxDistance.atan2sX_Z(), 0);
|
||||
|
||||
while (maxDistanceF > var_f30) {
|
||||
#if TARGET_PC
|
||||
int subChainLinks = 0;
|
||||
#endif
|
||||
|
||||
while (maxDistanceF > var_f30 IF_DUSK(&&subChainLinks < HS_CHAIN_MAX_LINKS)) {
|
||||
mDoMtx_stack_c::copy(j3dSys.getViewMtx());
|
||||
mDoMtx_stack_c::transM(sp98);
|
||||
mDoMtx_stack_c::ZXYrotM(sp6C);
|
||||
@@ -211,11 +229,39 @@ void daAlink_c::hsChainShape_c::draw() {
|
||||
sp98 += maxDistance * 5.0f;
|
||||
ANGLE_ADD_2(sp6C.z, 0x3000);
|
||||
var_f30 += 5.0f;
|
||||
#if TARGET_PC
|
||||
subChainLinks++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void ironBallChainInterpCallback(bool isSimFrame, void* pUserWork) {
|
||||
static_cast<daAlink_c*>(pUserWork)->onIronBallChainInterpCallback();
|
||||
}
|
||||
|
||||
void daAlink_c::onIronBallChainInterpCallback() {
|
||||
if (!mIBChainInterpPrevValid || !mIBChainInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
if (mIronBallChainPos == NULL || mIronBallChainAngle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
|
||||
for (int i = 0; i < IRON_BALL_CHAIN_COUNT; i++) {
|
||||
mIronBallChainPos[i] = mIBChainInterpPrevPos[i] + (mIBChainInterpCurrPos[i] - mIBChainInterpPrevPos[i]) * alpha;
|
||||
mIronBallChainAngle[i].x = mIBChainInterpPrevAngle[i].x + (s16)((s16)(mIBChainInterpCurrAngle[i].x - mIBChainInterpPrevAngle[i].x) * alpha);
|
||||
mIronBallChainAngle[i].y = mIBChainInterpPrevAngle[i].y + (s16)((s16)(mIBChainInterpCurrAngle[i].y - mIBChainInterpPrevAngle[i].y) * alpha);
|
||||
mIronBallChainAngle[i].z = mIBChainInterpPrevAngle[i].z + (s16)((s16)(mIBChainInterpCurrAngle[i].z - mIBChainInterpPrevAngle[i].z) * alpha);
|
||||
}
|
||||
mHookshotTopPos = mIBChainInterpPrevHandRoot + (mIBChainInterpCurrHandRoot - mIBChainInterpPrevHandRoot) * alpha;
|
||||
}
|
||||
#endif
|
||||
|
||||
void daAlink_c::hookshotAtHitCallBack(dCcD_GObjInf* i_atObjInf, fopAc_ac_c* i_tgActor,
|
||||
dCcD_GObjInf* i_tgObjInf) {
|
||||
if (i_tgActor != NULL && fopAcM_IsActor(i_tgActor) && !i_tgObjInf->ChkTgHookshotThrough()) {
|
||||
|
||||
@@ -2721,7 +2721,7 @@ int daAlink_c::procHorseRun() {
|
||||
}
|
||||
|
||||
if (mProcVar2.field_0x300c == 0) {
|
||||
set3DStatus(BUTTON_STATUS_HOLD_ON, 4);
|
||||
set3DStatus(BUTTON_STATUS_HOLD_ON, IF_DUSK(dusk::getSettings().game.enableMirrorMode ? 1 :) 4);
|
||||
}
|
||||
} else {
|
||||
if (mProcVar3.field_0x300e != 0) {
|
||||
@@ -2731,7 +2731,7 @@ int daAlink_c::procHorseRun() {
|
||||
}
|
||||
|
||||
if (mProcVar2.field_0x300c == 0) {
|
||||
set3DStatus(BUTTON_STATUS_HOLD_ON, 1);
|
||||
set3DStatus(BUTTON_STATUS_HOLD_ON, IF_DUSK(dusk::getSettings().game.enableMirrorMode ? 4 :) 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/gyro.h"
|
||||
#include "dusk/action_bindings.h"
|
||||
#endif
|
||||
|
||||
bool daAlink_c::checkNoSubjectModeCamera() {
|
||||
@@ -119,8 +120,8 @@ BOOL daAlink_c::setBodyAngleToCamera() {
|
||||
var_f31 /= dComIfGp_getCameraZoomScale(field_0x317c);
|
||||
}
|
||||
|
||||
shape_angle.y = shape_angle.y + (var_f31 * cM_ssin(mStickAngle));
|
||||
sp8 = mBodyAngle.x + (var_f31 * cM_scos(mStickAngle));
|
||||
shape_angle.y = shape_angle.y + (var_f31 * cM_ssin(mStickAngle) IF_DUSK(* (dusk::getSettings().game.invertFirstPersonXAxis ? -1.0f : 1.0f)));
|
||||
sp8 = mBodyAngle.x + (var_f31 * cM_scos(mStickAngle) IF_DUSK(* (dusk::getSettings().game.invertFirstPersonYAxis ? -1.0f : 1.0f)));
|
||||
|
||||
if (checkNotItemSinkLimit() && sp8 > 0 && sp8 > mBodyAngle.x) {
|
||||
sp8 = mBodyAngle.x;
|
||||
@@ -192,7 +193,9 @@ BOOL daAlink_c::subjectCancelTrigger() {
|
||||
BOOL daAlink_c::checkSubjectEnd(BOOL i_isPlaySe) {
|
||||
setDoStatus(BUTTON_STATUS_BACK);
|
||||
|
||||
if (checkEventRun() || checkEquipAnime() || doTrigger() || checkSetItemTrigger(dItemNo_HAWK_EYE_e) || subjectCancelTrigger() || checkEndResetFlg0(ERFLG0_FORCE_SUBJECT_CANCEL) || dComIfGp_checkCameraAttentionStatus(field_0x317c, 0x2000)) {
|
||||
// Allow pressing the first person binding to also leave first person
|
||||
if (IF_DUSK(dusk::getActionBindTrig(dusk::ActionBinds::FIRST_PERSON_CAMERA, 0)) ||
|
||||
checkEventRun() || checkEquipAnime() || doTrigger() || checkSetItemTrigger(dItemNo_HAWK_EYE_e) || subjectCancelTrigger() || checkEndResetFlg0(ERFLG0_FORCE_SUBJECT_CANCEL) || dComIfGp_checkCameraAttentionStatus(field_0x317c, 0x2000)) {
|
||||
if (i_isPlaySe) {
|
||||
seStartSystem(Z2SE_SUBJ_VIEW_OUT);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,11 @@ void daAlink_c::setOriginalHeap(JKRExpHeap** i_ppheap, u32 i_size) {
|
||||
u32 var_r28 = 0x10;
|
||||
u32 size = ROUND(i_size, 16);
|
||||
#if TARGET_PC
|
||||
size *= 2;
|
||||
size *= 20; // Increase Link's heap size to prevent mods from crashing with higher-quality models.
|
||||
#endif
|
||||
JKRHeap* parent = mDoExt_getGameHeap();
|
||||
|
||||
JKRExpHeap* heap = JKRExpHeap::create(size + (var_r29 + var_r28), parent, true);
|
||||
JKRHEAP_NAME(heap, "Alink original");
|
||||
*i_ppheap = heap;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +77,12 @@ int daAlink_c::loadModelDVD() {
|
||||
mpWlMidnaHairModel = NULL;
|
||||
|
||||
if (!checkNoResetFlg2(FLG2_UNK_280000)) {
|
||||
dComIfG_resDelete(&mPhaseReq, mArcName);
|
||||
if (!dComIfG_resDelete(&mPhaseReq, mArcName)) {
|
||||
#if TARGET_PC
|
||||
// resDelete no-ops if load was in-progress; force-unregister before freeAll
|
||||
dComIfG_deleteObjectResMain(mArcName);
|
||||
#endif
|
||||
}
|
||||
cPhs_Reset(&mPhaseReq);
|
||||
mpArcHeap->freeAll();
|
||||
|
||||
|
||||
@@ -8723,6 +8723,12 @@ int daAlink_c::procWolfCargoCarry() {
|
||||
return checkNextActionWolf(0);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (field_0x280c.getActor() == NULL) {
|
||||
return checkNextActionWolf(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
mDoMtx_stack_c::copy(((e_yc_class*)field_0x280c.getActor())->getLegR3Mtx());
|
||||
mDoMtx_stack_c::transM(-9.0f, -7.0f, -30.0f);
|
||||
mDoMtx_stack_c::multVecZero(¤t.pos);
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
#include "d/actor/d_a_e_pz.h"
|
||||
#include "d/actor/d_a_horse.h"
|
||||
#include "d/actor/d_a_hozelda.h"
|
||||
#if TARGET_PC
|
||||
#include "dusk/achievements.h"
|
||||
#endif
|
||||
|
||||
int daArrow_c::createHeap() {
|
||||
J3DModelData* model_data;
|
||||
@@ -92,7 +95,12 @@ void daArrow_c::atHitCallBack(dCcD_GObjInf* i_atObjInf, fopAc_ac_c* i_tgActor, d
|
||||
if (dist_to_hitpos < field_0x998) {
|
||||
field_0x998 = dist_to_hitpos;
|
||||
mHitAcID = fopAcM_GetID(i_tgActor);
|
||||
|
||||
#if TARGET_PC
|
||||
if (fopAcM_GetGroup(i_tgActor) == fopAc_ENEMY_e &&
|
||||
current.pos.abs(mStartPos) > 10000.0f) {
|
||||
dusk::AchievementSystem::get().signal("arrow_hit_100m");
|
||||
}
|
||||
#endif
|
||||
if (mArrowType == 1) {
|
||||
field_0x9a8 = *hit_pos_p;
|
||||
} else if (i_tgObjInf->ChkTgShield()) {
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
#if TARGET_PC
|
||||
#include "dusk/achievements.h"
|
||||
#endif
|
||||
|
||||
class daB_GND_HIO_c : public JORReflexible {
|
||||
public:
|
||||
@@ -1289,6 +1292,9 @@ static void b_gnd_g_wait(b_gnd_class* i_this) {
|
||||
if (i_this->mMoveMode < 5 && i_this->mPlayerDistXZ < 600.0f) {
|
||||
i_this->mMoveMode = 5;
|
||||
i_this->field_0xc44[0] = 10;
|
||||
#if TARGET_PC
|
||||
dusk::AchievementSystem::get().signal("ganondorf_fishing_rod");
|
||||
#endif
|
||||
}
|
||||
} else if (i_this->mMoveMode == 5) {
|
||||
i_this->mMoveMode = 6;
|
||||
|
||||
@@ -254,7 +254,11 @@ BOOL daBdoor_c::checkArea() {
|
||||
if (fabsf(vec.z) > 100.0f) {
|
||||
return false;
|
||||
}
|
||||
#ifdef TARGET_PC
|
||||
return (s16)((s32)fabs(current.angle.y - 0x7fff - player->current.angle.y) & 0xffff) <= 0x4000 ? 1 : 0;
|
||||
#else
|
||||
return (s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000 ? 1 : 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOL daBdoor_c::checkFront() {
|
||||
|
||||
@@ -825,7 +825,11 @@ int daBdoorL1_c::checkArea() {
|
||||
if (fabsf(local_48.z) > 100.0f) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef TARGET_PC
|
||||
if ((s16)((s32)fabs(current.angle.y - 0x7fff - player->current.angle.y) & 0xffff) <= 0x4000) {
|
||||
#else
|
||||
if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) {
|
||||
#endif
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@@ -348,7 +348,11 @@ int daBdoorL5_c::checkArea() {
|
||||
if (fabsf(local_48.z) > 100.0f) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef TARGET_PC
|
||||
if ((s16)((s32)fabs(current.angle.y - 0x7fff - player->current.angle.y) & 0xffff) <= 0x4000) {
|
||||
#else
|
||||
if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) {
|
||||
#endif
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@@ -1317,8 +1317,12 @@ int daMBdoorL1_c::checkArea() {
|
||||
if (fabsf(local_48.z) > 110.0f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TARGET_PC
|
||||
if ((s16)((s32)fabs(angle - 0x7fff - player->current.angle.y) & 0xffff) > 0x4000) {
|
||||
#else
|
||||
if ((s16)fabs((f64)(angle - 0x7fff - player->current.angle.y)) > 0x4000) {
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
#include <f_ap/f_ap_game.h>
|
||||
#include <dusk/autosave.h>
|
||||
#endif
|
||||
|
||||
char* daDoor20_c::getStopBmdName() {
|
||||
switch (door_param2_c::getKind(this)) {
|
||||
case 3:
|
||||
@@ -196,6 +201,7 @@ void daDoor20_c::setEventPrm() {
|
||||
} else {
|
||||
roomNo = FRoomNo;
|
||||
}
|
||||
|
||||
if (dComIfGp_roomControl_checkStatusFlag(roomNo, 1)) {
|
||||
if (door_param2_c::getKind(this) == 9) {
|
||||
if (daPy_py_c::checkNowWolf()) {
|
||||
@@ -564,6 +570,11 @@ int daDoor20_c::openEnd(int param_1) {
|
||||
openEnd_1();
|
||||
break;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
triggerAutoSave();
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#include "f_op/f_op_kankyo_mng.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#endif
|
||||
|
||||
class daE_DB_HIO_c : public JORReflexible {
|
||||
public:
|
||||
daE_DB_HIO_c();
|
||||
@@ -66,6 +70,22 @@ static BOOL leaf_anm_init(e_db_class* i_this, int i_anm, f32 i_morf, u8 i_mode,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void daE_DB_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_db_class* i_this = (e_db_class*)pUserWork;
|
||||
if (!i_this->mStalkLineInterpPrevValid || !i_this->mStalkLineInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
cXyz* dst = i_this->stalkLine.getPos(0);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
const cXyz& p0 = i_this->mStalkLineInterpPrev[i];
|
||||
const cXyz& p1 = i_this->mStalkLineInterpCurr[i];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int daE_DB_Draw(e_db_class* i_this) {
|
||||
fopAc_ac_c* actor = &i_this->enemy;
|
||||
|
||||
@@ -95,6 +115,17 @@ static int daE_DB_Draw(e_db_class* i_this) {
|
||||
static GXColor l_color = {0x14, 0x0F, 0x00, 0xFF};
|
||||
i_this->stalkLine.update(12, l_color, &actor->tevStr);
|
||||
dComIfGd_set3DlineMat(&i_this->stalkLine);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mStalkLineInterpCurrValid) {
|
||||
memcpy(i_this->mStalkLineInterpPrev, i_this->mStalkLineInterpCurr, sizeof(i_this->mStalkLineInterpCurr));
|
||||
i_this->mStalkLineInterpPrevValid = true;
|
||||
}
|
||||
memcpy(i_this->mStalkLineInterpCurr, i_this->stalkLine.getPos(0), 12 * sizeof(cXyz));
|
||||
i_this->mStalkLineInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_DB_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 1; i < 11; i++) {
|
||||
if (i_this->thornModel[i] != NULL) {
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "d/actor/d_a_e_hb_leaf.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#endif
|
||||
|
||||
enum daE_HB_ACTION {
|
||||
ACTION_STAY,
|
||||
ACTION_APPEAR,
|
||||
@@ -64,6 +68,22 @@ static BOOL leaf_anm_init(e_hb_class* i_this, int i_anm, f32 i_morf, u8 i_mode,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void daE_HB_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_hb_class* i_this = (e_hb_class*)pUserWork;
|
||||
if (!i_this->mStalkLineInterpPrevValid || !i_this->mStalkLineInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
cXyz* dst = i_this->stalkLine.getPos(0);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
const cXyz& p0 = i_this->mStalkLineInterpPrev[i];
|
||||
const cXyz& p1 = i_this->mStalkLineInterpCurr[i];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int daE_HB_Draw(e_hb_class* i_this) {
|
||||
fopAc_ac_c* actor = &i_this->enemy;
|
||||
|
||||
@@ -82,6 +102,17 @@ static int daE_HB_Draw(e_hb_class* i_this) {
|
||||
static GXColor l_color = {0x14, 0x0F, 0x00, 0xFF};
|
||||
i_this->stalkLine.update(12, l_color, &actor->tevStr);
|
||||
dComIfGd_set3DlineMat(&i_this->stalkLine);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mStalkLineInterpCurrValid) {
|
||||
memcpy(i_this->mStalkLineInterpPrev, i_this->mStalkLineInterpCurr, sizeof(i_this->mStalkLineInterpCurr));
|
||||
i_this->mStalkLineInterpPrevValid = true;
|
||||
}
|
||||
memcpy(i_this->mStalkLineInterpCurr, i_this->stalkLine.getPos(0), 12 * sizeof(cXyz));
|
||||
i_this->mStalkLineInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_HB_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 1; i < 11; i++) {
|
||||
if (i_this->thornModel[i] != NULL) {
|
||||
|
||||
@@ -157,6 +157,21 @@ static void* s_h_sub(void* i_actor, void* i_data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void sort_target_info_by_id() {
|
||||
for (int i = 1; i < target_info_count; i++) {
|
||||
void* key = target_info[i];
|
||||
fpc_ProcID key_id = fopAcM_GetID(key);
|
||||
int j = i - 1;
|
||||
while (j >= 0 && fopAcM_GetID(target_info[j]) > key_id) {
|
||||
target_info[j + 1] = target_info[j];
|
||||
j--;
|
||||
}
|
||||
target_info[j + 1] = key;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static daPillar_c* search_hasira(e_mk_class* i_this) {
|
||||
fopEn_enemy_c* actor = (fopEn_enemy_c*)&i_this->actor;
|
||||
daPillar_c* pillar_p;
|
||||
@@ -170,6 +185,9 @@ static daPillar_c* search_hasira(e_mk_class* i_this) {
|
||||
|
||||
if (i_this->firstHasiraFlag == 0) {
|
||||
i_this->firstHasiraFlag++;
|
||||
#if TARGET_PC
|
||||
sort_target_info_by_id();
|
||||
#endif
|
||||
return (daPillar_c*)target_info[TREG_S(7) + 5];
|
||||
}
|
||||
|
||||
|
||||
@@ -517,6 +517,12 @@ void daE_OctBg_c::core_fish_attack() {
|
||||
field_0xbaf = cM_rndFX(80.0f) + 100.0f;
|
||||
}
|
||||
}
|
||||
#if AVOID_UB
|
||||
else {
|
||||
in_f31 = cM_rndF(400.0f) + 80.0f;
|
||||
field_0xbaf = cM_rndFX(80.0f) + 100.0f;
|
||||
}
|
||||
#endif
|
||||
} else if (current.pos.abs(cStack_5c) < 400.0f) {
|
||||
in_f31 = cM_rndF(50.0f) + 20.0f;
|
||||
field_0xbaf = cM_rndFX(20.0f) + 40.0f;
|
||||
|
||||
@@ -7053,6 +7053,12 @@ static int daE_RD_IsDelete(e_rd_class*) {
|
||||
}
|
||||
|
||||
static int daE_RD_Delete(e_rd_class* i_this) {
|
||||
#if TARGET_PC
|
||||
if (boss == i_this) {
|
||||
boss = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
fopEn_enemy_c* enemy = (fopEn_enemy_c*)&i_this->enemy;
|
||||
fopAcM_RegisterDeleteID(i_this, "E_RD");
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "d/d_s_play.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
#include "f_op/f_op_camera_mng.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
#include <cstring>
|
||||
|
||||
class daE_S1_HIO_c {
|
||||
@@ -99,6 +101,25 @@ static void anm_init(e_s1_class* i_this, int i_resNo, f32 i_morf, u8 i_attr, f32
|
||||
i_this->mAnm = i_resNo;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void daE_S1_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_s1_class* i_this = (e_s1_class*)pUserWork;
|
||||
if (!i_this->mHairInterpPrevValid || !i_this->mHairInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
for (int s = 0; s < e_s1_class::HAIR_STRAND_COUNT; s++) {
|
||||
cXyz* dst = i_this->mLineMat.getPos(s);
|
||||
for (int i = 0; i < e_s1_class::HAIR_SEGMENT_COUNT; i++) {
|
||||
int idx = s * e_s1_class::HAIR_SEGMENT_COUNT + i;
|
||||
const cXyz& p0 = i_this->mHairInterpPrev[idx];
|
||||
const cXyz& p1 = i_this->mHairInterpCurr[idx];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int daE_S1_Draw(e_s1_class* i_this) {
|
||||
if (i_this->field_0x306c != 0) {
|
||||
return 1;
|
||||
@@ -132,6 +153,22 @@ static int daE_S1_Draw(e_s1_class* i_this) {
|
||||
i_this->mLineMat.update(16, line_color, &i_this->tevStr);
|
||||
dComIfGd_set3DlineMatDark(&i_this->mLineMat);
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mHairInterpCurrValid) {
|
||||
memcpy(i_this->mHairInterpPrev, i_this->mHairInterpCurr, sizeof(i_this->mHairInterpCurr));
|
||||
i_this->mHairInterpPrevValid = true;
|
||||
}
|
||||
for (int s = 0; s < e_s1_class::HAIR_STRAND_COUNT; s++) {
|
||||
cXyz* src = i_this->mLineMat.getPos(s);
|
||||
memcpy(&i_this->mHairInterpCurr[s * e_s1_class::HAIR_SEGMENT_COUNT], src,
|
||||
e_s1_class::HAIR_SEGMENT_COUNT * sizeof(cXyz));
|
||||
}
|
||||
i_this->mHairInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_S1_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
dComIfGd_setList();
|
||||
return 1;
|
||||
}
|
||||
@@ -2149,6 +2186,11 @@ static int daE_S1_Create(fopAc_ac_c* i_this) {
|
||||
return cPhs_ERROR_e;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
a_this->mHairInterpPrevValid = false;
|
||||
a_this->mHairInterpCurrValid = false;
|
||||
#endif
|
||||
|
||||
OS_REPORT("//////////////E_S1 SET 2 !!\n");
|
||||
|
||||
if (path_no != 0xFF) {
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include "c/c_damagereaction.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
#include "f_op/f_op_camera_mng.h"
|
||||
#if TARGET_PC
|
||||
#include "dusk/achievements.h"
|
||||
#endif
|
||||
|
||||
class daE_TH_HIO_c : public JORReflexible {
|
||||
public:
|
||||
@@ -282,6 +285,11 @@ static void e_th_spin_B(e_th_class* i_this) {
|
||||
i_this->current.pos += spC;
|
||||
|
||||
f32 speed_target;
|
||||
|
||||
#if AVOID_UB
|
||||
speed_target = 0;
|
||||
#endif
|
||||
|
||||
f32 anm_frame = i_this->mpModelMorf->getFrame();
|
||||
|
||||
switch (i_this->mMode) {
|
||||
@@ -537,6 +545,7 @@ static void damage_check(e_th_class* i_this) {
|
||||
if (i_this->field_0x6a4 == 0 && i_this->mAction != ACTION_SPIN) {
|
||||
daPy_py_c* player = (daPy_py_c*)dComIfGp_getPlayer(0);
|
||||
OS_REPORT("E_th HP1 %d\n", i_this->health);
|
||||
s16 prevHealth = i_this->health;
|
||||
cc_at_check(i_this, &i_this->mAtInfo);
|
||||
OS_REPORT("E_th HP2 %d\n", i_this->health);
|
||||
|
||||
@@ -549,6 +558,11 @@ static void damage_check(e_th_class* i_this) {
|
||||
dComIfGs_onOneZoneSwitch(3, -1);
|
||||
|
||||
if (i_this->health <= 0) {
|
||||
#if TARGET_PC
|
||||
if (prevHealth == i_this->field_0x560) {
|
||||
dusk::AchievementSystem::get().signal("dark_hammer_one_hit");
|
||||
}
|
||||
#endif
|
||||
i_this->mAction = ACTION_END;
|
||||
i_this->mMode = 0;
|
||||
i_this->field_0x68a |= 4;
|
||||
|
||||
@@ -5852,6 +5852,8 @@ static int daE_WB_Create(fopAc_ac_c* actor) {
|
||||
daE_WB_Execute(i_this);
|
||||
c_start = 0;
|
||||
|
||||
// Note: this flag makes king bulblin 1 instant die when set, as it only requires 2 laps
|
||||
// for insta-kill to trigger.
|
||||
if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[88])) {
|
||||
i_this->lap_num = 1;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "d/d_cc_uty.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#endif
|
||||
|
||||
class daE_YD_HIO_c {
|
||||
public:
|
||||
daE_YD_HIO_c();
|
||||
@@ -73,6 +77,22 @@ static s32 leaf_anm_init(e_yd_class* i_this, int param_1, f32 param_2, u8 param_
|
||||
return false;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void daE_YD_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_yd_class* i_this = (e_yd_class*)pUserWork;
|
||||
if (!i_this->mLineMatInterpPrevValid || !i_this->mLineMatInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
cXyz* dst = i_this->mLineMat.getPos(0);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
const cXyz& p0 = i_this->mLineMatInterpPrev[i];
|
||||
const cXyz& p1 = i_this->mLineMatInterpCurr[i];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static s32 daE_YD_Draw(e_yd_class* i_this) {
|
||||
static GXColor l_color = { 0x14, 0x0F, 0x00, 0xFF };
|
||||
|
||||
@@ -86,6 +106,17 @@ static s32 daE_YD_Draw(e_yd_class* i_this) {
|
||||
i_this->mpMorf->entryDL();
|
||||
i_this->mLineMat.update(12, l_color, &i_this->actor.tevStr);
|
||||
dComIfGd_set3DlineMat(&i_this->mLineMat);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mLineMatInterpCurrValid) {
|
||||
memcpy(i_this->mLineMatInterpPrev, i_this->mLineMatInterpCurr, sizeof(i_this->mLineMatInterpCurr));
|
||||
i_this->mLineMatInterpPrevValid = true;
|
||||
}
|
||||
memcpy(i_this->mLineMatInterpCurr, i_this->mLineMat.getPos(0), 12 * sizeof(cXyz));
|
||||
i_this->mLineMatInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_YD_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
for (s32 i = 1; i < 11; i++) {
|
||||
if (i_this->field_0x77c[i] != 0) {
|
||||
g_env_light.setLightTevColorType_MAJI(i_this->field_0x77c[i], &i_this->actor.tevStr);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "f_op/f_op_kankyo_mng.h"
|
||||
#include "d/actor/d_a_obj_carry.h"
|
||||
#include "Z2AudioLib/Z2Instances.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
|
||||
enum E_yg_RES_File_ID {
|
||||
@@ -134,7 +136,26 @@ static BOOL pl_check(e_yg_class* i_this, f32 i_dist) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int daE_YG_Draw(e_yg_class* i_this) {
|
||||
#if TARGET_PC
|
||||
static void daE_YG_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_yg_class* i_this = (e_yg_class*)pUserWork;
|
||||
if (!i_this->mTentacleInterpPrevValid || !i_this->mTentacleInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
for (int s = 0; s < e_yg_class::TENTACLE_STRAND_COUNT; s++) {
|
||||
cXyz* dst = i_this->mLineMat.getPos(s);
|
||||
for (int i = 0; i < e_yg_class::TENTACLE_SEGMENT_COUNT; i++) {
|
||||
int idx = s * e_yg_class::TENTACLE_SEGMENT_COUNT + i;
|
||||
const cXyz& p0 = i_this->mTentacleInterpPrev[idx];
|
||||
const cXyz& p1 = i_this->mTentacleInterpCurr[idx];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int daE_YG_Draw(e_yg_class* i_this) {
|
||||
if (i_this->mDispFlag) {
|
||||
return 1;
|
||||
}
|
||||
@@ -160,6 +181,23 @@ static int daE_YG_Draw(e_yg_class* i_this) {
|
||||
color.a = 0xFF;
|
||||
i_this->mLineMat.update(10, color, &actor->tevStr);
|
||||
dComIfGd_set3DlineMatDark(&i_this->mLineMat);
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mTentacleInterpCurrValid) {
|
||||
memcpy(i_this->mTentacleInterpPrev, i_this->mTentacleInterpCurr, sizeof(i_this->mTentacleInterpCurr));
|
||||
i_this->mTentacleInterpPrevValid = true;
|
||||
}
|
||||
for (int s = 0; s < e_yg_class::TENTACLE_STRAND_COUNT; s++) {
|
||||
cXyz* src = i_this->mLineMat.getPos(s);
|
||||
memcpy(&i_this->mTentacleInterpCurr[s * e_yg_class::TENTACLE_SEGMENT_COUNT], src,
|
||||
e_yg_class::TENTACLE_SEGMENT_COUNT * sizeof(cXyz));
|
||||
}
|
||||
i_this->mTentacleInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_YG_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
dComIfGd_setList();
|
||||
|
||||
return 1;
|
||||
@@ -1378,6 +1416,11 @@ static cPhs_Step daE_YG_Create(fopAc_ac_c* actor) {
|
||||
return cPhs_ERROR_e;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
i_this->mTentacleInterpPrevValid = false;
|
||||
i_this->mTentacleInterpCurrValid = false;
|
||||
#endif
|
||||
|
||||
if (!hio_set) {
|
||||
i_this->mIsFirstSpawn = 1;
|
||||
hio_set = true;
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "f_op/f_op_actor_enemy.h"
|
||||
#include "f_op/f_op_kankyo_mng.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#endif
|
||||
|
||||
class daE_YH_HIO_c : public JORReflexible {
|
||||
public:
|
||||
daE_YH_HIO_c();
|
||||
@@ -85,6 +89,22 @@ static BOOL leaf_anm_init(e_yh_class* i_this, int param_2, f32 param_3, u8 param
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void daE_YH_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
e_yh_class* i_this = (e_yh_class*)pUserWork;
|
||||
if (!i_this->mLineInterpPrevValid || !i_this->mLineInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
cXyz* dst = i_this->mLine.getPos(0);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
const cXyz& p0 = i_this->mLineInterpPrev[i];
|
||||
const cXyz& p1 = i_this->mLineInterpCurr[i];
|
||||
dst[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int daE_YH_Draw(e_yh_class* i_this) {
|
||||
fopAc_ac_c* a_this = (fopAc_ac_c*)i_this;
|
||||
|
||||
@@ -114,6 +134,17 @@ static int daE_YH_Draw(e_yh_class* i_this) {
|
||||
|
||||
i_this->mLine.update(12, l_color, &a_this->tevStr);
|
||||
dComIfGd_set3DlineMat(&i_this->mLine);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (i_this->mLineInterpCurrValid) {
|
||||
memcpy(i_this->mLineInterpPrev, i_this->mLineInterpCurr, sizeof(i_this->mLineInterpCurr));
|
||||
i_this->mLineInterpPrevValid = true;
|
||||
}
|
||||
memcpy(i_this->mLineInterpCurr, i_this->mLine.getPos(0), 12 * sizeof(cXyz));
|
||||
i_this->mLineInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&daE_YH_interp_callback, i_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 1; i < 11; i++) {
|
||||
if (i_this->mModels[i] != NULL) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/dusk.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
|
||||
namespace {
|
||||
// FRAME INTERP NOTE: Sim tick control point snapshots for interpolation
|
||||
@@ -32,6 +33,7 @@ int s_horseReinSimNumPrev;
|
||||
int s_horseReinSimNumCurr;
|
||||
bool s_horseReinSimPrevValid;
|
||||
bool s_horseReinSimCurrValid;
|
||||
uint64_t s_horseReinSimRolledSeq;
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
@@ -3033,10 +3035,14 @@ void daHorse_c::copyReinPos() {
|
||||
}
|
||||
#if TARGET_PC
|
||||
if (field_0x1204 > 0) {
|
||||
if (s_horseReinSimCurrValid && s_horseReinSimNumCurr > 0) {
|
||||
memcpy(s_horseReinSimPrev, s_horseReinSimCurr, s_horseReinSimNumCurr * sizeof(cXyz));
|
||||
s_horseReinSimNumPrev = s_horseReinSimNumCurr;
|
||||
s_horseReinSimPrevValid = true;
|
||||
const uint64_t simSeq = dusk::frame_interp::sim_tick_seq();
|
||||
if (simSeq != s_horseReinSimRolledSeq) {
|
||||
s_horseReinSimRolledSeq = simSeq;
|
||||
if (s_horseReinSimCurrValid && s_horseReinSimNumCurr > 0) {
|
||||
memcpy(s_horseReinSimPrev, s_horseReinSimCurr, s_horseReinSimNumCurr * sizeof(cXyz));
|
||||
s_horseReinSimNumPrev = s_horseReinSimNumCurr;
|
||||
s_horseReinSimPrevValid = true;
|
||||
}
|
||||
}
|
||||
memcpy(s_horseReinSimCurr, m_reinLine.getPos(0), field_0x1204 * sizeof(cXyz));
|
||||
s_horseReinSimNumCurr = field_0x1204;
|
||||
|
||||
@@ -3519,7 +3519,15 @@ void daKago_c::action() {
|
||||
checkSizeBg();
|
||||
setFlyEffect();
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
mStickX = -mDoCPd_c::getStickX3D(PAD_1);
|
||||
} else {
|
||||
mStickX = mDoCPd_c::getStickX3D(PAD_1);
|
||||
}
|
||||
#else
|
||||
mStickX = mDoCPd_c::getStickX3D(PAD_1);
|
||||
#endif
|
||||
mStickY = mDoCPd_c::getStickY(PAD_1);
|
||||
|
||||
u8 prevIsWaterfall = mIsWaterfall;
|
||||
|
||||
@@ -729,10 +729,12 @@ static void koro2_game(fshop_class* i_this) {
|
||||
cLib_addCalcAngleS2(&i_this->field_0x4020.z, 0, 2, 0x200);
|
||||
case 2:
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableGyroRollgoal) {
|
||||
if (dusk::gyro::rollgoal_gyro_enabled()) {
|
||||
if (!dusk::gyro::get_sensor_keep_alive()) {
|
||||
dusk::gyro::set_sensor_keep_alive(true);
|
||||
}
|
||||
} else if (dusk::gyro::get_sensor_keep_alive()) {
|
||||
dusk::gyro::set_sensor_keep_alive(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -753,7 +755,7 @@ static void koro2_game(fshop_class* i_this) {
|
||||
old_stick_x = mDoCPd_c::getSubStickX(PAD_1);
|
||||
cLib_addCalcAngleS2(&i_this->field_0x4060, i_this->field_0x4062, 4, 0x1000);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableGyroRollgoal) {
|
||||
if (dusk::gyro::rollgoal_gyro_enabled()) {
|
||||
dusk::gyro::rollgoalTick(true, i_this->field_0x4060);
|
||||
}
|
||||
#endif
|
||||
@@ -791,7 +793,7 @@ static void koro2_game(fshop_class* i_this) {
|
||||
s16 gyro_ax = 0;
|
||||
s16 gyro_az = 0;
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableGyroRollgoal) {
|
||||
if (dusk::gyro::rollgoal_gyro_enabled()) {
|
||||
dusk::gyro::rollgoalTableOffset(gyro_ax, gyro_az);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -419,9 +419,30 @@ int daMidna_c::createHeap() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (mpDemoFCTongueBmd != NULL) {
|
||||
if(!daAlink_c::initDemoBck(&mpDemoFCTmpBck, "demo00_Midna_cut00_FC_tmp.bck")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Update Midna's eye maxLOD to prevent the eyes from disappearing
|
||||
J3DTexture* tex = mpDemoFCTongueBmd->getModelData()->getTexture();
|
||||
JUTNameTab* nametable = mpDemoFCTongueBmd->getModelData()->getTextureName();
|
||||
if (tex != nullptr && nametable != nullptr) {
|
||||
for (u16 i = 0; i < tex->getNum(); i++) {
|
||||
const char* tex_name = nametable->getName(i);
|
||||
if (tex_name != NULL && strcmp(tex_name, "midona_eyeball") == 0) {
|
||||
ResTIMG* timg = tex->getResTIMG(i);
|
||||
timg->maxLOD = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (mpDemoFCTongueBmd != NULL && !daAlink_c::initDemoBck(&mpDemoFCTmpBck, "demo00_Midna_cut00_FC_tmp.bck")) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
modelData =
|
||||
(J3DModelData*)dComIfG_getObjectRes(dStage_roomControl_c::getDemoArcName(), "demo00_Midna_cut00_BD_tmp.bmd");
|
||||
@@ -433,6 +454,21 @@ int daMidna_c::createHeap() {
|
||||
|
||||
modelData->getMaterialNodePointer(2)->setMaterialAnm(mpEyeMatAnm[0]);
|
||||
modelData->getMaterialNodePointer(3)->setMaterialAnm(mpEyeMatAnm[1]);
|
||||
|
||||
#if TARGET_PC
|
||||
// Update Midna's eye maxLOD to prevent the eyes from disappearing
|
||||
J3DTexture* tex = modelData->getTexture();
|
||||
JUTNameTab* nametable = modelData->getTextureName();
|
||||
if (tex != nullptr && nametable != nullptr) {
|
||||
for (u16 i = 0; i < tex->getNum(); i++) {
|
||||
const char* tex_name = nametable->getName(i);
|
||||
if (tex_name != NULL && strcmp(tex_name, "midona_eyeball") == 0) {
|
||||
ResTIMG* timg = tex->getResTIMG(i);
|
||||
timg->maxLOD = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!initDemoModel(&mpDemoBDMaskBmd, "demo00_Midna_cut00_BD_mask.bmd", 0)) {
|
||||
@@ -463,6 +499,23 @@ int daMidna_c::createHeap() {
|
||||
JKRReadIdxResource(mBckHeap[0].getBuffer(), mBckHeap[0].getBufferSize(), 0x1DC, dComIfGp_getAnmArchive());
|
||||
J3DAnmTransform* md_anm = (J3DAnmTransform*)J3DAnmLoaderDataBase::load(mBckHeap[0].getBuffer());
|
||||
modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 14);
|
||||
|
||||
#if TARGET_PC
|
||||
J3DTexture* tex = modelData->getTexture();
|
||||
JUTNameTab* nametable = modelData->getTextureName();
|
||||
if (tex != NULL && nametable != NULL) {
|
||||
for (u16 i = 0; i < tex->getNum(); i++) {
|
||||
const char* name = nametable->getName(i);
|
||||
if (name != NULL && strcmp(name, "midona_eye") == 0) {
|
||||
ResTIMG* timg = tex->getResTIMG(i);
|
||||
timg->mipmapEnabled = false;
|
||||
tex->loadGXTexObj(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
JUT_ASSERT(852, modelData != NULL);
|
||||
mpMorf = JKR_NEW mDoExt_McaMorfSO(modelData, &mMorfCB, NULL, md_anm, J3DFrameCtrl::EMode_LOOP, 1.0f, 0, -1, NULL, 0, 0x11000284);
|
||||
if (mpMorf == NULL || mpMorf->getModel() == NULL) {
|
||||
|
||||
@@ -40,6 +40,7 @@ dMirror_packet_c::dMirror_packet_c() {
|
||||
void dMirror_packet_c::reset() {
|
||||
#if TARGET_PC
|
||||
mbReset = true;
|
||||
mbHadEntry = false;
|
||||
#else
|
||||
mModelCount = 0;
|
||||
#endif
|
||||
@@ -84,11 +85,21 @@ void dMirror_packet_c::calcMinMax() {
|
||||
}
|
||||
|
||||
int dMirror_packet_c::entryModel(J3DModel* i_model) {
|
||||
#if TARGET_PC
|
||||
if (mbReset) {
|
||||
mModelCount = 0;
|
||||
mbReset = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mModelCount >= 0x40) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
mModels[mModelCount++] = i_model;
|
||||
#if TARGET_PC
|
||||
mbHadEntry = true;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -592,13 +603,6 @@ int daMirror_c::execute() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (mPacket.mbReset) {
|
||||
mPacket.mModelCount = 0;
|
||||
mPacket.mbReset = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
daPy_py_c* player = daPy_getLinkPlayerActorClass();
|
||||
JUT_ASSERT(0, player != NULL);
|
||||
|
||||
@@ -624,6 +628,12 @@ int daMirror_c::draw() {
|
||||
mDoExt_modelUpdateDL(mpModel);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (mPacket.mbReset && !mPacket.mbHadEntry) {
|
||||
mPacket.mModelCount = 0;
|
||||
}
|
||||
mPacket.mbHadEntry = true;
|
||||
#endif
|
||||
dComIfGd_getOpaListBG()->entryImm(&mPacket, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1967,7 +1967,11 @@ static void demo_camera_shop(npc_henna_class* i_this) {
|
||||
i_this->mMsgFlow.init(actor, 0x365, 0, NULL);
|
||||
/* dSv_event_flag_c::KORO2_ALLCLEAR - Fishing - After all stages (8-8) of roll goal game cleared */
|
||||
dComIfGs_onEventBit(dSv_event_flag_c::saveBitLabels[0x335]);
|
||||
#if TARGET_PC
|
||||
dComIfGp_setItemRupeeCount(dComIfGs_getRupeeMax());
|
||||
#else
|
||||
dComIfGp_setItemRupeeCount(1000);
|
||||
#endif
|
||||
} else if ((lbl_82_bss_91 & 0x38) == 0) {
|
||||
i_this->mMsgFlow.init(actor, 0x34f, 0, NULL);
|
||||
/* dSv_event_flag_c::F_0469 - Fishing Pond - Reserved for fishing */
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "d/actor/d_a_obj_automata.h"
|
||||
#include "d/d_msg_object.h"
|
||||
#include "d/actor/d_a_obj_scannon.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include <cstring>
|
||||
|
||||
const daNpc_Toby_HIOParam daNpc_Toby_Param_c::m = {
|
||||
@@ -1398,6 +1399,7 @@ int daNpc_Toby_c::cutRepairSCannon(int arg0) {
|
||||
old.pos = current.pos;
|
||||
setAngle(cM_deg2s(5.0f * f32(mPath.getArg0())));
|
||||
mEventTimer = mPath.getArg2();
|
||||
dusk::frame_interp::request_presentation_sync();
|
||||
}
|
||||
} else if (!mHide) {
|
||||
mHide = 1;
|
||||
|
||||
@@ -62,6 +62,16 @@ void daObj_Balloon_c::saveBestScore() {
|
||||
dComIfGp_setMessageCountNumber(m_balloon_score);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void minigameReset() {
|
||||
// !@bug d_a_obj_balloon.rel unload used to zero these file-statics; with static linking they dangle across scenes.
|
||||
m_combo_type = 0xFFFFFFFF;
|
||||
m_combo_count = 0;
|
||||
m_combo_next_score = 0;
|
||||
m_balloon_score = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static u8 hio_set;
|
||||
|
||||
static daObj_Balloon_HIO_c l_HIO;
|
||||
@@ -205,13 +215,6 @@ int daObj_Balloon_c::_delete() {
|
||||
Z2GetAudioMgr()->seStop(Z2SE_OBJ_WATERMILL_ROUND, 0);
|
||||
if (mHIOInit) {
|
||||
hio_set = false;
|
||||
#ifdef TARGET_PC
|
||||
// !@bug d_a_obj_balloon.rel unload used to zero these file-statics; with static linking they dangle across scenes.
|
||||
m_combo_type = 0xFFFFFFFF;
|
||||
m_combo_count = 0;
|
||||
m_combo_next_score = 0;
|
||||
m_balloon_score = 0;
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -253,6 +256,7 @@ int daObj_Balloon_c::create() {
|
||||
}
|
||||
|
||||
if (!hio_set) {
|
||||
IF_DUSK(minigameReset());
|
||||
mHIOInit = true;
|
||||
hio_set = true;
|
||||
l_HIO.field_0x04 = -1;
|
||||
|
||||
@@ -299,7 +299,8 @@ int daObjDrop_c::modeParentWait() {
|
||||
|
||||
#if TARGET_PC
|
||||
static inline BOOL checkGetCargoRide() {
|
||||
if ((daPy_getPlayerActorClass()->checkCargoCarry() && strcmp(dComIfGp_getStartStageName(), "F_SP112") == 0) ||
|
||||
if (daPy_getPlayerActorClass()->checkCargoCarry() &&
|
||||
strcmp(dComIfGp_getStartStageName(), "F_SP112") == 0 &&
|
||||
dComIfGs_isLightDropGetFlag(dComIfGp_getStartStageDarkArea()))
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "JSystem/J3DGraphBase/J3DDrawBuffer.h"
|
||||
#include "SSystem/SComponent/c_math.h"
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
#include <cstring>
|
||||
|
||||
static char const l_arcName[] = "Fchain";
|
||||
@@ -65,6 +67,10 @@ int daObjFchain_c::create() {
|
||||
local_48++;
|
||||
}
|
||||
rv = cPhs_COMPLEATE_e;
|
||||
#if TARGET_PC
|
||||
mChainInterpPrevValid = false;
|
||||
mChainInterpCurrValid = false;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
@@ -289,6 +295,26 @@ void daObjFchain_shape_c::draw() {
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void fchain_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
static_cast<daObjFchain_c*>(pUserWork)->onInterpCallback();
|
||||
}
|
||||
|
||||
void daObjFchain_c::onInterpCallback() {
|
||||
if (!mChainInterpPrevValid || !mChainInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
|
||||
for (int i = 0; i < CHAIN_COUNT; i++) {
|
||||
const cXyz& p0 = mChainInterpPrev[i];
|
||||
const cXyz& p1 = mChainInterpCurr[i];
|
||||
field_0x694[i] = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int daObjFchain_c::draw() {
|
||||
if (field_0x584 != 0) {
|
||||
g_env_light.settingTevStruct(0, ¤t.pos, &tevStr);
|
||||
@@ -297,6 +323,19 @@ int daObjFchain_c::draw() {
|
||||
return 1;
|
||||
}
|
||||
dComIfGd_getOpaListDark()->entryImm(&mShape, 0);
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (mChainInterpCurrValid) {
|
||||
memcpy(mChainInterpPrev, mChainInterpCurr, sizeof(mChainInterpCurr));
|
||||
mChainInterpPrevValid = true;
|
||||
}
|
||||
|
||||
memcpy(mChainInterpCurr, field_0x694, sizeof(mChainInterpCurr));
|
||||
mChainInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&fchain_interp_callback, this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "d/d_bg_w.h"
|
||||
#include "d/d_cc_uty.h"
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/settings.h"
|
||||
|
||||
struct daObjKLift00_HIO_c : public mDoHIO_entry_c {
|
||||
daObjKLift00_HIO_c();
|
||||
@@ -295,6 +297,11 @@ int daObjKLift00_c::Create() {
|
||||
if(getLock())
|
||||
mStopSwingingFrames = 5;
|
||||
|
||||
#if TARGET_PC
|
||||
mChainInterpPrevValid = false;
|
||||
mChainInterpCurrValid = false;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -436,6 +443,34 @@ int daObjKLift00_c::Execute(Mtx** i_mtx) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static void klift00_interp_callback(bool isSimFrame, void* pUserWork) {
|
||||
static_cast<daObjKLift00_c*>(pUserWork)->onInterpCallback();
|
||||
}
|
||||
|
||||
void daObjKLift00_c::onInterpCallback() {
|
||||
if (!mChainInterpPrevValid || !mChainInterpCurrValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const f32 alpha = dusk::frame_interp::get_interpolation_step();
|
||||
cXyz savedPositions[64];
|
||||
|
||||
for (int i = 0; i < mNumChains; i++) {
|
||||
savedPositions[i] = mChainPositions[i].mCurrentPos;
|
||||
const cXyz& p0 = mChainInterpPrev[i];
|
||||
const cXyz& p1 = mChainInterpCurr[i];
|
||||
mChainPositions[i].mCurrentPos = p0 + (p1 - p0) * alpha;
|
||||
}
|
||||
|
||||
setMtx();
|
||||
|
||||
for (int i = 0; i < mNumChains; i++) {
|
||||
mChainPositions[i].mCurrentPos = savedPositions[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int daObjKLift00_c::Draw() {
|
||||
g_env_light.settingTevStruct(16, ¤t.pos, &tevStr);
|
||||
g_env_light.setLightTevColorType_MAJI(mpLiftPlatform, &tevStr);
|
||||
@@ -457,6 +492,22 @@ int daObjKLift00_c::Draw() {
|
||||
|
||||
dComIfGd_setList();
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
if (mChainInterpCurrValid) {
|
||||
memcpy(mChainInterpPrev, mChainInterpCurr, mNumChains * sizeof(cXyz));
|
||||
mChainInterpPrevValid = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mNumChains; i++) {
|
||||
mChainInterpCurr[i] = mChainPositions[i].mCurrentPos;
|
||||
}
|
||||
|
||||
mChainInterpCurrValid = true;
|
||||
dusk::frame_interp::add_interpolation_callback(&klift00_interp_callback, this);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "SSystem/SComponent/c_counter.h"
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
#define DRAW_TYPE_YELLOW 0
|
||||
#define DRAW_TYPE_RED 1
|
||||
|
||||
@@ -1422,6 +1426,11 @@ int dAttention_c::Run() {
|
||||
}
|
||||
|
||||
void dAttention_c::Draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (mAttParam.CheckFlag(dAttParam_c::EFlag_ARROW_OFF)) {
|
||||
draw[0].field_0x173 = 3;
|
||||
draw[1].field_0x173 = 3;
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
#include "d/d_msg_string.h"
|
||||
#include "dusk/livesplit.h"
|
||||
#include "dusk/imgui/ImGuiConsole.hpp"
|
||||
#include "dusk/speedrun.h"
|
||||
#include "m_Do/m_Do_controller_pad.h"
|
||||
#include <dusk/autosave.h>
|
||||
|
||||
dBrightCheck_c::dBrightCheck_c(JKRArchive* i_archive) {
|
||||
mArchive = i_archive;
|
||||
@@ -141,15 +143,16 @@ void dBrightCheck_c::modeMove() {
|
||||
if (mDoCPd_c::getTrigA(PAD_1) || mDoCPd_c::getTrigStart(PAD_1)) {
|
||||
mDoAud_seStart(Z2SE_ENTER_GAME, NULL, 0, 0);
|
||||
#ifdef TARGET_PC
|
||||
dusk::speedrun::start();
|
||||
|
||||
if (dusk::getSettings().game.speedrunMode && !dusk::getSettings().game.hideTvSettingsScreen) {
|
||||
// start a new run if a run isn't already in progress
|
||||
if (!dusk::m_speedrunInfo.m_isRunStarted) {
|
||||
dusk::ImGuiMenuGame::resetForSpeedrunMode();
|
||||
dusk::resetForSpeedrunMode();
|
||||
dusk::m_speedrunInfo.startRun();
|
||||
dusk::speedrun::start();
|
||||
}
|
||||
}
|
||||
|
||||
toggleAutoSave(true);
|
||||
#endif
|
||||
mCompleteCheck = true;
|
||||
mMode = MODE_WAIT_e;
|
||||
|
||||
+290
-48
@@ -31,6 +31,8 @@
|
||||
#if TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/logging.h"
|
||||
#include "dusk/action_bindings.h"
|
||||
#include "imgui.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@@ -837,6 +839,12 @@ void dCamera_c::updatePad() {
|
||||
mTrigB = mDoCPd_c::getTrigB(mPadID) ? true : false;
|
||||
|
||||
#if TARGET_PC
|
||||
// If our custom action binding is triggered, and we're not already in first person, go into first person
|
||||
if (dusk::getActionBindTrig(dusk::ActionBinds::FIRST_PERSON_CAMERA, mPadID) && mGear != -1) {
|
||||
setComStat(0x1000);
|
||||
mGear = 0;
|
||||
}
|
||||
|
||||
if (mCamParam.mManualMode) {
|
||||
return;
|
||||
}
|
||||
@@ -876,7 +884,8 @@ void dCamera_c::updatePad() {
|
||||
|
||||
if (mPadInfo.mCStick.mLastPosY < -mCamSetup.mCStick.SwTHH()) {
|
||||
if (mCStickYState != -1) {
|
||||
if (mGear == -1 && mCurMode == 4) {
|
||||
// Don't use regular first person trigger if custom mapping is set
|
||||
if (mGear == -1 && mCurMode == 4 IF_DUSK(&& !dusk::isActionBound(dusk::ActionBinds::FIRST_PERSON_CAMERA, mPadID))) {
|
||||
mGear = 0;
|
||||
setComStat(0x2000);
|
||||
} else if (mGear == 0 && sp6C) {
|
||||
@@ -887,7 +896,8 @@ void dCamera_c::updatePad() {
|
||||
mCStickYState = -1;
|
||||
} else if (mPadInfo.mCStick.mLastPosY > mCamSetup.mCStick.SwTHH()) {
|
||||
if (mCStickYState != 1) {
|
||||
if (mGear == 0 && sp6B) {
|
||||
// Don't use regular first person trigger if custom mapping is set
|
||||
if (mGear == 0 && sp6B IF_DUSK(&& !dusk::isActionBound(dusk::ActionBinds::FIRST_PERSON_CAMERA, mPadID))) {
|
||||
setComStat(0x1000);
|
||||
} else if (mGear == 1) {
|
||||
mGear = 0;
|
||||
@@ -1040,6 +1050,11 @@ void dCamera_c::debugDrawInit() {
|
||||
bool dCamera_c::Run() {
|
||||
#if TARGET_PC
|
||||
ResetView();
|
||||
if (executeDebugFlyCam()) {
|
||||
mFrameCounter++;
|
||||
mTicks++;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
daAlink_c* link = daAlink_getAlinkActorClass();
|
||||
@@ -1175,6 +1190,12 @@ bool dCamera_c::Run() {
|
||||
clrFlag(0x200000);
|
||||
}
|
||||
} else {
|
||||
#if TARGET_PC
|
||||
if (mCamParam.Algorythmn(mCamStyle) != 1) {
|
||||
mCamParam.mManualMode = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
sp0F = (this->*engine_tbl[mCamParam.Algorythmn(mCamStyle)])(mCamStyle);
|
||||
|
||||
field_0x170++;
|
||||
@@ -1481,7 +1502,7 @@ void dCamera_c::CalcTrimSize() {
|
||||
mTrimHeight += -mTrimHeight * 0.25f;
|
||||
break;
|
||||
case 2:
|
||||
#if WIDESCREEN_SUPPORT
|
||||
#if !TARGET_PC && WIDESCREEN_SUPPORT
|
||||
if (mDoGph_gInf_c::isWide() && mDoGph_gInf_c::isWideZoom()) {
|
||||
mTrimHeight += (16.0f - mTrimHeight) * 0.25f;
|
||||
break;
|
||||
@@ -3089,10 +3110,6 @@ bool dCamera_c::bumpCheck(u32 i_flags) {
|
||||
field_0x968 *= mMonitor.field_0xc / 5.0f;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (!dusk::getSettings().game.freeCamera || !mCamParam.mManualMode) {
|
||||
#endif
|
||||
|
||||
f32 tmp = field_0x96c * (mIsWolf == 1 ? 30.0f : 30.0f);
|
||||
center += vec3.norm() * (tmp * globe.V().Sin());
|
||||
cSGlobe globe2(vec2 - center);
|
||||
@@ -3106,10 +3123,6 @@ bool dCamera_c::bumpCheck(u32 i_flags) {
|
||||
vec = lin_chk1.GetCross();
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
}
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
if (mCamSetup.CheckFlag(0x8000)) {
|
||||
dDbVw_Report(20, 235, " U");
|
||||
@@ -3520,12 +3533,6 @@ void dCamera_c::checkGroundInfo() {
|
||||
}
|
||||
|
||||
bool dCamera_c::chaseCamera(s32 param_0) {
|
||||
#if TARGET_PC
|
||||
if (freeCamera()) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static f32 JumpCushion = 0.9f;
|
||||
f32 charge_latitude = mCamSetup.ChargeLatitude();
|
||||
int charge_timer = mCamSetup.ChargeTimer();
|
||||
@@ -4207,6 +4214,11 @@ bool dCamera_c::chaseCamera(s32 param_0) {
|
||||
chase->field_0x8 -= chase->field_0xc;
|
||||
chase->field_0x8c = 0;
|
||||
chase->field_0x90 = false;
|
||||
|
||||
#if TARGET_PC
|
||||
freeCamera();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4644,6 +4656,11 @@ bool dCamera_c::chaseCamera(s32 param_0) {
|
||||
if (chase->field_0x1c != 0) {
|
||||
chase->field_0x1c--;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
freeCamera();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7091,10 +7108,12 @@ bool dCamera_c::subjectCamera(s32 param_0) {
|
||||
cXyz sp1E0(val0, val2, val1);
|
||||
|
||||
#if TARGET_PC
|
||||
f32 aspect = mDoGph_gInf_c::getAspect();
|
||||
f32 baseAspect = FB_WIDTH / FB_HEIGHT;
|
||||
if (aspect > baseAspect) {
|
||||
sp1E0.z += (aspect - baseAspect) * 4;
|
||||
if (sp13) {
|
||||
f32 aspect = mDoGph_gInf_c::getAspect();
|
||||
f32 baseAspect = FB_WIDTH / FB_HEIGHT;
|
||||
if (aspect > baseAspect) {
|
||||
sp1E0.z += (aspect - baseAspect) * 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7470,54 +7489,201 @@ bool dCamera_c::test2Camera(s32 param_0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr f32 FLYCAM_SPEED = 0.5f;
|
||||
static constexpr f32 FLYCAM_FAST_SPEED = 4.0f;
|
||||
static constexpr f32 FLYCAM_ROTATION_SPEED = 0.002f;
|
||||
static constexpr f32 FLYCAM_TRIGGER_DEADZONE = 20.0f;
|
||||
static constexpr s16 FLYCAM_ROLL_SPEED = 256;
|
||||
static ImVec2 sFlyCamLastMousePos = {-1.f, -1.f};
|
||||
|
||||
#if TARGET_PC
|
||||
bool dCamera_c::executeDebugFlyCam() {
|
||||
if (!dusk::getSettings().game.debugFlyCam) {
|
||||
if (mDebugFlyCam.initialized) {
|
||||
deactivateDebugFlyCam();
|
||||
}
|
||||
sFlyCamLastMousePos = {-1.f, -1.f};
|
||||
return false;
|
||||
}
|
||||
|
||||
dEvt_control_c* event = dComIfGp_getEvent();
|
||||
if (event == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mDebugFlyCam.initialized && (event->mEventStatus != 0 || dComIfGp_isPauseFlag())) {
|
||||
dusk::getSettings().game.debugFlyCam.setValue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mDebugFlyCam.initialized) {
|
||||
mDebugFlyCam.savedCenter = mCenter;
|
||||
mDebugFlyCam.savedEye = mEye;
|
||||
mDebugFlyCam.savedFovy = mFovy;
|
||||
mDebugFlyCam.savedBank = mBank;
|
||||
|
||||
f32 dx = mCenter.x - mEye.x;
|
||||
f32 dy = mCenter.y - mEye.y;
|
||||
f32 dz = mCenter.z - mEye.z;
|
||||
mDebugFlyCam.yaw = atan2f(dz, dx);
|
||||
f32 horizontal = sqrtf(dx * dx + dz * dz);
|
||||
mDebugFlyCam.pitch = atan2f(dy, horizontal);
|
||||
|
||||
mDebugFlyCam.initialized = true;
|
||||
}
|
||||
|
||||
if (dusk::getSettings().game.debugFlyCamLockEvents) {
|
||||
event->mEventStatus = 1;
|
||||
dComIfGp_getEventManager().setCameraPlay(1);
|
||||
} else {
|
||||
if (event->mEventStatus != 0) {
|
||||
event->mEventStatus = 0;
|
||||
}
|
||||
dComIfGp_getEventManager().setCameraPlay(0);
|
||||
}
|
||||
|
||||
f32 stickY = 0.f;
|
||||
f32 stickX = 0.f;
|
||||
f32 cStickY = 0.f;
|
||||
f32 cStickX = 0.f;
|
||||
f32 trigL = 0.f;
|
||||
f32 trigR = 0.f;
|
||||
f32 rollInput = 0.f;
|
||||
bool fast = false;
|
||||
|
||||
if (dusk::getSettings().game.debugFlyCamLockEvents) {
|
||||
interface_of_controller_pad& pad = mDoCPd_c::getCpadInfo(0);
|
||||
stickY = pad.mMainStickPosY * 72.0f;
|
||||
stickX = pad.mMainStickPosX * 72.0f;
|
||||
cStickY = pad.mCStickPosY * 59.0f;
|
||||
cStickX = pad.mCStickPosX * 59.0f;
|
||||
trigL = pad.mTriggerLeft * 150.0f;
|
||||
trigR = pad.mTriggerRight * 150.0f;
|
||||
fast = mDoCPd_c::getHoldZ(PAD_1);
|
||||
if (mDoCPd_c::getHoldY(PAD_1)) rollInput -= 1.f;
|
||||
if (mDoCPd_c::getHoldX(PAD_1)) rollInput += 1.f;
|
||||
}
|
||||
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (!io.WantCaptureKeyboard) {
|
||||
f32 kbX = 0.0f, kbY = 0.0f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_W) || ImGui::IsKeyDown(ImGuiKey_UpArrow)) kbY += 1.f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_S) || ImGui::IsKeyDown(ImGuiKey_DownArrow)) kbY -= 1.f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_D) || ImGui::IsKeyDown(ImGuiKey_RightArrow)) kbX += 1.f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_A) || ImGui::IsKeyDown(ImGuiKey_LeftArrow)) kbX -= 1.f;
|
||||
f32 len = sqrtf(kbX * kbX + kbY * kbY);
|
||||
if (len > 1.f) { kbX /= len; kbY /= len; }
|
||||
stickX += kbX * 72.0f;
|
||||
stickY += kbY * 72.0f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_Space)) trigR += 150.0f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) trigL += 150.0f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) fast = true;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_Q)) rollInput -= 1.0f;
|
||||
if (ImGui::IsKeyDown(ImGuiKey_E)) rollInput += 1.0f;
|
||||
}
|
||||
bool mouseValid = !io.WantCaptureMouse && io.MousePos.x >= 0.0f && io.MousePos.y >= 0.0f;
|
||||
if (mouseValid && sFlyCamLastMousePos.x >= 0.0f) {
|
||||
cStickX -= (io.MousePos.x - sFlyCamLastMousePos.x) * 2.0f;
|
||||
cStickY -= (io.MousePos.y - sFlyCamLastMousePos.y) * 2.0f;
|
||||
}
|
||||
sFlyCamLastMousePos = mouseValid ? io.MousePos : ImVec2{-1.0f, -1.0f};
|
||||
}
|
||||
|
||||
f32 verticalDisp = 0.0f;
|
||||
if (trigR >= FLYCAM_TRIGGER_DEADZONE) {
|
||||
verticalDisp += trigR;
|
||||
}
|
||||
if (trigL >= FLYCAM_TRIGGER_DEADZONE) {
|
||||
verticalDisp -= trigL;
|
||||
}
|
||||
|
||||
f32 moveDy = stickY * sinf(mDebugFlyCam.pitch) + verticalDisp;
|
||||
f32 moveDx = stickY * cosf(mDebugFlyCam.yaw) * cosf(mDebugFlyCam.pitch) - stickX * sinf(mDebugFlyCam.yaw);
|
||||
f32 moveDz = stickY * sinf(mDebugFlyCam.yaw) * cosf(mDebugFlyCam.pitch) + stickX * cosf(mDebugFlyCam.yaw);
|
||||
|
||||
f32 speed = fast ? FLYCAM_FAST_SPEED : FLYCAM_SPEED;
|
||||
|
||||
mEye.x += speed * moveDx;
|
||||
mEye.y += speed * moveDy;
|
||||
mEye.z += speed * moveDz;
|
||||
|
||||
static constexpr f32 FLYCAM_TARGET_DIST = 100.0f;
|
||||
mCenter.x = mEye.x + cosf(mDebugFlyCam.yaw) * cosf(mDebugFlyCam.pitch) * FLYCAM_TARGET_DIST;
|
||||
mCenter.z = mEye.z + sinf(mDebugFlyCam.yaw) * cosf(mDebugFlyCam.pitch) * FLYCAM_TARGET_DIST;
|
||||
mCenter.y = mEye.y + sinf(mDebugFlyCam.pitch) * FLYCAM_TARGET_DIST;
|
||||
|
||||
mBank = mBank + static_cast<s16>(rollInput * FLYCAM_ROLL_SPEED * (fast ? FLYCAM_FAST_SPEED / FLYCAM_SPEED : 1.f));
|
||||
Reset(mCenter, mEye);
|
||||
|
||||
f32 yawInput = dusk::getSettings().game.invertCameraXAxis ? cStickX : -cStickX;
|
||||
mDebugFlyCam.yaw += yawInput * FLYCAM_ROTATION_SPEED;
|
||||
mDebugFlyCam.yaw = fmodf(mDebugFlyCam.yaw + 2.0f * (f32)M_PI, 2.0f * (f32)M_PI);
|
||||
|
||||
f32 maxPitch = (f32)M_PI / 2.0f - 0.1f;
|
||||
f32 minPitch = -(f32)M_PI / 2.0f + 0.1f;
|
||||
mDebugFlyCam.pitch = std::clamp(mDebugFlyCam.pitch + cStickY * FLYCAM_ROTATION_SPEED, minPitch, maxPitch);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dCamera_c::deactivateDebugFlyCam() {
|
||||
Reset(mDebugFlyCam.savedCenter, mDebugFlyCam.savedEye, mDebugFlyCam.savedFovy, mDebugFlyCam.savedBank.Val());
|
||||
|
||||
dEvt_control_c* event = dComIfGp_getEvent();
|
||||
if (event != nullptr && event->mEventStatus != 0) {
|
||||
event->mEventStatus = 0;
|
||||
}
|
||||
dComIfGp_getEventManager().setCameraPlay(0);
|
||||
mDebugFlyCam.initialized = false;
|
||||
}
|
||||
|
||||
bool dCamera_c::freeCamera() {
|
||||
if (!dusk::getSettings().game.freeCamera) {
|
||||
if (dusk::getSettings().game.freeCamera && mGear == 1) {
|
||||
mGear = 0;
|
||||
}
|
||||
|
||||
if (!dusk::getSettings().game.freeCamera || mCamStyle == 70)
|
||||
{
|
||||
mCamParam.mManualMode = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
mCamParam.freeXAngle = mViewCache.mDirection.mAzimuth.Degree();
|
||||
mCamParam.freeYAngle = mViewCache.mDirection.mInclination.Degree();
|
||||
if (!mCamParam.mManualMode) {
|
||||
mCamParam.freeXAngle = mViewCache.mDirection.mAzimuth.Degree();
|
||||
mCamParam.freeYAngle = mViewCache.mDirection.mInclination.Degree();
|
||||
}
|
||||
|
||||
cXyz camMovement = {mPadInfo.mCStick.mLastPosX, mPadInfo.mCStick.mLastPosY, 0.0f};
|
||||
f32 magnitude = sqrt(mPadInfo.mCStick.mLastPosX * mPadInfo.mCStick.mLastPosX + mPadInfo.mCStick.mLastPosY * mPadInfo.mCStick.mLastPosY);
|
||||
|
||||
if (mPadInfo.mCStick.mLastPosX != 0 || mPadInfo.mCStick.mLastPosY != 0) {
|
||||
if (!mCamParam.mManualMode) {
|
||||
mCamParam.mManualMode = 1;
|
||||
mCamParam.freeXAngle = mViewCache.mDirection.mAzimuth.Degree();
|
||||
mCamParam.freeYAngle = mViewCache.mDirection.mInclination.Degree();
|
||||
}
|
||||
|
||||
// If we aren't in manual cam mode, don't trigger it if the player tries to hit C-up
|
||||
// for first person unless they have first person bound to a custom binding
|
||||
if ((dusk::isActionBound(dusk::ActionBinds::FIRST_PERSON_CAMERA, mPadID) && mPadInfo.mCStick.mLastPosY != 0) ||
|
||||
mPadInfo.mCStick.mLastPosX != 0 || mPadInfo.mCStick.mLastPosY < 0 || (mCamParam.mManualMode == 1 && mPadInfo.mCStick.mLastPosY != 0))
|
||||
{
|
||||
mCamParam.mManualMode = 1;
|
||||
camMovement = camMovement.normalize();
|
||||
camMovement.y *= dusk::getSettings().game.invertCameraYAxis ? 1.0f : -1.0f;
|
||||
mCamParam.freeXAngle += camMovement.x * magnitude * dusk::getSettings().game.freeCameraSensitivity * 4.0f;
|
||||
mCamParam.freeYAngle += camMovement.y * magnitude * dusk::getSettings().game.freeCameraSensitivity * 4.0f;
|
||||
mCamParam.freeXAngle += camMovement.x * magnitude * dusk::getSettings().game.freeCameraSensitivity * 5.0f;
|
||||
mCamParam.freeYAngle += camMovement.y * magnitude * dusk::getSettings().game.freeCameraSensitivity * 5.0f;
|
||||
}
|
||||
|
||||
if (!mCamParam.mManualMode) {
|
||||
fopAc_ac_c* player = dComIfGp_getPlayer(0);
|
||||
if (!mCamParam.mManualMode || player == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
f32 minYAngle = -10.0f;
|
||||
f32 minYAngle = -30.0f;
|
||||
f32 maxAngle = 50.0f;
|
||||
|
||||
mCamParam.freeYAngle = std::clamp(mCamParam.freeYAngle, minYAngle, maxAngle);
|
||||
mViewCache.mDirection.mAzimuth = cSAngle(mCamParam.freeXAngle);
|
||||
mViewCache.mDirection.mInclination = cSAngle(mCamParam.freeYAngle);
|
||||
f32 currentLerp = (mCamParam.freeYAngle - minYAngle) / (maxAngle - minYAngle);
|
||||
mViewCache.mDirection.mRadius = std::lerp(200.0f, 1000.0f, currentLerp);
|
||||
|
||||
cXyz finalCenter = mpPlayerActor->current.pos;
|
||||
finalCenter.y += mIsWolf ? 90.0f : 100.0f;
|
||||
mViewCache.mCenter = finalCenter;
|
||||
|
||||
cXyz finalEye = finalCenter + mViewCache.mDirection.Xyz();
|
||||
cXyz finalEye = mViewCache.mCenter + mViewCache.mDirection.Xyz();
|
||||
mViewCache.mEye = finalEye;
|
||||
|
||||
mViewCache.mFovy = 60.0f;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -11078,6 +11244,62 @@ cXyz dCamera_c::Center() {
|
||||
return mCenter + mShake.field_0x24;
|
||||
}
|
||||
|
||||
#ifdef TARGET_PC
|
||||
f32 get_target_trim_height(camera_process_class* i_this) {
|
||||
const auto camera = &i_this->mCamera;
|
||||
if (camera->mCurState != 2) {
|
||||
switch (camera->mTrimSize) {
|
||||
case 0:
|
||||
case 4:
|
||||
return 0.0f;
|
||||
case 1:
|
||||
return camera->mCamSetup.VistaTrimHeight();
|
||||
case 2:
|
||||
case 3:
|
||||
return camera->mCamSetup.CinemaScopeTrimHeight();
|
||||
default:
|
||||
return camera->mTrimHeight;
|
||||
}
|
||||
}
|
||||
return camera->mTrimHeight;
|
||||
}
|
||||
|
||||
void widezoom_correction(camera_process_class* i_this, float trim_height) {
|
||||
camera_class* camera = (camera_class*)i_this;
|
||||
dDlst_window_c* window = get_window(camera);
|
||||
view_port_class* viewport = window->getViewPort();
|
||||
|
||||
auto trim_width = 0.0f;
|
||||
|
||||
if (mDoGph_gInf_c::isWideZoom()) {
|
||||
const auto target_ar = FB_WIDTH_BASE / (FB_HEIGHT_BASE - trim_height * 2.0f);
|
||||
const auto target_ar_real =
|
||||
FB_WIDTH_BASE / (FB_HEIGHT_BASE - get_target_trim_height(i_this) * 2.0f);
|
||||
const auto current_ar = camera->view.aspect;
|
||||
|
||||
if (current_ar < target_ar) {
|
||||
trim_height = FB_HEIGHT_BASE / 2.0f * (1.0f - current_ar / target_ar);
|
||||
} else {
|
||||
trim_height = 0.0f;
|
||||
trim_width = FB_WIDTH_BASE / 2.0f * (1.0f - target_ar_real / current_ar);
|
||||
}
|
||||
|
||||
if (dusk::frame_interp::is_sim_frame()) {
|
||||
constexpr auto base_ar =
|
||||
static_cast<f32>(FB_WIDTH_BASE) / static_cast<f32>(FB_HEIGHT_BASE);
|
||||
const auto ar_corr = base_ar / std::min(current_ar, target_ar_real);
|
||||
camera->view.fovy =
|
||||
MTXRadToDeg(2.0f * atanf(tanf(MTXDegToRad(camera->view.fovy) * 0.5f) * ar_corr));
|
||||
}
|
||||
}
|
||||
|
||||
trim_width *= viewport->width / FB_WIDTH_BASE;
|
||||
trim_height *= viewport->height / FB_HEIGHT_BASE;
|
||||
window->setScissor(trim_width, trim_height, viewport->width - trim_width * 2.0f,
|
||||
viewport->height - trim_height * 2.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int camera_execute(camera_process_class* i_this) {
|
||||
preparation(i_this);
|
||||
|
||||
@@ -11098,6 +11320,28 @@ static int camera_execute(camera_process_class* i_this) {
|
||||
store(i_this);
|
||||
|
||||
#ifdef TARGET_PC
|
||||
widezoom_correction(i_this, i_this->mCamera.TrimHeight());
|
||||
|
||||
if (dusk::getSettings().game.enableFrameInterpolation) {
|
||||
dusk::frame_interp::add_interpolation_callback([](bool _, void* pUserWork) {
|
||||
const auto i_this = static_cast<camera_process_class*>(pUserWork);
|
||||
const auto camera = &i_this->mCamera;
|
||||
|
||||
const auto trim_size = camera->mTrimSize;
|
||||
|
||||
if (camera->mCurState != 2 && trim_size >= 0 && trim_size <= 3) {
|
||||
// derive trim height at previous tick using current camera state
|
||||
const auto target = get_target_trim_height(i_this);
|
||||
const auto step = dusk::frame_interp::get_interpolation_step();
|
||||
const auto cur = camera->TrimHeight();
|
||||
const auto prev = (4.0f * cur - target) / 3.0f;
|
||||
const auto trim_height = prev + (cur - prev) * step;
|
||||
|
||||
widezoom_correction(i_this, trim_height);
|
||||
}
|
||||
}, i_this);
|
||||
}
|
||||
|
||||
// record new camera for our sim frame
|
||||
dusk::frame_interp::record_camera(i_this, get_camera_id(i_this));
|
||||
// interpolate the view now so that this sim frame's view matrix matches what
|
||||
@@ -11161,12 +11405,10 @@ static int camera_draw(camera_process_class* i_this) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !TARGET_PC
|
||||
// trim handling moved to camera_execute for PC
|
||||
int trim_height = body->TrimHeight();
|
||||
|
||||
#if TARGET_PC
|
||||
trim_height *= viewport->height / FB_HEIGHT;
|
||||
window->setScissor(0.0f, trim_height, viewport->width, viewport->height - trim_height * 2.0f);
|
||||
#else
|
||||
window->setScissor(0.0f, trim_height, FB_WIDTH, FB_HEIGHT - trim_height * 2.0f);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "d/d_s_play.h"
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "f_op/f_op_actor_mng.h"
|
||||
#if TARGET_PC
|
||||
#include "dusk/achievements.h"
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
static int plCutLRC[58] = {
|
||||
0, //
|
||||
@@ -426,6 +430,13 @@ fopAc_ac_c* cc_at_check(fopAc_ac_c* i_enemy, dCcU_AtInfo* i_AtInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.invincibleEnemies &&
|
||||
fopAcM_GetGroup(i_enemy) == fopAc_ENEMY_e) {
|
||||
i_AtInfo->mAttackPower = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (i_AtInfo->mAttackPower != 0) {
|
||||
i_enemy->health -= i_AtInfo->mAttackPower;
|
||||
}
|
||||
@@ -434,6 +445,11 @@ fopAc_ac_c* cc_at_check(fopAc_ac_c* i_enemy, dCcU_AtInfo* i_AtInfo) {
|
||||
if (i_AtInfo->mAttackPower != 0 && i_enemy->health <= 0) {
|
||||
i_AtInfo->mHitStatus = 2;
|
||||
i_enemy->health = 0;
|
||||
#if TARGET_PC
|
||||
if (fopAcM_GetGroup(i_enemy) == fopAc_ENEMY_e) {
|
||||
dusk::AchievementSystem::get().signal("enemy_killed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int uvar8;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "d/d_timer.h"
|
||||
#include "f_op/f_op_msg_mng.h"
|
||||
#include "f_op/f_op_scene_mng.h"
|
||||
#include "m_Do/m_Do_MemCard.h"
|
||||
#include "m_Do/m_Do_Reset.h"
|
||||
#include "m_Do/m_Do_controller_pad.h"
|
||||
#include "m_Do/m_Do_graphic.h"
|
||||
@@ -1238,6 +1239,13 @@ BOOL dComIfG_resetToOpening(scene_class* i_scene) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_PC
|
||||
if (!mDoMemCd_isCardCommNone()) {
|
||||
return 0;
|
||||
}
|
||||
g_mDoMemCd_control.SaveSync();
|
||||
#endif
|
||||
|
||||
dComIfG_changeOpeningScene(i_scene, fpcNm_OPENING_SCENE_e);
|
||||
mDoAud_bgmStop(30);
|
||||
mDoAud_resetProcess();
|
||||
|
||||
@@ -11,6 +11,62 @@
|
||||
#include "JSystem/JGadget/define.h"
|
||||
#include <cstring>
|
||||
|
||||
#include "dusk/logging.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/ui/ui.hpp"
|
||||
|
||||
namespace {
|
||||
static int sJaiSkip = -1;
|
||||
|
||||
static JSUList<JAIStream>* get_stream_list() {
|
||||
return Z2GetSoundMgr()->getStreamMgr()->getStreamList();
|
||||
}
|
||||
|
||||
static int get_stream_count(JSUList<JAIStream>* list) {
|
||||
int i = 0;
|
||||
for (JSULink<JAIStream>* l = list != nullptr ? list->getFirst() : nullptr; l != nullptr;
|
||||
l = l->getNext()) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static void pause_stream(int skip_first, bool paused) {
|
||||
int i = 0;
|
||||
JSUList<JAIStream>* list = get_stream_list();
|
||||
for (JSULink<JAIStream>* l = list->getFirst(); l != nullptr; l = l->getNext(), ++i) {
|
||||
if (i >= skip_first) {
|
||||
l->getObject()->pause(paused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pause_streams(int skip_first) {
|
||||
if (!dusk::ui::is_prelaunch_open()) {
|
||||
return;
|
||||
}
|
||||
JSUList<JAIStream>* list = get_stream_list();
|
||||
if (list == nullptr || get_stream_count(list) <= skip_first) {
|
||||
return;
|
||||
}
|
||||
pause_stream(skip_first, true);
|
||||
sJaiSkip = skip_first;
|
||||
}
|
||||
|
||||
static void unpause_streams(bool require_prelaunch_hidden) {
|
||||
if (sJaiSkip < 0) {
|
||||
return;
|
||||
}
|
||||
if (require_prelaunch_hidden && dusk::ui::is_prelaunch_open()) {
|
||||
return;
|
||||
}
|
||||
pause_stream(sJaiSkip, false);
|
||||
sJaiSkip = -1;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
s16 dDemo_c::m_branchId = -1;
|
||||
|
||||
namespace {
|
||||
@@ -1006,7 +1062,16 @@ int dDemo_c::start(u8 const* p_data, cXyz* p_translation, f32 rotationY) {
|
||||
m_control->setSuspend(0);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
const int existing_streams = get_stream_count(get_stream_list());
|
||||
#endif
|
||||
|
||||
m_control->forward(0);
|
||||
|
||||
#if TARGET_PC
|
||||
pause_streams(existing_streams);
|
||||
#endif
|
||||
|
||||
m_translation = p_translation;
|
||||
|
||||
if (m_translation != NULL) {
|
||||
@@ -1034,6 +1099,10 @@ static void dummyString2() {
|
||||
void dDemo_c::end() {
|
||||
JUT_ASSERT(1956, m_system != NULL);
|
||||
|
||||
#if TARGET_PC
|
||||
unpause_streams(false);
|
||||
#endif
|
||||
|
||||
m_control->destroyObject_all();
|
||||
m_object->remove();
|
||||
m_data = NULL;
|
||||
@@ -1054,6 +1123,10 @@ void dDemo_c::branch() {
|
||||
int dDemo_c::update() {
|
||||
JUT_ASSERT(2064, m_system != NULL);
|
||||
|
||||
#if TARGET_PC
|
||||
unpause_streams(true);
|
||||
#endif
|
||||
|
||||
if (m_data == NULL) {
|
||||
if (m_branchData == NULL) {
|
||||
return 0;
|
||||
|
||||
+45
-9
@@ -22,6 +22,10 @@
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/gx_helper.h"
|
||||
#include "dusk/logging.h"
|
||||
|
||||
static const void* getInterpKey(const void* base, int idx) {
|
||||
return reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(base) ^ idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
class dDlst_2Dm_c {
|
||||
@@ -1062,7 +1066,15 @@ void dDlst_shadowReal_c::reset() {
|
||||
}
|
||||
|
||||
void dDlst_shadowReal_c::imageDraw(Mtx param_0) {
|
||||
GXSetProjection(mRenderProjMtx, GX_ORTHOGRAPHIC);
|
||||
#ifdef TARGET_PC
|
||||
Mtx render_proj_mtx;
|
||||
if (dusk::frame_interp::lookup_replacement(getInterpKey(mpModels[0], 2), render_proj_mtx)) {
|
||||
GXSetProjection(render_proj_mtx, GX_ORTHOGRAPHIC);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
GXSetProjection(mRenderProjMtx, GX_ORTHOGRAPHIC);
|
||||
}
|
||||
JUT_ASSERT(1916, mModelNum);
|
||||
J3DModelData* model_data;
|
||||
J3DModel** models = mpModels;
|
||||
@@ -1075,7 +1087,15 @@ void dDlst_shadowReal_c::imageDraw(Mtx param_0) {
|
||||
for (u16 j = 0; j < model_data->getShapeNum(); j++) {
|
||||
if (!model_data->getShapeNodePointer(j)->checkFlag(1)) {
|
||||
shape_pkt = (*models)->getShapePacket(j);
|
||||
shape_pkt->setBaseMtxPtr(&mViewMtx);
|
||||
#ifdef TARGET_PC
|
||||
Mtx view_mtx;
|
||||
if (dusk::frame_interp::lookup_replacement(getInterpKey(mpModels[0], 1), view_mtx)) {
|
||||
shape_pkt->setBaseMtxPtr(&view_mtx);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
shape_pkt->setBaseMtxPtr(&mViewMtx);
|
||||
}
|
||||
shape_pkt->drawFast();
|
||||
shape_pkt->setBaseMtxPtr((Mtx*)param_0);
|
||||
}
|
||||
@@ -1096,7 +1116,18 @@ void dDlst_shadowReal_c::draw() {
|
||||
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
|
||||
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
||||
GXSetCurrentMtx(GX_PNMTX0);
|
||||
GXLoadTexMtxImm(mReceiverProjMtx, GX_TEXMTX0, GX_MTX3x4);
|
||||
#ifdef TARGET_PC
|
||||
Mtx view_mtx, recv_proj_mtx;
|
||||
const auto have_view_mtx = dusk::frame_interp::lookup_replacement(getInterpKey(mpModels[0], 1), view_mtx);
|
||||
const auto have_recv_proj_mtx = dusk::frame_interp::lookup_replacement(getInterpKey(mpModels[0], 3), recv_proj_mtx);
|
||||
if (have_view_mtx && have_recv_proj_mtx) {
|
||||
cMtx_concat(recv_proj_mtx, view_mtx, recv_proj_mtx);
|
||||
GXLoadTexMtxImm(recv_proj_mtx, GX_TEXMTX0, GX_MTX3x4);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
GXLoadTexMtxImm(mReceiverProjMtx, GX_TEXMTX0, GX_MTX3x4);
|
||||
}
|
||||
mShadowRealPoly.draw();
|
||||
}
|
||||
|
||||
@@ -1253,6 +1284,13 @@ u8 dDlst_shadowReal_c::setShadowRealMtx(cXyz* param_0, cXyz* param_1, f32 param_
|
||||
cMtx_lookAt(mViewMtx, &local_64, param_1, 0);
|
||||
C_MTXOrtho(mRenderProjMtx, param_2, -param_2, -param_2, param_2, 1.0f, 10000.0f);
|
||||
C_MTXLightOrtho(mReceiverProjMtx, param_2, -param_2, -param_2, param_2, 0.5f, -0.5f, 0.5f, 0.5f);
|
||||
|
||||
#ifdef TARGET_PC
|
||||
const auto keybase = mpModels[0];
|
||||
dusk::frame_interp::record_final_mtx(mViewMtx, getInterpKey(keybase, 1));
|
||||
dusk::frame_interp::record_final_mtx(mRenderProjMtx, getInterpKey(keybase, 2));
|
||||
dusk::frame_interp::record_final_mtx(mReceiverProjMtx, getInterpKey(keybase, 3));
|
||||
#endif
|
||||
cMtx_concat(mReceiverProjMtx, mViewMtx, mReceiverProjMtx);
|
||||
return r29;
|
||||
}
|
||||
@@ -1277,6 +1315,10 @@ u32 dDlst_shadowReal_c::set(u32 i_key, J3DModel* i_model, cXyz* param_2, f32 par
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TARGET_PC
|
||||
// provide a stable key for interpolation
|
||||
mpModels[0] = i_model;
|
||||
#endif
|
||||
field_0x1 = setShadowRealMtx(&sp60, param_2, param_3, param_4, param_7, param_5);
|
||||
|
||||
if (!field_0x1) {
|
||||
@@ -1370,12 +1412,6 @@ void dDlst_shadowSimple_c::draw() {
|
||||
GXCallDisplayList(l_shadowVolumeDL, 0x40);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static const void* getInterpKey(const void* base, int idx) {
|
||||
return reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(base) ^ idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
void dDlst_shadowSimple_c::set(cXyz* param_0, f32 param_1, f32 param_2, cXyz* param_3,
|
||||
s16 param_4, f32 param_5, TGXTexObj* param_6) {
|
||||
if (param_5 < 0.0f) {
|
||||
|
||||
@@ -3882,7 +3882,11 @@ bool dCamera_c::hintTalkEvCamera() {
|
||||
|
||||
cSAngle acStack_1fc(20.0f);
|
||||
for (i = 0; i < 2; i++) {
|
||||
#if AVOID_UB
|
||||
for (j = 0; j < 10; j++) {
|
||||
#else
|
||||
for (j = 0; j < 12; j++) {
|
||||
#endif
|
||||
cSAngle acStack_200(local_b0[j] * fVar22);
|
||||
hintTalk->mDirection.U(acStack_1f8 + acStack_200);
|
||||
hintTalk->mDirection.V(((hintTalk->field_0x28.V() * acStack_200.Cos()) * 0.2f) + acStack_1fc);
|
||||
|
||||
+10
-1
@@ -36,6 +36,7 @@
|
||||
#include "dusk/imgui/ImGuiBloomWindow.hpp"
|
||||
#include "dusk/settings.h"
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include "dusk/game_clock.h"
|
||||
#endif
|
||||
|
||||
static void GxXFog_set();
|
||||
@@ -2268,6 +2269,7 @@ void dKy_calc_color_set(GXColorS10* out_color_p, color_RGB_class* color_a_start_
|
||||
color_b_start_p->b, color_b_end_p->b, blend_ratio, add_col.b, scale);
|
||||
}
|
||||
|
||||
|
||||
void dScnKy_env_light_c::setLight() {
|
||||
f32 color_ratio;
|
||||
|
||||
@@ -2513,7 +2515,14 @@ void dScnKy_env_light_c::setLight() {
|
||||
static s16 S_fuwan_sin;
|
||||
|
||||
f32 sin = cM_ssin(S_fuwan_sin);
|
||||
S_fuwan_sin += (s16)cM_rndF(2000.0f) + 500;
|
||||
|
||||
#if TARGET_PC
|
||||
const f32 deltaTime = dusk::game_clock::consume_interval(this);
|
||||
const f32 timeScale = deltaTime / dusk::game_clock::period_for_original_frames(1.0f);
|
||||
S_fuwan_sin += (s16)((cM_rndF(2000.0f) + 500) * timeScale);
|
||||
#else
|
||||
S_fuwan_sin += (s16)cM_rndF(2000.0f) + 500;
|
||||
#endif
|
||||
|
||||
blure_size += (u8)(sin * (0.2f * blure_size));
|
||||
}
|
||||
|
||||
+26
-1
@@ -152,7 +152,7 @@ u8 STControl::checkTrigger() {
|
||||
field_0x22 = -field_0x24;
|
||||
}
|
||||
}
|
||||
|
||||
#if !TARGET_PC
|
||||
if (!(mDirectionTrig & 3)) {
|
||||
Xinit();
|
||||
}
|
||||
@@ -160,10 +160,35 @@ u8 STControl::checkTrigger() {
|
||||
if (!(mDirectionTrig & 0xC)) {
|
||||
Yinit();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
mDirectionTrig = 0;
|
||||
#if !TARGET_PC
|
||||
Xinit();
|
||||
Yinit();
|
||||
#endif
|
||||
#if TARGET_PC
|
||||
if (mDoCPd_c::getHoldLeft(PAD_1)) {
|
||||
mDirectionTrig |= TRIG_LEFT;
|
||||
}
|
||||
if (mDoCPd_c::getHoldRight(PAD_1)) {
|
||||
mDirectionTrig |= TRIG_RIGHT;
|
||||
}
|
||||
if (mDoCPd_c::getHoldUp(PAD_1)) {
|
||||
mDirectionTrig |= TRIG_UP;
|
||||
}
|
||||
if (mDoCPd_c::getHoldDown(PAD_1)) {
|
||||
mDirectionTrig |= TRIG_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(mDirectionTrig & 3)) {
|
||||
Xinit();
|
||||
}
|
||||
|
||||
if (!(mDirectionTrig & 0xC)) {
|
||||
Yinit();
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((field_0x0d & mDirectionTrig & 3) && field_0x0e > 0) {
|
||||
|
||||
+18
-4
@@ -1141,6 +1141,9 @@ dMap_c::dMap_c(int width, int height, int param_2, int param_3) {
|
||||
field_0x91 = 0;
|
||||
m_mySelfPointer = this;
|
||||
#endif
|
||||
#if TARGET_PC
|
||||
previousMirror = dusk::getSettings().game.enableMirrorMode;
|
||||
#endif
|
||||
|
||||
m_res = JKR_NEW_ARGS (0x20) dMap_prm_res_s;
|
||||
JUT_ASSERT(2559, m_res != NULL);
|
||||
@@ -1579,6 +1582,17 @@ bool dMap_c::isDrawRoomIcon(int param_0, int param_1) const {
|
||||
}
|
||||
|
||||
void dMap_c::_move(f32 i_centerX, f32 i_centerZ, int i_roomNo, f32 param_3) {
|
||||
#if TARGET_PC
|
||||
bool currentMirror = dusk::getSettings().game.enableMirrorMode;
|
||||
if (currentMirror != previousMirror) {
|
||||
previousMirror = currentMirror;
|
||||
if (currentMirror) {
|
||||
mCenterX -= 2.0f * mPackX;
|
||||
} else {
|
||||
mCenterX += 2.0f * mPackX;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (mStayRoomNo == -1) {
|
||||
mStayRoomNo = i_roomNo;
|
||||
field_0x80 = mStayRoomNo;
|
||||
@@ -1595,7 +1609,7 @@ void dMap_c::_move(f32 i_centerX, f32 i_centerZ, int i_roomNo, f32 param_3) {
|
||||
calcMapCmPerTexel(field_0x80, &field_0x58);
|
||||
getPack(field_0x80, &mPackX, &mPackZ);
|
||||
|
||||
mCenterX += mPackX;
|
||||
mCenterX += IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -mPackX :) mPackX;
|
||||
mCenterZ -= mPackZ;
|
||||
mCenterX += field_0x64;
|
||||
mCenterZ += mPackPlusZ;
|
||||
@@ -1657,7 +1671,7 @@ void dMap_c::_move(f32 i_centerX, f32 i_centerZ, int i_roomNo, f32 param_3) {
|
||||
calcMapCmPerTexel(field_0x80, &field_0x58);
|
||||
getPack(field_0x80, &mPackX, &mPackZ);
|
||||
|
||||
mCenterX += mPackX;
|
||||
mCenterX += IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -mPackX :) mPackX;
|
||||
mCenterZ -= mPackZ;
|
||||
}
|
||||
break;
|
||||
@@ -1737,7 +1751,7 @@ void dMap_c::_move(f32 i_centerX, f32 i_centerZ, int i_roomNo, f32 param_3) {
|
||||
calcMapCmPerTexel(field_0x80, &field_0x58);
|
||||
getPack(field_0x80, &mPackX, &mPackZ);
|
||||
|
||||
mCenterX += mPackX;
|
||||
mCenterX += IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -mPackX :) mPackX;
|
||||
mCenterZ -= mPackZ;
|
||||
field_0x8f = 4;
|
||||
#if DEBUG
|
||||
@@ -1829,7 +1843,7 @@ void dMap_c::_move(f32 i_centerX, f32 i_centerZ, int i_roomNo, f32 param_3) {
|
||||
|
||||
sp14 += temp_f31_2 * (spC - sp14);
|
||||
sp10 += temp_f31_2 * (sp8 - sp10);
|
||||
mCenterX += sp14;
|
||||
mCenterX += IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -sp14 :) sp14;
|
||||
mCenterZ -= sp10;
|
||||
break;
|
||||
}
|
||||
|
||||
+134
-1
@@ -15,12 +15,47 @@
|
||||
#include <cstring>
|
||||
|
||||
#ifdef TARGET_PC
|
||||
#include <span>
|
||||
#include <numbers>
|
||||
#include <array>
|
||||
|
||||
constexpr u16 kMapResolutionMultiplier = 4;
|
||||
constexpr u16 kMapImageSide = 16 * kMapResolutionMultiplier;
|
||||
constexpr u32 kMapImageTotalPixels = kMapImageSide * kMapImageSide;
|
||||
|
||||
typedef std::function<u8(size_t, size_t)> PaintI8Fn;
|
||||
|
||||
void paint_i8(std::span<u8> dst, size_t width, PaintI8Fn paint) {
|
||||
const auto blocksAcross = width >> 3;
|
||||
|
||||
for (size_t i = 0; i < dst.size(); i++) {
|
||||
// 8x4 block swizzling for I8
|
||||
const auto blockIdx = i >> 5;
|
||||
const auto localIdx = i & 31;
|
||||
|
||||
const auto blockY = blockIdx / blocksAcross;
|
||||
const auto blockX = blockIdx % blocksAcross;
|
||||
|
||||
const auto localY = localIdx >> 3;
|
||||
const auto localX = localIdx & 7;
|
||||
|
||||
const auto x = (blockX << 3) + localX;
|
||||
const auto y = (blockY << 2) + localY;
|
||||
|
||||
dst[i] = paint(x, y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void dMpath_n::dTexObjAggregate_c::create() {
|
||||
static int const data[7] = {
|
||||
79, 80, 77, 78, 76, 81, 82,
|
||||
79, // 0: im_map_icon_square_4i.bti
|
||||
80, // 1: im_map_icon_tresurebox_4i.bti
|
||||
77, // 2: im_map_icon_enter_4i.bti
|
||||
78, // 3: im_map_icon_nijumaru_4i.bti
|
||||
76, // 4: im_map_icon_circle_4i.bti
|
||||
81, // 5: im_map_icon_try_force_4i.bti
|
||||
82, // 6: map_icon_circle16x16_4i.bti
|
||||
};
|
||||
|
||||
for (int lp1 = 0; lp1 < 7; lp1++) {
|
||||
@@ -32,6 +67,104 @@ void dMpath_n::dTexObjAggregate_c::create() {
|
||||
JUT_ASSERT(74, image->magFilter == GX_NEAR);
|
||||
mDoLib_setResTimgObj(image, mp_texObj[lp1], 0, NULL);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
static bool hqTexsDrawn = false;
|
||||
|
||||
static u8 hqCircleData[kMapImageTotalPixels];
|
||||
static u8 hqCircleAltData[kMapImageTotalPixels];
|
||||
static u8 hqNijumaruData[kMapImageTotalPixels];
|
||||
static u8 hqEnterData[kMapImageTotalPixels];
|
||||
static u8 hqTryForceData[kMapImageTotalPixels];
|
||||
|
||||
if (!hqTexsDrawn) {
|
||||
constexpr auto center = kMapImageSide / 2.0f;
|
||||
constexpr auto radiusSq = center * center;
|
||||
|
||||
// 6: map_icon_circle16x16_4i.bti - simple circle
|
||||
paint_i8(std::span{hqCircleData}, kMapImageSide, [=](auto x, auto y) {
|
||||
const auto dx = (x + 0.5f) - center;
|
||||
const auto dy = (y + 0.5f) - center;
|
||||
return (dx * dx + dy * dy < radiusSq) ? 0x11 : 0;
|
||||
});
|
||||
|
||||
// 4: im_map_icon_circle_4i.bti - outlined circle
|
||||
paint_i8(std::span{hqCircleAltData}, kMapImageSide, [=](auto x, auto y) {
|
||||
constexpr auto innerRadius = kMapImageSide * 3.0f / 8.0f;
|
||||
constexpr auto innerRadiusSq = innerRadius * innerRadius;
|
||||
|
||||
const auto dx = (x + 0.5f) - center;
|
||||
const auto dy = (y + 0.5f) - center;
|
||||
const auto dSq = dx * dx + dy * dy;
|
||||
|
||||
return dSq < radiusSq ? (dSq < innerRadiusSq ? 0x22 : 0x11) : 0;
|
||||
});
|
||||
|
||||
// 3: im_map_icon_nijumaru_4i.bti - concentric rings
|
||||
paint_i8(std::span{hqNijumaruData}, kMapImageSide, [=](auto x, auto y) {
|
||||
constexpr u8 nijumaruRings[] = {0x11, 0x22, 0x11, 0x11, 0x22, 0x22};
|
||||
|
||||
const auto dx = (x + 0.5f) - center;
|
||||
const auto dy = (y + 0.5f) - center;
|
||||
const auto dSq = dx * dx + dy * dy;
|
||||
|
||||
if (dSq < radiusSq) {
|
||||
const auto ringIndex =
|
||||
static_cast<size_t>(std::trunc(std::sqrt(dSq) / kMapImageSide * 12));
|
||||
return nijumaruRings[ringIndex];
|
||||
}
|
||||
return u8{0};
|
||||
});
|
||||
|
||||
// 2: im_map_icon_enter_4i.bti - outlined octagram
|
||||
paint_i8(std::span{hqEnterData}, kMapImageSide, [=](auto x, auto y) {
|
||||
constexpr auto outlineWidth = kMapImageSide / 6.0f;
|
||||
|
||||
const auto adx = std::abs((x + 0.5f) - center);
|
||||
const auto ady = std::abs((y + 0.5f) - center);
|
||||
const auto dist =
|
||||
std::min(adx + ady, std::max(adx, ady) * std::numbers::sqrt2_v<float>) -
|
||||
kMapImageSide / 2.0f;
|
||||
|
||||
return dist > 0.0f ? 0 : (dist > -outlineWidth ? 0x22 : 0x33);
|
||||
});
|
||||
|
||||
// 5: im_map_icon_try_force_4i.bti - outlined circle with triangle
|
||||
paint_i8(std::span{hqTryForceData}, kMapImageSide, [=](auto x, auto y) {
|
||||
constexpr auto innerRadiusNorm = 5.0f / 12.0f;
|
||||
constexpr auto innerRadius = kMapImageSide * innerRadiusNorm;
|
||||
constexpr auto innerRadiusSq = innerRadius * innerRadius;
|
||||
constexpr auto triRadius = kMapImageSide * innerRadiusNorm / 2.0f;
|
||||
|
||||
const auto dx = (x + 0.5f) - center;
|
||||
const auto dy = (y + 0.5f) - center;
|
||||
const auto dSq = dx * dx + dy * dy;
|
||||
const auto triSideDist = (std::numbers::sqrt3_v<float> * std::abs(dx) - dy) * 0.5f;
|
||||
const auto insideTri = std::max(dy, triSideDist) < triRadius;
|
||||
|
||||
return insideTri ? 0x22 : (dSq < radiusSq ? (dSq < innerRadiusSq ? 0x33 : 0x22) : 0);
|
||||
});
|
||||
|
||||
hqTexsDrawn = true;
|
||||
}
|
||||
|
||||
constexpr auto replacements = std::to_array<std::pair<size_t, const u8*> >({
|
||||
{2, hqEnterData},
|
||||
{3, hqNijumaruData},
|
||||
{4, hqCircleAltData},
|
||||
{5, hqTryForceData},
|
||||
{6, hqCircleData},
|
||||
});
|
||||
|
||||
for (const auto& [idx, data] : replacements) {
|
||||
JKR_DELETE(mp_texObj[idx]);
|
||||
const auto texobj = JKR_NEW TGXTexObj();
|
||||
GXInitTexObj(
|
||||
texobj, data, kMapImageSide, kMapImageSide, GX_TF_I8, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
GXInitTexObjLOD(texobj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1);
|
||||
mp_texObj[idx] = texobj;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void dMpath_n::dTexObjAggregate_c::remove() {
|
||||
|
||||
+43
-1
@@ -856,7 +856,46 @@ void dMenu_DmapBg_c::decGoldFrameAlphaRate() {
|
||||
setGoldFrameAlphaRate(rate);
|
||||
}
|
||||
|
||||
void dMenu_DmapBg_c::dMapBgWide() {
|
||||
// Scale Base HUD
|
||||
mBaseScreen->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mBaseScreen->translate(mDoGph_gInf_c::getSafeMinXF(), 0.0f);
|
||||
|
||||
// Boss Key, Compass & Map icons
|
||||
mBaseScreen->search(MULTI_CHAR('key_n'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mBaseScreen->search(MULTI_CHAR('con_n'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mBaseScreen->search(MULTI_CHAR('map_n'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
|
||||
// Text Header
|
||||
mBaseScreen->search(MULTI_CHAR('t_t00'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mBaseScreen->search(MULTI_CHAR('f_t_00'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
|
||||
// C Button
|
||||
mBaseScreen->search(MULTI_CHAR('c_btn2'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
|
||||
// Scale Buttons HUD
|
||||
mButtonScreen->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mButtonScreen->translate(mDoGph_gInf_c::getSafeMinXF(), 0.0f);
|
||||
|
||||
// Buttons
|
||||
mButtonScreen->search(MULTI_CHAR('cont_n'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
|
||||
// C Button
|
||||
mButtonScreen->search(MULTI_CHAR('c_btn'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mButtonScreen->search(MULTI_CHAR('c_text_s'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mButtonScreen->search(MULTI_CHAR('c_text'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mButtonScreen->search(MULTI_CHAR('f_text_s'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
mButtonScreen->search(MULTI_CHAR('f_text'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
|
||||
// Decorations
|
||||
mButtonScreen->search(MULTI_CHAR('kazari_n'))->scale(mDoGph_gInf_c::hudAspectScaleDown, 1.0f);
|
||||
}
|
||||
|
||||
void dMenu_DmapBg_c::draw() {
|
||||
#if TARGET_PC
|
||||
dMapBgWide();
|
||||
#endif
|
||||
|
||||
u32 scissor_left;
|
||||
u32 scissor_top;
|
||||
u32 scissor_width;
|
||||
@@ -903,7 +942,10 @@ void dMenu_DmapBg_c::draw() {
|
||||
f32 local_28c = mpBackTexture->getBounds().i.x;
|
||||
mpBackTexture->setBlackWhite(color_black, color_white);
|
||||
mpBackTexture->draw(local_28c, field_0xd94 + mpBackTexture->getBounds().i.y, mpBackTexture->getWidth(),
|
||||
mpBackTexture->getHeight(), false, false, false);
|
||||
mpBackTexture->getHeight(),
|
||||
IF_DUSK(dusk::getSettings().game.enableMirrorMode ? true :) false,
|
||||
false,
|
||||
false);
|
||||
|
||||
grafContext->scissor(field_0xd94 + mDoGph_gInf_c::getMinXF(),
|
||||
scissor_top, mDoGph_gInf_c::getWidthF(),
|
||||
|
||||
@@ -368,7 +368,7 @@ void dMenu_StageMapCtrl_c::initGetTreasureList(u8 param_0, s8 param_1) {
|
||||
}
|
||||
|
||||
inline static s16 rightModeCnvRot(s16 param_0) {
|
||||
return param_0;
|
||||
return IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -param_0 :) param_0;
|
||||
}
|
||||
|
||||
bool dMenu_StageMapCtrl_c::getTreasureList(f32* o_posX, f32* o_posY, s8* param_2, u8* o_swbit,
|
||||
@@ -405,7 +405,7 @@ bool dMenu_StageMapCtrl_c::getTreasureList(f32* o_posX, f32* o_posY, s8* param_2
|
||||
}
|
||||
|
||||
inline static f32 rightModeCnvPos(f32 param_0) {
|
||||
return param_0;
|
||||
return IF_DUSK(dusk::getSettings().game.enableMirrorMode ? -param_0 :) param_0;
|
||||
}
|
||||
|
||||
void dMenu_StageMapCtrl_c::cnvPosTo2Dpos(f32 param_0, f32 param_1, f32* param_2,
|
||||
|
||||
@@ -139,7 +139,7 @@ bool dMenu_Fishing_c::isSync() {
|
||||
void dMenu_Fishing_c::init() {
|
||||
#if TARGET_PC || VERSION == VERSION_GCN_PAL
|
||||
BOOL isEnglish = FALSE;
|
||||
if (dusk::version::isRegionUsa() || (dusk::version::isRegionPal() && dComIfGs_getPalLanguage() == dSv_player_config_c::LANGUAGE_ENGLISH)) {
|
||||
if (dusk::version::isRegionPal() && dComIfGs_getPalLanguage() == dSv_player_config_c::LANGUAGE_ENGLISH) {
|
||||
isEnglish = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -919,9 +919,20 @@ void dMenu_Fmap_c::region_map_proc() {
|
||||
}
|
||||
mpDraw2DBack->regionMapMove(mpStick);
|
||||
int stage_no, room_no;
|
||||
|
||||
#if TARGET_PC
|
||||
f32 arrow_pos_x = mpDraw2DBack->getArrowPos2DX();
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
arrow_pos_x = mpDraw2DBack->getMirrorPosX(arrow_pos_x, 0.0f);
|
||||
}
|
||||
|
||||
f32 pos_x = arrow_pos_x - mDoGph_gInf_c::getMinXF() - mDoGph_gInf_c::getWidthF() * 0.5f;
|
||||
#else
|
||||
f32 pos_x = mpDraw2DBack->getArrowPos2DX() - mDoGph_gInf_c::getMinXF()
|
||||
- mDoGph_gInf_c::getWidthF() * 0.5f;
|
||||
#endif
|
||||
f32 pos_y = mpDraw2DBack->getArrowPos2DY() - mDoGph_gInf_c::getHeightF() * 0.5f;
|
||||
|
||||
mpMenuFmapMap->getPointStagePathInnerNo(getNowFmapRegionData(), pos_x, pos_y,
|
||||
mStayStageNo, &stage_no, &room_no);
|
||||
if (mStageCursor != stage_no || mRoomCursor != room_no || mResetAreaName) {
|
||||
@@ -2464,6 +2475,13 @@ void dMenu_Fmap_c::portalWarpMapMove(STControl* i_stick) {
|
||||
f32 arrow_y = mpDraw2DBack->getArrowPos2DY();
|
||||
u8 uVar6 = 0xff;
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
arrow_x = mpDraw2DBack->getMirrorPosX(arrow_x, 0.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for (int i = 0; i < portal_dat->mCount; i++) {
|
||||
if (portals[i].mRegionNo == mpDraw2DBack->getRegionCursor() + 1
|
||||
&& checkDrawPortalIcon(portals[i].mStageNo, portals[i].mSwitchNo))
|
||||
|
||||
+58
-1
@@ -20,6 +20,15 @@
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
void dMenu_Fmap2DBack_c::fMapBackWide() {
|
||||
mpBaseScreen->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mpBaseScreen->translate(mDoGph_gInf_c::getSafeMinXF(), 0.0f);
|
||||
mpBackScreen->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mpBackScreen->translate(mDoGph_gInf_c::getSafeMinXF(), 0.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
dMenu_Fmap2DBack_c::dMenu_Fmap2DBack_c() {
|
||||
dMeter2Info_setMapDrugFlag(0);
|
||||
|
||||
@@ -267,6 +276,10 @@ dMenu_Fmap2DBack_c::~dMenu_Fmap2DBack_c() {
|
||||
}
|
||||
|
||||
void dMenu_Fmap2DBack_c::draw() {
|
||||
#if TARGET_PC
|
||||
fMapBackWide();
|
||||
#endif
|
||||
|
||||
calcBlink();
|
||||
|
||||
J2DGrafContext* grafPort = dComIfGp_getCurrentGrafPort();
|
||||
@@ -1030,6 +1043,12 @@ void dMenu_Fmap2DBack_c::allmap_move2(STControl* param_0) {
|
||||
calcAllMapPos2D((mArrowPos3DX + control_xpos) - mStageTransX,
|
||||
(mArrowPos3DZ + control_ypos) - mStageTransZ, &sp14, &sp10);
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
sp14 = getMirrorPosX(sp14, 0.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
mSelectRegion = 0xff;
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
int val = field_0x1230[i];
|
||||
@@ -1199,7 +1218,7 @@ f32 dMenu_Fmap2DBack_c::getMapScissorAreaSizeX() {
|
||||
}
|
||||
|
||||
f32 dMenu_Fmap2DBack_c::getMapScissorAreaSizeRealX() {
|
||||
#if PLATFORM_GCN && !TARGET_PC
|
||||
#if PLATFORM_GCN
|
||||
return getMapScissorAreaSizeX();
|
||||
#else
|
||||
return getMapScissorAreaSizeX() * mDoGph_gInf_c::getScale();
|
||||
@@ -1384,6 +1403,15 @@ void dMenu_Fmap2DBack_c::regionTextureDraw() {
|
||||
if (uVar10 != uVar9) {
|
||||
bool b = 0;
|
||||
f32 v = mTransX + (dVar14 + (mRegionMinMapX[uVar10] + field_0xf0c[uVar10]));
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
b = true;
|
||||
v = getMirrorPosX(mTransX + (dVar14 + (mRegionMinMapX[uVar10] + field_0xf0c[uVar10])),
|
||||
mRegionMapSizeX[uVar10] * mZoom * 0.5f);
|
||||
}
|
||||
#endif
|
||||
|
||||
mpAreaTex[uVar10]->draw(
|
||||
v, mTransZ + (dVar13 + (mRegionMinMapY[uVar10] + field_0xf2c[uVar10])),
|
||||
mRegionMapSizeX[uVar10] * mZoom, mRegionMapSizeY[uVar10] * mZoom, b, false,
|
||||
@@ -1391,6 +1419,15 @@ void dMenu_Fmap2DBack_c::regionTextureDraw() {
|
||||
} else {
|
||||
bool b = 0;
|
||||
f32 v = mTransX + (dVar14 + (mRegionMinMapX[uVar9] + field_0xf0c[uVar9]));
|
||||
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
b = true;
|
||||
v = getMirrorPosX(mTransX + (dVar14 + (mRegionMinMapX[uVar9] + field_0xf0c[uVar9])),
|
||||
mRegionMapSizeX[uVar9] * mZoom * 0.5f);
|
||||
}
|
||||
#endif
|
||||
|
||||
mpAreaTex[uVar9]->draw(
|
||||
v, mTransZ + (dVar13 + (mRegionMinMapY[uVar9] + field_0xf2c[uVar9])),
|
||||
mRegionMapSizeX[uVar9] * mZoom, mRegionMapSizeY[uVar9] * mZoom, b, false,
|
||||
@@ -1407,6 +1444,11 @@ void dMenu_Fmap2DBack_c::stageTextureDraw() {
|
||||
mpSpotTexture->setAlpha(mAlphaRate * 255.0f * field_0xfa8 * mSpotTextureFadeAlpha);
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
JUTPalette* pPalette = mpSpotTexture->getTexture(0)->getPalette();
|
||||
pPalette->dataUploaded();
|
||||
#endif
|
||||
|
||||
mpSpotTexture->draw(mTransX + getMapScissorAreaLX(), mTransZ + getMapScissorAreaLY(),
|
||||
getMapScissorAreaSizeRealX(), getMapScissorAreaSizeRealY(), false, false,
|
||||
false);
|
||||
@@ -2179,6 +2221,17 @@ void dMenu_Fmap2DBack_c::setArrowPosAxis(f32 i_posX, f32 i_posZ) {
|
||||
control_ypos = 0.0f;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
void dMenu_Fmap2DTop_c::fMapTopWide() {
|
||||
mpTitleScreen->search(MULTI_CHAR('spot0_n'))->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mpTitleScreen->search(MULTI_CHAR('spot2_n'))->scale(mDoGph_gInf_c::hudAspectScaleUp, 1.0f);
|
||||
mpTitleScreen->search(MULTI_CHAR('name_n'))->translate(mDoGph_gInf_c::ScaleHUDXLeft(-243.0f), -169.0f);
|
||||
mpTitleScreen->search(MULTI_CHAR('sub_n_n'))->translate(mDoGph_gInf_c::ScaleHUDXLeft(-80.0f), -154.0f);
|
||||
mpTitleScreen->search(MULTI_CHAR('btn_i_n'))->translate(mDoGph_gInf_c::ScaleHUDXLeft(-241.0f), 177.0f);
|
||||
mpTitleScreen->search(MULTI_CHAR('cont_n'))->translate(mDoGph_gInf_c::ScaleHUDXRight(515.0f), 83.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
dMenu_Fmap2DTop_c::dMenu_Fmap2DTop_c(JKRExpHeap* i_heap, STControl* i_stick) {
|
||||
mpHeap = i_heap;
|
||||
mTransX = 0.0f;
|
||||
@@ -2572,6 +2625,10 @@ void dMenu_Fmap2DTop_c::setAllAlphaRate(f32 i_rate, bool i_init) {
|
||||
}
|
||||
|
||||
void dMenu_Fmap2DTop_c::draw() {
|
||||
#if TARGET_PC
|
||||
fMapTopWide();
|
||||
#endif
|
||||
|
||||
u32 scissor_left, scissor_top, scissor_width, scissor_height;
|
||||
J2DOrthoGraph* ctx = static_cast<J2DOrthoGraph*>(dComIfGp_getCurrentGrafPort());
|
||||
ctx->setup2D();
|
||||
|
||||
+10
-1
@@ -17,6 +17,10 @@
|
||||
#include "d/d_msg_scrn_arrow.h"
|
||||
#include "d/d_lib.h"
|
||||
|
||||
#ifdef TARGET_PC
|
||||
#include "dusk/achievements.h"
|
||||
#endif
|
||||
|
||||
#if VERSION == VERSION_GCN_JPN
|
||||
#define D_MENU_LETTER_LINE_MAX 9
|
||||
#else
|
||||
@@ -514,6 +518,10 @@ void dMenu_Letter_c::read_open_init() {
|
||||
setAButtonString(0);
|
||||
setBButtonString(0);
|
||||
mpBlackTex->setAlpha(0);
|
||||
|
||||
#ifdef TARGET_PC
|
||||
dusk::AchievementSystem::get().signal("open_letter");
|
||||
#endif
|
||||
}
|
||||
|
||||
void dMenu_Letter_c::read_open_move() {
|
||||
@@ -957,7 +965,8 @@ void dMenu_Letter_c::screenSetBase() {
|
||||
}
|
||||
if (field_0x374 > 1) {
|
||||
J2DPane* pJVar6 = mpBaseScreen->search('pi_n');
|
||||
f32 dVar18 = field_0x1f0[1]->getBounds().i.x - field_0x1f0[0]->getBounds().i.x;
|
||||
f32 x1 = field_0x1f0[1]->getBounds().i.x;
|
||||
f32 dVar18 = x1 - field_0x1f0[0]->getBounds().i.x;
|
||||
f32 dVar17 = dVar18 * (field_0x374 - 1);
|
||||
f32 dVar16 = (pJVar6->getWidth() / 2) - (dVar17 / 2);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
|
||||
@@ -343,6 +343,11 @@ void dMenuMapCommon_c::drawIcon(f32 i_posX, f32 i_posY, f32 param_3, f32 param_4
|
||||
}
|
||||
|
||||
f32 pos_x = icon_pos_x + i_posX;
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
pos_x = getMirrorCenterPosX(pos_x, 0.0f);
|
||||
}
|
||||
#endif
|
||||
mpDrawCursor->setPos(pos_x, icon_pos_y + i_posY);
|
||||
mpDrawCursor->setScale(mIconInfo[info_idx].scale * g_fmapHIO.mMapIconHIO.mPortalCursorScale);
|
||||
mpDrawCursor->draw();
|
||||
@@ -364,6 +369,12 @@ void dMenuMapCommon_c::drawIcon(f32 i_posX, f32 i_posY, f32 param_3, f32 param_4
|
||||
}
|
||||
|
||||
f32 pos_x = (icon_pos_x + i_posX);
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
pos_x = getMirrorCenterPosX(pos_x, 0.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
mpPortalIcon->setPos(pos_x, icon_pos_y + i_posY);
|
||||
mpPortalIcon->setScale(mIconInfo[info_idx].scale * g_fmapHIO.mMapIconHIO.mPortalIconScale);
|
||||
mpPortalIcon->draw();
|
||||
@@ -399,6 +410,12 @@ void dMenuMapCommon_c::drawIcon(f32 i_posX, f32 i_posY, f32 param_3, f32 param_4
|
||||
}
|
||||
|
||||
f32 pos_x = i_posX + (icon_pos_x - (icon_size_x / 2));
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
pos_x = getMirrorCenterPosX(i_posX + (icon_pos_x - (icon_size_x / 2)), icon_size_x / 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
mPictures[mIconInfo[info_idx].icon_no]->draw(pos_x, (i_posY + (icon_pos_y - icon_size_y / 2)),
|
||||
icon_size_x, icon_size_y, false, false, false);
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#include "f_op/f_op_overlap_mng.h"
|
||||
#include "m_Do/m_Do_controller_pad.h"
|
||||
|
||||
#ifdef TARGET_PC
|
||||
#include "dusk/frame_interpolation.h"
|
||||
#endif
|
||||
|
||||
class dDlst_MENU_CAPTURE_c : public dDlst_base_c {
|
||||
public:
|
||||
virtual void draw() {
|
||||
@@ -1088,6 +1092,10 @@ void dMw_c::dMw_ring_create(u8 i_origin) {
|
||||
}
|
||||
|
||||
mpCapture->setCaptureFlag();
|
||||
|
||||
#ifdef TARGET_PC
|
||||
dusk::frame_interp::request_presentation_sync();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool dMw_c::dMw_ring_delete() {
|
||||
|
||||
+6
-3
@@ -24,9 +24,10 @@
|
||||
#include "d/actor/d_a_horse.h"
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/memory.h"
|
||||
|
||||
#include "dusk/memory.h"
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
int dMeter2_c::_create() {
|
||||
stage_stag_info_class* stag_info = dComIfGp_getStageStagInfo();
|
||||
@@ -317,7 +318,9 @@ int dMeter2_c::_execute() {
|
||||
|
||||
int dMeter2_c::_draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.disableMainHUD) {
|
||||
if (dusk::getSettings().game.recordingMode || dusk::getSettings().game.minimalHUD ||
|
||||
dusk::getSettings().game.debugFlyCam)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2306,6 +2306,10 @@ void dMeter_drawHIO_c::updateOnWide() {
|
||||
// River Canoe Minigame
|
||||
g_drawHIO.mMiniGame.mCounterPosX[1] = mDoGph_gInf_c::ScaleHUDXRight(g_drawHIO.mMiniGame.mCounterPosX[1]);
|
||||
g_drawHIO.mMiniGame.mIconPosX[1] = mDoGph_gInf_c::ScaleHUDXRight(g_drawHIO.mMiniGame.mIconPosX[1]);
|
||||
|
||||
// Bulblin Count in Hidden Village
|
||||
g_drawHIO.mMiniGame.mCounterPosX[2] = mDoGph_gInf_c::ScaleHUDXRight(g_drawHIO.mMiniGame.mCounterPosX[2]);
|
||||
g_drawHIO.mMiniGame.mIconPosX[2] = mDoGph_gInf_c::ScaleHUDXRight(g_drawHIO.mMiniGame.mIconPosX[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -2066,7 +2066,7 @@ bool jmessage_tSequenceProcessor::do_isReady() {
|
||||
case 0:
|
||||
case 5:
|
||||
case 6:
|
||||
if (mDoCPd_c::getTrigA(PAD_1) || field_0xb2 != 0) {
|
||||
if (mDoCPd_c::getTrigA(PAD_1) || field_0xb2 != 0 IF_DUSK(|| (dusk::getSettings().game.instantText && mDoCPd_c::getHoldB(0)))) {
|
||||
field_0xa4 = 0;
|
||||
pReference->onBatchFlag();
|
||||
pReference->setCharCnt(D_MSG_CLASS_CHAR_CNT_MAX);
|
||||
|
||||
+48
-1
@@ -32,6 +32,9 @@
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#endif
|
||||
|
||||
static void dMsgObject_addFundRaising(s16 param_0);
|
||||
@@ -424,6 +427,17 @@ static void dummyStrings() {
|
||||
dMsgObject_HIO_c g_MsgObject_HIO_c;
|
||||
|
||||
int dMsgObject_c::_execute() {
|
||||
// TODO: enabling wii message overrides fixes direction text, but gives wrong item control text
|
||||
/*#if TARGET_PC
|
||||
if (dusk::getSettings().game.enableMirrorMode) {
|
||||
// enable wii message index override
|
||||
g_MsgObject_HIO_c.mMessageDisplay = 1;
|
||||
} else if (!dusk::getSettings().game.enableMirrorMode && g_MsgObject_HIO_c.mMessageDisplay == 1) {
|
||||
g_MsgObject_HIO_c.mMessageDisplay = 0;
|
||||
}
|
||||
#endif*/
|
||||
|
||||
|
||||
field_0x4c7 = 0;
|
||||
if (mpTalkHeap != NULL) {
|
||||
field_0x148 = mDoExt_setCurrentHeap(mpTalkHeap);
|
||||
@@ -1594,7 +1608,7 @@ u8 dMsgObject_c::isSend() {
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
if (IF_DUSK((dusk::getSettings().game.instantText && mDoCPd_c::getHoldB(0)) ||)
|
||||
if (IF_DUSK((dusk::getSettings().game.instantText && mDoCPd_c::getHoldB(0) && !isShopItemMessage()) ||)
|
||||
mDoCPd_c::getTrigA(0) != 0 || mDoCPd_c::getTrigB(0) != 0) {
|
||||
return 2;
|
||||
}
|
||||
@@ -1866,6 +1880,39 @@ bool dMsgObject_c::isTalkMessage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
bool dMsgObject_c::isShopItemMessage() {
|
||||
|
||||
// Probably a better way to do this than just listing every message id, but this works for now
|
||||
// Note: Keep contents sorted so we can use binary search
|
||||
const auto shopMsgIds = std::to_array<std::vector<s16>>({
|
||||
{},
|
||||
// zel_01.bmg - Seras Shop
|
||||
{7001, 7003, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7013, 7014, 7022, 7023, 7028, 7029,
|
||||
7044, 7045, 7053},
|
||||
// zel_02.bmg - Kakariko Shops
|
||||
{5181, 5182, 5251, 5253, 5254, 5256, 5258, 5259, 5653, 5654, 5656, 5660, 5661, 5664, 5665,
|
||||
5697, 5698, 5699, 5803, 5804, 5806, 5810, 5811, 5812, 5814, 5821, 5823, 5824, 5987, 5988,
|
||||
5989, 5990, 5991, 5992, 5993, 5994, 5995, 5996, 5997, 5998, 5999},
|
||||
// zel_03.bmg - Death Mountain Shop
|
||||
{5303, 5304, 5306, 5310, 5311, 5314, 5315, 5322, 5323, 5324, 5496, 5497, 5498, 5499},
|
||||
// zel_04.bmg - Castle Town Shops
|
||||
{5407, 5408, 5409, 5410, 5411, 5412, 5413, 5414, 5415, 5416, 5417, 5418, 5419, 5420, 5431,
|
||||
5432, 5434, 5435, 5436, 5437, 5438, 5439, 5440, 5441, 5444, 5449, 5450, 5451, 5452, 5462},
|
||||
// zel_05.bmg - Oocca Shop
|
||||
{9428, 9429, 9430, 9431, 9432, 9437, 9443, 9448, 9449, 9451, 9459}
|
||||
});
|
||||
|
||||
u16 id = mMessageID;
|
||||
s16 group = dMsgObject_getGroupID();
|
||||
if (group < shopMsgIds.size()) {
|
||||
return std::ranges::binary_search(shopMsgIds[group], id);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* dMsgObject_c::getSmellName() {
|
||||
JMSMesgInfo_c* info_header_p = (JMSMesgInfo_c*)((char*)mpMsgRes + 0x20);
|
||||
char* data_ptr = (char*)info_header_p + info_header_p->header.size;
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "d/d_pane_class.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnArrow_c::dMsgScrnArrow_c() {
|
||||
mpScreen = JKR_NEW J2DScreen();
|
||||
JUT_ASSERT(0, mpScreen != NULL);
|
||||
@@ -65,6 +69,11 @@ dMsgScrnArrow_c::~dMsgScrnArrow_c() {
|
||||
}
|
||||
|
||||
void dMsgScrnArrow_c::draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* graf_ctx = dComIfGp_getCurrentGrafPort();
|
||||
mpScreen->draw(0.0f, 0.0f, graf_ctx);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "d/d_pane_class.h"
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnBase_c::dMsgScrnBase_c() {
|
||||
init();
|
||||
}
|
||||
@@ -57,12 +61,22 @@ void dMsgScrnBase_c::init() {
|
||||
}
|
||||
|
||||
void dMsgScrnBase_c::multiDraw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (field_0x48 != NULL) {
|
||||
dComIfGd_set2DOpa(field_0x48);
|
||||
}
|
||||
}
|
||||
|
||||
void dMsgScrnBase_c::draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* ctx = dComIfGp_getCurrentGrafPort();
|
||||
|
||||
ctx->setup2D();
|
||||
@@ -72,10 +86,20 @@ void dMsgScrnBase_c::draw() {
|
||||
}
|
||||
|
||||
void dMsgScrnBase_c::drawSelf() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
drawOutFont(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void dMsgScrnBase_c::drawOutFont(f32 param_0, f32 param_1, f32 param_2) {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
mpOutFont->draw(NULL, param_0, param_1, param_2);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "d/d_msg_object.h"
|
||||
#include "d/d_pane_class.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnBoss_c::dMsgScrnBoss_c() {
|
||||
static u64 t_tag[7] = {
|
||||
MULTI_CHAR('sfontb0'), MULTI_CHAR('sfontb1'), MULTI_CHAR('sfontb2'), MULTI_CHAR('sfontl0'), MULTI_CHAR('sfontl1'), MULTI_CHAR('sfontl2'), MULTI_CHAR('sfont00'),
|
||||
@@ -91,6 +95,11 @@ void dMsgScrnBoss_c::exec() {
|
||||
}
|
||||
|
||||
void dMsgScrnBoss_c::drawSelf() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* ctx = dComIfGp_getCurrentGrafPort();
|
||||
ctx->setup2D();
|
||||
drawOutFont(0.0f, 0.0f, 1.0f);
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "d/d_msg_out_font.h"
|
||||
#include "d/d_pane_class.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnKanban_c::dMsgScrnKanban_c(JKRExpHeap* param_0) {
|
||||
if (param_0 != NULL) {
|
||||
field_0xd4 = param_0;
|
||||
@@ -176,6 +180,11 @@ void dMsgScrnKanban_c::exec() {
|
||||
}
|
||||
|
||||
void dMsgScrnKanban_c::draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* grafContext = dComIfGp_getCurrentGrafPort();
|
||||
grafContext->setup2D();
|
||||
mpScreen->draw(0.0f, 0.0f, grafContext);
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "d/d_msg_object.h"
|
||||
#include "d/d_pane_class.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnPlace_c::dMsgScrnPlace_c() {
|
||||
static u64 t_tag[7] = {
|
||||
MULTI_CHAR('sfontb0'), MULTI_CHAR('sfontb1'), MULTI_CHAR('sfontb2'), MULTI_CHAR('sfontl0'), MULTI_CHAR('sfontl1'), MULTI_CHAR('sfontl2'), MULTI_CHAR('sfont00'),
|
||||
@@ -127,6 +131,11 @@ void dMsgScrnPlace_c::exec() {
|
||||
}
|
||||
|
||||
void dMsgScrnPlace_c::drawSelf() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* grafContext = dComIfGp_getCurrentGrafPort();
|
||||
grafContext->setup2D();
|
||||
drawOutFont(0.0f, 0.0f, 1.0f);
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "JSystem/J2DGraph/J2DScreen.h"
|
||||
#include <cstring>
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnTalk_c::dMsgScrnTalk_c(u8 param_1, u8 param_2, JKRExpHeap* param_3) {
|
||||
if (param_3 != NULL) {
|
||||
field_0xe4 = param_3;
|
||||
@@ -303,6 +307,11 @@ void dMsgScrnTalk_c::exec() {
|
||||
}
|
||||
|
||||
void dMsgScrnTalk_c::drawSelf() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* grafContext[1];
|
||||
grafContext[0] = dComIfGp_getCurrentGrafPort();
|
||||
grafContext[0]->setup2D();
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "d/d_msg_out_font.h"
|
||||
#include "d/d_pane_class.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#endif
|
||||
|
||||
dMsgScrnTree_c::dMsgScrnTree_c(JUTFont* param_0, JKRExpHeap* param_1) {
|
||||
if (param_1 != NULL) {
|
||||
field_0xd8 = param_1;
|
||||
@@ -187,6 +191,11 @@ void dMsgScrnTree_c::exec() {
|
||||
}
|
||||
|
||||
void dMsgScrnTree_c::draw() {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.recordingMode) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
J2DGrafContext* grafContext = dComIfGp_getCurrentGrafPort();
|
||||
grafContext->setup2D();
|
||||
mpScreen->draw(0.0f, 0.0f, grafContext);
|
||||
|
||||
+10
-7
@@ -134,16 +134,16 @@ static const char* l_mojiEisu[65] = {
|
||||
// That can't work on a modern platform, so instead I've filled them out ahead of time.
|
||||
static const char* l_mojiEisuPal_1[65] = {
|
||||
"A", "N", "\xC0", "\xCF", "1", "B", "O", "\xC1", "\xD0", "2", "C", "P", "\xC2", "\xD1", "3", "D", "Q",
|
||||
"\xC3", "\xD2", "4", "E", "R", "\xC4", "\xD3", "5", "F", "S", "\xC5", "\xD4", "6", "G", "T", "\xC6", "\xD5",
|
||||
"7", "H", "U", "\xC7", "\xD6", "8", "I", "V", "\xC8", "\xD7", "9", "J", "W", "\xC9", "\xD8", "0", "K",
|
||||
"X", "\xCA", "\xD9", ",", "L", "Y", "\xCB", "\xDA", ".", "M", "Z", "\xCC", "\xDB", " ",
|
||||
"\xC4", "\xD2", "4", "E", "R", "\xC6", "\xD3", "5", "F", "S", "\xC7", "\xD4", "6", "G", "T", "\xC8", "\xD6",
|
||||
"7", "H", "U", "\xC9", "\x8C", "8", "I", "V", "\xCA", "\xD9", "9", "J", "W", "\xCB", "\xDA", "0", "K",
|
||||
"X", "\xCC", "\xDB", ",", "L", "Y", "\xCD", "\xDC", ".", "M", "Z", "\xCE", "\x2D", " ",
|
||||
};
|
||||
|
||||
static const char* l_mojiEisuPal_2[65] = {
|
||||
"a", "n", "\xE0", "\xEF", "1", "b", "o", "\xE1", "\xF0", "2", "c", "p", "\xE2", "\xF1", "3", "d", "q",
|
||||
"\xE3", "\xF2", "4", "e", "r", "\xE4", "\xF3", "5", "f", "s", "\xE5", "\xF4", "6", "g", "t", "\xE6",
|
||||
"\xF5", "7", "h", "u", "\xE7", "\xF6", "8", "i", "v", "\xE8", "\xF7", "9", "j", "w", "\xE9", "\xF8", "0",
|
||||
"k", "x", "\xEA", "\xF9", ",", "l", "y", "\xEB", "\xFA", ".", "m", "z", "\xEC", "\xFB", " ",
|
||||
"\xE4", "\xF2", "4", "e", "r", "\xE6", "\xF3", "5", "f", "s", "\xE7", "\xF4", "6", "g", "t", "\xE8",
|
||||
"\xF6", "7", "h", "u", "\xE9", "\x9C", "8", "i", "v", "\xEA", "\xF9", "9", "j", "w", "\xEB", "\xFA", "0",
|
||||
"k", "x", "\xEC", "\xFB", ",", "l", "y", "\xED", "\xFC", ".", "m", "z", "\xEE", "\xDF", " ",
|
||||
};
|
||||
#elif REGION_PAL
|
||||
static const char* l_mojiEisuPal_1[65] = {
|
||||
@@ -352,6 +352,7 @@ void dName_c::_move() {
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
#if !TARGET_PC
|
||||
if (mDoCPd_c::getTrigRight(PAD_1)) {
|
||||
// BUG: this check only fails if the cursor is at exactly 7
|
||||
// setMoji allows the cursor to reach 8, which is out of bounds here
|
||||
@@ -368,7 +369,9 @@ void dName_c::_move() {
|
||||
mCurPos--;
|
||||
nameCursorMove();
|
||||
}
|
||||
} else if (mDoCPd_c::getTrigB(PAD_1)) {
|
||||
} else
|
||||
#endif
|
||||
if (mDoCPd_c::getTrigB(PAD_1)) {
|
||||
if (mCurPos == 0) {
|
||||
mDoAud_seStart(Z2SE_SY_MENU_BACK, 0, 0, 0);
|
||||
field_0x2ac = mSelProc;
|
||||
|
||||
+2
-16
@@ -1120,26 +1120,12 @@ int dScnLogo_c::create() {
|
||||
checkProgSelect();
|
||||
if (field_0x20a != 0) {
|
||||
mExecCommand = EXEC_PROG_IN;
|
||||
#if TARGET_PC
|
||||
mTimer = dusk::getSettings().game.skipWarningScreen ? 1 : 30;
|
||||
#else
|
||||
mTimer = 30;
|
||||
#endif
|
||||
field_0x218 = getProgressiveMode();
|
||||
} else {
|
||||
#if TARGET_PC
|
||||
if (dusk::getSettings().game.skipWarningScreen) {
|
||||
mTimer = 0; // Possibly unnecessary but just in case
|
||||
mExecCommand = EXEC_DVD_WAIT;
|
||||
} else {
|
||||
if (mDoRst::getWarningDispFlag()) {
|
||||
mTimer = 90;
|
||||
mExecCommand = EXEC_NINTENDO_IN;
|
||||
} else {
|
||||
mTimer = 120;
|
||||
mExecCommand = EXEC_WARNING_IN;
|
||||
}
|
||||
}
|
||||
mTimer = 0; // Possibly unnecessary but just in case
|
||||
mExecCommand = EXEC_DVD_WAIT;
|
||||
#else
|
||||
if (mDoRst::getWarningDispFlag()) {
|
||||
mTimer = 90;
|
||||
|
||||
+7
-1
@@ -10,7 +10,9 @@
|
||||
#include "d/d_meter2_info.h"
|
||||
#include "d/d_s_name.h"
|
||||
#include "dusk/imgui/ImGuiConsole.hpp"
|
||||
#include "dusk/livesplit.h"
|
||||
#include "dusk/memory.h"
|
||||
#include "dusk/speedrun.h"
|
||||
#include "dusk/settings.h"
|
||||
#include "f_op/f_op_overlap_mng.h"
|
||||
#include "f_op/f_op_scene_mng.h"
|
||||
@@ -19,6 +21,7 @@
|
||||
#include "m_Do/m_Do_machine.h"
|
||||
#include "m_Do/m_Do_main.h"
|
||||
#include "m_Do/m_Do_mtx.h"
|
||||
#include <dusk/autosave.h>
|
||||
|
||||
#if TARGET_PC
|
||||
#define SHOW_TV_SETTINGS_SCREEN (this->mShowTvSettingsScreen)
|
||||
@@ -418,10 +421,13 @@ void dScnName_c::changeGameScene() {
|
||||
if (dusk::getSettings().game.speedrunMode && dusk::getSettings().game.hideTvSettingsScreen) {
|
||||
// start a new run on file load if a run isn't already in progress
|
||||
if (!dusk::m_speedrunInfo.m_isRunStarted) {
|
||||
dusk::ImGuiMenuGame::resetForSpeedrunMode();
|
||||
dusk::resetForSpeedrunMode();
|
||||
dusk::m_speedrunInfo.startRun();
|
||||
dusk::speedrun::start();
|
||||
}
|
||||
}
|
||||
|
||||
toggleAutoSave(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
#include "JSystem/JKernel/JKRAramArchive.h"
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/autosave.h"
|
||||
#include "dusk/memory.h"
|
||||
#include "dusk/ui/ui.hpp"
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
@@ -700,6 +702,10 @@ static u8 lbl_8074CAE4;
|
||||
static u32 l_sceneChangeStartTick;
|
||||
#endif
|
||||
|
||||
#if TARGET_PC
|
||||
static BOOL autoSaved;
|
||||
#endif
|
||||
|
||||
static int dScnPly_Execute(dScnPly_c* i_this) {
|
||||
#if DEBUG
|
||||
fapGm_HIO_c::startCpuTimer();
|
||||
@@ -742,6 +748,15 @@ static int dScnPly_Execute(dScnPly_c* i_this) {
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_PC
|
||||
if (!dComIfGp_event_runCheck() && !fopOvlpM_IsPeek() && !dComIfG_resetToOpening(i_this) &&
|
||||
!dComIfGp_isEnableNextStage() && autoSaved == FALSE)
|
||||
{
|
||||
triggerAutoSave();
|
||||
autoSaved = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
dKy_itudemo_se();
|
||||
|
||||
#if DEBUG
|
||||
@@ -780,7 +795,17 @@ static int dScnPly_Execute(dScnPly_c* i_this) {
|
||||
dJprev_c::get()->update();
|
||||
#endif
|
||||
|
||||
#if TARGET_PC
|
||||
if (!dusk::ui::is_prelaunch_open()) {
|
||||
dDemo_c::update();
|
||||
} else if (dusk::getSettings().audio.menuSounds) {
|
||||
s8 reverb = dComIfGp_getReverb(dComIfGp_roomControl_getStayNo());
|
||||
f32 fxMix = reverb / 127.0f;
|
||||
g_mEnvSeMgr.field_0x144.startEnvSeDirLevel(JA_SE_ATM_WIND_1, fxMix, 1.0f);
|
||||
}
|
||||
#else
|
||||
dDemo_c::update();
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
dJcame_c::get()->update();
|
||||
@@ -1017,6 +1042,10 @@ static BOOL heapSizeCheck() {
|
||||
|
||||
bool dScnPly_c::resetGame() {
|
||||
if (fpcM_GetName(this) == fpcNm_OPENING_SCENE_e) {
|
||||
#if TARGET_PC
|
||||
toggleAutoSave(false);
|
||||
#endif
|
||||
|
||||
if (!dStage_roomControl_c::resetArchiveBank(0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1593,6 +1622,11 @@ static int dScnPly_Create(scene_class* i_this) {
|
||||
|
||||
dScnPly_c* a_this = (dScnPly_c*)i_this;
|
||||
int phase_state = dComLbG_PhaseHandler(&a_this->field_0x1c4, l_method, a_this);
|
||||
|
||||
#if TARGET_PC
|
||||
autoSaved = FALSE;
|
||||
#endif
|
||||
|
||||
return phase_state;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,13 @@
|
||||
#include "lingcod/lingcod.h"
|
||||
#endif
|
||||
|
||||
#if TARGET_PC
|
||||
#include "dusk/settings.h"
|
||||
#include <f_ap/f_ap_game.h>
|
||||
|
||||
#include "dusk/string.hpp"
|
||||
#define strcpy dusk::SafeStringCopy
|
||||
#endif
|
||||
|
||||
static u8 dSv_item_rename(u8 i_itemNo) {
|
||||
switch (i_itemNo) {
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
#include <memory>
|
||||
|
||||
#include "aurora/lib/logging.hpp"
|
||||
#include "os_report.h"
|
||||
|
||||
aurora::Module Log("dusk::osReport");
|
||||
|
||||
bool dusk::OSReportReallyForceEnable = false;
|
||||
|
||||
u8 __OSReport_disable;
|
||||
|
||||
void OSReportDisable() {
|
||||
__OSReport_disable = true;
|
||||
}
|
||||
|
||||
void OSReportEnable() {
|
||||
__OSReport_disable = false;
|
||||
}
|
||||
|
||||
static bool checkEnabled() {
|
||||
return !__OSReport_disable || dusk::OSReportReallyForceEnable;
|
||||
}
|
||||
|
||||
#ifndef va_copy
|
||||
#define va_copy(d, s) ((d) = (s))
|
||||
#endif
|
||||
|
||||
static std::string FormatToString(const char* msg, va_list list) {
|
||||
size_t size = (strlen(msg) * 2) + 50;
|
||||
std::string str;
|
||||
va_list ap;
|
||||
int attempts = 0;
|
||||
while (true) {
|
||||
str.resize(size);
|
||||
va_copy(ap, list);
|
||||
int n = vsnprintf(str.data(), size, msg, ap);
|
||||
va_end(ap);
|
||||
if (n > -1 && n < size) {
|
||||
str.resize(n);
|
||||
break;
|
||||
}
|
||||
|
||||
++attempts;
|
||||
if (attempts >= 3) {
|
||||
if (n == -1) {
|
||||
str.clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (n > -1) {
|
||||
size = n + 1;
|
||||
} else {
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
while (!str.empty() && str[str.size()-1] == '\n') {
|
||||
str.pop_back();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void OSReport(const char* fmt, ...) {
|
||||
if (!checkEnabled()) {
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const auto str = FormatToString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
Log.info("{}", str);
|
||||
}
|
||||
|
||||
void OSPanic(const char* file, int line, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const auto str = FormatToString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
Log.fatal("[{}:{}] {}", file, line, str);
|
||||
}
|
||||
|
||||
void OSReport_Error(const char* fmt, ...) {
|
||||
if (!checkEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const auto str = FormatToString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
Log.error("{}", str);
|
||||
}
|
||||
|
||||
void OSReport_FatalError(const char* fmt, ...) {
|
||||
if (!checkEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const auto str = FormatToString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
Log.fatal("{}", str);
|
||||
}
|
||||
|
||||
void OSReport_Warning(const char* fmt, ...) {
|
||||
if (!checkEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const auto str = FormatToString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
Log.warn("{}", str);
|
||||
}
|
||||
|
||||
void OSReport_System(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
OSVAttention(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void OSVAttention(const char* fmt, va_list args) {
|
||||
if (!checkEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto str = FormatToString(fmt, args);
|
||||
|
||||
Log.info("{}", str);
|
||||
}
|
||||
|
||||
void OSAttention(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
OSVAttention(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
+820
-131
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
#include "dusk/action_bindings.h"
|
||||
|
||||
#include "aurora/lib/input.hpp"
|
||||
#include "dusk/settings.h"
|
||||
#include "dusk/ui/ui.hpp"
|
||||
|
||||
namespace dusk {
|
||||
|
||||
static std::array<std::array<ActionBindPressData, static_cast<int>(ActionBinds::COUNT)>, PAD_CHANMAX> actionPressData{};
|
||||
|
||||
ActionBindsMap& getActionBinds() {
|
||||
static ActionBindsMap actionBinds = {
|
||||
{ActionBinds::FIRST_PERSON_CAMERA, {&getSettings().actionBindings.firstPersonCamera, "First Person Camera"}},
|
||||
{ActionBinds::CALL_MIDNA, {&getSettings().actionBindings.callMidna, "Call Midna"}},
|
||||
{ActionBinds::OPEN_DUSKLIGHT_MENU, {&getSettings().actionBindings.openDusklightMenu, "Open Dusklight Menu"}},
|
||||
{ActionBinds::TURBO_SPEED_BUTTON, {&getSettings().actionBindings.turboSpeedButton, "Turbo Speed Button"}},
|
||||
};
|
||||
return actionBinds;
|
||||
}
|
||||
|
||||
bool isActionBound(ActionBinds action, u32 port) {
|
||||
auto& actionBinds = getActionBinds();
|
||||
// Check to make sure action is properly bound
|
||||
if (!actionBinds.contains(action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getActionBindButton(action, port) != PAD_NATIVE_BUTTON_INVALID;
|
||||
}
|
||||
|
||||
void updateActionBindings() {
|
||||
for (u32 port = 0; port < PAD_CHANMAX; ++port) {
|
||||
// Move the current press to the previous frame
|
||||
for (auto& pressData : actionPressData[port]) {
|
||||
pressData.pressedPrevFrame = pressData.pressedCurFrame;
|
||||
pressData.pressedCurFrame = false;
|
||||
}
|
||||
|
||||
// Update current frame with whether action button is pressed
|
||||
for (auto& [action, boundAction] : getActionBinds()) {
|
||||
// If the action isn't bound, or if documents are visible and the action isn't
|
||||
// opening the dusklight menu, don't update. Otherwise, we may accidentally
|
||||
// perform actions while the dusklight menu is open.
|
||||
if (!isActionBound(action, port) ||
|
||||
(ui::any_document_visible() && action != ActionBinds::OPEN_DUSKLIGHT_MENU)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int button = boundAction.configVars->at(port);
|
||||
|
||||
// If keyboard is active for this port
|
||||
u32 count = 0;
|
||||
if (PADGetKeyButtonBindings(port, &count) != nullptr) {
|
||||
int numKeys = 0;
|
||||
const bool* kbState = SDL_GetKeyboardState(&numKeys);
|
||||
if (kbState[button]) {
|
||||
actionPressData[port][static_cast<int>(action)].pressedCurFrame = true;
|
||||
}
|
||||
} else {
|
||||
// If controller is active
|
||||
auto controller = aurora::input::get_controller_for_player(port);
|
||||
if (controller) {
|
||||
if (SDL_GetGamepadButton(controller->m_controller, static_cast<SDL_GamepadButton>(button))) {
|
||||
actionPressData[port][static_cast<int>(action)].pressedCurFrame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool getActionBindTrig(ActionBinds action, u32 port) {
|
||||
return isActionBound(action, port) &&
|
||||
actionPressData[port][static_cast<int>(action)].pressedCurFrame &&
|
||||
!actionPressData[port][static_cast<int>(action)].pressedPrevFrame;
|
||||
}
|
||||
|
||||
bool getActionBindHold(ActionBinds action, u32 port) {
|
||||
return isActionBound(action, port) &&
|
||||
actionPressData[port][static_cast<int>(action)].pressedCurFrame &&
|
||||
actionPressData[port][static_cast<int>(action)].pressedPrevFrame;
|
||||
}
|
||||
|
||||
bool getActionBindHoldAnyPort(ActionBinds action) {
|
||||
for (u32 port = 0; port < PAD_CHANMAX; ++port) {
|
||||
if (getActionBindHold(action, port)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int getActionBindButton(ActionBinds action, u32 port) {
|
||||
return (*getActionBinds()[action].configVars)[port];
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,20 @@ f32 dusk::audio::MasterVolume = 1.0f;
|
||||
f32 dusk::audio::PrevMasterVolume = 1.0f;
|
||||
bool dusk::audio::EnableReverb = true;
|
||||
bool dusk::audio::DumpAudio = false;
|
||||
bool dusk::audio::EnableHrtf = false;
|
||||
f32 dusk::audio::HrtfGain = 0.5f;
|
||||
|
||||
|
||||
// 3dB at 5kHz.
|
||||
static constexpr f32 HRTF_LP_K = 0.75f;
|
||||
static constexpr f32 HRTF_ALLPASS_G = 0.3f;
|
||||
// Front never drops below (1 - HRTF_EXTRACT_MAX).
|
||||
static constexpr f32 HRTF_EXTRACT_MAX = 0.6f;
|
||||
|
||||
static f32 sHrtfLp1 = 0.0f;
|
||||
static f32 sHrtfLp2 = 0.0f;
|
||||
static f32 sHrtfApIn1 = 0.0f;
|
||||
static f32 sHrtfApOut1 = 0.0f;
|
||||
|
||||
/**
|
||||
* Validate that a DSP channel's format is actually something we know how to play.
|
||||
@@ -283,6 +297,9 @@ void dusk::audio::DspRender(OutputSubframe& subframe) {
|
||||
DspSubframe reverbInputR = {};
|
||||
bool anyReverbInput = false;
|
||||
|
||||
DspSubframe surroundBus = {};
|
||||
bool anySurroundInput = false;
|
||||
|
||||
for (int i = 0; i < channels.size(); i++) {
|
||||
auto& channel = channels[i];
|
||||
auto& channelAux = ChannelAux[i];
|
||||
@@ -324,6 +341,21 @@ void dusk::audio::DspRender(OutputSubframe& subframe) {
|
||||
}
|
||||
}
|
||||
|
||||
if (EnableHrtf && channel.mAutoMixerBeenSet) {
|
||||
f32 dolby = (channel.mAutoMixerPanDolby & 0xFF) / 127.0f;
|
||||
if (dolby > 0.0f) {
|
||||
anySurroundInput = true;
|
||||
f32 extract = dolby * HRTF_EXTRACT_MAX;
|
||||
f32 frontScale = 1.0f - extract;
|
||||
for (int j = 0; j < DSP_SUBFRAME_SIZE; j++) {
|
||||
f32 mono = (channelSubframe.channels[0][j] + channelSubframe.channels[1][j]) * 0.5f;
|
||||
surroundBus[j] += mono * extract;
|
||||
channelSubframe.channels[0][j] *= frontScale;
|
||||
channelSubframe.channels[1][j] *= frontScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DumpAudio && sChannelDumpFiles[i]) {
|
||||
f32 interleaved[DSP_SUBFRAME_SIZE * 2];
|
||||
for (int j = 0; j < DSP_SUBFRAME_SIZE; j++) {
|
||||
@@ -349,6 +381,28 @@ void dusk::audio::DspRender(OutputSubframe& subframe) {
|
||||
ReverbHasTail = wetEnergy >= REVERB_ENERGY_EPSILON;
|
||||
}
|
||||
|
||||
if (EnableHrtf && anySurroundInput) {
|
||||
// Two-pole LPF: -12 dB/oct above 3 kHz
|
||||
for (int j = 0; j < DSP_SUBFRAME_SIZE; j++) {
|
||||
sHrtfLp1 = (1.0f - HRTF_LP_K) * sHrtfLp1 + HRTF_LP_K * surroundBus[j];
|
||||
sHrtfLp2 = (1.0f - HRTF_LP_K) * sHrtfLp2 + HRTF_LP_K * sHrtfLp1;
|
||||
surroundBus[j] = sHrtfLp2;
|
||||
}
|
||||
|
||||
// Mix into L and R
|
||||
// L gets the filtered signal directly; R gets it allpass for mild decorrelation
|
||||
for (int j = 0; j < DSP_SUBFRAME_SIZE; j++) {
|
||||
f32 s = surroundBus[j];
|
||||
|
||||
subframe.channels[0][j] += s * HrtfGain;
|
||||
|
||||
f32 r = -HRTF_ALLPASS_G * s + sHrtfApIn1 + HRTF_ALLPASS_G * sHrtfApOut1;
|
||||
sHrtfApIn1 = s;
|
||||
sHrtfApOut1 = r;
|
||||
subframe.channels[1][j] += r * HrtfGain;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& channel : subframe.channels) {
|
||||
ApplyVolume(channel, channel, PrevMasterVolume, MasterVolume);
|
||||
}
|
||||
|
||||
@@ -133,4 +133,6 @@ namespace dusk::audio {
|
||||
extern f32 PrevMasterVolume;
|
||||
extern bool EnableReverb;
|
||||
extern bool DumpAudio;
|
||||
extern bool EnableHrtf;
|
||||
extern f32 HrtfGain;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#include "dusk/autosave.h"
|
||||
#include "dusk/ui/ui.hpp"
|
||||
#include "imgui/ImGuiConsole.hpp"
|
||||
|
||||
bool shouldAutoSave = false;
|
||||
u8 mSaveBuffer[QUEST_LOG_SIZE * 3];
|
||||
u8 mAutoSaveProc = 0;
|
||||
int autoSaveWriteState = 0;
|
||||
|
||||
typedef void (*AutoSaveFuncs)();
|
||||
static AutoSaveFuncs AutoSaveFuncsProc[] = {
|
||||
noAutoSave, enterAutoSave, autoSaving, waitingForWrite, endAutoSave,
|
||||
};
|
||||
|
||||
void noAutoSave() {}
|
||||
|
||||
bool canAutoSave() {
|
||||
daAlink_c* player = (daAlink_c*)daAlink_getAlinkActorClass();
|
||||
if (player == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player->checkCargoCarry() || player->checkCanoeRide()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dusk::getSettings().game.autoSave && shouldAutoSave && mAutoSaveProc == 0 &&
|
||||
strcmp(dComIfGp_getStartStageName(), "F_SP102") != 0 &&
|
||||
strcmp(dComIfGp_getStartStageName(), "F_SP112") != 0;
|
||||
}
|
||||
|
||||
void triggerAutoSave() {
|
||||
if (canAutoSave())
|
||||
{
|
||||
mAutoSaveProc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void updateAutoSave() {
|
||||
(AutoSaveFuncsProc[mAutoSaveProc])();
|
||||
}
|
||||
|
||||
bool writeAutoSave() {
|
||||
stage_stag_info_class* stagInfo = dComIfGp_getStageStagInfo();
|
||||
if (stagInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int stageNo = dStage_stagInfo_GetSaveTbl(stagInfo);
|
||||
|
||||
dComIfGs_putSave(stageNo);
|
||||
dComIfGs_setMemoryToCard(mSaveBuffer, dComIfGs_getDataNum());
|
||||
mDoMemCdRWm_SetCheckSumGameData(mSaveBuffer, dComIfGs_getDataNum());
|
||||
|
||||
u8* save = mSaveBuffer;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
mDoMemCdRWm_TestCheckSumGameData(save);
|
||||
save += QUEST_LOG_SIZE;
|
||||
}
|
||||
|
||||
g_mDoMemCd_control.save(mSaveBuffer, sizeof(mSaveBuffer), 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void autoSaving() {
|
||||
int cardState = g_mDoMemCd_control.LoadSync(mSaveBuffer, sizeof(mSaveBuffer), 0);
|
||||
if (cardState != 0) {
|
||||
if (cardState == 2) {
|
||||
mAutoSaveProc = 1;
|
||||
} else if (cardState == 1) {
|
||||
if (writeAutoSave()) {
|
||||
mAutoSaveProc = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enterAutoSave() {
|
||||
u32 cardStatus = g_mDoMemCd_control.getStatus(0);
|
||||
|
||||
if (cardStatus != 14) {
|
||||
switch (cardStatus) {
|
||||
case 2:
|
||||
g_mDoMemCd_control.load();
|
||||
mAutoSaveProc = 2;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
break;
|
||||
default:
|
||||
mAutoSaveProc = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void waitingForWrite() {
|
||||
autoSaveWriteState = g_mDoMemCd_control.SaveSync();
|
||||
|
||||
if (autoSaveWriteState == 2) {
|
||||
mAutoSaveProc = 0;
|
||||
} else if (autoSaveWriteState == 1) {
|
||||
mAutoSaveProc = 4;
|
||||
}
|
||||
}
|
||||
|
||||
void endAutoSave() {
|
||||
dusk::ui::push_toast({
|
||||
.type = "autosave",
|
||||
.duration = std::chrono::milliseconds(1500),
|
||||
});
|
||||
mAutoSaveProc = 0;
|
||||
}
|
||||
|
||||
void toggleAutoSave(bool enabled) {
|
||||
shouldAutoSave = enabled;
|
||||
}
|
||||
+26
-7
@@ -11,6 +11,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "dusk/main.h"
|
||||
#include "dusk/action_bindings.h"
|
||||
|
||||
using namespace dusk::config;
|
||||
|
||||
@@ -23,8 +24,8 @@ aurora::Module DuskConfigLog("dusk::config");
|
||||
static absl::flat_hash_map<std::string_view, ConfigVarBase*> RegisteredConfigVars;
|
||||
static bool RegistrationDone = false;
|
||||
|
||||
static std::string GetConfigJsonPath() {
|
||||
return (dusk::ConfigPath / ConfigFileName).string();
|
||||
static std::u8string GetConfigJsonPath() {
|
||||
return (dusk::ConfigPath / ConfigFileName).u8string();
|
||||
}
|
||||
|
||||
ConfigVarBase::ConfigVarBase(const char* name, const ConfigImplBase* impl) : name(name), registered(false), layer(ConfigVarLayer::Default), impl(impl) {
|
||||
@@ -60,7 +61,7 @@ void ConfigImpl<T>::loadFromJson(ConfigVar<T>& cVar, const json& jsonValue) {
|
||||
|
||||
template<ConfigValue T>
|
||||
nlohmann::json ConfigImpl<T>::dumpToJson(const ConfigVar<T>& cVar) {
|
||||
return cVar.getValue();
|
||||
return cVar.getValueForSave();
|
||||
}
|
||||
|
||||
template<ConfigValue T> requires std::is_integral_v<T> && std::is_signed_v<T>
|
||||
@@ -154,7 +155,9 @@ namespace dusk::config {
|
||||
template class ConfigImpl<f64>;
|
||||
template class ConfigImpl<std::string>;
|
||||
template class ConfigImpl<dusk::BloomMode>;
|
||||
template class ConfigImpl<dusk::DiscVerificationState>;
|
||||
template class ConfigImpl<dusk::GameLanguage>;
|
||||
template class ConfigImpl<dusk::GyroMode>;
|
||||
}
|
||||
|
||||
void dusk::config::Register(ConfigVarBase& configVar) {
|
||||
@@ -187,7 +190,7 @@ void dusk::config::LoadFromUserPreferences() {
|
||||
if (configJsonPath.empty()) {
|
||||
return;
|
||||
}
|
||||
LoadFromFileName(configJsonPath.c_str());
|
||||
LoadFromFileName(reinterpret_cast<const char*>(configJsonPath.c_str()));
|
||||
}
|
||||
|
||||
static void LoadFromPath(const char* path) {
|
||||
@@ -239,17 +242,27 @@ void dusk::config::Save() {
|
||||
return;
|
||||
}
|
||||
|
||||
DuskConfigLog.info("Saving config to '{}'", configJsonPath);
|
||||
DuskConfigLog.info(
|
||||
"Saving config to '{}'",
|
||||
reinterpret_cast<const char*>(configJsonPath.c_str()));
|
||||
|
||||
json j;
|
||||
|
||||
for (const auto& pair : RegisteredConfigVars) {
|
||||
if (pair.second->getLayer() == ConfigVarLayer::Value) {
|
||||
const auto layer = pair.second->getLayer();
|
||||
if (layer == ConfigVarLayer::Value || layer == ConfigVarLayer::Speedrun) {
|
||||
j[pair.first] = pair.second->getImpl()->dumpToJson(*pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
io::FileStream::WriteAllText(configJsonPath.c_str(), j.dump(4));
|
||||
io::FileStream::WriteAllText(reinterpret_cast<const char*>(configJsonPath.c_str()), j.dump(4));
|
||||
}
|
||||
|
||||
void dusk::config::ClearAllActionBindings(int port) {
|
||||
for (auto& actionBinding : getActionBinds() | std::views::values) {
|
||||
actionBinding.configVars->at(port).setValue(PAD_NATIVE_BUTTON_INVALID);
|
||||
}
|
||||
Save();
|
||||
}
|
||||
|
||||
ConfigVarBase* dusk::config::GetConfigVar(std::string_view name) {
|
||||
@@ -260,3 +273,9 @@ ConfigVarBase* dusk::config::GetConfigVar(std::string_view name) {
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void dusk::config::EnumerateRegistered(std::function<void(ConfigVarBase&)> callback) {
|
||||
for (auto& pair : RegisteredConfigVars) {
|
||||
callback(*pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "dusk/dusk.h"
|
||||
#include "dusk/logging.h"
|
||||
#include "dusk/main.h"
|
||||
#include "dusk/settings.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -13,114 +12,83 @@
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
#include "SDL3/SDL_filesystem.h"
|
||||
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
#include <sentry.h>
|
||||
#endif
|
||||
|
||||
namespace dusk {
|
||||
namespace dusk::crash_reporting {
|
||||
|
||||
namespace {
|
||||
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
bool g_sentryInitialized = false;
|
||||
|
||||
bool IsTruthy(std::string_view value) {
|
||||
return value == "1" || value == "true" || value == "TRUE" || value == "yes"
|
||||
|| value == "YES" || value == "on" || value == "ON";
|
||||
bool truthy(std::string_view value) {
|
||||
return value == "1" || value == "true" || value == "TRUE" || value == "yes" || value == "YES" ||
|
||||
value == "on" || value == "ON";
|
||||
}
|
||||
|
||||
std::string GetEnvOrEmpty(const char* name) {
|
||||
std::string env_or_empty(const char* name) {
|
||||
if (const char* value = std::getenv(name)) {
|
||||
return value;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool GetEffectiveEnabled() {
|
||||
const std::string env = GetEnvOrEmpty("DUSK_SENTRY_ENABLED");
|
||||
if (!env.empty()) {
|
||||
return IsTruthy(env);
|
||||
}
|
||||
return getSettings().backend.enableCrashReporting;
|
||||
bool disabled_by_env() {
|
||||
const std::string env = env_or_empty("DUSK_SENTRY_ENABLED");
|
||||
return !env.empty() && !truthy(env);
|
||||
}
|
||||
|
||||
std::string GetEffectiveDsn() {
|
||||
const std::string env = GetEnvOrEmpty("DUSK_SENTRY_DSN");
|
||||
std::string effective_dsn() {
|
||||
const std::string env = env_or_empty("DUSK_SENTRY_DSN");
|
||||
if (!env.empty()) {
|
||||
return env;
|
||||
}
|
||||
return DUSK_SENTRY_DSN;
|
||||
}
|
||||
|
||||
bool GetEffectiveDebug() {
|
||||
const std::string env = GetEnvOrEmpty("DUSK_SENTRY_DEBUG");
|
||||
bool effective_debug() {
|
||||
const std::string env = env_or_empty("DUSK_SENTRY_DEBUG");
|
||||
if (!env.empty()) {
|
||||
return IsTruthy(env);
|
||||
return truthy(env);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string GetReleaseName() {
|
||||
std::string release_name() {
|
||||
return std::string(AppName) + "@" DUSK_WC_DESCRIBE;
|
||||
}
|
||||
|
||||
std::filesystem::path GetSentryDatabasePath() {
|
||||
return dusk::ConfigPath / "sentry";
|
||||
std::filesystem::path sentry_database_path() {
|
||||
return dusk::CachePath / "sentry";
|
||||
}
|
||||
|
||||
std::filesystem::path GetLogAttachmentPath() {
|
||||
std::filesystem::path log_attachment_path() {
|
||||
if (const char* logPath = GetLogFilePath()) {
|
||||
return logPath;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::filesystem::path GetCrashpadHandlerPath() {
|
||||
const char* basePath = SDL_GetBasePath();
|
||||
if (!basePath) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::filesystem::path handlerDir(basePath);
|
||||
#if _WIN32
|
||||
return handlerDir / "crashpad_handler.exe";
|
||||
#else
|
||||
return handlerDir / "crashpad_handler";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ConfigurePathOptions(sentry_options_t* options) {
|
||||
const auto databasePath = GetSentryDatabasePath();
|
||||
void configure_path_options(sentry_options_t* options) {
|
||||
const auto databasePath = sentry_database_path();
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(databasePath, ec);
|
||||
if (ec) {
|
||||
DuskLog.warn("Unable to create Sentry database path '{}': {}",
|
||||
databasePath.string(), ec.message());
|
||||
DuskLog.warn(
|
||||
"Unable to create Sentry database path '{}': {}", databasePath.string(), ec.message());
|
||||
}
|
||||
|
||||
#if _WIN32
|
||||
const std::wstring databasePathWide = databasePath.wstring();
|
||||
sentry_options_set_database_pathw(options, databasePathWide.c_str());
|
||||
|
||||
const auto handlerPath = GetCrashpadHandlerPath();
|
||||
if (!handlerPath.empty()) {
|
||||
const std::wstring handlerPathWide = handlerPath.wstring();
|
||||
sentry_options_set_handler_pathw(options, handlerPathWide.c_str());
|
||||
}
|
||||
#else
|
||||
const std::string databasePathUtf8 = databasePath.string();
|
||||
sentry_options_set_database_path(options, databasePathUtf8.c_str());
|
||||
|
||||
const auto handlerPath = GetCrashpadHandlerPath();
|
||||
if (!handlerPath.empty()) {
|
||||
const std::string handlerPathUtf8 = handlerPath.string();
|
||||
sentry_options_set_handler_path(options, handlerPathUtf8.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto logPath = GetLogAttachmentPath();
|
||||
const auto logPath = log_attachment_path();
|
||||
if (!logPath.empty()) {
|
||||
#if _WIN32
|
||||
sentry_options_add_attachmentw(options, logPath.wstring().c_str());
|
||||
@@ -133,32 +101,29 @@ void ConfigurePathOptions(sentry_options_t* options) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void InitializeCrashReporting() {
|
||||
void initialize() {
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
if (g_sentryInitialized) {
|
||||
if (g_sentryInitialized || disabled_by_env()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GetEffectiveEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string dsn = GetEffectiveDsn();
|
||||
const std::string dsn = effective_dsn();
|
||||
if (dsn.empty()) {
|
||||
DuskLog.warn("Crash reporting is enabled but no Sentry DSN is configured");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string release = GetReleaseName();
|
||||
const std::string release = release_name();
|
||||
|
||||
sentry_options_t* options = sentry_options_new();
|
||||
sentry_options_set_dsn(options, dsn.c_str());
|
||||
sentry_options_set_release(options, release.c_str());
|
||||
sentry_options_set_environment(options, DUSK_SENTRY_ENVIRONMENT);
|
||||
sentry_options_set_debug(options, GetEffectiveDebug() ? 1 : 0);
|
||||
sentry_options_set_debug(options, effective_debug() ? 1 : 0);
|
||||
sentry_options_set_require_user_consent(options, 1);
|
||||
sentry_options_set_cache_keep(options, 1);
|
||||
sentry_options_set_max_breadcrumbs(options, 100);
|
||||
ConfigurePathOptions(options);
|
||||
configure_path_options(options);
|
||||
|
||||
if (sentry_init(options) != 0) {
|
||||
DuskLog.warn("Failed to initialize Sentry crash reporting");
|
||||
@@ -173,7 +138,7 @@ void InitializeCrashReporting() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShutdownCrashReporting() {
|
||||
void shutdown() {
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
if (!g_sentryInitialized) {
|
||||
return;
|
||||
@@ -184,4 +149,40 @@ void ShutdownCrashReporting() {
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace dusk
|
||||
Consent get_consent() {
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
if (!g_sentryInitialized) {
|
||||
return Consent::Unavailable;
|
||||
}
|
||||
|
||||
switch (sentry_user_consent_get()) {
|
||||
case SENTRY_USER_CONSENT_GIVEN:
|
||||
return Consent::Given;
|
||||
case SENTRY_USER_CONSENT_REVOKED:
|
||||
return Consent::Revoked;
|
||||
case SENTRY_USER_CONSENT_UNKNOWN:
|
||||
default:
|
||||
return Consent::Unknown;
|
||||
}
|
||||
#else
|
||||
return Consent::Unavailable;
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_consent(bool enabled) {
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
if (!g_sentryInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
sentry_user_consent_give();
|
||||
} else {
|
||||
sentry_user_consent_revoke();
|
||||
}
|
||||
#else
|
||||
(void)enabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace dusk::crash_reporting
|
||||
|
||||
+1100
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || \
|
||||
(defined(__APPLE__) && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_MACCATALYST) || \
|
||||
(defined(__linux__) && !defined(__ANDROID__))
|
||||
#define DUSK_CAN_OPEN_DATA_FOLDER 1
|
||||
#else
|
||||
#define DUSK_CAN_OPEN_DATA_FOLDER 0
|
||||
#endif
|
||||
|
||||
#if (defined(__APPLE__) && TARGET_OS_IOS && !TARGET_OS_MACCATALYST) || defined(__ANDROID__)
|
||||
#define DUSK_CAN_CHANGE_DATA_FOLDER 0
|
||||
#else
|
||||
#define DUSK_CAN_CHANGE_DATA_FOLDER 1
|
||||
#endif
|
||||
|
||||
namespace dusk::data {
|
||||
|
||||
struct Paths {
|
||||
std::filesystem::path userPath;
|
||||
std::filesystem::path cachePath;
|
||||
};
|
||||
|
||||
Paths initialize_data();
|
||||
std::filesystem::path configured_data_path();
|
||||
std::filesystem::path cache_path();
|
||||
bool open_data_path();
|
||||
bool set_custom_data_path(const char* path, std::string* errorOut);
|
||||
bool set_custom_data_path(const std::filesystem::path& path, std::string* errorOut);
|
||||
bool set_portable_data_path();
|
||||
bool reset_data_path();
|
||||
bool is_default_data_path();
|
||||
bool is_data_path_restart_pending();
|
||||
|
||||
} // namespace dusk::data
|
||||
@@ -0,0 +1,867 @@
|
||||
#ifdef DUSK_DISCORD
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include "discord.hpp"
|
||||
|
||||
#include "dusk/logging.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMCX
|
||||
#define NOSERVICE
|
||||
#define NOIME
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace dusk::discord::rpc {
|
||||
namespace {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
constexpr uint32_t kRpcVersion = 1;
|
||||
constexpr size_t kFrameHeaderSize = sizeof(uint32_t) * 2;
|
||||
constexpr size_t kMaxFramePayloadSize = 64 * 1024;
|
||||
constexpr auto kIoWait = std::chrono::milliseconds(500);
|
||||
constexpr auto kShutdownClearTimeout = std::chrono::milliseconds(200);
|
||||
constexpr auto kInitialReconnectDelay = std::chrono::milliseconds(500);
|
||||
constexpr auto kMaxReconnectDelay = std::chrono::milliseconds(60 * 1000);
|
||||
|
||||
enum class Opcode : uint32_t {
|
||||
Handshake = 0,
|
||||
Frame = 1,
|
||||
Close = 2,
|
||||
Ping = 3,
|
||||
Pong = 4,
|
||||
};
|
||||
|
||||
enum class ConnectionState {
|
||||
Disconnected,
|
||||
SentHandshake,
|
||||
Connected,
|
||||
};
|
||||
|
||||
enum class DisconnectCode : int {
|
||||
PipeClosed = 1,
|
||||
ReadCorrupt = 2,
|
||||
BadFrame = 3,
|
||||
};
|
||||
|
||||
struct Frame {
|
||||
Opcode opcode = Opcode::Frame;
|
||||
std::string payload;
|
||||
};
|
||||
|
||||
struct QueuedEvent {
|
||||
enum class Type {
|
||||
Ready,
|
||||
Disconnected,
|
||||
Error,
|
||||
};
|
||||
|
||||
Type type = Type::Ready;
|
||||
User user;
|
||||
int code = 0;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class Backoff {
|
||||
public:
|
||||
std::chrono::milliseconds next_delay() {
|
||||
const auto delay = currentDelay;
|
||||
currentDelay = std::min(currentDelay * 2, kMaxReconnectDelay);
|
||||
return delay;
|
||||
}
|
||||
|
||||
void reset() { currentDelay = kInitialReconnectDelay; }
|
||||
|
||||
private:
|
||||
std::chrono::milliseconds currentDelay = kInitialReconnectDelay;
|
||||
};
|
||||
|
||||
class IpcConnection {
|
||||
public:
|
||||
IpcConnection() = default;
|
||||
~IpcConnection() { close(); }
|
||||
|
||||
IpcConnection(const IpcConnection&) = delete;
|
||||
IpcConnection& operator=(const IpcConnection&) = delete;
|
||||
|
||||
bool open() {
|
||||
#ifdef _WIN32
|
||||
wchar_t pipeName[] = L"\\\\?\\pipe\\discord-ipc-0";
|
||||
constexpr size_t kPipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
||||
|
||||
for (wchar_t pipeNumber = L'0'; pipeNumber <= L'9'; ++pipeNumber) {
|
||||
pipeName[kPipeDigit] = pipeNumber;
|
||||
pipe = CreateFileW(
|
||||
pipeName, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (pipe != INVALID_HANDLE_VALUE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GetLastError() == ERROR_PIPE_BUSY && WaitNamedPipeW(pipeName, 10000)) {
|
||||
--pipeNumber;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
const auto tempPaths = get_temp_paths();
|
||||
for (const std::string& tempPath : tempPaths) {
|
||||
for (int pipeNumber = 0; pipeNumber < 10; ++pipeNumber) {
|
||||
socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (socketFd == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sockaddr_un pipeAddress{};
|
||||
pipeAddress.sun_family = AF_UNIX;
|
||||
const std::string socketPath =
|
||||
tempPath + "/discord-ipc-" + std::to_string(pipeNumber);
|
||||
if (socketPath.size() >= sizeof(pipeAddress.sun_path)) {
|
||||
close();
|
||||
continue;
|
||||
}
|
||||
|
||||
std::strncpy(
|
||||
pipeAddress.sun_path, socketPath.c_str(), sizeof(pipeAddress.sun_path) - 1);
|
||||
if (connect(socketFd, reinterpret_cast<const sockaddr*>(&pipeAddress),
|
||||
sizeof(pipeAddress)) == 0)
|
||||
{
|
||||
fcntl(socketFd, F_SETFL, O_NONBLOCK);
|
||||
#ifdef SO_NOSIGPIPE
|
||||
int optval = 1;
|
||||
setsockopt(socketFd, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
close();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void close() {
|
||||
#ifdef _WIN32
|
||||
if (pipe != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(pipe);
|
||||
pipe = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
#else
|
||||
if (socketFd != -1) {
|
||||
::close(socketFd);
|
||||
socketFd = -1;
|
||||
}
|
||||
#endif
|
||||
pendingRead.clear();
|
||||
}
|
||||
|
||||
bool is_open() const {
|
||||
#ifdef _WIN32
|
||||
return pipe != INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
return socketFd != -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool write_frame(const Frame& frame) {
|
||||
std::array<uint8_t, kFrameHeaderSize> header{};
|
||||
write_u32(header.data(), static_cast<uint32_t>(frame.opcode));
|
||||
write_u32(header.data() + sizeof(uint32_t), static_cast<uint32_t>(frame.payload.size()));
|
||||
|
||||
return write_all(header.data(), header.size()) &&
|
||||
write_all(
|
||||
reinterpret_cast<const uint8_t*>(frame.payload.data()), frame.payload.size());
|
||||
}
|
||||
|
||||
enum class ReadStatus {
|
||||
None,
|
||||
Frame,
|
||||
Closed,
|
||||
Corrupt,
|
||||
};
|
||||
|
||||
ReadStatus read_frame(Frame& frame) {
|
||||
if (!read_available()) {
|
||||
return is_open() ? ReadStatus::None : ReadStatus::Closed;
|
||||
}
|
||||
|
||||
if (pendingRead.size() < kFrameHeaderSize) {
|
||||
return ReadStatus::None;
|
||||
}
|
||||
|
||||
const uint32_t payloadLength = read_u32(pendingRead.data() + sizeof(uint32_t));
|
||||
if (payloadLength > kMaxFramePayloadSize) {
|
||||
return ReadStatus::Corrupt;
|
||||
}
|
||||
|
||||
const size_t frameLength = kFrameHeaderSize + payloadLength;
|
||||
if (pendingRead.size() < frameLength) {
|
||||
return ReadStatus::None;
|
||||
}
|
||||
|
||||
frame.opcode = static_cast<Opcode>(read_u32(pendingRead.data()));
|
||||
frame.payload.assign(
|
||||
reinterpret_cast<const char*>(pendingRead.data() + kFrameHeaderSize), payloadLength);
|
||||
pendingRead.erase(
|
||||
pendingRead.begin(), pendingRead.begin() + static_cast<std::ptrdiff_t>(frameLength));
|
||||
return ReadStatus::Frame;
|
||||
}
|
||||
|
||||
private:
|
||||
#ifndef _WIN32
|
||||
static std::vector<std::string> get_temp_paths() {
|
||||
std::vector<std::string> paths;
|
||||
for (const char* name : {"XDG_RUNTIME_DIR", "TMPDIR", "TMP", "TEMP"}) {
|
||||
if (const char* value = std::getenv(name); value && value[0] != '\0') {
|
||||
if (std::find(paths.begin(), paths.end(), value) == paths.end()) {
|
||||
paths.emplace_back(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (std::find(paths.begin(), paths.end(), "/tmp") == paths.end()) {
|
||||
paths.emplace_back("/tmp");
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void write_u32(uint8_t* out, uint32_t value) {
|
||||
out[0] = static_cast<uint8_t>(value & 0xff);
|
||||
out[1] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
out[2] = static_cast<uint8_t>((value >> 16) & 0xff);
|
||||
out[3] = static_cast<uint8_t>((value >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static uint32_t read_u32(const uint8_t* in) {
|
||||
return static_cast<uint32_t>(in[0]) | (static_cast<uint32_t>(in[1]) << 8) |
|
||||
(static_cast<uint32_t>(in[2]) << 16) | (static_cast<uint32_t>(in[3]) << 24);
|
||||
}
|
||||
|
||||
bool write_all(const uint8_t* data, size_t length) {
|
||||
size_t written = 0;
|
||||
while (written < length) {
|
||||
#ifdef _WIN32
|
||||
DWORD bytesWritten = 0;
|
||||
if (WriteFile(pipe, data + written, static_cast<DWORD>(length - written), &bytesWritten,
|
||||
nullptr) == FALSE ||
|
||||
bytesWritten == 0)
|
||||
{
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
written += bytesWritten;
|
||||
#else
|
||||
#ifdef MSG_NOSIGNAL
|
||||
constexpr int kMsgFlags = MSG_NOSIGNAL;
|
||||
#else
|
||||
constexpr int kMsgFlags = 0;
|
||||
#endif
|
||||
const ssize_t bytesWritten =
|
||||
send(socketFd, data + written, length - written, kMsgFlags);
|
||||
if (bytesWritten < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
continue;
|
||||
}
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
if (bytesWritten == 0) {
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
written += static_cast<size_t>(bytesWritten);
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_available() {
|
||||
std::array<uint8_t, 4096> buffer{};
|
||||
bool readAny = false;
|
||||
|
||||
for (;;) {
|
||||
#ifdef _WIN32
|
||||
DWORD bytesAvailable = 0;
|
||||
if (PeekNamedPipe(pipe, nullptr, 0, nullptr, &bytesAvailable, nullptr) == FALSE) {
|
||||
close();
|
||||
return readAny;
|
||||
}
|
||||
if (bytesAvailable == 0) {
|
||||
return readAny;
|
||||
}
|
||||
|
||||
const DWORD bytesToRead =
|
||||
std::min<DWORD>(bytesAvailable, static_cast<DWORD>(buffer.size()));
|
||||
DWORD bytesRead = 0;
|
||||
if (ReadFile(pipe, buffer.data(), bytesToRead, &bytesRead, nullptr) == FALSE) {
|
||||
close();
|
||||
return readAny;
|
||||
}
|
||||
if (bytesRead == 0) {
|
||||
close();
|
||||
return readAny;
|
||||
}
|
||||
pendingRead.insert(pendingRead.end(), buffer.begin(), buffer.begin() + bytesRead);
|
||||
readAny = true;
|
||||
#else
|
||||
#ifdef MSG_NOSIGNAL
|
||||
constexpr int kMsgFlags = MSG_NOSIGNAL;
|
||||
#else
|
||||
constexpr int kMsgFlags = 0;
|
||||
#endif
|
||||
const ssize_t bytesRead = recv(socketFd, buffer.data(), buffer.size(), kMsgFlags);
|
||||
if (bytesRead < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return readAny;
|
||||
}
|
||||
close();
|
||||
return readAny;
|
||||
}
|
||||
if (bytesRead == 0) {
|
||||
close();
|
||||
return readAny;
|
||||
}
|
||||
pendingRead.insert(pendingRead.end(), buffer.begin(), buffer.begin() + bytesRead);
|
||||
readAny = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE pipe = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
int socketFd = -1;
|
||||
#endif
|
||||
std::vector<uint8_t> pendingRead;
|
||||
};
|
||||
|
||||
int current_process_id() {
|
||||
#ifdef _WIN32
|
||||
return static_cast<int>(GetCurrentProcessId());
|
||||
#else
|
||||
return static_cast<int>(getpid());
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string next_nonce() {
|
||||
static std::atomic_uint64_t sNonce{1};
|
||||
return std::to_string(sNonce.fetch_add(1));
|
||||
}
|
||||
|
||||
const json* find_member(const json& object, const char* key) {
|
||||
if (!object.is_object()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto member = object.find(key);
|
||||
if (member == object.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &*member;
|
||||
}
|
||||
|
||||
std::string json_string_member(const json& object, const char* key) {
|
||||
const json* member = find_member(object, key);
|
||||
if (!member || !member->is_string()) {
|
||||
return {};
|
||||
}
|
||||
return member->get<std::string>();
|
||||
}
|
||||
|
||||
int json_int_member(const json& object, const char* key, int defaultValue) {
|
||||
const json* member = find_member(object, key);
|
||||
if (!member || !member->is_number_integer()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try {
|
||||
return member->get<int>();
|
||||
} catch (const json::exception&) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
json make_presence_activity(const Presence& presence) {
|
||||
json activity = json::object();
|
||||
|
||||
if (!presence.state.empty()) {
|
||||
activity["state"] = presence.state;
|
||||
}
|
||||
if (!presence.details.empty()) {
|
||||
activity["details"] = presence.details;
|
||||
}
|
||||
if (presence.startTimestamp != 0) {
|
||||
activity["timestamps"] = {{"start", presence.startTimestamp}};
|
||||
}
|
||||
if (!presence.largeImageKey.empty() || !presence.largeImageText.empty()) {
|
||||
json assets = json::object();
|
||||
if (!presence.largeImageKey.empty()) {
|
||||
assets["large_image"] = presence.largeImageKey;
|
||||
}
|
||||
if (!presence.largeImageText.empty()) {
|
||||
assets["large_text"] = presence.largeImageText;
|
||||
}
|
||||
activity["assets"] = std::move(assets);
|
||||
}
|
||||
|
||||
return activity;
|
||||
}
|
||||
|
||||
Frame make_handshake_frame(std::string_view applicationId) {
|
||||
return {
|
||||
Opcode::Handshake,
|
||||
json{
|
||||
{"v", kRpcVersion},
|
||||
{"client_id", std::string(applicationId)},
|
||||
}
|
||||
.dump(),
|
||||
};
|
||||
}
|
||||
|
||||
Frame make_set_activity_frame(std::string nonce, int pid, std::optional<Presence> presence) {
|
||||
json args = {{"pid", pid}};
|
||||
if (presence) {
|
||||
args["activity"] = make_presence_activity(*presence);
|
||||
} else {
|
||||
args["activity"] = nullptr;
|
||||
}
|
||||
|
||||
return {
|
||||
Opcode::Frame,
|
||||
json{
|
||||
{"cmd", "SET_ACTIVITY"},
|
||||
{"nonce", std::move(nonce)},
|
||||
{"args", std::move(args)},
|
||||
}
|
||||
.dump(),
|
||||
};
|
||||
}
|
||||
|
||||
class Client {
|
||||
public:
|
||||
void initialize(std::string applicationId, EventHandlers handlers) {
|
||||
shutdown();
|
||||
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
this->applicationId = std::move(applicationId);
|
||||
this->handlers = std::move(handlers);
|
||||
shouldRun = true;
|
||||
queuedPresence.reset();
|
||||
hasQueuedPresence = false;
|
||||
clearRequested = false;
|
||||
sentInitialConnectLog = false;
|
||||
}
|
||||
|
||||
ioThread = std::thread([this] { io_loop(); });
|
||||
}
|
||||
|
||||
void run_callbacks() {
|
||||
std::deque<QueuedEvent> events;
|
||||
EventHandlers localHandlers;
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
events.swap(queuedEvents);
|
||||
localHandlers = handlers;
|
||||
}
|
||||
|
||||
for (const QueuedEvent& event : events) {
|
||||
switch (event.type) {
|
||||
case QueuedEvent::Type::Ready:
|
||||
if (localHandlers.ready) {
|
||||
localHandlers.ready(event.user);
|
||||
}
|
||||
break;
|
||||
case QueuedEvent::Type::Disconnected:
|
||||
if (localHandlers.disconnected) {
|
||||
localHandlers.disconnected(event.code, event.message);
|
||||
}
|
||||
break;
|
||||
case QueuedEvent::Type::Error:
|
||||
if (localHandlers.error) {
|
||||
localHandlers.error(event.code, event.message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_presence(Presence presence) {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (!shouldRun) {
|
||||
return;
|
||||
}
|
||||
queuedPresence = std::move(presence);
|
||||
hasQueuedPresence = true;
|
||||
}
|
||||
cv.notify_all();
|
||||
}
|
||||
|
||||
void clear_presence() {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (!shouldRun) {
|
||||
return;
|
||||
}
|
||||
queuedPresence.reset();
|
||||
hasQueuedPresence = false;
|
||||
clearRequested = true;
|
||||
}
|
||||
cv.notify_all();
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (!shouldRun && !ioThread.joinable()) {
|
||||
return;
|
||||
}
|
||||
shouldRun = false;
|
||||
clearRequested = true;
|
||||
}
|
||||
cv.notify_all();
|
||||
|
||||
if (ioThread.joinable()) {
|
||||
ioThread.join();
|
||||
}
|
||||
|
||||
std::lock_guard lock(mutex);
|
||||
queuedPresence.reset();
|
||||
hasQueuedPresence = false;
|
||||
clearRequested = false;
|
||||
queuedEvents.clear();
|
||||
handlers = {};
|
||||
applicationId.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
void io_loop() {
|
||||
IpcConnection connection;
|
||||
ConnectionState state = ConnectionState::Disconnected;
|
||||
Backoff reconnectBackoff;
|
||||
auto nextConnect = std::chrono::steady_clock::now();
|
||||
const int pid = current_process_id();
|
||||
std::string localApplicationId;
|
||||
|
||||
for (;;) {
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
if (!shouldRun) {
|
||||
break;
|
||||
}
|
||||
localApplicationId = applicationId;
|
||||
}
|
||||
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (state == ConnectionState::Disconnected && now >= nextConnect) {
|
||||
if (connection.open()) {
|
||||
if (connection.write_frame(make_handshake_frame(localApplicationId))) {
|
||||
state = ConnectionState::SentHandshake;
|
||||
} else {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ConnectionState::Disconnected) {
|
||||
log_waiting_for_discord_once();
|
||||
nextConnect = now + reconnectBackoff.next_delay();
|
||||
}
|
||||
}
|
||||
|
||||
if (state != ConnectionState::Disconnected) {
|
||||
process_reads(connection, state, reconnectBackoff, nextConnect);
|
||||
}
|
||||
|
||||
if (state == ConnectionState::Connected) {
|
||||
flush_pending_presence(connection, pid);
|
||||
}
|
||||
|
||||
std::unique_lock lock(mutex);
|
||||
if (!shouldRun) {
|
||||
break;
|
||||
}
|
||||
cv.wait_for(lock, kIoWait);
|
||||
}
|
||||
|
||||
flush_shutdown_clear(connection, state, pid);
|
||||
connection.close();
|
||||
}
|
||||
|
||||
void process_reads(IpcConnection& connection, ConnectionState& state, Backoff& reconnectBackoff,
|
||||
std::chrono::steady_clock::time_point& nextConnect) {
|
||||
for (;;) {
|
||||
Frame frame;
|
||||
const auto status = connection.read_frame(frame);
|
||||
if (status == IpcConnection::ReadStatus::None) {
|
||||
return;
|
||||
}
|
||||
if (status == IpcConnection::ReadStatus::Closed) {
|
||||
handle_disconnect(connection, state, reconnectBackoff, nextConnect,
|
||||
static_cast<int>(DisconnectCode::PipeClosed), "Pipe closed");
|
||||
return;
|
||||
}
|
||||
if (status == IpcConnection::ReadStatus::Corrupt) {
|
||||
handle_disconnect(connection, state, reconnectBackoff, nextConnect,
|
||||
static_cast<int>(DisconnectCode::ReadCorrupt), "Oversized Discord IPC frame");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frame.opcode) {
|
||||
case Opcode::Frame:
|
||||
process_json_frame(frame.payload, state, reconnectBackoff);
|
||||
break;
|
||||
case Opcode::Close:
|
||||
process_close_frame(
|
||||
frame.payload, connection, state, reconnectBackoff, nextConnect);
|
||||
return;
|
||||
case Opcode::Ping:
|
||||
connection.write_frame({Opcode::Pong, frame.payload});
|
||||
break;
|
||||
case Opcode::Pong:
|
||||
break;
|
||||
case Opcode::Handshake:
|
||||
default:
|
||||
handle_disconnect(connection, state, reconnectBackoff, nextConnect,
|
||||
static_cast<int>(DisconnectCode::BadFrame), "Bad Discord IPC frame");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_json_frame(
|
||||
const std::string& payload, ConnectionState& state, Backoff& reconnectBackoff) {
|
||||
json message;
|
||||
try {
|
||||
message = json::parse(payload);
|
||||
} catch (const json::parse_error&) {
|
||||
enqueue_error(
|
||||
static_cast<int>(DisconnectCode::ReadCorrupt), "Invalid Discord IPC JSON");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string cmd = json_string_member(message, "cmd");
|
||||
const std::string evt = json_string_member(message, "evt");
|
||||
|
||||
if (state == ConnectionState::SentHandshake && cmd == "DISPATCH" && evt == "READY") {
|
||||
state = ConnectionState::Connected;
|
||||
reconnectBackoff.reset();
|
||||
enqueue_ready(message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt == "ERROR") {
|
||||
const json* data = find_member(message, "data");
|
||||
enqueue_error(data ? json_int_member(*data, "code", 0) : 0,
|
||||
data ? json_string_member(*data, "message") : std::string{});
|
||||
}
|
||||
}
|
||||
|
||||
void process_close_frame(const std::string& payload, IpcConnection& connection,
|
||||
ConnectionState& state, Backoff& reconnectBackoff,
|
||||
std::chrono::steady_clock::time_point& nextConnect) {
|
||||
int code = static_cast<int>(DisconnectCode::PipeClosed);
|
||||
std::string message = "Discord closed IPC connection";
|
||||
|
||||
try {
|
||||
const json closePayload = json::parse(payload);
|
||||
code = json_int_member(closePayload, "code", code);
|
||||
const std::string closeMessage = json_string_member(closePayload, "message");
|
||||
if (!closeMessage.empty()) {
|
||||
message = closeMessage;
|
||||
}
|
||||
} catch (const json::exception&) {
|
||||
}
|
||||
|
||||
handle_disconnect(connection, state, reconnectBackoff, nextConnect, code, message);
|
||||
}
|
||||
|
||||
void handle_disconnect(IpcConnection& connection, ConnectionState& state,
|
||||
Backoff& reconnectBackoff, std::chrono::steady_clock::time_point& nextConnect, int code,
|
||||
std::string_view message) {
|
||||
const bool wasConnected =
|
||||
state == ConnectionState::Connected || state == ConnectionState::SentHandshake;
|
||||
connection.close();
|
||||
state = ConnectionState::Disconnected;
|
||||
nextConnect = std::chrono::steady_clock::now() + reconnectBackoff.next_delay();
|
||||
if (wasConnected) {
|
||||
enqueue_disconnected(code, message);
|
||||
}
|
||||
}
|
||||
|
||||
void flush_pending_presence(IpcConnection& connection, int pid) {
|
||||
std::optional<Presence> presence;
|
||||
bool shouldClear = false;
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (hasQueuedPresence) {
|
||||
presence = queuedPresence;
|
||||
hasQueuedPresence = false;
|
||||
} else if (clearRequested) {
|
||||
shouldClear = true;
|
||||
clearRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (presence) {
|
||||
if (!connection.write_frame(
|
||||
make_set_activity_frame(next_nonce(), pid, std::move(presence))))
|
||||
{
|
||||
requeue_presence();
|
||||
}
|
||||
} else if (shouldClear) {
|
||||
connection.write_frame(make_set_activity_frame(next_nonce(), pid, std::nullopt));
|
||||
}
|
||||
}
|
||||
|
||||
void flush_shutdown_clear(IpcConnection& connection, ConnectionState state, int pid) {
|
||||
if (state != ConnectionState::Connected || !connection.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
connection.write_frame(make_set_activity_frame(next_nonce(), pid, std::nullopt));
|
||||
const auto deadline = std::chrono::steady_clock::now() + kShutdownClearTimeout;
|
||||
while (std::chrono::steady_clock::now() < deadline) {
|
||||
Frame frame;
|
||||
const auto status = connection.read_frame(frame);
|
||||
if (status == IpcConnection::ReadStatus::None) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
continue;
|
||||
}
|
||||
if (status != IpcConnection::ReadStatus::Frame) {
|
||||
break;
|
||||
}
|
||||
if (frame.opcode == Opcode::Ping) {
|
||||
connection.write_frame({Opcode::Pong, frame.payload});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void requeue_presence() {
|
||||
std::lock_guard lock(mutex);
|
||||
if (queuedPresence) {
|
||||
hasQueuedPresence = true;
|
||||
}
|
||||
}
|
||||
|
||||
void enqueue_ready(const json& readyMessage) {
|
||||
User user;
|
||||
const auto data = readyMessage.find("data");
|
||||
if (data != readyMessage.end() && data->is_object()) {
|
||||
const auto userIt = data->find("user");
|
||||
if (userIt != data->end() && userIt->is_object()) {
|
||||
user.id = json_string_member(*userIt, "id");
|
||||
user.username = json_string_member(*userIt, "username");
|
||||
user.discriminator = json_string_member(*userIt, "discriminator");
|
||||
user.avatar = json_string_member(*userIt, "avatar");
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard lock(mutex);
|
||||
queuedEvents.push_back({QueuedEvent::Type::Ready, std::move(user)});
|
||||
}
|
||||
|
||||
void enqueue_disconnected(int code, std::string_view message) {
|
||||
std::lock_guard lock(mutex);
|
||||
QueuedEvent event;
|
||||
event.type = QueuedEvent::Type::Disconnected;
|
||||
event.code = code;
|
||||
event.message = message;
|
||||
queuedEvents.push_back(std::move(event));
|
||||
}
|
||||
|
||||
void enqueue_error(int code, std::string_view message) {
|
||||
std::lock_guard lock(mutex);
|
||||
QueuedEvent event;
|
||||
event.type = QueuedEvent::Type::Error;
|
||||
event.code = code;
|
||||
event.message = message;
|
||||
queuedEvents.push_back(std::move(event));
|
||||
}
|
||||
|
||||
void log_waiting_for_discord_once() {
|
||||
bool shouldLog = false;
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (!sentInitialConnectLog) {
|
||||
sentInitialConnectLog = true;
|
||||
shouldLog = true;
|
||||
}
|
||||
}
|
||||
if (shouldLog) {
|
||||
DuskLog.info("Discord: Waiting for local Discord IPC");
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv;
|
||||
std::thread ioThread;
|
||||
std::string applicationId;
|
||||
EventHandlers handlers;
|
||||
std::deque<QueuedEvent> queuedEvents;
|
||||
std::optional<Presence> queuedPresence;
|
||||
bool hasQueuedPresence = false;
|
||||
bool clearRequested = false;
|
||||
bool shouldRun = false;
|
||||
bool sentInitialConnectLog = false;
|
||||
};
|
||||
|
||||
Client& client() {
|
||||
static Client sClient;
|
||||
return sClient;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void initialize(std::string applicationId, EventHandlers handlers) {
|
||||
client().initialize(std::move(applicationId), std::move(handlers));
|
||||
}
|
||||
|
||||
void run_callbacks() {
|
||||
client().run_callbacks();
|
||||
}
|
||||
|
||||
void update_presence(Presence presence) {
|
||||
client().update_presence(std::move(presence));
|
||||
}
|
||||
|
||||
void clear_presence() {
|
||||
client().clear_presence();
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
client().shutdown();
|
||||
}
|
||||
|
||||
} // namespace dusk::discord::rpc
|
||||
|
||||
#endif // DUSK_DISCORD
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef DUSK_DISCORD
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace dusk::discord::rpc {
|
||||
|
||||
struct User {
|
||||
std::string id;
|
||||
std::string username;
|
||||
std::string discriminator;
|
||||
std::string avatar;
|
||||
};
|
||||
|
||||
struct Presence {
|
||||
std::string state;
|
||||
std::string details;
|
||||
int64_t startTimestamp = 0;
|
||||
std::string largeImageKey;
|
||||
std::string largeImageText;
|
||||
};
|
||||
|
||||
struct EventHandlers {
|
||||
std::function<void(const User&)> ready;
|
||||
std::function<void(int, std::string_view)> disconnected;
|
||||
std::function<void(int, std::string_view)> error;
|
||||
};
|
||||
|
||||
void initialize(std::string applicationId, EventHandlers handlers);
|
||||
void run_callbacks();
|
||||
void update_presence(Presence presence);
|
||||
void clear_presence();
|
||||
void shutdown();
|
||||
|
||||
} // namespace dusk::discord::rpc
|
||||
|
||||
#endif // DUSK_DISCORD
|
||||
@@ -1,38 +1,39 @@
|
||||
#ifdef DUSK_DISCORD_RPC
|
||||
#ifdef DUSK_DISCORD
|
||||
|
||||
#include "dusk/discord_presence.hpp"
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "discord.hpp"
|
||||
#include "dusk/logging.h"
|
||||
#include "dusk/main.h"
|
||||
#include "dusk/map_loader_definitions.h"
|
||||
#include "d/d_com_inf_game.h"
|
||||
#include "discord_rpc.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace dusk {
|
||||
namespace discord {
|
||||
namespace dusk::discord {
|
||||
|
||||
static int64_t g_startTime = 0;
|
||||
static bool g_initialized = false;
|
||||
static const char* APPLICATION_ID = "1495632471994405035";
|
||||
static constexpr const char* kApplicationId = "1495632471994405035";
|
||||
|
||||
static void OnReady(const DiscordUser* user) {
|
||||
DuskLog.info("Discord: Connected as {}", user->username);
|
||||
static void on_ready(const rpc::User& user) {
|
||||
DuskLog.info("Discord: Connected as {}", user.username);
|
||||
}
|
||||
|
||||
static void OnDisconnected(int errorCode, const char* message) {
|
||||
static void on_disconnected(int errorCode, std::string_view message) {
|
||||
DuskLog.warn("Discord: Disconnected ({}: {})", errorCode, message);
|
||||
}
|
||||
|
||||
static void OnError(int errorCode, const char* message) {
|
||||
static void on_error(int errorCode, std::string_view message) {
|
||||
DuskLog.warn("Discord: Error ({}: {})", errorCode, message);
|
||||
}
|
||||
|
||||
static const char* LookupMapName(const char* mapFile) {
|
||||
if (!mapFile || mapFile[0] == '\0') return nullptr;
|
||||
static const char* lookup_map_name(const char* mapFile) {
|
||||
if (!mapFile || mapFile[0] == '\0')
|
||||
return nullptr;
|
||||
for (const auto& region : gameRegions) {
|
||||
for (const auto& map : region.maps) {
|
||||
if (map.mapFile && strcmp(mapFile, map.mapFile) == 0) {
|
||||
@@ -43,80 +44,80 @@ static const char* LookupMapName(const char* mapFile) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
g_startTime = static_cast<int64_t>(
|
||||
std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()
|
||||
).count()
|
||||
);
|
||||
void initialize() {
|
||||
g_startTime = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
|
||||
DiscordEventHandlers handlers{};
|
||||
handlers.ready = OnReady;
|
||||
handlers.disconnected = OnDisconnected;
|
||||
handlers.errored = OnError;
|
||||
Discord_Initialize(APPLICATION_ID, &handlers, 0, nullptr);
|
||||
rpc::EventHandlers handlers{};
|
||||
handlers.ready = on_ready;
|
||||
handlers.disconnected = on_disconnected;
|
||||
handlers.error = on_error;
|
||||
rpc::initialize(kApplicationId, std::move(handlers));
|
||||
g_initialized = true;
|
||||
|
||||
DuskLog.info("Discord Rich Presence initialized");
|
||||
}
|
||||
|
||||
void RunCallbacks() {
|
||||
if (!g_initialized) return;
|
||||
Discord_RunCallbacks();
|
||||
void run_callbacks() {
|
||||
if (!g_initialized)
|
||||
return;
|
||||
rpc::run_callbacks();
|
||||
}
|
||||
|
||||
void UpdatePresence() {
|
||||
if (!g_initialized) return;
|
||||
void update_presence() {
|
||||
if (!g_initialized)
|
||||
return;
|
||||
|
||||
static auto lastUpdate = std::chrono::steady_clock::time_point{};
|
||||
static auto sLastUpdate = std::chrono::steady_clock::time_point{};
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now - lastUpdate < std::chrono::seconds(15)) return;
|
||||
lastUpdate = now;
|
||||
if (now - sLastUpdate < std::chrono::seconds(15))
|
||||
return;
|
||||
sLastUpdate = now;
|
||||
|
||||
static std::string detailsBuf;
|
||||
static std::string stateBuf;
|
||||
static std::string sDetailsBuf;
|
||||
static std::string sStateBuf;
|
||||
|
||||
DiscordRichPresence presence{};
|
||||
rpc::Presence presence{};
|
||||
presence.startTimestamp = g_startTime;
|
||||
presence.largeImageKey = "icon";
|
||||
presence.largeImageText = "Dusk";
|
||||
presence.largeImageText = "Dusklight";
|
||||
|
||||
if (dusk::IsGameLaunched) {
|
||||
if (IsGameLaunched) {
|
||||
const char* stageName = dComIfGp_getLastPlayStageName();
|
||||
|
||||
// stageName is empty until a room is actually entered
|
||||
if (stageName[0] != '\0') {
|
||||
const char* locationName = LookupMapName(stageName);
|
||||
const char* locationName = lookup_map_name(stageName);
|
||||
|
||||
if (locationName) {
|
||||
detailsBuf = locationName;
|
||||
}
|
||||
else {
|
||||
detailsBuf = "Twilight Princess";
|
||||
sDetailsBuf = locationName;
|
||||
} else {
|
||||
sDetailsBuf = "Twilight Princess";
|
||||
}
|
||||
|
||||
presence.details = detailsBuf.c_str();
|
||||
presence.details = sDetailsBuf;
|
||||
|
||||
stateBuf = fmt::format(FMT_STRING("{}/{} \u2665 | {} Rupees"),
|
||||
sStateBuf = fmt::format(FMT_STRING("{}/{} \u2665 | {} Rupees"),
|
||||
dComIfGs_getLife() / 4, dComIfGs_getMaxLife() / 5, dComIfGs_getRupee());
|
||||
|
||||
presence.state = stateBuf.c_str();
|
||||
presence.state = sStateBuf;
|
||||
}
|
||||
}
|
||||
|
||||
Discord_UpdatePresence(&presence);
|
||||
rpc::update_presence(std::move(presence));
|
||||
DuskLog.debug("Discord Rich Presence sent");
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
if (!g_initialized) return;
|
||||
Discord_ClearPresence();
|
||||
Discord_Shutdown();
|
||||
void shutdown() {
|
||||
if (!g_initialized)
|
||||
return;
|
||||
rpc::clear_presence();
|
||||
rpc::shutdown();
|
||||
g_initialized = false;
|
||||
DuskLog.info("Discord Rich Presence shut down");
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
} // namespace dusk
|
||||
} // namespace dusk::discord
|
||||
|
||||
#endif // DUSK_DISCORD_RPC
|
||||
#endif // DUSK_DISCORD
|
||||
|
||||
+227
-4
@@ -1,14 +1,28 @@
|
||||
#include "file_select.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include <SDL3/SDL_dialog.h>
|
||||
#include <SDL3/SDL_error.h>
|
||||
#include <SDL3/SDL_init.h>
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
|
||||
#if defined(__ANDROID__) || defined(ANDROID)
|
||||
#include <SDL3/SDL_system.h>
|
||||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_MACCATALYST
|
||||
#define USE_MACOS_FOLDER_DIALOG 1
|
||||
#else
|
||||
#define USE_MACOS_FOLDER_DIALOG 0
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
||||
#define USE_IOS_DIALOG 1
|
||||
#include "ios/FileSelectDialog.h"
|
||||
@@ -16,9 +30,175 @@
|
||||
#define USE_IOS_DIALOG 0
|
||||
#endif
|
||||
|
||||
#if USE_MACOS_FOLDER_DIALOG
|
||||
namespace dusk {
|
||||
bool ShowMacOSFolderSelect(
|
||||
FileCallback callback, void* userdata, SDL_Window* window, const char* default_location);
|
||||
} // namespace dusk
|
||||
#endif
|
||||
|
||||
namespace dusk {
|
||||
namespace {
|
||||
|
||||
std::string fallback_display_name(std::string_view path) {
|
||||
if (path.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string pathString(path);
|
||||
while (pathString.size() > 1 && (pathString.back() == '/' || pathString.back() == '\\')) {
|
||||
pathString.pop_back();
|
||||
}
|
||||
|
||||
const std::size_t slash = pathString.find_last_of("/\\");
|
||||
if (slash == std::string::npos || slash + 1 >= pathString.size()) {
|
||||
return pathString;
|
||||
}
|
||||
return pathString.substr(slash + 1);
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__) || defined(ANDROID)
|
||||
bool clear_pending_exception(JNIEnv* env) {
|
||||
if (env == nullptr || !env->ExceptionCheck()) {
|
||||
return false;
|
||||
}
|
||||
env->ExceptionClear();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string to_string(JNIEnv* env, jstring value) {
|
||||
if (env == nullptr || value == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const char* utf8 = env->GetStringUTFChars(value, nullptr);
|
||||
if (utf8 == nullptr) {
|
||||
clear_pending_exception(env);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result(utf8);
|
||||
env->ReleaseStringUTFChars(value, utf8);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string android_display_name(std::string_view path) {
|
||||
auto* env = static_cast<JNIEnv*>(SDL_GetAndroidJNIEnv());
|
||||
if (env == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
jobject activity = static_cast<jobject>(SDL_GetAndroidActivity());
|
||||
if (activity == nullptr || clear_pending_exception(env)) {
|
||||
if (activity != nullptr) {
|
||||
env->DeleteLocalRef(activity);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
jclass activityClass = env->GetObjectClass(activity);
|
||||
if (activityClass == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(activity);
|
||||
return {};
|
||||
}
|
||||
|
||||
jmethodID getDisplayName = env->GetMethodID(
|
||||
activityClass, "getDisplayNameForUri", "(Ljava/lang/String;)Ljava/lang/String;");
|
||||
env->DeleteLocalRef(activityClass);
|
||||
if (getDisplayName == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(activity);
|
||||
return {};
|
||||
}
|
||||
|
||||
jstring uri = env->NewStringUTF(std::string(path).c_str());
|
||||
if (uri == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(activity);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto* displayName = static_cast<jstring>(env->CallObjectMethod(activity, getDisplayName, uri));
|
||||
env->DeleteLocalRef(uri);
|
||||
env->DeleteLocalRef(activity);
|
||||
if (displayName == nullptr || clear_pending_exception(env)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result = to_string(env, displayName);
|
||||
env->DeleteLocalRef(displayName);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct AndroidFolderDialogState {
|
||||
FileCallback callback;
|
||||
void* userdata;
|
||||
std::string path;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
void onAndroidFolderDialogFinished(void* userdata) {
|
||||
std::unique_ptr<AndroidFolderDialogState> state(
|
||||
static_cast<AndroidFolderDialogState*>(userdata));
|
||||
|
||||
const char* path = state->path.empty() ? nullptr : state->path.c_str();
|
||||
const char* error = state->error.empty() ? nullptr : state->error.c_str();
|
||||
state->callback(state->userdata, path, error);
|
||||
}
|
||||
|
||||
bool show_android_folder_select(AndroidFolderDialogState* state) {
|
||||
auto* env = static_cast<JNIEnv*>(SDL_GetAndroidJNIEnv());
|
||||
if (env == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jobject activity = static_cast<jobject>(SDL_GetAndroidActivity());
|
||||
if (activity == nullptr || clear_pending_exception(env)) {
|
||||
if (activity != nullptr) {
|
||||
env->DeleteLocalRef(activity);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
jclass activityClass = env->GetObjectClass(activity);
|
||||
if (activityClass == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(activity);
|
||||
return false;
|
||||
}
|
||||
|
||||
jmethodID showFolderDialog =
|
||||
env->GetMethodID(activityClass, "showFolderDialog", "(J)Z");
|
||||
env->DeleteLocalRef(activityClass);
|
||||
if (showFolderDialog == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(activity);
|
||||
return false;
|
||||
}
|
||||
|
||||
const jboolean shown = env->CallBooleanMethod(
|
||||
activity, showFolderDialog, reinterpret_cast<jlong>(state));
|
||||
env->DeleteLocalRef(activity);
|
||||
if (clear_pending_exception(env)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return shown == JNI_TRUE;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_dev_twilitrealm_dusk_DuskActivity_nativeFolderDialogResult(
|
||||
JNIEnv* env, jclass, jlong userdata, jstring path, jstring error) {
|
||||
auto* state = reinterpret_cast<AndroidFolderDialogState*>(userdata);
|
||||
if (state == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
state->path = to_string(env, path);
|
||||
state->error = to_string(env, error);
|
||||
|
||||
if (!SDL_RunOnMainThread(&onAndroidFolderDialogFinished, state, false)) {
|
||||
onAndroidFolderDialogFinished(state);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_IOS_DIALOG
|
||||
struct IOSDialogCallbackState {
|
||||
FileCallback callback;
|
||||
@@ -66,8 +246,8 @@ void onSDLDialogFinished(void* userdata, const char* const* filelist, [[maybe_un
|
||||
} // namespace
|
||||
|
||||
void ShowFileSelect(FileCallback callback, void* userdata, SDL_Window* window,
|
||||
const SDL_DialogFileFilter* filters, int nfilters, const char* default_location,
|
||||
bool allow_many) {
|
||||
const SDL_DialogFileFilter* filters, int nfilters, const char* default_location,
|
||||
bool allow_many) {
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -78,14 +258,57 @@ void ShowFileSelect(FileCallback callback, void* userdata, SDL_Window* window,
|
||||
state->userdata = userdata;
|
||||
|
||||
Dusk_iOS_ShowFileSelect(&onIOSDialogFinished, state.release(), window, filters, nfilters,
|
||||
default_location, allow_many);
|
||||
default_location, allow_many);
|
||||
#else
|
||||
auto state = std::make_unique<SDLDialogCallbackState>();
|
||||
state->callback = callback;
|
||||
state->userdata = userdata;
|
||||
|
||||
SDL_ShowOpenFileDialog(&onSDLDialogFinished, state.release(), window, filters, nfilters,
|
||||
default_location, allow_many);
|
||||
default_location, allow_many);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShowFolderSelect(
|
||||
FileCallback callback, void* userdata, SDL_Window* window, const char* default_location) {
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if USE_IOS_DIALOG
|
||||
callback(userdata, nullptr, "Folder selection is not supported on this platform");
|
||||
#elif USE_MACOS_FOLDER_DIALOG
|
||||
ShowMacOSFolderSelect(callback, userdata, window, default_location);
|
||||
#elif defined(__ANDROID__) || defined(ANDROID)
|
||||
auto state = std::make_unique<AndroidFolderDialogState>();
|
||||
state->callback = callback;
|
||||
state->userdata = userdata;
|
||||
|
||||
if (show_android_folder_select(state.get())) {
|
||||
state.release();
|
||||
return;
|
||||
}
|
||||
|
||||
callback(userdata, nullptr, "Folder selection is not supported on this platform");
|
||||
#else
|
||||
auto state = std::make_unique<SDLDialogCallbackState>();
|
||||
state->callback = callback;
|
||||
state->userdata = userdata;
|
||||
|
||||
SDL_ShowOpenFolderDialog(
|
||||
&onSDLDialogFinished, state.release(), window, default_location, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string display_name_for_path(std::string_view path) {
|
||||
#if defined(__ANDROID__) || defined(ANDROID)
|
||||
if (path.starts_with("content:") || path.starts_with("file:")) {
|
||||
std::string displayName = android_display_name(path);
|
||||
if (!displayName.empty()) {
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return fallback_display_name(path);
|
||||
}
|
||||
} // namespace dusk
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <SDL3/SDL_dialog.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
namespace dusk {
|
||||
@@ -9,7 +12,11 @@ namespace dusk {
|
||||
using FileCallback = void (*)(void* userdata, const char* path, const char* error);
|
||||
|
||||
void ShowFileSelect(FileCallback callback, void* userdata, SDL_Window* window,
|
||||
const SDL_DialogFileFilter* filters, int nfilters, const char* default_location,
|
||||
bool allow_many);
|
||||
const SDL_DialogFileFilter* filters, int nfilters, const char* default_location,
|
||||
bool allow_many);
|
||||
void ShowFolderSelect(
|
||||
FileCallback callback, void* userdata, SDL_Window* window, const char* default_location);
|
||||
|
||||
std::string display_name_for_path(std::string_view path);
|
||||
|
||||
} // namespace dusk
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "file_select.hpp"
|
||||
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
namespace dusk {
|
||||
namespace {
|
||||
|
||||
struct MacOSFolderDialogState {
|
||||
FileCallback callback;
|
||||
void* userdata;
|
||||
};
|
||||
|
||||
void finish_folder_dialog(MacOSFolderDialogState* state, NSURL* url, const char* error) {
|
||||
if (state == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (error != nullptr) {
|
||||
state->callback(state->userdata, nullptr, error);
|
||||
delete state;
|
||||
return;
|
||||
}
|
||||
|
||||
if (url == nil) {
|
||||
state->callback(state->userdata, nullptr, nullptr);
|
||||
delete state;
|
||||
return;
|
||||
}
|
||||
|
||||
state->callback(state->userdata, [[url path] UTF8String], nullptr);
|
||||
delete state;
|
||||
}
|
||||
|
||||
void configure_default_location(NSOpenPanel* panel, const char* defaultLocation) {
|
||||
if (panel == nil || defaultLocation == nullptr || defaultLocation[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString* path = [NSString stringWithUTF8String:defaultLocation];
|
||||
if (path == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL isDirectory = NO;
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSURL* url = [NSURL fileURLWithPath:path];
|
||||
if ([fileManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory) {
|
||||
[panel setDirectoryURL:url];
|
||||
} else {
|
||||
[panel setDirectoryURL:[url URLByDeletingLastPathComponent]];
|
||||
}
|
||||
}
|
||||
|
||||
NSWindow* window_for_sdl_window(SDL_Window* window) {
|
||||
if (window == nullptr) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
auto props = SDL_GetWindowProperties(window);
|
||||
return (__bridge NSWindow*)SDL_GetPointerProperty(
|
||||
props, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, nullptr);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ShowMacOSFolderSelect(
|
||||
FileCallback callback, void* userdata, SDL_Window* window, const char* defaultLocation) {
|
||||
if (callback == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* state = new MacOSFolderDialogState{
|
||||
.callback = callback,
|
||||
.userdata = userdata,
|
||||
};
|
||||
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
[panel setCanChooseFiles:NO];
|
||||
[panel setCanChooseDirectories:YES];
|
||||
[panel setAllowsMultipleSelection:NO];
|
||||
[panel setCanCreateDirectories:YES];
|
||||
configure_default_location(panel, defaultLocation);
|
||||
|
||||
NSWindow* modalWindow = window_for_sdl_window(window);
|
||||
if (modalWindow != nil) {
|
||||
[panel beginSheetModalForWindow:modalWindow
|
||||
completionHandler:^(NSModalResponse result) {
|
||||
finish_folder_dialog(
|
||||
state, result == NSModalResponseOK ? [panel URL] : nil, nullptr);
|
||||
}];
|
||||
return true;
|
||||
}
|
||||
|
||||
const NSModalResponse result = [panel runModal];
|
||||
finish_folder_dialog(state, result == NSModalResponseOK ? [panel URL] : nil, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dusk
|
||||
@@ -21,6 +21,7 @@ bool g_sync_presentation = false;
|
||||
float g_step = 0.0f;
|
||||
bool g_is_sim_frame = false;
|
||||
bool g_ui_tick_pending = false;
|
||||
uint64_t g_sim_tick_seq = 0;
|
||||
|
||||
Recording g_current_recording;
|
||||
Recording g_previous_recording;
|
||||
@@ -66,19 +67,18 @@ void copy_view_to_snap(CameraSnapshot* dst, const view_class& v) {
|
||||
}
|
||||
|
||||
inline void lerp_matrix(Mtx out, const Mtx lhs, const Mtx rhs, float step) {
|
||||
const float old_weight = 1.0f - step;
|
||||
for (size_t row = 0; row < 3; ++row) {
|
||||
for (size_t col = 0; col < 4; ++col) {
|
||||
out[row][col] = lhs[row][col] * old_weight + rhs[row][col] * step;
|
||||
const float l = lhs[row][col];
|
||||
out[row][col] = l + (rhs[row][col] - l) * step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void lerp_xyz(cXyz* out, const cXyz& lhs, const cXyz& rhs, float step) {
|
||||
const float old_weight = 1.0f - step;
|
||||
out->x = lhs.x * old_weight + rhs.x * step;
|
||||
out->y = lhs.y * old_weight + rhs.y * step;
|
||||
out->z = lhs.z * old_weight + rhs.z * step;
|
||||
out->x = lhs.x + (rhs.x - lhs.x) * step;
|
||||
out->y = lhs.y + (rhs.y - lhs.y) * step;
|
||||
out->z = lhs.z + (rhs.z - lhs.z) * step;
|
||||
}
|
||||
|
||||
static s16 lerp_bank(s16 a, s16 b, f32 t) {
|
||||
@@ -135,6 +135,11 @@ void begin_sim_tick() {
|
||||
|
||||
s_interpolationCallBackWork.clear();
|
||||
s_cam_prev = std::move(s_cam_curr);
|
||||
++g_sim_tick_seq;
|
||||
}
|
||||
|
||||
uint64_t sim_tick_seq() {
|
||||
return g_sim_tick_seq;
|
||||
}
|
||||
|
||||
void begin_frame(bool enabled, bool is_sim_frame, float step) {
|
||||
|
||||
+81
-20
@@ -1,5 +1,9 @@
|
||||
#include "dusk/gyro.h"
|
||||
#include "dusk/ui/ui.hpp"
|
||||
#include "d/actor/d_a_alink.h"
|
||||
|
||||
#include <aurora/lib/window.hpp>
|
||||
#include <SDL3/SDL_mouse.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace dusk::gyro {
|
||||
@@ -12,11 +16,14 @@ constexpr float kGravityEmaAlpha = 0.1f;
|
||||
constexpr float kMinGravityProjection = 0.2f;
|
||||
// Let roll contribute more strongly as the pad approaches an upright posture.
|
||||
constexpr float kRollAimBoostMax = 2.0f;
|
||||
constexpr float kMousePixelToRad = 0.0025f;
|
||||
|
||||
bool s_sensor_enabled = false;
|
||||
bool s_accel_enabled = false;
|
||||
bool s_was_aiming = false;
|
||||
bool s_have_gravity_baseline = false;
|
||||
bool s_mouse_enabled = false;
|
||||
bool s_mouse_relative = false;
|
||||
float s_smooth_gx = 0.0f;
|
||||
float s_smooth_gy = 0.0f;
|
||||
float s_smooth_gz = 0.0f;
|
||||
@@ -36,6 +43,7 @@ void reset_filter_state() {
|
||||
s_baseline_gravity_y = s_baseline_gravity_z = 0.0f;
|
||||
s_was_aiming = false;
|
||||
s_have_gravity_baseline = false;
|
||||
s_mouse_enabled = false;
|
||||
s_yaw_rad = s_pitch_rad = s_roll_rad = 0.0f;
|
||||
s_rollgoal_ax = s_rollgoal_az = 0;
|
||||
}
|
||||
@@ -46,14 +54,29 @@ float apply_deadband(float v, float deadband_rad_s) {
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void disable_pad_sensors() {
|
||||
if (s_sensor_enabled) {
|
||||
PADSetSensorEnabled(PAD_CHAN0, PAD_SENSOR_GYRO, FALSE);
|
||||
s_sensor_enabled = false;
|
||||
}
|
||||
if (s_accel_enabled) {
|
||||
PADSetSensorEnabled(PAD_CHAN0, PAD_SENSOR_ACCEL, FALSE);
|
||||
s_accel_enabled = false;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool s_sensor_keep_alive = false;
|
||||
bool get_sensor_keep_alive() { return s_sensor_keep_alive; }
|
||||
void set_sensor_keep_alive(bool value) { s_sensor_keep_alive = value; }
|
||||
|
||||
bool rollgoal_gyro_enabled() {
|
||||
return getSettings().game.enableGyroRollgoal && getSettings().game.gyroMode.getValue() != GyroMode::Mouse;
|
||||
}
|
||||
|
||||
bool queryGyroAimContext() {
|
||||
if (!static_cast<bool>(dusk::getSettings().game.enableGyroAim)) {
|
||||
if (!static_cast<bool>(getSettings().game.enableGyroAim)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -71,15 +94,28 @@ void read(float dt) {
|
||||
const bool aim_just_ended = !aim_active && s_was_aiming;
|
||||
s_was_aiming = aim_active;
|
||||
|
||||
const bool mouse_mode = getSettings().game.gyroMode.getValue() == GyroMode::Mouse;
|
||||
const bool mouse_gyro_active = !ui::any_document_visible() && mouse_mode && (aim_active || s_sensor_keep_alive);
|
||||
SDL_Window* window = aurora::window::get_sdl_window();
|
||||
if (window != nullptr && mouse_gyro_active != s_mouse_relative &&
|
||||
SDL_SetWindowRelativeMouseMode(window, mouse_gyro_active))
|
||||
{
|
||||
s_mouse_relative = mouse_gyro_active;
|
||||
}
|
||||
|
||||
if (mouse_gyro_active && !s_mouse_enabled && window != nullptr) {
|
||||
const AuroraWindowSize sz = aurora::window::get_window_size();
|
||||
const float cx = static_cast<float>(sz.width) * 0.5f;
|
||||
const float cy = static_cast<float>(sz.height) * 0.5f;
|
||||
SDL_WarpMouseInWindow(window, cx, cy);
|
||||
float discard_x = 0.0f;
|
||||
float discard_y = 0.0f;
|
||||
SDL_GetRelativeMouseState(&discard_x, &discard_y);
|
||||
}
|
||||
s_mouse_enabled = mouse_gyro_active;
|
||||
|
||||
if (!s_sensor_keep_alive && !aim_active) {
|
||||
if (s_sensor_enabled) {
|
||||
PADSetSensorEnabled(PAD_CHAN0, PAD_SENSOR_GYRO, FALSE);
|
||||
s_sensor_enabled = false;
|
||||
}
|
||||
if (s_accel_enabled) {
|
||||
PADSetSensorEnabled(PAD_CHAN0, PAD_SENSOR_ACCEL, FALSE);
|
||||
s_accel_enabled = false;
|
||||
}
|
||||
disable_pad_sensors();
|
||||
reset_filter_state();
|
||||
return;
|
||||
}
|
||||
@@ -90,6 +126,31 @@ void read(float dt) {
|
||||
s_have_gravity_baseline = false;
|
||||
}
|
||||
|
||||
if (mouse_mode && !mouse_gyro_active) {
|
||||
s_pitch_rad = 0.0f;
|
||||
s_yaw_rad = 0.0f;
|
||||
s_roll_rad = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouse_mode) {
|
||||
disable_pad_sensors();
|
||||
|
||||
float mx_rel = 0.0f;
|
||||
float my_rel = 0.0f;
|
||||
SDL_GetRelativeMouseState(&mx_rel, &my_rel);
|
||||
// Convert pixels to radians
|
||||
s_pitch_rad = my_rel * kMousePixelToRad * getSettings().game.gyroSensitivityY;
|
||||
s_yaw_rad = -mx_rel * kMousePixelToRad * getSettings().game.gyroSensitivityX;
|
||||
s_roll_rad = 0.0f;
|
||||
|
||||
s_pitch_rad = getSettings().game.gyroInvertPitch ? -s_pitch_rad : s_pitch_rad;
|
||||
s_yaw_rad = getSettings().game.gyroInvertYaw ? -s_yaw_rad : s_yaw_rad;
|
||||
s_yaw_rad = getSettings().game.enableMirrorMode ? -s_yaw_rad : s_yaw_rad;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s_sensor_enabled) {
|
||||
if (!PADHasSensor(PAD_CHAN0, PAD_SENSOR_GYRO)) {
|
||||
return;
|
||||
@@ -112,8 +173,8 @@ void read(float dt) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float smooth_alpha = kGyroEmaAlphaMax + dusk::getSettings().game.gyroSmoothing * (kGyroEmaAlphaMin - kGyroEmaAlphaMax);
|
||||
const float deadband = dusk::getSettings().game.gyroDeadband;
|
||||
const float smooth_alpha = kGyroEmaAlphaMax + getSettings().game.gyroSmoothing * (kGyroEmaAlphaMin - kGyroEmaAlphaMax);
|
||||
const float deadband = getSettings().game.gyroDeadband;
|
||||
|
||||
s_smooth_gx += smooth_alpha * (gyro[0] - s_smooth_gx);
|
||||
s_smooth_gy += smooth_alpha * (gyro[1] - s_smooth_gy);
|
||||
@@ -123,8 +184,8 @@ void read(float dt) {
|
||||
const float yaw_rate = apply_deadband(s_smooth_gy, deadband);
|
||||
const float roll_rate = apply_deadband(s_smooth_gz, deadband);
|
||||
|
||||
s_pitch_rad = -pitch_rate * dt * dusk::getSettings().game.gyroSensitivityX;
|
||||
s_roll_rad = roll_rate * dt * dusk::getSettings().game.gyroSensitivityX; // GYRO NOTE: Exposing Z sensitivity seems unusual, so I'm just using X
|
||||
s_pitch_rad = -pitch_rate * dt * getSettings().game.gyroSensitivityY;
|
||||
s_roll_rad = roll_rate * dt * getSettings().game.gyroSensitivityX; // GYRO NOTE: Exposing Z sensitivity seems unusual, so I'm just using X
|
||||
|
||||
float horizontal_rate = yaw_rate;
|
||||
if (aim_active && s_accel_enabled) {
|
||||
@@ -162,11 +223,11 @@ void read(float dt) {
|
||||
}
|
||||
}
|
||||
|
||||
s_yaw_rad = horizontal_rate * dt * dusk::getSettings().game.gyroSensitivityY;
|
||||
s_yaw_rad = horizontal_rate * dt * getSettings().game.gyroSensitivityX;
|
||||
|
||||
s_pitch_rad = dusk::getSettings().game.gyroInvertPitch ? -s_pitch_rad : s_pitch_rad;
|
||||
s_yaw_rad = dusk::getSettings().game.gyroInvertYaw ? -s_yaw_rad : s_yaw_rad;
|
||||
s_yaw_rad = dusk::getSettings().game.enableMirrorMode ? -s_yaw_rad : s_yaw_rad;
|
||||
s_pitch_rad = getSettings().game.gyroInvertPitch ? -s_pitch_rad : s_pitch_rad;
|
||||
s_yaw_rad = getSettings().game.gyroInvertYaw ? -s_yaw_rad : s_yaw_rad;
|
||||
s_yaw_rad = getSettings().game.enableMirrorMode ? -s_yaw_rad : s_yaw_rad;
|
||||
}
|
||||
|
||||
void getAimDeltas(float& out_yaw, float& out_pitch) {
|
||||
@@ -180,9 +241,9 @@ void rollgoalTick(bool play_active, s16 camera_yaw) {
|
||||
return;
|
||||
}
|
||||
|
||||
float pitch_rad = -s_pitch_rad * dusk::getSettings().game.gyroSensitivityRollgoal;
|
||||
float roll_rad = s_roll_rad * dusk::getSettings().game.gyroSensitivityRollgoal;
|
||||
roll_rad = dusk::getSettings().game.enableMirrorMode ? -roll_rad : roll_rad;
|
||||
float pitch_rad = -s_pitch_rad * getSettings().game.gyroSensitivityRollgoal;
|
||||
float roll_rad = s_roll_rad * getSettings().game.gyroSensitivityRollgoal;
|
||||
roll_rad = getSettings().game.enableMirrorMode ? -roll_rad : roll_rad;
|
||||
|
||||
s_rollgoal_az += cM_rad2s(roll_rad);
|
||||
cXyz in(roll_rad, 0.0f, pitch_rad);
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
#include "http.hpp"
|
||||
|
||||
#include <SDL3/SDL_system.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace dusk::http {
|
||||
namespace {
|
||||
|
||||
constexpr int JavaErrorNone = 0;
|
||||
constexpr int JavaErrorInvalidUrl = 1;
|
||||
constexpr int JavaErrorUnsupportedScheme = 2;
|
||||
constexpr int JavaErrorTimeout = 3;
|
||||
constexpr int JavaErrorTooLarge = 4;
|
||||
|
||||
int timeout_ms(std::chrono::milliseconds timeout) {
|
||||
const auto count = std::max<std::chrono::milliseconds::rep>(1, timeout.count());
|
||||
return static_cast<int>(
|
||||
std::min<std::chrono::milliseconds::rep>(count, std::numeric_limits<int>::max()));
|
||||
}
|
||||
|
||||
jlong max_body_bytes(size_t maxBodyBytes) {
|
||||
return static_cast<jlong>(std::min<size_t>(
|
||||
maxBodyBytes, static_cast<size_t>(std::numeric_limits<jlong>::max())));
|
||||
}
|
||||
|
||||
bool clear_pending_exception(JNIEnv* env) {
|
||||
if (env == nullptr || !env->ExceptionCheck()) {
|
||||
return false;
|
||||
}
|
||||
env->ExceptionClear();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string to_string(JNIEnv* env, jstring value) {
|
||||
if (env == nullptr || value == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const char* utf8 = env->GetStringUTFChars(value, nullptr);
|
||||
if (utf8 == nullptr) {
|
||||
clear_pending_exception(env);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result(utf8);
|
||||
env->ReleaseStringUTFChars(value, utf8);
|
||||
return result;
|
||||
}
|
||||
|
||||
jstring to_jstring(JNIEnv* env, std::string_view value) {
|
||||
if (env == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return env->NewStringUTF(std::string(value).c_str());
|
||||
}
|
||||
|
||||
Error map_java_error(int error) {
|
||||
switch (error) {
|
||||
case JavaErrorNone:
|
||||
return Error::None;
|
||||
case JavaErrorInvalidUrl:
|
||||
return Error::InvalidUrl;
|
||||
case JavaErrorUnsupportedScheme:
|
||||
return Error::UnsupportedScheme;
|
||||
case JavaErrorTimeout:
|
||||
return Error::Timeout;
|
||||
case JavaErrorTooLarge:
|
||||
return Error::TooLarge;
|
||||
default:
|
||||
return Error::Network;
|
||||
}
|
||||
}
|
||||
|
||||
jclass load_dusk_class(JNIEnv* env, jobject activity, const char* className) {
|
||||
jclass activityClass = env->GetObjectClass(activity);
|
||||
if (activityClass == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jmethodID getClassLoader =
|
||||
env->GetMethodID(activityClass, "getClassLoader", "()Ljava/lang/ClassLoader;");
|
||||
env->DeleteLocalRef(activityClass);
|
||||
if (getClassLoader == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jobject classLoader = env->CallObjectMethod(activity, getClassLoader);
|
||||
if (classLoader == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass classLoaderClass = env->FindClass("java/lang/ClassLoader");
|
||||
if (classLoaderClass == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(classLoader);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jmethodID loadClass = env->GetMethodID(
|
||||
classLoaderClass, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
env->DeleteLocalRef(classLoaderClass);
|
||||
if (loadClass == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(classLoader);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jstring javaClassName = env->NewStringUTF(className);
|
||||
if (javaClassName == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(classLoader);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* loadedClass =
|
||||
static_cast<jclass>(env->CallObjectMethod(classLoader, loadClass, javaClassName));
|
||||
env->DeleteLocalRef(javaClassName);
|
||||
env->DeleteLocalRef(classLoader);
|
||||
if (loadedClass == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return loadedClass;
|
||||
}
|
||||
|
||||
jobjectArray make_string_array(JNIEnv* env, const std::vector<Header>& headers, bool names) {
|
||||
jclass stringClass = env->FindClass("java/lang/String");
|
||||
if (stringClass == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jobjectArray array =
|
||||
env->NewObjectArray(static_cast<jsize>(headers.size()), stringClass, nullptr);
|
||||
env->DeleteLocalRef(stringClass);
|
||||
if (array == nullptr || clear_pending_exception(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (jsize i = 0; i < static_cast<jsize>(headers.size()); ++i) {
|
||||
const std::string& value = names ? headers[static_cast<size_t>(i)].name :
|
||||
headers[static_cast<size_t>(i)].value;
|
||||
jstring javaValue = to_jstring(env, value);
|
||||
if (javaValue == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(array);
|
||||
return nullptr;
|
||||
}
|
||||
env->SetObjectArrayElement(array, i, javaValue);
|
||||
env->DeleteLocalRef(javaValue);
|
||||
if (clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(array);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
std::vector<Header> read_headers(JNIEnv* env, jobjectArray names, jobjectArray values) {
|
||||
std::vector<Header> headers;
|
||||
if (names == nullptr || values == nullptr) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
const jsize count = std::min(env->GetArrayLength(names), env->GetArrayLength(values));
|
||||
headers.reserve(static_cast<size_t>(count));
|
||||
for (jsize i = 0; i < count; ++i) {
|
||||
auto* name = static_cast<jstring>(env->GetObjectArrayElement(names, i));
|
||||
auto* value = static_cast<jstring>(env->GetObjectArrayElement(values, i));
|
||||
if (clear_pending_exception(env)) {
|
||||
if (name != nullptr) {
|
||||
env->DeleteLocalRef(name);
|
||||
}
|
||||
if (value != nullptr) {
|
||||
env->DeleteLocalRef(value);
|
||||
}
|
||||
headers.clear();
|
||||
return headers;
|
||||
}
|
||||
|
||||
if (name != nullptr) {
|
||||
headers.push_back({
|
||||
.name = to_string(env, name),
|
||||
.value = to_string(env, value),
|
||||
});
|
||||
}
|
||||
|
||||
if (name != nullptr) {
|
||||
env->DeleteLocalRef(name);
|
||||
}
|
||||
if (value != nullptr) {
|
||||
env->DeleteLocalRef(value);
|
||||
}
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
std::string read_body(JNIEnv* env, jbyteArray body) {
|
||||
if (body == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const jsize bodySize = env->GetArrayLength(body);
|
||||
std::string result(static_cast<size_t>(bodySize), '\0');
|
||||
if (bodySize > 0) {
|
||||
env->GetByteArrayRegion(body, 0, bodySize, reinterpret_cast<jbyte*>(result.data()));
|
||||
if (clear_pending_exception(env)) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Result result_from_response(JNIEnv* env, jobject response) {
|
||||
if (response == nullptr) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Android HTTP request did not return a response",
|
||||
};
|
||||
}
|
||||
|
||||
jclass responseClass = env->GetObjectClass(response);
|
||||
if (responseClass == nullptr || clear_pending_exception(env)) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to inspect Android HTTP response",
|
||||
};
|
||||
}
|
||||
|
||||
jfieldID errorField = env->GetFieldID(responseClass, "error", "I");
|
||||
jfieldID messageField = env->GetFieldID(responseClass, "message", "Ljava/lang/String;");
|
||||
jfieldID statusField = env->GetFieldID(responseClass, "statusCode", "I");
|
||||
jfieldID headerNamesField =
|
||||
env->GetFieldID(responseClass, "headerNames", "[Ljava/lang/String;");
|
||||
jfieldID headerValuesField =
|
||||
env->GetFieldID(responseClass, "headerValues", "[Ljava/lang/String;");
|
||||
jfieldID bodyField = env->GetFieldID(responseClass, "body", "[B");
|
||||
env->DeleteLocalRef(responseClass);
|
||||
if (errorField == nullptr || messageField == nullptr || statusField == nullptr ||
|
||||
headerNamesField == nullptr || headerValuesField == nullptr || bodyField == nullptr ||
|
||||
clear_pending_exception(env))
|
||||
{
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Android HTTP response shape was not recognized",
|
||||
};
|
||||
}
|
||||
|
||||
const int javaError = env->GetIntField(response, errorField);
|
||||
auto* message = static_cast<jstring>(env->GetObjectField(response, messageField));
|
||||
auto* headerNames = static_cast<jobjectArray>(env->GetObjectField(response, headerNamesField));
|
||||
auto* headerValues =
|
||||
static_cast<jobjectArray>(env->GetObjectField(response, headerValuesField));
|
||||
auto* body = static_cast<jbyteArray>(env->GetObjectField(response, bodyField));
|
||||
if (clear_pending_exception(env)) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to read Android HTTP response",
|
||||
};
|
||||
}
|
||||
|
||||
Response httpResponse{
|
||||
.statusCode = static_cast<int>(env->GetIntField(response, statusField)),
|
||||
.headers = read_headers(env, headerNames, headerValues),
|
||||
.body = read_body(env, body),
|
||||
};
|
||||
|
||||
std::string messageString = to_string(env, message);
|
||||
|
||||
if (message != nullptr) {
|
||||
env->DeleteLocalRef(message);
|
||||
}
|
||||
if (headerNames != nullptr) {
|
||||
env->DeleteLocalRef(headerNames);
|
||||
}
|
||||
if (headerValues != nullptr) {
|
||||
env->DeleteLocalRef(headerValues);
|
||||
}
|
||||
if (body != nullptr) {
|
||||
env->DeleteLocalRef(body);
|
||||
}
|
||||
|
||||
return {
|
||||
.error = map_java_error(javaError),
|
||||
.message = std::move(messageString),
|
||||
.response = std::move(httpResponse),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool available() noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
Backend backend() noexcept {
|
||||
return Backend::Android;
|
||||
}
|
||||
|
||||
const char* backend_name() noexcept {
|
||||
return "Android";
|
||||
}
|
||||
|
||||
Result get(const Request& request) {
|
||||
if (request.url.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is empty",
|
||||
};
|
||||
}
|
||||
if (!request.url.starts_with("https://")) {
|
||||
return {
|
||||
.error = Error::UnsupportedScheme,
|
||||
.message = "Only https:// URLs are supported",
|
||||
};
|
||||
}
|
||||
|
||||
auto* env = static_cast<JNIEnv*>(SDL_GetAndroidJNIEnv());
|
||||
if (env == nullptr) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to access Android JNI environment",
|
||||
};
|
||||
}
|
||||
|
||||
jobject activity = static_cast<jobject>(SDL_GetAndroidActivity());
|
||||
if (activity == nullptr || clear_pending_exception(env)) {
|
||||
if (activity != nullptr) {
|
||||
env->DeleteLocalRef(activity);
|
||||
}
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to access Android activity",
|
||||
};
|
||||
}
|
||||
|
||||
jclass clientClass =
|
||||
load_dusk_class(env, activity, "dev.twilitrealm.dusk.DuskHttpClient");
|
||||
env->DeleteLocalRef(activity);
|
||||
if (clientClass == nullptr) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to load Android HTTP helper",
|
||||
};
|
||||
}
|
||||
|
||||
jmethodID getMethod = env->GetStaticMethodID(clientClass, "get",
|
||||
"(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;IJ)"
|
||||
"Ldev/twilitrealm/dusk/DuskHttpClient$Response;");
|
||||
if (getMethod == nullptr || clear_pending_exception(env)) {
|
||||
env->DeleteLocalRef(clientClass);
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to find Android HTTP helper method",
|
||||
};
|
||||
}
|
||||
|
||||
jstring url = to_jstring(env, request.url);
|
||||
jobjectArray headerNames = make_string_array(env, request.headers, true);
|
||||
jobjectArray headerValues = make_string_array(env, request.headers, false);
|
||||
if (url == nullptr || headerNames == nullptr || headerValues == nullptr ||
|
||||
clear_pending_exception(env))
|
||||
{
|
||||
if (url != nullptr) {
|
||||
env->DeleteLocalRef(url);
|
||||
}
|
||||
if (headerNames != nullptr) {
|
||||
env->DeleteLocalRef(headerNames);
|
||||
}
|
||||
if (headerValues != nullptr) {
|
||||
env->DeleteLocalRef(headerValues);
|
||||
}
|
||||
env->DeleteLocalRef(clientClass);
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to prepare Android HTTP request",
|
||||
};
|
||||
}
|
||||
|
||||
jobject response = env->CallStaticObjectMethod(clientClass, getMethod, url, headerNames,
|
||||
headerValues, timeout_ms(request.timeout), max_body_bytes(request.maxBodyBytes));
|
||||
env->DeleteLocalRef(url);
|
||||
env->DeleteLocalRef(headerNames);
|
||||
env->DeleteLocalRef(headerValues);
|
||||
env->DeleteLocalRef(clientClass);
|
||||
if (clear_pending_exception(env)) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Android HTTP request failed with a Java exception",
|
||||
};
|
||||
}
|
||||
|
||||
Result result = result_from_response(env, response);
|
||||
if (response != nullptr) {
|
||||
env->DeleteLocalRef(response);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace dusk::http
|
||||
@@ -0,0 +1,206 @@
|
||||
#include "http.hpp"
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace dusk::http {
|
||||
namespace {
|
||||
|
||||
struct CurlHeaders {
|
||||
curl_slist* list = nullptr;
|
||||
|
||||
~CurlHeaders() {
|
||||
if (list != nullptr) {
|
||||
curl_slist_free_all(list);
|
||||
}
|
||||
}
|
||||
|
||||
bool append(const std::string& header) {
|
||||
curl_slist* next = curl_slist_append(list, header.c_str());
|
||||
if (next == nullptr) {
|
||||
return false;
|
||||
}
|
||||
list = next;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct CurlContext {
|
||||
Response response;
|
||||
size_t maxBodyBytes = 0;
|
||||
bool tooLarge = false;
|
||||
};
|
||||
|
||||
void initialize_curl() {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
}
|
||||
|
||||
std::string trim_header_value(std::string_view value) {
|
||||
while (!value.empty() && (value.front() == ' ' || value.front() == '\t')) {
|
||||
value.remove_prefix(1);
|
||||
}
|
||||
while (!value.empty() &&
|
||||
(value.back() == '\r' || value.back() == '\n' || value.back() == ' ' ||
|
||||
value.back() == '\t')) {
|
||||
value.remove_suffix(1);
|
||||
}
|
||||
return std::string(value);
|
||||
}
|
||||
|
||||
size_t write_body(char* ptr, size_t size, size_t nmemb, void* userdata) {
|
||||
auto* context = static_cast<CurlContext*>(userdata);
|
||||
const size_t bytes = size * nmemb;
|
||||
if (bytes > context->maxBodyBytes ||
|
||||
context->response.body.size() > context->maxBodyBytes - bytes) {
|
||||
context->tooLarge = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
context->response.body.append(ptr, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t write_header(char* ptr, size_t size, size_t nmemb, void* userdata) {
|
||||
auto* context = static_cast<CurlContext*>(userdata);
|
||||
const std::string_view line(ptr, size * nmemb);
|
||||
if (line.starts_with("HTTP/")) {
|
||||
context->response.headers.clear();
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
const size_t colon = line.find(':');
|
||||
if (colon == std::string_view::npos) {
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
context->response.headers.push_back({
|
||||
.name = std::string(line.substr(0, colon)),
|
||||
.value = trim_header_value(line.substr(colon + 1)),
|
||||
});
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
Error map_curl_error(CURLcode code, bool tooLarge) {
|
||||
if (tooLarge) {
|
||||
return Error::TooLarge;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case CURLE_OK:
|
||||
return Error::None;
|
||||
case CURLE_URL_MALFORMAT:
|
||||
return Error::InvalidUrl;
|
||||
case CURLE_UNSUPPORTED_PROTOCOL:
|
||||
return Error::UnsupportedScheme;
|
||||
case CURLE_OPERATION_TIMEDOUT:
|
||||
return Error::Timeout;
|
||||
default:
|
||||
return Error::Network;
|
||||
}
|
||||
}
|
||||
|
||||
long timeout_ms(std::chrono::milliseconds timeout) {
|
||||
return std::max<std::chrono::milliseconds::rep>(1, timeout.count());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool available() noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
Backend backend() noexcept {
|
||||
return Backend::LibCurl;
|
||||
}
|
||||
|
||||
const char* backend_name() noexcept {
|
||||
return "libcurl";
|
||||
}
|
||||
|
||||
Result get(const Request& request) {
|
||||
if (request.url.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is empty",
|
||||
};
|
||||
}
|
||||
if (!request.url.starts_with("https://")) {
|
||||
return {
|
||||
.error = Error::UnsupportedScheme,
|
||||
.message = "Only https:// URLs are supported",
|
||||
};
|
||||
}
|
||||
|
||||
static std::once_flag initFlag;
|
||||
std::call_once(initFlag, initialize_curl);
|
||||
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl == nullptr) {
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to create libcurl request",
|
||||
};
|
||||
}
|
||||
|
||||
CurlHeaders headers;
|
||||
for (const Header& header : request.headers) {
|
||||
if (!headers.append(header.name + ": " + header.value)) {
|
||||
curl_easy_cleanup(curl);
|
||||
return {
|
||||
.error = Error::Network,
|
||||
.message = "Failed to allocate libcurl headers",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
CurlContext context{
|
||||
.maxBodyBytes = request.maxBodyBytes,
|
||||
};
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, request.url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.list);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout_ms(request.timeout));
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, timeout_ms(request.timeout));
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_body);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &context);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_header);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &context);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||
#if CURL_AT_LEAST_VERSION(7, 85, 0)
|
||||
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "https");
|
||||
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, "https");
|
||||
#else
|
||||
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
|
||||
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
|
||||
#endif
|
||||
|
||||
const CURLcode code = curl_easy_perform(curl);
|
||||
long statusCode = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &statusCode);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
context.response.statusCode = static_cast<int>(statusCode);
|
||||
if (code == CURLE_OK) {
|
||||
return {
|
||||
.response = std::move(context.response),
|
||||
};
|
||||
}
|
||||
|
||||
const Error error = map_curl_error(code, context.tooLarge);
|
||||
return {
|
||||
.error = error,
|
||||
.message = error == Error::TooLarge ? "Response body exceeded the configured limit"
|
||||
: curl_easy_strerror(code),
|
||||
.response = std::move(context.response),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace dusk::http
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef DUSK_HTTP_HTTP_HPP
|
||||
#define DUSK_HTTP_HTTP_HPP
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dusk::http {
|
||||
|
||||
enum class Backend {
|
||||
None,
|
||||
WinHttp,
|
||||
UrlSession,
|
||||
LibCurl,
|
||||
Android,
|
||||
};
|
||||
|
||||
enum class Error {
|
||||
None,
|
||||
NoBackend,
|
||||
InvalidUrl,
|
||||
UnsupportedScheme,
|
||||
Timeout,
|
||||
TooLarge,
|
||||
Network,
|
||||
};
|
||||
|
||||
struct Header {
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct Request {
|
||||
std::string url;
|
||||
std::vector<Header> headers;
|
||||
std::chrono::milliseconds timeout{10000};
|
||||
size_t maxBodyBytes = 1024 * 1024;
|
||||
};
|
||||
|
||||
struct Response {
|
||||
int statusCode = 0;
|
||||
std::vector<Header> headers;
|
||||
std::string body;
|
||||
};
|
||||
|
||||
struct Result {
|
||||
Error error = Error::None;
|
||||
std::string message;
|
||||
Response response;
|
||||
};
|
||||
|
||||
bool available() noexcept;
|
||||
Backend backend() noexcept;
|
||||
const char* backend_name() noexcept;
|
||||
Result get(const Request& request);
|
||||
|
||||
} // namespace dusk::http
|
||||
|
||||
#endif // DUSK_HTTP_HTTP_HPP
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "http.hpp"
|
||||
|
||||
namespace dusk::http {
|
||||
|
||||
bool available() noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
Backend backend() noexcept {
|
||||
return Backend::None;
|
||||
}
|
||||
|
||||
const char* backend_name() noexcept {
|
||||
return "none";
|
||||
}
|
||||
|
||||
Result get(const Request&) {
|
||||
return {
|
||||
.error = Error::NoBackend,
|
||||
.message = "No HTTP backend is available",
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace dusk::http
|
||||
@@ -0,0 +1,238 @@
|
||||
#include "http.hpp"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
@interface DuskHttpRequestDelegate : NSObject <NSURLSessionDataDelegate, NSURLSessionTaskDelegate>
|
||||
@property(nonatomic) dispatch_semaphore_t semaphore;
|
||||
@property(nonatomic) size_t maxBodyBytes;
|
||||
@property(nonatomic, strong) NSMutableData* data;
|
||||
@property(nonatomic, strong) NSURLResponse* response;
|
||||
@property(nonatomic, strong) NSError* error;
|
||||
@property(nonatomic) BOOL tooLarge;
|
||||
- (instancetype)initWithMaxBodyBytes:(size_t)maxBodyBytes;
|
||||
@end
|
||||
|
||||
@implementation DuskHttpRequestDelegate
|
||||
|
||||
- (instancetype)initWithMaxBodyBytes:(size_t)maxBodyBytes {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_semaphore = dispatch_semaphore_create(0);
|
||||
_maxBodyBytes = maxBodyBytes;
|
||||
_data = [NSMutableData data];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession*)session
|
||||
task:(NSURLSessionTask*)task
|
||||
willPerformHTTPRedirection:(NSHTTPURLResponse*)response
|
||||
newRequest:(NSURLRequest*)request
|
||||
completionHandler:(void (^)(NSURLRequest*))completionHandler {
|
||||
if ([[request.URL.scheme lowercaseString] isEqualToString:@"https"]) {
|
||||
completionHandler(request);
|
||||
} else {
|
||||
completionHandler(nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession*)session
|
||||
dataTask:(NSURLSessionDataTask*)dataTask
|
||||
didReceiveResponse:(NSURLResponse*)response
|
||||
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
||||
self.response = response;
|
||||
completionHandler(NSURLSessionResponseAllow);
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession*)session
|
||||
dataTask:(NSURLSessionDataTask*)dataTask
|
||||
didReceiveData:(NSData*)data {
|
||||
if (data.length > self.maxBodyBytes ||
|
||||
self.data.length > self.maxBodyBytes - data.length) {
|
||||
self.tooLarge = YES;
|
||||
[dataTask cancel];
|
||||
return;
|
||||
}
|
||||
[self.data appendData:data];
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession*)session
|
||||
task:(NSURLSessionTask*)task
|
||||
didCompleteWithError:(NSError*)error {
|
||||
if (error != nil && !self.tooLarge) {
|
||||
self.error = error;
|
||||
}
|
||||
dispatch_semaphore_signal(self.semaphore);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace dusk::http {
|
||||
namespace {
|
||||
|
||||
NSString* to_nsstring(std::string_view value) {
|
||||
return [[NSString alloc] initWithBytes:value.data()
|
||||
length:value.size()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
std::string to_string(NSString* value) {
|
||||
if (value == nil) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const char* utf8 = [value UTF8String];
|
||||
return utf8 == nullptr ? std::string() : std::string(utf8);
|
||||
}
|
||||
|
||||
Error map_nsurl_error(NSError* error) {
|
||||
if (error == nil || ![error.domain isEqualToString:NSURLErrorDomain]) {
|
||||
return Error::Network;
|
||||
}
|
||||
|
||||
switch (error.code) {
|
||||
case NSURLErrorTimedOut:
|
||||
return Error::Timeout;
|
||||
case NSURLErrorBadURL:
|
||||
case NSURLErrorUnsupportedURL:
|
||||
return Error::InvalidUrl;
|
||||
default:
|
||||
return Error::Network;
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_time_t timeout_deadline(std::chrono::milliseconds timeout) {
|
||||
const auto milliseconds = std::max<std::chrono::milliseconds::rep>(1, timeout.count());
|
||||
return dispatch_time(DISPATCH_TIME_NOW,
|
||||
static_cast<int64_t>(milliseconds) * static_cast<int64_t>(NSEC_PER_MSEC));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool available() noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
Backend backend() noexcept {
|
||||
return Backend::UrlSession;
|
||||
}
|
||||
|
||||
const char* backend_name() noexcept {
|
||||
return "NSURLSession";
|
||||
}
|
||||
|
||||
Result get(const Request& request) {
|
||||
@autoreleasepool {
|
||||
if (request.url.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is empty",
|
||||
};
|
||||
}
|
||||
if (!request.url.starts_with("https://")) {
|
||||
return {
|
||||
.error = Error::UnsupportedScheme,
|
||||
.message = "Only https:// URLs are supported",
|
||||
};
|
||||
}
|
||||
|
||||
NSString* urlString = to_nsstring(request.url);
|
||||
if (urlString == nil) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is not valid UTF-8",
|
||||
};
|
||||
}
|
||||
|
||||
NSURL* url = [NSURL URLWithString:urlString];
|
||||
if (url == nil || ![[url.scheme lowercaseString] isEqualToString:@"https"]) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "Failed to parse URL",
|
||||
};
|
||||
}
|
||||
|
||||
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
|
||||
urlRequest.HTTPMethod = @"GET";
|
||||
urlRequest.timeoutInterval = request.timeout.count() / 1000.0;
|
||||
urlRequest.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||
for (const Header& header : request.headers) {
|
||||
NSString* name = to_nsstring(header.name);
|
||||
NSString* value = to_nsstring(header.value);
|
||||
if (name == nil || value == nil) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "Request header is not valid UTF-8",
|
||||
};
|
||||
}
|
||||
[urlRequest setValue:value forHTTPHeaderField:name];
|
||||
}
|
||||
|
||||
NSURLSessionConfiguration* configuration =
|
||||
[NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||
configuration.timeoutIntervalForRequest = request.timeout.count() / 1000.0;
|
||||
configuration.timeoutIntervalForResource = request.timeout.count() / 1000.0;
|
||||
|
||||
DuskHttpRequestDelegate* delegate =
|
||||
[[DuskHttpRequestDelegate alloc] initWithMaxBodyBytes:request.maxBodyBytes];
|
||||
NSURLSession* session = [NSURLSession sessionWithConfiguration:configuration
|
||||
delegate:delegate
|
||||
delegateQueue:nil];
|
||||
NSURLSessionDataTask* task = [session dataTaskWithRequest:urlRequest];
|
||||
[task resume];
|
||||
|
||||
if (dispatch_semaphore_wait(delegate.semaphore, timeout_deadline(request.timeout)) != 0) {
|
||||
[task cancel];
|
||||
[session invalidateAndCancel];
|
||||
return {
|
||||
.error = Error::Timeout,
|
||||
.message = "Request timed out",
|
||||
};
|
||||
}
|
||||
|
||||
[session finishTasksAndInvalidate];
|
||||
|
||||
Response response;
|
||||
if ([delegate.response isKindOfClass:[NSHTTPURLResponse class]]) {
|
||||
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)delegate.response;
|
||||
response.statusCode = static_cast<int>(httpResponse.statusCode);
|
||||
NSDictionary* headers = httpResponse.allHeaderFields;
|
||||
for (id key in headers) {
|
||||
id value = headers[key];
|
||||
response.headers.push_back({
|
||||
.name = to_string([key description]),
|
||||
.value = to_string([value description]),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (delegate.data != nil && delegate.data.length > 0) {
|
||||
response.body.assign(static_cast<const char*>(delegate.data.bytes),
|
||||
static_cast<size_t>(delegate.data.length));
|
||||
}
|
||||
|
||||
if (delegate.tooLarge) {
|
||||
return {
|
||||
.error = Error::TooLarge,
|
||||
.message = "Response body exceeded the configured limit",
|
||||
.response = std::move(response),
|
||||
};
|
||||
}
|
||||
if (delegate.error != nil) {
|
||||
return {
|
||||
.error = map_nsurl_error(delegate.error),
|
||||
.message = to_string(delegate.error.localizedDescription),
|
||||
.response = std::move(response),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
.response = std::move(response),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dusk::http
|
||||
@@ -0,0 +1,320 @@
|
||||
#include "http.hpp"
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
#include <winhttp.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace dusk::http {
|
||||
namespace {
|
||||
|
||||
struct WinHttpHandle {
|
||||
HINTERNET handle = nullptr;
|
||||
|
||||
WinHttpHandle() = default;
|
||||
explicit WinHttpHandle(HINTERNET handle) : handle(handle) {}
|
||||
WinHttpHandle(const WinHttpHandle&) = delete;
|
||||
WinHttpHandle& operator=(const WinHttpHandle&) = delete;
|
||||
|
||||
~WinHttpHandle() {
|
||||
if (handle != nullptr) {
|
||||
WinHttpCloseHandle(handle);
|
||||
}
|
||||
}
|
||||
|
||||
operator HINTERNET() const { return handle; }
|
||||
};
|
||||
|
||||
std::wstring utf8_to_wide(std::string_view value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int required = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, value.data(), static_cast<int>(value.size()), nullptr, 0);
|
||||
if (required <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring result(static_cast<size_t>(required), L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, value.data(), static_cast<int>(value.size()),
|
||||
result.data(), required);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string wide_to_utf8(std::wstring_view value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int required = WideCharToMultiByte(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0, nullptr, nullptr);
|
||||
if (required <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result(static_cast<size_t>(required), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), result.data(),
|
||||
required, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
DWORD timeout_ms(std::chrono::milliseconds timeout) {
|
||||
const auto count = std::max<std::chrono::milliseconds::rep>(1, timeout.count());
|
||||
return static_cast<DWORD>(
|
||||
std::min<std::chrono::milliseconds::rep>(count, std::numeric_limits<int>::max()));
|
||||
}
|
||||
|
||||
Error map_winhttp_error(DWORD error) {
|
||||
switch (error) {
|
||||
case ERROR_WINHTTP_TIMEOUT:
|
||||
return Error::Timeout;
|
||||
case ERROR_WINHTTP_INVALID_URL:
|
||||
case ERROR_WINHTTP_UNRECOGNIZED_SCHEME:
|
||||
return Error::InvalidUrl;
|
||||
case ERROR_WINHTTP_SECURE_FAILURE:
|
||||
case ERROR_WINHTTP_CANNOT_CONNECT:
|
||||
case ERROR_WINHTTP_CONNECTION_ERROR:
|
||||
default:
|
||||
return Error::Network;
|
||||
}
|
||||
}
|
||||
|
||||
Result fail_from_last_error(const char* message) {
|
||||
const DWORD error = GetLastError();
|
||||
return {
|
||||
.error = map_winhttp_error(error),
|
||||
.message = std::string(message) + " (" + std::to_string(error) + ")",
|
||||
};
|
||||
}
|
||||
|
||||
std::string trim_header_value(std::string_view value) {
|
||||
while (!value.empty() && (value.front() == ' ' || value.front() == '\t')) {
|
||||
value.remove_prefix(1);
|
||||
}
|
||||
while (!value.empty() && (value.back() == '\r' || value.back() == '\n' || value.back() == ' ' ||
|
||||
value.back() == '\t'))
|
||||
{
|
||||
value.remove_suffix(1);
|
||||
}
|
||||
return std::string(value);
|
||||
}
|
||||
|
||||
void parse_headers(std::wstring_view rawHeaders, Response& response) {
|
||||
size_t start = 0;
|
||||
bool firstLine = true;
|
||||
while (start < rawHeaders.size()) {
|
||||
size_t end = rawHeaders.find(L"\r\n", start);
|
||||
if (end == std::wstring_view::npos) {
|
||||
end = rawHeaders.size();
|
||||
}
|
||||
|
||||
const std::wstring_view line = rawHeaders.substr(start, end - start);
|
||||
if (!line.empty() && !firstLine) {
|
||||
const size_t colon = line.find(L':');
|
||||
if (colon != std::wstring_view::npos) {
|
||||
response.headers.push_back({
|
||||
.name = wide_to_utf8(line.substr(0, colon)),
|
||||
.value = trim_header_value(wide_to_utf8(line.substr(colon + 1))),
|
||||
});
|
||||
}
|
||||
}
|
||||
firstLine = false;
|
||||
|
||||
if (end == rawHeaders.size()) {
|
||||
break;
|
||||
}
|
||||
start = end + 2;
|
||||
}
|
||||
}
|
||||
|
||||
bool read_status(HINTERNET request, Response& response) {
|
||||
DWORD statusCode = 0;
|
||||
DWORD statusCodeSize = sizeof(statusCode);
|
||||
if (!WinHttpQueryHeaders(request, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX, &statusCode, &statusCodeSize, WINHTTP_NO_HEADER_INDEX))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
response.statusCode = static_cast<int>(statusCode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_headers(HINTERNET request, Response& response) {
|
||||
DWORD headerBytes = 0;
|
||||
WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
WINHTTP_NO_OUTPUT_BUFFER, &headerBytes, WINHTTP_NO_HEADER_INDEX);
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring rawHeaders(headerBytes / sizeof(wchar_t), L'\0');
|
||||
if (!WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
rawHeaders.data(), &headerBytes, WINHTTP_NO_HEADER_INDEX))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!rawHeaders.empty() && rawHeaders.back() == L'\0') {
|
||||
rawHeaders.pop_back();
|
||||
}
|
||||
parse_headers(rawHeaders, response);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool available() noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
Backend backend() noexcept {
|
||||
return Backend::WinHttp;
|
||||
}
|
||||
|
||||
const char* backend_name() noexcept {
|
||||
return "WinHTTP";
|
||||
}
|
||||
|
||||
Result get(const Request& request) {
|
||||
if (request.url.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is empty",
|
||||
};
|
||||
}
|
||||
|
||||
std::wstring wideUrl = utf8_to_wide(request.url);
|
||||
if (wideUrl.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "URL is not valid UTF-8",
|
||||
};
|
||||
}
|
||||
|
||||
URL_COMPONENTS components{};
|
||||
components.dwStructSize = sizeof(components);
|
||||
components.dwSchemeLength = static_cast<DWORD>(-1);
|
||||
components.dwHostNameLength = static_cast<DWORD>(-1);
|
||||
components.dwUrlPathLength = static_cast<DWORD>(-1);
|
||||
components.dwExtraInfoLength = static_cast<DWORD>(-1);
|
||||
if (!WinHttpCrackUrl(wideUrl.c_str(), static_cast<DWORD>(wideUrl.size()), 0, &components)) {
|
||||
return fail_from_last_error("Failed to parse URL");
|
||||
}
|
||||
if (components.nScheme != INTERNET_SCHEME_HTTPS) {
|
||||
return {
|
||||
.error = Error::UnsupportedScheme,
|
||||
.message = "Only https:// URLs are supported",
|
||||
};
|
||||
}
|
||||
|
||||
const std::wstring host(components.lpszHostName, components.dwHostNameLength);
|
||||
std::wstring path;
|
||||
if (components.lpszUrlPath != nullptr && components.dwUrlPathLength > 0) {
|
||||
path.assign(components.lpszUrlPath, components.dwUrlPathLength);
|
||||
}
|
||||
if (components.lpszExtraInfo != nullptr && components.dwExtraInfoLength > 0) {
|
||||
path.append(components.lpszExtraInfo, components.dwExtraInfoLength);
|
||||
}
|
||||
if (path.empty()) {
|
||||
path = L"/";
|
||||
}
|
||||
|
||||
WinHttpHandle session(WinHttpOpen(L"Dusk", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
|
||||
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0));
|
||||
if (session.handle == nullptr) {
|
||||
return fail_from_last_error("Failed to create WinHTTP session");
|
||||
}
|
||||
|
||||
const DWORD timeout = timeout_ms(request.timeout);
|
||||
WinHttpSetTimeouts(session, timeout, timeout, timeout, timeout);
|
||||
|
||||
WinHttpHandle connection(WinHttpConnect(session, host.c_str(), components.nPort, 0));
|
||||
if (connection.handle == nullptr) {
|
||||
return fail_from_last_error("Failed to connect");
|
||||
}
|
||||
|
||||
WinHttpHandle httpRequest(WinHttpOpenRequest(connection, L"GET", path.c_str(), nullptr,
|
||||
WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE));
|
||||
if (httpRequest.handle == nullptr) {
|
||||
return fail_from_last_error("Failed to create request");
|
||||
}
|
||||
|
||||
DWORD redirectPolicy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
|
||||
WinHttpSetOption(
|
||||
httpRequest, WINHTTP_OPTION_REDIRECT_POLICY, &redirectPolicy, sizeof(redirectPolicy));
|
||||
DWORD maxRedirects = 5;
|
||||
WinHttpSetOption(httpRequest, WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, &maxRedirects,
|
||||
sizeof(maxRedirects));
|
||||
|
||||
for (const Header& header : request.headers) {
|
||||
const std::wstring wideHeader = utf8_to_wide(header.name + ": " + header.value);
|
||||
if (wideHeader.empty()) {
|
||||
return {
|
||||
.error = Error::InvalidUrl,
|
||||
.message = "Request header is not valid UTF-8",
|
||||
};
|
||||
}
|
||||
if (!WinHttpAddRequestHeaders(httpRequest, wideHeader.c_str(),
|
||||
static_cast<DWORD>(wideHeader.size()), WINHTTP_ADDREQ_FLAG_ADD))
|
||||
{
|
||||
return fail_from_last_error("Failed to add request header");
|
||||
}
|
||||
}
|
||||
|
||||
if (!WinHttpSendRequest(
|
||||
httpRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0))
|
||||
{
|
||||
return fail_from_last_error("Failed to send request");
|
||||
}
|
||||
if (!WinHttpReceiveResponse(httpRequest, nullptr)) {
|
||||
return fail_from_last_error("Failed to receive response");
|
||||
}
|
||||
|
||||
Response response;
|
||||
if (!read_status(httpRequest, response)) {
|
||||
return fail_from_last_error("Failed to read response status");
|
||||
}
|
||||
read_headers(httpRequest, response);
|
||||
|
||||
for (;;) {
|
||||
DWORD availableBytes = 0;
|
||||
if (!WinHttpQueryDataAvailable(httpRequest, &availableBytes)) {
|
||||
return fail_from_last_error("Failed to query response body");
|
||||
}
|
||||
if (availableBytes == 0) {
|
||||
break;
|
||||
}
|
||||
if (availableBytes > request.maxBodyBytes ||
|
||||
response.body.size() > request.maxBodyBytes - availableBytes)
|
||||
{
|
||||
return {
|
||||
.error = Error::TooLarge,
|
||||
.message = "Response body exceeded the configured limit",
|
||||
.response = std::move(response),
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<char> buffer(availableBytes);
|
||||
DWORD bytesRead = 0;
|
||||
if (!WinHttpReadData(httpRequest, buffer.data(), availableBytes, &bytesRead)) {
|
||||
return fail_from_last_error("Failed to read response body");
|
||||
}
|
||||
response.body.append(buffer.data(), bytesRead);
|
||||
}
|
||||
|
||||
return {
|
||||
.response = std::move(response),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace dusk::http
|
||||
@@ -1,228 +0,0 @@
|
||||
#include "ImGuiAchievements.hpp"
|
||||
#include "ImGuiConfig.hpp"
|
||||
#include "dusk/achievements.h"
|
||||
#include "dusk/settings.h"
|
||||
#include "fmt/format.h"
|
||||
#include "imgui.h"
|
||||
|
||||
namespace dusk {
|
||||
|
||||
void ImGuiAchievements::notify(std::string name) {
|
||||
if (m_notifyTimer <= 0.f) {
|
||||
m_notifyName = std::move(name);
|
||||
m_notifyTimer = NOTIFY_DURATION;
|
||||
} else {
|
||||
m_notifyQueue.push(std::move(name));
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiAchievements::showNotification() {
|
||||
if (!getSettings().game.enableAchievementNotifications.getValue()) {
|
||||
return;
|
||||
}
|
||||
if (m_notifyTimer <= 0.f) {
|
||||
if (m_notifyQueue.empty()) {
|
||||
return;
|
||||
}
|
||||
m_notifyName = std::move(m_notifyQueue.front());
|
||||
m_notifyQueue.pop();
|
||||
m_notifyTimer = NOTIFY_DURATION;
|
||||
}
|
||||
|
||||
m_notifyTimer -= ImGui::GetIO().DeltaTime;
|
||||
|
||||
const float alpha = std::min({
|
||||
m_notifyTimer / NOTIFY_FADE_TIME,
|
||||
(NOTIFY_DURATION - m_notifyTimer) / NOTIFY_FADE_TIME,
|
||||
1.0f
|
||||
});
|
||||
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
const float padding = 12.0f;
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(viewport->WorkPos.x + viewport->WorkSize.x - padding, viewport->WorkPos.y + padding),
|
||||
ImGuiCond_Always, ImVec2(1.0f, 0.0f)
|
||||
);
|
||||
|
||||
ImGui::SetNextWindowBgAlpha(alpha * 0.92f);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.08f, 0.06f, 0.01f, alpha * 0.92f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 0.8f, 0.1f, alpha));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, alpha));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 2.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14.0f, 10.0f));
|
||||
|
||||
constexpr ImGuiWindowFlags flags =
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs;
|
||||
|
||||
if (ImGui::Begin("##achievement_notify", nullptr, flags)) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.82f, 0.1f, alpha));
|
||||
ImGui::TextUnformatted("Achievement Unlocked!");
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted(m_notifyName.c_str());
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(3);
|
||||
}
|
||||
|
||||
void ImGuiAchievements::draw(bool& open) {
|
||||
showNotification();
|
||||
|
||||
if (!open) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(640, 200), ImVec2(800, 900));
|
||||
ImGui::SetNextWindowSize(ImVec2(640, 480), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin(
|
||||
"Achievements", &open,
|
||||
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)
|
||||
)
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto achievements = AchievementSystem::get().getAchievements();
|
||||
|
||||
int unlocked = 0;
|
||||
for (const auto& a : achievements) {
|
||||
if (a.unlocked) {
|
||||
++unlocked;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Text("%d / %d achievements unlocked", unlocked, (int)achievements.size());
|
||||
ImGui::SameLine();
|
||||
config::ImGuiCheckbox("Notifications", getSettings().game.enableAchievementNotifications);
|
||||
ImGui::Separator();
|
||||
|
||||
static const struct {
|
||||
AchievementCategory cat;
|
||||
const char* label;
|
||||
ImVec4 color;
|
||||
} ACHIEVEMENT_CATEGORIES[] = {
|
||||
{AchievementCategory::Story, "Story", ImVec4(1.0f, 0.82f, 0.1f, 1.0f)},
|
||||
{AchievementCategory::Collection, "Collection", ImVec4(0.3f, 0.85f, 0.4f, 1.0f)},
|
||||
{AchievementCategory::Challenge, "Challenge", ImVec4(1.0f, 0.65f, 0.15f, 1.0f)},
|
||||
{AchievementCategory::Minigame, "Minigame", ImVec4(0.5f, 0.85f, 1.0f, 1.0f)},
|
||||
{AchievementCategory::Glitched, "Glitched", ImVec4(0.75f, 0.4f, 1.0f, 1.0f)},
|
||||
};
|
||||
|
||||
const float footerHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
||||
|
||||
if (ImGui::BeginTabBar("##achievement_tabs", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
||||
for (const auto& catInfo : ACHIEVEMENT_CATEGORIES) {
|
||||
int catTotal = 0, catUnlocked = 0;
|
||||
for (const auto& a : achievements) {
|
||||
if (a.category == catInfo.cat) {
|
||||
++catTotal;
|
||||
if (a.unlocked) {
|
||||
++catUnlocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (catTotal == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string tabLabel = fmt::format("{} ({}/{})", catInfo.label, catUnlocked, catTotal);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, catInfo.color);
|
||||
const bool tabOpen = ImGui::BeginTabItem(tabLabel.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
if (tabOpen) {
|
||||
ImGui::BeginChild(
|
||||
"##cat_list",
|
||||
ImVec2(0, -footerHeight),
|
||||
ImGuiChildFlags_None,
|
||||
ImGuiWindowFlags_NoBackground
|
||||
);
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
for (const auto& a : achievements) {
|
||||
if (a.category != catInfo.cat) {
|
||||
continue;
|
||||
}
|
||||
ImGui::PushID(a.key);
|
||||
|
||||
ImGui::PushStyleColor(
|
||||
ImGuiCol_Text,
|
||||
a.unlocked ?
|
||||
ImVec4(1.0f, 0.65f, 0.15f, 1.0f) :
|
||||
ImGui::GetStyleColorVec4(ImGuiCol_Text)
|
||||
);
|
||||
|
||||
ImGui::TextUnformatted(a.name);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
const char* statusLabel = a.unlocked ? "[Unlocked]" : "[Locked]";
|
||||
ImGui::SameLine(
|
||||
ImGui::GetContentRegionMax().x -
|
||||
ImGui::CalcTextSize(statusLabel).x
|
||||
);
|
||||
|
||||
if (a.unlocked) {
|
||||
ImGui::TextColored(ImVec4(0.2f, 0.8f, 0.2f, 1.0f), "%s", statusLabel);
|
||||
} else {
|
||||
ImGui::TextColored(ImVec4(0.8f, 0.2f, 0.2f, 1.0f), "%s", statusLabel);
|
||||
}
|
||||
|
||||
ImGui::TextDisabled("%s", a.description);
|
||||
|
||||
if (a.isCounter) {
|
||||
const float fraction = a.goal > 0 ? (float)(a.progress) / (float)(a.goal) : 1.0f;
|
||||
const std::string overlay = fmt::format("{} / {}", a.progress, a.goal);
|
||||
ImGui::PushStyleColor(
|
||||
ImGuiCol_PlotHistogram,
|
||||
a.unlocked ?
|
||||
ImVec4(0.4f, 0.7f, 0.1f, 1.0f) :
|
||||
ImVec4(0.2f, 0.45f, 0.8f, 1.0f)
|
||||
);
|
||||
ImGui::ProgressBar(fraction, ImVec2(-1.0f, 0.0f), overlay.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
|
||||
if (ImGui::Button("Clear All Achievements")) {
|
||||
ImGui::OpenPopup("##confirm_clear");
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopup("##confirm_clear")) {
|
||||
ImGui::Text("Reset all achievement progress?");
|
||||
ImGui::Spacing();
|
||||
if (ImGui::Button("Yes, reset all")) {
|
||||
AchievementSystem::get().clearAll();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Cancel")) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace dusk
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user