@@ -543,16 +543,19 @@ def add_act_selector_ignore(base_path, level_enum):
543543 file_path = os .path .join (base_path , "src/game/level_update.c" )
544544 data = getDataFromFile (file_path )
545545
546- function_start = re . search ( "s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{" , data , re . DOTALL )
547-
548- if function_start is None :
546+ try :
547+ function_start = re . search ( "s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{" , data , re . DOTALL ). end ()
548+ except :
549549 raise PluginError ('Could not find lvl_set_current_level in "' + file_path + '".' )
550550
551- function_end = re .search ("\s*return\s*\!gDebugLevelSelect;\s*" , data , re .DOTALL )
552- if function_end is None :
553- raise PluginError ('Could not find return in lvl_set_current_level in "' + file_path + '".' )
551+ try :
552+ function_end = (
553+ re .search ("\s*return\s*(?:(?!(0|FALSE)).)*?;" , data [function_start :], re .DOTALL ).start () + function_start
554+ )
555+ except :
556+ raise PluginError ('Could not find final return in lvl_set_current_level in "' + file_path + '".' )
554557
555- function_contents = data [function_start . end () : function_end . start () ]
558+ function_contents = data [function_start : function_end ]
556559
557560 check_result = re .search (
558561 "if\s*\(gCurrLevelNum\s*==\s*" + level_enum + "\)\s*return\s*0;" , function_contents , re .DOTALL
@@ -562,7 +565,7 @@ def add_act_selector_ignore(base_path, level_enum):
562565
563566 function_contents += "\n \t if (gCurrLevelNum == " + level_enum + ") return 0;"
564567
565- new_data = data [: function_start . end () ] + function_contents + data [function_end . start () :]
568+ new_data = data [:function_start ] + function_contents + data [function_end :]
566569
567570 saveDataToFile (file_path , new_data )
568571
@@ -571,23 +574,26 @@ def remove_act_selector_ignore(base_path, level_enum):
571574 file_path = os .path .join (base_path , "src/game/level_update.c" )
572575 data = getDataFromFile (file_path )
573576
574- function_start = re . search ( "s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{" , data , re . DOTALL )
575-
576- if function_start is None :
577+ try :
578+ function_start = re . search ( "s32\s*lvl\_set\_current\_level\s*\((((?!\)).)*)\)\s*\{" , data , re . DOTALL ). end ()
579+ except :
577580 raise PluginError ('Could not find lvl_set_current_level in "' + file_path + '".' )
578581
579- function_end = re .search ("\s*return\s*\!gDebugLevelSelect;\s*" , data , re .DOTALL )
580- if function_end is None :
581- raise PluginError ('Could not find return in lvl_set_current_level in "' + file_path + '".' )
582+ try :
583+ function_end = (
584+ re .search ("\s*return\s*(?:(?!(0|FALSE)).)*?;" , data [function_start :], re .DOTALL ).start () + function_start
585+ )
586+ except :
587+ raise PluginError ('Could not find final return in lvl_set_current_level in "' + file_path + '".' )
582588
583- function_contents = data [function_start . end () : function_end . start () ]
589+ function_contents = data [function_start : function_end ]
584590
585591 new_function_contents = re .sub (
586592 "\s*?if\s*\(gCurrLevelNum\s*==\s*" + level_enum + "\)\s*return\s*0;" , "" , function_contents , re .DOTALL
587593 )
588594
589595 if function_contents != new_function_contents :
590- new_data = data [: function_start . end () ] + new_function_contents + data [function_end . start () :]
596+ new_data = data [:function_start ] + new_function_contents + data [function_end :]
591597 saveDataToFile (file_path , new_data )
592598
593599
0 commit comments