ScriptUO

Scripting Resources & Utilities => Stealth Client => Topic started by: Boydon on October 25, 2013, 03:47:57 AM

Title: [Release] Stealth Python wrapper [UPDATED 2014-08-21]
Post by: Boydon on October 25, 2013, 03:47:57 AM
Hello everybody,

the first release of Python wrapper for stealth is now available in the beta repository of Stealth:
https://bitbucket.org/Stealthadmin/stealth-beta-client/downloads

It was developed to be full compliant with the standard Python implementation already embedded within Stealth: in this way people can recycle already developed code while having the full power of Python.

I developed it using Python 3.X, but the code should be cross compatible with Python 2.7 (although I didn't have enough time to test it). Not all the function have been tested so please report any bug you meet.

Once you have imported it, you need to compile your .py project with your favorite freeze tool (cx_Freeze (http://cx-freeze.sourceforge.net/) is my favorite) to be able to run it in Stealth.


Changelog
---------- 2014-08-03 ----------
Changed:
- Renamed StartStealthPipeInstance to StartStealthSocketInstance for compatibility with Stealt 6.5.2 and addes some backward compatibility


---------- 2014-08-03 ----------
Added:
- GetMoveTroughNPC
- SetMoveTroughNPC
- StealthPath

Fixed:
- The following methods are now returning a list and not a single CR/LF separed string
    + GetContextMenu
   + GetGumpButtonDescription
   + GetGumpFullLines
   + GetGumpShortLines
   + GetGumpTextLines
   + GetLastMenuItems
   + GetMenuItems
   + GetShopList
- TStaticItemRealXY is now correctly declared
- AddToSystemJournal arguments are handled correctly
- Added the missing Tile filed to the TStaticItemRealXY
   
Changed:
- Renamed TStaticCellRealXY into TStaticItemRealXY


---------- 2014-04-15 ----------
Added:
- StartStealthPipeInstance
- CorrectDisconnection
- FindTypesArrayEx
The first two method are now needed to start external scripts.

Removed:
- StelathPath
- GetMoveTroughNPC
- SetMoveTroughNPC
All this methods are not public yet and will be available with the next stealth release.

Fixed:
- GetStaticArtBitmap
- FoundedParamID
- SetStatState (thx Encelar for this)


---------- 2014-01-03 ----------
Added:
- GetMoveOpenDoor
- SetMoveOpenDoor
- ClearInfoWindow
- FillInfoWindow
- ClearSystemJournal

Removed:
- ConvertFlagsToFlagSet (better implementation is needed)

Fixed:
- fixes suggested from slyone at http://www.scriptuo.com/index.php?topic=11704.msg100039#msg100039
- some code cleaning
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-25]
Post by: Crome969 on October 25, 2013, 04:01:22 AM
Added to Pinpoint List. Thank you for your contribution :)
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-25]
Post by: dxrom on October 25, 2013, 12:37:12 PM
Boydon is alive!

\o/
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-25]
Post by: slyone on October 25, 2013, 04:57:09 PM
Thanks for posting this wrapper.

I just loaded it up in Eclipse PyDev (http://www.scriptuo.com/index.php?topic=9374.0) and saw an error in reference to 
Code: [Select]
TTilePichueI see the disclaimer of the Tile wrapping not being complete and this may be part of what you were referring to but I thought I'd post in an effort to be helpful.  I also don't know all the differences between Python3.x and Python2.x.  I currently run with Python2.7 and the error I see in PyDev may not be an error in Python3.x.  Anyways, I haven't tried to test this specific code in a script yet to see if it fails at these locations due to Python's case sensitivity.  So hopefully I'm not crying wolf.

On line 407 you defined the
Code: [Select]
class TTilePichue(Structure): with lowercase 'hue' and then you refer to a
Code: [Select]
TTilePicHue with uppercase 'Hue' on lines 1376, 1378, 1379, and 1380.  Then you refer to a
Code: [Select]
ttilepichue all lowercase on lines 1382 and 1383. 

Here are the lines I'm refering too:
Code: [Select]
407 class TTilePichue(Structure):
408     _pack_ = 1
409     _fields_ = [
410         ('x', c_int),
411         ('y', c_int),
412         ('id', c_int),
413         ('color', c_int),
414         ('Page', c_int),
415         ('ElemNum', c_int),
416    ]

Code: [Select]
1376        # TilePicHue : array of TTilePicHue
1377        if tmp.value > 0:
1378            # print('TilePicHue : array of {} TTilePicHue'.format(tmp.value))
1379            gump_elements = (TTilePicHue * tmp.value )()
1380            memmove(addressof(gump_elements), addressof(byte_array) + stream_position, ( sizeof(TTilePicHue) * tmp.value ))
1381            Result['TilePicHue'] = [
1382                {'x' : ttilepichue.x, 'y' : ttilepichue.y, 'id' : ttilepichue.id, 'color' : ttilepichue.color,
1383                'Page' : ttilepichue.Page, 'ElemNum' : ttilepichue.ElemNum, } for ttilepichue in gump_elements]
1384            stream_position += sizeof(TTilePicHue) * tmp.value

Thanks again.

-S
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-25]
Post by: Boydon on October 26, 2013, 09:12:00 AM
Thank you, slyone.
This is now fixed and you can grab it from the beta repo.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-26]
Post by: slyone on December 06, 2013, 03:20:21 PM
Below are four changes to have the wrapper (dated 2013-10-26) (https://bitbucket.org/Stealthadmin/stealth-beta-client/downloads) more closely match the embedded python functions in Script.dll:

1)  Change
 
Code: [Select]
line 951:        def Script_ClientTargetResponse():  To
 
Code: [Select]
line 951:        def ClientTargetResponse():
2)  Add (starting at about line 2415)
Code: [Select]
  stealth_dll.Script_FindTypesArrayEx.argtypes = [[c_ushort], [c_ushort], [c_uint], [c_bool]]
  stealth_dll.Script_FindTypesArrayEx.restype = [c_uint]
  def FindTypesArrayEx(ObjTypes, Colors, Containers, Recursive):
      return stealth_dll.Script_FindTypesArrayEx(ObjTypes, Colors, Containers, Recursive)

3)  Change
 
Code: [Select]
line 2249:        def FindDistance():  To
 
Code: [Select]
line 2249:        def GetFindDistance():
4)  Change
 
Code: [Select]
line 3031:        def GetTargetStatus():  To
 
Code: [Select]
line 3031:        def TargetPresent():

Thanks,
S
Title: Re: [Release] Stealth Python wrapper [UPDATED 2013-10-26]
Post by: Boydon on December 07, 2013, 01:36:43 PM
Thank you slyone.

Points #1, #3 and #4 are are fixed in my copy and will be available in next realese (it will be realsed after Stealth update).
Point #2 require a different implementation cause ObjTypes, Colors, Containers are arrays and need to be handled differently.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-01-03]
Post by: Boydon on January 03, 2014, 05:34:59 AM
Wrapper is updated, see the first post for a list of changes.

Happy new year to everyone.  :)
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-01-03]
Post by: Node on March 26, 2014, 05:29:19 AM
Stealth 6.4.0 , Python 2.7

GetMoveThroughNPC()
Code: [Select]
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import stealth
  File "C:\Python\custom\stealth.py", line 2051, in <module>
    stealth_dll.Script_GetMoveThroughNPC.restype = c_ushort
  File "C:\Python\lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python\lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Script_GetMoveThroughNPC' not found

SetMoveThroughNPC()
Code: [Select]
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import stealth
  File "C:\Python\custom\stealth.py", line 2060, in <module>
    stealth_dll.Script_SetMoveThroughNPC.argtypes = [c_ushort]
  File "C:\Python\lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python\lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Script_SetMoveThroughNPC' not found
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-01-03]
Post by: Boydon on April 01, 2014, 01:36:37 AM
You where faster than my fix. :D

Problem is that those two function are in current Stealth git version, but are not public yet (they will on next release). :D
Version 2014-03-28 has this fixed. Sorry for the inconvenience. ;)
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-04-03]
Post by: Boydon on April 15, 2014, 01:35:37 PM
Some of you already noticed intermediate versions, but as of today there is a new version of the wrapper: all the news are in the first post.

