Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 16:50

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



c++ and python

Discussion on c++ and python within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2009
Posts: 101
Received Thanks: 167
c++ and python

I have a dll made in c++ (gnu gcc compiler - codeblocks) injected in my metin2 pserver client and i need to call a function from game.py (or to execute a python code) but i don't know how to do it ...
I need an example ... (I have instaled python2.2 and I can use function from python.h but how?)
3t3r4n is offline  
Old 06/28/2013, 15:47   #2
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Schlüsselbein is offline  
Old 06/28/2013, 16:22   #3
 
elite*gold: 0
Join Date: Dec 2009
Posts: 101
Received Thanks: 167
I have tried this
Code:
PyObject* args = PyTuple_New(0);
PyObject_Call(PyObject_GetAttrString(PyImport_ImportModule("app"), "Exit"), args, NULL);
Py_XDECREF(args);
but nothing happened
3t3r4n is offline  
Old 06/28/2013, 16:59   #4
 
elite*gold: 0
Join Date: Sep 2010
Posts: 454
Received Thanks: 212
Maybe this helps you:
Zwawo is offline  
Old 06/28/2013, 17:26   #5
 
elite*gold: 0
Join Date: Dec 2009
Posts: 101
Received Thanks: 167
Code:
    PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
    Py_Initialize();
    pName = PyString_FromString("testfile");
    pModule = PyImport_Import(pName);
    pDict = PyModule_GetDict(pModule);
    pFunc = PyDict_GetItemString(pDict, "functocall");
    if (PyCallable_Check(pFunc))
    {
        PyObject_CallObject(pFunc, NULL);
    } else
    {
        ShowMessageFunc("ERROR");
    }
    Py_DECREF(pModule);
    Py_DECREF(pName);
    Py_Finalize();
testfile - i have testfile.py in root.epk
Code:
import uiCommon

def functocall():
	alertbox=uiCommon.PopupDialog()
	alertbox.SetText("message")
	alertbox.Open()
After Py_Finalize() i got a crash ...
3t3r4n is offline  
Old 06/28/2013, 18:25   #6
 
elite*gold: 0
Join Date: Sep 2010
Posts: 454
Received Thanks: 212
Delete "Py_Finalize()".
Zwawo is offline  
Old 06/28/2013, 18:31   #7
 
elite*gold: 0
Join Date: Dec 2009
Posts: 101
Received Thanks: 167
Quote:
Originally Posted by Zwawo View Post
Delete "Py_Finalize()".
If I delete Py_Finalize() nothing happens ...
3t3r4n is offline  
Old 06/28/2013, 18:32   #8
 
elite*gold: 0
Join Date: Sep 2010
Posts: 454
Received Thanks: 212
Just as example(this works):
Code:
string GetName(void)
{
	PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
	string name;
	Py_Initialize();
	pName =  PyString_FromString("player");

    pModule = PyImport_Import(pName);

    pDict = PyModule_GetDict(pModule);

	pFunc = PyDict_GetItemString(pDict, "GetName");
	if (PyCallable_Check(pFunc)) 
    {
       pValue = PyObject_CallObject(pFunc, NULL);
	   name = PyString_AsString(pValue);
	   if(name.empty())
	   {
		   name = "ERROR";
	   }

    } else 
    {
		name = "ERROR";
    }

	Py_DECREF(pModule);
    Py_DECREF(pName);
	Py_DECREF(pValue);


	return name;
}
Zwawo is offline  
Old 06/28/2013, 18:42   #9
 
elite*gold: 0
Join Date: Dec 2009
Posts: 101
Received Thanks: 167
"player" is a module but my file (i compiled it and i have put it in lib folder) i don't think it is a module ....

Do you have a source of a python module loader?
3t3r4n is offline  
Old 06/28/2013, 18:51   #10
 
elite*gold: 0
Join Date: Sep 2010
Posts: 454
Received Thanks: 212
Quote:
Originally Posted by 3t3r4n View Post
Do you have a source of a python module loader?
No, sry. I'm not very familiar with python.
Zwawo is offline  
Reply


Similar Threads Similar Threads
[Python-Modul]EXP-Donator (kompatibel mit Python Loader)
11/23/2013 - Metin2 Hacks, Bots, Cheats, Exploits & Macros - 27 Replies
Moin, da man mich danach gefragt hat und ich sowieso mal ein Beispiel für die Benutzung meines Python Loaders veröffentlichen wollte, habe ich die Gelegenheit genutzt und euch eben einen EXP-Spendebot geschrieben. Man kann ihn einfach mit dem oben verlinkten Python Module Loader laden und ihn mit F5 aktivieren/deaktivieren. Sobald ihr mehr als 99 Erfahrungspunkte habt (man kann nur in 100er Schritten spenden), werden alle Erfahrungspunkte an eure Gilde gespendet. Wer Lust hat und...
Help to make a python file works with python loader
03/03/2013 - Metin2 - 2 Replies
Hey epvp! I want make a very. Little hack works on pythonn loader can anybody help me please?
Metin2 - Python - Wie Python Hacks verschlüsseln und Server überprüfen (GF/PServe)
09/23/2012 - Metin2 - 2 Replies
Ich wollte fragen, wie man Python Hacks am besten Verschlüsselt ? und wie man feststellen kann ob man auf einem GF / Pserver spielt. ?
Python + Eric Python IDE installieren ?!
07/05/2011 - General Coding - 0 Replies
hat sich erledigt.
Python
05/23/2010 - Metin2 Private Server - 4 Replies
Metin2 ist ja mit Python geschrieben worden. Ich würde es gerne erlernen und nach ein paar Monaten/Jahren Übung, ein Game schreiben...^ Was haltet ihr von Python? Lohnt es sich damit anzufangen, wenn man ein Game schreiben will? LG NedFlanders ;)



All times are GMT +2. The time now is 16:50.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.