"""Use the dedicated critical sound at the native shot-exit call, once per crit."""
ORIGIN = 0x2FF600


def install(data, assemble, patch, with_flash=True):
    code = assemble('critical_sound', ORIGIN)
    assert ORIGIN+len(code) <= 0x2FF800, 'critical sound overlaps ratings'
    patch(ORIGIN, b'\xFF'*len(code), code)
    original = '4eb9002ff504' if with_flash else '303900ffbede'
    patch(0x2FF472, bytes.fromhex(original), bytes.fromhex('4eb9002ff600'))