I've been working slow on the wrapper cause I put my efforts in another project, some news will come at the due time. :)
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-04-03]
Post by: TrailMyx on April 15, 2014, 02:46:24 PM
I've been working slow on the wrapper cause I put my efforts in another project, some news will come at the due time. :)

Other project?  You are a big tease!
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-04-15]
Post by: Vlek on July 20, 2014, 09:23:42 AM
Hello, I know I'm a little late to the party, but is this wrapper still 2.7 compatible? I tried running it as is in both 2.7.5 and 3.2.5, but it's throwing up errors at the stealth_dll = WinDLL("") line even though I set it to the correct location.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-04-15]
Post by: Boydon on July 22, 2014, 04:08:46 AM
It should work with Python 2.7.

What kind of error do you have?
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-03]
Post by: Boydon on August 03, 2014, 09:45:14 AM
Wrapper is updated.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-03]
Post by: Vlek on August 06, 2014, 07:51:38 PM
Link is broken.  :'(
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-03]
Post by: Boydon on August 08, 2014, 04:54:52 PM
Try again. :)
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-03]
Post by: Vlek on August 19, 2014, 06:44:08 PM
I was reading through the wrapper, and you have an event persistence class that looks very, very intriguing. Is it possible to get a tut on how to use it? I am thinking about using something like that to do statistical data analysis.

Is it possible to use it to receive data such as damage (who damages who, the amount, etc), healing (same as damage), players showing up, players leaving, hiding, recall, etc, etc?
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-03]
Post by: Boydon on August 21, 2014, 01:31:43 PM
Wrapper is updated.

@Vlek
What exactly do you want to know? I am not sure if you want to know how to use it (see below) or why it has been done in that way (as you probably guess there is a reason behind ;)).
Anyway feel free to use my code as you like. :D

Here is a snippet that shows you how to use it (beware that it is untested! :P):

Code: [Select]
#!python2
from __future__ import print_function
import os
import sys
from py_stealth import *

#this only works if you freeze with cx_freeze
exe_name = os.path.basename(sys.executable)
print(exe_name)

StartStealthSocketInstance(exe_name)

def OnSpeech(text, senderName, senderID):
    AddToSystemJournal('[{}] {} has just said: {}'.format(senderID, senderName, text))

AddToSystemJournal('test')
SetEventProc('evSpeech', OnSpeech)
SetEventProc('evUnicodeSpeech', OnSpeech)

#20 seconds
for x in range(0, 401):
    Wait(50)

CorrectDisconnection()

To have a list of events and parameters, have a look here (http://stealth.od.ua/Doc:Manual/Reference/Events).
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-21]
Post by: Vlek on August 23, 2014, 08:04:53 AM
Oooo, perfect. That's exactly what I was looking for. I was thinking I'd have to make my own event handler, but hopefully I can make a semi-veneer that'll make this easily callable for my statistical analysis module I'm trying to make. Thanks, man.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-21]
Post by: Vlek on November 24, 2015, 09:36:06 AM
I know it has been over a year, but I never was able to use the wrapper. I'm having significant, weird issues with stealth not liking my scripts that are entirely legal python code.

I understand I have to use something like cx_freeze to put these into executables, but, when I do that, I was getting a silent error that the script.dll wasn't included. I tried adding it into the archive file that gets generated with the executable in cx_freeze, but then it doesn't error out at all. It just runs the program forever in the background if I try to use it or run it through stealth.

I mean, I froze literally this for crying out loud:
Code: [Select]
import py_stealth as stealth
stealth.UOSay('Hello world!')

And it was playing forever without having put anything in game.

I guess what I'm asking is, can I get a brief tutorial on how to properly create an executable using this thing? I think that's where I'm messing up.
Title: Re: [Release] Stealth Python wrapper [UPDATED 2014-08-21]
Post by: Vlek on November 24, 2015, 02:34:28 PM
Sorry! I figured it out on my own.

One thing though, it looks like your

On line 2259,
Code: [Select]
def FindTypeArrayEx(ObjTypes, Colors, Containers, InSub):
should be:
Code: [Select]
def FindTypesArrayEx(ObjTypes, Colors, Containers, InSub):