1 QuestHelper_File
["db_get.lua"] = "Development Version"
2 QuestHelper_Loadtime
["db_get.lua"] = GetTime()
4 local dev_mode
= (QuestHelper_File
["db_get.lua"] == "Development Version")
10 local QHDB = QHDB_temp]]
11 QuestHelper
: Assert(dev_mode
or #QHDB
== 4)
13 local weak_v
= { __mode
= 'v' }
14 local weak_k
= { __mode
= 'k' }
18 local frequencies
= setmetatable({}, weak_k
)
20 -- guhhh just want this to work
21 local freq_group
= setmetatable({}, weak_k
)
22 local freq_id
= setmetatable({}, weak_k
)
24 local function DBC_Get(group
, id
)
25 if not cache
[group
] then return end
26 return cache
[group
][id
]
29 local function DBC_Put(group
, id
, item
)
30 if not cache
[group
] then cache
[group
] = setmetatable({}, weak_v
) end
31 QuestHelper
: Assert(not cache
[group
][id
])
32 cache
[group
][id
] = item
34 --DB_how_many_are_used()
37 local function mark(tab
, tomark
)
38 for k
, v
in pairs(tab
) do
39 if k
~= "__owner" and type(v
) == "table" then
46 local function read_adaptint(data
, offset
)
50 local v
= strbyte(data
, offset
)
51 QuestHelper
: Assert(v
, string.format("%d %d", #data
, offset
))
52 stx
= stx
+ acu
* math
.floor(v
/ 2)
55 if mod(v
, 2) == 0 then break end
60 local function search_index(index
, data
, item
)
63 Itemid (0 for endnode)
69 assert(index
and type(index
) == "string")
70 assert(data
and type(data
) == "string")
73 local idx
, ofs
, len
, rlink
74 idx
, cofs
= read_adaptint(index
, cofs
)
75 if idx
== 0 then return end
76 ofs
, cofs
= read_adaptint(index
, cofs
)
77 len
, cofs
= read_adaptint(index
, cofs
)
78 rlink
, cofs
= read_adaptint(index
, cofs
)
81 return strsub(data
, ofs
, ofs
+ len
)
84 if idx
< item
then cofs
= cofs
+ rlink
end
90 QuestHelper
: Assert(not initted
)
91 for _
, db
in ipairs(QHDB
) do
92 for _
, v
in pairs(db
) do
93 --print("db", not not v.__dictionary, not not v.__tokens)
94 if v
.__dictionary
and v
.__tokens
then
95 local redictix
= v
.__dictionary
96 if not redictix
:find("\"") then redictix
= redictix
.. "\"" end
97 if not redictix
:find(",") then redictix
= redictix
.. "," end
98 if not redictix
:find("\\") then redictix
= redictix
.. "\\" end
99 local tokens
= loadstring("return {" .. QH_LZW_Decompress_Dicts_Arghhacky(v
.__tokens
, redictix
) .. "}")()
100 QuestHelper
: Assert(tokens
)
102 local _
, _
, prep
= QH_LZW_Prepare_Arghhacky(v
.__dictionary
, tokens
)
103 QuestHelper
: Assert(prep
)
105 QuestHelper
: Assert(type(prep
) == "table")
112 QH_UpdateQuests() -- just in case it's been waiting on us (it has almost certainly been waiting on us)
119 function DB_GetItem(group
, id
, silent
, register
)
120 QuestHelper
: Assert(initted
)
122 QuestHelper
: Assert(group
, string.format("%s %s", tostring(group
), tostring(id
)))
123 QuestHelper
: Assert(id
, string.format("%s %s", tostring(group
), tostring(id
)))
124 local ite
= DBC_Get(group
, id
)
126 if type(id
) == "string" then QuestHelper
: Assert(not id
:match("__.*")) end
128 --QuestHelper:TextOut(string.format("%s %d", group, id))
130 for _
, db
in ipairs(QHDB
) do
131 --print(db, db[group], db[group] and db[group][id], type(group), type(id))
133 if not ite
then ite
= QuestHelper
:CreateTable("db") end
136 if db
[group
][id
] then
140 --print(not dat, type(id), id, not not db[group].__serialize_index, not not db[group].__serialize_index)
141 if not dat
and type(id
) == "number" and id
> 0 and db
[group
].__serialize_index
and db
[group
].__serialize_data
then
142 dat
= search_index(db
[group
].__serialize_index
, db
[group
].__serialize_data
, id
)
148 if type(dat
) == "string" then
149 QuestHelper
: Assert(db
[group
].__tokens
== nil or type(db
[group
].__tokens
) == "table")
150 srctab
= loadstring("return {" .. (db
[group
].__prefix
or "") .. QH_LZW_Decompress_Dicts_Prepared_Arghhacky(dat
, db
[group
].__dictionary
, nil, db
[group
].__tokens
) .. (db
[group
].__suffix
or "") .. "}")()
151 elseif type(dat
) == "table" then
154 QuestHelper
: Assert()
157 for k
, v
in pairs(srctab
) do
158 QuestHelper
: Assert(not ite
[k
] or k
== "used")
167 --print("marking", group, id, silent, register)
169 --print("done marking")
171 DBC_Put(group
, id
, ite
)
173 freq_group
[ite
] = group
177 QuestHelper
:TextOut(string.format("Tried to get %s/%s, failed", tostring(group
), tostring(id
)))
183 frequencies
[ite
] = (frequencies
[ite
] or 0) + (register
and 1 or 1000000000) -- effectively infinity
189 local function incinerate(ite
, crunchy
)
190 if dev_mode
then return end -- wellllp
192 if not crunchy
[ite
] then
195 for k
, v
in pairs(ite
) do
196 if type(k
) == "table" then incinerate(k
, crunchy
) end
197 if type(v
) == "table" then incinerate(v
, crunchy
) end
202 function DB_ReleaseItem(ite
)
203 QuestHelper
: Assert(ite
)
204 frequencies
[ite
] = frequencies
[ite
] - 1
206 if frequencies
[ite
] == 0 then
207 --print("incinerating", freq_group[ite], freq_id[ite])
208 cache
[freq_group
[ite]]
[freq_id
[ite]]
= nil
209 freq_group
[ite
] = nil
212 local incin
= QuestHelper
:CreateTable("incinerate")
213 incinerate(ite
, incin
)
214 for k
, _
in pairs(incin
) do
215 QuestHelper
:ReleaseTable(k
)
216 end -- burn baby burn
217 QuestHelper
:ReleaseTable(incin
)
221 function DB_ListItems(group
)
223 for _
, db
in ipairs(QHDB
) do
225 QuestHelper
: Assert(not db
.__serialize_index
and not db
.__serialize_data
)
226 for k
, _
in pairs(db
[group
]) do
227 if type(k
) ~= "string" or not k
:match("__.*") then
235 for k
, _
in pairs(tab
) do
242 function DB_how_many_are_used()
244 for k
, v
in pairs(cache
) do
245 for k2
, v2
in pairs(v
) do
252 function DB_DumpItems()
254 for k
, v
in pairs(freq_group
) do
255 dt
[string.format("%s/%s", freq_group
[k
], tostring(freq_id
[k
]))] = true