https://github.com/squeek502/lua-d2itemreader
Lua bindings for the d2itemreader library
https://github.com/squeek502/lua-d2itemreader
Last synced: 2 months ago
JSON representation
Lua bindings for the d2itemreader library
- Host: GitHub
- URL: https://github.com/squeek502/lua-d2itemreader
- Owner: squeek502
- License: unlicense
- Created: 2018-10-06T00:12:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-07T05:17:00.000Z (over 3 years ago)
- Last Synced: 2025-01-29T12:32:42.037Z (4 months ago)
- Language: C
- Size: 14.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lua-d2itemreader
================**work in progress**
Lua bindings to the [d2itemreader](https://github.com/squeek502/d2itemreader) library
## API Reference
### `d2itemreader.getfiletype(filepath)`
Returns the type of the file at `filepath`, or `nil, err` if the filetype cannot be determined. If the filetype can be determined, it will be returned as one of the following strings: `"character"`, `"item"`, `"atma"`, `"personal"`, `"shared"`### `d2itemreader.getitems(filepath)`
Returns an array-like table of items, or `nil, err` if there was an error reading the file. See [Item Format](#item-format) for the format of each item.### `d2itemreader.itemiterator(filepath)`
Returns an iterator for all items in the file. Items in the file are parsed while iterating, and are returned in `item, source` pairs. See [Item Format](#item-format) for the format of each item. Example usage:```lua
for item, source in d2itemreader.itemiterator('char.d2s') do
print(item.code .. ' in ' .. source.file)
end
```### `d2itemreader.loadfiles(filepaths)`
Load custom Diablo II .txt data files from disk at the filepaths given. `filepaths` should be a table of the format:```lua
{
armors = , -- path to Armor.txt
weapons = , -- path to Weapons.txt
miscs = , -- path to Misc.txt
itemstats = , -- path to ItemStatCost.txt
}
```### `d2itemreader.loaddata(databufs)`
Load custom Diablo II .txt data files from memory with the contents given. `databufs` should be a table of the format:```lua
{
armors = , -- contents of Armor.txt
weapons = , -- contents of Weapons.txt
miscs = , -- contents of Misc.txt
itemstats = , -- contents of ItemStatCost.txt
}
```### Item Format
```lua
-- Item
{
source = {
-- filepath containing the item
file = ,
-- section only exists for filetype "character",
-- will be one of "character", "corpse", "merc"
section = ,
-- page only exists for paginated filetypes
-- ("personal" or "shared")
page =
},identified = ,
socketed = ,
isNew = ,
isEar = ,
startItem = ,
simpleItem = ,
ethereal = ,
personalized = ,
isRuneword = ,
version = ,
locationID = ,
equippedID = ,
positionX = ,
positionY = ,
panelID = ,-- only exists if isEar is true
ear = {
classID = ,
level = ,
name =
},code = ,
socketedItems = {...} -- array-like table of items-- every key below only exists if simpleItem is false
id = , -- unique ID of the item in hexadecimal
level = ,
-- rarity is one of:
-- "unique", "set", "normal", "lowquality"
-- "superior", "magic", "crafted", "rare"
rarity = ,
-- rarityData is different depending on rarity, and
-- doesn't exist for "normal" rarity
rarityData = {
-- for "unique", "set", "lowquality", "superior" rarities
id = ,
-- for "magic" rarity
prefix = ,
suffix = ,
-- for "rare" or "crafted" rarities
name1 = ,
name2 = ,
prefixes = {...}, -- array-like table of prefix IDs (numbers)
suffixes = {...} -- array-like table of suffix IDs (numbers)
},
multiplePictures = ,
pictureID = ,
classSpecific = ,
automagicID = ,
-- only exists if personalized is true
personalizedName = ,
timestamp = ,
defenseRating = ,
maxDurability = ,
currentDurability = ,
quantity = ,
numSockets = ,
magicProperties = {...}, -- array-like table of magic properties (see 'Magic Property' below)
setBonuses = {...}, -- see 'Set Bonuses' below
runewordProperties = {...} -- array-like table of magic properties (see 'Magic Property' below)
}-- Magic Property
{
id = ,
params = {...} -- array-like table of parameter values (numbers)
}-- Set Bonuses
--
-- A table with keys 1-5 where each key may have a nil value. This means that it is
-- not guaranteed to be an array-like table (so ipairs and the # operator will not
-- always work, use `for i=1,5 do` to iterate instead)
--
-- Note: These are the green per-item set bonuses, not the overall set bonuses
{
-- Each non-nil value is an array-like table of magic properties (see 'Magic Property' above)
[1] = {...} or nil,
[2] = {...} or nil,
[3] = {...} or nil,
[4] = {...} or nil,
[5] = {...} or nil,
-- When the bonuses are active depends on the value of add_func in SetItems.txt
-- for the setID of the item:
--
-- If add_func=2, then it uses the number of items of the set that are worn:
-- - The property list at key 1 is active when >= 2 items of the set are worn.
-- - The property list at key 2 is active when >= 3 items of the set are worn.
-- - etc.
--
-- If add_func=1, then specific other items of the set need to be worn:
-- - If the item's setID is the first of the set:
-- + then the property list at key 1 is active when the second setID of the set is worn
-- + and the property list at key 2 is active when the third setID of the set is worn
-- + etc.
-- - If the item's setID is the second of the set:
-- + then the property list at key 1 is active when the first setID of the set is worn
-- + and the property list at key 2 is active when the third setID of the set is worn
-- + etc.
-- - etc.
}
```