Skip to content

Commit

Permalink
properly restore frame offset and other things from last checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jul 30, 2021
1 parent d754f67 commit f2c13db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ void __fastcall Hooks::PlayLayer::pauseGame_H(gd::PlayLayer* self, int, bool idk


CCObject* __fastcall Hooks::CheckpointObject_create_H() {
std::cout << sizeof(CheckpointObjectMod) << std::endl;
return CheckpointObjectMod::create();
}

Expand Down
58 changes: 35 additions & 23 deletions src/replay_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ unsigned ReplaySystem::get_frame() {
return 0;
}

void ReplaySystem::update_frame_offset() {
// if there is no last checkpoint then it should default to 0
frame_offset = practice_fixes.get_last_checkpoint().frame;
}

void ReplaySystem::on_reset() {
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
if (is_playing()) {
update_frame_offset();
Hooks::PlayLayer::releaseButton(play_layer, 0, false);
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
action_index = 0;
} else if (is_recording()) {
practice_fixes.activated_objects.clear();
practice_fixes.activated_objects_p2.clear();
} else {
bool has_checkpoints = play_layer->m_checkpoints->count();
const auto checkpoint = practice_fixes.get_last_checkpoint();
if (!has_checkpoints) {
Expand All @@ -53,33 +61,37 @@ void ReplaySystem::on_reset() {
};
delete_from(practice_fixes.activated_objects, checkpoint.activated_objects_size);
delete_from(practice_fixes.activated_objects_p2, checkpoint.activated_objects_p2_size);
for (const auto& object : practice_fixes.activated_objects) {
object->m_hasBeenActivated = true;
}
for (const auto& object : practice_fixes.activated_objects_p2) {
object->m_hasBeenActivatedP2 = true;
if (is_recording()) {
for (const auto& object : practice_fixes.activated_objects) {
object->m_hasBeenActivated = true;
}
for (const auto& object : practice_fixes.activated_objects_p2) {
object->m_hasBeenActivatedP2 = true;
}
}
}
if (replay.get_type() == ReplayType::XPOS)
replay.remove_actions_after(play_layer->m_player1->m_position.x);
else
replay.remove_actions_after(get_frame());
const auto& actions = replay.get_actions();
bool holding = play_layer->m_player1->m_isHolding;
if ((holding && actions.empty()) || (!actions.empty() && actions.back().hold != holding)) {
record_action(holding, true, false);
if (holding) {
if (is_recording()) {
if (replay.get_type() == ReplayType::XPOS)
replay.remove_actions_after(play_layer->m_player1->m_position.x);
else
replay.remove_actions_after(get_frame());
const auto& actions = replay.get_actions();
bool holding = play_layer->m_player1->m_isHolding;
if ((holding && actions.empty()) || (!actions.empty() && actions.back().hold != holding)) {
record_action(holding, true, false);
if (holding) {
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
Hooks::PlayLayer::pushButton(play_layer, 0, true);
play_layer->m_player1->m_hasJustHeld = true;
}
} else if (!actions.empty() && actions.back().hold && holding && has_checkpoints && checkpoint.player1.buffer_orb) {
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
Hooks::PlayLayer::pushButton(play_layer, 0, true);
play_layer->m_player1->m_hasJustHeld = true;
}
} else if (!actions.empty() && actions.back().hold && holding && has_checkpoints && checkpoint.player1.buffer_orb) {
Hooks::PlayLayer::releaseButton(play_layer, 0, true);
Hooks::PlayLayer::pushButton(play_layer, 0, true);
if (play_layer->m_levelSettings->m_twoPlayerMode)
record_action(false, false, false);
practice_fixes.apply_checkpoint();
}
if (play_layer->m_levelSettings->m_twoPlayerMode)
record_action(false, false, false);
practice_fixes.apply_checkpoint();
}
}

Expand Down Expand Up @@ -121,7 +133,7 @@ auto _create_status_label(CCLayer* layer) {
void ReplaySystem::_update_status_label() {
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
if (play_layer) {
auto label = cast<CCLabelBMFont*>(play_layer->getChildByTag(10032));
auto label = cast<CCLabelBMFont*>(play_layer->getChildByTag(STATUS_LABEL_TAG));
if (!label)
label = _create_status_label(play_layer);
switch (state) {
Expand Down
8 changes: 5 additions & 3 deletions src/replay_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@ class ReplaySystem {
inline bool is_playing() { return state == PLAYING; }
inline bool is_recording() { return state == RECORDING; }

void update_frame_offset();

void toggle_playing() {
state = is_playing() ? NOTHING : PLAYING;
frame_offset = 0;
update_frame_offset();
_update_status_label();
}
void toggle_recording() {
state = is_recording() ? NOTHING : RECORDING;
if (!is_recording()) frame_advance = false;
else replay = Replay(default_fps, default_type);
frame_offset = 0;
update_frame_offset();
_update_status_label();
}

void reset_state() {
state = NOTHING;
frame_advance = false;
frame_offset = 0;
update_frame_offset();
_update_status_label();
}

Expand Down

0 comments on commit f2c13db

Please sign in to comment.