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

📄 clmain.pas

📁 传奇源代码的delphi版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  BoOneClick       :Boolean;
  OneClickMode     :TOneClickMode;
  m_boPasswordIntputStatus:Boolean = False;
  CLI              :TCLIParser;
  
implementation

uses
  FState, DlgConfig{, gShare};

{$R *.DFM}
var
  ShowMsgActor:TActor;

function  CheckMirProgram: Boolean;
var
   pstr, cstr: array[0..255] of char;
   mirapphandle: HWnd;
begin
   Result := FALSE;
   StrPCopy (pstr, 'legend of mir');
   mirapphandle := FindWindow (nil, pstr);
   if (mirapphandle <> 0) and (mirapphandle <> Application.Handle) then begin
{$IFNDEF COMPILE}
      SetActiveWindow(mirapphandle);
      Result := TRUE;
{$ENDIF}
      exit;
   end;
end;

procedure PomiTextOut (dsurface: TDirectDrawSurface; x, y: integer; str: string);
var
   i, n: integer;
   d: TDirectDrawSurface;
begin
   for i:=1 to Length(str) do begin
      n := byte(str[i]) - byte('0');
      if n in [0..9] then begin
         d := g_WMainImages.Images[30 + n];
         if d <> nil then
            dsurface.Draw (x + i*8, y, d.ClientRect, d, TRUE);
      end else begin
         if str[i] = '-' then begin
            d := g_WMainImages.Images[40];
            if d <> nil then
               dsurface.Draw (x + i*8, y, d.ClientRect, d, TRUE);
         end;
      end;
   end;
end;

procedure WaitAndPass (msec: longword);
var
   start: longword;
begin
   start := GetTickCount;
   while GetTickCount - start < msec do begin
      Application.ProcessMessages;
   end;
end;

function GetRGB (c256: byte): integer;
begin
  with frmMain.DxDraw do
    Result:=RGB(DefColorTable[c256].rgbRed,
                DefColorTable[c256].rgbGreen,
                DefColorTable[c256].rgbBlue);
end;

procedure DebugOutStr (msg: string);
var
   flname: string;
   fhandle: TextFile;
begin
//DScreen.AddChatBoardString(msg,clWhite, clBlack);
   exit;
   flname := '.\!debug.txt';
   if FileExists(flname) then begin
      AssignFile (fhandle, flname);
      Append (fhandle);
   end else begin
      AssignFile (fhandle, flname);
      Rewrite (fhandle);
   end;
   WriteLn (fhandle, TimeToStr(Time) + ' ' + msg);
   CloseFile (fhandle);
end;

function KeyboardHookProc (Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
begin
   Result:=0;
   if ((WParam = 9){ or (WParam = 13)}) and (g_nLastHookKey = 18) and (GetTickCount - g_dwLastHookKeyTime < 500) then begin
      if FrmMain.WindowState <> wsMinimized then begin
         FrmMain.WindowState := wsMinimized;
      end else
         Result := CallNextHookEx(g_ToolMenuHook, Code, WParam, Longint(@Msg));
      exit;
   end;
   g_nLastHookKey := WParam;
   g_dwLastHookKeyTime := GetTickCount;

   Result := CallNextHookEx(g_ToolMenuHook, Code, WParam, Longint(@Msg));
end;

procedure TfrmMain.FormCreate(Sender: TObject);
var
  flname, str: string;
  ini: TIniFile;
begin
  CLI := TCLIParser.Create;
  if (CLI.Exists('ini') = -1) then CLI.ParseArgs('--ini .\mir2.ini');
  if not FileExists(CLI.Get(CLI.Exists('ini')).sValue) then CLI.ParseArgs('--ini .\mir2.ini');
  ini := nil;

  g_AutoPickupList :=TList.Create;
  g_ShowItemList   :=TGList.Create;

  g_DWinMan:=TDWinManager.Create(Self);
  g_DXDraw:=DXDraw;
   Randomize;
   ini := TIniFile.Create (CLI.Get(CLI.Exists('ini')).sValue);
   if ini <> nil then begin
       g_sServerAddr := ini.ReadString ('Setup', 'ServerAddr', g_sServerAddr);
       g_nServerPort := ini.ReadInteger ('Setup', 'ServerPort', g_nServerPort);
       LocalLanguage := imOpen;

      g_boWindowTest := False;//ini.ReadBool ('Setup', 'WindowTest', g_boWindowTest);
      g_boDisableFlip := ini.ReadBool ('Setup', 'DisableFlip', g_boDisableFlip);
      g_boFullScreen := ini.ReadBool ('Setup', 'FullScreen', g_boFullScreen);
      g_sCurFontName := ini.ReadString ('Setup', 'FontName', g_sCurFontName);
      g_boForceAddr := ini.ReadBool ('Setup', 'ForceAddr', g_boForceAddr);
      g_sSelectServerAddr := ini.ReadString ('Setup', 'SelectServerAddr', g_sSelectServerAddr);
      g_nSelectServerPort := ini.ReadInteger ('Setup', 'SelectServerPort', g_nSelectServerPort);
      g_sGameServerAddr := ini.ReadString ('Setup', 'GameServerAddr', g_sGameServerAddr);
      g_nGameServerPort := ini.ReadInteger ('Setup', 'GameServerPort', g_nGameServerPort);
      g_boAutoLogin := ini.ReadBool ('Auto', 'AutoLogin', g_boAutoLogin);
      g_boAutoServer := ini.ReadBool ('Auto', 'AutoServer', g_boAutoServer);
      g_sAutoID := ini.ReadString ('Auto', 'AutoID', g_sAutoID);
      g_sAutoPass := ini.ReadString ('Auto', 'AutoPass', g_sAutoPass);
      g_sAutoServerName := ini.ReadString ('Auto', 'AutoServerName', g_sAutoServerName);
      g_boSkillSetting := ini.ReadBool ('Option', 'SkillKeyMode', g_boSkillSetting);
      g_boSkillBarNum := ini.ReadBool ('Option', 'SkillBarNum', g_boSkillBarNum);
      g_boShowSkillBar := ini.ReadBool ('Option', 'SkillBarView', g_boShowSkillBar);
      g_boEffect := ini.ReadBool ('Option', 'ViewEffect', g_boEffect);
      g_boSound := ini.ReadBool ('Option', 'Sound', g_boSound);
      g_boShowAllItem := ini.ReadBool ('Option', 'DropItemView', g_boShowAllItem);
      g_boNameAllView := ini.ReadBool ('Option', 'ViewAllName', g_boNameAllView);
      g_boHPView := ini.ReadBool ('Option', 'ViewHPType', g_boHPView);

      if g_boFullScreen or not g_boWindowTest then begin
        frmMain.BorderStyle := bsNone;
        g_boDisableFlip := True;
        frmMain.Left := 0;
        frmMain.Top := 0;        
      end
      else begin
        frmMain.BorderStyle := bsSingle;
        frmMain.Left := ini.ReadInteger('Positions', 'Left', 100);
        frmMain.Top := ini.ReadInteger('Positions', 'Top', 100);
      end;
      ini.Free;
   end;

{$IF CLIENTTYPE = RMCLIENT}
//    g_sLogoText:=RMCLIENTTITLE;
{$IFEND}

   Caption:=DecodeString(DecodeString(RMCLIENTTITLE));
   if g_boFullScreen then
     DXDraw.Options:=DXDraw.Options + [doFullScreen];
   LoadWMImagesLib(nil);
   NpcImageList:=TList.Create;
   ItemImageList:=TList.Create;
   WeaponImageList:=TList.Create;
   HumImageList:=TList.Create;
   g_DXSound:=TDXSound.Create(Self);
   g_DXSound.Initialize;
   DXDraw.Display.Width:=SCREENWIDTH;
   DXDraw.Display.Height:=SCREENHEIGHT;

  if g_DXSound.Initialized then begin
    g_Sound:= TSoundEngine.Create (g_DXSound.DSound);
    MP3:=TMPEG.Create(nil);
  end else begin
    g_Sound:= nil;
    MP3:=nil;
  end;
  LoadDecoList();

   g_ToolMenuHook := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, 0, GetCurrentThreadID);

   g_SoundList := TStringList.Create;
   BGMusicList:=TStringList.Create;

   flname := '.\wav\mirsound.lst';
   LoadSoundList (flname);
   flname := '.\wav\BGList.lst';
   LoadBGMusicList(flname);
   //if FileExists (flname) then
   //   SoundList.LoadFromFile (flname);

   DScreen := TDrawScreen.Create;
   IntroScene := TIntroScene.Create;
   LoginScene := TLoginScene.Create;
   SelectChrScene := TSelectChrScene.Create;
