[Python/dll] It should work !

01/25/2014 00:10 dramcio#1
Hello.

I try to use python in my DLL i'm newbie :<

Code:
#include "windows.h"
#define MS_NO_COREDLL
#include <Python.h>
#include <detours.h>

#include "stdafx.h"
#include <string>
#include <sstream>
#include <iostream>
#include <fcntl.h>
#pragma comment(lib, "detours.lib")
using namespace std;

void pickupitem(){
	PyObject* args = PyTuple_New(0);
	PyObject* ret = PyObject_Call(PyObject_GetAttrString(PyImport_ImportModule("player"), "PickCloseItem"), args, NULL);
	double result = PyFloat_AsDouble(ret);
	Py_DECREF(ret);
	Py_XDECREF(args);
	//return result;
}
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		pickupitem();
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
I attach this to process (and it compile successfull but it dont pickup item in game)

Btw. what is the best dll + python injector ? I remember that i saw python + dll injector in one program (DE for metin)

// 2 my metin2 client is still running as administrator privillages.

I dont know how to remove it ( i dont set it in file proporties )
01/25/2014 13:05 [uLow]Beni#2
i think player.PickCloseItem don't have any return (None).

and its impossible to compile because a void function (must not return) returns double.
01/25/2014 14:10 dramcio#3
ohh i edit this in forum there i fix the code in 1st post. Sorry.

Btw. i try to inject this dll into P SERVER ..


I think it is fault of my VISUAL STUDIO.

Bcoz when i inject it by Winject (program to inject dll into process )

i have got injection failed.

But when i remove python func and change that when the dll is attach show message box - it works.

IF i make that :

Quote:
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, (LPCSTR) "WORK!", (LPCSTR) "YES !", NULL);
pickupitem();
break;
I saw 2x WORK! but python dont work and this injector still show error.

It is possible to debug this dll ?
And know whats wrong ? ;x
01/25/2014 14:13 Sanchez_x#4
You can easily remove the administrator privileges with Resource Hacker. Here are the steps:

1. Download Resource Hacker from this site: [Only registered and activated users can see links. Click Here To Register...]
2. Open the binary in Resource Hacker and in the Folder tree go here: 24 > 1 > 1033
3. Replace this line:
Code:
<requestedExecutionLevel  level="requireAdministrator" uiAccess="false"></requestedExecutionLevel>
with this:
Code:
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
4. Go to File and click Save as, now Resource Hacker will save your binary without administrator privileges.
01/25/2014 14:28 Mi4uric3#5
I don't get the point of using Python in c++ for Metin2.
Those Python-"Exports" are just c++ functions exported by metin2client.bin so the Python-scripts can use it.
Why don't you call them directly?
You are trying to:
c++ -> Python -> Python -> C++ -> Result

But you could simply do:
c++ -> c++ -> Result
01/25/2014 14:47 dramcio#6
ok i understand that python run c++ function.

But i dont understand why it dont work ?

IF i make that :

Quote:
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, (LPCSTR) "WORK!", (LPCSTR) "YES !", NULL);
pickupitem();
break;
I saw 2x WORK! but python dont work and this injector still show error.

It is possible to debug this dll ?
And know whats wrong ? ;x
01/25/2014 14:52 Mi4uric3#7
Maybe you need to link to the python lib?
01/25/2014 14:57 dramcio#8
IN: project > proporties > linker > additional libary directories > C:\Python27\libs

Whats more?
01/26/2014 16:46 dramcio#9
Halo. You can use python in dll , but why me cant ?:x

I paste python27.dll into metin2.

2. It is possible to debug this dll?

Py_initalize() - crash Metin2 ;0
01/31/2014 00:11 dramcio#10
Refresh, any one dont know how to solve problem?
02/01/2014 09:32 KaMeR1337#11
are you trying it on python27? (GameForge), try it on python22 (pservers) and see if works. i had crashing problem on python27 too