[--------------------------------------------------------------------------------
-- hook.lua is part of ZS Shaiya Bot.
--
-- ZS Shaiya Bot is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- ZS Shaiya Bot is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with ZS Shaiya Bot. If not, see <
http://www.gnu.org/licenses/>.
--
-- Copyright © 2008 ZS Shaiya Bot
--------------------------------------------------------------------------------
--AVATAR_PTR = 0x0081CBEC
AVATAR_PTR = 0x00825CB4
--AVATAR_NAME_ADDRESS = 0x00820A3C
AVATAR_NAME_ADDRESS = 0x0082AC0C
--AVATAR_SIT_CHECK_ADDR = 0x006DCC80
AVATAR_ACTION_ADDR = 0x006E5D40
--MEM_ADDRESS_AVATAR_LEVEL = 0x0081F670
MEM_ADDRESS_AVATAR_LEVEL = 0x00828780
--MAP_NAME = 0x1745A7E0
avi_offset = {
pos_x=0x10,
pos_y=0x14,
pos_z=0x18,
pos_rot_x=0x1c,
pos_rot_y=0x24,
hp=0x12c,
hp_max=0x130,
mp=0x134,
mp_max=0x138,
sp=0x13C,
sp_max=0x140,
damage_dealt=0x1b8,
--movement=609,
}
AVATAR_ACTION_STANDING = 0
AVATAR_ACTION_MOVING = 1
AVATAR_ACTION_ATTACKING = 2
AVATAR_ACTION_JUMPING = 3
AVATAR_ACTION_SIT_DOWN = 5
AVATAR_ACTION_STAND_UP = 6
AVATAR_ACTION_SITTING = 7
-- constructor.
Hook = class(
function(obj)
end
)
function Hook:set_avi_rotation(pos)
local l_proc = get_process()
memoryWriteFloatPtr(l_proc, AVATAR_PTR, ROTATION_X_OFFSET, pos.x)
memoryWriteFloatPtr(l_proc, AVATAR_PTR, ROTATION_Y_OFFSET, pos.y)
end
function Hook:get_avi_rotation()
local l_proc = get_process()
local l_pos = {
x=memoryReadFloatPtr(l_proc, AVATAR_PTR, avi_offset.pos_rot_x),
y=memoryReadFloatPtr(l_proc, AVATAR_PTR, avi_offset.pos_rot_y),
}
return l_pos
end
function Hook:get_map_name()
local l_map_name = g_cfg.map_name
--local l_map_name = memoryReadString(g_proc, MAP_NAME)
--print("map_name: " .. l_map_name)
return l_map_name
end
function Hook:get_avi_level()
local l_avi_lvl = memoryReadInt(g_proc, MEM_ADDRESS_AVATAR_LEVEL)
return l_avi_lvl
end
function Hook:get_avi_position()
local l_proc = get_process()
local l_pos = {
x=memoryReadFloatPtr(l_proc, AVATAR_PTR, avi_offset.pos_x),
y=memoryReadFloatPtr(l_proc, AVATAR_PTR, avi_offset.pos_y),
z=memoryReadFloatPtr(l_proc, AVATAR_PTR, avi_offset.pos_z),
}
--debug_message("pos(" .. l_pos.x .. "," .. l_pos.y .. "," .. l_pos.z .. ")")
return l_pos
end
function Hook:set_avi_position(pos)
local l_proc = get_process()
memoryWriteFloatPtr(l_proc, AVATAR_PTR, POS_X_OFFSET, pos.x)
memoryWriteFloatPtr(l_proc, AVATAR_PTR, POS_Y_OFFSET, pos.y)
memoryWriteFloatPtr(l_proc, AVATAR_PTR, POS_Z_OFFSET, pos.z)
end
function Hook:get_avi_data(offset)
--debug_message("avi_offset: " .. offset)
if (offset == "pos_x" or offset == "pos_y" or offset == "pos_z" or
offset == "pos_rot_x" or offset == "pos_rot_y") then
return memoryReadFloatPtr(g_proc, AVATAR_PTR, avi_offset[offset])
elseif (offset == "movement") then
return memoryReadBytePtr(g_proc, AVATAR_PTR, avi_offset[offset])
else
return memoryReadIntPtr(g_proc, AVATAR_PTR, avi_offset[offset])
end
end
function Hook:set_avi_data(offset, data)
if (offset == "movement") then
memoryWriteBytePtr(get_process(), AVATAR_PTR, avi_offset[offset], data)
end
end
function Hook:get_avi_name()
l_name = memoryReadString(get_process(), AVATAR_NAME_ADDRESS)
debug_message("name: " .. l_name)
return l_name
end
function Hook:get_avi_action()
return memoryReadByte(get_process(), AVATAR_ACTION_ADDR)
end
MEM_GAME_MESSAGE_OFFSET = 0x006E3D08
MEM_GAME_MESSAGE_INDEX = MEM_GAME_MESSAGE_OFFSET + 0x1404
MEM_GAME_MESSAGE_SIZE = 0x400
MEM_COMMON_MESSAGE_OFFSET = 0x021FC010
function Hook:get_latest_text_msg(channel_name, proc)
if (channel_name == "main") then
local l_offset = self:get_text_msg_offset(proc)
local l_message = nil
local l_address = MEM_GAME_MESSAGE_OFFSET + (l_offset * MEM_GAME_MESSAGE_SIZE)
--debug_message(sprintf("l_address: %d", l_address))
l_message = memoryReadString(proc, l_address)
--[[if (l_message ~= nil) then
debug_message("l_message=" .. l_message)
end]]
return l_message
elseif (channel_name == "common") then
local l_message = memoryReadString(proc, MEM_COMMON_MESSAGE_OFFSET)
--[[if (l_message ~= nil) then
debug_message("l_message=" .. l_message)
end]]
return l_message
end
end
function Hook:get_text_msg_offset(proc)
local l_offset = memoryReadInt(proc, MEM_GAME_MESSAGE_INDEX);
--debug_message(sprintf("text_msg_offset: %s", l_offset));
return l_offset;
end