BenLand100
2012-04-29 16:06:25
Things to know:
- The new libsmart is IDENTICAL to the old libsmart (except for one additional method allowing it to be remotely started), so that, if you desire, you can continue to use the new SMART in the old way. That's not an issue now since libsmart was hardly changed besides bumping the version number and changing the screen title, but it may be in the future.
- There are two new binaries for each platform (windows 32bit users need libsmart32.dll, libsmartremote32.dll and smartremote.exe) that facilitate remote usage. Simba no longer interacts with libsmart directly, but rather interacts with libsmartremote, which starts new processes with smartremote, and provides communication.
- libsmartremote implements all of the functionality of libsmart under the same names, so programmers won't see a significant change there. There is one caveat to this: because I'm lazy, I didn't implement the reflection methods (though if they make a come back I will implement them).
- libsmartremote, like libsmart in v7.0+, implements EIOS that makes targeting SMART much easier, more intuitive, and less hackish.
- Remote SMART clients (referred to as clients from here on out) are referenced by their process id (PID) and generate files of the form SMART.PID, where PID is replaced by the numeric representation, in the current directory. This is how the script using libsmartremote (referred to as the controller from here on out) is made aware of existing SMART clients.
- smartremote takes arguments from the command line when invoked by libsmartremote and starts a new client.
- The client sets up a file mapped shared memory to transfer the image data and listen for commands
- A controller can pair with a client if it is unpaired, and maps its shared memory
- Once a controller is paired to a client, the controller can invoke methods across the shared memory, and read the image data provided by the client in the usual way. If the controller is unpaired, no client specific methods do nothing and return failure values.
- function SmartSpawnClient(remote_path, root, params: string; width, height: integer; initseq, useragent, jvmpath: string; maxmem: integer): integer; This is the new SmartSetup. The arguments are the same, with the addition of remote_path which is the path relative to the current directory to libsmart and smartremote. For Simba this is always './Plugins/'. useragent ,jvmpath, and maxmem produce sane defaults when set to zero length strings (or less than or equal to zero for maxmem). After invoking this method, the controller is automatically paired with the spawned client.
- function SmartGetClients(only_unpaired: boolean): integer; This tells libsmartremote to search for available clients, and returns the number found. It either searches for all clients or only the unpaired clients depending on the only_unpaired flag.
- function SmartClientID(idx: integer): integer; After calling SmartGetClients, you can use this method to retrieve the ID of any client found. 0 <= idx < SmartGetClients(true/false);
- function SmartPairClient(pid: integer): boolean; This pairs the controller to the client identified by pid. If the pairing fails, the function returns false and the controller is left in an unpaired state. On success, the function returns true. Failure is a result of the client being paired or being a zombie (zombies are automatically killed by this function).
- function SmartKillClient(pid: integer): boolean; This tells the client identified by pid to shutdown. It fails if the client is paired with another controller. After this method is invoked, the controller returns to its previous state unless it was paired with the client that was killed, in which case it is left unpaired. Returns true on success, false on failure.
- function SmartCurrentClient(): integer; Returns the ID of the client this controller is paired with, or zero if unpaired.
Invoking SetEIOSTarget('libsmartremote',IntToStr(pid)); sets all of Simba's targeted function, e.g. mouse/key/image related methods, to use the client identified by pid. This method fails with an exception if the client doesn't exist, is a zombie, or is paired with another controller. EIOS pairings DO NOT affect the controller's pairing, i.e. EIOS can have client A targeted while the controller has client B targetd. In this case, all Smart* methods will invoke client B while all Simba methods will interact with client A. Using EIOS targeting prevents you from having to manually override methods and is preferred over the old method. It requires a version of Simba that may or may not have been released as stable yet, so be patient.
tl/dr: Example Usage:
Smart runs in it's own process now, and here's an example of how to start it (requires Simba with EIOS support)
[LEFT]program RemoteSmartTest;
{$loadlib libsmartremote}
{**
* Pairs with some client. If force_new is false, it checks
* for running, unpaired clients and attempts to pair with
* one of them. If none of them were pairable (i.e. someone
* beat us to it / it was a zombie) or force_new is true,
* it then creates a new remote SMART client and pairs to it.
* The ID of the newly paired client is returned, or 0 for
* ultimate failure (this would be a serious bug and should
* never happen).
*}
function InitSmart(force_new: boolean): integer;
var
i, count: integer;
begin
if not force_new then
begin
count:= SmartGetClients(true); //Gets a list of the current clients (true->unpaired only)
if count > 0 then
begin
for i:= 0 to count-1 do
begin
result:= SmartClientID(i); //Get the i'th client ID
if SmartPairClient(result) then //Pair with that client
begin
SetEIOSTarget('libsmartremote',IntToStr(result)); //Set the client as the mouse/image target
exit; //Exit on success (could fail if it was a zombie)
end;
//Otherwise, try the next in the list
end;
end;
end;
//Otherwise, start a new chttps://github.com/downloads/BenLand100/SMART/SMARTv7.1alpha3.ziplient (auto pairs)
//These arguments are old, use new ones in practice. Note the jvmpath is for gentoo, it fails on other systems and tries the fallback jvm paths
result:= SmartSpawnClient('./Plugins/','http://world19.runescape.com/',',f5',765,503,'','','/usr/lib/jvm/sun-jre-bin-1.6/lib/amd64/server/libjvm.so',-1);
SetEIOSTarget('libsmartremote',IntToStr(result)); //Set the client as the mouse/image target
end;
var
bmp: integer;
begin
InitSmart(false);
writeln(SmartGetColor(50,50));
writeln(GetColor(50,50));
bmp:= BitmapFromClient(0,0,764,502);
DisplayDebugImgWindow(765,503);
DrawBitmapDebugImg(bmp);
FreeBitmap(bmp);
end.
[/LEFT]
Changelog: ===v7.1alpha4===
+Breaks compatibility with Simba pre 0.99
+All exports -> cdecl for full lape compatibility in Simba >=0.99
+Improved loading efficiency
+Fixed static-linking problems for windows
===v7.1beta===
+Export bugfixes
+Improved stability
+Proper ABI for Simba
===v7.1beta2===
+EIOS compatibility with new Simba (fixes access violation on SendKeys)
===v7.1===
+SendKeys uses the appropriate arguments now across the board
Source: https://github.com/BenLand100/SMART
Binaries: https://github.com/downloads/BenLand100/SMART/SMARTv7.1.zip

