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

📄 debugfindpattern.pas

📁 一个不出名的GBA模拟器
💻 PAS
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// debugFindPattern.pas: Find pattern dialog (for the hex editor)   //
//                                                                  //
// The contents of this file are subject to the Bottled Light       //
// Public License Version 1.0 (the "License"); you may not use this //
// file except in compliance with the License. You may obtain a     //
// copy of the License at http://www.bottledlight.com/BLPL/         //
//                                                                  //
// Software distributed under the License is distributed on an      //
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   //
// implied. See the License for the specific language governing     //
// rights and limitations under the License.                        //
//                                                                  //
// The Original Code is the Mappy VM User Interface, released       //
// April 1st, 2003. The Initial Developer of the Original Code is   //
// Bottled Light, Inc. Portions created by Bottled Light, Inc. are  //
// Copyright (C) 2001-2003 Bottled Light, Inc. All Rights Reserved. //
//                                                                  //
// Author(s):                                                       //
//   Michael Noland (joat), michael@bottledlight.com                //
//                                                                  //
// Changelog:                                                       //
//   1.0: First public release (April 1st, 2003)                    //
//                                                                  //
// Notes:                                                           //
//   None at present.                                               //
//                                                                  //
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
unit debugFindPattern; ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
interface ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, nexus, AddressSpace;

//////////////////////////////////////////////////////////////////////

type
  TdbgFindPattern = class(TForm)
    addressGroup: TGroupBox;
    cbBaseAddress: TComboBox;
    rgDirection: TRadioGroup;
    bFind: TButton;
    bCancel: TButton;
    bHelp: TButton;
    findGroup: TGroupBox;
    rbText: TRadioButton;
    rbHex: TRadioButton;
    ePattern: TEdit;
    bLoad: TButton;
    openDialog: TOpenDialog;
    procedure FormShow(Sender: TObject);
    procedure LoadPattern(Sender: TObject);
    procedure ChangePatternType(Sender: TObject);
    procedure ChangeBaseAddress(Sender: TObject);
    procedure ChangeDirection(Sender: TObject);
    procedure CancelSearch(Sender: TObject);
    procedure ShowHelp(Sender: TObject);
    procedure ePatternChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    data: string;
    address: uint32;
    goDown: boolean;
    procedure UpdateText;
  end;

//////////////////////////////////////////////////////////////////////

var
  dbgFindPattern: TdbgFindPattern;

//////////////////////////////////////////////////////////////////////
implementation ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

{$R *.DFM}

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.FormShow(Sender: TObject);
begin
  cbBaseAddress.Text := '$' + IntToHex(address, 8);
  if goDown then rgDirection.ItemIndex := 1;
  rbText.Checked := true;
  UpdateText;

  // Load the translation
  LoadTranslation(self, translation);
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.LoadPattern(Sender: TObject);
var
  fp: TFileStream;
begin
  if openDialog.Execute then begin
    fp := TFileStream.Create(openDialog.FileName, fmOpenRead);
    SetLength(data, fp.Size);
    fp.Read((@(data[1]))^, fp.Size);
    fp.Free;
    UpdateText;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.ChangePatternType(Sender: TObject);
begin
  UpdateText;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.ChangeBaseAddress(Sender: TObject);
var
  st: string;
begin
  st := Trim(cbBaseAddress.Text);
  if Length(st) > 0 then begin
    if st[1] <> '$' then st := '$' + st;
    address := StrToIntDef(st, address);
    cbBaseAddress.Text := '$' + IntToHex(address, 8);
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.ChangeDirection(Sender: TObject);
begin
  goDown := rgDirection.ItemIndex > 0;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.CancelSearch(Sender: TObject);
begin
  Close;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.ShowHelp(Sender: TObject);
begin
  ShowWebPage(helpFiles.strings[HelpContext-1]);
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.UpdateText;
var
  i: integer;
  st: string;
begin
  if rbText.Checked then
    ePattern.Text := data
  else begin
    st := '';
    for i := 1 to Length(data) do
      st := st + IntToHex(Ord(data[i]), 2);
    ePattern.Text := st;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.ePatternChange(Sender: TObject);
var
  i: integer;
  st: string;
begin
  if rbHex.Checked then begin
    st := ePattern.Text;
    if Odd(Length(st)) then st := '0' + st;
    SetLength(data, Length(st) div 2);
    for i := 1 to Length(data) do
      data[i] := Chr(StrToIntDef('$' + Copy(st, i*2-1, 2), Ord(data[i])));
  end else
    data := ePattern.Text;
end;

//////////////////////////////////////////////////////////////////////

procedure TdbgFindPattern.FormCreate(Sender: TObject);
begin
  HelpContext := LinkHelp('memory_editor.html#find');
  address := $00000000;
  goDown := false;
  data := '';
end;

//////////////////////////////////////////////////////////////////////

end.

//////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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