getprop("ro.product.device") == "dipper" || abort("E3004: This package is for \"dipper\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.1.0.QEARUXM:user/release-keys");
ui_print("Target: Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.2.0.QEARUXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.1.0.QEARUXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.2.0.QEARUXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.1.0.QEARUXM:user/release-keys or Xiaomi/dipper_ru/dipper:10/QKQ1.190828.002/V12.0.2.0.QEARUXM:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
show_progress(0.100000, 10);
patch_partition_check("EMMC:/dev/block/bootdevice/by-name/boot:45524298:618738fbcec43377be860879e471d0037d209ab1",
                      "EMMC:/dev/block/bootdevice/by-name/boot:45524298:3c26b81a12b530d05789c6837c509b229911a95d") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:618738fbcec43377be860879e471d0037d209ab1\" or \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:3c26b81a12b530d05789c6837c509b229911a95d\" has unexpected contents.");
apply_patch_space(115630080) || abort("E3006: Not enough free space on /cache to apply patches.");
show_progress(0.100000, 70);
if (range_sha1("/dev/block/bootdevice/by-name/system", "268,1,534,698,712,744,751,753,754,1000,1005,1007,1008,1114,1115,1599,1600,2288,2289,2291,2293,2294,2295,2310,2311,2492,2493,3664,3665,3667,3668,3672,3673,3681,3682,3683,3684,9041,9042,9044,9045,9449,9450,9452,9453,10449,10451,16390,16391,16524,16525,19294,19296,25543,25545,32768,32770,32959,32960,34681,34682,34684,34686,34745,34746,34879,34881,34949,34950,34964,34965,34977,34978,35599,35602,35608,35609,35614,35615,35734,35737,37351,65537,66043,80492,81282,81431,82091,96350,98304,98306,98495,98496,102645,131073,131579,161408,161410,163842,164031,164032,164538,196609,197115,229378,229567,229568,230074,262145,262651,294914,295103,295104,295610,327681,328187,360449,360955,393217,393723,425985,426491,429570,429576,435553,438244,458753,459259,473743,473912,487268,491520,491521,494784,506324,506330,506331,506333,506335,506336,506339,506342,506347,506350,506351,506353,506355,506356,506358,506365,506366,506368,506370,506376,506378,506385,506387,506389,506393,506417,506419,506424,506425,506435,506436,506445,506446,506450,506454,506459,506460,506462,506463,506469,506471,506473,506476,506480,506481,506482,506484,506485,506488,506490,506491,506493,506496,506505,506506,506507,506508,506525,506526,506528,506529,506532,506534,506555,506557,506559,506560,506608,506613,506620,506622,506623,506625,506626,506630,506631,506632,506635,506639,506640,506641,506662,506663,506664,506665,506666,506668,506683,506686,506688,506689,506695,506696,506697,506702,506703,506705,506720,506721,506722,506726,506728,506731,506739,506741,506743,506744,506752,506755,506763,524289,524795,525369,528142,535144,535151,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,753665,754171,768869,774155,780254,780261,780677") == "14027c28c8e1fbf694797703a6ec7100458a4554" || block_image_verify("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")) then
ui_print("Verified system image...");
else
check_first_block("/dev/block/bootdevice/by-name/system");
ifelse (block_image_recover("/dev/block/bootdevice/by-name/system", "268,1,534,698,712,744,751,753,754,1000,1005,1007,1008,1114,1115,1599,1600,2288,2289,2291,2293,2294,2295,2310,2311,2492,2493,3664,3665,3667,3668,3672,3673,3681,3682,3683,3684,9041,9042,9044,9045,9449,9450,9452,9453,10449,10451,16390,16391,16524,16525,19294,19296,25543,25545,32768,32770,32959,32960,34681,34682,34684,34686,34745,34746,34879,34881,34949,34950,34964,34965,34977,34978,35599,35602,35608,35609,35614,35615,35734,35737,37351,65537,66043,80492,81282,81431,82091,96350,98304,98306,98495,98496,102645,131073,131579,161408,161410,163842,164031,164032,164538,196609,197115,229378,229567,229568,230074,262145,262651,294914,295103,295104,295610,327681,328187,360449,360955,393217,393723,425985,426491,429570,429576,435553,438244,458753,459259,473743,473912,487268,491520,491521,494784,506324,506330,506331,506333,506335,506336,506339,506342,506347,506350,506351,506353,506355,506356,506358,506365,506366,506368,506370,506376,506378,506385,506387,506389,506393,506417,506419,506424,506425,506435,506436,506445,506446,506450,506454,506459,506460,506462,506463,506469,506471,506473,506476,506480,506481,506482,506484,506485,506488,506490,506491,506493,506496,506505,506506,506507,506508,506525,506526,506528,506529,506532,506534,506555,506557,506559,506560,506608,506613,506620,506622,506623,506625,506626,506630,506631,506632,506635,506639,506640,506641,506662,506663,506664,506665,506666,506668,506683,506686,506688,506689,506695,506696,506697,506702,506703,506705,506720,506721,506722,506726,506728,506731,506739,506741,506743,506744,506752,506755,506763,524289,524795,525369,528142,535144,535151,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,753665,754171,768869,774155,780254,780261,780677") && block_image_verify("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat"), ui_print("system recovered successfully."), abort("E1004: system partition fails to recover"));
endif;
if (range_sha1("/dev/block/bootdevice/by-name/vendor", "60,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,867,869,880,885,886,888,889,897,898,1333,15563,21102,32770,32832,32833,33338,45232,50225,50226,62758,62759,65536,65537,70984,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,229378,229440,229441,229946,253491,258044,260078,260085,260207") == "b2101fc0f267e250b774fcc96ee4429f30200a6b" || block_image_verify("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat")) then
ui_print("Verified vendor image...");
else
check_first_block("/dev/block/bootdevice/by-name/vendor");
ifelse (block_image_recover("/dev/block/bootdevice/by-name/vendor", "60,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,867,869,880,885,886,888,889,897,898,1333,15563,21102,32770,32832,32833,33338,45232,50225,50226,62758,62759,65536,65537,70984,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,229378,229440,229441,229946,253491,258044,260078,260085,260207") && block_image_verify("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat"), ui_print("vendor recovered successfully."), abort("E2004: vendor partition fails to recover"));
endif;

# ---- start making changes here ----

ui_print("Patching boot image...");
show_progress(0.100000, 10);
patch_partition("EMMC:/dev/block/bootdevice/by-name/boot:45524298:618738fbcec43377be860879e471d0037d209ab1",
                "EMMC:/dev/block/bootdevice/by-name/boot:45524298:3c26b81a12b530d05789c6837c509b229911a95d",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:45524298:3c26b81a12b530d05789c6837c509b229911a95d");

# ---- radio update tasks ----

ui_print("Patching firmware images...");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl_a");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl_b");
show_progress(0.600000, 600);
ui_print("Patching system image after verification.");
block_image_update("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");
ui_print("Patching vendor image after verification.");
block_image_update("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");
show_progress(0.100000, 2);

# ---- radio update tasks 2 ----

ui_print("Patching vbmeta dtbo logo binimages...");
