Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit spellbook;
- interface
- uses SysUtils, Classes, reader;
- type PWReader = ^WReader;
- type TSpellbook = class
- Spells: TStringList;
- SID: TStringList;
- pReader: PWReader;
- constructor Create(pTr: PWReader);
- procedure ImportSpellBook;
- end;
- type PSpellBook = ^TSpellBook;
- type TSpell = class
- Addr: Cardinal;
- pReader: PWReader;
- SpellBook: PSpellBook;
- constructor Create(pTr: Cardinal; Reader: PWReader; pSB: PSpellBook);
- function Name: String;
- function SpellID: Integer;
- end;
- function GetSpellByName(const pSB: PSpellBook; const Name: String): TSpell; stdcall;
- procedure CastSpellBySpell(Spell: TSpell);stdcall;
- implementation
- uses MainFrame;
- constructor TSpell.Create(pTr: Cardinal; Reader: PWReader; pSB: PSpellBook);
- begin
- Self.Addr := Ptr;
- Self.pReader := Reader;
- Self.SpellBook := pSB;
- // Debuging shows: SpellBook.SID.Count is ok
- end;
- function TSpell.Name: String;
- begin
- Result := SpellBook^.SID.Values[IntToStr(Self.SpellID)];
- // Here Spellbook^.SID.Count -> Access Violation
- if Result = '' then begin
- Result := 'Unknown';
- end;
- end;
- function TSpell.SpellID: Integer;
- begin
- Result := pReader^.ReadInteger(Addr + $4, false);
- end;
- constructor TSpellBook.Create(pTr: PWReader);
- begin
- pReader := pTr;
- Spells := TStringList.Create();
- SID := TStringList.Create();
- SID.LoadFromFile('spellnames.txt');
- end;
- procedure TSpellBook.ImportSpellBook();
- begin
- for I := 0 to NOS - 1 do begin
- Spells.AddObject(IntToStr(I), TObject(TSpell.Create(Struct, pReader, @Self)));
- 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));
- // Debugging: Here .Name works!!
- end;
- end;
- function GetSpellByName(const pSB: PSpellBook; const Name: String): TSpell; stdcall;
- var I: Cardinal;
- begin
- Result := nil;
- for I := 0 to pSB^.Spells.Count - 1 do begin
- 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...
- Result := TSpell(pSB^.Spells.Objects[pSB^.Spells.IndexOf(IntToStr(I))]);
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement