Jump to content

Change a container script in Area


Recommended Posts

I'm trying to add a small script to all containers from a specific area, but i'm struggling with my code. Can someone help me here ?

Spoiler

    ACTION_IF FILE_EXISTS_IN_GAME ~%file%.are~ BEGIN
        COPY_EXISTING ~%file%.are~ override
        PATCH_IF (%SOURCE_SIZE% > 0xd4) BEGIN
        READ_LONG 0x70 cont_off
        READ_SHORT 0x74 cont_nb
        script_added = 0
            FOR (i = 0 ; i < cont_nb ; ++i) BEGIN
                READ_ASCII cont_off + (0x3c + (i * 0xc0)) ~contscript~
                PATCH_PRINT ~container script is %contscript%~

                    PATCH_IF ~%contscript%~ STRING_EQUAL_CASE ~None~ BEGIN // search if no script is already in place
                            PATCH_IF script_added = 0 BEGIN
                                WRITE_EVALUATED_ASCII cont_off + (0x3c + (i * 0xc0)) ~ACT02~ #8 // add script trap alarm
                                SPRINT ~contscript~ ~%file%~
                                script_added += 1
                            END
                    END
            END
        END
        BUT_ONLY
    END

I don't understand how to evaluate correctly the script type (which should be "none" in that case) in the container offset. The Patch_Print command show me wrong numbers, so i know i'm not looking at the right place, but i've tried to look into others code, but with no results so far. If someone could help me understand what's wrong here, i would gladly appreciate it :)

Link to comment

Just off the top of my head, I might guess that [ ~%contscript%~ STRING_EQUAL_CASE ~None~ ] might be failing, because it shows "none" in NI but has some other value when Weidu reads it. Maybe run an altered version of this on a known area and PATCH_PRINT the container script it finds.

Also, I'm not sure that "script_added" variable will work as written. Looks like it might only change one container script per area?

Link to comment

Offset to the script resref is incorrect. It is 0x48 instead of 0x3c (IESDP info). I would also suggest to add the "NULL" argument to READ_ASCII, so that trailing \0 characters are skipped.

As subtledoctor mentioned, don't compare the script with "None". This is only a symbolic placeholder in NI to indicate that the script field is empty. Use an empty string instead.

Link to comment
Posted (edited)

It worked like a charm, thanks to you both. Here's the code as a reference for others:

ACTION_IF FILE_EXISTS_IN_GAME ~%file%.are~ BEGIN
	COPY_EXISTING ~%file%.are~ override
	PATCH_IF (%SOURCE_SIZE% > 0xd4) BEGIN
	READ_LONG 0x70 cont_off
	READ_SHORT 0x74 cont_nb
		FOR (i = 0 ; i < cont_nb ; ++i) BEGIN
			READ_ASCII cont_off + (0x48 + (i * 0xc0)) ~contscript~ ELSE 0
			PATCH_PRINT ~container script is %contscript%~
				PATCH_IF ~%contscript%~ STRING_EQUAL_CASE ~~ BEGIN // search if no script is already in place
					WRITE_EVALUATED_ASCII cont_off + (0x48 + (i * 0xc0)) ~ACT02~ #8 // add script trap alarm
				END
		END
	END
	BUT_ONLY
END

 

Edited by ptifab
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...