//   LoadingScene := TLoading.Create;
//   LoginNoticeScene := TLoginNotice.Create;
   PlayScene := TPlayScene.Create;
   Map              := TMap.Create;
   g_DropedItemList := TList.Create;
   g_MagicList        := TList.Create;
   g_FreeActorList    := TList.Create;
   //DObjList := TList.Create;
   EventMan := TClEventManager.Create;
   g_ChangeFaceReadyList := TList.Create;
   g_ServerList:=TStringList.Create;
   g_MySelf := nil;
   FillChar (g_UseItems, sizeof(TClientItem)*13, #0);
   FillChar (g_ItemArr, sizeof(TClientItem)*MAXBAGITEMCL, #0);
   FillChar (g_StoreItem, sizeof(TClientItem)*MAXSTORAGEITEMCL, #0);
   FillChar (g_DealItems, sizeof(TClientItem)*10, #0);
   FillChar (g_DealRemoteItems, sizeof(TClientItem)*20, #0);
   FillChar (g_RefineItems, sizeof(TClientItem)*16, #0);
   g_SaveItemList := TList.Create;
   g_MenuItemList := TList.Create;
   g_WaitingUseItem.Item.S.Name := '';
   g_EatingItem.S.Name := '';

   g_nTargetX := -1;
   g_nTargetY := -1;
   g_TargetCret := nil;
   g_FocusCret := nil;
   g_FocusItem := nil;
   g_MagicTarget := nil;
   g_nDebugCount := 0;
   g_nDebugCount1 := 0;
   g_nDebugCount2 := 0;
   g_nTestSendCount := 0;
   g_nTestReceiveCount := 0;
   g_boServerChanging := FALSE;
   g_boBagLoaded := FALSE;
   g_boStoreLoaded := FALSE;
   g_boAutoDig := FALSE;

   g_dwLatestClientTime2 := 0;
   g_dwFirstClientTime := 0;
   g_dwFirstServerTime := 0;
   g_dwFirstClientTimerTime := 0;
   g_dwLatestClientTimerTime := 0;
   g_dwFirstClientGetTime := 0;
   g_dwLatestClientGetTime := 0;

   g_nTimeFakeDetectCount := 0;
   g_nTimeFakeDetectTimer := 0;
   g_nTimeFakeDetectSum := 0;

   g_dwSHGetTime := 0;
   g_dwSHTimerTime := 0;
   g_nSHFakeCount := 0;

   g_nDayBright := 3;
   g_nAreaStateValue := 0;
   g_ConnectionStep := cnsLogin;
   g_boSendLogin:=False;
   g_boServerConnected := FALSE;
   SocStr := '';
   WarningLevel := 0;
   ActionFailLock := FALSE;
   g_boMapMoving := FALSE;
   g_boMapMovingWait := FALSE;
   g_boCheckBadMapMode := FALSE;
   g_boCheckSpeedHackDisplay := FALSE;
   g_boViewMiniMap := FALSE;
   g_boShowGreenHint := FALSE;
   g_boShowWhiteHint := FALSE;
   FailDir := 0;
   FailAction := 0;
   g_nDupSelection := 0;

   g_dwLastAttackTick := GetTickCount;
   g_dwLastMoveTick := GetTickCount;
   g_dwLatestSpellTick := GetTickCount;

   g_dwAutoPickupTick := GetTickCount;
   g_boFirstTime := TRUE;
   g_boItemMoving := FALSE;
   g_boDoFadeIn := FALSE;
   g_boDoFadeOut := FALSE;
   g_boDoFastFadeOut := FALSE;
   g_boAttackSlow := FALSE;
   g_boMoveSlow := FALSE;
   g_boFrozen := FALSE;
   g_boNextTimePowerHit := FALSE;
   g_boCanLongHit := FALSE;
   g_boCanWideHit := FALSE;
   g_boCanCrsHit   := False;
   g_boCanTwnHit   := False;

   g_boNextTimeFireHit := FALSE;

   g_boNoDarkness := FALSE;
   g_SoftClosed := FALSE;
   g_boQueryPrice := FALSE;
   g_sSellPriceStr := '';

   g_boAllowGroup := FALSE;
   g_GroupMembers := TStringList.Create;

   MainWinHandle := DxDraw.Handle;

   BoOneClick := False;
   OneClickMode := toNone;

   g_boSound:=True;
   g_boBGSound:=True;

   if g_sMainParam1 = '' then begin
     CSocket.Address:=g_sServerAddr;
     CSocket.Port:=g_nServerPort;
   end else begin
      if (g_sMainParam1 <> '') and (g_sMainParam2 = '') then
         CSocket.Address := g_sMainParam1;
      if (g_sMainParam2 <> '') and (g_sMainParam3 = '') then begin
         CSocket.Address := g_sMainParam1;
         CSocket.Port := Str_ToInt (g_sMainParam2, 0);
      end;
      if (g_sMainParam3 <> '') then begin
         if CompareText (g_sMainParam1, '/KWG') = 0 then begin
            {
            CSocket.Address := kornetworldaddress;  //game.megapass.net';
            CSocket.Port := 9000;
            BoOneClick := TRUE;
            OneClickMode := toKornetWorld;
            with KornetWorld do begin
               CPIPcode := MainParam2;
               SVCcode  := MainParam3;
               LoginID  := MainParam4;
               CheckSum := MainParam5; //'dkskxhdkslxlkdkdsaaaasa';
            end;
            }
         end else begin
            CSocket.Address := g_sMainParam2;
            CSocket.Port := Str_ToInt (g_sMainParam3, 0);
            BoOneClick := TRUE;
         end;
      end;
   end;
   if BO_FOR_TEST then
      CSocket.Address := TestServerAddr;

   CSocket.Active:=True;

   //MainSurface := nil;
   DebugOutStr ('----------------------- started ------------------------');

   Application.OnException := OnProgramException;
   Application.OnIdle := AppOnIdle;
end;

procedure TfrmMain.OnProgramException (Sender: TObject; E: Exception);
begin
   DebugOutStr (E.Message);
end;

procedure TfrmMain.WMSysCommand(var Message: TWMSysCommand);
begin
{   with Message do begin
      if (CmdType and $FFF0) = SC_KEYMENU then begin

⌨️ 快捷键说明

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