J J
2012-10-25 14:44:50
EDIT: I got it working now, look at the bottom of the post. If anyone has tips to clean up my code / make it better let me know anyways!
Hi,
I've been playing around with Lazarus to make a plugin.
I no longer get compiling errors but when running my script I get an access violation error: Error: Exception: Access violation at line 30
I've added the stuff I'm using in a .zip
Script
Lazarus source
Added the dll and 0_0 map in a zip.
What am I trying to do?
Using a plugin to calculate where I am - very similar to SPS. Except that I want to make it more accurate as I will only use it in my Great Orb Project script.
If anyone has an idea why I get this access violation error or how I can fix the plugin/script, let me know :)
EDIT:
I was working with preset array lengths first but I changed it later. That was getting the error.
Setting the lengths has fixed it!
And a picture
http://imageshack.us/a/img198/7712/pluginworked.png
Pretty accurate aswell :)
Topics I've used
http://villavu.com/forum/showthread.php?t=41311
http://villavu.com/forum/showthread.php?t=58815
http://villavu.com/forum/showthread.php?t=78465
Hi,
I've been playing around with Lazarus to make a plugin.
I no longer get compiling errors but when running my script I get an access violation error: Error: Exception: Access violation at line 30
I've added the stuff I'm using in a .zip
Script
program GopWalking;
{$DEFINE SMART}
{$i SRL/srl.simba}
{$i SRL/srl/misc/smartgraphics.simba}
{$i SPS/sps.simba}
{$loadlib GOP}
procedure GetPos;
var
Minimap, x, y: Integer;
TMinimap, TMap: TMufasaBitmap;
MinimapInfo, MapInfo: TT3DIntegerArray;
Location: TPoint;
begin
// Getting minimap colorboxes
CopyClientToBitmap(Minimap, MMCX-50, MMCY-50, MMCX+50, MMCY+50);
TMinimap := GetMufasaBitmap(Minimap);
for x:=0 to high(MinimapInfo) do
for y:=0 to high(MinimapInfo[x]) do
SPS_MakeColorBox(TMinimap, x*5, y*5, 5, MinimapInfo[x][y]);
// Getting gopmap colorboxes
TMap := SPS_GetArea('0_0', RUNESCAPE_SURFACE);
for x:=0 to high(MapInfo) do
for y:=0 to high(MapInfo[x]) do
SPS_MakeColorBox(TMap, x*5, y*5, 5, MapInfo[x][y]);
TMap.Free;
Location := GopPos(MinimapInfo, MapInfo, 0.3);
end;
begin
// Setting up Simba
SetupSRL;
GetPos;
end.Lazarus source
library GOP;
{$mode objfpc}{$H+}
uses
Classes, sysutils
{ you can add units after this };
type
TT3DIntegerArray = array of array of array of integer;
function GopPos(MinimapInfo: TT3DIntegerArray; MapInfo: TT3DIntegerArray; Tolerance: Extended): TPoint; register;
var
x, y, i, j, R1, R2, G1, G2, B1, B2, Matches, BiggestMatch: Integer;
Location: TPoint;
begin
for x:=0 to 79 do
for y:=0 to 79 do
begin
Matches := 0;
for i:=0 to 19 do
for j:=0 to 19 do
begin
R1 := MapInfo[x+i][y+j][0];
R2 := MinimapInfo[i][j][0];
if(R1 > R2*(1-Tolerance)) then
if(R1 < R2*(1+Tolerance)) then
begin
G1 := MapInfo[x+i][y+j][1];
G2 := MinimapInfo[i][j][1];
if(G1 > G2*(1-Tolerance)) then
if(G1 < G2*(1+Tolerance)) then
begin
B1 := MapInfo[x+i][y+j][2];
B2 := MinimapInfo[i][j][2];
if(B1 > B2*(1-Tolerance)) then
if(B1 < B2*(1+Tolerance)) then
Inc(Matches);
end;
end;
if(Matches > BiggestMatch) then
begin
BiggestMatch := Matches;
Location := Point(x, y);
end;
end;
end;
Result := Point(Location.x*5+50, Location.y*5+50);
end;
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: integer; var sType, sTypeDef : string): integer; stdcall;
begin
result := x;
case (x) of
0: begin
sType := 'TT3DIntegerArray';
sTypeDef := 'array of array of array of integer;';
end;
else
result := -1;
end;
end;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetFunctionCallingConv(x: Integer): Integer; stdcall; export;
begin
Result := 0;
case x of
0: Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0: begin
ProcAddr := @GopPos;
StrPCopy(ProcDef, 'function GopPos(MinimapInfo: TT3DIntegerArray; MapInfo: TT3DIntegerArray; Tolerance: Extended): TPoint;');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount, GetFunctionInfo, GetFunctionCallingConv,
GetTypeCount, GetTypeInfo;
begin
end.Added the dll and 0_0 map in a zip.
What am I trying to do?
Using a plugin to calculate where I am - very similar to SPS. Except that I want to make it more accurate as I will only use it in my Great Orb Project script.
If anyone has an idea why I get this access violation error or how I can fix the plugin/script, let me know :)
EDIT:
I was working with preset array lengths first but I changed it later. That was getting the error.
Setting the lengths has fixed it!
program GopWalking;
{$DEFINE SMART}
{$i SRL/srl.simba}
{$i SRL/srl/misc/smartgraphics.simba}
{$i SPS/sps.simba}
{$loadlib GOP}
procedure GetPos;
var
Minimap, x, y: Integer;
TMinimap, TMap: TMufasaBitmap;
MinimapInfo, MapInfo: TT3DIntegerArray;
Location: TPoint;
begin
// Getting minimap colorboxes
SetLength(MinimapInfo, 20);
for x:=0 to 19 do
SetLength(MinimapInfo[x], 20);
CopyClientToBitmap(Minimap, MMCX-50, MMCY-50, MMCX+50, MMCY+50);
TMinimap := GetMufasaBitmap(Minimap);
for x:=0 to 19 do
for y:=0 to 19 do
SPS_MakeColorBox(TMinimap, x*5, y*5, 5, MinimapInfo[x][y]);
// Getting gopmap colorboxes
SetLength(MapInfo, 100);
for x:=0 to 99 do
SetLength(MapInfo[x], 100);
TMap := SPS_GetArea('0_0', RUNESCAPE_SURFACE);
for x:=0 to 99 do
for y:=0 to 99 do
SPS_MakeColorBox(TMap, x*5, y*5, 5, MapInfo[x][y]);
TMap.Free;
Location := GopPos(MinimapInfo, MapInfo, 0.3);
writeln('My location: ' + ToStr(Location));
end;
begin
// Setting up Simba
SetupSRL;
writeln('Start: ' + ToStr(GetSystemTime));
GetPos;
writeln('End: ' + ToStr(GetSystemTime));
end.And a picture
http://imageshack.us/a/img198/7712/pluginworked.png
Pretty accurate aswell :)
Topics I've used
http://villavu.com/forum/showthread.php?t=41311
http://villavu.com/forum/showthread.php?t=58815
http://villavu.com/forum/showthread.php?t=78465