// SPDX-License-Identifier: GPL-3.0-only // Implements the tax animation declared in game_end_tax_animation.hpp: decoding the animation script bytes // into steps, loading the art, and advancing the screen one step at a time (copy rectangles, present by // swapping buffers, optional full-frame copy). Timing is only reported, never waited on here. #include "formats/executable_layout.hpp" #include "ui/game_end_tax_animation.hpp" #include #include "formats/le.hpp" namespace bmh::ui { std::filesystem::path asset_path(const std::filesystem::path&, const std::string&); namespace { void valid_image(const Image& image, int width, int height, const char* message) { if (image.width decode_tax_animation_script(std::span bytes) { std::vector steps; std::vector copies; size_t offset=0; while (offset script; // Read complete commands so zero/255 inside rectangles cannot end the script. uint32_t address=::bmh::layout::GameEndTaxAnimation_LoadGameEndTaxAnimationAssets_ExecutableField; while (script.size()<4096) { if (!exe.contains(address)) throw FormatError("truncated EXE tax animation script"); const auto token=exe.u8(address); const unsigned length=token==0?7:1; if (!exe.contains(address+length-1)) throw FormatError("truncated EXE tax animation rectangle"); for (unsigned i=0; i4 || variant>assets_.steps.size()) throw FormatError("invalid tax animation variant"); valid_image(visible_,320,240,"tax animation requires a visible320x240 frame"); valid_image(drawing_,320,240,"tax animation requires a drawing320x240 frame"); if (visible_.width!=320 || visible_.height!=240 || drawing_.width!=320 || drawing_.height!=240) throw FormatError("tax animation requires exact320x240 frames"); valid_image(assets_.art,1,1,"tax animation requires Original KB17"); if (!flat_background) valid_image(assets_.background,224,148,"tax animation requires Original KB56"); for (const auto& step:assets_.steps) { if (step.wait_ticks<1 || step.wait_ticks>154) throw FormatError("invalid tax animation wait marker"); for (const auto& r:step.copies) if (r.width==0 || r.height==0 || r.x>320 || r.width>320-r.x || r.y>240 || r.height>240-r.y || r.source_x>unsigned(assets_.art.width) || r.width>unsigned(assets_.art.width)-r.source_x || r.source_y>unsigned(assets_.art.height) || r.height>unsigned(assets_.art.height)-r.source_y) throw FormatError("invalid tax animation copy rectangle"); } frame(drawing_,assets_.background,flat_background); } bool GameEndTaxAnimationScreen::advance_step() { if (finished()) return false; const auto& step=assets_.steps[steps_presented_]; for (const auto& rectangle:step.copies) copy(drawing_,assets_.art,rectangle); std::swap(visible_,drawing_); // DecodeTaxAnimationScript always swaps these two buffers. if (step.copy_after_present) drawing_=visible_; // TotalMilliseconds full image copy, only param1!=0. wait_milliseconds_=step.wait_ticks*20; ++steps_presented_; return true; } unsigned GameEndTaxAnimationScreen::total_milliseconds() const { unsigned total=0; for (unsigned i=0; i