ReadySteadyGo
11-09-2011, 05:54 AM
library Dungeon;
{$mode objfpc}{$H+}
uses
Classes, math, sysutils
{ you can add units after this };
{type
TPoint = record
x: Integer;
y: Integer;
end; }
type
TPointArray = Array of TPoint;
type
T2DPointArray = Array of TPointArray;
type
TTarget_Exported = record
Target : Pointer;
FindColorsTolerance: function(target: pointer; var pts: TPointArray; col, x1, y1, x2, y2, tol: Integer): Boolean; stdcall;
SortTPAFrom: procedure(target: pointer; var a: TPointArray; const From: TPoint); stdcall;
SplitTPA: function(target: pointer; const arr: TPointArray; Dist: Integer): T2DPointArray; stdcall;
end;
{$R *.res}
{function Point(x, y: LongInt): TPoint;
begin
Result.x := x;
Result.y := y;
end; }
function Plugin_RoomBounds(ImageClient: TTarget_Exported): TPointArray; Register;
var
Rooms: TPointArray;
RoomsSplit: T2DPointArray;
begin
SetLength(Rooms, 0);
if ImageClient.FindColorsTolerance(ImageClient.Target , Rooms, 16777215 , 550{MMX1}, 8{MMY1}, 703{MMX2}, 161{MMY2}, 400) then
begin
ImageClient.SortTPAFrom(ImageClient.Target, Rooms, Point(627{MMCX}, 85{MMCY}));
RoomsSplit := ImageClient.SplitTPA(ImageClient.Target, Rooms, 1);
Result := RoomsSplit[0];
//DebugTPA(Result, '');
end;
end;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetFunctionCallingConv(x : integer) : integer; stdcall;
begin
Result := 0;
case x of
0..0 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:
begin
ProcAddr := @Plugin_RoomBounds;
StrPCopy(ProcDef, 'function Plugin_RoomBounds(ImageClient: TTarget_Exported): TPointArray;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
end.
Getting an access violation when Plugin_RoomBounds is called. Can anyone work out why?
{$mode objfpc}{$H+}
uses
Classes, math, sysutils
{ you can add units after this };
{type
TPoint = record
x: Integer;
y: Integer;
end; }
type
TPointArray = Array of TPoint;
type
T2DPointArray = Array of TPointArray;
type
TTarget_Exported = record
Target : Pointer;
FindColorsTolerance: function(target: pointer; var pts: TPointArray; col, x1, y1, x2, y2, tol: Integer): Boolean; stdcall;
SortTPAFrom: procedure(target: pointer; var a: TPointArray; const From: TPoint); stdcall;
SplitTPA: function(target: pointer; const arr: TPointArray; Dist: Integer): T2DPointArray; stdcall;
end;
{$R *.res}
{function Point(x, y: LongInt): TPoint;
begin
Result.x := x;
Result.y := y;
end; }
function Plugin_RoomBounds(ImageClient: TTarget_Exported): TPointArray; Register;
var
Rooms: TPointArray;
RoomsSplit: T2DPointArray;
begin
SetLength(Rooms, 0);
if ImageClient.FindColorsTolerance(ImageClient.Target , Rooms, 16777215 , 550{MMX1}, 8{MMY1}, 703{MMX2}, 161{MMY2}, 400) then
begin
ImageClient.SortTPAFrom(ImageClient.Target, Rooms, Point(627{MMCX}, 85{MMCY}));
RoomsSplit := ImageClient.SplitTPA(ImageClient.Target, Rooms, 1);
Result := RoomsSplit[0];
//DebugTPA(Result, '');
end;
end;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetFunctionCallingConv(x : integer) : integer; stdcall;
begin
Result := 0;
case x of
0..0 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:
begin
ProcAddr := @Plugin_RoomBounds;
StrPCopy(ProcDef, 'function Plugin_RoomBounds(ImageClient: TTarget_Exported): TPointArray;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
end.
Getting an access violation when Plugin_RoomBounds is called. Can anyone work out why?