Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$DEFINE SRL_USE_REMOTEINPUT}
- {$I SRL-T/osr.simba}
- var
- NativeClient: PtrInt;
- // -----------------------------------------------------------------------------
- // -----------------------------------------------------------------------------
- // WIN API stuff
- const WINAPI_CC = {$IFDEF CPU386}' stdcall'{$ELSE}' win64'{$ENDIF};
- const ffi_winapi = {$IFDEF CPU386}ffi_stdcall{$ELSE}ffi_win64{$ENDIF};
- type
- _EnumWindowsProc = function(wnd:DWORD; Param:Pointer): LongBool;
- TEnumWindowsProc = native(_EnumWindowsProc, ffi_winapi);
- function GetAsyncKeyState(vKey: Int32): Int16; external 'GetAsyncKeyState@user32.dll' + WINAPI_CC;
- function GetForegroundWindow(): PtrUInt; external 'GetForegroundWindow@user32.dll' + WINAPI_CC;
- function GetWindowThreadProcessId(wnd: PtrUInt; out dwProcessId: DWORD): DWORD; external 'GetWindowThreadProcessId@user32.dll' + WINAPI_CC;
- function EnumChildWindows(hWndParent: DWORD; func: TEnumWindowsProc; Param: Pointer): LongBool; external 'EnumChildWindows@user32.dll' + WINAPI_CC;
- function GetKeyDown(): Char;
- var
- key: Word;
- keys: array of Word;
- begin
- keys := [VK_A..VK_Z];
- keys += [VK_0..VK_9];
- keys += [VK_OEM_PERIOD, VK_OEM_MINUS]; //add more keys if you need
- for Key in keys do
- if GetAsyncKeyState(key) and $8000 <> 0 then
- begin
- while GetAsyncKeyState(key) and $8000 <> 0 do Wait(10);
- if key = VK_OEM_PERIOD then key := Ord('.');
- if key = VK_OEM_MINUS then key := Ord('-');
- Exit(Char(key));
- end;
- end;
- function IsKeyDown2(vKey: Word): Boolean;
- begin
- Result := GetAsyncKeyState(vKey) and $8000 <> 0;
- end;
- function GetRSAppletWnd(PID: DWORD): DWORD;
- function GetLastChild(Handle: DWORD; Param: Pointer): LongBool; static;
- begin
- if handle <> 0 then
- begin
- DWORD(Param^) := handle;
- Result := True;
- end;
- end;
- var
- p: TSysProc;
- client: DWORD;
- begin
- for p in GetProcesses() do
- if p.Pid = PID then
- Break;
- EnumChildWindows(p.Handle, @GetLastChild, @Result);
- if Result = 0 then
- Result := NativeClient;
- end;
- // ---------
- // ---------
- // ---------
- procedure Setup();
- var
- r: String;
- DefaultBox: TBox = [75,40, 425,140];
- client2: TClient;
- type
- TButtonBox = record
- TextTPA: TPointArray;
- Bounds: TBox;
- end;
- procedure WaitReleaseMouse(key:Int32);
- begin
- while client2.GetIOManager.IsMouseButtonDown(key) do Wait(10);
- end;
- function GetClick(out p: TPoint): Boolean;
- begin
- if not EIOS_HasFocus(RSClient.RemoteInput.EIOS) then Exit();
- if client2.GetIOManager.IsMouseButtonDown(1) then
- begin
- client2.GetIOManager.GetMousePos(p.x,p.y);
- Result := p.InBox(GetClientBounds);
- WaitReleaseMouse(1);
- end;
- end;
- function GetButton(txt: String): TButtonBox;
- begin
- Result.TextTPA := TPAFromText(txt, 'StatChars07');
- Result.Bounds := GetTPABounds(Result.TextTPA).Expand(8);
- end;
- function DrawButton(p: TPoint; var Button: TButtonBox): TButtonBox;
- var tmp: TButtonBox;
- begin
- Button.TextTPA := Button.TextTPA.Offset(p);
- Button.Bounds := Button.Bounds.Offset(p);
- RSClient.Image.DrawBoxFilled(Button.Bounds, False, 2502198);
- RSClient.Image.DrawBoxFilled(Button.Bounds.Expand(-1), False, 4607315);
- RSClient.Image.DrawTPA(Button.TextTPA, $FFFFFF);
- end;
- function MessageBox(Text: String; Area:TBox=[]): string;
- var
- xstart: Int32;
- TPA: TPointArray;
- box: TBox;
- begin
- if (Area.x1 = Area.x2) then Area := chat.Bounds();
- RSClient.Image.DrawBox(Area.Expand(-0), $1F2F33);
- RSClient.Image.DrawBox(Area.Expand(-1), $3F4A5A);
- RSClient.Image.DrawBox(Area.Expand(-2), $1F2F33);
- RSClient.Image.DrawBoxFilled(Area.Expand(-3), False, $171D20);
- TPA := TPAFromText(Text, 'SmallChars07');
- box := GetTPABounds(TPA);
- xstart := (box.Width + Area.Width) div 2 - box.Width;
- OffsetTPA(TPA, Point(Area.x1+xstart, Area.y1+20));
- RSClient.Image.DrawTPA(TPA, $FFFFFF);
- end;
- function Query(Text: String; Alts:TStringArray; Area:TBox=[]): string;
- var
- i,xstart,CurrWidth: Int32;
- p: TPoint;
- Buttons: array of TButtonBox;
- xOffset: TIntegerArray;
- begin
- if (Area.x1 = Area.x2) then Area := chat.Bounds;
- // query
- MessageBox(Text, Area);
- // buttons
- for i:=0 to High(Alts) do
- begin
- Buttons += GetButton(Alts[i]);
- xOffset += CurrWidth;
- CurrWidth += Buttons[i].Bounds.X2+20;
- end;
- CurrWidth -= 20;
- xstart := (CurrWidth + Area.Width) div 2 - CurrWidth;
- for i:=0 to High(Buttons) do
- begin
- DrawButton(Point(Area.x1+xstart+xOffset[i], Area.y1+50), Buttons[i]);
- end;
- // handling
- while True do
- begin
- if GetClick(p) then
- begin
- for i:=0 to High(Buttons) do
- if PointInBox(p, Buttons[i].Bounds) then
- begin
- RSClient.Image.DrawBoxFilled(Area, False, 0);
- Exit(Alts[i]);
- end;
- end;
- Wait(1);
- end;
- end;
- function QueryStr(Text: String; Area:TBox=[]): string;
- var
- i: Int32;
- pt, p: TPoint;
- chr: Char;
- B: TBox;
- TPA: TPointArray;
- Button: TButtonBox;
- textArea: Tbox;
- begin
- if (Area.x1 = Area.x2) then
- Area := Chat.Bounds;
- // query
- RSClient.Image.DrawBox(Area.Expand(-0), $1F2F33);
- RSClient.Image.DrawBox(Area.Expand(-1), $3F4A5A);
- RSClient.Image.DrawBox(Area.Expand(-2), $1F2F33);
- RSClient.Image.DrawBoxFilled(Area.Expand(-3), False, $171D20);
- TPA := TPAFromText(Text, 'SmallChars07');
- OffsetTPA(TPA, Point(Area.x1+40, Area.y1+20));
- RSClient.Image.DrawTPA(TPA, $FFFFFF);
- B := GetTPABounds(TPA);
- // button
- Button := GetButton('OK');
- DrawButton(Point(Area.x1+48, Area.y1+50), Button);
- // handling
- pt.x := B.x2+5;
- pt.y := Area.y1+25;
- repeat
- while not EIOS_HasFocus(RSClient.RemoteInput.EIOS) do Wait(10);
- if GetClick(p) then
- if PointInBox(p, Button.Bounds) then
- begin
- RSClient.Image.DrawBoxFilled(Area, False, 0);
- Exit(Result);
- end;
- chr := GetKeyDown();
- if chr <> #0 then
- begin
- Result += Lowercase(chr);
- PressKey(VK_BACK); //ensure deletion if bugged input blocking
- RSClient.Image.DrawText(Result, pt, $FFCCAA);
- end;
- if IsKeyDown2(VK_BACK) and (Result <> '') then
- begin
- textArea := [pt.X, pt.y, RSClient.Image.TextWidth(Result)+pt.x, RSClient.Image.TextHeight(Result)+pt.y];
- RSClient.Image.DrawBoxFilled(textArea, False, $171D20);
- while IsKeyDown2(VK_BACK) do Wait(50);
- SetLength(Result, Length(Result)-1);
- RSClient.Image.DrawText(Result, pt, $FFCCAA);
- end;
- until False;
- end;
- label
- START, QUERY_CONFIG;
- begin
- client2.Init(PluginPath);
- client2.GetIOManager.SetTarget2(GetRSAppletWnd(RSClient.RemoteInput.PID));
- RSClient.Image.setFontSize(10);
- RSClient.Image.setFontAntialiasing(False);
- START:
- r := Query('Do you wish to run setup?', ['Yes','No'], DefaultBox);
- WriteLn(r);
- Writeln QueryStr('Save config as: ', DefaultBox);
- client2.Free();
- end;
- begin
- NativeClient := GetNativeWindow();
- if EIOS_IsMouseInputEnabled(RSClient.RemoteInput.EIOS) then
- EIOS_SetMouseInputEnabled(RSClient.RemoteInput.EIOS, False);
- if EIOS_IsKeyboardInputEnabled(RSClient.RemoteInput.EIOS) then
- EIOS_SetKeyboardInputEnabled(RSClient.RemoteInput.EIOS, False);
- Setup();
- EIOS_SetMouseInputEnabled(RSClient.RemoteInput.EIOS, True);
- EIOS_SetKeyboardInputEnabled(RSClient.RemoteInput.EIOS, True);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement