WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
90 stars 20 forks source link

Adding an actor using fj_are_structure causes a read out-of-bounds error. #241

Closed LCA-EET closed 5 months ago

LCA-EET commented 6 months ago

Hi,

I'm working on a mod that involves copying and extending a BG1 area, AR0608. I'm trying to add two new actors to the area using fj_are_structure. I'm able to add one without issue, but when I try adding the second, I get an out of bounds error. It's strange because I've used this approach on other BG1 areas without issue.

The code from my .tph file and the error message are provided below. A copy of the .are file is attached.

COPY ~%MOD_FOLDER%/rbg/are/ar0608.are~ ~override~ LPF fj_are_structure INT_VAR fj_loc_x = 380 fj_loc_y = 309 fj_orientation = 4 // W STR_VAR fj_structure_type = actor fj_name = Kent fj_cre_resref = xakent END LPF fj_are_structure INT_VAR fj_loc_x = 233 fj_loc_y = 399 fj_orientation = 11 // ENE STR_VAR fj_structure_type = actor fj_name = Nederlok fj_cre_resref = xanederl END

Error Text ERROR: illegal 228-byte read from offset 2144 of 2144-byte file LCA/rbg/are/ar0608.are ERROR: [LCA/rbg/are/ar0608.are] -> [override/ar0608.are] Patching Failed (COPY) (Failure("LCA/rbg/are/ar0608.are: read out of bounds"))

I don't believe its a .cre issue, as I'm able add any .cre as an actor so long as only one actor is added. It's the addition of the second actor using fj_are_strcture that is causing the issue. I've tried doing another copy and modification of the area modified after the first actor addition, but I received the same error. AR0608.zip Any insight would be appreciated, thanks.

FredrikLindgren commented 6 months ago

I would guess there is some unexpected quirk to the ARE file that causes fj_are_structure to create a patched ARE that may be technically valid, but sets subsequent patches up to fail. I'll look into it.

LCA-EET commented 6 months ago

No rush, thanks. I appreciate it.

From: Fredrik Lindgren @.> Sent: Tuesday, May 14, 2024 7:18 PM To: WeiDUorg/weidu @.> Cc: LCAMod @.>; Author @.> Subject: Re: [WeiDUorg/weidu] Adding an actor using fj_are_structure causes a read out-of-bounds error. (Issue #241)

I would guess there is some unexpected quirk to the ARE file that causes fj_are_structure to create a patched ARE that may be technically valid, but sets subsequent patches up to fail. I'll look into it.

— Reply to this email directly, view it on GitHubhttps://github.com/WeiDUorg/weidu/issues/241#issuecomment-2111313751, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A66L7WM4OHN753GXOMFOJTLZCKLRXAVCNFSM6AAAAABHQ2THW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJRGMYTGNZVGE. You are receiving this because you authored the thread.Message ID: @.**@.>>

Argent77 commented 6 months ago

The attached ARE file does not contain a Rest Encounter structure. Offset to that structure is initially 0x0 which apparently instructs "fj_are_structure" to ignore it in the first function call.

After the first actor is added the Rest Encounter offset is updated with a nonzero value which seems to trigger the error in the second function call.

LCA-EET commented 6 months ago

Thanks for looking into it. To reset the rest encounter offset back to zero, I added the following line between the two calls to fj_are_structure.

WRITE_LONG 0xC0 0 // Rest Encounter Offset Bug Fix

This fixed the problem. Thanks again for the help.

From: Argent77 @.> Sent: Wednesday, May 15, 2024 4:30 AM To: WeiDUorg/weidu @.> Cc: LCAMod @.>; Author @.> Subject: Re: [WeiDUorg/weidu] Adding an actor using fj_are_structure causes a read out-of-bounds error. (Issue #241)

The attached ARE file does not contain a Rest Encounter structure. Offset to that structure is initially 0x0 which apparently instructs "fj_are_structure" to ignore it in the first function call.

After the first actor is added the Rest Encounter offset is updated with a nonzero value which seems to trigger the error in the second function call.

— Reply to this email directly, view it on GitHubhttps://github.com/WeiDUorg/weidu/issues/241#issuecomment-2111891018, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A66L7WOC6SWI3VMCRC6YEYDZCMMH5AVCNFSM6AAAAABHQ2THW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJRHA4TCMBRHA. You are receiving this because you authored the thread.Message ID: @.**@.>>

Roberciiik commented 6 months ago

Potentially a proper fix would be to add an empty Rest Encounter section, so each following area change would not generate such issue again.

Argent77 commented 6 months ago

Potentially a proper fix would be to add an empty Rest Encounter section, so each following area change would not generate such issue again.

I would suggest that too. An ARE file can be considered malformed if it lacks Song and Rest Encounter structures since these cannot be automatically detected under all circumstances.

LCA-EET commented 6 months ago

Adding a call to fj_are_structure to include a disabled rest interrupt (before the calls to add the creatures to the area) did the trick. Thanks for the suggestion.

From: Argent77 @.> Sent: Wednesday, May 15, 2024 7:21 AM To: WeiDUorg/weidu @.> Cc: LCAMod @.>; Author @.> Subject: Re: [WeiDUorg/weidu] Adding an actor using fj_are_structure causes a read out-of-bounds error. (Issue #241)

Potentially a proper fix would be to add an empty Rest Encounter section, so each following area change would not generate such issue again.

I would suggest that too. An ARE file can be considered malformed if it lacks Song and Rest Encounter structures since these cannot be automatically detected under all circumstances.

— Reply to this email directly, view it on GitHubhttps://github.com/WeiDUorg/weidu/issues/241#issuecomment-2112258560, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A66L7WIBSOL7255RNCBXMBDZCNALPAVCNFSM6AAAAABHQ2THW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJSGI2TQNJWGA. You are receiving this because you authored the thread.Message ID: @.**@.>>