Blizzhackers

Return of the Jedi

* Login   * Register    * FAQ    * Search

Join us on IRC: #bh@irc.synirc.net (or Mibbit Web IRC)


MuleFactory


It is currently Fri May 24, 2013 8:47 am


All times are UTC [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [Release] Copy-Paste
PostPosted: Thu Jun 30, 2011 1:30 pm 
 
User
User

Joined: Sun Jun 22, 2008 7:40 pm
Copy-Paste

Intro
Sometimes it happens that I wrote something in Diablo II game that I want to copy later, but I can't which means I'll have to rewrite that long text. So I decided to write little tool that would allow copy text out of Diablo II game.

After that I thought why not paste text in game. So I wrote Paste part too

This program is really easy to use.


Features
To say in short: chat box is now rwx

1)Copy - You can copy text out of game
2)Paste - You can paste text in game. Over than 255 characters long text will be sent as multiple shorter messages
If you have multi line text to paste, every line will be separate message.
3)Execute - You can execute text on your chatbox as AutoIt code if you append .exec to it. As a result text in chatbox will change.

For example you want to tell someone how much your mf % is but you are too lazy to calculate it yourself then you can:

Press enter (to open chat box)
type: "My mf is: "& 50 + 20 +1 10
since we want to see result we append .exec so full message would be "My mf is: "& 50 + 20 +1 10.exec
As soon as you finished typing .exec, message will be executed and you will see My mf is: 80
Press enter again (to send message)

Screenshots

Multiline text splitted into separate messages
Quote:
CONTENTS

1 Introduction
1.1 Version history
1.2 Plot
1.3 Changes
1.4 Reasons for writing
1.5 Legal-ish stuff

2 New units
2.1 Orcs
2.2 Humans
3 Walkthrough

3.1 Humans
3.1.1 Alleria's Journey
3.1.2 Battle for Nethergarde
3.1.3 Once more unto the breach
3.1.4 Beyond the Dark Portal

Image

One long line splitted into messages
Quote:
MsgBox(0, "Help", "Copy-Paste help" & @CRLF & "This program allows you to copy and paste text in game where you normally can't do this." & @CRLF & @CRLF & "Usage:" & @CRLF & '1) Select process by clicking on "Select" button (Usually it is done automatically and there is no need for this)' & @CRLF & "2) Copy and/or paste text" & @CRLF & @CRLF & "To copy text, click on Copy button or press Ctrl + C" & @CRLF & "To paste simply click on Paste button or press Ctrl + V" & @CRLF & "Important! When you paste, chat box (where you type in) must be CLOSED" & @CRLF & @CRLF & 'If you have "execute as code" selected text in your chatbox will be trated as code when you append .exec to it' & @CRLF & @CRLF & "Example:" & @CRLF & '"My mf is: " & 20 + 50 +10.exec would change this text to My mf is: 80')

Image

Executing message:

Before executing
Image

After executing:
Image

Download
Executable: http://autoit.net.ee/downloads/copy-paste.zip
Source: http://autoit.net.ee/downloads/copy-paste_src.zip

Just in case Download link is broken, you can copy code below:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Paste.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <OpenSecureProcess.au3>
#include <procselect.au3>
#include <WinAPI.au3>
#include <Process.au3>
#include <Misc.au3>
#include <GuiEdit.au3>

$dll = DllOpen("user32.dll")
Opt("SendKeyDelay", 20) ;5 milliseconds
Opt("SendKeyDownDelay", 20) ;1 millisecond

$MemAddress = 0x6FBCEC80;chat
;Use -1 so we can use it later to check if those variables have been redefined

$consolegui = -1
$consoleedit = -1
$ForcedhWnd = -1
$pro = 0

_ConsoleWrite("Number of args: " & $cmdline[0] & @CRLF)
If $cmdline[0] = 2 Then
   _ConsoleWrite("Arg 2: " & $cmdline[2] & @CRLF)
   $ForcedhWnd = HWnd($cmdline[2])
EndIf

