<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>tekIDmemo.lua</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,15 +3,14 @@
 --      Locals      --
 ----------------------
 
-local L = setmetatable({}, {__index=function(t,i) return i end})
-local defaults, db = {}
+local db
 
 
 ------------------------------
 --      Util Functions      --
 ------------------------------
 
-local function Print(...) ChatFrame1:AddMessage(string.join(&quot; &quot;, &quot;|cFF33FF99Addon Template|r:&quot;, ...)) end
+local function Print(...) print(&quot;|cFF33FF99NutCounter|r:&quot;, ...) end
 
 local debugf = tekDebug and tekDebug:GetFrame(&quot;NutCounter&quot;)
 local function Debug(...) if debugf then debugf:AddMessage(string.join(&quot;, &quot;, tostringall(...))) end end
@@ -29,32 +28,105 @@ f:RegisterEvent(&quot;ADDON_LOADED&quot;)
 function f:ADDON_LOADED(event, addon)
 	if addon ~= &quot;NutCounter&quot; then return end
 
-	NutCounterDB = setmetatable(NutCounterDB or {min = {}, max = {}, last = {}}, {__index = defaults})
-	db = NutCounterDB
+	local dbkey = GetRealmName().. &quot; &quot;.. UnitFactionGroup(&quot;player&quot;)
 
-	-- Do anything you need to do after addon has loaded
+	NutCounterDB = NutCounterDB or {}
+	NutCounterDB[dbkey] = NutCounterDB[dbkey] or {min = {}, max = {}, last = {}, sold = {}, failed = {}}
+	db = NutCounterDB[dbkey]
 
-	LibStub(&quot;tekKonfig-AboutPanel&quot;).new(&quot;NutCounter&quot;, &quot;NutCounter&quot;) -- Remove first arg if no parent config panel
+	LibStub(&quot;tekKonfig-AboutPanel&quot;).new(nil, &quot;NutCounter&quot;)
+
+	self:RegisterEvent(&quot;MAIL_INBOX_UPDATE&quot;)
 
 	self:UnregisterEvent(&quot;ADDON_LOADED&quot;)
 	self.ADDON_LOADED = nil
+end
+
+
+local lastcount, lastitem, lastprice, cashingout, lastexpire
 
-	if IsLoggedIn() then self:PLAYER_LOGIN() else self:RegisterEvent(&quot;PLAYER_LOGIN&quot;) end
+local orig = AutoLootMailItem
+function AutoLootMailItem(i, ...)
+	Debug(&quot;AutoLootMailItem&quot;, i, ...)
+
+	local _, _, _, subject = GetInboxHeaderInfo(i)
+	if subject:match(&quot;^Auction expired:&quot;) then lastexpire = GetInboxItem(i, 1)
+	else cashingout = i end
+	return orig(i, ...)
 end
 
+function f:MAIL_INBOX_UPDATE()
+	local count = GetInboxNumItems()
+	Debug(&quot;MAIL_INBOX_UPDATE&quot;, count)
+
+	if cashingout then
+		local invoiceType, itemName, _, bid, buyout = GetInboxInvoiceInfo(cashingout)
+		Debug(&quot;Detected cashout&quot;, invoiceType, bid, buyout)
+		if invoiceType then
+			if invoiceType == &quot;seller&quot; then
+				lastitem, lastprice = itemName, buyout or bid
+			end
+			cashingout = nil
+		end
+	elseif lastexpire and lastcount and count == lastcount - 1 then
+		Debug(&quot;Detected expired mail removal&quot;, lastexpire)
+		db.failed[lastexpire] = (db.failed[lastexpire] or 0) + 1
+		lastexpire = nil
+	elseif lastprice and count == lastcount - 1 then
+		Debug(&quot;Detected mail removal&quot;, lastprice, lastitem)
+		db.min[lastitem] = math.min(lastprice, db.min[lastitem] or math.huge)
+		db.max[lastitem] = math.max(lastprice, db.max[lastitem] or 0)
+		db.last[lastitem] = lastprice
+		db.sold[lastitem] = (db.sold[lastitem] or 0) + 1
+		lastprice, lastitem = nil
+	end
+
+	lastcount = count
+end
 
