BenLand100
2007-12-22 22:35:47
This should be getting more towards the done state, here's an example of the reflection system and what it can do (really, it can do anything you are willing to maintain, or nothing assuming no one will maintain it ;)) This does not do everything (the MaxLevels and Experiences hooks aren't even used) but it gives you enough information to expand. All GetField methods now take an Object as the first parameter, if the field is static, this value should be 0, if its a field in an object, this should be the object. Look at GetMyPos.
Note, any method that returns an Object MUST be freed with SmartFreeObject unless you really want to crash Scar/Smart/Java all at the same time ;)
@Anyone who knows the client, feel free to extend this however, if you have any questions, post/ask.
Note, any method that returns an Object MUST be freed with SmartFreeObject unless you really want to crash Scar/Smart/Java all at the same time ;)
@Anyone who knows the client, feel free to extend this however, if you have any questions, post/ask.
const
//Global Static Hooks
SettingsArray = 'jb.k'; //int[]
CurrentLevels = 'ca.jb'; //int[]
MaxLevels = 'ma.V'; //int[]
Experiances = 'oa.d'; //int[]
BaseX = 'oa.a'; //int
BaseY = 'dd.b'; //int
MyPlayer = 'nf.j'; //Player
CompassAngle = 'rg.o'; //int (MinimapInt1)
MapOffsetAngle = 'vf.c'; //int (MinimapInt2)
//Character Hooks
CurrentX = 'nb'; //int
CurrentY = 'db'; //int
CharAnim = 'ac'; //int
CharMotion = 'T'; //int
CharName = 'W'; //StringWrap
//StringWrap Hooks
StringBytes = 'K'; //byte[]
//Returns the current level of your player (its a funny array)
function GetLevel(index: integer): integer;
begin
result:= SmartGetFieldArrayInt(0,CurrentLevels,index);
end;
//Converts a byte[] from StringWrap to a DelphiString (max length 256)
function StringFromBytes(jbytearray: integer): string;
begin
SetLength(result, 256);
SetLength(result, SmartStringFromBytes(jbytearray,result));
end;
//Returns last logged in player's name
function GetMyName: string;
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(0,MyPlayer+'.'+CharName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;
//Returns your animation
function GetMyAnim: integer;
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharAnim);
end;
//True if you are moving
function GetMyMoving: boolean;
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharMotion) > 0;
end;
//Calculates your x,y position or [somehugenumber] if not logged in
procedure GetMyPos(var x, y: Integer);
var
me: Integer;
begin
me:= SmartGetFieldObject(0,MyPlayer);
x:= SmartGetFieldInt(0,BaseX) + SmartGetFieldInt(me,CurrentX) shr 7;
y:= SmartGetFieldInt(0,BaseY) + SmartGetFieldInt(me,CurrentY) shr 7;
SmartFreeObject(me);
end;
//Dumps the settings array to an integer array
function DumpSettingArray: array[0..1999] of integer;
var
i: integer;
begin
for i:= 0 to 1999 do
Result[i]:= SmartGetFieldArrayInt(0,SettingsArray,i);
end;
//Returns -1 if no box open or 0..2 for the correct answer to the box
function BoxAnswer: integer;
var
boxIndex: Integer;
begin
boxIndex:= SmartGetFieldArrayInt(0,SettingsArray,312);
if boxIndex = 0 then
result:= -1
else
result:= (boxIndex shr 24) and $FF;
end;
//Returns the current Map angle in degrees
function GetMinimapAngleDeg: extended;
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * 180 / 1024;
end;
//Returns the current map angle in radians
function GetMinimapAngleRad: extended;
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * Pi / 1024;
end;
//converts the tile position tileX,tileY to a minimap location
procedure TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
GetMyPos(tempX, tempY);
tempX:= (tileX - tempX) * 4 - 2;
tempY:= (tempY - tileY) * 4 - 2; //Origin is South-West
screenX:= round(tempX*cos(angle) - tempY*sin(angle)) + 643;
screenY:= round(tempX*sin(angle) + tempY*cos(angle)) + 84;
end;