;create gui
$gui = GUICreate("Copy-Paste", 230, 60)
$copy = GUICtrlCreateButton("Copy", 2, 2, 60)
$paste = GUICtrlCreateButton("Paste", 64, 2, 60)
$Replace = GUICtrlCreateCheckbox("execute as code", 130, 2, 100)
GUICtrlCreateLabel("Pid:", 2, 32, 30)
$PidInput = GUICtrlCreateInput("", 32, 32, 45)
$PidSelect = GUICtrlCreateButton("Select", 95, 32)
$Help = GUICtrlCreateButton("Help", 140, 32)
If $ForcedhWnd <> -1 Then
   GUICtrlSetState($PidInput, @SW_DISABLE)
   GUICtrlSetState($PidSelect, @SW_DISABLE)
EndIf
GUISetState()



AdlibRegister("SetTarget", 100)

If $cmdline[0] = 1 Then
   GUICtrlSetData($PidInput, $cmdline[1])
   _ConsoleWrite("Arg 1: " & $cmdline[1] & @CRLF)
Else
   $pl = ProcessList("game.exe")
   If $pl[0][0] = 1 Then
      GUICtrlSetData($PidInput, $pl[1][1])
   EndIf
EndIf

;define vars
$hwnda = WinGetHandle("[active]")
$proca = 0

;loop
While 1
   If $hwnda <> WinGetHandle("[active]") Then
      $hwnda = WinGetHandle("[active]")
      $proca = WinGetProcess($hwnda)
      _ConsoleWrite($hwnda & " - " & _ProcessGetName(WinGetProcess($hwnda)) & @CRLF)
   EndIf
   If _IsPressed("11", $dll) Then
      If _IsPressed("43", $dll) Then
         If $proca = $pro Or WinGetHandle("[active]") = $gui Then
            ClipPut(DiaGetChat($pro))
         EndIf
      EndIf
   EndIf
   If _IsPressed("11", $dll) Then
      If _IsPressed("56", $dll) Then
         $hwnd1 = _ProcessGetWindow($pro)
         $hwnd2 = WinGetHandle("[active]")
         If $proca = $pro Or WinGetHandle("[active]") = $gui Then
            _ConsoleWrite(@CRLF & "CTRL + V" & @CRLF)
            Paste()
         EndIf
      EndIf
   EndIf
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case -3
         Exit
      Case $Replace
         If GUICtrlRead($Replace) = 1 Then
            AdlibRegister("Replace", 100)
         Else
            AdlibUnRegister("Replace")
         EndIf
      Case $copy
         ClipPut(DiaGetChat($pro))
      Case $paste
         _ConsoleWrite(@CRLF & "BUTTON " & $paste & @CRLF)
         Paste()
      Case $PidSelect
         GUICtrlSetData($PidInput, _ProcessSelect("game.exe"))
      Case $Help
         MsgBox(0, "Help", "Copy-Paste help" & @CRLF & "This program allows you to copy and paste text in game where you normally can't do this." & @CRLF & @CRLF & "Usage:" & @CRLF & '1) Select process  by clicking on "Select" button (Usually it is done automatically and there is no need for this)' & @CRLF & "2) Copy and/or paste text" & @CRLF & @CRLF & "To copy text, click on Copy button or press Ctrl + C" & @CRLF & "To paste simply click on Paste button or press Ctrl + V" & @CRLF & "Important! When you paste, chat box (where you type in) must be CLOSED" & @CRLF & @CRLF & 'If you have "execute as code" selected text in your chatbox will be trated as code when you append .exec to it' & @CRLF & @CRLF & "Example:" & @CRLF & '"My mf is: " & 20 + 50 +10.exec would change this text to My mf is: 80')
   EndSwitch
WEnd


Func SetTarget()
   $pro = GUICtrlRead($PidInput)
EndFunc   ;==>SetTarget