-function f:PLAYER_LOGIN()
-	self:RegisterEvent(&quot;PLAYER_LOGOUT&quot;)
 
-	-- Do anything you need to do after the player has entered the world
+-----------------------------
+--      Tooltip stuff      --
+-----------------------------
+
+local function GS(cash)
+	if not cash then return end
+	cash = cash/100
+	local s = floor(cash%100)
+	local g = floor(cash/100)
+	if g &gt; 0 then return string.format(&quot;|cffffd700%d.|cffc7c7cf%02d&quot;, g, s)
+	else return string.format(&quot;|cffc7c7cf%d&quot;, s) end
+end
+
+
+local origs = {}
+local OnTooltipSetItem = function(frame, ...)
+	assert(frame, &quot;arg 1 is nil, someone isn't hooking correctly&quot;)
+
+	local name = frame:GetItem()
+	if name then
+		local min, max, last, sold, failed = db.min[name], db.max[name], db.last[name], db.sold[name], db.failed[name]
+		if min then frame:AddDoubleLine(&quot;Previous sales:&quot;, max and max ~= min and (GS(min)..&quot; - &quot;..GS(max)) or GS(min)) end
+		if last then frame:AddDoubleLine(&quot;Last sale:&quot;, GS(last)) end
+		if sold or failed then frame:AddDoubleLine(&quot;Sellthrough:&quot;, string.format(&quot;%d%%&quot;, (sold or 0)/((sold or 0) + (failed or 0))*100)) end
+	end
+
+	if origs[frame] then return origs[frame](frame, ...) end
+end
 
-	self:UnregisterEvent(&quot;PLAYER_LOGIN&quot;)
-	self.PLAYER_LOGIN = nil
+for i,frame in pairs{GameTooltip, ItemRefTooltip} do
+	origs[frame] = frame:GetScript(&quot;OnTooltipSetItem&quot;)
+	frame:SetScript(&quot;OnTooltipSetItem&quot;, OnTooltipSetItem)
 end
 
 
-function f:PLAYER_LOGOUT()
-	for i,v in pairs(defaults) do if db[i] == v then db[i] = nil end end
+--------------------------------
+--      GetAuctionBuyout      --
+--------------------------------
 
-	-- Do anything you need to do as the player logs out
+local ids = LibStub(&quot;tekIDmemo&quot;)
+local orig = GetAuctionBuyout
+function GetAuctionBuyout(item)
+	local id = ids[item]
+	return orig and orig(item) or id and db.last[GetItemInfo(id)]
 end</diff>
      <filename>NutCounter.lua</filename>
    </modified>
    <modified>
      <diff>@@ -17,5 +17,6 @@
 
 LibStub.lua
 tekKonfigAboutPanel.lua
+tekIDmemo.lua
 
 NutCounter.lua</diff>
      <filename>NutCounter.toc</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>696871557e53e96f34bcc7ec0e87a2145610b9d6</id>
    </parent>
  </parents>
  <author>
    <name>Tekkub</name>
    <email>tekkub@gmail.com</email>
  </author>
  <url>http://github.com/tekkub/nutcounter/commit/e68e59918839262e4c40ebc06784c747fa5229ec</url>
  <id>e68e59918839262e4c40ebc06784c747fa5229ec</id>
  <committed-date>2008-10-26T13:43:26-07:00</committed-date>
  <authored-date>2008-10-26T13:43:26-07:00</authored-date>
  <message>Lookie lookie worky worky!</message>
  <tree>e7903b15dd3cc72321767abe85f7bb3dd2b698ae</tree>
  <committer>
    <name>Tekkub</name>
    <email>tekkub@gmail.com</email>
  </committer>
</commit>
