⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 walk.cpp

📁 This programm is proxy server for ragnarok online game. Also it s can be use as bot. It control all
💻 CPP
字号:
#include "walk.h"
#include <limits.h>
#include "../proto/proto.h "
#include "../proto/stt_proto.h"
#include "../proto/ctt_proto.h"
#include "../proto/ttg_proto.h"
#include "map/path.h"
#include "statistic.h"
#include "../game.h"
#include "../timers.h"

int walking_state;

//route
FILE * route_file;
int is_rt_rec;

PathList * route;
int following_state;

char walk_s[256];

// forward declarations
void walk_load_pathfile(ParsePoint * pp, char * filename);
void walk_do_rt_follow(ParsePoint * pp);
int walk_sub(ParsePoint * pp);

DWORD walk_timer(ParsePoint * pp, DWORD timestamp);
int walk_on_timer_death(ParsePoint * pp);

int walk_on_STT_CharSelection(ParsePoint * pp);
int walk_on_STT_ChangeMapCell(ParsePoint * pp);
int walk_on_STT_ChangeMap(ParsePoint * pp);


int walk_init(void)
{
    walking_state = 0; // staying
    is_rt_rec = 0;
    route_file = NULL;
    following_state = 0; // 0 = disabled

    //MyAssert( map_readwater("db/water_height.txt"),"", 0);
    
    register_parser(DIR_STT, -1, PC_STT_WALKOK,        walk_on_STT_WalkOk);
    register_parser(DIR_STT, -1, PC_STT_CHARSELECTION, walk_on_STT_CharSelection);
    register_parser(DIR_STT, -1, PC_STT_CHANGEMAPCELL, walk_on_STT_ChangeMapCell);
    register_parser(DIR_STT, -1, PC_STT_CHANGEMAP, walk_on_STT_ChangeMap);

    return 1;
}

void walk_finish(void) // subsystem finalization
{
    is_rt_rec = 0;

    map_finish();

    if(route_file != NULL )
        fclose(route_file);

    if(route != NULL)
    {
        while(route)
        {
            PathList * tmp = route->next;
            free(route);
            route = tmp;
        }
    }
}

//*****************************

int walk_on_STT_WalkOk(ParsePoint *pp)
{
        short x,y,to_x,to_y;

    if( !parse_STT_WalkOk(pp,&x,&y,&to_x,&to_y) )
        return 0;
    
    _snprintf(walk_s,255,DIR_STT_TXT " WalkOk (%d,%d)->(%d,%d)",x,y, to_x,to_y);
    send_tout(pp, walk_s);

    if(walking_state != 0) // if walking
    {
        if( (x==to_x) && (y==to_y) )
        {
            char dx = dirx[(int)sd.dir];
            char dy = diry[(int)sd.dir];

            sprintf(walk_s, "WalkOk subst: (%d,%d)->(%d,%d)", sd.x, sd.y, sd.x-dx, sd.y-dy);
            send_tout(pp, walk_s);
            stt_block_packet = 2; // packet substitution
            send_CLI_WalkOk(pp, sd.x, sd.y, sd.x-dx, sd.y-dy);
        }
    }

    sd.x = x; sd.y = y;
    sd.to_x = to_x; sd.to_y = to_y;

    if(is_rt_rec)
    {
        fprintf(route_file, "%d,%d\n", x,y);
        fflush(route_file);
    }

    if(walking_state == 0)
    {    
        int delay = walk_sub(pp);
        if(delay)
        {
            walking_state = 1; // walking
            register_timer(pp->timestamp+delay/2, walk_timer, TTAG_WALK, TID_WALK, walk_on_timer_death);
        }
    }

    return 1;
}

int walk_on_timer_death(ParsePoint * pp)
{
    walking_state = 0;

    if( (sd.x==sd.to_x) && (sd.y==sd.to_y) )
    {
        // all ok
        rise_event(EID_WALKDONE, pp);
    }
    else
    {
        // failure: we haven't finished walking, but timer have dead.
    }

    return 1;
}

int walk_on_cmd_rtrecOn(ParsePoint * pp)
{
    route_file = fopen("route.txt","w");
    if(route_file == NULL)
    {
        is_rt_rec = 0;
        send_tout(pp, "硒栳赅 镳

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -