Skip to content

Commit f2c13db

Browse files
committed
properly restore frame offset and other things from last checkpoint
1 parent d754f67 commit f2c13db

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

src/hooks.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ void __fastcall Hooks::PlayLayer::pauseGame_H(gd::PlayLayer* self, int, bool idk
153153

154154

155155
CCObject* __fastcall Hooks::CheckpointObject_create_H() {
156-
std::cout << sizeof(CheckpointObjectMod) << std::endl;
157156
return CheckpointObjectMod::create();
158157
}
159158

src/replay_system.cpp

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ unsigned ReplaySystem::get_frame() {
3333
return 0;
3434
}
3535

36+
void ReplaySystem::update_frame_offset() {
37+
// if there is no last checkpoint then it should default to 0
38+
frame_offset = practice_fixes.get_last_checkpoint().frame;
39+
}
40+
3641
void ReplaySystem::on_reset() {
3742
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
3843
if (is_playing()) {
44+
update_frame_offset();
3945
Hooks::PlayLayer::releaseButton(play_layer, 0, false);
4046
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
4147
action_index = 0;
42-
} else if (is_recording()) {
48+
practice_fixes.activated_objects.clear();
49+
practice_fixes.activated_objects_p2.clear();
50+
} else {
4351
bool has_checkpoints = play_layer->m_checkpoints->count();
4452
const auto checkpoint = practice_fixes.get_last_checkpoint();
4553
if (!has_checkpoints) {
@@ -53,33 +61,37 @@ void ReplaySystem::on_reset() {
5361
};
5462
delete_from(practice_fixes.activated_objects, checkpoint.activated_objects_size);
5563
delete_from(practice_fixes.activated_objects_p2, checkpoint.activated_objects_p2_size);
56-
for (const auto& object : practice_fixes.activated_objects) {
57-
object->m_hasBeenActivated = true;
58-
}
59-
for (const auto& object : practice_fixes.activated_objects_p2) {
60-
object->m_hasBeenActivatedP2 = true;
64+
if (is_recording()) {
65+
for (const auto& object : practice_fixes.activated_objects) {
66+
object->m_hasBeenActivated = true;
67+
}
68+
for (const auto& object : practice_fixes.activated_objects_p2) {
69+
object->m_hasBeenActivatedP2 = true;
70+
}
6171
}
6272
}
63-
if (replay.get_type() == ReplayType::XPOS)
64-
replay.remove_actions_after(play_layer->m_player1->m_position.x);
65-
else
66-
replay.remove_actions_after(get_frame());
67-
const auto& actions = replay.get_actions();
68-
bool holding = play_layer->m_player1->m_isHolding;
69-
if ((holding && actions.empty()) || (!actions.empty() && actions.back().hold != holding)) {
70-
record_action(holding, true, false);
71-
if (holding) {
73+
if (is_recording()) {
74+
if (replay.get_type() == ReplayType::XPOS)
75+
replay.remove_actions_after(play_layer->m_player1->m_position.x);
76+
else
77+
replay.remove_actions_after(get_frame());
78+
const auto& actions = replay.get_actions();
79+
bool holding = play_layer->m_player1->m_isHolding;
80+
if ((holding && actions.empty()) || (!actions.empty() && actions.back().hold != holding)) {
81+
record_action(holding, true, false);
82+
if (holding) {
83+
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
84+
Hooks::PlayLayer::pushButton(play_layer, 0, true);
85+
play_layer->m_player1->m_hasJustHeld = true;
86+
}
87+
} else if (!actions.empty() && actions.back().hold && holding && has_checkpoints && checkpoint.player1.buffer_orb) {
7288
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
7389
Hooks::PlayLayer::pushButton(play_layer, 0, true);
74-
play_layer->m_player1->m_hasJustHeld = true;
7590
}
76-
} else if (!actions.empty() && actions.back().hold && holding && has_checkpoints && checkpoint.player1.buffer_orb) {
77-
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
78-
Hooks::PlayLayer::pushButton(play_layer, 0, true);
91+
if (play_layer->m_levelSettings->m_twoPlayerMode)
92+
record_action(false, false, false);
93+
practice_fixes.apply_checkpoint();
7994
}
80-
if (play_layer->m_levelSettings->m_twoPlayerMode)
81-
record_action(false, false, false);
82-
practice_fixes.apply_checkpoint();
8395
}
8496
}
8597

@@ -121,7 +133,7 @@ auto _create_status_label(CCLayer* layer) {
121133
void ReplaySystem::_update_status_label() {
122134
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
123135
if (play_layer) {
124-
auto label = cast<CCLabelBMFont*>(play_layer->getChildByTag(10032));
136+
auto label = cast<CCLabelBMFont*>(play_layer->getChildByTag(STATUS_LABEL_TAG));
125137
if (!label)
126138
label = _create_status_label(play_layer);
127139
switch (state) {

src/replay_system.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,25 @@ class ReplaySystem {
4343
inline bool is_playing() { return state == PLAYING; }
4444
inline bool is_recording() { return state == RECORDING; }
4545

46+
void update_frame_offset();
47+
4648
void toggle_playing() {
4749
state = is_playing() ? NOTHING : PLAYING;
48-
frame_offset = 0;
50+
update_frame_offset();
4951
_update_status_label();
5052
}
5153
void toggle_recording() {
5254
state = is_recording() ? NOTHING : RECORDING;
5355
if (!is_recording()) frame_advance = false;
5456
else replay = Replay(default_fps, default_type);
55-
frame_offset = 0;
57+
update_frame_offset();
5658
_update_status_label();
5759
}
5860

5961
void reset_state() {
6062
state = NOTHING;
6163
frame_advance = false;
62-
frame_offset = 0;
64+
update_frame_offset();
6365
_update_status_label();
6466
}
6567

0 commit comments

Comments
 (0)