Guthix / Jagex-Store-5

A library for modifying Jagex Store 5 game files
Apache License 2.0
28 stars 12 forks source link

Writing new groups not working #16

Closed Z-Kris closed 3 years ago

Z-Kris commented 3 years ago

Adding a brand-new group doesn't seem to actually write said group into the cache. The code used to write:

        if (serverOnlyCache) {
            val basGroup = runCatching { configArchive.readGroup(BaseAnimationSetConfig.id) }
                .getOrElse { Js5Group(BaseAnimationSetConfig.id, 0, 1) }
            ConfigArchive.configs.basConfigs.toSortedMap().forEach { (id, value) ->
                basGroup.files[id] = Js5File(id, null, value.encode(serverOnlyCache))
            }
            configArchive.writeGroup(basGroup, appendVersion = true)
        }
        cache.writeArchive(configArchive)

BaseAnimationSetConfig.id = 15 Number of files being encoded = 1

Edit: After some investigating, I've found out the issue to be the fact that it adds in the middle of the groups. The map behind the groups must be sorted for some reason, so adding this:

            val settings = configArchive.groupSettings.toSortedMap()
            configArchive.groupSettings.clear()
            settings.forEach { (key, value) -> configArchive.groupSettings[key] = value }

Right before the cache.writeArchive(configArchive) solved the issue.

The same issue applies for individual files. They must be sorted manually by the user, or else it corrupts the cache and writes the ids completely weird.