local emergencyHeal=0; text1 = 0x00641608; text2 = 0x00641E08; text3 = 0x00642208; text4 = 0x00652608; text5 = 0x00641A08; message = "too far away from an opponent"; ------------------------------------------------ -- HOTKEYS ------------------------------------------------ MOVEMENT_OFFSET = 609; SPEED_OFFSET = 260; startKey = key.VK_INSERT; stopKey = key.VK_DELETE; key_switchtarget = key.VK_TILDE; key_attack = key.VK_1; key_pickup = key.VK_2; key_skill1 = key.VK_3; key_skill2 = key.VK_4; key_skill3 = key.VK_5; key_buff1 = key.VK_6; key_buff2 = key.VK_7; key_hp_potion = key.VK_8; key_mp_potion1 = key.VK_NUMPAD1; key_mp_potion2 = key.VK_NUMPAD2; key_mp_potion3 = key.VK_NUMPAD3; key_mp_potion4 = key.VK_NUMPAD4; key_mp_potion5 = key.VK_NUMPAD5; key_mp_potion6 = key.VK_NUMPAD6; key_mp_potion7 = key.VK_NUMPAD7; key_mp_potion8 = key.VK_NUMPAD8; key_mp_potion9 = key.VK_NUMPAD9; key_mp_potion0 = key.VK_NUMPAD0; key_mp_potion = key.VK_9; key_sp_potion = key.VK_0; key_sit = key.VK_C; myself = key.VK_F1; partner = key.VK_F2 ------------------------------------------------ -- Buff 1 = hotkey 7 Buff 2 = hot key 6 -- Set value to 0 if you don't want to buff ------------------------------------------------ buff1_reuse_time = 29; -- measured by minutes, prayer buff1_MP = 85 -- Put in how much MP does Buff1 needs buff2_reuse_time = 9; -- measured by minutes, AOP buff2_MP = 165 -- Put in how much MP does Buff2 needs ------------------------------------------------ -- Emergency heal a target by percentage ------------------------------------------------ HP_emergency_heal = 70; ------------------------------------------------ -- SKILLS secondsToTimer(x); measured by seconds -- minutesToTimer(x); measured by minutes ------------------------------------------------ -- Set to 0 if you don't want to use a skill skill1_time = 0; skill2_time = 0; skill3_time = minutesToTimer(3); -- body protector ------------------------------------------------ -- POTIONS ------------------------------------------------ -- All potion use values are specified in % -- Set the values to 0 to not use that potion HP_potion_use = 50; MP_potion_use = 30; SP_potion_use = 30; ------------------------------------------------ -- SITTING ------------------------------------------------ -- All sitting values are specified in % -- We will only sit while out of battle -- Set the values to 0 to not use sitting HP_sit = 25; MP_sit = 10; SP_sit = 10; --[[********************************************************************* ************************************************************************** DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ************************************************************************** ************************************************************************]] ------------------------------------------------ -- Memory addresses ------------------------------------------------ playerptr_addr = 0x007835B4; HP_offset = 296; MaxHP_offset = 300; MP_offset = 304; MaxMP_offset = 308; SP_offset = 312; MaxSP_offset = 316; targetid_addr = 0x0062FAD4; -- short, 65535 if none selected -- REMOVED -- targettype_addr = 0x00619B1F; -- byte, 0 = player/NPC, 7 = monster sitcheck_addr = 0x00643648; -- byte, 0 = standing, 7 = sitting -------------------------------------------------------------------------------------------------------------- function init_window() win = findWindow("Shaiya"); if(win == nil) then printf(error_init); macro_running = false; end end function init_process() proc = openProcess( findProcessByExe("game.exe") ); if(proc == 0) then printf("error opening process.\n"); macro_running = false; end end function init_hdc() hdc = openDC(get_win()); local wx, wy, ww, wh = windowRect(get_win()); end function get_hdc() return hdc; end function get_win() return win; end function debug_message(msg) if (g_debug) then print(msg); logMessage(msg); end end window_mode = false; g_debug = true; function set_movement() memoryWriteBytePtr(proc, playerptr_addr, MOVEMENT_OFFSET, 3); end function set_attackspeed() memoryWriteIntPtr(proc, playerptr_addr, SPEED_OFFSET, 520); speedatk = memoryReadIntPtr(proc, playerptr_addr, SPEED_OFFSET); printf(speedatk); end function buffing1() if(buff1_reuse_time == 0) then return; else local startTime = os.time(); if(os.difftime(startTime,buff1_beginTime)>buff1 and MP>=buff1_MP) then buff1_beginTime = os.time(); keyboardPress(key_buff1); yrest(2000); end end end function buffing2() if(buff2_reuse_time == 0) then return; else local startTime = os.time(); if(os.difftime(startTime,buff2_beginTime)>buff2 and MP>=buff2_MP) then buff2_beginTime = os.time(); keyboardPress(key_buff2); yrest(2000); end end end eHeal = (HP_emergency_heal* 0.01)* 166; buff1 = buff1_reuse_time * 60; buff2 = buff2_reuse_time * 60; -------------------------------------------------------------------------------- -- Memory Addresses. TARGET_POS_X_ADDRESS = 0x1FCFE80; TARGET_POS_Y_ADDRESS = 0x1FCFE84; TARGET_POS_Z_ADDRESS = 0x1FCFE88; TARGET_TYPE_ADDR = 0x0619B1F; -- Field Values. TARGET_UNKNOWN = 0; TARGET_DAMAGED = 1; TARGET_FULL = 2; TARGET_BAR_COLOR = { r_min=150, r_max=181, g_min=10, g_max=73, b_min=50, b_max=107 }; TARGET_HEALTH_BAR_PIXEL_OFFSET_1 = {x=36, y=36}; TARGET_HEALTH_BAR_PIXEL_OFFSET_F = {x=166, y=36}; TARGET_HEALTH_BAR_PIXEL_OFFSET_2 = {x=150, y=36}; TARGET_HEALTH_BAR_PIXEL_OFFSET_3 = {x=eHeal, y=36}; cant = {x=0, y=0}; -- Target Name Color TARGET_NAME_COLOR_SCAN_OFFSET_1 = {x=98, y=15}; TARGET_NAME_COLOR_SCAN_OFFSET_2 = {x=110, y=15}; target_name_color = { unknown=0, white=1, cyan=2, blue=3, green=4, yellow=5, orange=6, red=7, purple=8, grey=9, } --[[TARGET_NAME_COLOR_WHITE = 1; TARGET_NAME_COLOR_CYAN = 2; TARGET_NAME_COLOR_BLUE = 3; TARGET_NAME_COLOR_GREEN = 4; TARGET_NAME_COLOR_YELLOW = 5; TARGET_NAME_COLOR_ORANGE = 6; TARGET_NAME_COLOR_RED = 7; TARGET_NAME_COLOR_PURPLE = 8; TARGET_NAME_COLOR_GREY = 9;]] -- In order of difficulty, from easiest to hardest. target_name_color_rgb = { [target_name_color["white"]] = {r_min=255, r_max=255, g_min=255, g_max=255, b_min=255, b_max=255}, [target_name_color["cyan"]] = {r_min=120, r_max=140, g_min=255, g_max=255, b_min=255, b_max=255}, [target_name_color["blue"]] = {r_min=0, r_max=0, g_min=0, g_max=0, b_min=255, b_max=255}, [target_name_color["green"]] = {r_min=0, r_max=0, g_min=255, g_max=255, b_min=0, b_max=0}, [target_name_color["yellow"]] = {r_min=255, r_max=255, g_min=255, g_max=255, b_min=0, b_max=0}, [target_name_color["orange"]] = {r_min=255, r_max=255, g_min=128, g_max=128, b_min=0, b_max=0}, [target_name_color["red"]] = {r_min=255, r_max=255, g_min=0, g_max=0, b_min=0, b_max=0}, [target_name_color["purple"]] = {r_min=255, r_max=255, g_min=0, g_max=0, b_min=255, b_max=255}, --[target_name_color["grey"]] = {r_min=255, r_max=255, -- g_min=255, g_max=255, -- b_min=255, b_max=255}, } TARGET_TYPE_FRIENDLY = 0; TARGET_TYPE_NOTHING = -1; -- Delays. MONSTER_DIE_DELAY = 500; -- Status Info Bar, offset. STATUSINFOBAR_POS = {x=0, y=0}; -- Target constructor. -- Refreshes the variables of the target from memory. -- @return nothing. -- Looks at pixels in the status info bar in the h/w device context, -- to determine the status of the monster. -- note - this has known errors, changing the colour bit value, or restarting PC -- seems to fix it. -- @return TARGET_UNKNOWN does not have any detectable red bar. -- TARGET_DAMAGED if some red bar exists. -- TARGET_FULL full red bar. function status() local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_1["y"])}; local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_2["y"])}; local pos_3 = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_3["y"])}; local pos_4 = {x=(STATUSINFOBAR_POS["x"] + cant["x"]), y=(STATUSINFOBAR_POS["y"] + cant["y"])}; --printf("x1:%d y1:%d x2:%d y2:%d\n", pos_1["x"], pos_1["y"], pos_2["x"], pos_2["y"]); local l_hdc = get_hdc(); -- s(RGB) begining E(RGB) end M(RGB) middle; local sr,sg,sb; local er,eg,eb; local cr,cg,cb; local mr,mg,mb; if (window_mode) then local wx, wy = windowRect(get_win()); --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy)); sr,sg,sb = getPixel(l_hdc, (wx + pos_1["x"]), (wy + pos_1["y"])); er,eg,eb = getPixel(l_hdc, (wx + pos_2["x"]), (wy + pos_2["y"])); mr,mg,mb = getPixel(l_hdc, (wx + pos_3["x"]), (wy + pos_3["y"])); cr,cg,cb = getPixel(l_hdc, (wx + pos_4["x"]), (wy + pos_4["y"])); else sr,sg,sb = getPixel(l_hdc, pos_1["x"], pos_1["y"]); er,eg,eb = getPixel(l_hdc, pos_2["x"], pos_2["y"]); mr,mg,mb = getPixel(l_hdc, pos_3["x"], pos_3["y"]); cr,cg,cb = getPixel(l_hdc, pos_4["x"], pos_4["y"]); end --closeDC(hdc); --debug_message(sprintf("sr: %d, sg: %d, sb: %d", sr, sg, sb)); --debug_message(sprintf("er: %d, eg: %d, eb: %d", er, eg, eb)); --debug_message(sprintf("mr: %d, mg: %d, mb: %d", mr, mg, mb)); --debug_message(sprintf("cr: %d, cg: %d, cb: %d", cr, cg, cb)); if ((sr >= TARGET_BAR_COLOR["r_min"] and sr <= TARGET_BAR_COLOR["r_max"]) and (sg >= TARGET_BAR_COLOR["g_min"] and sg <= TARGET_BAR_COLOR["g_max"]) and (sb >= TARGET_BAR_COLOR["b_min"] and sb <= TARGET_BAR_COLOR["b_max"])) then if((er <= TARGET_BAR_COLOR["r_min"] and er <= TARGET_BAR_COLOR["r_max"]) and (eg <= TARGET_BAR_COLOR["g_min"] and eg <= TARGET_BAR_COLOR["g_max"]) and (eb <= TARGET_BAR_COLOR["b_min"] and eb <= TARGET_BAR_COLOR["b_max"])) then if((mr <= TARGET_BAR_COLOR["r_min"] and mr <= TARGET_BAR_COLOR["r_max"]) and (mg <= TARGET_BAR_COLOR["g_min"] and mg <= TARGET_BAR_COLOR["g_max"]) and (mb <= TARGET_BAR_COLOR["b_min"] and mb <= TARGET_BAR_COLOR["b_max"])) then emergencyHeal=1; end return TARGET_DAMAGED; end return TARGET_FULL; end return TARGET_UNKNOWN; end function targetFull() local pos_F = {x=(STATUSINFOBAR_POS["x"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_F["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_HEALTH_BAR_PIXEL_OFFSET_F["y"])}; local l_hdc = get_hdc(); local fr,fg,fb; if (window_mode) then local wx, wy = windowRect(get_win()); --debug_message(sprintf("win_x: %d, wim_y: %d\n", wx, wy)); fr,fg,fb = getPixel(l_hdc, (wx + pos_F["x"]), (wy + pos_F["y"])); else fr,fg,fb = getPixel(l_hdc, pos_F["x"], pos_F["y"]); end --closeDC(hdc); debug_message(sprintf("fr: %d, fg: %d, fb: %d", fr, fg, fb)); --debug_message(sprintf("fr: %d, fg: %d, fb: %d", fr, fg, fb)); if ((fr >= TARGET_BAR_COLOR["r_min"] and fr <= TARGET_BAR_COLOR["r_max"]) and (fg >= TARGET_BAR_COLOR["g_min"] and fg <= TARGET_BAR_COLOR["g_max"]) and (fb >= TARGET_BAR_COLOR["b_min"] and fb <= TARGET_BAR_COLOR["b_max"])) then printf("\\n True!! \n\n"); return false; end return true; end function get_color() local pos_1 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_1["y"])}; local pos_2 = {x=(STATUSINFOBAR_POS["x"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["x"]), y=(STATUSINFOBAR_POS["y"] + TARGET_NAME_COLOR_SCAN_OFFSET_2["y"])}; local pr, pg, pb; --local l_color = TARGET_NAME_COLOR_UNKNOWN; --local hdc = openDC(shaiya_win); local l_hdc = get_hdc(); for i=pos_1["x"], pos_2["x"] do for j=pos_1["y"], pos_2["y"] do if (window_mode) then local wx, wy = windowRect(get_win()); printf("win_x: %d, wim_y: %d\n", wx, wy); pr, pg, pb = getPixel(l_hdc, wx + i, wy + j); else pr, pg, pb = getPixel(l_hdc, i, j); end debug_message(sprintf("pr: %d, pg: %d, pb: %d", pr, pg, pb)); for k,v in pairs(target_name_color_rgb) do --printf("v[r]: %d, v[g]: %d, v[b]: %d\n", v["r"], v["g"], v["b"]); if(pr >= v["r_min"] and pr <= v["r_max"] and pg >= v["g_min"] and pg <= v["g_max"] and pb >= v["b_min"] and pb <= v["b_max"]) then --printf("target_difficulty_color: %s\n", k); return k; end end end end --closeDC(hdc); return target_name_color["unknown"]; end ----------------------------------------------------------------------------------- ------------------------------------------------ -- Variable setup ------------------------------------------------ HP = 10000; MaxHP = HP; MP = 10000; MaxMP = MP; SP = 10000; MaxSP = SP; skill1_ready = true; skill2_ready = true; skill3_ready = true; buff1_ready = true; buff2_ready = true; ------------------------------------------------ -- Functions ------------------------------------------------ skill1_toggle = function () skill1_ready = true; end; skill2_toggle = function () skill2_ready = true; end; skill3_toggle = function () skill3_ready = true; end; buff1_toggle = function () buff1_ready = true; end; buff2_toggle = function () buff2_ready = true; end; function use_hp_potion() keyboardPress(key_hp_potion); printf("Using HP potion\n"); end function use_mp_potion() keyboardPress(key_mp_potion); keyboardPress(key_mp_potion1); keyboardPress(key_mp_potion2); keyboardPress(key_mp_potion3); keyboardPress(key_mp_potion4); keyboardPress(key_mp_potion5); keyboardPress(key_mp_potion6); keyboardPress(key_mp_potion7); keyboardPress(key_mp_potion8); keyboardPress(key_mp_potion9); keyboardPress(key_mp_potion0); printf("Using MP potion\n"); end function use_sp_potion() keyboardPress(key_sp_potion); printf("Using SP potion\n"); end function sit() if( HP_sit == 0 ) then return; end printf("Sitting.\n"); local sitting = false; while( sitting == false ) do keyboardPress(key_sit); yrest(1000); sitting = memoryReadByte(proc, sitcheck_addr) ~= 0; end local lasthp = HP; while( true ) do if( HP == MaxHP and MP == MaxMP and SP == MaxSP ) then switch_target(); break; end if( HP < (lasthp - 10) ) then printf("Exiting rest...under attack\n"); break; else lasthp = HP; end yrest(100); end sitting = true; while( sitting ) do keyboardPress(key_sit); yrest(1000); sitting = memoryReadByte(proc, sitcheck_addr) ~= 0; end printf("Standing... Resuming bot\n"); yrest(1000); end function pickup() printf("Pickup!\n"); if( key_pickup == 0 ) then return; end local i; for i = 0, 5 do keyboardPress(key_pickup); yrest(500); end yrest(1000); end function update_vars() HP = memoryReadIntPtr(proc, playerptr_addr, HP_offset); MaxHP = memoryReadIntPtr(proc, playerptr_addr, MaxHP_offset); MP = memoryReadIntPtr(proc, playerptr_addr, MP_offset); MaxMP = memoryReadIntPtr(proc, playerptr_addr, MaxMP_offset); SP = memoryReadIntPtr(proc, playerptr_addr, SP_offset); MaxSP = memoryReadIntPtr(proc, playerptr_addr, MaxSP_offset); end function have_target() local readid = memoryReadShort(proc, targetid_addr); return ( readid ~= 0xFFFF ); end function find_target() keyboardPress(key_attack); end function switch_target() keyboardPress(key_switchtarget); end ------------------------------------------------ -- MAIN ------------------------------------------------ function main() proc = openProcess(findProcessByExe("game.exe")); win = findWindow("Shaiya"); attach(win); setPriority(PRIORITY_HIGH); init_window(); init_process(); init_hdc(); printf("working"); registerTimer("update_vars", 100, update_vars); keyboardPress(key_buff1); yrest(2000); keyboardPress(key_buff2); yrest(2000); buff1_beginTime = os.time(); buff2_beginTime = os.time(); while( true ) do local target_status = status(); local color_status = get_color(); local player_color = 1; if(player_color == color_status) then --printf("Status ", status(), "\n"); --printf("target_color: %d\n", target_color); printf("target_status=%d\n", target_status); --logMessage(sprintf("target_status=%d", target_status)); if (target_status == TARGET_DAMAGED) then if (emergencyHeal==1) then keyboardPress(key_skill1); printf("Emergency Healing: Key 2 \n \n"); emergencyHeal=0; else local varableT = targetFull(); while (varableT == true) do keyboardPress(key_skill2); printf("Healing: Key 2 \n \n"); yrest(2000); varableT = targetFull(); end end else buffing1(); buffing2(); yrest(2000); end else yrest(2000); end --if( (HP/MaxHP*100) < HP_emergency_heal and HP_emergency_heal > 0 ) then --keyboardPress(myself); --keyboardPress(key_skill1); --yrest(200); --keyboardPress(partner); --end --yrest(500) if( skill3_ready and skill3_time > 0) then keyboardPress(key_skill3); skill3_ready = false; yrest(1000); registerTimer("skill3_toggle", skill3_time, skill3_toggle); end --local readings; --readings = memoryReadString(proc, text1); --if (readings == message) then --printf("\n\n OMG it works! \n\n"); --else --printf("\n\n Keep trying Don't give Up! \n\n"); --end if( (HP/MaxHP*100) < HP_potion_use and HP_potion_use > 0 ) then use_hp_potion(); end if( (MP/MaxMP*100) < MP_potion_use and MP_potion_use > 0 ) then use_mp_potion(); end if( (SP/MaxSP*100) < SP_potion_use and SP_potion_use > 0 ) then use_sp_potion(); end end end startMacro(main);