Jarno Mikkola Posted February 19, 2015 Share Posted February 19, 2015 So if I want to patch "every spell" with an effect with opcode 1, if it is not already using that opcode, how should I do it ? I was thinking it would be something to this effect: BEGIN ~Experiment 1~ COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~ PATCH_IF (SOURCE_SIZE > 0x72) BEGIN READ_LONG 0x6a fx_offset FOR (y = %fx_offset% ; y < %SOURCE_SIZE% ; y = y + 0x30) BEGIN // scan all effects READ_SHORT %y% opcode1 // important line 1 PATCH_IF (opcode1 != 1) BEGIN // important line 2 LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode=1 END // the patch BUT_ONLY Yes, I stole that off of here. Could someone check/approve that ? Yeah, it should be clear that I intent to not just add an effect with Attack per rounds that does nothing, and without restrictions, but it's just a filler for example for now, that checks that the spell doesn't have that any other effects with that particular opcode in use. Ouh yeah, there's likely too few END's in that, don't bother with them just for now... Link to comment
CrevsDaak Posted February 19, 2015 Share Posted February 19, 2015 I could say it's alright. If you want something more bullet-proof and debuggable, I'd recommend using a WHILE loop and looping through the effects in the abilities Link to comment
Mike1072 Posted February 19, 2015 Share Posted February 19, 2015 The code you posted is the potentially dangerous code from the other thread, not the suggested code. For your task, consider the logic of what you are trying to do. You want to check all spell effects to see if any use opcode 1. If none use opcode 1, you want to add an effect that does. What your code is currently doing is checking EACH spell effect to see if it uses opcode 1. If that effect doesn't use opcode 1, then it adds an effect that does. That's a big difference in how many effects get added. I'm assuming you want each ABILITY that doesn't contain an effect with opcode 1 to gain an effect using opcode 1. COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~ PATCH_IF (SOURCE_SIZE > 0x72) BEGIN READ_LONG 0x64 abilities_off READ_SHORT 0x68 num_abilities READ_LONG 0x6a effects_off FOR (i = 0; i < num_abilities; i += 1) BEGIN READ_SHORT (abilities_off + 0x28*i + 0x1e) num_features READ_SHORT (abilities_off + 0x28*i + 0x20) features_ind SET missing_effect = 1 FOR (j = 0; j < num_features; j += 1) BEGIN READ_SHORT (effects_off + 0x30*(features_ind + j)) opcode PATCH_IF (opcode == 1) BEGIN // already has the effect SET missing_effect = 0 END END PATCH_IF (missing_effect) BEGIN // add effect to this ability END END END BUT_ONLY The code that is labelled // add effect to this ability executes if that particular ability does not contain any effects using opcode 0. If you just plug in your function to add a new effect there, that will insert bytes into the file, which may change the value of abilities_off. So, one way to do it would be to launch the function there and then re-read abilities_off from 0x64. Another way would be to not make any changes to the file until you finish reading all of the abilities. To do it this way, you need to keep track of all of the abilities that match the criteria. An easy way to do that is to use a list - in this case, a WeiDU array. After you have read all the abilities, you can loop through the array and add all of the effects. COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~ PATCH_IF (SOURCE_SIZE > 0x72) BEGIN READ_LONG 0x64 abilities_off READ_SHORT 0x68 num_abilities READ_LONG 0x6a effects_off CLEAR_ARRAY matching_abilities FOR (i = 0; i < num_abilities; i += 1) BEGIN READ_SHORT (abilities_off + 0x28*i + 0x1e) num_features READ_SHORT (abilities_off + 0x28*i + 0x20) features_ind SET missing_effect = 1 FOR (j = 0; j < num_features; j += 1) BEGIN READ_SHORT (effects_off + 0x30*(features_ind + j)) opcode PATCH_IF (opcode == 1) BEGIN // already has the effect SET missing_effect = 0 END END PATCH_IF (missing_effect) BEGIN SET $matching_abilities(~%i%~) = 1 END END PHP_EACH matching_abilities AS ability => val BEGIN LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode = 1 header = (ability + 1) END END END BUT_ONLY Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.