Jump to content

Scanning for containers and patching them


Recommended Posts

I need to go through areas, check their containers and, if some flags are set and not set and the "Key" field is empty, enter something in that field. The first part I know how to do, on the monkey-see-monkey-do level, thanks to Luke...

COPY_EXISTING_REGEXP GLOB ~.*\.ARE~ ~override~

PATCH_IF (SOURCE_SIZE > 228) THEN BEGIN

GET_OFFSET_ARRAY "containers" ARE_V10_CONTAINERS
PHP_EACH "containers" AS "ind" => "cont_offset" BEGIN

...

I know how to go about changing all containers or, say, all items in them. But now it comes to reading container flags and the Key field, and I can't do that without knowing their offsets. If I could find out, I would do for all containers something like this for the first:

READ_LONG 0x4AC flags
    
PATCH_IF ((flags & BIT0) == BIT0) & ((flags & BIT2) != BIT2) THEN BEGIN

Then a check for an empty Key field, and after that - to write into that field. Can someone tell me for a big sapphire how to get those offsets? The opposite approach is to use LPF ALTER_AREA_CONTAINER, where I probably don't even need to know the required STR_VAR container_name, if I use INT_VAR silent = 1. I could just make an enormous list beyond the number of containers any area has and shoot in the dark. But even here I would need to know about the flags and the Key field content before patching, or it would be like shooting in the dark with Confucius.

Link to comment
18 hours ago, temnix said:

But now it comes to reading container flags and the Key field, and I can't do that without knowing their offsets

You know the offset, it's "%cont_offset%". So:

COPY_EXISTING_REGEXP GLOB ~.*\.ARE~ ~override~
	PATCH_IF (SOURCE_SIZE > 228) THEN BEGIN
		GET_OFFSET_ARRAY "containers" ARE_V10_CONTAINERS
		PHP_EACH "containers" AS "ind" => "cont_offset" BEGIN
			READ_LONG ("%cont_offset%" + 0x28) "flags"
  			READ_ASCII ("%cont_offset%" + 0x78) "key_item"

 

Link to comment

This is right. Thanks. But where do you get the hex intervals between offsets? I can find out what they are in bytes from the resource file, but people around here seem to have an uncanny ability to count in hexadecimal off the top of their heads. You are all cyborgs, most likely... But helpful sometimes.

Link to comment
Posted (edited)
21 hours ago, temnix said:

This is right. Thanks. But where do you get the hex intervals between offsets? I can find out what they are in bytes from the resource file, but people around here seem to have an uncanny ability to count in hexadecimal off the top of their heads.

The following instruction

GET_OFFSET_ARRAY "containers" ARE_V10_CONTAINERS

collects all containers' info (i.e., offset, hex intervals between offsets, iterations, and so forth) into the array "containers". Let us consider "AR0016.ARE" as an example. The following code

COPY_EXISTING - ~AR0016.ARE~ ~override~
	PATCH_IF (SOURCE_SIZE > 228) THEN BEGIN
		GET_OFFSET_ARRAY "containers" ARE_V10_CONTAINERS
		PHP_EACH "containers" AS "ind" => "cont_offset" BEGIN
			PATCH_PRINT "%ind% => %cont_offset%"
		END
	END
BUT_ONLY

will print "current container index => current container offset". In this case:

0 => 1876

1 => 2068

As you can see, there's no need to compute those values manually (from the resource file). PHP_EACH loops through all containers and at each iteration "%cont_offset%" contains the current container offset.

Anyway, more info here and here.

Edited by Luke
Link to comment

That's more detailed than I care to read. I prefer making mods to that great science. My point is, you still need to count the bytes between the offset for the container name (start) and the one for whether it's locked or its key field. PHP_EACH writes there automatically for all containers, but you have to tell it to do it 20 bytes to the right or 55 bytes to the right of the main value, and I'm mystified how people count from 0x12C to 0x5AE with ease. This is not important, however.  

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...