Advertisement
WarPie90

RI.simba for Simba 2.0

Oct 18th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.44 KB | None | 0 0
  1. {$loadlib ..\Includes\SRL\plugins\libremoteinput}
  2.  
  3. type
  4.   TRemoteInput = record
  5.     FImage: TExternalImage;
  6.     EIOS: Pointer;
  7.     PID: Int32;
  8.   end;
  9.  
  10. procedure TRemoteInput.Setup;
  11. const
  12.   RS_EXECUTABLE = {$IFDEF WINDOWS}'JagexLauncher.exe'{$ELSE}'java'{$ENDIF};
  13. begin
  14.   {$IFNDEF SIMBAHEADLESS}
  15.   if (Self.PID = 0) then
  16.     Self.PID := GetSimbaTargetPID();
  17.   {$ENDIF}
  18.  
  19.   try
  20.     if (Self.PID = 0) then
  21.     begin
  22.       if (ShowQuestionDialog('SRL', 'Automatically try to find a RS client?') = False) then
  23.         raise 'No RS clients found';
  24.  
  25.       RIInject(RS_EXECUTABLE, Self.PID);
  26.     end else
  27.       RIInject(Self.PID);
  28.  
  29.     Self.EIOS := EIOS_PairClient(Self.PID);
  30.     if (Self.EIOS <> nil) then
  31.       Target.SetEIOS('..\Includes\SRL\plugins\libremoteinput', ToString(Self.PID));
  32.   except
  33.     WriteLn(GetExceptionMessage());
  34.   end;
  35. end;
  36.  
  37. function TRemoteInput.IsSetup: Boolean;
  38. begin
  39.   Result := (Self.PID > 0);
  40. end;
  41.  
  42. property TRemoteInput.Image: TExternalImage;
  43. begin
  44.   if (Self.FImage = nil) then
  45.   begin
  46.     EIOS_SetGraphicsDebugging(Self.EIOS, True);
  47.  
  48.     Self.FImage := TExternalImage.Create();
  49.     Self.FImage.SetMemory(PColorBGRA(EIOS_GetDebugImageBuffer(Self.EIOS)), Target.Width, Target.Height);
  50.  
  51.     (*
  52.     Self.Image.SetPersistentMemory(
  53.        PtrUInt(EIOS_GetDebugImageBuffer(Self.EIOS)),
  54.        Target.Width, Target.Height
  55.     );
  56.     *)
  57.     Self.FImage.BeginUpdate();
  58.     Self.FImage.Clear();
  59.     Self.FImage.EndUpdate();
  60.   end;
  61.  
  62.   Result := Self.FImage;
  63. end;
  64.  
  65. function EIOS_GetClientPIDs: TIntegerArray;
  66. var
  67.   I: Int32;
  68. begin
  69.   for I := 0 to EIOS_GetClients(True) - 1 do
  70.     Result += EIOS_GetClientPID(I);
  71. end;
  72.  
  73. //function EIOS_PairClient(Pid: Int32): Pointer; override;
  74. //begin
  75. //  Result := inherited();
  76. //  if (Result = nil) then
  77. //    raise 'Failed to pair client';
  78. //end;
  79.  
  80. procedure RIInject(PID: Int32); override;
  81. var
  82.   PIDs: TIntegerArray;
  83. begin
  84.   inherited();
  85.  
  86.   if (not SleepUntil(Length(PIDs := EIOS_GetClientPIDs()) > 0, 100, 1000) and (Pids.Contains(Pid))) then
  87.     raise 'Failed to inject into pid ' + ToString(pid);
  88. end;
  89.  
  90. procedure RIInject(ProcessName: String; out PID: Int32); overload;
  91. var
  92.   PIDs: TIntegerArray;
  93. begin
  94.   RIInject(ProcessName);
  95.  
  96.   if (not SleepUntil(Length(PIDs := EIOS_GetClientPIDs()) > 0, 100, 1000)) then
  97.     raise 'Failed to inject into "' + ProcessName + '"';
  98.  
  99.   PID := PIDs[0];
  100. end;
  101.  
  102. var RI: TRemoteInput;
  103.  
  104. begin
  105.   RI.Setup();
  106. end;
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement