Jump to content

Whats wrong with my PATCH_IF / How to print a variable to see whats being read?


Recommended Posts

Im trying to read an item, then , if its a certain kind I proceed to patch it

Right now I have it set to only get the regular battle axe for testing. For some reason, the "PATCH_IF (weapon = 0x5c) BEGIN" skips over it.

IESDP has the code for axes be 0x19, opcodes has 92 (0x5c) for axes in the #233 (0xE9) opcode. So I've tried both and neither works. 

If I remove this line, it goes through and works, except ill be going through all items so I need the PATCH_IF.

 

What am I doing wrong? Also is there a way to print out my variable so I can see what being saved to it? PRINT weapon doesnt seem to work

Quote

    COPY_EXISTING ~AX1H01.ITM~ ~override~
        PATCH_IF (SOURCE_SIZE > 0x71) BEGIN // avoid crashing on empty items
        READ_SHORT 0xE9 weapon ELSE 0x0e // checks weapon prof needed. ELSE is for items that go out of bounds
        
                PATCH_IF (weapon = 0x5c) BEGIN // set right now to see if it is in the axe weapon group
                    READ_BYTE 0x2b class // Reads section that says if unusable by beastmaster
                        PATCH_IF ((class BAND 0b00000010)= 0b00000010) BEGIN  // Checks if the weapon is unusable by beastmasters.
                            WRITE_BYTE 0x2b (class BAND 0b11111101) // Makes it usable by beastmasters
                        END
                END
        END
BUT_ONLY_IF_IT_CHANGES

 

Edited by Enkidu555
Link to comment

Why are you reading at offset 0xE9? That's not in the header at all; the ITM format's header has total size 0x72, and everything you care about here should be in there. (Also, reading/writing at a fixed offset that's not in the header is always a bad idea. You either read a field in the header to find the offset you need, or you use a function)

Item type is the two-byte field at offset 0x1E, and "axe" is type 25. Or if you're going by proficiency, that's the one-byte field at offset 0x31 and "axe" is proficiency 92 (unless a mod changes that, and some mods do).

Oh, and a neat little simplification of the block where you make the actual change:

WRITE_BYTE 0x2b (THIS BAND 0b11111101) // Make usable by beastmaster

That can replace the four-line READ_BYTE/PATCH_IF/WRITE_BYTE block. THIS is a variable that contains whatever's already there when you're doing a WRITE, so it's useful for making incremental changes.

Link to comment
20 minutes ago, jmerry said:

Why are you reading at offset 0xE9? That's not in the header at all; the ITM format's header has total size 0x72, and everything you care about here should be in there. (Also, reading/writing at a fixed offset that's not in the header is always a bad idea. You either read a field in the header to find the offset you need, or you use a function)

Item type is the two-byte field at offset 0x1E, and "axe" is type 25. Or if you're going by proficiency, that's the one-byte field at offset 0x31 and "axe" is proficiency 92 (unless a mod changes that, and some mods do).

Oh, and a neat little simplification of the block where you make the actual change:

WRITE_BYTE 0x2b (THIS BAND 0b11111101) // Make usable by beastmaster

That can replace the four-line READ_BYTE/PATCH_IF/WRITE_BYTE block. THIS is a variable that contains whatever's already there when you're doing a WRITE, so it's useful for making incremental changes.

That did it thanks! changed E9 to 1c. I guess i was getting mixed p between opcodes and headers

Link to comment

Oh, and as for the question about printing a variable? PRINT or PATCH_PRINT, depending on whether you're in an ACTION or PATCH environment (whether you have a file loaded; running a PATCH in an ACTION environment will cause an error, while running an ACTION in a PATCH environment will close the file). And any variables you want the value of will need to be enclosed in %%; PRINT ~Number~ prints the literal string "Number", while PRINT ~%Number%~ prints the value of the variable "Number".

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...