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

📄 gamecode.pas

📁 网络游戏神迹脱机外挂PASCAL源码
💻 PAS
字号:
unit GameCode;

interface

uses
Windows,SysUtils,Dialogs,Messages;


procedure DBGOut(const Format1: string; const Args: array of const);
//输出debug信息。用debugview查看。
function StrToASCII(str:PChar;strlen:Integer):string;
//PChar转ASCII表示的string
function ASCStrToStr(ascstr:string):string;
//ASCII表示的string转string
procedure ASCStrToPChar(ascstr:string;buf:PChar);
//ASCII表示的string转PChar 结尾不+#0
function DecodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
//游戏解包函数1,结尾+#0
function EncodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
//游戏打包函数1,结尾不加#0
procedure CopyChar(Dest:PChar;Source:PChar;Len:Integer);
//字符数组copy函数source copy to dest

implementation

procedure CopyChar(Dest:PChar;Source:PChar;Len:Integer);
var
 i:Integer;
begin
 for i:=0 to Len do
  begin
   Dest[i]:=Source[i];
  end;
end;

function HexCharToInt(hc:string):integer;
var
m : Integer;
Ch: Char;
begin
m:=16;
Ch:=PChar(hc)^;
  case Ch of
  '0','1','2','3','4','5','6','7','8','9' : m:=StrToInt(hc);
  'A','a' : m:=10;
  'B','b' : m:=11;
  'C','c' : m:=12;
  'D','d' : m:=13;
  'E','e' : m:=14;
  'F','f' : m:=15;
   end;
HexChartoInt:=m;
end;


procedure DBGOut(const Format1: string; const Args: array of const);
var
s:string;
begin
s:=Format(Format1,Args);
OutputDebugString(PChar(s));
end;

function StrToASCII(str:PChar;strlen:Integer):string;
var
str2  : string;
i     : Integer;
p     : Integer;
ascii : string;
begin
setlength(ascii,2*strlen);
ascii:='';
for i:=0 to strlen-1 do
  begin
  p:=integer(str[i]);
  str2:=IntToHex(p,2);
  ascii:=ascii+str2;
  end;
StrToASCII:=ascii;
end;

function ASCStrToStr(ascstr:string):string;
var
s1    :   string;
asclen:   integer;
strl  :   integer;
n     :   integer;
i     :   integer;
i2    :   integer;
begin
asclen:=strlen(PChar(ascstr));
i2:=asclen mod 2;
if i2=1 then
  begin
  ShowMessage('ASCStrToStr:Wrong Length');
  exit;
  end;

s1:='';
strl  :=  asclen div 2;

for i:=1 to strl  do
  begin
  n:=0;
  n:=16*HexCharToInt(ascstr[2*i-1])+HexCharToInt(ascstr[2*i]);
  //ShowMessage(IntToStr(n));
  s1:=s1+char(n);
  //ShowMessage(char(n));
  end;
//ShowMessage(s1);
ASCStrToStr:=s1;
end;

procedure ASCStrToPChar(ascstr:string;buf:PChar);
var
asclen:   integer;
strl  :   integer;
n     :   integer;
i     :   integer;
i2    :   integer;
begin
asclen:=strlen(PChar(ascstr));
i2:=asclen mod 2;
if i2=1 then
  begin
  ShowMessage('ASCStrToStr:Wrong Length');
  exit;
  end;

strl  :=  asclen div 2;

for i:=1 to strl do
  begin
  n:=16*HexCharToInt(ascstr[2*i-1])+HexCharToInt(ascstr[2*i]);
  buf[i-1]:=Char(n);
  //DBGOut('buf[i+1]=%d,n=%d',[i,n]);
  end;
buf[strl]:=#0;
end;

function EncodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
var
    iptr,optr,i           : Integer;
    b1,bcal,bflag1,bflag2 : byte;
    key1,key2             : byte;
begin
    iptr:=0;
    optr:=0;
    i:=0;
    b1:=0;
    bcal:=0;
    bflag1:=0;
    bflag2:=0;
    key1:=$ac;
    key2:=$3c;
while iptr<Size do
  begin
  b1:=byte(pIn[iptr]) xor key1;
  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+key2;
      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+key2;
      pOut[optr]:=chr(bcal);
      Inc(optr);
      b1:=b1 shr 2;
      b1:=b1 and $30;
      b1:=b1 or bflag2;
      b1:=b1+key2;
      pOut[optr]:=chr(b1);
      Inc(optr);
      bflag2:=0;
    end;
  Inc(i);
  i:=i mod 3;
  end;
 //DBGOut('optr=%d',[optr]);
  //下面是零头处理
if i=0 then       //不是零头则返回。
  begin
    //pOut[optr]:=#0;
    EncodeA:=optr;
    exit;
  end;
  pOut[optr]:=chr(bflag2+key2);
  Inc(optr);
//pOut[optr]:=#0;
EncodeA:=optr;
end;

function DecodeA(pIn:PChar;pOut:PChar;Size:Integer):Integer;
var
  i1,i2,i3,i4:byte;
  i,iptr,optr:integer;
  key1,key2:byte;
begin
  key1:=$ac;
  key2:=$3c;
  iptr:=0;
  optr:=0;
for i:=0 to (Size div 4)-1 do
  begin
  //依次取出4个字符
    i1:=byte(pIn[iptr])-key2;
    Inc(iptr);
    i2:=byte(pIn[iptr])-key2;
    Inc(iptr);
    i3:=byte(pIn[iptr])-key2;
    Inc(iptr);
    i4:=byte(pIn[iptr])-key2;
    Inc(iptr);
  //生成第一个明文字符
  pOut[optr]:=chr((i1 and 3) or (((i1 and $3c) shl 2) or (i4 and $c)) xor key1);
  Inc(optr);
  //生成第二个明文字符
  pOut[optr]:=chr((i2 and 3) or (((i2 and $3c) shl 2) or ((i4 and $3)) shl 2) xor key1);
  Inc(optr);
  //生成第三个明文字符
  pOut[optr]:=chr((i3 and $3f) or ((i4 and $30) shl 2) xor key1);
  Inc(optr);
  end;
case (Size mod 4) of
  //当密文有2个零头字符的处理
  2:begin
    //分别取出零头的2个字符
      i1:=byte(pIn[iptr])-key2;
      Inc(iptr);
      i2:=byte(pIn[iptr])-key2;
      Inc(iptr);
    //生成零头明文字符
      pOut[optr]:=chr((i1 and 3) or ((i1 and $3c) shl 2) or ((i2 and 3) shl 2) xor key1);
      Inc(optr);
    end;
  //当密文有3个零头字符的处理
  3:begin
    //分别取出零头的3个字符
      i1:=byte(pIn[iptr])-key2;
      Inc(iptr);
      i2:=byte(pIn[iptr])-key2;
      Inc(iptr);
      i3:=byte(pIn[iptr])-key2;
      Inc(iptr);
    //生成两个零头明文字符
      pOut[optr]:=chr((i1 and 3) or ((i1 and $3c) shl 2) or (i3 and $0C) xor key1);
      inc(optr);
      pOut[optr]:=chr((i2 and 3) or ((i2 and $3c) shl 2) or ((i3 and $03) shl 2) xor key1);
      Inc(optr);
    end;
end;//case结束  ;
pOut[optr]:=#0;
DecodeA:=optr;
end;

end.
 

⌨️ 快捷键说明

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