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.0.1.0.QEAMIXM:user/release-keys");
ui_print("Target: Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.0.2.0.QEAMIXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.0.1.0.QEAMIXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.0.2.0.QEAMIXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.0.1.0.QEAMIXM:user/release-keys or Xiaomi/dipper/dipper:10/QKQ1.190828.002/V12.0.2.0.QEAMIXM: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:58c86b3755f0723c54251c76b9ab660b81c67376",
                      "EMMC:/dev/block/bootdevice/by-name/boot:45524298:9189860ce93f77c77d032863bd3050b4fc4ec8a1") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:58c86b3755f0723c54251c76b9ab660b81c67376\" or \"EMMC:/dev/block/bootdevice/by-name/boot:45524298:9189860ce93f77c77d032863bd3050b4fc4ec8a1\" has unexpected contents.");
apply_patch_space(45524298) || 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", "470,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,37352,37383,37384,37595,37596,37695,39110,40923,40924,40937,40938,40943,40944,40946,40947,43420,43421,43791,43792,43879,43880,44071,44072,46757,46758,46761,46762,46767,46768,47077,47078,47326,47327,47787,47788,48694,48695,48699,48700,48722,48723,49948,49949,50353,50354,50390,50391,53698,53700,57486,57487,57674,57675,58977,58978,59116,59117,59149,59150,59600,59601,60284,60285,61638,61639,61815,61816,63630,63631,65536,65537,66623,66624,67109,67110,69838,69839,69911,69912,74561,74564,77867,77868,80491,80492,81282,81283,81430,81431,82091,82092,82104,82105,82109,82110,96120,96121,96347,96350,98304,98306,98495,98496,102645,102646,104294,104295,104346,104347,104350,104353,106210,106211,106295,106296,106298,106299,106320,106321,107255,107258,107658,107661,107827,107828,107869,107870,109854,109855,109875,109876,109926,109927,110277,110278,110299,110300,110372,110373,110989,110990,115142,115143,115148,115149,115545,115546,117027,117028,118572,118573,119021,119022,119026,119027,119039,119040,119044,119045,119056,119057,119080,119081,121042,121043,121197,121198,121477,121480,121483,121484,122402,122403,122669,122672,124963,124964,125313,125314,127943,127944,127956,127957,128293,128294,129712,129721,130037,130038,130472,130473,131072,131073,132727,132728,135407,135412,135418,135419,135738,135739,136052,136053,136065,136066,136076,136079,136080,136081,136082,136083,136085,136086,136087,136088,136134,136135,136141,136142,136226,136229,136232,136233,136239,136240,136263,136264,136330,136331,136334,136339,136340,136341,136342,136343,136344,136345,137275,137276,137283,137284,137837,137839,138392,138394,138395,138396,138397,138398,138399,138400,138401,138402,138403,138404,138405,138406,138408,138409,138410,138413,139270,139272,139273,139274,139357,141277,141280,141282,141540,141541,141548,141550,142038,142040,142148,142149,142179,142180,142191,142192,142458,142459,142572,142573,142589,142591,142593,142594,151528,151529,159451,159452,161400,161401,161678,161679,163840,163842,164031,164032,167532,167533,184279,184280,184443,184444,190557,190558,196608,196609,212042,212043,229376,229378,229567,229568,230552,231053,231088,231370,231384,231386,231397,231398,231433,239214,241170,244650,246854,246855,251257,251258,251606,251607,251922,251923,251938,251939,251966,251967,252010,252011,252687,252699,253116,253235,253314,253326,254390,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,753665,754171,768868,774155,780254,780261,780677") == "d59316b5e239ef0808029e6d9ad9f9b7a4f86e44" || 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", "470,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,37352,37383,37384,37595,37596,37695,39110,40923,40924,40937,40938,40943,40944,40946,40947,43420,43421,43791,43792,43879,43880,44071,44072,46757,46758,46761,46762,46767,46768,47077,47078,47326,47327,47787,47788,48694,48695,48699,48700,48722,48723,49948,49949,50353,50354,50390,50391,53698,53700,57486,57487,57674,57675,58977,58978,59116,59117,59149,59150,59600,59601,60284,60285,61638,61639,61815,61816,63630,63631,65536,65537,66623,66624,67109,67110,69838,69839,69911,69912,74561,74564,77867,77868,80491,80492,81282,81283,81430,81431,82091,82092,82104,82105,82109,82110,96120,96121,96347,96350,98304,98306,98495,98496,102645,102646,104294,104295,104346,104347,104350,104353,106210,106211,106295,106296,106298,106299,106320,106321,107255,107258,107658,107661,107827,107828,107869,107870,109854,109855,109875,109876,109926,109927,110277,110278,110299,110300,110372,110373,110989,110990,115142,115143,115148,115149,115545,115546,117027,117028,118572,118573,119021,119022,119026,119027,119039,119040,119044,119045,119056,119057,119080,119081,121042,121043,121197,121198,121477,121480,121483,121484,122402,122403,122669,122672,124963,124964,125313,125314,127943,127944,127956,127957,128293,128294,129712,129721,130037,130038,130472,130473,131072,131073,132727,132728,135407,135412,135418,135419,135738,135739,136052,136053,136065,136066,136076,136079,136080,136081,136082,136083,136085,136086,136087,136088,136134,136135,136141,136142,136226,136229,136232,136233,136239,136240,136263,136264,136330,136331,136334,136339,136340,136341,136342,136343,136344,136345,137275,137276,137283,137284,137837,137839,138392,138394,138395,138396,138397,138398,138399,138400,138401,138402,138403,138404,138405,138406,138408,138409,138410,138413,139270,139272,139273,139274,139357,141277,141280,141282,141540,141541,141548,141550,142038,142040,142148,142149,142179,142180,142191,142192,142458,142459,142572,142573,142589,142591,142593,142594,151528,151529,159451,159452,161400,161401,161678,161679,163840,163842,164031,164032,167532,167533,184279,184280,184443,184444,190557,190558,196608,196609,212042,212043,229376,229378,229567,229568,230552,231053,231088,231370,231384,231386,231397,231398,231433,239214,241170,244650,246854,246855,251257,251258,251606,251607,251922,251923,251938,251939,251966,251967,252010,252011,252687,252699,253116,253235,253314,253326,254390,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,753665,754171,768868,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", "168,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,867,869,880,885,886,888,889,897,898,3050,3051,3174,3479,3546,3547,6640,6641,6759,6760,6881,6933,7644,7645,8328,8329,8926,8932,11185,11187,15562,15563,21102,21103,32768,32770,32832,32833,33339,33340,40521,40522,45231,45232,50225,50226,62758,62759,65536,65537,70984,70985,72007,72009,72152,72153,72515,72517,72926,72927,72979,72980,74914,74917,74935,74936,74981,74982,75000,75001,75003,75004,75052,75053,75080,75081,75677,75678,75703,75704,75738,75739,76073,76074,76091,76092,89178,89180,95316,95317,95319,95320,95895,95897,98304,98306,98368,98369,102774,102775,102784,102785,102823,102824,102825,102826,102846,102847,103272,103273,103326,103327,103668,103670,103671,103677,103685,103687,103693,103704,103754,103755,103757,103761,103899,103922,111507,111508,111616,111633,111658,111670,111738,111749,111757,111773,111781,131073,131578,163842,163904,163905,164410,196609,197114,229378,229440,229441,229946,253491,258044,260078,260085,260207") == "cdaf00324d968e6373291e85c19a550dcb5f3c90" || 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", "168,1,220,570,578,588,589,670,671,693,694,798,799,863,864,866,867,869,880,885,886,888,889,897,898,3050,3051,3174,3479,3546,3547,6640,6641,6759,6760,6881,6933,7644,7645,8328,8329,8926,8932,11185,11187,15562,15563,21102,21103,32768,32770,32832,32833,33339,33340,40521,40522,45231,45232,50225,50226,62758,62759,65536,65537,70984,70985,72007,72009,72152,72153,72515,72517,72926,72927,72979,72980,74914,74917,74935,74936,74981,74982,75000,75001,75003,75004,75052,75053,75080,75081,75677,75678,75703,75704,75738,75739,76073,76074,76091,76092,89178,89180,95316,95317,95319,95320,95895,95897,98304,98306,98368,98369,102774,102775,102784,102785,102823,102824,102825,102826,102846,102847,103272,103273,103326,103327,103668,103670,103671,103677,103685,103687,103693,103704,103754,103755,103757,103761,103899,103922,111507,111508,111616,111633,111658,111670,111738,111749,111757,111773,111781,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:58c86b3755f0723c54251c76b9ab660b81c67376",
                "EMMC:/dev/block/bootdevice/by-name/boot:45524298:9189860ce93f77c77d032863bd3050b4fc4ec8a1",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:45524298:9189860ce93f77c77d032863bd3050b4fc4ec8a1");

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