elitepvpers

elitepvpers (https://www.elitepvpers.com/forum/)
-   Metin2 PServer Guides & Strategies (https://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/)
-   -   [RELEASE] Source library for add functions to game (https://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/2485132-release-source-library-add-functions-game.html)

Niks90 03/19/2013 10:58

[RELEASE] Source library for add functions to game
 
THAT SOURCE IS NOT COPYRIGHTED, IS NOT A YMIR WORK, SO DONT DELETE MY THREAD!!!!

As the first topic has been closed without a valid reason by a moderator, now i re-post that source.


Hello guys, this release is targeted to publish the source code of the infamous library for editing
and the addition of features to the game file. The source code is quite simple, there is a main that has the task of loading
and initialize the modules (which will contain the code changes to the server) and there are folders containing utility
and some functions already written. This library contains an example the addition of a function of quests
has the task of query through lua (using directly the functions of the server, so no unnecessary
lua modules and scripts pataccosi), which I called "sql.query()" and another function that its role is to apply
files "dif" directly at server startup, in memory (hotpatch), without actually changing the executable itself.

USE:
The example functions are two as I said. For "sql.query()" i'll write some example for explain is at best.

The query is performed trivially by passing it as an argument to the function.
Example:
sql.query("UPDATE table SET a = b WHERE c = d ;")

If the query does not return values (UPDATE, DROP, etc ...), then there is no problem, but if I were to get interest
one or more values returned from query, how do you make that?
Example:
local my_query = sql.query("SELECT a, b, c, d FROM table WHERE a = b ;")

Nothing could be easier! We have a variable my_query, that my function "fills" as if it were a lua table.
So you must return name_of_variable.column_selected: my_query.a
Simple, no?

With regard to differ on the fly instead, as you can see in the main there is a way, but what does it represent? Is the path
the folder that contains the dif be applied when the server starts. Instead of the one present at the time, it can be
use any path, but since he is "the same" for each game, if the folders that contain the game are not symmetrical
to the folder that contains the dif advice to put a static route (Example "/usr/user/my_dif_folder/").
In this folder, you must create a file called "dif.cfg" which will contain in order (one per line) the names of the files
loaded, which must be in the same folder.

Example:
file1.dif
file2.dif
# File3.dif ---> yes, putting a # in front of the name of the file will not load!
...
filen.dif

For convenience, it is best that the dif files contain only the offset and bytes to patch (without header created by ida and without various comments in the file).

HOW TO FILL:
Make sure you have gcc installed on the server, place a terminal in the source directory and run the command "./compile.sh"
(if it says that you can not run, it is likely that the missing execute permissions, assign them with a "chmod + x compile.sh" and then fed back the compile command).
This will create a new file in the folder above where the source, called "royalsword.so", this is your library.

HOW TO START WITH THE LIB:
To make it load to the server, just change the script you use to start different game, changing the line
Run the game (eg "./path/to/my/game") with:
LD_PRELOAD = "/path/to/my/lib/royalsword.so" ./Path/to/my/game
Obviously, for a server with multiple cores, you need to edit each line where a core is loaded.

*Casi* 03/19/2013 11:24

wrong password

Niks90 03/19/2013 11:49

Try now, without "http://"

mt2malaka 03/19/2013 12:24

i haven`t can open the file because the pass is bad i test with [Only registered and activated users can see links. Click Here To Register...]

MrGanja 03/19/2013 12:26

Quote:

Originally Posted by mt2malaka (Post 21743402)
i haven`t can open the file because the pass is bad i test with [Only registered and activated users can see links. Click Here To Register...]

try without http:// only [Only registered and activated users can see links. Click Here To Register...] .

[The]Domco 03/19/2013 12:27

So what the hell this does ? I must write code in C++ and then save it and i can add functions to the game core or what ?

Zonni 03/19/2013 12:36

Quote:

Originally Posted by [The]Domco (Post 21743450)
So what the hell this does ? I must write code in C++ and then save it and i can add functions to the game core or what ?

Yes. You can.

Mi4uric3 03/19/2013 14:29

Quote:

Originally Posted by pixen1 (Post 21744656)
Reupload - no password.
[Only registered and activated users can see links. Click Here To Register...]

There is no need of reuploading it.
I reported your post

*Casi* 03/19/2013 14:45

Thx

JachuPL 03/19/2013 15:42

sooo, if i know C/C++ i can write my own functions and recompile it using your stuff, right?

*Casi* 03/19/2013 16:49

Quote:

Originally Posted by JachuPL (Post 21746285)
sooo, if i know C/C++ i can write my own functions and recompile it using your stuff, right?

yes

balika01 03/19/2013 16:52

not nice source :D

Sphinx² 03/19/2013 17:08

Hmm.... It's bad(wrong?) to release the method for hooking functions in the game...
Now every idiot can do that...

Kind regards
Sphinx

HalloweeN² 03/19/2013 19:38

ich versteh nur bhf

Edit: liegt nicht an meinem Englisch

Perfection- 03/19/2013 19:57

mit den sachen hier kannst du quasi alles zur game an funktionen hinzufügen was du willst und wie du lustig bist, so im klartext so das hier ist ein beispiel so wie ich das verstehe.

Aber die methode ist auch nicht ganz so neu eig musste man nur hier in den threads rumschauen es wurden immer hinweise gegebene wie es funktioniert, naja jetzt weis es jeder nur noch ein hindernis gibt es :D nicht jeder kann C++ :P ( ich bin am lernen ).

zum thread:
Nice thread very good, thanks bro :)

ricky92 03/19/2013 22:59

Quote:

Originally Posted by balika01 (Post 21747529)
not nice source :D

Wait wait wait, are you fu**ing serious? You "wrote" an archiver tool with the worst syntax and style I've ever seen. And you even accuse others of having stolen your work when you have no proof of what you say (I'm making a reference to the "EterNexus" thread).
Yet, you came here saying "not nice source", and you probably also rated this thread at just one star just to make people think this release is rubbish. I'm astonished.

Back on topic, anyway, this is a great release and will allow greater development on the metin2 server files. I already had a library I made, but I'm sure this will let people be creative.

xcape414 03/20/2013 00:37

Every idiot who can at least do some C++, you mean.
Not all can understand those kind of thing

balika01 03/20/2013 01:31

Quote:

Originally Posted by ricky92 (Post 21754301)
Wait wait wait, are you fu**ing serious? You "wrote" an archiver tool with the worst syntax and style I've ever seen. And you even accuse others of having stolen your work when you have no proof of what you say (I'm making a reference to the "EterNexus" thread).
Yet, you came here saying "not nice source", and you probably also rated this thread at just one star just to make people think this release is rubbish. I'm astonished.

