Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.26 KB | None | 0 0
  1. unit spellbook;
  2. interface
  3. uses SysUtils, Classes, reader;
  4.  
  5. type PWReader = ^WReader;
  6.  
  7. type TSpellbook = class
  8.   Spells: TStringList;
  9.   SID: TStringList;
  10.   pReader: PWReader;
  11.   constructor Create(pTr: PWReader);
  12.   procedure ImportSpellBook;
  13. end;
  14.  
  15. type PSpellBook = ^TSpellBook;
  16.  
  17. type TSpell = class
  18.     Addr: Cardinal;
  19.     pReader: PWReader;
  20.     SpellBook: PSpellBook;
  21.     constructor Create(pTr: Cardinal; Reader: PWReader; pSB: PSpellBook);
  22.     function Name: String;
  23.     function SpellID: Integer;
  24. end;
  25.  
  26. function GetSpellByName(const pSB: PSpellBook; const Name: String): TSpell; stdcall;
  27. procedure CastSpellBySpell(Spell: TSpell);stdcall;
  28.  
  29. implementation
  30. uses MainFrame;
  31.  
  32. constructor TSpell.Create(pTr: Cardinal; Reader: PWReader; pSB: PSpellBook);
  33. begin
  34.   Self.Addr := Ptr;
  35.   Self.pReader := Reader;
  36.   Self.SpellBook := pSB;
  37. // Debuging shows: SpellBook.SID.Count is ok
  38. end;
  39.  
  40. function TSpell.Name: String;
  41. begin
  42. Result := SpellBook^.SID.Values[IntToStr(Self.SpellID)];
  43. // Here Spellbook^.SID.Count -> Access Violation
  44. if Result = '' then begin
  45.   Result := 'Unknown';
  46. end;
  47. end;
  48.  
  49. function TSpell.SpellID: Integer;
  50. begin
  51.   Result := pReader^.ReadInteger(Addr + $4, false);
  52. end;
  53.  
  54. constructor TSpellBook.Create(pTr: PWReader);
  55. begin
  56.   pReader := pTr;
  57.   Spells := TStringList.Create();
  58.   SID := TStringList.Create();
  59.   SID.LoadFromFile('spellnames.txt');
  60. end;
  61.  
  62. procedure TSpellBook.ImportSpellBook();
  63. begin
  64.   for I := 0 to NOS - 1 do begin
  65.       Spells.AddObject(IntToStr(I), TObject(TSpell.Create(Struct, pReader, @Self)));
  66.       MainFrame.Form1.Memo1.Lines.Add('Found Spell: ' + TSpell(Spells.Objects[Spells.IndexOf(IntToStr(I))]).Name + ' ID: ' + IntToStr(TSpell(Spells.Objects[Spells.IndexOf(IntToStr(I))]).SpellID));
  67.     // Debugging: Here .Name works!!
  68.   end;
  69. end;
  70.  
  71. function GetSpellByName(const pSB: PSpellBook; const Name: String): TSpell; stdcall;
  72. var I: Cardinal;
  73. begin
  74. Result := nil;
  75.   for I := 0 to pSB^.Spells.Count - 1 do begin
  76.     if TSpell(pSB^.Spells.Objects[pSB^.Spells.IndexOf(IntToStr(I))]).Name = Name then begin // Access Violation [pSB^.Spells.Count works but TSpell().Spellbook.Spells.Count does not work...
  77.       Result := TSpell(pSB^.Spells.Objects[pSB^.Spells.IndexOf(IntToStr(I))]);
  78.     end;
  79.   end;  
  80. end;
  81. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement