Following is the logger code:
Logger code
Code: Select all
[ENABLE]
{$lua}
function getTimeStamp()
return os.date("%d-%m-%Y %X: ")
end
function getLogFile()
-- get relative path or get user input
local ffile = io.open("E:\TQ_combat_logs.txt", "a")
return ffile
end
function myLog(logString)
local str = readString(logString,300)
if not str then
return 1
end
--print(s)
local lb = string.byte(str,-1)
if(lb ~= 10) then
str = str.."
"
end
if (logFile ~= nil) then
logFile:write(getTimeStamp()..str)
logFile:flush()
end
return 0
end
logFile = getLogFile()
if (logFile ~= nil) then
logFile:write(getTimeStamp().."--------------Session start".."
")
end
{$asm}
loadlibrary(luaclient-i386.dll)
luacall(openLuaServer('CELUASERVER'))
CELUA_ServerName:
db 'CELUASERVER',0
//hook to Game::Engine:Log method
aobscanmodule(_loggerInject,Engine.dll,8D 44 24 24 50 8D 4C 24 10 E8 ?? ?? ?? ?? 8b 8F) // should be unique
registersymbol(_loggerInject)
alloc(newmem,$2048)
alloc(_loggerFuncName,256)
alloc(_loggerFuncRef,4)
alloc(_logString, 4)
registersymbol(_logString)
label(code)
label(return)
_loggerFuncName:
db 'myLog',0
newmem:
lea eax,[esp+24]
mov [_logString],eax //retrive pointer to data to log.
push eax
pushad
mov eax,[_loggerFuncRef]
test eax, eax
jne @f
push _loggerFuncName
call CELUA_GetFunctionReferenceFromName
mov [_loggerFuncRef],eax
@@:
push 0 //async
push _logString
push 1 //no of parameters
push [_loggerFuncRef]
call CELUA_ExecuteFunctionByReference //call to myLog method
popad
code:
jmp return
_loggerInject:
jmp newmem
return:
[DISABLE]
{$Lua}
if (logFile ~= nil) then
logFile:write(getTimeStamp().."--------------Session End".."
")
logFile:close()
end
{$Asm}
_loggerInject:
db 8D 44 24 24 50
unregistersymbol(_loggerInject)
dealloc(newmem)
dealloc(_loggerFuncName)
dealloc(_loggerFuncRef)
dealloc(_logString)
unregistersymbol(_logString)
Following are the logs from the game:
Log data
Code: Select all
1006/25/18 16:38:27: combat
1006/25/18 16:38:27: [
1006/25/18 16:38:27: attackerName = Records/XPack/Creatures/PC/MalePC01.dbr
1006/25/18 16:38:27: attackerID = 25964
1006/25/18 16:38:27: defenderName = RecordsCreatureMonsterSatyrAM_Peltast_04.dbr
1006/25/18 16:38:27: defenderID = 66640
1006/25/18 16:38:27: combatType = Retaliation Attack
1006/25/18 16:38:27: Total Damage: Absolute (97.983086), Over Time (0.000000)
4106/25/18 16:38:27: ^y 97.983086 of Fire(6) Damage to Defender 0x10450
1006/25/18 16:38:27: ^bRacial Bonus Damage: (0.000000)
4106/25/18 16:38:27: criticalStrike = 1.000000
1006/25/18 16:38:27: regionHit = Torso
1006/25/18 16:38:27:
1006/25/18 16:38:27: ]
Let me know any improvements/suggestions.