Code:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,math, ComCtrls,StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TNPCDude = record
ID : Cardinal;
X : Single;
Y : Single;
Z : Single;
end;
type
TNPCDudes = array of TNPCDude;
var
Form1: TForm1;
NPCs : TNPCDudes;
fs : TFilestream;
ml : TStringlist;
implementation
{$R *.dfm}
{
Function GetNPCName (ID : Cardinal) : string;
var
i : Integer;
begin
ml.LoadFromFile('npclist.txt');
for I := 0 to ml.Count - 1 do
begin
if StrUtils.ContainsText(ml[i],IntToStr(ID)) = true then
begin
if ContainsText(ml[i],' '
result := Copy(ml[i],Pos(' ',
end;
end;
end; }
Function WeGotThis(ID : Cardinal) : Boolean;
var i : integer;
begin
result := false;
for i := 0 to length(NPCs) - 1 do
if NPCs[i].ID = ID then
begin
result := True;
Exit;
end;
end;
function FileSize(fileName: wideString): Int64;
var
sr: TSearchRec;
begin
if FindFirst(fileName, faAnyFile, sr) = 0 then
result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) +
Int64(sr.FindData.nFileSizeLow)
else
result := -1;
FindClose(sr);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
Buffer : array of Byte;
NPCType,Structtype : Cardinal;
t1,t2,t0 : cardinal;
offset,lastoffset : cardinal;
sl : TStringlist;
files : Cardinal;
nCreatures : Cardinal;
tid : cardinal;
begin
files := FileSize('npcgen.data');
fs := TFileStream.Create('npcgen.data',fmOpenRead);
SetLength(Buffer,files);
fs.ReadBuffer(Buffer[0],files);
sl := TStringList.Create;
t1 := 0;
t0 := 0;
t2 := 0;
offset := 24;
Copymemory(@nCreatures,@Buffer[4],4);
ProgressBar1.Max := nCreatures;
Setlength(NPCs,nCreatures);
for i := 0 to nCreatures -1 do
begin
Copymemory(@NPCType,@Buffer[offset + 40 {NPC type in struct} ],4);
Copymemory(@tid,@Buffer[Offset + 67],4);
Copymemory(@NPCs[i].X,@Buffer[Offset + 4],4);
NPCs[i].X := NPCs[i].X / 10 + 400;
Copymemory(@NPCs[i].Y,@Buffer[Offset + 12],4);
NPCs[i].Y := NPCs[i].Y / 10 + 550;
Copymemory(@NPCs[i].Z,@Buffer[Offset + 8],4);
NPCs[i].Z := NPCs[i].Z / 10;
NPCs[i].ID := tid;
sl.Add(IntToStr(NPCs[i].ID) + ' X : ' +
FloatToStr(NPCs[i].X) + ' Y ' +
FloatToStr(NPCs[i].Y) + ' Z : ' +
FloatToStr(NPCs[i].Z) +
' -> '+ IntToStr(offset));
Copymemory(@StructType,@Buffer[offset{NPC type in struct} ],4);
case Structtype of
0 : Inc(offset,71);
1 : inc(offset,131);
2 : inc(offset,191);
3 : inc(offset,251);
4 : inc(offset,311);
5 : inc(offset,371);
6 : inc(offset,431);
7 : inc(offset,491);
end;
if lastoffset = Offset then
begin
Memo1.Lines.Add('error, unknown datatype : ' + IntToStr(offset));
sl.SaveToFile('test.txt');
Exit;
end;
lastoffset := offset;
ProgressBar1.Position := i;
Application.ProcessMessages;
end;
sl.SaveToFile('test.txt');
Memo1.Lines.Add('Done, no errors! :)');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ml := TStringList.Create;
end;
end.