Skip to content

Commit eaec0ed

Browse files
authored
Merge pull request #2206 from HDR-Development/shield-mechanics
Shield Mechanics Rewrite
2 parents 9089d3c + 04cc88f commit eaec0ed

File tree

31 files changed

+1100
-964
lines changed

31 files changed

+1100
-964
lines changed

dynamic/src/consts.rs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ pub mod vars {
178178

179179
pub const IS_ATTACK_CANCEL: i32 = 0x0063;
180180

181+
pub const DISABLE_CSTICK_BUFFER_ROLL_OOS: i32 = 0x0064;
182+
181183
// ints
182184

183185
pub const LAST_ATTACK_RECEIVER_ENTRY_ID: i32 = 0x0000;

fighters/common/src/general_statuses/catch/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@ mod catchcut;
33
mod catchdash;
44
mod catchattack;
55

6+
#[skyline::hook(replace = L2CFighterCommon_sub_transition_group_check_ground_catch)]
7+
unsafe fn sub_transition_group_check_ground_catch(fighter: &mut L2CFighterCommon) -> L2CValue {
8+
// prevents c-stick grabs, making c-stick roll feel smooth
9+
if super::shield::misc::check_cstick_escape_oos(fighter, false).get_bool() || super::shield::misc::check_escape_oos(fighter, false).get_bool() {
10+
return false.into();
11+
}
12+
call_original!(fighter)
13+
}
14+
15+
fn nro_hook(info: &skyline::nro::NroInfo) {
16+
if info.name == "common" {
17+
skyline::install_hooks!(sub_transition_group_check_ground_catch);
18+
}
19+
}
20+
621
pub fn install() {
22+
skyline::nro::add_hook(nro_hook);
723
catchcut::install();
824
catchdash::install();
925
catchattack::install();
10-
}
26+
}

fighters/common/src/general_statuses/shield/fighter_status_guard/mod.rs

+48-37
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@ use globals::*;
55
#[skyline::hook(replace = L2CFighterCommon_FighterStatusGuard__calc_shield_scale)]
66
pub unsafe fn calc_shield_scale(
77
fighter: &mut L2CFighterCommon,
8-
shield_level: L2CValue,
8+
shield_level: L2CValue
99
) -> L2CValue {
1010
let shield_level = shield_level.get_f32();
1111
let shield_max = WorkModule::get_float(
1212
fighter.module_accessor,
13-
*FIGHTER_INSTANCE_WORK_ID_FLOAT_GUARD_SHIELD_MAX,
13+
*FIGHTER_INSTANCE_WORK_ID_FLOAT_GUARD_SHIELD_MAX
1414
);
1515

1616
let shield_size = WorkModule::get_param_float(
1717
fighter.module_accessor,
1818
hash40("common"),
19-
hash40("shield_size"),
19+
hash40("shield_size")
20+
);
21+
let shield_scale = WorkModule::get_param_float(
22+
fighter.module_accessor,
23+
hash40("shield_scale"),
24+
0
2025
);
21-
let shield_scale =
22-
WorkModule::get_param_float(fighter.module_accessor, hash40("shield_scale"), 0);
2326
let shield_scale_min = WorkModule::get_param_float(
2427
fighter.module_accessor,
2528
hash40("common"),
26-
hash40("shield_scale_min"),
29+
hash40("shield_scale_min")
30+
);
31+
let shield_radius = WorkModule::get_param_float(
32+
fighter.module_accessor,
33+
hash40("shield_radius"),
34+
0
2735
);
28-
let shield_radius =
29-
WorkModule::get_param_float(fighter.module_accessor, hash40("shield_radius"), 0);
3036

3137
// let analog = InputModule::get_analog_for_guard(fighter.battle_object);
3238
// let scale = if analog > 0.0 && analog < 1.0 {
@@ -47,18 +53,18 @@ pub unsafe fn check_hit_stop_delay(fighter: &mut L2CFighterCommon, arg: L2CValue
4753
let hit_stop_delay_stick = WorkModule::get_param_float(
4854
fighter.module_accessor,
4955
hash40("common"),
50-
hash40("hit_stop_delay_stick"),
56+
hash40("hit_stop_delay_stick")
5157
);
5258
if hit_stop_delay_stick <= stick_x {
5359
let mut pos = *PostureModule::pos(fighter.module_accessor);
5460
let auto_mul = WorkModule::get_param_float(
5561
fighter.module_accessor,
5662
hash40("common"),
57-
hash40("hit_stop_delay_stick_auto_mul"),
63+
hash40("hit_stop_delay_stick_auto_mul")
5864
);
5965
let delay_mul = WorkModule::get_float(
6066
fighter.module_accessor,
61-
*FIGHTER_STATUS_GUARD_ON_WORK_FLOAT_DELAY_MUL,
67+
*FIGHTER_STATUS_GUARD_ON_WORK_FLOAT_DELAY_MUL
6268
);
6369
pos.x += stick_x * auto_mul * delay_mul;
6470
PostureModule::set_pos(fighter.module_accessor, &pos);
@@ -71,32 +77,34 @@ pub unsafe fn check_hit_stop_delay(fighter: &mut L2CFighterCommon, arg: L2CValue
7177
#[skyline::hook(replace = L2CFighterCommon_FighterStatusGuard__check_hit_stop_delay_flick)]
7278
pub unsafe fn check_hit_stop_delay_flick(
7379
fighter: &mut L2CFighterCommon,
74-
user_mul: L2CValue,
80+
user_mul: L2CValue
7581
) -> L2CValue {
7682
let stick_x = ControlModule::get_stick_x(fighter.module_accessor).abs();
7783
let sub_x = ControlModule::get_flick_sub_x(fighter.module_accessor) as f32;
7884
let hit_stop_delay_stick = WorkModule::get_param_float(
7985
fighter.module_accessor,
8086
hash40("common"),
81-
hash40("hit_stop_delay_stick"),
87+
hash40("hit_stop_delay_stick")
8288
);
83-
if !WorkModule::is_flag(
84-
fighter.module_accessor,
85-
*FIGHTER_STATUS_GUARD_ON_WORK_FLAG_DISABLE_HIT_STOP_DELAY_STICK,
86-
) && StopModule::is_hit(fighter.module_accessor)
87-
&& sub_x < hit_stop_delay_stick
88-
&& hit_stop_delay_stick <= stick_x
89+
if
90+
!WorkModule::is_flag(
91+
fighter.module_accessor,
92+
*FIGHTER_STATUS_GUARD_ON_WORK_FLAG_DISABLE_HIT_STOP_DELAY_STICK
93+
) &&
94+
StopModule::is_hit(fighter.module_accessor) &&
95+
sub_x < hit_stop_delay_stick &&
96+
hit_stop_delay_stick <= stick_x
8997
{
9098
let mut pos = *PostureModule::pos(fighter.module_accessor);
9199
let flick_mul = WorkModule::get_param_float(
92100
fighter.module_accessor,
93101
hash40("common"),
94-
hash40("hit_stop_delay_flick_mul"),
102+
hash40("hit_stop_delay_flick_mul")
95103
);
96104
let guard_mul = WorkModule::get_param_float(
97105
fighter.module_accessor,
98106
hash40("common"),
99-
hash40("hit_stop_delay_guard_mul"),
107+
hash40("hit_stop_delay_guard_mul")
100108
);
101109
let user_mul = WorkModule::get_float(fighter.module_accessor, user_mul.get_i32());
102110
pos.x += stick_x * flick_mul * guard_mul * user_mul;
@@ -112,12 +120,12 @@ pub unsafe fn check_hit_stop_delay_flick(
112120
pub unsafe fn is_continue_just_shield_count(fighter: &mut L2CFighterCommon) -> L2CValue {
113121
let just_shield_count = WorkModule::get_int(
114122
fighter.module_accessor,
115-
*FIGHTER_STATUS_GUARD_ON_WORK_INT_JUST_SHEILD_COUNT,
123+
*FIGHTER_STATUS_GUARD_ON_WORK_INT_JUST_SHEILD_COUNT
116124
);
117125
let max_count = WorkModule::get_param_int(
118126
fighter.module_accessor,
119127
hash40("common"),
120-
hash40("continue_just_shield_count"),
128+
hash40("continue_just_shield_count")
121129
);
122130
L2CValue::Bool(just_shield_count <= max_count)
123131
}
@@ -126,23 +134,23 @@ pub unsafe fn is_continue_just_shield_count(fighter: &mut L2CFighterCommon) -> L
126134
pub unsafe fn landing_effect_control(fighter: &mut L2CFighterCommon) -> L2CValue {
127135
WorkModule::dec_int(
128136
fighter.module_accessor,
129-
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME,
137+
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME
130138
);
131139
let frame = WorkModule::get_int(
132140
fighter.module_accessor,
133-
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME,
141+
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME
134142
);
135143
if frame <= 0 {
136144
MotionAnimcmdModule::call_script_single(
137145
fighter.module_accessor,
138146
*FIGHTER_ANIMCMD_EFFECT,
139147
Hash40::new("effect_guardlandingeffect"),
140-
-1,
148+
-1
141149
);
142150
WorkModule::set_int(
143151
fighter.module_accessor,
144152
8,
145-
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME,
153+
*FIGHTER_STATUS_GUARD_ON_WORK_INT_LANDING_EFFECT_FRAME
146154
);
147155
}
148156
L2CValue::I32(0)
@@ -155,7 +163,7 @@ pub unsafe fn set_guard_blend_motion(
155163
delta_y: L2CValue,
156164
stick_x: L2CValue,
157165
stick_y: L2CValue,
158-
flag: L2CValue,
166+
flag: L2CValue
159167
) -> L2CValue {
160168
let magnitude = stick_x.get_f32().powi(2) + stick_y.get_f32().powi(2);
161169
let magnitude = magnitude.sqrt().min(1.0);
@@ -173,7 +181,7 @@ pub unsafe fn set_guard_blend_motion(
173181
pub unsafe fn set_guard_blend_motion_angle(
174182
fighter: &mut L2CFighterCommon,
175183
delta_x: L2CValue,
176-
delta_y: L2CValue,
184+
delta_y: L2CValue
177185
) -> L2CValue {
178186
let delta_x = delta_x.get_f32();
179187
let delta_y = delta_y.get_f32();
@@ -195,25 +203,28 @@ pub unsafe fn set_just_shield_scale(fighter: &mut L2CFighterCommon) -> L2CValue
195203
let shield_size = WorkModule::get_param_float(
196204
fighter.module_accessor,
197205
hash40("common"),
198-
hash40("shield_size"),
206+
hash40("shield_size")
199207
);
200208
let shield_scale_min = WorkModule::get_param_float(
201209
fighter.module_accessor,
202210
hash40("common"),
203-
hash40("shield_scale_min"),
211+
hash40("shield_scale_min")
212+
);
213+
let shield_radius = WorkModule::get_param_float(
214+
fighter.module_accessor,
215+
hash40("shield_radius"),
216+
0
204217
);
205-
let shield_radius =
206-
WorkModule::get_param_float(fighter.module_accessor, hash40("shield_radius"), 0);
207218

208219
let scale = ((1.0 - shield_scale_min) * shield_size + shield_scale_min) * shield_radius;
209220
ModelModule::set_joint_scale(
210221
fighter.module_accessor,
211222
Hash40::new("throw"),
212-
&Vector3f {
223+
&(Vector3f {
213224
x: scale,
214225
y: scale,
215226
z: scale,
216-
},
227+
})
217228
);
218229
L2CValue::I32(0)
219230
}
@@ -224,11 +235,11 @@ pub unsafe fn set_shield_scale(fighter: &mut L2CFighterCommon, scale: L2CValue)
224235
ModelModule::set_joint_scale(
225236
fighter.module_accessor,
226237
Hash40::new("throw"),
227-
&Vector3f {
238+
&(Vector3f {
228239
x: scale,
229240
y: scale,
230241
z: scale,
231-
},
242+
})
232243
);
233244
L2CValue::I32(0)
234245
}

fighters/common/src/general_statuses/shield/guard/end.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ use globals::*;
44

55
#[skyline::hook(replace = L2CFighterCommon_status_end_Guard)]
66
pub unsafe fn status_end_Guard(fighter: &mut L2CFighterCommon) -> L2CValue {
7-
if fighter.global_table[STATUS_KIND] != FIGHTER_STATUS_KIND_GUARD && fighter.global_table[STATUS_KIND] != FIGHTER_STATUS_KIND_GUARD_DAMAGE {
8-
effect!(fighter, MA_MSC_CMD_EFFECT_EFFECT_OFF_KIND, Hash40::new("sys_shield"), true, true);
9-
effect!(fighter, MA_MSC_CMD_EFFECT_EFFECT_OFF_KIND, Hash40::new("sys_shield_smoke"), true, true);
7+
if
8+
fighter.global_table[STATUS_KIND] != FIGHTER_STATUS_KIND_GUARD &&
9+
fighter.global_table[STATUS_KIND] != FIGHTER_STATUS_KIND_GUARD_DAMAGE
10+
{
11+
effect!(
12+
fighter,
13+
MA_MSC_CMD_EFFECT_EFFECT_OFF_KIND,
14+
Hash40::new("sys_shield"),
15+
true,
16+
true
17+
);
18+
effect!(
19+
fighter,
20+
MA_MSC_CMD_EFFECT_EFFECT_OFF_KIND,
21+
Hash40::new("sys_shield_smoke"),
22+
true,
23+
true
24+
);
1025
}
1126
L2CValue::I32(0)
1227
}
1328

1429
pub fn install() {
15-
skyline::install_hook!(
16-
status_end_Guard
17-
);
18-
}
30+
skyline::install_hook!(status_end_Guard);
31+
}

fighters/common/src/general_statuses/shield/guard/exec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub fn install() {
2828
sub_ftStatusUniqProcessGuard_execStatus_common,
2929
sub_ftStatusUniqProcessGuard_execStop_common,
3030
ftStatusUniqProcessGuard_execStatus,
31-
ftStatusUniqProcessGuard_execStop,
31+
ftStatusUniqProcessGuard_execStop
3232
);
3333
}

fighters/common/src/general_statuses/shield/guard/exit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ unsafe fn sub_ftStatusUniqProcessGuard_exitStatus_common(fighter: &mut L2CFighte
88
fighter.module_accessor,
99
*FIGHTER_SHIELD_KIND_GUARD,
1010
app::ShieldStatus(*SHIELD_STATUS_NONE),
11-
0,
11+
0
1212
);
1313
ShieldModule::set_hit_stop_mul(fighter.module_accessor, 1.0);
1414
}

fighters/common/src/general_statuses/shield/guard/init.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ unsafe fn sub_ftStatusUniqProcessGuard_initStatus_common(fighter: &mut L2CFighte
88
fighter.module_accessor,
99
*FIGHTER_SHIELD_KIND_GUARD,
1010
app::ShieldStatus(*SHIELD_STATUS_NORMAL),
11-
0,
11+
0
12+
);
13+
let hit_stop_mul = WorkModule::get_param_float(
14+
fighter.module_accessor,
15+
hash40("common"),
16+
0x20d241cd64
1217
);
13-
let hit_stop_mul =
14-
WorkModule::get_param_float(fighter.module_accessor, hash40("common"), 0x20d241cd64);
1518
ShieldModule::set_hit_stop_mul(fighter.module_accessor, hit_stop_mul);
1619
}
1720

fighters/common/src/general_statuses/shield/guard/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ unsafe fn sub_status_guard_common(fighter: &mut L2CFighterCommon) {
1010
if !StopModule::is_stop(fighter.module_accessor) {
1111
misc::sub_guard_on_uniq(fighter, false.into());
1212
}
13-
fighter.global_table[SUB_STATUS]
14-
.assign(&L2CValue::Ptr(misc::sub_guard_on_uniq as *const () as _));
13+
fighter.global_table[SUB_STATUS].assign(
14+
&L2CValue::Ptr(misc::sub_guard_on_uniq as *const () as _)
15+
);
1516
}
1617

1718
#[skyline::hook(replace = L2CFighterCommon_status_guard_main_common_air)]
@@ -26,6 +27,7 @@ unsafe fn status_guard_common_air(fighter: &mut L2CFighterCommon) -> L2CValue {
2627

2728
#[skyline::hook(replace = L2CFighterCommon_status_Guard_Main)]
2829
unsafe fn status_Guard_Main(fighter: &mut L2CFighterCommon) -> L2CValue {
30+
misc::check_enable_cstick_buffer_rolls(fighter);
2931
if !status_guard_common_air(fighter).get_bool() {
3032
if !misc::sub_guard_cont(fighter).get_bool() {
3133
misc::status_guard_main_common(fighter);
@@ -36,6 +38,7 @@ unsafe fn status_Guard_Main(fighter: &mut L2CFighterCommon) -> L2CValue {
3638

3739
#[skyline::hook(replace = L2CFighterCommon_status_Guard)]
3840
unsafe fn status_Guard(fighter: &mut L2CFighterCommon) -> L2CValue {
41+
misc::check_enable_cstick_buffer_rolls(fighter);
3942
sub_status_guard_common(fighter);
4043
fighter.sub_shift_status_main(L2CValue::Ptr(status_Guard_Main as *const () as _))
4144
}

fighters/common/src/general_statuses/shield/guard/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ pub fn install() {
1414
init::install();
1515
exec::install();
1616
exit::install();
17-
}
17+
}

fighters/common/src/general_statuses/shield/guard/pre.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unsafe fn status_pre_Guard(fighter: &mut L2CFighterCommon) -> L2CValue {
1414
*FIGHTER_STATUS_WORK_KEEP_FLAG_GUARD_FLAG,
1515
*FIGHTER_STATUS_WORK_KEEP_FLAG_GUARD_INT,
1616
*FIGHTER_STATUS_WORK_KEEP_FLAG_GUARD_FLOAT,
17-
*FS_SUCCEEDS_KEEP_VISIBILITY,
17+
*FS_SUCCEEDS_KEEP_VISIBILITY
1818
);
1919

2020
FighterStatusModuleImpl::set_fighter_status_data(
@@ -27,7 +27,7 @@ unsafe fn status_pre_Guard(fighter: &mut L2CFighterCommon) -> L2CValue {
2727
0,
2828
*FIGHTER_STATUS_ATTR_DISABLE_SHIELD_RECOVERY as u32,
2929
0,
30-
0,
30+
0
3131
);
3232

3333
L2CValue::I32(0)

0 commit comments

Comments
 (0)