DecDuck Posted April 14, 2022 Share Posted April 14, 2022 This may not belong here, but I don't know where else to put it. For my project here, I would like to have some way to import all the items in the game as an Item.java object. I don't need to import all the item components, just it's name and id (for recipe menus, starting inventory, etc...). Has anyone done this or something similar before, and how? Link to comment Share on other sites More sharing options...
Bumber64 Posted April 14, 2022 Share Posted April 14, 2022 (edited) Closest thing I've done is print stuff in CSV format to the game log so I could import data into a spreadsheet. The timestamps in the log needed trimming so I used Notepad++'s macro function to get rid of them. (Alternatives would be using a regex to ignore/replace them or just printing in a way that only has a timestamp on the very first line (e.g., single print statement,) if possible.) This may be impractical depending on how often you need to do it. Edited April 14, 2022 by Bumber64 Link to comment Share on other sites More sharing options...
DecDuck Posted April 15, 2022 Author Share Posted April 15, 2022 Ideally I would like a way to generate the list from the game files directly, instead of having a pre-build list. That is definitely an option though, if nothing else works out. Link to comment Share on other sites More sharing options...
CarlZalph Posted April 15, 2022 Share Posted April 15, 2022 7 hours ago, decduck3 said: Ideally I would like a way to generate the list from the game files directly, instead of having a pre-build list. That is definitely an option though, if nothing else works out. The problem you're going to have with parsing these files is that LUA is a highly mutable language, and some of the prefabs take this for granted when generating out new prefabs. Take a look at scripts/prefabs/chesspieces.lua for example: Quote local prefabname = materialid and ("chesspiece_"..PIECES[pieceid].name.."_"..MATERIALS[materialid].name) or ("chesspiece_"..PIECES[pieceid].name) return Prefab(prefabname, fn, assets, prefabs) A tokenizer won't be able to figure out what this is doing because it's missing key concepts in LUA's evaluation chain. Writing a sandbox to run the files and extract the information might be one route, binding LUA to Java, but I think that'll be painful trying to run the game's files without the engine. I'd think the easiest solution is to write a quick mod that generates your file for you with all of the game-context related goodies you want with it. 2 Link to comment Share on other sites More sharing options...
DecDuck Posted April 16, 2022 Author Share Posted April 16, 2022 I really would like a way to scrap the information at runtime without having the game running. Would it be possible to extract the information from the texture? Like get all the files in inventoryimages and then read the build names for each? Also with this approach would it be possible to get the localized names of the items. Maybe also import the speech files? Link to comment Share on other sites More sharing options...
CarlZalph Posted April 16, 2022 Share Posted April 16, 2022 2 hours ago, decduck3 said: I really would like a way to scrap the information at runtime without having the game running. Would it be possible to extract the information from the texture? Like get all the files in inventoryimages and then read the build names for each? Also with this approach would it be possible to get the localized names of the items. Maybe also import the speech files? If all of the art assets matched up with their prefab names and such, then yes. They don't unfortunately. See: "nightsword" prefab having "nightmaresword" bank+build and "nightsword.tex" inventory icon with the in-game name "Dark Sword". If all you're after is just the prefab name and a readable text with no component information, then you might be able to get away with parsing strings.lua's STRINGS.NAMES table. This and the speech files will present names for non-inventory items. I'm still recommending writing a quick mod to export out what you're after rather than trying to parse the LUA without using LUA. 1 Link to comment Share on other sites More sharing options...
DecDuck Posted April 17, 2022 Author Share Posted April 17, 2022 Yeah that may be an issue. With the mod, how would I get all the prefabs? Is there a place where they are all registered at once? Link to comment Share on other sites More sharing options...
DecDuck Posted April 17, 2022 Author Share Posted April 17, 2022 I've done a bit of research and apparently GLOBAL.Prefabs contains all the prefabs, however I don't know how trigger a loop to print the to the log. AddPrefabPostInit doesn't work according to this thread. Link to comment Share on other sites More sharing options...
Leonidas IV Posted April 17, 2022 Share Posted April 17, 2022 local prefabs = {} AddPrefabPostInitAny(function(inst) table.insert(prefabs, inst.prefab) end) I think this works for list them Link to comment Share on other sites More sharing options...
DecDuck Posted April 18, 2022 Author Share Posted April 18, 2022 Wouldn't this also get all prefabs like bosses, particle effects and other stuff? Link to comment Share on other sites More sharing options...
Bumber64 Posted April 18, 2022 Share Posted April 18, 2022 You'd need to check for an inventoryitem component to get just items. Link to comment Share on other sites More sharing options...
Leonidas IV Posted April 19, 2022 Share Posted April 19, 2022 (edited) I think PostInit don't runs in the env, so me previus solution don't work... Maybe this way: AddPrefabPostInitAny(function(inst) if inst and inst.components. and inst.components.inventoryitem then GLOBAL.nolineprint(inst.prefab) end end) nolineprint will help to parsing the log. Edited April 19, 2022 by Leonidas IV Link to comment Share on other sites More sharing options...
DecDuck Posted April 22, 2022 Author Share Posted April 22, 2022 This only runs when a prefab is instantiated, like when my character spawns in and has items in their inventory. To get the proper list, I'd have to instantiate an instance of every item, which I'd rather like to avoid. Link to comment Share on other sites More sharing options...
Bumber64 Posted April 23, 2022 Share Posted April 23, 2022 There's a list of all prefabs in "scripts/prefablist.lua" that says it was generated by "exportprefabs.lua". I can't find any such export script, but that's at least one list of all prefabs you can iterate. IDK if you can check for a prefab's components without spawning them. Link to comment Share on other sites More sharing options...
Friendly Grass Posted April 23, 2022 Share Posted April 23, 2022 10 hours ago, Bumber64 said: There's a list of all prefabs in "scripts/prefablist.lua" that says it was generated by "exportprefabs.lua". I can't find any such export script, but that's at least one list of all prefabs you can iterate. IDK if you can check for a prefab's components without spawning them. That's a list of files that return prefabs within the prefabs directory; not a list of prefabs. For example there is no "farm_plant_watermelon" on the list; just "farm_plants". The file prefabs/farm_plants.lua generates prefabs for every farm plant. As has been said you can get a list of prefab names with their in game names fairly easily by having a mod script run in game that loops through the Prefabs table. I would recommend writing to a new file which would show up in steamapps/common/Don't Starve Together/data. As CarlZarph also said if you don't want to have to open the game you can statically analyze strings.lua for the contents of STRINGS.NAMES (UPPERCASE_PREFABNAME = "In-Game Name") with some minor extra discrepancies. Getting a list of components for each prefab is unavoidably error prone because Prefabs aren't connected to components; components can be added and removed from entities dynamically. Link to comment Share on other sites More sharing options...
Bumber64 Posted April 24, 2022 Share Posted April 24, 2022 (edited) 16 hours ago, Friendly Grass said: Getting a list of components for each prefab is unavoidably error prone because Prefabs aren't connected to components; components can be added and removed from entities dynamically. The "inventoryitem" component isn't likely to be removed after init. The only obstacle is that init has to happen first, which probably requires spawning it in. OP wants a list of items, so non-items need to be filtered out somehow. If you want to parse the prefab files to determine that, you have to deal with the issue that there can be multiple prefabs per file, which might not all be items (see: fruitfly.lua.) Edited April 24, 2022 by Bumber64 Link to comment Share on other sites More sharing options...
DecDuck Posted May 4, 2022 Author Share Posted May 4, 2022 So maybe the best approach is the auto-generate a list then hand curate them to get the correct list. 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