Back on topic, anyway, this is a great release and will allow greater development on the metin2 server files. I already had a library I made, but I'm sure this will let people be creative.

you think this accidentally have worst syntax? :cool: lets see the source.. parts from s0beit for samp ([Only registered and activated users can see links. Click Here To Register...] [Only registered and activated users can see links. Click Here To Register...]) xD and "void __attribute__ ((constructor)) my_load(void);
void __attribute__ ((destructor)) my_unload(void); .." from [Only registered and activated users can see links. Click Here To Register...] not full copy?! and detour main? what the hell? xD no, this not nice souce. that all form full stolen stuffs.. and any copyright or licence? i found nothing.. (and i said nothing about your releases..)

edit:
who didn't made own dinamic library? (ex.: my petsytem in a lib :cool:)

Niks90 03/20/2013 01:55

Quote:

Originally Posted by balika01 (Post 21755414)
you think this accidentally have worst syntax? :cool: lets see the source.. parts from s0beit for samp ([Only registered and activated users can see links. Click Here To Register...] [Only registered and activated users can see links. Click Here To Register...]) xD and "void __attribute__ ((constructor)) my_load(void);
void __attribute__ ((destructor)) my_unload(void); .." from [Only registered and activated users can see links. Click Here To Register...] not full copy?! and detour main? what the hell? xD no, this not nice souce. that all form full stolen stuffs.. and any copyright or licence? i found nothing.. (and i said nothing about your releases..)

edit:
who didn't made own dinamic library? (ex.: my petsytem in a lib :cool:)


ADE32 is adapted (from darkanima and mr.lucifer) to run on linux, so, how it can be copied?
Part of this code was taken on stackoverflow, and documentation of BSD.
my_load and my_unload, are just a coincidence that they are like the code that you linked.
Are you angry because you no longer have the exclusive?

balika01 03/20/2013 02:09

Quote:

Originally Posted by Niks90 (Post 21755526)
ADE32 is adapted (from darkanima and mr.lucifer) to run on linux, so, how it can be copied?
Part of this code was taken on stackoverflow, and documentation of BSD.
my_load and my_unload, are just a coincidence that they are like the code that you linked.
Are you angry because you no longer have the exclusive?

i said 3 word and a smiley.. xD (and respond for ricky92) im angry? no xD

--> mr.lucifer have it from s0beit

WinDef.h for linux: (form vc++2010 whit removed unneeded stuffs for linux) (whit this work official ADE32)
Code:

/****************************************************************************
*                                                                          *
* windef.h -- Basic Windows Type Definitions                                *
*                                                                          *
* Copyright (c) Microsoft Corporation. All rights reserved.                *
*                                                                          *
****************************************************************************/


#ifndef _WINDEF_
#define _WINDEF_
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#ifndef BASETYPES
#define BASETYPES
typedef unsigned long ULONG;
typedef ULONG *PULONG;
typedef unsigned short USHORT;
typedef USHORT *PUSHORT;
typedef unsigned char UCHAR;
typedef UCHAR *PUCHAR;
typedef char *PSZ;
#endif  /* !BASETYPES */

#undef far
#undef near

#define far
#define near

#undef FAR
#undef  NEAR
#define FAR                far
#define NEAR                near
#ifndef CONST
#define CONST              const
#endif

typedef unsigned long      DWORD;
typedef int                BOOL;
typedef unsigned char      BYTE;
typedef unsigned short      WORD;
typedef float              FLOAT;
typedef FLOAT              *PFLOAT;
typedef BOOL near          *PBOOL;
typedef BOOL far            *LPBOOL;
typedef BYTE near          *PBYTE;
typedef BYTE far            *LPBYTE;
typedef int near            *PINT;
typedef int far            *LPINT;
typedef WORD near          *PWORD;
typedef WORD far            *LPWORD;
typedef long far            *LPLONG;
typedef DWORD near          *PDWORD;
typedef DWORD far          *LPDWORD;
typedef void far            *LPVOID;
typedef CONST void far      *LPCVOID;

typedef int                INT;
typedef unsigned int        UINT;
typedef unsigned int        *PUINT;

#ifndef NOMINMAX

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#endif  /* NOMINMAX */

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
#define LOWORD(l)          ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l)          ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define LOBYTE(w)          ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w)          ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))

#ifdef __cplusplus
}
#endif

#endif /* _WINDEF_ */


doraemonita 03/20/2013 02:58

Quote:

Originally Posted by balika01 (Post 21755580)
i said 3 word and a smiley.. xD (and respond for ricky92) im angry? no xD

--> mr.lucifer have it from s0beit

WinDef.h for linux: (form vc++2010 whit removed unneeded stuffs for linux) (whit this work official ADE32)
Code:

/****************************************************************************
*                                                                          *
* windef.h -- Basic Windows Type Definitions                                *
*                                                                          *
* Copyright (c) Microsoft Corporation. All rights reserved.                *
*                                                                          *
****************************************************************************/


#ifndef _WINDEF_
#define _WINDEF_
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#ifndef BASETYPES
#define BASETYPES
typedef unsigned long ULONG;
typedef ULONG *PULONG;
typedef unsigned short USHORT;
typedef USHORT *PUSHORT;
typedef unsigned char UCHAR;
typedef UCHAR *PUCHAR;
typedef char *PSZ;
#endif  /* !BASETYPES */

#undef far
#undef near

#define far
#define near

#undef FAR
#undef  NEAR
#define FAR                far
#define NEAR                near
#ifndef CONST
#define CONST              const
#endif

typedef unsigned long      DWORD;
typedef int                BOOL;
typedef unsigned char      BYTE;
typedef unsigned short      WORD;
typedef float              FLOAT;
typedef FLOAT              *PFLOAT;
typedef BOOL near          *PBOOL;
typedef BOOL far            *LPBOOL;
typedef BYTE near          *PBYTE;
typedef BYTE far            *LPBYTE;
typedef int near            *PINT;
typedef int far            *LPINT;
typedef WORD near          *PWORD;
typedef WORD far            *LPWORD;
typedef long far            *LPLONG;
typedef DWORD near          *PDWORD;
typedef DWORD far          *LPDWORD;
typedef void far            *LPVOID;
typedef CONST void far      *LPCVOID;

typedef int                INT;
typedef unsigned int        UINT;
typedef unsigned int        *PUINT;

#ifndef NOMINMAX

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#endif  /* NOMINMAX */

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
#define LOWORD(l)          ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l)          ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define LOBYTE(w)          ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w)          ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))

#ifdef __cplusplus
}
#endif

#endif /* _WINDEF_ */


come on man, do you think that i need to copy stuff because i'm too stupid to do it? be serious, i got ADE32 from CDetours lib (for windows) from someone that i don't remember on a forum, when i was writing my lib for the client, then i realized that "DETOUR_LEN_AUTO" could be used with a detour library on *nix, so i fixed a couple of types (because only an idiot would include that header you posted on linux os, that convention is NOT standard, why the hell should i use LPDWORD instead of int *?). not lucifer nor me got code from that link, contructor and destructor comes from the link you poster, you are right, i read them here. now tell me, that is an article that explains how to use a constructor when a library is loaded, so that code "following your idea" should not be used, right? you are ridiculous. detour func for linux comes from someone on the 'net too but who cares, why would i have to reinvent the wheel? i wrote a petsystem too! oh, maybe you think that i copied it from someone :D

Cescoso 03/20/2013 10:51

Quote:

Originally Posted by ricky92 (Post 21754301)
Wait wait wait, are you fu**ing serious? You "wrote" an archiver tool with the worst syntax and style I've ever seen. And you even accuse others of having stolen your work when you have no proof of what you say (I'm making a reference to the "EterNexus" thread).
Yet, you came here saying "not nice source", and you probably also rated this thread at just one star just to make people think this release is rubbish. I'm astonished.

That's really funny :D
Copied or not, these are things never seen on a metin2 forum since i remember.

zeromentu 03/20/2013 15:09

This library works on AMD 64bit's?

balika01 03/20/2013 15:41

Quote:

Originally Posted by zeromentu (Post 21760576)
This library works on ADM 64bit's?

what is the ADM?

(if you mean amd i can say yes)

Anohros 03/20/2013 16:05

Hello,

the source code doesn't look nice, needs a rework of code.

I worked out this method of modding with ld_preload since months, it's nothing special.
Use g++(c++) to compile! (Object oriented programming) :handsdown:

To attaching the i386 library in a amd64 environment you must adjust the ld_preload environment variable. To inject the library in amd64 environment you can make usage of the coreext_amd64 injector.


With regards,
Anohros

lollo_9_1 03/20/2013 21:10

Quote:

Originally Posted by Anohros (Post 21761562)
To inject the library in amd64 environment you can make usage of the coreext_amd64 injector.

Rotfl?

Code:

#compile
g++ -m32 ...
#env var
LD_32_PRELOAD="/path/lib.so"
./game


LazYGirl. 03/21/2013 16:00

but we have to get some game functions such as equipitem etc. can we get current functions ? if yes then how?

Niks90 03/21/2013 20:03

Yes, you can use all default functions how you prefer.
How? Eheh, you must analyze your elf :D

xDeStRuCtx 03/21/2013 20:27

look, if i inject new func, like pc.kill or something like that.. then, how to do, that first argument of this function is vid of player? you know, like:
int kill(a1){
gamefunctionkill(a1)
return 1 }

LazYGirl. 03/21/2013 20:32

Quote:

Originally Posted by Niks90 (Post 21782292)
Yes, you can use all default functions how you prefer.
How? Eheh, you must analyze your elf :D

okey i did it and why we didnt think that its awesome idea :D

Perfection- 03/23/2013 10:20

hey kann mir einer von den wissenden erklären, ob wenn ich es am anfang mit LD_32_Preload in die game einfüge ( also bevor ich die cores starte ) ob ich es dann nach dem core start in jeden core nochmal einfügen muss oder nicht?

und wenn es so ist das ich es nur 1 mal einfügen muss ist es dann nach einem reboot wieder weg und muss neu gemacht werden?

danke im vorraus an die wissenden :P

ricky92 03/23/2013 10:36

Quote:

Originally Posted by .Xero (Post 21806055)
hey kann mir einer von den wissenden erklären, ob wenn ich es am anfang mit LD_32_Preload in die game einfüge ( also bevor ich die cores starte ) ob ich es dann nach dem core start in jeden core nochmal einfügen muss oder nicht?

und wenn es so ist das ich es nur 1 mal einfügen muss ist es dann nach einem reboot wieder weg und muss neu gemacht werden?

danke im vorraus an die wissenden :P

You need to set the LD[_32]_PRELOAD environment variable every time you execute the game file for each core. Your best option would be to add it to the start.sh script, or use a "loader program" like Anohros did (I don't really like this approach, though, as it tends to overcomplicate the whole thing, while still being nothing more than a program which sets an environment variable and then executes the game file).

ricky92 03/27/2013 11:52

Quote:

Originally Posted by kwiatmix (Post 21883282)
[Only registered and activated users can see links. Click Here To Register...]

chmod a+x ./compile.sh

[The]Domco 04/07/2013 15:31

Please how to run the library ? the ld_preload i think dont work can anyone send me your start server file where it works ? :(

Zonni 04/07/2013 19:38

Quote:

Originally Posted by [The]Domco (Post 22095383)
Please how to run the library ? the ld_preload i think dont work can anyone send me your start server file where it works ? :(

[Only registered and activated users can see links. Click Here To Register...]

use coreext to preload .so to your gamefile.

[The]Domco 04/07/2013 20:45

Quote:

Originally Posted by Zonni (Post 22100145)
[Only registered and activated users can see links. Click Here To Register...]

use coreext to preload .so to your gamefile.

why the hell its creating sh.core not royalsword.so.core ? :(

Niks90 04/09/2013 03:42

I'll republic the link, mod in this forum like remove all :asd:
[Only registered and activated users can see links. Click Here To Register...]

Mijago 04/09/2013 07:04

ld_preload
It works; but you need a shell script!
#!/bin/sh

.Bloddy 05/05/2013 23:06

[Only registered and activated users can see links. Click Here To Register...]
Help me v.v

ionutxp 05/06/2013 11:07

This is a great library.
1.You can make a small documentation for it. Documentation with: Classes and methods from the game.
Ingame cmd's support.
2. It would be awsome if you can get the mysql function to act like:
PHP Code:

result sql.query("SELECT `id`, `name` FROM `player`;")
say(result[1].id .. ": " .. result[1].name)
say(result[2].id .. ": " .. result[2].name)
.
.
.
say(result[n].id .. ": " .. result[n].name

C's lua_* functions are quite strange for me.


All times are GMT +2. The time now is 15:14.

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.