NickHugi / PyKotor

A Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Missing support `AddStructToGFFList` (see `test_gff_add_inside_list` in `test_reader.py`) #9

Closed th3w1zard1 closed 12 months ago

th3w1zard1 commented 1 year ago

See the test test_gff_add_inside_list for why this is broken. https://github.com/NickHugi/PyKotor/blob/master/tests/tslpatcher/test_reader.py

Logs:

Note: Patching drdparts.dlg in the \override\ folder.
Note: apply in ModifyFieldGFF: add value({1: '725'}, 2)
Note: apply in ModifyFieldGFF: add value({1: '725'}, 2)

relevant changes.ini snippet:

[GFFList]
File1=drdparts.dlg
[drdparts.dlg]
AddField0=gff_drdparts_EntryList_14_0
AddField1=gff_drdparts_EntriesList_2_0
AddField2=gff_drdparts_ReplyList_11_0
ReplyList\7\EntriesList\0\ParamStrA=HK_REPAIR_STATE
ReplyList\7\EntriesList\0\Index=2DAMEMORY2
...omitted for brevity...
ReplyList\7\EntriesList\1\ParamStrA=000_HK_Total_Parts
[gff_drdparts_EntryList_14_0]
FieldType=Struct
Path=EntryList
Label=
TypeId=14
AddField0=gff_drdparts_Speaker_0
...omitted for brevity...
AddField42=gff_drdparts_RecordNoVOOverri_0
2DAMEMORY2=ListIndex

The issue is due to a lack of support for the syntax 2DAMEMORY2=ListIndex and then referencing the value 2DAMEMORY2 later in the GFFList. The problem is caused by missing support for adding structs to GFF lists. The struct is never added, therefore it can never be found in patcher memory, thus the KeyError.

I've noticed the mod Visually Repair HK-47 is one of the only ones to have this error.

Error message: image

th3w1zard1 commented 1 year ago

Perhaps this needs the bug label instead of enhancement as you already have code that should support it?

th3w1zard1 commented 1 year ago

Looking into this further I've found this original post by Stoffe on how the syntax works: http://web.archive.org/web/20150911133933/http://www.lucasforums.com/showpost.php?p=2135535&postcount=177

th3w1zard1 commented 1 year ago

I've finally figured out the problem here. The problem is missing support for adding a struct into a GFF list. See this code from the test_reader_nodiff.py

            [GFFList]
            File0=test.gff

            [test.gff]
            AddField0=add_list

            [add_list]
            FieldType=List
            CustomPath=
            Label=SomeList
            AddField0=add_insidelist

            [add_insidelist]
            FieldType=Struct
            Label=
            TypeId=111
            2DAMEMORY5=ListIndex

https://github.com/NickHugi/PyKotor/blob/master/tests/tslpatcher/test_reader.py

th3w1zard1 commented 1 year ago

Fixed by #18