Jump to content

How to get every time in the game as a List of objects in Java?


Recommended Posts

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

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 by Bumber64
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

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.

  • Sanity 1
Link to comment
Share on other sites

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 by Leonidas IV
Link to comment
Share on other sites

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

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

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

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 by Bumber64
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...