Got this running at pure bytecode.
SMART doesn't work: SIGSEGV @ 'client waiting'. Yes I got SRL compiling and semi-working with it (there's no window selector so it's a bit hard to get the right client and my FindWindowBySize only works with Simba, not this). It moves the mouse and writeln's shit and such so it looks like the script is actually running.
Note: in order to execute you
NEED to compile
any random script this is so it populates the function arrays (really, it's the most clean way to do it.) So I added some Hello World/"dont crack my scripts plz". If you add plugins there it just works, too. Yup, they just work. No extra code required (notice my attempts everywhere to try to hack them in manually).
If anyone can fix SMART I'd love them forever.
program compileur;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, Interfaces, Forms, mmlpsthread, ocr, LCLIntf,
lazmouseandkeyinput, uPSComponent, plugins, uPSCompiler, uPSRuntime, mufasabase;
type
TPSThreadEx = class(TPSThread)
private
procedure NewExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
public
procedure Execute; override;
procedure AddFuncExec(Ptr: Pointer; const Decl: string;
CallingConv: TDelphiCallingConvention);
end;
TBasket = class
public
procedure SafeCallThread;
end;
var
Thread: TPSThreadEx;
AppPath, IncludePath, PluginPath, FontPath, Output: string;
NeedsCompile: boolean = True;
CurrentSyncInfo: TSyncInfo;
OldExecImport : TPSOnExecImportEvent;
function Muf_Conv_to_PS_Conv( conv : integer) : TDelphiCallingConvention;
begin
case conv of
cv_StdCall : result := cdStdCall;
cv_Register: result := cdRegister;
else
raise exception.createfmt('Unknown Calling Convention[%d]',[conv]);
end;
end;
function GetFileContents(const filename: string): string;
begin
with TFileStream.Create(filename, fmOpenRead) do
try
SetLength(Result, Size);
Read(PChar(Result)^, Size);
finally
Free;
end;
end;
procedure TPSThreadEx.AddFuncExec(Ptr: Pointer; const Decl: string;
CallingConv: TDelphiCallingConvention);
var
P: TPSRegProc;
name : string;
pDecl: TPSParametersDecl;
FT : TPMFuncType;
begin
// pDecl := TPSParametersDecl.Create;
name := LowerCase(Decl);
//if Pos('procedure', name) <> 0 then
//name := betw ( 'procedure', '(');
p := Self.PSScript.Comp.AddDelphiFunction(Decl);
Self.PSScript.Exec.RegisterDelphiFunction(Ptr, p.Name, CallingConv); //yay!
// pDecl.Free; //no leaky leaky
end;
procedure TPSThreadEx.NewExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
var
i, ii : integer;
begin
writeln('Now is execimport');
OldExecImport(Sender, se, x);
{for i := High(PluginsToLoad) downto 0 do
begin
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
Self.AddFuncExec(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
end; }
end;
procedure TPSThreadEx.Execute;
procedure AddAllShit;
var
i, ii : integer;
begin
writeln('bla');
{for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
begin
writeln('adding function..');
self.AddFuncExec(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
end;}
// for i := 0 to high(ExportedMethods) do
// if ExportedMethods[i].FuncPtr <> nil then
// Self.AddFuncExec(ExportedMethods[i].FuncPtr,ExportedMethods[i].FuncDecl,
// {$ifdef PS_SafeCall}cdSafeCall{$else}cdRegister{$endif});
end;
begin
CurrThread := Self;
try
if (NeedsCompile) then
begin
Starttime := GetTickCount;
if PSScript.Compile then
begin
OutputMessages;
Writeln('Compiled successfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
end else
begin
OutputMessages;
Writeln('Compiling failed.');
exit;
end;
end;
if (not (CompileOnly)) then
begin
//PSScript.Script.Add('{$Loadlib libsmart}'); //Don't ask..
PSScript.Script.Add('{$Loadlib irokiplugin}');
PSScript.Script.Add('begin');
PSScript.Script.Add('writeln(''COPYRIGHT (C) SCREENSCRAPERS.ORG 2012'');');
PSScript.Script.Add('writeln(''Remember: Piracy is a crime!''); end.');
PSScript.Script.Add('end.');
if PSScript.Compile then
begin
OutputMessages;
Writeln('Compiled successfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
end else
begin
OutputMessages;
Writeln('Compiling failed.');
exit;
end;
writeln('compiled bla.');
//PSScript.o;
OldExecImport := @Self.OnExecImport;
PSScript.OnExecImport:= @Self.NewExecImport;
//AddAllShit;
Writeln('Loading script');
PSScript.Exec.LoadData(GetFileContents(Application.GetOptionValue('l', 'load')));
Writeln('Loaded ftw.');
if (PSScript.Exec.RunScript) then
begin
HandleScriptTerminates;
Writeln('Successfully executed.');
end else
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString, errRuntime, PSScript.ExecErrorFileName);
writeln('Done now already???');
end;
except
on E: Exception do
Writeln('Exception in Script: ' + e.message);
end;
end;
procedure _WriteLn(x: string);
begin
WriteLn(x);
end;
procedure SetFileContents(const filename: string; const Data: string);
var
fmCustom: Word = fmOpenWrite;
begin
if (not (FileExists(filename))) then
fmCustom := fmCreate;
with TFileStream.Create(filename, fmCustom) do
try
Write(PChar(Data)^, Length(Data));
finally
Free;
end;
end;
procedure HandleParameters;
var
ErrorMsg: string;
I: LongInt;
begin
ErrorMsg := Application.CheckOptions('rf:s:l:p:', 'run file: save: load: plugins:');
if (ErrorMsg <> '') then
begin
WriteLn(ErrorMsg);
Exit;
end;
if (Application.HasOption('f', 'file')) then
begin
Thread.PSScript.Script.Text := GetFileContents(Application.GetOptionValue('f', 'file'));
if (Application.HasOption('r', 'run')) then
Thread.CompileOnly := False;
if (Application.HasOption('s', 'save')) then
Output := Application.GetOptionValue('s', 'save');
exit;
end;
if (Application.HasOption('p', 'plugins')) then
begin
with TStringList.Create() do
try
CommaText := Application.GetOptionValue('p', 'plugins');
for I := 0 to Count - 1 do
PluginsGlob.LoadPlugin(Strings[I]);
finally
Free;
end;
end;
if (Application.HasOption('l', 'load')) then
begin
Thread.CompileOnly := False;
NeedsCompile := False;
end;
end;
procedure TBasket.SafeCallThread;
var
_Thread: TPSThread;
LocalCopy: TSyncInfo;
begin
LocalCopy := CurrentSyncInfo;
WriteLn('Executing: ' + LocalCopy.MethodName);
_Thread := TPSThread(LocalCopy.OldThread);
mmlpsthread.CurrThread := _Thread;
try
with _Thread.PSScript do
LocalCopy.Res^ := Exec.RunProcPVar(LocalCopy.V^, Exec.GetProc(LocalCopy.MethodName));
finally
mmlpsthread.CurrThread := nil;
end;
end;
procedure DoRun;
var
temp: string;
Basket: TBasket;
begin
writeln('Welcome to script compiler based on Simba '+IntToStr(SimbaVersion));
AppPath := IncludeTrailingPathDelimiter(Application.Location);
IncludePath := IncludeTrailingPathDelimiter(AppPath + 'Includes');
PluginPath := IncludeTrailingPathDelimiter(AppPath + 'Plugins');
FontPath := IncludeTrailingPathDelimiter(AppPath + 'Fonts');
Basket := TBasket.Create();
CurrentSyncInfo.SyncMethod:= @Basket.SafeCallThread;
Thread := TPSThreadEx.Create(True, @CurrentSyncInfo, PluginPath);
Thread.CompileOnly := True;
Thread.FreeOnTerminate := False;
Thread.SetDebug(@_Writeln);
Thread.SetPaths(AppPath, AppPath, IncludePath, PluginPath, FontPath);
if DirectoryExists(PluginPath) then
PluginsGlob.AddPath(PluginPath);
Thread.Client.MOCR := TMOCR.Create(Thread.Client);
Thread.Client.MOCR.InitTOCR(FontPath);
HandleParameters;
Thread.Start;
Thread.WaitFor;
if (Assigned(Basket)) then
Basket.Free;
if (Output <> '') then
begin
temp := '';
Thread.PSScript.GetCompiled(temp);
SetFileContents(Output, temp);
end;
if (Assigned(Thread)) then
Thread.Free;
end;
begin
Application.Initialize;
DoRun;
ReadLn;
Application.Terminate;
end.
Edit: wtf when I used essminer it actually loaded smart and worked.. Cheers!