# Xenoblade Chronicles 3 2.2.0/2.2.1
# BID: 82D187FE9EF9BE92

DECLARATIONS:
  -
    type: variable
    name: dr_target
    value_type: float
    default_value: 0.0166666666
    evaluate: "(1 / FPS_TARGET) / VSYNC_TARGET"
  -
    type: const
    name: default_frametime
    value: 0x3d088889
  - 
    type: code
    name: etherFix
    instructions: [
      [ldr, x21, [x0]],
      [mov, w8, $default_frametime],
      [movk, w8, $default_frametime, 16],
      [str, w8, [x21, 0x214]],
      [ret]
    ]    
MASTER_WRITE:
  # Redirect DR frametime target reading
  -
    type: asm_a64
    main_offset: 0x124F518
    instructions: [
      [adrp, x8, $dr_target],
      [ldr, s0, [x8, $dr_target]]
    ]
  # Fix crash when gathering big amount of ether for > 30 FPS
  -
    type: asm_a64
    main_offset: 0x67360
    instructions: [
      [bl, _etherFix()]
    ]
ALL_FPS:
  # vsync
  -
    type: evaluate_write
    address: [MAIN, 0x1B42DB0]
    value_type: int32
    value: [VSYNC_TARGET, VSYNC_TARGET]
  # UI speed
  -
    type: evaluate_write
    address: [MAIN, 0x1BA1A90, 128]
    address_unsafe: true
    value_type: float
    value: "1 / FPS_TARGET"
  -
    type: compare
    compare_address: [MAIN, 0x1BA1A98]
    compare_type: "!="
    compare_value_type: int8
    compare_value: 0
    address: [MAIN, 0x1B42DB0]
    value_type: int32
    value: [2, 2]
  -
    type: compare
    compare_address: [MAIN, 0x1BA1A98]
    compare_type: "!="
    compare_value_type: int8
    compare_value: 0
    address: [VARIABLE, dr_target]
    value: 0.0166666666
  -
    type: compare
    compare_address: [MAIN, 0x1BA1A98]
    compare_type: "!="
    compare_value_type: int8
    compare_value: 0
    address: [MAIN, 0x1BA1A90, 128]
    address_unsafe: true
    value_type: float
    value: 0.0333333333
  -
    type: compare
    compare_address: [MAIN, 0x1BA1A98]
    compare_type: "!="
    compare_value_type: int8
    compare_value: 0
    value_type: refresh_rate
    value: 30
