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

📄 sdk.pas

📁 传奇2...飘飘M2的源码.曾经是传奇"龙"版用得最好的M2程序.完整M2源码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit SDK;

interface
uses
  Windows, SysUtils, Classes, Grobal2, ObjBase, Forms;
const
  MAXPULGCOUNT = 20;
type
  TProcArrayInfo = record
    sProcName: string;
    nProcAddr: Pointer;
    nCheckCode: Integer;
  end;

  TObjectArrayInfo = record
    Obj: TObject;
    sObjcName: string;
    nCheckCode: Integer;
  end;

  TProcArray = array[0..MAXPULGCOUNT - 1] of TProcArrayInfo;
  TObjectArray = array[0..MAXPULGCOUNT - 1] of TObjectArrayInfo;

  TMsgProc = procedure(Msg: PChar; nMsgLen: Integer; nMode: Integer); stdcall;
  TFindProc = function(ProcName: PChar; nNameLen: Integer): Pointer; stdcall;
  TSetProc = function(ProcAddr: Pointer; ProcName: PChar; nNameLen: Integer): Boolean; stdcall;
  TFindObj = function(ObjName: PChar; nNameLen: Integer): TObject; stdcall;
  TStartPlug = function(): Boolean; stdcall;
  TSetStartPlug = function(StartPlug: TStartPlug): Boolean; stdcall;

  TPlugInit = function(AppHandle: HWnd; MsgProc: TMsgProc; FindProc: TFindProc; SetProc: TSetProc; FindOBj: TFindObj): PChar; stdcall;
  TClassProc = procedure(Sender: TObject);
  TStartProc = procedure(); stdcall;
  TStartRegister = function(sRegisterInfo, sUserName: PChar): Integer; stdcall;
  TGetStrProc = function(): PChar; stdcall;
  TGameDataLog = function(ProcName: PChar; nNameLen: Integer): Boolean; stdcall;
  TIPLocal = procedure(sIPaddr: PChar; sLocal: PChar; nLocalLen: Integer); stdcall;
  TDeCryptString = procedure(Src, Dest: PChar; nSrc: Integer; var nDest: Integer); stdcall;

  TCheckCode = record
  end;

  TSaveRcd = record
    sAccount: string[12];
    sChrName: string[14];
    nSessionID: Integer;
    nReTryCount: Integer;
    PlayObject: TPlayObject;
    HumanRcd: THumDataInfo;
  end;
  pTSaveRcd = ^TSaveRcd;

  TLoadDBInfo = record
    sAccount: string[12];
    sCharName: string[14];
    sIPaddr: string[15];
    nSessionID: Integer;
    nSoftVersionDate: Integer;
    nPayMent: Integer;
    nPayMode: Integer;
    nSocket: Integer;
    nGSocketIdx: Integer;
    nGateIdx: Integer;
    dwNewUserTick: LongWord;
    PlayObject: TPlayObject;
    nReLoadCount: Integer;
  end;
  pTLoadDBInfo = ^TLoadDBInfo;

  TUserOpenInfo = record
    sAccount: string[12];
    sChrName: string[14];
    LoadUser: TLoadDBInfo;
    HumanRcd: THumDataInfo;
  end;
  pTUserOpenInfo = ^TUserOpenInfo;

  TSellOffGoodList = class(TGList)
  private
    FRecCount: Cardinal;
    FUpDateSellOff: Boolean;
    m_nChangeCount: Integer;
  public
    constructor Create;
    destructor Destroy; override;
    procedure LoadSellOffGoodList();
    procedure UnLoadSellOffGoodList();
    procedure GetSellOffGoodList(var SellOffList: TList);
    procedure GetUserSellOffGoodListByChrName(sChrName: string; var SellOffList: TList);
    procedure GetUserSellOffGoodListByItemName(sItemName: string; var SellOffList: TList);
    procedure GetUserSellOffGoodListByMakeIndex(nMakeIndex: Integer; var SellOffInfo: pTSellOffInfo);
    procedure GetUserSellOffItem(sItemName: string; nMakeIndex: Integer; var SellOffInfo: pTSellOffInfo; var StdItem: pTStdItem);
    function GetUserSellOffCount(sCharName: string): Integer;
    function GetUserLimitSellOffCount(sCharName: string): Boolean;
    procedure GetUserSellOffListByIndex(nIndex: Integer; var SellOffList: TList);
    function AddItemToSellOffGoodsList(SellOffInfo: pTSellOffInfo): Boolean;
    function DelSellOffItem(nMakeIndex: Integer): Boolean;
    function SaveSellOffGoodList(): Boolean;
  published
    property RecCount: Cardinal read FRecCount write FRecCount;
    property UpDateSellOff: Boolean read FUpDateSellOff write FUpDateSellOff;
  end;

  TSellOffGoldList = class(TGList)
  private
    FRecCount: Cardinal;
    FUpDateSellOff: Boolean;
    m_nChangeCount: Integer;
  public
    constructor Create;
    destructor Destroy; override;
    procedure LoadSellOffGoldList();
    procedure UnLoadSellOffGoldList();
    procedure GetUserSellOffGoldListByChrName(sChrName: string; var SellOffList: TList);
    function AddItemToSellOffGoldList(SellOffInfo: pTSellOffInfo): Boolean;
    function DelSellOffGoldItem(nMakeIndex: Integer): Boolean;
    function SaveSellOffGoldList(): Boolean;
  published
    property RecCount: Cardinal read FRecCount write FRecCount;
    property UpDateSellOff: Boolean read FUpDateSellOff write FUpDateSellOff;
  end;

  //==============================================================================
  //TStartStorageProc = procedure(BigStorageList: TBigStorageList);
  TBigStorageList = class(TGList)

  private
    FRecordCount: Cardinal;
    FHumManCount: Cardinal;
    FPosition: Cardinal;
    FUpDate: Boolean;
    FStopLoad: Boolean;
    m_nChangeCount: Integer;

  public
    FOnLoadStorage: procedure();
    FOnBeginLoadStorage: procedure();
    FOnEndLoadStorage: procedure();
    FOnLoadPro: Boolean;
    constructor Create;
    destructor Destroy; override;
    procedure LoadBigStorageList(); overload;
    procedure LoadBigStorageList(sFileName: string); overload;
    procedure UnLoadBigStorageList();
    function GetUserBigStorageList(var StorageList: TList): Boolean;
    function GetUserStorageListByChrName(sChrName: string; var StorageList: TList): Boolean;
    function GetUserStorageListByItemName(sItemName: string; var StorageList: TList): Boolean;
    function GetUserStorageListByMakeIndex(sChrName, sItemName: string; nMakeIndex: Integer; var UserItem: pTUserItem): Boolean;
    function AddItemToUserBigStorageList(sChrName: string; UserItem: pTUserItem): Boolean;
    function GetUserStorageCount(sChrName: string): Integer;
    function DelBigStorageItem(sChrName, sItemName: string; nMakeIndex: Integer): Boolean;
    function SaveStorageList(): Boolean;overload;
    function SaveStorageList(sFileName: string): Boolean;overload;
    function ClearRec(): Boolean;
  published
    property RecordCount: Cardinal read FRecordCount write FRecordCount;
    property HumManCount: Cardinal read FHumManCount write FHumManCount;
    property Position: Cardinal read FPosition;
    property UpDate: Boolean read FUpDate write FUpDate;
    property StopLoad: Boolean read FStopLoad write FStopLoad;
    //property OnLoadStorage: Pointer read FOnLoadStorage write FOnLoadStorage;
    //property OnBeginLoadStorage: Pointer read FOnBeginLoadStorage write FOnBeginLoadStorage;
  end;

implementation
uses ItmUnit, UsrEngn, M2Share;

{BigStorageList}
constructor TBigStorageList.Create;
begin
  inherited Create;
  FRecordCount := 0;
  FHumManCount := 0;
  FUpDate := False;
  m_nChangeCount := 0;
  FPosition := 0;
  FStopLoad := False;
  FOnLoadStorage := nil;
  FOnBeginLoadStorage := nil;
  FOnEndLoadStorage := nil;
  FOnLoadPro := False;
end;

destructor TBigStorageList.Destroy;
begin

  inherited;
end;
procedure TBigStorageList.LoadBigStorageList();
var
  i: Integer;
  sFileName: string;
  FileHandle: Integer;
  List: TList;
  BigStorage: pTBigStorage;
  nItemCount: TItemCount;
begin
  Lock();
  try
    sFileName := g_Config.sEnvirDir + '\Market_Storage\';
    if not DirectoryExists(sFileName) then begin
      ForceDirectories(sFileName);
    end;
    sFileName := sFileName + 'UserStorage.db';
    if FileExists(sFileName) then begin
      FileHandle := FileOpen(sFileName, fmOpenRead or fmShareDenyNone);
      List := nil;
      if FileHandle > 0 then begin
        if FileRead(FileHandle, nItemCount, SizeOf(TItemCount)) = SizeOf(TItemCount) then begin
          FRecordCount := nItemCount;
          for i := 0 to nItemCount - 1 do begin
            New(BigStorage);
            FillChar(BigStorage.UseItems, SizeOf(TUserItem), #0);
            if (FileRead(FileHandle, BigStorage^, SizeOf(TBigStorage)) = SizeOf(TBigStorage)) and (not BigStorage.boDelete) and (BigStorage.UseItems.wIndex > 0) then begin
              if List = nil then begin
                List := TList.Create;
                List.Add(BigStorage);
              end else begin
                if (List.Count > 0) and (CompareText(pTBigStorage(List.Items[0]).sCharName, BigStorage.sCharName) = 0) then begin
                  List.Add(BigStorage);
                end else begin
                  Self.Add(List);
                  List := TList.Create;
                  List.Add(BigStorage);
                end;
              end;
            end else begin
              DisPose(BigStorage);
            end;
          end;
          if List <> nil then
            Self.Add(List);
          FileClose(FileHandle);
        end;
      end;
    end else begin
      FileHandle := FileCreate(sFileName);
      if FileHandle > 0 then begin
        nItemCount := 0;
        FileWrite(FileHandle, nItemCount, SizeOf(TItemCount));
        FileClose(FileHandle);
      end;
    end;
    FHumManCount := Count;
  finally
    UnLock();
  end;
  //MainOutMessage('LoadSellGoodRecord: '+IntToStr(Self.Count));
end;

procedure TBigStorageList.LoadBigStorageList(sFileName: string);
var
  i: Integer;
  FileHandle: Integer;
  List: TList;
  BigStorage: pTBigStorage;
  nItemCount: TItemCount;
begin
  Lock();
  try
    if FileExists(sFileName) then begin
      FileHandle := FileOpen(sFileName, fmOpenRead or fmShareDenyNone);
      List := nil;
      if FileHandle > 0 then begin
        if FileRead(FileHandle, nItemCount, SizeOf(TItemCount)) = SizeOf(TItemCount) then begin
          FRecordCount := nItemCount;
          if Assigned(FOnBeginLoadStorage) then begin
            FOnBeginLoadStorage();
          end;
          for i := 0 to nItemCount - 1 do begin
            Application.ProcessMessages;
            FPosition := i;
            if FStopLoad then break;
            if Assigned(FOnLoadStorage) then begin
              FOnLoadStorage();
            end;
            New(BigStorage);
            FillChar(BigStorage.UseItems, SizeOf(TUserItem), #0);
            if (FileRead(FileHandle, BigStorage^, SizeOf(TBigStorage)) = SizeOf(TBigStorage)) and (not BigStorage.boDelete) and (BigStorage.UseItems.wIndex > 0) then begin
              if List = nil then begin
                List := TList.Create;
                List.Add(BigStorage);
              end else begin
                if (List.Count > 0) and (CompareText(pTBigStorage(List.Items[0]).sCharName, BigStorage.sCharName) = 0) then begin
                  List.Add(BigStorage);
                end else begin
                  Self.Add(List);
                  List := TList.Create;
                  List.Add(BigStorage);
                end;
              end;
            end else begin
              DisPose(BigStorage);
            end;
          end;
          if List <> nil then
            Self.Add(List);
          FileClose(FileHandle);
        end;
      end;
    end else begin
      FileHandle := FileCreate(sFileName);
      if FileHandle > 0 then begin
        nItemCount := 0;
        FileWrite(FileHandle, nItemCount, SizeOf(TItemCount));
        FileClose(FileHandle);
      end;
    end;
    FHumManCount := Count;
  finally
    UnLock();
    if Assigned(FOnEndLoadStorage) then begin
      FOnEndLoadStorage();
    end;
  end;
  //MainOutMessage('LoadSellGoodRecord: '+IntToStr(Self.Count));
end;

procedure TBigStorageList.UnLoadBigStorageList();
begin

end;
function TBigStorageList.GetUserBigStorageList(var StorageList: TList): Boolean;
begin

end;
function TBigStorageList.GetUserStorageListByChrName(sChrName: string; var StorageList: TList): Boolean;
var
  i, ii: Integer;
  List: TList;
  BigStorage: pTBigStorage;
begin
  Lock();
  Result := False;
  StorageList := nil;
  if FOnLoadPro then begin
    FRecordCount := Count;
    if Assigned(FOnBeginLoadStorage) then begin
      FOnBeginLoadStorage();
    end;
  end;
  for i := 0 to Count - 1 do begin
    if Count <= 0 then break;

    if FOnLoadPro then begin
      Application.ProcessMessages;
      FPosition := i;
      if FStopLoad then break;
      if Assigned(FOnLoadStorage) then begin
        FOnLoadStorage();
      end;
    end;

    List := TList(Items[i]);
    if (List <> nil) and (List.Count > 0) then begin
      BigStorage := pTBigStorage(List.Items[0]);
      if CompareText(BigStorage.sCharName, sChrName) = 0 then begin
        StorageList := List;
        Result := TRUE;
        break;
      end;
    end;
  end;

  if FOnLoadPro then begin
    if Assigned(FOnEndLoadStorage) then begin
      FOnEndLoadStorage();
    end;
  end;

  UnLock();
end;
function TBigStorageList.GetUserStorageListByItemName(sItemName: string; var StorageList: TList): Boolean;
var
  i, ii, nIndex: Integer;
  List: TList;
  BigStorage: pTBigStorage;
  sItem: string;
begin
  Lock();
  Result := False;
  nIndex := 0;
  if FOnLoadPro then begin
    FRecordCount := Count;
    if Assigned(FOnBeginLoadStorage) then begin
      FOnBeginLoadStorage();
    end;
  end;
  for i := 0 to Count - 1 do begin
    if Count <= 0 then break;
    List := TList(Items[i]);
    if (List <> nil) and (List.Count > 0) then begin
      for ii := 0 to List.Count - 1 do begin
        if FOnLoadPro then begin
          Application.ProcessMessages;
          FPosition := nIndex;
          if FStopLoad then break;
          if Assigned(FOnLoadStorage) then begin
            FOnLoadStorage();
          end;
        end;
        BigStorage := pTBigStorage(List.Items[ii]);
        sItem := UserEngine.GetStdItemName(BigStorage.UseItems.wIndex);
        if CompareText(sItem, sItemName) = 0 then begin
          StorageList.Add(BigStorage);
          Inc(nIndex);
          Result := TRUE;
        end;
      end;
    end;
  end;
  if FOnLoadPro then begin
    if Assigned(FOnEndLoadStorage) then begin
      FOnEndLoadStorage();
    end;
  end;
  UnLock();
end;

function TBigStorageList.GetUserStorageCount(sChrName: string): Integer;
var
  i, ii: Integer;
  List: TList;
  BigStorage: pTBigStorage;
begin
  Lock();
  Result := 0;
  for i := 0 to Count - 1 do begin
    if Count <= 0 then break;
    List := TList(Items[i]);
    if (List <> nil) and (List.Count > 0) then begin
      BigStorage := pTBigStorage(List.Items[0]);
      if CompareText(BigStorage.sCharName, sChrName) = 0 then begin
        Result := List.Count;

⌨️ 快捷键说明

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