dexyfex / CodeWalker

https://www.gta5-mods.com/tools/codewalker-gtav-interactive-3d-map
453 stars 202 forks source link

fix: YMAPs truncated to 256 entities #223

Closed dukeofsussex closed 2 weeks ago

dukeofsussex commented 8 months ago

When exporting and reimporting bkr_id1_rd_long_0.ymap, I noticed that the entity list gets truncated to 256 entities. Debugging the meta datablocks revealed the following:

[0] {CMapData: 1342184032 (512)}
[1] {CEntityDef: 1342193664 (16384)}
[2] {CEntityDef: 1342210048 (16384)}
[3] {CLightAttrDef: 1342226432 (960)}
[4] {CExtensionDefLightEffect: 1342227392 (96)}
[5] {7: 1342227488 (2608)}
[6] {CEntityDef: 1342230096 (8448)}
[7] {74: 1342238544 (64)}

The original code assumes all datablocks of the same meta type are grouped/sorted, so only the first two datablocks were used (128 entities per block).

dexyfex commented 7 months ago

I think this is the wrong approach to solving this problem. The problem really is that the YmapFile and related code is treating the entities array as a contiguous block of structures, when it should be treating it as an array of structure pointers - so basically the current way it's reading entities in YmapFile is completely wrong. MetaTypes.GetTypedDataArray should definitely not be used for this, and really the whole concept of that function is flawed anyway (it should probably be deleted). The correct approach to solving this issue would be to get YmapFile to actually read the entity pointers, instead of just trying to read all CEntityDef structures that might be in the file.

dukeofsussex commented 7 months ago

It wouldn't surprise me in the slightest if I chose the wrong way to fix this issue, but it has been a functional one for me, so I thought I'd share it either way, at the very least to raise awareness that this bug exists.

dexyfex commented 2 weeks ago

Manually merged equivalent changes