传奇单机版,GM论坛,传奇版本库,GM基地

新1.4C登录器Delphi源码冷雨夜适配King1.4c插件

[复制链接]
查看: 236   回复: 0     # 登录器源码

197

主题

199

帖子

7614

积分

霸王教主

Rank: 9Rank: 9Rank: 9

积分
7614
2022-9-12 16:52:25   显示全部楼层   阅读模式  
lyy冷雨夜登录器主程序源码,新1.4c可用,编译通过,可正常使用。

新1.4c.png
[Delphi] 纯文本查看 复制代码
unit EDcode;
//编码/解码函数库
interface

uses
  Windows, SysUtils, Classes;

const
  BUFFERSIZE        = 6400;

  CM_CheckNet       = 1;                //检查服务器状态,包含检测版本登命令
  CM_GetRenStr      = 2;                //获取随机验证码
  CM_Reg            = 3;                //用户注册
  CM_ModPass        = 4;                //修改密码
  CM_GetQuest       = 5;                //获取密码提示问题
  CM_ReSetPass      = 6;                //重设密码

  PM_VerOk          = 11;               //客户端版本符合
  PM_VerNo          = 12;               //客户端版本不符合
  PM_SMess          = 13;               //仅弹出公告
  PM_SMessButt      = 14;               //弹出公告+更新按钮

  PM_UserRep        = 31;               //用户名称已经存在
  PM_PwsError       = 41;               //老密码错误
  PM_NotUser        = 51;               //ID不存在
  PM_InfoError      = 61;               //资料不符合

  PM_RenError       = 3451;             //随机验证码错误
  PM_Disable        = 3452;             //管理员禁止使用
  PM_SqlError       = 3453;             //服务器数据库连接错误
  PM_StrError       = 3454;             //字符串包含非法字符
  PM_StrBlank       = 3455;             //字符串中包含有空格
  PM_UnError        = 3456;             //发生未知异常
  PM_UserOK         = 3457;             //用户操作成功

type
  TEnDecodeType = (edtMir2, edtMirWorld);

  TLongMsg = packed record
    Comm: Word;
    param: Word;
  end;

  TRegUser = packed record
    UserID: string[15];
    UserPass: string[15];
    PQ1: string[30];
    PA1: string[30];
    PQ2: string[30];
    PA2: string[15];
    UserEmail: string[40];
    EnRenKey: string[8];
  end;



function EncodeString(str: string; EnDecodeType: TEnDecodeType): string;
function DecodeString(str: string; EnDecodeType: TEnDecodeType): string;
function EncodeBuffer(buf: pChar; bufsize: integer; EnDecodeType: TEnDecodeType): string;
procedure DecodeBuffer(src: string; buf: pChar; bufsize: integer; EnDecodeType: TEnDecodeType);
//传世封包加/解密方法
function MirDecode(pIn: string; Size: Word; pOut: pChar): Word;
function MirEncode(pIn: pChar; Size: Word; pOut: pChar): Word;

var
  CSEncode          : TRTLCriticalSection;

implementation

uses math;
var
  EncBuf, TempBuf   : pChar;

procedure Encode6BitBuf(src, dest: pChar; srclen, destlen: integer; EnDecodeType: TEnDecodeType);
var
  i, restcount, destpos: integer;
  made, ch, rest    : byte;
begin
  if EnDecodeType = edtMirWorld then
  begin
    //fillchar(dest,destlen,0);
    MirEncode(src, srclen, dest);
  end
  else
  try
    restcount := 0;
    rest := 0;
    destpos := 0;
    for i := 0 to srclen - 1 do
    begin
      if destpos >= destlen then break;
      ch := byte(src[i]);
      made := byte((rest or (ch shr (2 + restcount))) and $3F);
      rest := byte(((ch shl (8 - (2 + restcount))) shr 2) and $3F);
      Inc(restcount, 2);

      if restcount < 6 then
      begin
        dest[destpos] := char(made + $3C);
        Inc(destpos);
      end
      else
      begin
        if destpos < destlen - 1 then
        begin
          dest[destpos] := char(made + $3C);
          dest[destpos + 1] := char(rest + $3C);
          Inc(destpos, 2);
        end
        else
        begin
          dest[destpos] := char(made + $3C);
          Inc(destpos);
        end;
        restcount := 0;
        rest := 0;
      end;

    end;
    if restcount > 0 then
    begin
      dest[destpos] := char(rest + $3C);
      Inc(destpos);
    end;
    dest[destpos] := #0;
  except
  end;
end;

//解码

procedure Decode6BitBuf(source: string; buf: pChar; buflen: integer; EnDecodeType: TEnDecodeType);
const
  Masks             : array[2..6] of byte = ($FC, $F8, $F0, $E0, $C0);
  //($FE, $FC, $F8, $F0, $E0, $C0, $80, $00);
var
  i, len, bitpos, madebit, bufpos: integer;
  ch, tmp, _byte    : byte;
begin
  if EnDecodeType = edtMirWorld then
  begin
    //fillchar(buf,buflen,0);
    MirDecode(source, length(source), buf);
    i := round(length(source) * 3 / 4);
    buf[i] := #$0;
  end
  else
  try
    len := length(source);
    bitpos := 2;
    madebit := 0;
    bufpos := 0;
    tmp := 0;
    for i := 1 to len do
    begin
      if integer(source[i]) - $3C >= 0 then
        ch := byte(source[i]) - $3C
      else
      begin
        bufpos := 0;
        break;
      end;

      if bufpos >= buflen then break;

      if (madebit + 6) >= 8 then
      begin
        _byte := byte(tmp or ((ch and $3F) shr (6 - bitpos)));
        buf[bufpos] := char(_byte);
        Inc(bufpos);
        madebit := 0;
        if bitpos < 6 then
          Inc(bitpos, 2)
        else
        begin
          bitpos := 2;
          continue;
        end;
      end;

      tmp := byte(byte(ch shl bitpos) and Masks[bitpos]); // #### ##--
      Inc(madebit, 8 - bitpos);
    end;
    buf[bufpos] := #0;
  except
  end;
end;

function DecodeString(str: string; EnDecodeType: TEnDecodeType): string;
begin
  try
    EnterCriticalSection(CSEncode);
    Decode6BitBuf(str, EncBuf, BUFFERSIZE,EnDecodeType);
    result := StrPas(EncBuf);           //error, 1, 2, 3,...
  finally
    LeaveCriticalSection(CSEncode);
  end;
end;

procedure DecodeBuffer(src: string; buf: pChar; bufsize: integer; EnDecodeType: TEnDecodeType);
begin
  try
    EnterCriticalSection(CSEncode);
    Decode6BitBuf(src, EncBuf, BUFFERSIZE,EnDecodeType);
    Move(EncBuf^, buf^, bufsize);
  finally
    LeaveCriticalSection(CSEncode);
  end;
end;

function EncodeString(str: string; EnDecodeType: TEnDecodeType): string;
begin
  try
    EnterCriticalSection(CSEncode);
    Encode6BitBuf(pChar(str), EncBuf, length(str), BUFFERSIZE,EnDecodeType);
    result := StrPas(EncBuf);
  finally
    LeaveCriticalSection(CSEncode);
  end;
end;

function EncodeBuffer(buf: pChar; bufsize: integer; EnDecodeType: TEnDecodeType): string;
begin
  try
    EnterCriticalSection(CSEncode);
    if bufsize < BUFFERSIZE then
    begin
      Move(buf^, TempBuf^, bufsize);
      Encode6BitBuf(TempBuf, EncBuf, bufsize, BUFFERSIZE,EnDecodeType);
      result := StrPas(EncBuf);
    end
    else
      result := '';
  finally
    LeaveCriticalSection(CSEncode);
  end;
end;

function MirDecode(pIn: string; Size: Word; pOut: pChar): Word;
//传奇世界封包解密
var
  b1, b2, b3        : byte;
  c1, c2, c3, c4    : byte;
  i, oPtr           : Word;
  x, y              : Word;