Func Paste()
   $datatopaste = StringSplit(StringReplace(ClipGet(), @CR, ""), @LF, 1) ; make is linux friendly, but still sucks to be mac user
   $hDiaWnd = $hwnda
   If $ForcedhWnd <> -1 Then
      $hDiaWnd = $ForcedhWnd
      _ConsoleWrite("FORCED hwnd: " & $hDiaWnd & @CRLF)
   Else
      If $hDiaWnd = $gui Then
         $hDiaWnd = _ProcessGetWindow($pro) ;get window handle from pid
         _ConsoleWrite("Window handle from pid: " & $pro & " hwnd: " & $hDiaWnd & @CRLF)
      EndIf
   EndIf
   For $i = 1 To $datatopaste[0]
      $sNewString = StringRegExpReplace($datatopaste[$i], "(?s)(.{255})", "$1" & @LF);we have 255 char max so we need to split longer texts
      $array = StringSplit($sNewString, @LF, 1);split here
      For $n = 1 To $array[0]
         _ConsoleWrite($hDiaWnd & " (" & _ProcessGetName(WinGetProcess($hDiaWnd)) & ") " & " >> " & $array[$n] & @CRLF)
         _SendMinimized($hDiaWnd, "{enter}")
         DiaSetChat(ProcessExists("game.exe"), $array[$n]);insert text
         _SendMinimized($hDiaWnd, "{enter}")
      Next
   Next
EndFunc   ;==>Paste

Func Replace()
   If $pro > 0 Then
      $data = DiaGetChat($pro)
      If StringRight($data, 5) = ".exec" Then
         $data = StringLeft($data, StringLen($data) - 5)
         $dataExec = Execute($data)
         If Not ($dataExec == "") Then
            DiaSetChat($pro, $dataExec)
         EndIf
      EndIf
   EndIf
EndFunc   ;==>Replace

Func DiaGetChat($iPid)
   $Struct = DllStructCreate("wchar [255]")
   $MAX_CHAT = 255 * 2
   $hProc = openSecureProcess($iPid, 0x001F0FFF)
   _WinAPI_ReadProcessMemory($hProc, "0x" & Hex($MemAddress), DllStructGetPtr($Struct), DllStructGetSize($Struct), $MAX_CHAT)
   Return DllStructGetData($Struct, 1)
EndFunc   ;==>DiaGetChat

Func DiaSetChat($iPid, $sStr)
   $Struct = DllStructCreate("wchar [255]")
   DllStructSetData($Struct, 1, $sStr)
   $MAX_CHAT = StringLen($sStr)
   $hProc = openSecureProcess($iPid, 0x001F0FFF)
   $ret = _WinAPI_WriteProcessMemory($hProc, "0x" & Hex($MemAddress), DllStructGetPtr($Struct), DllStructGetSize($Struct), $MAX_CHAT)
   Return $ret
EndFunc   ;==>DiaSetChat


Func _ProcessGetWindow($PId)
   If ProcessExists(_ProcessGetName($PId)) = 0 Then
      SetError(1)
   Else
      Local $WinList = WinList()
      Local $i = 1
      Local $WindowHandle = ""
      While $i <= $WinList[0][0] And $WindowHandle = ""
         If WinGetProcess($WinList[$i][0], "") = $PId Then
            $WindowHandle = $WinList[$i][1]
         Else
            $i += 1
         EndIf
      WEnd
      Return $WindowHandle
   EndIf
EndFunc   ;==>_ProcessGetWindow

Func _SendMinimized($Window, $keys)
   ControlSend($Window, "", "", $keys)
EndFunc   ;==>_SendMinimized

Func _ConsoleWrite($sStr)
   Return ;We dont need this on release version
   If $consolegui = -1 Then
      $consolegui = GUICreate("Console", 400, 500)
      $consoleedit = GUICtrlCreateEdit("", 0, 0, 400, 500)
      GUISetState()
   EndIf
   _GUICtrlEdit_AppendText($consoleedit, $sStr)
EndFunc   ;==>_ConsoleWrite

_________________
Discuss: Copy-Paste [url=http://www.blizzhackers.cc/viewtopic.php?f=182&t=483257&p=4520230#p4520230]Tabbed Dia
Download: Copy-Paste Tabbed Dia D2 function caller

Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron