Skip to content

Commit 2e17b47

Browse files
committed
Update README.md
1 parent a49e7a6 commit 2e17b47

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,99 @@
11
# G-Python
22
G-Earth extension interface for Python.
33

4-
G-Earth + G-Python allows you to create simple scripts for Habbo and run them on the fly!
4+
G-Earth + G-Python allows you to create simple scripts for Habbo and run them on the fly!
5+
6+
## Installation
7+
_Requires python >= 3.2_
8+
9+
> python -m pip install g-python
10+
11+
## Features
12+
G-Python exports the following modules:
13+
14+
```python
15+
from g_python.gextension import Extension
16+
from g_python.hmessage import Direction, HMessage
17+
from g_python.hpacket import HPacket
18+
from g_python import hparsers
19+
from g_python import htools
20+
```
21+
22+
* At any point where a `(header)id` is required, a `name` or `hash` can be used as well, if G-Earth is connected to Harble API
23+
* "hparsers" contains a load of useful parsers
24+
* "htools" contains fully prepared environments for accessing your Inventory, Room Furniture, and Room Users
25+
26+
27+
## Usage
28+
29+
Examples are available in the `tests/` folder. _(highly recommended to check out, since it contains functionality not shown underneath)_
30+
31+
This is a template extension with the minimal amount of code to connect with G-Earth:
32+
33+
```python
34+
import sys
35+
from g_python.gextension import Extension
36+
37+
extension_info = {
38+
"title": "Extension stuff",
39+
"description": "g_python test",
40+
"version": "1.0",
41+
"author": "sirjonasxx"
42+
}
43+
44+
ext = Extension(extension_info, sys.argv) # sys.argv are the commandline arguments, for example ['-p', '9092'] (G-Earth's extensions port)
45+
ext.start()
46+
```
47+
It is possible to register for events:
48+
```python
49+
ext.on_event('double_click', lambda: print('Extension has been clicked'))
50+
ext.on_event('init', lambda: print('Initialized with g-earth'))
51+
ext.on_event('connection_start', lambda: print('Connection started'))
52+
ext.on_event('connection_end', lambda: print('Connection ended'))
53+
```
54+
Packet injection:
55+
```python
56+
# sending packets to the server
57+
ext.send_to_server(HPacket('RoomUserAction', 1)) # wave using harble api name
58+
ext.send_to_server(HPacket(1843, 1)) # wave using header Id
59+
ext.send_to_server(HPacket('623058bd68a68267114aa8d1ee15b597', 1)) # wave using harble api hash
60+
61+
# sending packets from raw text:
62+
ext.send_to_client('{l}{u:1411}{i:0}{s:"hi"}{i:0}{i:23}{i:0}{i:2}')
63+
ext.send_to_client('[0][0][0][6][5][131][0][0][0][0]')
64+
ext.send_to_client(HPacket.from_string('[0][0][0][6][5][131][0][0][0][0]', ext))
65+
66+
# string methods:
67+
packet = HPacket(1231, "hi", 5, "old", False, True, "lol")
68+
expression = packet.g_expression(ext) # G-Earth's predicted expression
69+
g_string = packet.g_string(ext) # G-Earth's string representation
70+
```
71+
Intercepting packets:
72+
```python
73+
# intercept & print all packets
74+
def all_packets(message):
75+
packet = message.packet
76+
print(packet.g_string(ext))
77+
78+
ext.intercept(Direction.TO_CLIENT, all_packets)
79+
ext.intercept(Direction.TO_SERVER, all_packets)
80+
81+
82+
# intercept & parse specific packets
83+
def on_walk(message):
84+
(x, y) = message.packet.read('ii')
85+
print("Walking to x:{}, y={}".format(x, y))
86+
87+
def on_speech(message):
88+
(text, color, index) = message.packet.read('sii')
89+
message.is_blocked = (text == 'blocked') # block packet if speech equals "blocked"
90+
print("User said: {}".format(text))
91+
92+
ext.intercept(Direction.TO_SERVER, on_walk, 'RoomUserWalk')
93+
ext.intercept(Direction.TO_SERVER, on_speech, 'RoomUserTalk')
94+
```
95+
There is much more, such as:
96+
* packet manipulation
97+
* specific settings to be given to an Extension object
98+
* `hparsers`: example in `tests/user_profile.py`
99+
* `htools`: `tests/room_stuff.py` & `tests/inventory_items.py`

0 commit comments

Comments
 (0)