Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Item proto converter made by PACIFICADOR.
- -- It converts client's item_proto (*.xml) to server's item_proto (item_proto and item_names (*.txt) or item_proto.sql)
- -- To prevent copyright's change
- local by,ver = "PACIFICADOR","1.5"
- function _error(t)
- if t ~= nil then
- print("\nAn error occurred.\nHint: "..t)
- end
- print("\nPress Enter to exit...")
- io.stdin:read('*l')
- end
- dat = io.open("ItemData.lua", "r")
- if not dat then
- _error("Could not find ItemData.lua")
- return
- end
- dat:close()
- require "itemdata" -- item's lib
- require "os"
- print("\nItem proto converter made by "..by..". Version "..ver.."\nContact the creator of this software if you have any issue.\n")
- io.write("Do you want to convert it to *.txt or *.sql?\n")
- io.flush()
- answ = io.read()
- toTxt, toSQL = answ == "txt", answ == "sql"
- if not toTxt and not toSQL then
- _error("You can only choose between 'txt' or 'sql'.")
- return
- end
- output = toTxt and io.open("output/item_names.txt","w") or io.open("output/item_proto.sql","w")
- linetab, TimStr, isTimArchiver, LocalizedName, name = {}, {"Tim N","\t<ItemDef%s"}, false, "gb2312Name", "name"
- if not output then
- os.execute("mkdir output")
- output = toSQL and "item_proto.sql" or "item_names.txt"
- io.open("output/"..output, "w")
- end
- dmp = io.open("item_proto_dump.xml")
- if not dmp then
- _error("Could not find item_proto_dump.xml.")
- return
- end
- print("\nReading item_proto_dump.xml...")
- for line in dmp:lines() do
- if not string.find(line, "</") then
- name = string.find(line, "hashName") and "hashName" or name
- LocalizedName = (string.find(line, "LocalizedName") and "LocalizedName") or (string.find(line, "gb2312name") and "gb2312Name") or "name"
- -- Tim's Archiver
- for i = 1, 2 do
- if string.find(line, TimStr[i]) then
- line = string.gsub(line, TimStr[i], "")
- isTimArchiver = true
- break
- end
- end
- -- Nexus Extractor (Mr. Lucifer)
- elseif string.find(line, '<!--AddonType="0"-->') or string.find(line, '<!--AddonType="99"-->') then
- line = string.gsub(string.gsub(line, '\t<!--AddonType="99"-->', ''), '\t<!--AddonType="0"-->', '')
- end
- line = string.gsub(string.gsub(line, string.find(line, "<Item%s") and "\t<Item%s" or "\t<ItemDef%s", ""), '"%s', '"ENTER')
- if isTimArchiver then
- TimArchiverTables = {"Name","Type","SubType","Weight","Size","AntiFlags","Flags","WearFlags","ImmuneFlags","Gold","ShopBuyPrice","LimitType0","LimitValue0","LimitType1","LimitValue1","ApplyType0","ApplyValue0","ApplyType1","ApplyValue1","ApplyType2","ApplyValue2","Value0","Value1","Value2","Value3","Value4","Value5","Socket0","Socket1","Socket2","RefinedVnum","RefineSet","AlterToMagicItemPercent","Specular","GainSocketPercent"}
- for i = 1, #TimArchiverTables do
- if string.find(line, '"ENTER'..TimArchiverTables[i]) then
- local main = {["AntiFlags"] = "antiflag", ["Flags"] = "Flag", ["WearFlags"] = "wearflag", ["ImmuneFlags"] = "immuneflag", ["AlterToMagicItemPercent"] = "magic_pct",["GainSocketPercent"] = "socket_pct",["RefinedVnum"] = "refine_vnum",["RefineSet"] = "refine_set", ["ShopBuyPrice"] = "buy_price"}
- line = string.gsub(line, '"ENTER'..TimArchiverTables[i], '"ENTER'..(main[TimArchiverTables[i]] == nil and string.lower(TimArchiverTables[i]) or main[TimArchiverTables[i]]))
- end
- end
- else
- if string.find(line, "vnum", 1, 5) then
- line = string.gsub(string.gsub(line, "vnum", "Vnum", 1, 5), '"ENTERflag', '"ENTERFlag')
- end
- end
- line = string.gsub(line, "subtype", "subType")
- if string.find(line, string.lower(LocalizedName)) then
- line = string.gsub(line, string.lower(LocalizedName), LocalizedName)
- end
- table.insert(linetab, line)
- end
- dmp:close()
- -- Separates a string in X parts (returns a table)
- -- Taken from Lua.org
- function string:split(inSplitPattern, outResults)
- if not outResults then
- outResults = {}
- end
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- while theSplitStart do
- table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
- theStart = theSplitEnd + 1
- theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- end
- table.insert( outResults, string.sub( self, theStart ) )
- return outResults
- end
- -- Used to get the value or string of each item_proto table
- function get(line, w)
- local a, res = string.split(line, '"ENTER'),0
- for i = 1, #a do
- if string.find(a[i], w.."=") then
- res = string.gsub(string.split(a[i], w.."=")[2], '"', '')
- end
- end
- return res
- end
- -- Used to get the value of each item_proto flag table (except immuneflag)
- function getf(value, w)
- tmp = io.open("output/temp.txt", "w")
- for i = 22, 0, -1 do
- pot = 2^i
- toWrite = {["antiflag"] = data.antiflag[pot],["flag"] = data.flag[pot],["wearflag"] = data.wearflag[pot]}
- if pot == value then
- tmp:write(toWrite[w])
- break
- elseif pot < value then
- tmp:write(toWrite[w].." | ")
- value = value - pot
- end
- end
- tmp:close()
- tmp = io.open("output/temp.txt", "r")
- out = tmp:read("*l")
- tmp:close()
- return out
- end
- -- Not really necessary, used for short if-statements
- function isnil(k) return k == nil end
- -- Used to get if a weapon has SD and MD
- function get_addon_type(vnum)
- local ret = 0
- if #data.addon_type_items == 0 then return 0 end
- for i = 1, #data.addon_type_items,2 do
- if tonumber(vnum) >= data.addon_type_items[i] and tonumber(vnum) <= data.addon_type_items[i+1] then
- ret = -1
- break
- end
- end
- return ret
- end
- print("\nAttempt to convert "..#linetab.." lines. This may take a few seconds.\nPlease wait...\n")
- conv,skp = 0, 0 -- Used to count the succesfuly/ignored converted lines
- -- Creates item_names.txt archive and writes it's content
- if toTxt then
- for _,v in pairs(linetab) do
- if get(v,"Vnum") ~= 0 and get(v, LocalizedName) ~= 0 then
- output:write(get(v, "Vnum").."\t"..get(v, LocalizedName).."\n")
- end
- end
- output:close()
- output = io.open("output/item_proto.txt", "w")
- end
- -- Creates item_proto.txt/.sql archive and writes it's content
- for _,v in pairs(linetab) do
- if get(v,"Vnum") ~= 0 and get(v, name) ~= 0 then
- for i = 1, 10 do
- local str = tostring(4294967280+i)
- if string.find(v, str) then
- v = string.gsub(v, str, tostring(-4294967296+4294967280+i))
- end
- end
- if toSQL then
- local function hexstr(str) return (string.gsub(str, "(.)", function(s) return string.format("%02X%s", string.byte(s), "") end)) end
- -- (vnum,name,locale_name,type,subtype,weight,size,antiflag,flag,wearflag,immuneflag,gold,shop_buy_price,refined_vnum,refine_set,magic_pct,limittype0,limitvalue0,limittype1,limitvalue1,applytype0,applyvalue0,applytype1,applyvalue1,applytype2,applyvalue2,value0,value1,value2,value3,value4,value5,socket0,socket1,socket2,socket3,socket4,socket5,specular,socket_pct,addon_type)
- output:write("INSERT INTO `item_proto` VALUES('"..get(v, "Vnum").."',0x"..hexstr(get(v, name))..",0x"..hexstr(get(v,LocalizedName))..",'"..get(v, "type").."','"..get(v, "subType").."','"..get(v,"weight").."','"..get(v, "size").."','"..get(v, "antiflag").."','"..get(v, "Flag").."','"..get(v, "wearflag").."','0','"..get(v, "gold").."','"..get(v, "buy_price").."','"..get(v, "refine_vnum").."','"..get(v, "refine_set").."','"..get(v, "magic_pct").."','"..get(v,"limittype0").."','"..get(v,"limitvalue0").."','"..get(v,"limittype1").."','"..get(v,"limitvalue1").."','"..get(v,"applytype0").."','"..get(v,"applyvalue0").."','"..get(v,"applytype1").."','"..get(v,"applyvalue1").."','"..get(v,"applytype2").."','"..get(v,"applyvalue2").."','"..get(v,"value0").."','"..get(v,"value1").."','"..get(v,"value2").."','"..get(v,"value3").."','"..get(v,"value4").."','"..get(v,"value5").."','-1','-1','-1','-1','-1','-1','"..get(v,"specular").."','"..get(v,"socket_pct").."','"..get_addon_type(get(v,"Vnum")).."');\n")
- elseif toTxt then
- output:write(get(v, "Vnum").."\t"..get(v, name).."\t"..data.type[tonumber(get(v, "type"))+1].."\t"..(isnil(data.subtype[tonumber(get(v, "type"))]) and 0 or data.subtype[tonumber(get(v, "type"))][tonumber(get(v, "subType"))+1]).."\t"..tonumber(get(v, "size")).."\t"..(isnil(getf(tonumber(get(v, "antiflag")), "antiflag")) and "NONE" or getf(tonumber(get(v, "antiflag")), "antiflag")).."\t"..(isnil(getf(tonumber(get(v, "Flag")), "flag")) and "NONE" or getf(tonumber(get(v, "Flag")), "flag")).."\t"..(isnil(getf(tonumber(get(v, "wearflag")), "wearflag")) and "NONE" or getf(tonumber(get(v, "wearflag")), "wearflag")).."\tNONE\t"..get(v, "gold").."\t"..get(v, "buy_price").."\t"..get(v, "refine_vnum").."\t"..get(v, "refine_set").."\t"..get(v, "magic_pct").."\t"..data.limittype[tonumber(get(v,"limittype0"))+1].."\t"..get(v,"limitvalue0").."\t"..data.limittype[tonumber(get(v,"limittype1"))+1].."\t"..get(v,"limitvalue1").."\t"..data.applytype[tonumber(get(v,"applytype0"))+1].."\t"..get(v,"applyvalue0").."\t"..data.applytype[tonumber(get(v,"applytype1"))+1].."\t"..get(v,"applyvalue1").."\t"..data.applytype[tonumber(get(v,"applytype2"))+1].."\t"..get(v,"applyvalue2").."\t"..get(v,"value0").."\t"..get(v,"value1").."\t"..get(v,"value2").."\t"..get(v,"value3").."\t"..get(v,"value4").."\t"..get(v,"value5").."\t"..get(v,"specular").."\t"..get(v,"socket_pct").."\t"..get_addon_type(get(v,"Vnum")).."\n")
- end
- conv = conv+1
- else skp = skp+1 end
- end
- os.remove("output/temp.txt")
- print("\n"..conv.."/"..#linetab.." lines have been converted succesfuly.")
- print(skp.."/"..#linetab.." lines have been ignored.")
- output:close()
- _error()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement