storge Posted May 5 Share Posted May 5 (edited) NB: This issue is not game breaking and does not seem to affect the stability of the game. NB2: This post contains a bugfix. (Scroll to the bottom for bugfix if tl;dr) Version: 41.78.16 Affects all game modes. (single/multiplayer) Reproduction steps: 1. save any game. Issue description: WorldDictionaryReadable.lua is currently not syntactically correct lua code and will error any code that attempts to load it: > -- in lua repl > worldDict = require("WorldDictionaryReadable") error loading module 'WorldDictionaryReadable' from file './WorldDictionaryReadable.lua': ./WorldDictionaryReadable.lua:20356: '}' expected (to close '{' at line 20355) near '=' stack traceback: [C]: in ? [C]: in function 'require' stdin:1: in main chunk [C]: in ? > dofile("WorldDictionaryReadable.lua") WorldDictionaryReadable.lua:20356: '}' expected (to close '{' at line 20355) near '=' stack traceback: [C]: in function 'dofile' stdin:1: in main chunk [C]: in ? This is due to the following generated section (e.g. from a save file of mine, note file continues before and after this section): --[[ ---- OBJECTS ---- --]] objects = { 0 = "American Holly", 1 = "Canadian Hemlock", 2 = "Virginia Pine", 3 = "Riverbirch", 4 = "Cockspur Hawthorn", 5 = "Dogwood", 6 = "Carolina Silverbell", 7 = "Yellowwood", 8 = "Eastern Redbud", 9 = "Redmaple", 10 = "American Linden", 11 = "Spicebush", 12 = "Ninebark", 13 = "Blueberry", 14 = "Blackberry", 15 = "Piedmont azalea", 16 = "Arrowwood viburnum", 17 = "Red chokeberry", 18 = "Beautyberry", 19 = "New jersey tea", 20 = "Wild hydrangea", 21 = "Shrubby St. John's wort", 22 = "Butterfly Weed", 23 = "Swamp Sunflower", 24 = "Purple Coneflower", 25 = "Joe-Pye Weed", 26 = "Blazing Star", 27 = "Wild Bergamot", 28 = "White Beard-tongue", 29 = "Ironweed", 30 = "White Baneberry", 31 = "Wild Columbine", 32 = "Jack-in-the-pulpit", 33 = "Wild Ginger", 34 = "Wild Geranium", 35 = "Alumroot", 36 = "Wild Blue Phlox", 37 = "Polemonium Reptans", 38 = "Foamflower", 39 = "Grass", 40 = "Generic", 41 = "Fern", 42 = "CrackGrass", 43 = "WallVines", 44 = "WallCracks", 45 = "Flowerbed", } Two things are wrong with this generated dump. The first, and minor issue which does not result in syntax errors, is that the generated table is 0-indexed and not 1-indexed which lua operates on. The second, and major issue, is that Number = Value syntax directly is not possible in lua. This is what's causing the loading errors. -- lua requires this syntax for numerical indexes, so the section should look like this: objects = { [1] = "American Holly", -- [...] [45] = "Flowerbed", } this file is generated by zombie.world.DictionaryData's saveAsText method. Debugging the related string information (https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-4.html#jvms-4.4.3) from the compiled class, one finds that the string being interpolated in this section of saveAsText's execution is: "\t\u0001 = \"\u0001\",\u0001" Which, when interpolated with a key of 0, a value of "American Holly" (without quotes), and a local system's newline (here we use "\n" for simplicity) would give an example of: "\t0 = \"American Holly\",\n" Which matches the currently syntactically erroneous lua file. It should be: "\t[\u0001] = \"\u0001\",\u0001" which with the above example interpolation would give "\t[0] = \"American Holly\",\n" Which, along with some further knowledge of Java's instruction set allows us to arrive at our solution: Fix (for the syntax errors): The following relevant code inferred from DictionaryData's saveAsText method: // zombie.world.DictionaryData // nb: variable names are ad hoc based on my notes and may not represent those in actual The Indie Store codebases public class DictionaryData { // [...] protected void saveAsText(String readableSaveFileName) throws IOException, WorldDictionaryException { // [...] // the foor loop is extrapolated based on my notes, // in decompiled code this would show as a while(hasNext) called on an iterator. // actual code may vary. for(object in objectIdToNameMap) { readableSaveWriter.write("\t" + object.getKey() + " = \"" + object.getValue() + "\"," + System.lineSeperator()); } // [...] } /* N.B. The instantiation of the readableSaveWriter variable (a java.io.FileWriter instance) * on a java.io.File (opened on the readableSaveFileName argument) is omitted for brevity, as are any related * try blocks or error handling, as that is beyond the scope of this report, and is all working perfectly well. */ Should be: // zombie.world.DictionaryData // nb: above comments in previous code-section apply, but are omitted for brevity public class DictionaryData { // [...] protected void saveAsText(String readableSaveFileName) throws IOException, WorldDictionaryException { // [...] for(object in objectIdToNameMap) { readableSaveWriter.write("\t[" + object.getKey() + "] = \"" + object.getValue() + "\"," + System.lineSeperator()); } // [...] } Edited May 5 by storge added that the context of the first code snippet is the current behavior of the code Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now