begin
  //  i := 0;
  oPtr := 0;
  x := length(pIn) div 4;
  if length(pIn) > 3 then
    for i := 0 to x - 1 do
    begin
      c1 := ord(pIn[i * 4 + 1]) - $3B;
      c2 := ord(pIn[i * 4 + 2]) - $3B;
      c3 := ord(pIn[i * 4 + 3]) - $3B;
      c4 := ord(pIn[i * 4 + 4]) - $3B;
      b1 := (c1 and $FC) shl 2;         //11111100->11110000
      b2 := (c1 and 3);                 //00000011
      b3 := c4 and $C;                  //00001100
      pOut[oPtr] := chr((b1 or b2 or b3) xor $EB);
      Inc(oPtr);
      b1 := (c2 and $FC) shl 2;         //11111100->11110000
      b2 := (c2 and 3);                 //00000011
      b3 := (c4 and 3) shl 2;           //00000011  ->00001100
      pOut[oPtr] := chr((b1 or b2 or b3) xor $EB);
      Inc(oPtr);
      b1 := (c4 and $30) shl 2;         //00110000->11000000
      pOut[oPtr] := chr((c3 or b1) xor $EB);
      Inc(oPtr);
    end;
  y := length(pIn) mod 4;
  if y = 2 then
  begin
    c1 := ord(pIn[x * 4 + 1]) - $3B;
    c2 := ord(pIn[x * 4 + 2]) - $3B;

    b1 := (c1 and $FC) shl 2;           //11111100->11110000
    b2 := (c1 and 3);                   //00000011
    b3 := (c2 and 3) shl 2;             //00000011->00001100
    pOut[oPtr] := chr((b1 or b2 or b3) xor $EB);
    Inc(oPtr);
  end;
  if y = 3 then
  begin
    c1 := ord(pIn[x * 4 + 1]) - $3B;
    c2 := ord(pIn[x * 4 + 2]) - $3B;

    c4 := ord(pIn[x * 4 + 3]) - $3B;

    b1 := (c1 and $FC) shl 2;           //11111100->11110000
    b2 := (c1 and 3);                   //00000011
    b3 := c4 and $C;                    //00001100
    pOut[oPtr] := chr((b1 or b2 or b3) xor $EB);
    Inc(oPtr);

    b1 := (c2 and $FC) shl 2;           //11111100->11110000
    b2 := (c2 and 3);                   //00000011
    b3 := (c4 and 3) shl 2;             //00000011  ->00001100
    pOut[oPtr] := chr((b1 or b2 or b3) xor $EB);
    Inc(oPtr);
  end;
  result := oPtr;
end;

function MirEncode(pIn: pChar; Size: Word; pOut: pChar): Word;
//传奇世界封包加密
var
  b1, bcal          : byte;
  bflag1, bflag2    : byte;
  i, iPtr, oPtr     : Word;
begin
  //  b1 := 0;
  //  bcal := 0;
  //  bflag1 := 0;
  bflag2 := 0;
  i := 0;
  iPtr := 0;
  oPtr := 0;
  while iPtr < Size do
  begin
    b1 := ord(pIn[iPtr]) xor $EB;
    Inc(iPtr);
    if i < 2 then
    begin
      bcal := b1;
      bcal := bcal shr 2;
      bflag1 := bcal;
      bcal := bcal and $3C;
      b1 := b1 and 3;
      bcal := bcal or b1;
      bcal := bcal + $3B;
      pOut[oPtr] := chr(bcal);
      Inc(oPtr);
      bflag2 := (bflag1 and 3) or (bflag2 shl 2);
    end
    else
    begin
      bcal := b1;
      bcal := bcal and $3F;
      bcal := bcal + $3B;
      pOut[oPtr] := chr(bcal);
      Inc(oPtr);
      b1 := b1 shr 2;
      b1 := b1 and $30;
      b1 := b1 or bflag2;
      b1 := b1 + $3B;
      pOut[oPtr] := chr(b1);
      Inc(oPtr);
      bflag2 := 0;
    end;
    Inc(i);
    i := i mod 3;
  end;
  pOut[oPtr] := chr(0);
  if i <> 0 then
  begin
    pOut[oPtr] := chr(bflag2 + $3B);
    Inc(oPtr);
    pOut[oPtr] := chr(0);
  end;
  result := oPtr;
end;

initialization
  begin
    GetMem(EncBuf, BUFFERSIZE + 100);   //BUFFERSIZE + 100);
    GetMem(TempBuf, 10240);             //2048);
    InitializeCriticalSection(CSEncode);
  end;

finalization
  begin
    FreeMem(EncBuf);
    FreeMem(TempBuf);
    DeleteCriticalSection(CSEncode);

  end;

end.





游客,如果您要查看本帖隐藏内容请回复





上一篇:新火鸟登录器源代码Delphi,lyy冷雨夜代码
下一篇:华立3.56登录器源码lyy冷雨夜登录器Delphi源码
回复 关闭延时

使用道具 举报

您需要登录后才可以回帖   登录 立即注册

高级模式

Powered by Discuz! X3.4 © Comsenz Inc.

Archiver|手机版|小黑屋|美林传奇GM论坛 ( 蜀ICP备2020030293号-2 )