Jump to content

Skeletton of Python modules for IDE.


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

This is the hidden content, please
( GitHub )

Hi !

 

First: sorry. My code is not clean, I am not a developer or anything, I am just a math student. I am just trying to do my best. And my skills in English are… non-existent. So, be nice please.

 

Using very often PyCharm, I wanted to be able to use it on Metin2, but PyCharm (or another IDE) hit me hard with baseball bat because he could not find the modules.

So, I have made this tool to create module’s python skeleton and use autocompletion with IDE. The biggest flaw is that you must have Python3 installed on your machine to use typing.

 

Example of result with PyCharm:

205724result-example.png

 

And you can't find an exemple of output here.

 

 

To follow this tutorial, you must have:

  • Python3 (i'm using Python3.8)
  • PyCharm or other IDE, but in this tutorial, I will use PyCharm (from JetBrains).
  • This is the hidden content, please
    .

 

 

 

 

I – Generate your module skeleton.

You can find just upper, a link to download my script. It is easy to use. You can find all the manipulations in README.md file, but I will explain it here too:

  • Move all your client’s .cpp file (with module) in src folder.
  • Just use now main.py with Python3 (I developed it with Python3.8)

You will see many files in bin folder.

 

 

II – Make a virtual environment of Python3 for IDEs

We will have to create a virtual environment for our IDEs to do not dirty our real Python installation. To do that, you can use the command :

 

python3 -m venv /path/to/new/virtual/environment

 

Find all information on the doc : https://docs.python.org/3/library/venv.html

 

I will show you how to do that with PyCharm:

Spoiler

 

  1. Open your pack folder with PyCharm, you will have something like this :
    201037Capture-d-ecran-2021-01-20-163730.
  2. Now, we have to create a new virtual environment of Python. For this, click on the button at the bottom right of PyCharm to select an interpreter, and choose Add interpreter:
    201231Image1.png
  3. Configure now a new virtual environment with Python3x as base intrepreter and create it. You will have something like that:
    201358Capture-d-ecran-2021-01-20-165314.

 

 

 

 

And with Visual Studo Code:

Spoiler

 

You must have Python extension. You can get it in the MarketPlace, and create your venv with command.

  1. Open your pack folder with Visual Studio Code and save it as a Workspace.
    211238image-2021-01-21-001218.png
  2. In this Workspace, on Visual Studio Code Press : Ctrl + Alt + P.
  3. Select Python: Select Interpreter:
    211554Capture-d-ecran-2021-01-21-001535.
  4. Specify that it's for the Entire WorkSpace:
    211659image-2021-01-21-001657.png
  5. Select after Enter interpreter path...:
    212011image-2021-01-21-002010.png
  6. After, Find... and go search python.exe in venv folder (venv/Script/python.exe).

And it's done. Congratulation.

 

 

 

III - Add our skeletons to virtualenv

For that, you just must move all your .py file in bin folder to venv/Lib/site-packages. Example :

201556Capture-d-ecran-2021-01-20-214039.

This manipulation is a little dirty ... But I couldn't find anything better so as not to have too much change to make. If you have a better one, I take...

 

Don't forget to configure your IDE to use new virtualenv.

 

 

IV - Known issues:

  • Script cannot predict value of the constants;
  • It does not yed manage structures of this type:

202028unknown.png

 

V - Debug:

  • Script now support Tuple in functions' returns;
  • Add the method GetWindow for arguments.

 

With using Python3 IDE, he will consider print without parentheses and except bloc as error...

 

Thanks to @Gurgarath for his help ❤️ 

 

 

This is the hidden content, please

 

Takuma.

Edited by Gurgarath
  • Metin2 Dev 51
  • Dislove 2
  • Think 1
  • Good 3
  • Love 2
  • Love 29
Link to comment
Share on other sites

  • Forum Moderator

spacer.png

 

At least there's someone in metin2 that using Python 3+ for tools (since already we've 3.9 and they're still using 2.7), great. 
The problem is that 99% of them will not understand the code from your tool, but it's fine, let's just run it and see the magic. 🤯
Thanks for the release, it's really useful for 'developers'.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 5
Link to comment
Share on other sites

16 minutes ago, VegaS™ said:

spacer.png

 

At least there's someone in metin2 that using Python 3+ for tools (since already we've 3.9 and they're still using 2.7), great. 
The problem is that 99% of them will not understand the code from your tool, but it's fine, let's just run it and see the magic. 🤯
Thanks for the release, it's really useful for 'developers'.

Well if it's bothering you, why not sharing a guide and helping the people to move to py 3?

It's not like it's that difficult to upgrade to py3 tho. But I guess you can't complain if people don't want to touch a running system especially without the knowledge of what they're supposed to do or how to debug after converting the py2 files to 3. Especially since developers tend to just sell their precompiled stuff which runs on - tada - py2. I can imagine the autistic screeching after finding out that after porting py2 to 3 results in some systems done by greedy devs not working properly.

But yes I agree, it's best to use py3 in any case possible! :)

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 1

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

  • Forum Moderator
1 hour ago, Vanilla said:

Well if it's bothering you, why not sharing a guide and helping the people to move to py 3?

Sorry, you understood it wrong, maybe my bad.

I talked about general stuff, tools, not crap metin2 or about porting it to py3, doesn't have any relevance with what I said. 

Was all about that in the last years I didn't saw any public tool coded in py3 well, just py2 and that's really sad when you look at py3 release date: 03-Dec-2008.

There're no excuses for 'developers/programmers' that don't use the latest versions of python in other apps/tools just because metin2 doesn't have it, which means they didn't care about improving their skills in that language, simple.
Those tools don't have anything related to metin2 code, that's why I told those things.

It's like still using full C++98 after 20 years in your tools when you've no limits and C++2x is here.

 

@TakumaA good feature would be a detailed documentation for functions, like this

 

If you need any help with the documentation or anything else, don't hesitate to contact me as well, I would like to contribute in my free time.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 3
Link to comment
Share on other sites

  • Forum Moderator

Good job for this release. It's highly needed for everyone who wants to take the advantage of whatever is in their source without having to open the module and check how it works and if it's there. It just makes it simpler for everyone who wants to start coding something without knowing exactly the usage or just for people who wants to gain time.

  • Love 4

Gurgarath
coming soon

Link to comment
Share on other sites

1 hour ago, VegaS™ said:

 Sorry, you understood it wrong, maybe my bad.

I talked about general stuff, tools, not crap metin2 or about porting it to py3, doesn't have any relevance with what I said. 

Was all about that in the last years I didn't saw any public tool coded in py3 well, just py2 and that's really sad when you look at py3 release date: 03-Dec-2008.
Those tools don't have anything related to metin2 code, that's why I told those things.

It's like still using full C++98 after 20 years in your tools when you've no limits and C++2x is here.

 

@TakumaA good feature would be a detailed documentation for functions, like this

 

I've already thought about converting the docstrings, but I don't know the sources well enough to comment everything... But when I have some time I will do the docstrings converter.

 

Thanks for the idea ! 

 

I will add the method to use venv with Visual Studio Code too. Added.

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

14 hours ago, VegaS™ said:

spacer.png

 

At least there's someone in metin2 that using Python 3+ for tools (since already we've 3.9 and they're still using 2.7), great. 
The problem is that 99% of them will not understand the code from your tool, but it's fine, let's just run it and see the magic. 🤯
Thanks for the release, it's really useful for 'developers'.

 

I agree with you python 3-3+ better than python 2.7.

Dear takuma in my opinion u should consider converting Docstrings.This is so important thing.

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

Hi !

Use Python3 with the client can be very interesting.. For use UTF-8 everywhere for example (Unicode...). i tried to do this before, but my client crashed when I created empty tuple... xd if someone want share a client with Python3.. I take it  !

 

 

I just specify that i updated the code for two errors that were reported to me :

  • Tuple in return;
  • GetWindow() method.

 

 

  • Love 1
Link to comment
Share on other sites

11 minutes ago, Takuma said:

Hi !

Use Python3 with the client can be very interesting.. For use UTF-8 everywhere for example (Unicode...). i tried to do this before, but my client crashed when I created empty tuple... xd if someone want share a client with Python3.. I take it  !

 

 

I just specify that i updated the code for two errors that were reported to me :

  • Tuple in return;
  • GetWindow() method.

 

 

mostly it's converting everything to utf-8 and then run 2to3 tool to convert the scripts. You'll have to make some changes to the scripts tho, since the tool obviously can't be perfect. And then it's changing the the python initialization and modules declaration. You'd better use Unicode in client source, so if I were you I'd start with using utf-8 on client and all files (text files, py scripts etc.) and then swap the project to unicode. You have to change a bit on the client there but in the end it's definitely worth it! :) After that you can do the actual upgrade to py3. Side note: I also recommend using utf-8 in database tables, server source and files

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

  • Forum Moderator
Quote

With using Python3 IDE, he will consider print without parentheses and except bloc as error...

 

That moment when you hate regex..

I'll add it tomorrow night on GitHub + other features. 😴

 

Edited by VegaS™
removed code tag
  • Confused 1
  • Love 3
Link to comment
Share on other sites

2 hours ago, Mali61 said:

Thank you, it's working great ❤️

 

You can add these two modules(EterPythonLib)

  Hide contents

yrtqWv0.png

yCJ2bQw.png

Aoy6hJ8.png

wudbZZk.png

 

 

Hi ! 

Thanks for your feedback !

I added the two functions. I did as they took an int as parameter. I will think about how to properly model these objects in Python automatically.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

  • Forum Moderator
On 1/22/2021 at 4:19 AM, VegaS™ said:

I'll add it tomorrow night on GitHub + other features. 😴

On 1/22/2021 at 7:16 PM, Takuma said:

To continue, you can use VegaS's script to convert your python2 code to python3.

This will adapt your code to be usable both in python2 and python 3.

 

 

Link to comment
Share on other sites

  • 9 months later...
  • Premium

After trying it out on atom and pycharm, I decided to use it on VS Code.

However, there's a problem with the sintax from the pylance (built-in with the python extension):

spacer.png

This is because the functions are set as NoReturn and pylance doesn't like that, that's why the code seems unreachable.

 

In order to fix this, you need to change the type NoReturn to None:

spacer.png

You can do it by changing all the files after the manipulation or change the 

This is the hidden content, please
.

 

Thank you for the release, everything is working as expected!

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 3
  • Love 2
Link to comment
Share on other sites

  • 1 month later...
On 11/13/2021 at 2:39 PM, msnas said:

After trying it out on atom and pycharm, I decided to use it on VS Code.

However, there's a problem with the sintax from the pylance (built-in with the python extension):

spacer.png

This is because the functions are set as NoReturn and pylance doesn't like that, that's why the code seems unreachable.

 

In order to fix this, you need to change the type NoReturn to None:

spacer.png

You can do it by changing all the files after the manipulation or change the 

Hidden Content

  • Give reaction to this post to see the hidden content.

.

 

 

Thank you for the release, everything is working as expected!

 

Thanks for the feedback. I update the repo, sorry for be late !
I also add you to Thanks part in README.MD, I can put your GitHub profile if you want.

I was wrong on the NoReturn, it is actually intended for a code that exits the program (Source).
 

Takuma.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 2
Link to comment
Share on other sites

  • 2 months later...
  • Honorable Member

 

Tool for converting official builtins: 

This is the hidden content, please

example safebox.py:

Spoiler
__author__ = "blackdragonx61/Mali"
__unpacker__ = "xP3NG3Rx"
__skeleton__ = "Takuma"

SAFEBOX_PAGE_SIZE = 45
SAFEBOX_SLOT_X_COUNT = 5
SAFEBOX_SLOT_Y_COUNT = 9
__name__ = 'safebox'

def GetItemApplyRandom() -> None:
	pass

def GetItemAttribute() -> None:
	pass

def GetItemChangeLookVnum() -> None:
	pass

def GetItemCount() -> None:
	pass

def GetItemFlags() -> None:
	pass

def GetItemID() -> None:
	pass

def GetItemMetinSocket() -> None:
	pass

def GetItemRareAttribute() -> None:
	pass

def GetItemRefineElement() -> None:
	pass

def GetItemSetValue() -> None:
	pass

def GetMallItemApplyRandom() -> None:
	pass

def GetMallItemAttribute() -> None:
	pass

def GetMallItemChangeLookVnum() -> None:
	pass

def GetMallItemCount() -> None:
	pass

def GetMallItemID() -> None:
	pass

def GetMallItemMetinSocket() -> None:
	pass

def GetMallItemRareAttribute() -> None:
	pass

def GetMallItemRefineElement() -> None:
	pass

def GetMallItemSetValue() -> None:
	pass

def GetMallSize() -> None:
	pass

def GetMoney() -> None:
	pass

def IsSealedMallItem() -> None:
	pass

 

Sorry for the function return type and parameters.

There is not enough information to convert them.

Spoiler

Put the tool in official unpacked builtins and use it:

155248mali.png

 

  • Metin2 Dev 7
  • Good 2
  • Love 2

 

Link to comment
Share on other sites

  • 2 months later...

Hi devs !

So, I just pushed a commit. It's a an uptdate :

  • I refactored all the code (not in only one file);
  • Tools can know support many modules in same file;
  • Some parameters, such as the use of the snake_case for the arguments, can be configured in the CONSTANTS.py file

No modification to use the script. Do as before.

 

(Sorry for my bad english)

 

Takuma.

Edited by Takuma
  • Metin2 Dev 2
  • Good 1
  • Love 3
Link to comment
Share on other sites

I cannot edit my subject, so... I'll write the changes here.

Now you no longer need to use bin and src folders mandatorily.

This is the hidden content, please

Please, read README.md file to know how to use the script. A example of use could be :

Quote

python main.py -s src -o bin

to use src and bin folders as before.

Thank to NewWars ❤️

 

  • Metin2 Dev 4
  • Good 1
  • Love 2
Link to comment
Share on other sites

  • 6 months later...
  • Premium

I found something interesting.

The tool is only checking if Pi_InitModule starts as a PyObject's variable.
However, there are some files that aren't being initialized in that way - 14 to be exact:

6596a8b2cc806aa54c2d3f836a350ba0.png7095949cac34b57eaf0a2e696921ab5f.png733bcc18bf420eec814c35eb6d90fecb.png

 

The solution would be to remove/comment this line:
ffdfdc2f4aae619d3d080972d984543a.png

 

And voilá, files like PythonDebugModule.cpp are being called correctly:
11cdb0243d339d7e263616d4f74befe8.png
8242fe080a591f7cf72a0d5246b5fac1.png

Edited by Metin2 Dev
Core X - External 2 Internal
  • Good 1
  • Love 1
Link to comment
Share on other sites

3 hours ago, msnas said:

I found something interesting.

The tool is only checking if Pi_InitModule starts as a PyObject's variable.
However, there are some files that aren't being initialized in that way - 14 to be exact:

6596a8b2cc806aa54c2d3f836a350ba0.png7095949cac34b57eaf0a2e696921ab5f.png733bcc18bf420eec814c35eb6d90fecb.png

 

The solution would be to remove/comment this line:
ffdfdc2f4aae619d3d080972d984543a.png

 

And voilá, files like PythonDebugModule.cpp are being called correctly:
11cdb0243d339d7e263616d4f74befe8.png
8242fe080a591f7cf72a0d5246b5fac1.png

Hi. I'm a little bit busy now. Could you maybe make a pull request on github ? I'll check this. 

 

Thanks you ! 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

Announcements



  • Similar Content

  • Activity

    1. 0

      Moving server from FreeBSD 11.2 to 13.2 - lib needed

    2. 0

      I just implemented some costumes and they are not visible

    3. 0

      Skill Tree Problem

    4. 97

      Ulthar SF V2 (TMP4 Base)

    5. 5

      Client Crashes through Offline Shop (Ikarus)

    6. 5

      VIVY-WORLD2 - FARM TO THE TOP

    7. 0

      ToolTip Bug?

    8. 0

      Skill tree build erorr

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.