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/dipper:10/QKQ1.190828.002/V12.5.1.0.QEACNXM:user/release-keys");
ui_print("Target: Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.5.2.0.QEACNXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.5.1.0.QEACNXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.5.2.0.QEACNXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.5.1.0.QEACNXM:user/release-keys or Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.5.2.0.QEACNXM: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:cbab30a4747d84f3c38be36db6dbe36d6d1d50c4",
                      "EMMC:/dev/block/bootdevice/by-name/boot:45524298:349d298b3781a45df9dcf7ca1ec221cbc63ba84d") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:cbab30a4747d84f3c38be36db6dbe36d6d1d50c4\" or \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:349d298b3781a45df9dcf7ca1ec221cbc63ba84d\" has unexpected contents.");
apply_patch_space(77230080) || 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", "204,1,590,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,25544,25546,32768,32770,32959,32960,34683,34684,34686,34688,34747,34748,34881,34883,35113,35114,35182,35183,35197,35198,35268,35269,35278,35279,35747,35750,35756,35757,35762,35763,35807,35810,35821,35822,35947,35948,35951,35952,35969,37271,38881,38882,38890,38891,38896,38897,38899,38900,45473,45474,45476,45477,45564,45565,45648,45649,48548,48549,48554,48555,48803,48804,49821,49822,50196,50197,50233,50234,55853,55855,61225,61226,61578,61580,61633,61634,61640,61641,61654,61655,62277,62278,63168,63169,63431,63432,63609,63610,65536,65537,66756,66757,67815,67816,70380,70381,71726,98306,98495,98496,99002,131073,131579,163842,164031,164032,164538,196609,197115,229378,229567,229568,230074,262145,262651,294914,295103,295104,295610,327681,328187,360449,360955,393217,393723,425985,426491,458753,459259,491521,492027,524289,524795,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,751601,753664,753665,774155,780254,780261,780367") == "08e07696f47b476435e5f011c1c43166f06eb49a" || 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", "204,1,590,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,25544,25546,32768,32770,32959,32960,34683,34684,34686,34688,34747,34748,34881,34883,35113,35114,35182,35183,35197,35198,35268,35269,35278,35279,35747,35750,35756,35757,35762,35763,35807,35810,35821,35822,35947,35948,35951,35952,35969,37271,38881,38882,38890,38891,38896,38897,38899,38900,45473,45474,45476,45477,45564,45565,45648,45649,48548,48549,48554,48555,48803,48804,49821,49822,50196,50197,50233,50234,55853,55855,61225,61226,61578,61580,61633,61634,61640,61641,61654,61655,62277,62278,63168,63169,63431,63432,63609,63610,65536,65537,66756,66757,67815,67816,70380,70381,71726,98306,98495,98496,99002,131073,131579,163842,164031,164032,164538,196609,197115,229378,229567,229568,230074,262145,262651,294914,295103,295104,295610,327681,328187,360449,360955,393217,393723,425985,426491,458753,459259,491521,492027,524289,524795,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,751601,753664,753665,774155,780254,780261,780367") && 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", "52,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,870,872,883,888,889,891,892,900,901,1336,32770,32832,32833,33338,65537,66042,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,222706,229376,229378,229440,229441,258044,260078,260085,260210") == "516f7707fea7eaf76caacfca39b209e752391250" || 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", "52,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,870,872,883,888,889,891,892,900,901,1336,32770,32832,32833,33338,65537,66042,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,222706,229376,229378,229440,229441,258044,260078,260085,260210") && 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:cbab30a4747d84f3c38be36db6dbe36d6d1d50c4",
                "EMMC:/dev/block/bootdevice/by-name/boot:45524298:349d298b3781a45df9dcf7ca1ec221cbc63ba84d",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:45524298:349d298b3781a45df9dcf7ca1ec221cbc63ba84d");

# ---- 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...");
