免责声明:内容仅供学习参考,请合法利用知识,禁止进行违法犯罪活动!
如果看不懂、不知道现在做的什么,那就跟着做完看效果
现在的代码都是依据数据包来写的,如果看不懂代码,就说明没看懂数据包
内容参考于: 易道云信息技术研究院VIP课
上一个内容:106.在UI中显示装备与技能信息
码云版本号:5577e100ec208cdc53690bc306e32b8e63586523
代码下载地址,在 titan 目录下,文件名为:titan-装备信息更新的处理.zip
链接:https://pan.baidu.com/s/1W-JpUcGOWbSJmMdmtMzYZg
提取码:q9n5
--来自百度网盘超级会员V4的分享
HOOK引擎,文件名为:黑兔sdk升级版.zip
链接:https://pan.baidu.com/s/1IB-Zs6hi3yU8LC2f-8hIEw
提取码:78h8
--来自百度网盘超级会员V4的分享
以 106.在UI中显示装备与技能信息 它的代码为基础进行修改
这次没有效果图:图片没法看出效果
上一个内容中把背包、装备、技能都显示在了列表中,当使用了一个物品的时候数量会减少,这个更新数量等操作并没有实现,本次实现装备信息的更新
使用物品修改数量的数据包
可以看到更新物品的数据包也是用的10数据包,更新物品信息的数据包是10 01,更新角色信息的数据包是 10 00,从下图可以看出10 01为了兼容 10 00,它把原本角色id的位置换成了两个int
物品交换
交换下图红框的两个物品
交换的数据包
数据包拆解
然后把一个物品交换的空白的地方
数据包与正常交换物品一样
丢弃物品
丢弃下图红框位置的物品
丢弃的数据包
数据包拆分
然后装备替换背包的更新,用下图红框位置的装备把装备上的装备替换下来
现在装备的
替换之后的数据包,它也有用来删除物品的19数据包,所以处理了19数据包,替换装备也能支持上了
CWndSkill.cpp文件的修改:修改了 OnBnClickedButton1函数
// CWndSkill.cpp: 实现文件
//#include "pch.h"
#include "CWndSkill.h"
#include "resource.h"
#include "CUI.h"
#include "extern_all.h"// CWndSkill 对话框IMPLEMENT_DYNAMIC(CWndSkill, CDialogEx)CWndSkill::CWndSkill(CWnd* pParent /*=nullptr*/): CDialogEx(IDD_PAGE_4, pParent)
{}CWndSkill::~CWndSkill()
{
}void CWndSkill::DoDataExchange(CDataExchange* pDX)
{CDialogEx::DoDataExchange(pDX);DDX_Control(pDX, IDC_LIST1, lstSkill);
}BOOL CWndSkill::OnInitDialog()
{CDialogEx::OnInitDialog();CUI* ui = (CUI*)Client;ui->SetListView(&lstSkill);lstSkill.InsertColumn(0, L"名称", 0, 100);lstSkill.InsertColumn(1, L"冷却时间", 0, 100);return TRUE;
}BEGIN_MESSAGE_MAP(CWndSkill, CDialogEx)ON_BN_CLICKED(IDC_BUTTON1, &CWndSkill::OnBnClickedButton1)
END_MESSAGE_MAP()// CWndSkill 消息处理程序void CWndSkill::OnBnClickedButton1()
{lstSkill.DeleteAllItems();CString txt;float coolDown;int index = 0;for (int i = 0; i < Client->SkillMax; i++){if (!Client->Skill[i]->Isfree) {coolDown = Client->Skill[i]->CoolDownTime / 1000;lstSkill.InsertItem(index, Client->Skill[i]->Name);txt.Format(L"%.2f秒", coolDown);lstSkill.SetItemText(index++, 1, txt);}}
}
CWndItem.cpp文件的修改:修改了 OnBnClickedButton1函数、OnBnClickedButton4函数、OnBnClickedButton5函数、OnBnClickedButton6函数
// CWndItem.cpp: 实现文件
//#include "pch.h"
#include "CWndItem.h"
#include "resource.h"
#include "extern_all.h"
#include "CUI.h"// CWndItem 对话框IMPLEMENT_DYNAMIC(CWndItem, CDialogEx)CWndItem::CWndItem(CWnd* pParent /*=nullptr*/): CDialogEx(IDD_PAGE_3, pParent)
{}CWndItem::~CWndItem()
{
}void CWndItem::DoDataExchange(CDataExchange* pDX)
{CDialogEx::DoDataExchange(pDX);DDX_Control(pDX, IDC_LIST1, lstItem);
}BOOL CWndItem::OnInitDialog()
{CDialogEx::OnInitDialog();CUI* ui = (CUI*)Client;ui->SetListView(&lstItem);lstItem.InsertColumn(0, L"名称",0, 100);lstItem.InsertColumn(1, L"数量",0, 100);return TRUE;
}BEGIN_MESSAGE_MAP(CWndItem, CDialogEx)ON_BN_CLICKED(IDC_BUTTON1, &CWndItem::OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON4, &CWndItem::OnBnClickedButton4)ON_BN_CLICKED(IDC_BUTTON5, &CWndItem::OnBnClickedButton5)ON_BN_CLICKED(IDC_BUTTON6, &CWndItem::OnBnClickedButton6)
END_MESSAGE_MAP()// CWndItem 消息处理程序void CWndItem::OnBnClickedButton1()
{lstItem.DeleteAllItems();CString txt;int index = 0;for (int i = 0; i < Client->EquipMax; i++){if (!Client->Equip[i]->Isfree) {lstItem.InsertItem(index, Client->Equip[i]->Name);txt.Format(L"%d/%d", Client->Equip[i]->Amount, Client->Equip[i]->MaxAmount);lstItem.SetItemText(index++, 1, txt);}}
}void CWndItem::OnBnClickedButton4()
{lstItem.DeleteAllItems();CString txt;int index = 0;for (int i = 0; i < Client->ItemMax; i++){if (!Client->ItemBag[i]->Isfree) {lstItem.InsertItem(index, Client->ItemBag[i]->Name);txt.Format(L"%d/%d", Client->ItemBag[i]->Amount, Client->ItemBag[i]->MaxAmount);lstItem.SetItemText(index++, 1, txt);}}
}void CWndItem::OnBnClickedButton5()
{lstItem.DeleteAllItems();CString txt;int index = 0;for (int i = 0; i < Client->MountMax; i++){if (!Client->MountBag[i]->Isfree) {lstItem.InsertItem(index, Client->MountBag[i]->Name);txt.Format(L"%d/%d", Client->MountBag[i]->Amount, Client->MountBag[i]->MaxAmount);lstItem.SetItemText(index++, 1, txt);}}
}void CWndItem::OnBnClickedButton6()
{lstItem.DeleteAllItems();CString txt;int index = 0;for (int i = 0; i < Client->ItemExMax; i++){if (!Client->ItemEx[i]->Isfree) {lstItem.InsertItem(index, Client->ItemEx[i]->Name);txt.Format(L"%d/%d", Client->ItemEx[i]->Amount, Client->ItemEx[i]->MaxAmount);lstItem.SetItemText(index++, 1, txt);}}
}
NetClient.cpp文件的修改:修改了 GetGameOBJECT函数、ReSetGameOBJECT函数、Init函数、OnSvrUpdateProperty函数,新加 ExChangeOBJECT函数、DestoryOBJECT函数、OnSvrGameBaseExChange函数、OnSvrGameBaseDestroy函数
#include "pch.h"
#include "NetClient.h"
#include "extern_all.h"bool NetClient::login(const char* Id, const char* Pass)
{const int bufflen = sizeof(DATA_LOGIN) + 1;char buff[bufflen];DATA_LOGIN data;// 有些操作系统这样写会报错,因为内存不对齐,现在Windows下没事//PDATALOGIN _data = (PDATALOGIN)(buff + 1);// 这样写就能解决内存对齐问题PDATALOGIN _data =&data;int len = strlen(Id);memcpy(_data->Id, Id, len);len = strlen(Pass);memcpy(_data->Pass, Pass, len);memcpy(buff+1, _data, sizeof(DATA_LOGIN));buff[0] = I_LOGIN;return WinSock->OnSend(buff, sizeof(buff));}bool NetClient::DelRole(const wchar_t* rolename)
{PROLEDATA _role = GetRoleByName(rolename);if (_role == nullptr) {return false;}else {return DelRole(rolename, _role->name.lenth);}return false;
}bool NetClient::StartCreateRole()
{NET_CREATEROLE_START _data;return WinSock->OnSend(&_data.op, _data.len);
}bool NetClient::SelectCamp(const char* _campname)
{NET_SEND_BUFF _buff;NET_SEND_CHOOSECAMP _data;_data.opcode.Set(SC_CHOOSECAMP);_data.camps.Set(_campname);/* sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}//性别 0 男 1 女
//
//阵营 1 艾森赫特 2 格兰蒂尔
//
//种族 1 布冯特人 3 格洛玛人 4 尤恩图人 6 喀什人
//
//职业 1 仲裁者 3秘法师 6 猎魔人 8 元素法师
//
//脸型 0 1 2 3
bool NetClient::CreateRole(wchar_t* name, double sex, double camp, double race, double occu, const char* photo, const char* infos, const char* txt, double faceShape)
{// rolecount > 4说明角色的数量够了if (rolecount > 4)return false;int index = 0;bool roleindex[5]{true, true, true, true, true };for (int i = 0; i < rolecount; i++) {roleindex[roles[i].index] = false;}for (int i = 0; i < 5; i++){if (roleindex[i]) {index = i;break;}}// wchar_t _name[] = L"am52111";NS_CREATEROLE_HEAD_BUFF _buff;CREATE_ROLE_DATAS _data;_data.sex.Set(sex);_data.camp.Set(camp);_data.face.Set(race);_data.occu.Set(occu);_data.faceSahpe.Set(faceShape);//_data.Photo.Set("gui\BG_team\TeamRole\Teamrole_zq_humF_001.PNG");_data.Photo.Set(photo);//_data.Infos.Set("Face,0;Hat,0;Eyes,0;Beard,0;Ears,0;Tail,0;Finger,0;Cloth,0;Pants,0;Gloves,0;Shoes,0;Trait,0;HairColor,0;SkinColor,0;SkinMtl,0;Tattoo,0;TattooColor,16777215;");_data.Infos.Set(infos);_data.Txt.Set(txt);short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;_buff.index = index;int lenth = wcslen(name) + 1;lenth = lenth * 2;memcpy(_buff.name, name, lenth);int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEHD_CREATEROLE_HEAD) - 3;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::SelectRole(const wchar_t* rolename)
{PROLEDATA roles = GetRoleByName(rolename);if (roles == nullptr)return false;NS_SELECTROLE _data;memcpy(_data.buff, roles->name.value(), roles->name.lenth);return WinSock->OnSend((char*)&_data, sizeof(_data));
}bool NetClient::Fall()
{NET_SEND_BUFF _buff;FALL_DATA_STOP _data2;_data2.opcode.Set(SC_FALL_HEADER);_data2.Mode.Set(0x2);_data2.StartH.Set(Player.h);_data2.NextH.Set(Player.h - 12);_data2.EndH.Set(Player.h - 120);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data2) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data2.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);}void NetClient::Teleport(float x, float h, float y, float face)
{// 修正坐标//PAIM aim = Client->GetAimByName(L"r");//if (aim == nullptr) {// return;//}// 目的地坐标//float decX = aim->x;//float decH = aim->h;//float decY = aim->y;/* float decX = 3843.776123f;float decH = 11.731983f;float decY = -2005.533813f;float face = 0.0f;*/union {unsigned nt = 0xFFC00000;float fNan;}v;/*这里的参数虽然都是无效值,但不见得就非要全部是无效值可能只设置x坐标就可以,可能值设置y坐标就可以,可能要设置x、y坐标就可以。。。现在全部设置成无效值了,如果游戏服务端有这个漏洞,我们角色的坐标就会全部设置成无效值,然后按照逻辑来讲下一次设置坐标的函数可以任意修改然后还可能有的游戏设置NaN不成功,这种的可以多试几个修改坐标或者其它数据的函数如果还都不行那就没办法了*///Client->MoveWJump(v.fNan, v.fNan, v.fNan, v.fNan, v.fNan, v.fNan, v.fNan); // 可以把坐标设置成nan//Client->MoveWalk(v.fNan, v.fNan, v.fNan, v.fNan, v.fNan, v.fNan, v.fNan); // 可以把坐标设置成nanClient->MoveStop(v.fNan, v.fNan, v.fNan, v.fNan); // 可以把坐标设置成nanClient->MoveStop(x, h, y, face);// 利用修正坐标数据包瞬移Client->SetCoord(Client->Player.lId, x, h, y, face);
}bool NetClient::MoveStop(float x, float h, float y, float face)
{NET_SEND_BUFF _buff;MOVE_DATA_STOP _data;_data.opcode.Set(SC_MOVE_HEADER);_data.Mode.Set(0x0);_data.Count.Set(4);_data.x.Set(x);_data.h.Set(h);_data.y.Set(y);_data.face.Set(face);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::MoveJump(float x, float h, float y, float face, float oldy, float xNext, float yNext)
{NET_SEND_BUFF _buff;MOVE_DATA_JUMP _data;_data.opcode.Set(SC_MOVE_HEADER);_data.Mode.Set(0x2);_data.Count.Set(9);_data.x.Set(x);_data.h.Set(h);_data.y.Set(y);_data.xNext.Set(xNext);_data.yNext.Set(yNext);_data.MoveSpeed.Set(Player.MoveSpeed);_data.JumpSpeed.Set(Player.JumpSpeed);_data.GSpeed.Set(0.0f);_data.face.Set(face);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::MoveWalk(float x, float h, float y, float face, float oldy, float xNext, float yNext)
{NET_SEND_BUFF _buff;MOVE_DATA_WALK _data;_data.opcode.Set(SC_MOVE_HEADER);_data.Mode.Set(0x1);_data.Count.Set(8);_data.x.Set(x);_data.h.Set(h);_data.y.Set(y);_data.xNext.Set(xNext);_data.yNext.Set(yNext);_data.MoveSpeed.Set(Player.MoveSpeed);_data.GSpeed.Set(0.0f);_data.face.Set(face);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::MoveWJump(float x, float h, float y, float face, float oldy, float xNext, float yNext)
{NET_SEND_BUFF _buff;MOVE_DATA_WJUMP _data;_data.opcode.Set(SC_MOVE_HEADER);_data.Mode.Set(0x3);_data.Count.Set(7);_data.x.Set(x);_data.h.Set(h);_data.y.Set(y);_data.xNext.Set(xNext);_data.yNext.Set(yNext);_data.MoveSpeed.Set(Player.MoveSpeed);_data.face.Set(face);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::UseSkill(const char* _skillName, float x, float h, float y, float face, float xTarget, float hTarget, float yTarget, int rInt1, int rInt2, int rInt3)
{NET_SEND_BUFF _buff;USESKILL_DATA _data;_data.opcode.Set(SC_USESKILL);_data.skillName.Set(_skillName);_data.x.Set(x);_data.h.Set(h);_data.y.Set(y);_data.xTarget.Set(xTarget);_data.hTarget.Set(hTarget);_data.yTarget.Set(yTarget);_data.un0.Set(rInt1);_data.un1.Set(rInt2);_data.un2.Set(rInt3);//_data.face.Set(face);_data.face.Set(0);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}PROLEDATA NetClient::GetRoleByName(const wchar_t* rolename)
{//PROLEDATA result = nullptr;for (int i = 0; i < rolecount; i++){// StrCmpW判断两个字符串是否相同// 比较时区分大小写,如果字符串相同返回0if (StrCmpW(roles[i].name.value(), rolename) == 0) {return &roles[i];}}return nullptr;
}bool NetClient::Talk(wchar_t* txt, int PdId, double un)
{NET_SEND_BUFF _buff;CHAT_PUBLIC _data;_data.opcode.Set(SC_CHAT);_data.ChartId.Set(PdId);_data.txt.Set(txt);_data.un.Set(un);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::TalkTo(wchar_t* name, wchar_t* txt, double un)
{NET_SEND_BUFF _buff;CHAT_PRIVATE _data;_data.opcode.Set(SC_CHAT);_data.ChartId.Set(3);_data.txt.Set(txt);_data.name.Set(name);_data.un.Set(un);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::HeartBeep()
{NET_SEND_BUFF _buff;HEART_BEEP _data;_data.opcode.Set(SC_BEEP);_data.tick.Set(3);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::HeartLoop()
{NET_SEND_BUFF _buff;HEART_LOOP _data;_data.opcode.Set(SC_LOOP);_data.tick.Set(GetTickCount64());_data.txt.Set("");/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::Backtoroles()
{// 返回角色NET_SEND_BUFF _buff;NSR_CHEAD _data;_data.opcode.Set(SC_REONLINE);/*sizeof(_data) / sizeof(EnCode)的原因NET_SEND_CHOOSECAMP结构体里面,没别 东西全是 EnCode 这个结构*/short count = sizeof(_data) / sizeof(EnCode);_buff.count = count;/*CodeMe函数给 _buff.buff里写数据参数的数据也就是给0A开头数据包里写,数据参数个数后面的内容然后返回值是写了多长的数据也就是给0A开头数据包里的数据参数个数后面的数据写了多长*/int ilen = _data.CodeMe(count, _buff.buff);ilen = ilen + sizeof(NET_SEND_HEAD) - 1;return WinSock->OnSend(&_buff.op, ilen);
}bool NetClient::DelRole(const wchar_t* rolename, unsigned _len)
{DATA_DELROLE _data;_data.op = 0x06;_data.len = _len;memcpy(_data.buff, rolename, _len);return WinSock->OnSend((char*)&_data, sizeof(DATA_DELROLE) - 1);
}PAIM NetClient::GetAimById(long long lId)
{if (Player.lId == 0)return &Player;// 我们玩家的数据未初始化其它的也不能初始化if (Player.lId == lId)return &Player;for (int i = 0; i < MAX_AIM; i++){if ((Aimlst[i] != nullptr) && (Aimlst[i]->lId == lId)) {return Aimlst[i];}}return CreateAim(lId);
}PAIM NetClient::CreateAim(long long lId)
{for (int i = 0; i < MAX_AIM; i++){if (Aimlst[i] == nullptr) {Aimlst[i] = new AIM();Aimlst[i]->lId = lId;return Aimlst[i];}else if (Aimlst[i]->Isfree) {Aimlst[i]->lId = lId;return Aimlst[i];}}return nullptr;
}void NetClient::RemoveAimById(long long lId)
{for (int i = 0; i < MAX_AIM; i++){if ((Aimlst[i] != nullptr) && (Aimlst[i]->lId == lId)) {// CString _txt;// _txt.Format(L"附近的 %s 消失", Aimlst[i]->Name);// AfxMessageBox(_txt);Aimlst[i]->Release();}}
}POBJECTBASE NetClient::GetGameOBJECT(short MainIndex, short Index)
{switch (MainIndex){case 1:return Equip[Index];case 2:return ItemBag[Index];case 3:return ItemEx[Index];case 8:return MountBag[Index];case 0x28:return Skill[Index];}return nullptr;
}void NetClient::ReSetGameOBJECT(short MainIndex, short max)
{max = max + 1;switch (MainIndex){case 1: // 装备栏,18 01 是装备if (Equip != nullptr) delete[] Equip;if (EquipAry != nullptr) delete[] EquipAry;Equip = new PITEM[max];EquipAry = new ITEM[max];EquipMax = max;for (int i = 0; i < EquipMax; i++) Equip[i] = &EquipAry[i];break;case 2: // 物品栏,18 02 是角色背包if (ItemBag != nullptr) {delete[] ItemBag;}if (ItemBagAry != nullptr) delete[] ItemBagAry;ItemBag = new PITEM[max];ItemBagAry = new ITEM[max];ItemMax = max;for (int i = 0; i < ItemMax; i++) ItemBag[i] = &ItemBagAry[i];break;case 3: // 扩展栏,18 03 是扩展背包if (ItemEx != nullptr) {delete[] ItemEx;}if (ItemExAry != nullptr) delete[] ItemExAry;ItemEx = new PITEM[max];ItemExAry = new ITEM[max];ItemExMax = max;for (int i = 0; i < ItemExMax; i++) ItemEx[i] = &ItemExAry[i];break;case 8: // 坐骑栏,18 08 是坐骑背包if (MountBag != nullptr) {delete[] MountBag;}if (MountBagAry != nullptr) delete[] MountBagAry;MountBag = new PITEM[max];MountBagAry = new ITEM[max];MountMax = max;for (int i = 0; i < MountMax; i++) MountBag[i] = &MountBagAry[i];break;case 0x28: // 技能栏,18 28 是技能信息if (Skill != nullptr) {delete[] Skill;}if (SkillAry != nullptr) delete[] SkillAry;Skill = new PSKILL[max];SkillAry = new SKILL[max];SkillMax = max;for (int i = 0; i < SkillMax; i++) Skill[i] = &SkillAry[i];break;}
}void NetClient::ExChangeOBJECT(short MainIndex, short IndexFrom, short IndexTo)
{POBJECTBASE* _base = nullptr;switch (MainIndex){case 1: // 装备栏,18 01 是装备_base = Equip;break;case 2: // 物品栏,18 02 是角色背包_base = ItemBag;break;case 3: // 扩展栏,18 03 是扩展背包_base = ItemEx;break;case 8: // 坐骑栏,18 08 是坐骑背包_base = MountBag;break;case 0x28: // 技能栏,18 28 是技能信息_base = (POBJECTBASE*)Skill;break;default:return;}POBJECTBASE _tmp = _base[IndexFrom];_base[IndexFrom] = _base[IndexTo];_base[IndexTo] = _tmp;
}void NetClient::DestoryOBJECT(short MainIndex, short Index)
{POBJECTBASE base = GetGameOBJECT(MainIndex, Index);if (base)base->Isfree = true;
}PAIM NetClient::GetAimByName(const wchar_t* name)
{for (int i = 0; i < MAX_AIM; i++){if ((Aimlst[i] != nullptr) && (!Aimlst[i]->Isfree) && (Aimlst[i]->Name == name)) {return Aimlst[i];}}return nullptr;
}// x,y是玩家的坐标,targetX,targetY是目标的坐标
float NetClient::GetFace(float x, float y, float targetX, float targetY)
{// 计算差值x = targetX - x;y = targetY - y;double pi = 3.14159265358979323846;double p = atan2(x, y); // atan2是计算三角形弧度atan2函数返回值-pi ~ pi,负的3.1415926...到正的3.1415926...// 如果x是负数atan2函数返回值必定是在三四象限里,也就是一个负πif (x < 0) {p = pi * 2 + p;}return p;
}void NetClient::FaceTo(const wchar_t* name)
{PAIM _aim = GetAimByName(name);if (_aim) {float _face = GetFace(Player.x, Player.y, _aim->x, _aim->y);MoveStop(Player.x, Player.h, Player.y, _face);}
}void NetClient::Init(GameWinSock* _winSock)
{for (int i = 0; i < 0x100; i++) {SendProc[i] = &NetClient::DefaultProc;RecvProc[i] = &NetClient::DefaultProc;}this->WinSock = _winSock;// 注册登录数据包处理函数SendProc[I_LOGIN] = &NetClient::OnClientlogin;SendProc[I_CREATEROLE_START] = &NetClient::OnClientStartCreateRole;SendProc[I_DELROLE] = &NetClient::OnClientDelRole;SendProc[I_SEND_CUSTOM] = &NetClient::OnClientSendCustom;SendProc[I_CREATEROLE] = &NetClient::OnClientCreateRole;SendProc[I_SELECT_ROLE] = &NetClient::OnClientSelectRole;// 注册数据登录失败数据包处理函数RecvProc[S_TIPS] = &NetClient::OnSvrTips;RecvProc[S_LOGINOK] = &NetClient::OnSvrloginOk;RecvProc[S_CREATEROLE_START] = &NetClient::OnSvrStartCreateRole;RecvProc[S_NOTICE] = &NetClient::OnSverNotice;RecvProc[S_NOTICE_COM] = &NetClient::OnSverNotice;RecvProc[S_OBJECT] = &NetClient::OnSverObject;RecvProc[S_STRUCT] = &NetClient::OnSverStruct;RecvProc[S_OBJECT_INIT] = &NetClient::OnSvrObjectInit;RecvProc[S_OBJECT_INITEX] = &NetClient::OnSvrObjectInitEx;RecvProc[S_OBJECT_INITEX_UCOM] = &NetClient::OnSvrObjectInitEx;RecvProc[S_UPDATECORD] = &NetClient::OnSvrUpdateCord;RecvProc[S_UPDATEPRO] = &NetClient::OnSvrUpdateProperty;RecvProc[S_UPDATEPROMU] = &NetClient::OnSvrUpdatePropertyMu;RecvProc[S_UPDATEPROMU_COM] = &NetClient::OnSvrUpdatePropertyMu;RecvProc[S_OBJECT_REMOVE] = &NetClient::OnSvrRemoveObjectMu;RecvProc[S_UPDATECORDEX] = &NetClient::OnSvrUpdateCordEx;RecvProc[S_GAMEBASE] = &NetClient::OnSvrGameBase;RecvProc[S_GAMEBASE_RESET] = &NetClient::OnSvrGameBaseReset;RecvProc[S_GAMEBASE_EXCHANGE] = &NetClient::OnSvrGameBaseExChange;RecvProc[S_GAMEBASE_DROP] = &NetClient::OnSvrGameBaseDestroy;
}bool NetClient::SetCoord(long long lId, float x, float h, float y, float face)
{NR_UPDATECOORD head;head.lId = lId;head.x = x;head.h = h;head.y = y;head.face = face;return WinSock->Recv(&head.op, head.len);
}bool NetClient::SetProperty(long long lId, int ProType, void* value)
{NR_OBJECT_UPDATEPRO head;head.lId = lId;head.itype = ProType;int valueType = ObjectTable[ProType].type;int valueSize = data_desc[2][valueType].lenth;int bufflen = 14;switch (valueType){case 1:case 2:case 3:case 4:case 5:case 6:case 9:memcpy(head.buff, value, valueSize);bufflen = bufflen + valueSize;break;case 7:head.lenth = strlen((char*)value) + 1;memcpy(head.buffEnd, value, head.lenth);bufflen = bufflen + 4 + head.lenth;break;case 8:head.lenth = wcslen((wchar_t*)value) + 1;head.lenth = head.lenth + 2;memcpy(head.buffEnd, value, head.lenth);bufflen = bufflen + 4 + head.lenth;break;default:break;}return WinSock->Recv(&head.op, bufflen);
}bool NetClient::OnDelRole(wchar_t* rolename, unsigned _len)
{// AfxMessageBox(rolename);return true;
}void NetClient::Onlogin(const char* Id, const char* Pass)
{/*const int bufflen = sizeof(DATA_LOGIN) + 1;char buff[bufflen];DATA_LOGIN data;// 有些操作系统这样写会报错,因为内存不对齐,现在Windows下没事//PDATALOGIN _data = (PDATALOGIN)(buff + 1);// 这样写就能解决内存对齐问题PDATALOGIN _data =&data;int len = strlen(Id);memcpy(_data->Id, Id, len);len = strlen(Pass);memcpy(_data->Pass, Pass, len);memcpy(buff+1, _data, sizeof(DATA_LOGIN));buff[0] = I_LOGIN;return WinSock->OnSend(buff, sizeof(buff));*/
}bool NetClient::OnStartCreateRole(int code)
{return true;
}bool NetClient::OnCreateRole(PNS_CREATEROLE _header, PCREATE_ROLE_DATAS _body)
{return true;
}bool NetClient::OnSendCustom(PNET_SEND_CHEAD _coder, char*& buffer, unsigned& len)
{switch (_coder->opcode.value()){case SC_CHOOSECAMP:return OnChooseCamp((PNS_CHOOSECAMP)_coder);case SC_CHAT:return OnChat((PCHAT_DATA)_coder);case SC_BEEP:return OnHeartBeep((PHEART_BEEP)_coder);case SC_LOOP:return OnHeartLoop((PHEART_LOOP)_coder);case SC_INITED:return OnInited();case SC_REONLINE://case SC_INIT_START://case SC_HAND://case SC_HAND_IN:// return false;case SC_MOVE_HEADER:return OnMove((PMOVE_DATA)_coder);case SC_FALL_HEADER:return OnFall((PFALL_DATA_START)_coder);case SC_INWATER:return false;case SC_USESKILL:return OnUseSkill((PUSESKILL)_coder);default:return true;}return true;
}bool NetClient::OnSelectRole(wchar_t* rolename)
{//AfxMessageBox(rolename);return true;
}bool NetClient::OnChooseCamp(PNS_CHOOSECAMP _coder)
{PNS_CHOOSECAMP _p = (PNS_CHOOSECAMP)_coder;return true;
}bool NetClient::OnChat(PCHAT_DATA _coder)
{switch (_coder->ChartId){case 3:// 私聊return OnChatPrivate((PCHAT_PRV)_coder);case 1:// 附近频道case 2:// 区域频道case 6:// 公会频道case 9:// 阵营频道case 21:// 喊话频道return OnChatPublic((PCHAT_PUB)_coder);break;}return true;
}bool NetClient::OnChatPublic(PCHAT_PUB _coder)
{return true;
}bool NetClient::OnChatPrivate(PCHAT_PRV _coder)
{return true;
}bool NetClient::OnHeartBeep(PHEART_BEEP _coder)
{return true; // 返回false会拦截81心跳包不给服务端发送
}bool NetClient::OnHeartLoop(PHEART_LOOP _coder)
{return true; // 返回false会拦截SC_LOOP心跳包不给服务端发送
}bool NetClient::OnMove(PMOVE_DATA _coder)
{switch (_coder->Mode){case 0:return OnMoveStop((PMOVE_DATA_STOP)_coder);case 1:return OnMoveWalk((PMOVE_DATA_WALK)_coder);case 2:return OnMoveJump((PMOVE_DATA_JUMP)_coder);case 3:return OnMoveWJump((PMOVE_DATA_WJUMP)_coder);}return false;
}// 移动中处理函数
bool NetClient::OnMoveWalk(PMOVE_DATA_WALK _coder)
{/*float* MoveSpeed = (float*)_coder->MoveSpeed.oldPointer;MoveSpeed[0] = 5.0f;*//*if (HideMode) {float* f = (float*)_coder->h.oldPointer;f[0] = f[0] + 5;}*/return true;
}// 停止移动处理函数
bool NetClient::OnMoveStop(PMOVE_DATA_STOP _coder)
{/* if (HideMode) {float* f = (float*)_coder->h.oldPointer;f[0] = f[0] + 5;}*/return true;
}// 跳跃处理函数
bool NetClient::OnMoveJump(PMOVE_DATA_JUMP _coder)
{//float* MoveSpeed = (float*)_coder->MoveSpeed.oldPointer;//MoveSpeed[0] = 5.0f;//if(HideMode) {// float* f = (float*)_coder->h.oldPointer;// f[0] = f[0] + 5;//}return true;
}// 移动时跳跃
bool NetClient::OnMoveWJump(PMOVE_DATA_WJUMP _coder)
{/* float* MoveSpeed = (float*)_coder->MoveSpeed.oldPointer;MoveSpeed[0] = 5.0f;*///if(HideMode) {// float* f = (float*)_coder->h.oldPointer;// f[0] = f[0] + 5;//}return true;
}bool NetClient::OnFall(PFALL_DATA_START _coder)
{return true;
}bool NetClient::OnSvrChat(PCHAT_PRV _coder)
{//AfxMessageBox(_coder->name);//AfxMessageBox(_coder->txt);//switch (_coder->ChartId)//{//case 3:// 私聊// return OnChatPrivate((PCHAT_PRV)_coder);//case 1:// 附近频道//case 2:// 区域频道//case 6:// 公会频道//case 9:// 阵营频道//case 21:// 喊话频道// return OnChatPublic((PCHAT_PUB)_coder);// break;//}return true;
}bool NetClient::OnUseSkill(PUSESKILL _coder)
{// 无法x坐标无效,会无法释放技能/*float* f = (float*)_coder->x.oldPointer;f[0] = 0;*/return true;
}bool NetClient::OnInited()
{return true;
}bool NetClient::Tips(int code)
{
#ifdef AnlyCString txt;if (code == 51001) {txt = L"登陆失败,易道云通行证不存在!";}else if (code == 51002) {txt = L"登录失败,密码错误!";}else if (code == 21101) {txt = L"人物重名!";}else if (code == 21109) {txt = L"名字过长或包含非法字符!";}else {txt.Format(L"未知登录错误:%d", code);}anly->SendData(TTYPE::I_LOG, 0, txt.GetBuffer(), (txt.GetLength() + 1)*2);
#endifreturn true;
}void NetClient::loginok(ROLE_DATA* _roles, int count)
{logined = true;if(roles) delete[] roles;roles = _roles;rolecount = count;
}bool NetClient::OnScrStartCreateRole(short code, wchar_t* _txt)
{return true;
}bool NetClient::OnSvrNotice(PNET_SEND_CHEAD _coder, int count, char*& buffer, unsigned& len)
{if (_coder->msgHeader == "chat") {return OnSvrChat((PCHAT_PRV)_coder);}return true;
}bool NetClient::OnRecvData(char*& buff, unsigned& len)
{
#ifdef Anlyanly->SendData(TTYPE::I_RECV, buff[0], buff, len);
#endifreturn (this->*RecvProc[buff[0]])(buff, len);
}bool NetClient::OnSendData(char*& buff, unsigned& len)
{
#ifdef Anlyanly->SendData(TTYPE::I_SEND, buff[0], buff, len);
#endifreturn (this->*SendProc[buff[0]])(buff, len);
}bool NetClient::OnConnect(char*& ip, unsigned& port)
{
#ifdef Anly// 长度24的原因,它是宽字节要,一个文字要2个字节,一共是10个文字加上结尾的0是11个// 所以 11 乘以2,然后再加2 anly->SendData(TTYPE::I_LOG, 0, L"服务器正在连接。。。", 24);
#endifreturn true;
}// 默认的数据处理函数
bool NetClient::DefaultProc(char*&, unsigned&)
{return true;
}// 复制过来的内容
bool NetClient::OnClientlogin(char*& buff, unsigned& len)
{PDATALOGIN _data = (PDATALOGIN)(buff + 1);char* _id = _data->Id;_data = (PDATALOGIN)(buff + 1 + _data->lenId - 0x10);char* _pass = _data->Pass;Onlogin(_id, _pass);/* 修改账号密码len = sizeof(DATA_LOGIN) + 1;buff = new char[len];DATA_LOGIN data;PDATALOGIN _data = &data;buff[0] = 0x2;CStringA _id = "";// 补充账号CStringA _pass = "";// 补充密码memcpy(_data->Id, _id.GetBuffer(), _id.GetLength());memcpy(_data->Pass, _pass.GetBuffer(), _pass.GetLength());memcpy(buff + 1, _data, len - 1);*//* 监控登录数据PDATALOGIN _data = (PDATALOGIN)buff;CStringA _id = _data->Id;_data = (PDATALOGIN)(buff + _data->lenId - 0x10);CStringA _pass = _data->Pass;CStringA _tmp;// 请求登录 账号[% s]密码[% s] 这个内容别人在逆向的时候就会看到// 所以这种东西需要自己搞个编码来代替它_tmp.Format("请求登录 账号[%s]密码[%s]", _id, _pass);
#ifdef Anlyanly->SendData(TTYPE::I_DIS, 1, _tmp.GetBuffer(), _tmp.GetAllocLength());
#endif*//*返回false,游戏无法发送数据包原因看调用此此函数的位置 OnSend 函数(if (SendDealProc[buff[0]]((buff + 1), len - 1)))*/return true;
}bool NetClient::OnClientStartCreateRole(char*& buff, unsigned& len)
{// 申请进入创建角色界面int* code = (int*)&buff[1];return OnStartCreateRole(code[0]);
}bool NetClient::OnClientCreateRole(char*& buff, unsigned& len) {PNS_CREATEROLE head = (PNS_CREATEROLE)(buff - 3);int icount = head->count;if (icount < 1)return true;char* buffStart = (char*)head + sizeof(NET_SEHD_CREATEROLE_HEAD);
#ifdef AnlyGameAnlyer->AnlyBuff(buffStart, buff + len, buff[0], 1);// 翻译解析约定数据
#endif // AnlyEnCode codes[sizeof(CREATE_ROLE_DATAS) / sizeof(EnCode)]{};int stDecode = 0;while (stDecode < icount) {codes[stDecode++] = buffStart;}/*Client->OnCreateRole(head, (PCREATE_ROLE_DATAS)codes) 数据包传给虚函数如果想对发送创建角色数据包做些什么直接继承NetClient重写OnCreateRole函数既可以了*/return OnCreateRole(head, (PCREATE_ROLE_DATAS)codes);// 返回false屏蔽05开头的数据包,也就是创建角色发送的数据包
}bool NetClient::OnClientSendCustom(char*& buff, unsigned& len) {PNET_SEND_HEAD head = (PNET_SEND_HEAD)(buff - 1);int icount = head->count;if (icount < 1)return true;char* buffStart = (char*)head + sizeof(NET_SEND_HEAD);if (buffStart[0] != 0x02) {#ifdef Anlyif (icount < MAX_SEND_COUNT)anly->SendData(TTYPE::I_DIS, I_SEND_CUSTOM, "SEND_CUSTOM MAX_SEND_COUNT 内存解码器空间不足", 46);anly->SendData(TTYPE::I_DIS, I_SEND_CUSTOM, "SEND_CUSTOM 发现异常数据", 25);
#endifreturn true;}#ifdef AnlyGameAnlyer->AnlyBuff(buffStart, buff + len, buff[0], 1);
#endifint stDecode = 0;EnCode codes[MAX_SEND_COUNT]{};while (stDecode < icount) {codes[stDecode++] = buffStart;}/*Client->OnSendCustom((PNET_SEND_CHEAD)codes, buff, len); 数据包传给虚函数如果想对发送数据的0A开头的据包做些什么直接继承NetClient重写OnSendCustom函数既可以了*/return Client->OnSendCustom((PNET_SEND_CHEAD)codes, buff, len);}bool NetClient::OnClientSelectRole(char*& buff, unsigned& len) {PNS_SELECTROLE p = (PNS_SELECTROLE)buff;return Client->OnSelectRole((wchar_t*)(p->buff));
}bool NetClient::OnClientDelRole(char*& buff, unsigned& len) {PDATADELROLE p = (PDATADELROLE)buff;return Client->OnDelRole((wchar_t*)(p->buff), p->len);// 返回值改为false将拦截发送的删除角色数据包// 详情看注册 OnDelRole 函数的位置,Init函数// return true;
}// 接收数据截取区bool NetClient::OnSvrTips(char*& buff, unsigned& len) {int* code = (int*)&buff[1];return Client->Tips(code[0]);
}bool NetClient::OnSvrloginOk(char*& buff, unsigned& len) {PDATALOGINOK _p = (PDATALOGINOK)&buff[1];ROLE_DATA* roleDatas = nullptr;if (_p->RoleCount > 0) {char* buffStart = buff + 1 + sizeof(DATA_LOGIN_OK);#ifdef AnlyGameAnlyer->AnlyBuff(buffStart, buff + len, buff[0]);
#endif // AnlyroleDatas = new ROLE_DATA[_p->RoleCount];for (int i = 0; i < _p->RoleCount; i++){roleDatas[i].byte.Init(buffStart, 0);roleDatas[i].index.Init(buffStart, 0);roleDatas[i].un1.Init(buffStart, 0);roleDatas[i].name.Init(buffStart, 0);roleDatas[i].infos.Init(buffStart, 0);roleDatas[i].un2.Init(buffStart, 0);roleDatas[i].un3.Init(buffStart, 0);}Client->loginok(roleDatas, _p->RoleCount);}return true;
}bool NetClient::OnSverObject(char*& buff, unsigned& len) {PNR_HEAD head = (PNR_HEAD)(buff - 1);//head->count;if (ObjectTable) {delete[] ObjectTable;}if (ObjectTxt) {delete[] ObjectTxt;}ObjectTable = new OBJECT_DESC[head->count];ObjectTxt = new char[len];memcpy(ObjectTxt, buff, len);// 这里怕 buff 的内容被游戏释放掉,后面我们用的时候没法用,所以把buff的内容复制到我们的变量里char* buffStart = ObjectTxt + sizeof(NR_HEAD)-1;
//#ifdef Anly
// CStringA szTxtA;
// CStringA szTmp;
//#endif // Anly
//#ifdef Anly
// szTmp.Format("[%X]%s:%d\r\n", i, ObjectTable[i].name, ObjectTable[i].type);
// szTxtA += szTmp;
//#endif // Anly
//#ifdef Anly
// anly->SendData(TTYPE::I_DIS, S_OBJECT, szTxtA.GetBuffer(), szTxtA.GetAllocLength() + 1);
//#endif // Anlyfor (int i = 0; i < head->count; i++){ObjectTable[i].name = buffStart;buffStart = buffStart + strlen(ObjectTable[i].name) + 1;ObjectTable[i].type = buffStart[0];buffStart++;}#ifdef AnlyGameAnlyer->CreateObjectfiles(ObjectTable, head->count);
#endif // Anlyreturn true;
}
bool NetClient::OnSverStruct(char*& buff, unsigned& len) {PNR_HEAD head = (PNR_HEAD)(buff - 1);if (StructTable) {delete[] StructTable;}if (StructTxt) {delete[] StructTxt;}StructTable = new STRUCT_DESC[head->count];StructTxt = new char[len];memcpy(StructTxt, buff, len);char* buffStart = StructTxt + sizeof(NR_HEAD) - 1;for (int i = 0; i < head->count; i++){StructTable[i].name = buffStart;buffStart = buffStart + strlen(StructTable[i].name) + 1;short* icount = (short*)buffStart;StructTable[i].count = icount[0];buffStart = buffStart + 2;StructTable[i].buff = buffStart;buffStart = buffStart + icount[0];}#ifdef AnlyGameAnlyer->CreateStructfile(StructTable, head->count);
#endif // Anlyreturn true;
}
bool NetClient::OnSvrObjectInit(char*& buff, unsigned& len)
{/*00 00 00 00 00 00 00 为了内存对齐补充了7个0,也就是 un1[6] 和 len28 opCD 48 00 01 62 A7 DE 04 PNR_OBJINIT:lIdC1 AA FB C3 PNR_OBJINIT:x;3D FF 22 41 PNR_OBJINIT:h;D7 0B 4A 44 PNR_OBJINIT:y;52 B8 06 40 PNR_OBJINIT:face;C1 AA FB C3 PNR_OBJINIT:tx;3D FF 22 41 PNR_OBJINIT:th;D7 0B 4A 44 PNR_OBJINIT:ty;52 B8 06 40 PNR_OBJINIT:tface;00 00 00 00 PNR_OBJINIT:un2[0]00 00 00 00 PNR_OBJINIT:un2[1]00 00 00 00 PNR_OBJINIT:un2[2]00 00 00 00 PNR_OBJINIT:un2[3]00 00 00 00 PNR_OBJINIT:un2[4]61 00 PNR_OBJINIT:icount;1B 00 (char*)head + sizeof(NR_OBNJECT_INIT) - 2;也就是指向到了 PNR_OBJINIT:type 这个位置0C 00 00 00 CA 4E 5A 66 53 62 01 80 4E 86 00 00 1D 00*/// 初始化对象PNR_OBJINIT head = (PNR_OBJINIT)(buff - 7);char* buffStart = (char*)head + sizeof(NR_OBNJECT_INIT) - 2;//int nStart = (int)&Player.lId;//int nEnd = (int)&Player.endclass;//memcpy(&Player.lId, &head->lId, nEnd - nStart);Player.SetHeadDatas(&head->lId);
#ifdef AnlyGameAnlyer->AnlyData(buffStart, buff + len, head->icount, S_OBJECT_INIT, ObjectTable);
#endifint iProc = 0;while (iProc < head->icount){Player.UpdateData(buffStart);iProc++;}return true;
}
bool NetClient::OnSvrObjectInitEx(char*& buff, unsigned& len)
{// 初始化对象PNR_OBJINITEX head = (PNR_OBJINITEX)(buff - 5);char* buffStart;/*int nStart = (int)&Player.lId;int nEnd = (int)&Player.endclass;memcpy(&Player.lId, &head->lId, nEnd - nStart);*/int iObjectCount = 0;short objCount = head->obj_count; // 可以理解为一共有多少个接收的28数据while (iObjectCount < objCount) {PAIM _paim = GetAimById(head->lId);_paim->SetHeadDatas(&head->lId);buffStart = (char*)head + sizeof(NR_OBNJECT_INITEX) - 2;short refCount = head->icount; // 接收的28数据里的数据参数个数short iref = 0;
#ifdef AnlyGameAnlyer->AnlyData(buffStart, buff + len, refCount, S_OBJECT_INITEX, ObjectTable);
#endifwhile (iref < refCount) {_paim->UpdateData(buffStart);iref++;}head = (PNR_OBJINITEX)(buffStart - 8);iObjectCount++;}return true;
}
bool NetClient::OnSvrUpdateCord(char*& buff, unsigned& len)
{/*00 00 00 00 00 head21 02 00 CD 14 00 01 CD 14 00 00 第一个坐标数据6D BF 54 43 A6 FA C7 3F 8C 52 A9 C1 CB 30 06 40 00 00 00 00 DB 0F C9 41 00 00 00 00 00 00 00 00 01 00 00 00 StateCD 14 00 01 CD 14 00 00 第二个坐标数据61 41 5B 43 A6 FA C7 3F C5 8A C7 C1 CB 30 06 40 9A 99 99 3E DB 0F C9 40 00 00 00 00 00 00 00 00 01 00 00 00 */// 初始化对象PNR_OBJINITEX head = (PNR_OBJINITEX)(buff - 5);/*int nStart = (int)&Player.lId;int nEnd = (int)&Player.endclass;memcpy(&Player.lId, &head->lId, nEnd - nStart);*/int iObjectCount = 0;short objCount = head->obj_count; // 可以理解为一共有多少个接收的28数据while (iObjectCount < objCount) {PAIM _paim = GetAimById(head->lId);_paim->SetHeadDatas(&head->lId);CStringA txtA;txtA.Format("x:%f h:%f y:%f", head->x, head->h, head->y);
#ifdef Anlyanly->SendData(TTYPE::I_DIS, S_UPDATECORD, txtA.GetBuffer(), txtA.GetAllocLength() + 1);
#endifhead = (PNR_OBJINITEX)((char*)&head->State - 4);iObjectCount++;}return true;
}
bool NetClient::OnSvrUpdateProperty(char*& buff, unsigned& len)
{// 初始化对象PNR_OBJECT_UP head = (PNR_OBJECT_UP)(buff - 6);PGAMEOBJ _object = nullptr;char* buffStart = (char*)&head->itype;short refcount = head->icount;int iref = 0;
#ifdef AnlyGameAnlyer->AnlyData(buffStart, buff + len, refcount, S_UPDATEPRO, ObjectTable);
#endifif (head->MsgId ) {_object = GetGameOBJECT(head->Index[0], head->Index[1]);}else {_object = GetAimById(head->lId);}while ((iref < refcount)&&(_object)) {_object->UpdateData(buffStart);iref++;}return true;
}
bool NetClient::OnSvrUpdatePropertyMu(char*& buff, unsigned& len)
{// 初始化对象PNR_OBJECT_UPMU head = (PNR_OBJECT_UPMU)(buff - 5);int iobjCount = 0;short objCount = head->objCount; // 可以理解为一共有多少个接收的28数据char* buffStart;/*数据包是下方的样子,2D 01 00 objCount9B 49 00 01 D5 8C 98 05 GetAimById(head->lId);02 00 25 00 (char*)&head->itype18 00 00 00 29 00 BA 01 00 00 while (iobjCount < objCount) 里获取的是9B 49 00 01 D5 8C 98 0502 0025 00 18 00 00 0029 00 BA 01 00 00 这一块数据while (iref++ < refCount) 里获取的是25 00 18 00 00 00(PNR_OBJECT_UPMU)(buffStart - 8); 移动到下一个9B 49 00 01 D5 8C 98 05 GetAimById(head->lId);02 0025 00 (char*)&head->itype18 00 00 0029 00 BA 01 00 00 这个数据*/while (iobjCount < objCount) {PAIM _paim = GetAimById(head->lId);buffStart = (char*)&head->itype;short refCount = head->icount; // 接收的28数据里的数据参数个数short iref = 0;#ifdef AnlyGameAnlyer->AnlyData(buffStart, buff + len, refCount, S_UPDATEPROMU, ObjectTable);
#endifwhile (iref++ < refCount) {_paim->UpdateData(buffStart);}head = (PNR_OBJECT_UPMU)(buffStart - 8);iobjCount++;}return true;
}
bool NetClient::OnSvrRemoveObjectMu(char*& buff, unsigned& len)
{// 初始化对象PNR_OBJECT_REMOVEMU head = nullptr;head = (PNR_OBJECT_REMOVEMU)(buff - &head->op);int iobjCount = head->objCount;for (int i = 0; i < iobjCount; i++){RemoveAimById(head->lId[i]);}return true;
}/*1F87 44 00 01 7F B0 D6 05FE AD DE C36C F5 46 4207 FD 36 C490 D9 9C 40
*/
bool NetClient::OnSvrUpdateCordEx(char*& buff, unsigned& len)
{// 初始化对象PNR_UPDATECOORD head = nullptr;head = (PNR_UPDATECOORD)(buff - &head->op);PAIM aim = GetAimById(head->lId);if (aim) {return aim->SetHeadCord(&head->lId);}return true;
}
bool NetClient::OnSvrGameBase(char*& buff, unsigned& len)
{// 初始化对象PNR_GAMEBASE head = nullptr; head = (PNR_GAMEBASE)(buff - &head->op);char* buffStart = (char*)head + sizeof(NR_GAMEBASE);//int nStart = (int)&Player.lId;//int nEnd = (int)&Player.endclass;//memcpy(&Player.lId, &head->lId, nEnd - nStart);//Player.SetHeadDatas(&head->lId);
#ifdef AnlyCStringA szTxt;szTxt.Format("%X %X", head->type, head->index);anly->SendData(TTYPE::I_DIS, S_GAMEBASE, szTxt.GetBuffer(), szTxt.GetAllocLength() + 1);GameAnlyer->AnlyData(buffStart, buff + len, head->count, S_GAMEBASE, ObjectTable);
#endifPOBJECTBASE object = GetGameOBJECT(head->type, head->index);if (object == nullptr)return true;object->MainIndex = head->type;object->Index = head->index;int iProc = 0;while (iProc < head->count){object->UpdateData(buffStart);iProc++;}return true;
}
bool NetClient::OnSvrGameBaseReset(char*& buff, unsigned& len)
{PNR_GAMEBASE_RESET head = nullptr;head = (PNR_GAMEBASE_RESET)(buff - &head->op);ReSetGameOBJECT(head->type, head->max);return true;
}
bool NetClient::OnSvrGameBaseExChange(char*& buff, unsigned& len)
{PNR_GAMEBASE_EXCHANGE head = nullptr;head = (PNR_GAMEBASE_EXCHANGE)(buff - &head->op);ExChangeOBJECT(head->MainIndex, head->IndexFrom, head->IndexTo);return true;
}
bool NetClient::OnSvrGameBaseDestroy(char*& buff, unsigned& len)
{PNR_GAMEBASE_DROP head = nullptr;head = (PNR_GAMEBASE_DROP)(buff - &head->op);DestoryOBJECT(head->MainIndex, head->Index);return true;
}
/*OnSverrNotice函数处理的数据包格式如下1E 06 0006 11 00 00 00 70 6C 61 79 5F 70 6F 69 6E 74 5F 73 6F 75 6E 64 0006 01 00 00 00 0004 2C 92 87 C504 FA 03 BF 4204 33 14 BD 4502 00 00 00 001E 06 00 是 PNR_NOTICE_HEAD06 11 00 00 00 70 6C 61 79 5F 70 6F 69 6E 74 5F 73 6F 75 6E 64 00是一个EnCode06 01 00 00 00 00是一个EnCode04 2C 92 87 C5是一个EnCode04 FA 03 BF 42是一个EnCode04 33 14 BD 45是一个EnCode02 00 00 00 00是一个EnCode
*/
bool NetClient::OnSverNotice(char*& buff, unsigned& len) {PNR_NOTICE_HEAD head = (PNR_NOTICE_HEAD)(buff - 1);int icount = head->count;char* buffStart = (char*)head + sizeof(NR_NOTICE_HEAD);if (icount < 1) {return true;}if (icount > MAX_RECV_COUNT) {
#ifdef Anlyanly->SendData(TTYPE::I_DIS, S_NOTICE, "S_NOTICE 解码器内存不足", 24);
#endifreturn true;}#ifdef AnlyGameAnlyer->AnlyBuff(buffStart, buff + len, buff[0], 1);
#endifint stDecode = 0;EnCode codes[MAX_RECV_COUNT]{};while (stDecode < icount) {codes[stDecode++] = buffStart;}return Client->OnSvrNotice((PNET_SEND_CHEAD)codes, icount, buff, len);
}bool NetClient::OnSvrStartCreateRole(char*& buff, unsigned& len) {short* _st = (short*)&buff[1];wchar_t* _txt = (wchar_t*)&buff[3];
#ifdef AnlyCString txt;CStringA txtA;txt.Format(L"code:%d\r\n%s", _st[0], _txt);txtA = txt;//AfxMessageBox(txtA);anly->SendData(TTYPE::I_DIS, S_CREATEROLE_START, txtA.GetBuffer(), txt.GetAllocLength() + 1);
#endif/*Client->OnSendCustom((PNET_SEND_CHEAD)codes, buff, len); 数据包传给虚函数如果想对0A开头的据包做些什么直接继承NetClient重写OnSendCustom函数既可以了*/return Client->OnScrStartCreateRole(_st[0], _txt);
}
NetClient.h文件的修改:新加 OnSvrGameBaseExChange函数、OnSvrGameBaseDestroy函数、ExChangeOBJECT函数、DestoryOBJECT函数、EquipAry变量、MountBagAry变量、ItemBagAry变量、ItemExAry变量、SkillAry变量,修改了 Equip变量、MountBag变量、ItemBag变量、ItemEx变量、Skill变量
#pragma once
#include "NetClass.h"
#include "GameWinSock.h"
#include "AIM.h"
#include "ITEM.h"
#include "SKILL.h"#define CAMP_NAME_QH "xuanrenQH"
#define CAMP_NAME_ZE "xuanrenZQ"#define MAX_AIM 0x200class NetClient // 监视客户端每一个操作
{typedef bool (NetClient::* DATAPROC)(char*&, unsigned&);
public:AIM Player; // 玩家角色/* 怪物列表,最好排序,使用lId排序,然后使用二分查找实现快速查询结构用链表或者数组都可以怪物或附近玩家这种东西不可能会很多如果太多电脑处理不过来,所以数组设置为0x100大小差不多够用*/PAIM Aimlst[MAX_AIM]{};// 用来控制飞天bool HideMode;/*18 01 是装备18 02 是角色背包18 03 是扩展背包18 08 是坐骑背包18 31 是攻击技能18 28 是移动类型技能*/PITEM* Equip = nullptr; // 装备栏,18 01 是装备,用于列表交换PITEM* MountBag = nullptr; // 坐骑栏,18 08 是坐骑背包,用于列表交换PITEM* ItemBag = nullptr; // 物品栏,18 02 是角色背包,用于列表交换PITEM* ItemEx = nullptr; // 扩展栏,18 03 是扩展背包,用于列表交换PSKILL* Skill = nullptr; // 技能栏,18 28 是技能信息,用于列表交换short EquipMax = 0; // 装备栏数据个数short MountMax = 0; // 坐骑栏数据个数short ItemMax = 0; // 物品栏数据个数short ItemExMax = 0; // 扩展栏数据个数short SkillMax = 0; // 技能栏数据个数PITEM EquipAry = nullptr; // 装备栏,18 01 是装备,用于存放真正的数据PITEM MountBagAry = nullptr; // 坐骑栏,18 08 是坐骑背包,用于存放真正的数据PITEM ItemBagAry = nullptr; // 物品栏,18 02 是角色背包,用于存放真正的数据PITEM ItemExAry = nullptr; // 扩展栏,18 03 是扩展背包,用于存放真正的数据PSKILL SkillAry = nullptr; // 技能栏,18 28 是技能信息,用于存放真正的数据protected:PSTRUCT_DESC StructTable = nullptr;char* StructTxt = nullptr;POBJ_DESC ObjectTable = nullptr;// 游戏的数据类型表char* ObjectTxt = nullptr;DATAPROC SendProc[0x100];DATAPROC RecvProc[0x100];bool DefaultProc(char*&, unsigned&);
protected: // 消息处理函数-SENDbool OnClientlogin(char*& buff, unsigned& len); // 登录数据包的处理 I_LOGINbool OnClientStartCreateRole(char*& buff, unsigned& len); // 申请进入创建角色界面 I_CREATEROLE_STARTbool OnClientDelRole(char*& buff, unsigned& len);bool OnClientSendCustom(char*& buff, unsigned& len);bool OnClientCreateRole(char*& buff, unsigned& len);bool OnClientSelectRole(char*& buff, unsigned& len);
protected: // 消息处理函数-RECVbool OnSvrTips(char*& buff, unsigned& len);bool OnSvrloginOk(char*& buff, unsigned& len);bool OnSvrStartCreateRole(char*& buff, unsigned& len);bool OnSverNotice(char*& buff, unsigned& len);bool OnSverObject(char*& buff, unsigned& len);bool OnSverStruct(char*& buff, unsigned& len);bool OnSvrObjectInit(char*& buff, unsigned& len);bool OnSvrObjectInitEx(char*& buff, unsigned& len);bool OnSvrUpdateCord(char*& buff, unsigned& len);bool OnSvrUpdateProperty(char*& buff, unsigned& len);bool OnSvrUpdatePropertyMu(char*& buff, unsigned& len);bool OnSvrRemoveObjectMu(char*& buff, unsigned& len);bool OnSvrUpdateCordEx(char*& buff, unsigned& len);bool OnSvrGameBase(char*& buff, unsigned& len);bool OnSvrGameBaseReset(char*& buff, unsigned& len);bool OnSvrGameBaseExChange(char*& buff, unsigned& len);bool OnSvrGameBaseDestroy(char*& buff, unsigned& len);
public:PROLEDATA roles;unsigned rolecount;bool logined = false;
private:GameWinSock* WinSock;bool DelRole(const wchar_t* rolename, unsigned _len);PAIM GetAimById(long long lId);PAIM CreateAim(long long lId);void RemoveAimById(long long lId);POBJECTBASE GetGameOBJECT(short MainIndex, short Index);// 获取一个物品或技能void ReSetGameOBJECT(short MainIndex, short max);// 交换物品void ExChangeOBJECT(short MainIndex, short IndexFrom, short IndexTo);// 删除物品void DestoryOBJECT(short MainIndex, short Index);
public:// 通过角色名获取附近角色的信息PAIM GetAimByName(const wchar_t* name);// 获取面向float GetFace(float x, float y, float targetX, float targetY);// 通过附近角色名获取它的信息,然后通过它的信息里的坐标,再通过我们角色坐标计算面向,效果就是面向 GetAimByName(name); 这个角色void FaceTo(const wchar_t* name);
public:void virtual Init(GameWinSock * _winSock);// 模拟接收的数据包bool SetCoord(long long lId, float x, float h, float y, float face);bool SetProperty(long long lId, int ProType, void* value);/*模拟登陆的方法Id是账号Pass是密码它要基于发送的方法实现,因为我们没有连接socket的操作*/bool login(const char* Id, const char* Pass);bool DelRole(const wchar_t* rolename);bool StartCreateRole();// 用于创建角色bool SelectCamp(const char* _campname);// 选择阵营/*性别 0 男 1 女阵营 1 艾森赫特 2 格兰蒂尔种族 1 布冯特人 3 格洛玛人 4 尤恩图人 6 喀什人职业 1 仲裁者 3秘法师 6 猎魔人 8 元素法师脸型 0 1 2 3*/bool CreateRole(wchar_t* name,double sex, double camp, double face, double occu, const char* photo, const char*infos, const char* txt, double faceShape);// 角色创建// 选择角色并且登录进游戏bool SelectRole(const wchar_t* rolename);// 坠落bool Fall();// 瞬移void Teleport(float x, float h, float y, float face);// 模拟停止bool MoveStop(float x, float h, float y, float face);// 原地跳bool MoveJump(float x, float h, float y, float face, float oldy, float xNext, float yNext);// 移动开始bool MoveWalk(float x, float h, float y, float face, float oldy, float xNext, float yNext);// 应该是移动时跳跃bool MoveWJump(float x, float h, float y, float face, float oldy, float xNext, float yNext);// 使用技能bool UseSkill(const char* _skillName, float x, float h, float y, float face, float xTarget = 0, float hTarget = 0, float yTarget = 0, int rInt1 = 0, int rInt2 = 0, int rInt3 = 0);// 根据角色名字获取一个登录成功数据包(选择角色列表里的一个数据)PROLEDATA GetRoleByName(const wchar_t* rolename);bool Talk(wchar_t* txt, int PdId = 1, double un = 0.0);bool TalkTo(wchar_t* name, wchar_t* txt, double un = 0.0);bool HeartBeep();// 心跳数据包(5秒)bool HeartLoop();// 延迟心跳数据包(20秒)bool Backtoroles(); // 返回到选择角色界面
public:// 用于拦截游戏删除角色功能bool virtual OnDelRole(wchar_t* rolename, unsigned _len);// 用于拦截游戏登录功能void virtual Onlogin(const char* Id, const char*Pass);// 用于拦截游戏创建角色功能bool virtual OnStartCreateRole(int code);// 拦截创建角色bool virtual OnCreateRole(PNS_CREATEROLE _header, PCREATE_ROLE_DATAS _body);// opcode意思是操作码,count意思是数量,buffStart意思是解码的内容开始,buffend意思是解码的内容结束,buffer是原始的数据,len是原始数据的长度// char& buffer, int& len这俩参数带&的原因是,在 OnSendCustom 里进行修改之后,通过&的方式传递回去bool virtual OnSendCustom(PNET_SEND_CHEAD _coder, char*& buffer, unsigned& len);// 拦截0xA开头发送的数据包bool virtual OnSelectRole(wchar_t* rolename);
public:// 针对SendCustom的单独处理bool virtual OnChooseCamp(PNS_CHOOSECAMP _coder);bool virtual OnChat(PCHAT_DATA _coder);bool virtual OnChatPublic(PCHAT_PUB _coder);bool virtual OnChatPrivate(PCHAT_PRV _coder);bool virtual OnHeartBeep(PHEART_BEEP _coder);bool virtual OnHeartLoop(PHEART_LOOP _coder);// 分发移动处理函数bool virtual OnMove(PMOVE_DATA _coder);// 移动中处理函数bool virtual OnMoveWalk(PMOVE_DATA_WALK _coder);// 停止移动处理函数bool virtual OnMoveStop(PMOVE_DATA_STOP _coder);// 跳跃处理函数bool virtual OnMoveJump(PMOVE_DATA_JUMP _coder);// 移动时跳跃bool virtual OnMoveWJump(PMOVE_DATA_WJUMP _coder);// 分发坠落函数bool virtual OnFall(PFALL_DATA_START _coder);// 针对Notice的单独处理bool virtual OnSvrChat(PCHAT_PRV _coder);bool virtual OnUseSkill(PUSESKILL _coder);bool virtual OnInited(); // 发送完了964数据包,表示角色上线public:// 处理失败,参数是错误码bool virtual Tips(int code);void virtual loginok(ROLE_DATA* _roles, int count);bool virtual OnScrStartCreateRole(short code,wchar_t* _txt);bool virtual OnSvrNotice(PNET_SEND_CHEAD _coder, int count, char*& buffer, unsigned& len);
public:bool virtual OnRecvData(char*& buff, unsigned& len);bool virtual OnSendData(char*& buff, unsigned& len);bool virtual OnConnect(char*& ip, unsigned& port);};
NetClass.h文件的修改:新加 S_GAMEBASE_DROP宏、S_GAMEBASE_EXCHANGE宏、NR_GAMEBASE_EXCHANGE结构体
#pragma once
#include "EnCode.h"// 数据包头
// 发送
#define I_LOGIN 0x2 // 登录
#define I_CREATEROLE_START 0x3 // 创建角色发送数据包的头
#define I_SELECT_ROLE 0x04 // 选择角色进入游戏的数据包头
#define I_CREATEROLE 0x05 // 创建角色给服务端发送的数据包头
#define I_DELROLE 0x6 // 删除角色发送数据包的头
#define I_SEND_CUSTOM 0x0A // 进入游戏之后大部分数据包的头// 接收
#define S_TIPS 0x3 // 服务端返回错误的数据包头
#define S_LOGINOK 0x4 // 登录成功的返回数据包的头
// 创建角色服务端反馈的数据(发送03 01 00 00 00这个数据包服务端返回的数据包头)
#define S_CREATEROLE_START 0x05
#define S_OBJECT 0x9 // 数据类型表
#define S_STRUCT 0xA // 里面有玩家角色坐标信息,进入游戏时它有数据结构描述的信息
#define S_UPDATEPRO 0x10 // 更新角色怪物信息
#define S_GAMEBASE_RESET 0x15 // 通知更新数据
#define S_GAMEBASE 0x18 // 杂项数据包,里面有技能的信息、装备的信息 还有未知的信息
#define S_GAMEBASE_DROP 0x19 // 删除物品
#define S_NOTICE 0x1E // 里面有聊天数据
#define S_UPDATECORDEX 0x1F // 坐标修正
#define S_UPDATECORD 0x21 // 坐标更新
#define S_NOTICE_COM 0x27 // 里面有聊天数据
#define S_OBJECT_INIT 0x28 // 里面有角色基础信息
#define S_GAMEBASE_EXCHANGE 0x2B // 物品交换
#define S_UPDATEPROMU 0x2D // 更新信息
#define S_UPDATEPROMU_COM 0x2E // 更新信息
#define S_OBJECT_INITEX_UCOM 0x2F // 里面有附近NPC、玩家初始化信息,与0x30数据包一样只是它未压缩
#define S_OBJECT_INITEX 0x30 // 里面有附近NPC、玩家初始化信息
#define S_OBJECT_REMOVE 0x31 // 附近角色或怪物消失/*最多的数据项, 0A开头的数据包里有数据参数个数,这个宏就是用来设定数据参数个数最大数量是多少,0A开头的数据包目前见过最大数据参数个数是十几个,这里写20应该完全够用,如果不够用到时候再增加
*/
#define MAX_SEND_COUNT 100
#define MAX_RECV_COUNT 100
// 发送数据操作码定义
#define SC_CHOOSECAMP 591 // 阵营选择操作码
#define SC_CHAT 1
#define SC_BEEP 81
#define SC_LOOP 1015
// 游戏客户端处理完进入游戏按钮触发的数据包之后,发送的请求
#define SC_INITED 964
#define SC_REONLINE 860
#define SC_INIT_START 661
#define SC_HAND 962
#define SC_HAND_IN 102#define SC_MOVE_HEADER 15 // 移动
#define SC_FALL_HEADER 890 // 坠入摔血
#define SC_INWATER 478 // 只要发了这个数据包就说明在水下了
#define SC_USESKILL 211 // 使用技能/*交换物品的数据包00 为了内存对齐补个02B 02 00 04 00 06 00丢弃接收的数据包00 为了内存对齐补个01902 0004 00
*/
typedef struct NR_GAMEBASE_EXCHANGE {char un;char op = S_GAMEBASE_EXCHANGE;short MainIndex;union {short IndexFrom;short Index;};short IndexTo;
}NR_GAMEBASE_DROP, *PNR_GAMEBASE_DROP, *PNR_GAMEBASE_EXCHANGE;/*00 为了内存对齐补个015 40 00 0E 00 01 00 FA 01 0E 00 00 00 ------------------------------------------00 为了内存对齐补个01828 0013 0005 00BC 01E8 03 00 00 6101 12 00 00 00 53 6B 69 6C 6C 5F 47 6C 31 32 34 30 5F 30 31 5F 31 00F8 01 01 0007 00 01 00 00 00B6 00 20 4E 00 00
*/
typedef struct NR_GAMEBASE {// 15与18数据包的头部,当前用于技能与装备的结构char un;char op;short type;union {short index;short max;};short count;
}NR_GAMEBASE_RESET, *PNR_GAMEBASE, *PNR_GAMEBASE_RESET;
/*1F87 44 00 01 7F B0 D6 05FE AD DE C36C F5 46 4207 FD 36 C490 D9 9C 40
*/
typedef struct NR_UPDATECOORD {char un[6];char len = sizeof(NR_UPDATECOORD) - 7;char op = S_UPDATECORDEX;long long lId;float x;float h;float y;float face;
}*PNR_UPDATECOORD;/*31 01 00 个数9B 49 00 01 D5 8C 98 05 id内存对齐00 00 00 00 00 31 01 00 // 补五个0与id的8字节对齐9B 49 00 01 D5 8C 98 05
*/
typedef struct NR_OBJECT_REMOVEMU {char un[4];char len;char op = 0x31;short objCount = 0;long long lId[2];// 这里是一个指针,[]里写什么都行
}*PNR_OBJECT_REMOVEMU;
/*角色怪物数据更新结构 2D和2E00 00 00 00 00 2D 01 009B 49 00 01 D5 8C 98 0502 0025 00 18 00 00 0029 00 BA 01 00 00
*/
typedef struct NR_OBJECT_UPDATEPROMU {char un1[4]; // 为了向id数据的8字节对齐char len;char op = 0x2D;short objCount = 0;long long lId;short icount;short itype;
}NR_OBJECT_UPMU, * PNR_OBJECT_UPMU;/*角色怪物基本信息更新 接收的10数据包结构体*/
/*00 00 为了内存对齐补零10 0078 48 00 01 FC 61 79 0501 0029 00 65 09 00 00
*/
typedef struct NR_OBJECT_UPDATEPRO {char un1[5]; // 为了向id数据的8字节对齐char len;char op = 0x10;char MsgId = 0x00;union{long long lId;unsigned Index[2];};short icount = 1;short itype;union{char buff[0x04];int lenth;};char buffEnd[0x196];
}NR_OBJECT_UP, *PNR_OBJECT_UP;
/*角色怪物初始化结构00 00 00 00 00 30 0B 0082 0B 00 01 82 0B 00 0069 59 F8 C367 49 FF 41FE 55 9C 42C6 70 BA 40A8 8F 07 C406 52 58 413B D0 2A 43C6 70 BA 4000 00 20 4100 00 00 0000 00 00 0000 00 00 0004 00 00 0011 00
*/typedef struct NR_OBNJECT_INITEX {char un1[4];char len = sizeof(NR_OBNJECT_INITEX) - 7;char op = 0x30;short obj_count;long long lId;float x;float h;float y;float face;float tx;float th;float ty;float tface;int State;float un2[4]{};short icount;short type;
}*PNR_OBJINITEX;// 角色初始化数据
/*28 opE6 44 00 01 39 0A 63 04 lId6F 3A 07 C4 x49 C8 81 41 h46 1E 40 44 yBC 74 03 40 face6F 3A 07 C4 tx49 C8 81 41 th46 1E 40 44 tyBC 74 03 40 tface00 00 00 00 un[0]00 00 00 00 un[1]00 00 00 00 un[2]00 00 00 00 un[3]00 00 00 00 un[4]5E 00 icount多出来的type是为了内存对齐才写的
*/
typedef struct NR_OBNJECT_INIT {char un1[6];char len = sizeof(NR_OBNJECT_INIT) - 9;char op = 0x28;long long lId;float x;float h;float y;float face;float tx;float th;float ty;float tface;float un2[5]{};short icount;short type;
}*PNR_OBJINIT;
// 保存结构数据描述信息的结构体
typedef struct STRUCT_DESC {char* name;int count;// 为了内存对齐这里使用int类型char* buff;
}*PSTRUCT_DESC;
// 保存对象数据描述信息的结构体(游戏数据类型表)
typedef struct OBJECT_DESC {char* name;int type;
}*POBJ_DESC;// 数据头结构体 数据结构约定
// 也就是接收到1E包的头部
typedef struct NR_NOTICE_HEAD {char un;char op;short count;
}NR_HEAD, *PNR_HEAD, *PNR_NOTICE_HEAD;// 选择角色头部
typedef struct NET_SEND_SELECTROLE {char op = 0x04;char buff[83]{};
}NS_SELECTROLE, * PNS_SELECTROLE;// 创建角色数据头部
typedef struct NET_SEHD_CREATEROLE_HEAD {/*char un[0x2];char len = sizeof(NET_SEHD_CREATEROLE_HEAD) - 0x03;这俩代码是为了解决内存对齐的问题,创建角色给服务端发送的05开头的数据包,把05变成00 00 00 05*/char un[0x2];char len = sizeof(NET_SEHD_CREATEROLE_HEAD) - 0x03;char op = 0x05;int index = 0x0; // 选择角色列表索引/*宽字节是2字节0x10是16两个是32,正好满足给服务端发送的创建角色数据包,也就是05开头的数据包*/wchar_t name[0x20];short unst = 0x00;short count = 0x08;
}*PNS_CREATEROLE;// 基类
typedef class NET_SEND_BASE {
public:// 实现编码操作,模拟游戏数据包给服务端发送数据,这个模拟的数据包通过调用 CodeMe函数得到unsigned CodeMe(int size, char* buffer);
}NSR_BASE, *PNET_SEND_BASE, * PNSR_BASE;typedef struct NS_CREATEROLE_HEAD_BUFF :public NET_SEHD_CREATEROLE_HEAD {char buff[0x300]{};
}*PNS_CREATEROLEBUFF;// 解析约定结构体
// 创建角色数据结构体
typedef class CREATE_ROLE_DATAS:public NET_SEND_BASE {
public:GDOUBLE sex;//1.000000 性别 0 男 1 女GDOUBLE camp;//1.000000 阵营 1 艾森赫特 2 格兰蒂尔GDOUBLE face;//1.000000 种族 1 布冯特人 3 格洛玛人 4 尤恩图人 6 喀什人GDOUBLE occu;//3.000000 职业 1 仲裁者 3秘法师 6 猎魔人 8 元素法师GCHAR Photo;//gui\BG_team\TeamRole\Teamrole_zq_humF_001.PNGGCHAR Infos;//Face,0;Hat,0;Eyes,0;Beard,0;Ears,0;Tail,0;Finger,0;Cloth,0;Pants,0;Gloves,0;Shoes,0;Trait,0;HairColor,0;SkinColor,0;SkinMtl,0;Tattoo,0;TattooColor,16777215;GCHAR Txt;// 细节编辑捏脸GDOUBLE faceSahpe;//0.000000 脸型 0 1 2 3
}* PCREATE_ROLE_DATAS;// 发送数据标准头 0xA数据包
typedef struct NET_SEND_HEAD {// 为了内存对齐,当前结构不可能超过255,所以这样写是没问题的char len = sizeof(NET_SEND_HEAD) - 1;char op = 0x0A;short unst = 0;int unnt[4]{};short unst1 = 0;short count = 0;
}*PNET_SEND_HEAD;
// 开始创建角色的数据结构
// 申请创建角色结构体
typedef struct NET_CREATEROLE_START {char un[0x02];// 用来做内存对齐char len = sizeof(NET_CREATEROLE_START) - 3;// 用来做内存对齐char op = 0x03;int code = 0x01;
}*PNET_CREATEROLE_START;// 删除角色数据结构
typedef struct DATA_DELROLE {char op;char buff[0x1F];int len;int un[8] = { 0x01 , 0x03 };}*PDATADELROLE;/*数据包还原结构体要注意内存对齐,如果数据不满4字节,它字段会补齐比如结构体里有一个char变量,它是1字节,在内存里它可能会为了内存对齐让它变成4字节,所以这要注意
*/
// 登录数据
typedef struct DATA_LOGIN {int op = 0x0300;char buff[0x10]{};int lenId = 0x10;/*这个是登录的账号,它可能会变成0x20或更长,现在默认让它0x10读的时候以长度为准就好了*/char Id[0x10]{};int lenPass = 0x10;/*这个是登录的密码,它可能会变成0x20或更长,现在默认让它0x10读的时候以长度为准就好了*/char Pass[0x10]{};int lenCode = 0x10;char Code[0x10]{};int eop = 0x01;
}*PDATALOGIN;
typedef struct DATA_LOGIN_OK {// 登录成功数据包头int un[8] = { 0, 0, 0x76B, 0x0C, 0x1E,0, 0, 0 };int index = 0;int RoleCount = 0;
}*PDATALOGINOK;// 发送数据包含内存空间,也就是数据参数,数据参数的意思看44文章里的内容
typedef struct NET_SEND_BUFF:public NET_SEND_HEAD {char buff[0x1000]{};
}*PNET_SEND_BUFF;typedef class NET_SEND_CHEAD:public NET_SEND_BASE {
public:union {GCHAR msgHeader;GINT opcode;};
public:NET_SEND_CHEAD() {};~NET_SEND_CHEAD() {};
}NSR_CHEAD, *PNSR_CHEAD, *PNET_SEND_CHEAD;// 选择角色
typedef class NET_SEND_CHOOSECAMP :public NET_SEND_CHEAD {
public:GCHAR camps;
}*PNS_CHOOSECAMP;// 心跳包数据结构
typedef class HEART_BEEP :public NET_SEND_CHEAD {
public:// 20秒一次GINT tick;//3
}*PHEART_BEEP;typedef class HEART_LOOP :public NET_SEND_CHEAD {
public:// 5秒一次GINT64 tick;//9320695GCHAR txt;//}*PHEART_LOOP;typedef struct ONLINE_HAND: public NSR_CHEAD{GINT step; // 2GINT state; // 1
}*PONLINE_HAND;typedef struct ONLINE_INIT : public NSR_CHEAD {GINT state;//0GDOUBLE un;//180000000.000000
}*PONLINE_INIT;
// 登陆后角色数据区
// 聊天数据包的数据结构
typedef class CHAT_DATA :public NET_SEND_CHEAD {
public:GINT ChartId;//1
}*PCHAT_DATA;
typedef class CHAT_PUBLIC :public CHAT_DATA {
public:GUTF16 txt;//[222222222222222222222222222222222222222222<img src="Face37" valign="bottom" only="line"/>]GDOUBLE un;//0.000000
}*PCHAT_PUB;
typedef class CHAT_PRIVATE :public CHAT_DATA {
public:GUTF16 txt;//[222222222222222222222222222222222222222222<img src="Face37" valign="bottom" only="line"/>]GUTF16 name;//[皮革兔]GDOUBLE un;//0.000000
}*PCHAT_PRV;// 登陆后角色数据包
typedef class ROLE_DATA {// 登录成功数据包
public:GBYTE byte;GINT index;GINT un1;GUTF16 name;GUTF16 infos;GINT un2;GINT64 un3;
}*PROLEDATA;typedef class MOVE_DATA :public NET_SEND_CHEAD {
public:GINT Mode; // 0停止 1移动中 2跳跃GINT Count; // 带入场景这里就是一共有几个与坐标相关的数据
}*PMOVE_DATA;// 停止移动
typedef class MOVE_DATA_STOP :public MOVE_DATA {
public:GFLOAT x;//-584.845459GFLOAT h;//65.004677GFLOAT y;//708.458740 GFLOAT face;//4.912942
}*PMOVE_DATA_STOP;// 移动
typedef class MOVE_DATA_WALK :public MOVE_DATA {
public:GFLOAT x;//-584.845459 当前坐标 xGFLOAT h;//65.004677 当前坐标 hGFLOAT y;//708.458740 当前坐标 yGFLOAT xNext;//-596.604919 预计移动到的坐标GFLOAT yNext;//710.849304 预计移动到的坐标GFLOAT MoveSpeed;//5.000000 移动速度GFLOAT GSpeed;//0.000000 根据跳跃的数据包猜测它是重力加速(也就是坠落的速度)GFLOAT face;//4.912942 面向
}*PMOVE_DATA_WALK;// 跳跃或往前跳(前后左右跳)
typedef class MOVE_DATA_JUMP:public MOVE_DATA {
public:GFLOAT x;//-599.624939GFLOAT h;//65.004105GFLOAT y;//711.464600GFLOAT xNext;//-599.624939GFLOAT yNext;//711.464600GFLOAT MoveSpeed;//5.000000GFLOAT JumpSpeed;//4.500000GFLOAT GSpeed;//9.800000 重力加速(也就是坠落的速度)GFLOAT face;//4.912942
}*PMOVE_DATA_JUMP;// 移动时跳跃
typedef class MOVE_DATA_WJUMP :public MOVE_DATA {
public:GFLOAT x;//-394.622162GFLOAT h;//8.719633GFLOAT y;//912.655151GFLOAT xNext;//-400.995270GFLOAT yNext;//902.487366GFLOAT MoveSpeed;//50.000000GFLOAT face;//3.701483
}*PMOVE_DATA_WJUMP;// 开始坠落
typedef class FALL_DATA_START :public NET_SEND_CHEAD {
public:GINT Mode;//890GINT StartH;//1GFLOAT NextH;//58.223557GINT EndH;//0}*PFALL_DATA_START;// 坠落结束
typedef class FALL_DATA_STOP :public NET_SEND_CHEAD {
public:GINT Mode;//2GFLOAT StartH;//58.223557GFLOAT NextH;//48.128914GFLOAT EndH;//24.581387
}*PFALL_DATA_STOP;// 释放技能结构
typedef class USESKILL_DATA :public NET_SEND_CHEAD {
public://GINT gint;//211GCHAR skillName;//Skill_In1025_01_1GFLOAT x;//-522.842712,猜测它是使用技能的坐标GFLOAT h;//8.122560,猜测它是使用技能的坐标GFLOAT y;//866.518250,猜测它是使用技能的坐标GFLOAT face;//5.872537 面向GFLOAT xTarget;//0.000000 释放技能的目标位置,也就是技能释放到哪GFLOAT hTarget;//0.000000 释放技能的目标位置,也就是技能释放到哪GFLOAT yTarget;//0.000000 释放技能的目标位置,也就是技能释放到哪GINT un0;//0GINT un1;//0GINT un2;//1
}*PUSESKILL;