• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[GUIDE] Adding Code to Client or Server via a DLL. (Part 1.)

Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
Thanks AB. It's nice to know these tutorials are being read and people find them useful. :D:

This one has some waffle in it, because different people come here with different levels of skills and depths of understanding. I've tried to indent and aside anything that isn't key to the tutorial, but just background info.

You can see from the edits that I do also try to maintain my tutorials... if people are still posting about them. :wink:

So are Xternal okay with using DLLs to extend future clients?
 
Newbie Spellweaver
Joined
Sep 15, 2009
Messages
43
Reaction score
27
It's definitely nice to start to write real code by attaching a DLL.

Though, you seem to attach a dll, then write that DLL in asm, that's just confusing. Go write it in C++! Or atleast C, but that's still stupid since PT is written in C++ ;)

offtopic: whats with the tags of this topic? 'nerd loser, retarded faggot'.
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
:eek: I hadn't noticed that. I guess one of the Admins holds this opinion of me, as nobody else has the power to change my topic tags I think. :(: Maybe because I forgot to tag, or just because I multi-posted and filled in the info later (to avoid a tutorial interspersed by chat, that I could add chapter links to) or just because I hold some strong, and unusual, opinions that I will keep. (not that I insist everyone agrees with me on them) Like Object Orientation does not make code more reusable, good documentation does that. Or Instant Messengers and Mobile Phones are EVIL. :lol: I've fixed them now.

---EDIT---
Correction... I can edit DarkKnightH20s left click tags and call him names anonymously, it seems... (of course I wouldn't) :(:
---EDIT---

Hmm. Well, yes you could use C++, but I hate it, it's too Object Orientated and even COBOL is easier to read. You could use C, but I don't really see any advantage to writing C when you can build fast, clean, clear assembler. It builds quicker, is more within your own control and despite popular opinion, I find Assembler just as readable as C. I learned and used C when I needed code to run on Z80, 68000 and 80x86 CPU based systems, but if I'm targeting only one CPU family, I don't need C.

As I've already said, you could use "useful" languages, which are more readable than Assembler, like Basic, or Pascal. XD But since the first things we are likely to want to do, is export code that is already in the game.exe or server.exe, and add to it (maps, levels, items, ages, file & data formats etc. etc.) and know that our DLL is isolated, and works just as it did when it was part of the main exe, before we port that code to a higher level language... Assembler is where I shall start.

Besides, most people here wanted to write in C# or VB.net when I mentioned importing DLLs, which is clearly not practical... you want C++ or C, I want Basic or Pascal (but I'm fine with C)...

x86 Assembler is one language we all have to be familiar with if we are even going to attempt this. If we are not comfortable with Assembler, Olly will be too meaningless to achieve the connections between our DLL and the main game. So x86 Assembler it is for Part 1.

What should be Part 2?
  • Using DLLs written in a variety of other languages?
  • Loading DLLs, and importing their functions dynamically? (using LoadLibrary() or LoadLibraryEx())
  • Exporting functions and data from game.exe to a DLL?
I have some I've built in Dev-C++, (and they are C++, rather than C as well; interestingly) and some I've built in FreeBASIC, I'd like to have some in Free Pascal and maybe VB6, as that used to be popular here before MS went all .NET on us. XD

I can build BCB DLLs, but there's too little difference between that and Dev-C++ unless you use the VCL. (There's no point for PT I think) I don't have Delphi or Visual Studio, and don't see any reason to pollute my existing Development Environment (Borland / GNU) with MS nonsense. Lazarus is sufficient for my Pascal needs. :wink:

I have exported some sections with ease. I've Implemented most of the common KPTTrans code section patches in DLL form. I've written up patch code others have suggested putting in the exe as a DLL... but probably exporting all SQL functions in the server to a new PTSQL.dll that reads registry or ini configuration and doesn't need "hexing" and / or could be re-targeted at a different SQL database engine would be far more useful and interesting as a study.

If you're concerned with the client and the way it looks and feels on a users PC, then the LoadLibrary() routine, and a means of locking to specific DLL checksums would be far more useful to you. The ability to choose software, Direct3D or OpenGL as the rendering engine, setting volume levels and number of channels on sound, dynamic resolution and render (fog) distance all spring to mind and would make a great difference to performance vs. quality decisions for the users.

Each of these things needs discussing... but which should be given the greater priority for Part 2, I'm not yet sure... I hope the comments here will give me an idea of what people want most. Certainly, there is too much there to place in a single thread. No???
 
Last edited:
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
Posted mirrors of the present releases using DepositFiles... hope that's okay for you rxaicy. :)
 
Experienced Elementalist
Joined
Jan 1, 2009
Messages
217
Reaction score
61
i am so sorry ,bobsobol,i cannot download them from Deposit..can you use rapidshare? thank you very much..thank you.
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
I'm afraid I can't / won't use RapidShare on principal... they won't let me upload any 1 file to more than 10 persons without me giving them much personal information and money. (That's uncalled for)

Please try these links, using hosts I know are popular among my Far East Asian friends.








I also like , , (thought they can mess you around long term moving their servers:(:), (though many people complain about the commercials on that one. I tried to use it from IE once and saw what they meant, but with my setup they all get filtered. XD)
 
Last edited:
Imri Persiado
Joined
May 17, 2008
Messages
941
Reaction score
26
I was offline for the last weeks, only now I noticed..
this is so usefull and so interesting, I never had a clue how to add a dll to my server.
I think this is the most usefull guide in the tutorial section.
really thank you bobsbol.
Soon when my school tests will be finished I will work on that.

off topic: I've saw that UserName said that pristontale was writen in c++.
If I want to edit the client/server exe with C + + this is not possible in the current situation. What to do with the EXE? Need to convert it?

Sorry about the lack of knowledge on the subject, thanks.
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
You need to buy the source code from Triglow. There is no way you are ever going to get C++ back from the exe, the compiler optimizer has destroyed the reversibility. Besides, you would struggle to understand C++ code with all the "formatting" removed. (new lines, indentation etc, not to mention code comments)

I've had several attempts at re-writing a complete client from scratch, using Olly as my template, and even from Assembler, it's clear that most of the code is C, not C++. C++ is used for the Component Object Model (DirectX and OLE) and very little else.

I don't "know" this because I've seen the source, I "smell" it in the library routines (part of the C runtime in all Visual C programs) which are, and are not called.

You can, of course, rename a C file CPP and it will still compile as C++... but it's still C code. XD
 
Last edited:
Imri Persiado
Joined
May 17, 2008
Messages
941
Reaction score
26
Ok the how a c++ or c progrommar can help in the pristontale world?only build a launcher..
so c and c++ is useless for pt am I right?
and just wondering, triglow will sell the sources?and if they does you have any idea what is the range?just wondering.

thanks..
 
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
Ok the how a c++ or c progrommar can help in the pristontale world?only build a launcher..
so c and c++ is useless for pt am I right?
and just wondering, triglow will sell the sources?and if they does you have any idea what is the range?just wondering.

thanks..

For example you can write clan files in C#...

Actually C programmer would be great help for me right now :)

Heres server4096.c (attached) C code(pseudocode :)) migrate it to 64bits or compile it under Winelib so it will be more compatible with linux.

I wonder if its possible.

If its possible to do something with this we could start project where we would name all functions we know and than produce .c file that will be understandable.

Split in 2 files because ragezone cant take big files... if 1.10 MB is big XD
 

Attachments

You must be registered for see attachments list
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
For example you can write clan files in C#...
Only if your C# compiler allows you to set a build target of x86 Win32 PE... the last Visual C# I used would only build MSIL CLR assembly .exe / .dll files... and these cannot be called from x86 PE.

Can Mono do any better, or do newer, or more expensive VC# implementations allow you to compile machine native code.

C, C++, Basic, Fortran, Pascal (Delphi etc), ADA, even COBOL can be useful. But you must be able to build an x86 Win32 Portable Executable.

Visual Basic 5 and 6 could, VB4 and below only produced PCode... and the interoperability of those is questionable. VB 2005 + produce MSIL CLR binaries which are completely useless (for present PT servers). If you look at something like RapidQ, XBasic and many PHP, Python or Perl compilers, they actually only add an executable header stub, and maybe make some form of tokenised version of the source... Like VB 3 - 6 PCode. That's probably not going to help much.

On the other hand, if you took PHP, Python, Perl or Java and built the executable core (VM or whatever) into the server then you could use them to script it, just as it already supports LUA scripts for particle effects.

I've heard people talk about proxying between x86 / x64 and MSIL, but I've never seen any proof of a workable solution... which is a shame, because I know a lot of you like VB.net. :(

Here's the thing, if you have an x86 Windows OS, you can run 16 Bit LE, 16-bit MZ, 32-bit PE or MSIL CLR binary executables, but all the DLLs they link to (MZ can't link to DLLs but can load .OVLs or .MODs) must be of the same type as the primary executable, except MSIL CLR EXEs which can call pretty much anything, and that's the point of them. If you have an x64 Windows OS you can run 32-bit PE, or 64-bit PE+ or MSIL CLR EXEs, but any DLLs they call must be of the same type as the main executable, unless it is MSIL CLR EXE.
and just wondering, triglow will sell the sources?and if they does you have any idea what is the range?
Not sure what you mean about range... price or size I'm guessing. It's been suggested that the PT source code has been purchased / licensed either by Sandurr or other MMO developers like Yetime. I don't know if it's true, it's just a rumour, but the fact that Triglow still advertise PT as it was before Yedang got involved suggests that if the price was right, they may. I also don't know if one who wanted to make inquiries should contact Triglow directly, or via Yedang. That all depends on the agreement they have between them.

--- Edit ---
Triglow via HanGame (their owner?)
 
Last edited:
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
...Heres server4096.c (attached) C code(pseudocode :)) migrate it to 64bits or compile it under Winelib so it will be more compatible with linux.

I wonder if its possible.

If its possible to do something with this we could start project where we would name all functions we know and than produce .c file that will be understandable.

Split in 2 files because ragezone cant take big files... if 1.10 MB is big XD

That is so hard to make any sense of, let alone compile.

Here are links to a Disassembly of the original jPT 4096 that will almost compile in , and is much more readable. More readable even that the code listing in Olly.





You have to set the compiler memory above the normal 65536 that fasmw.exe will list... you can type 131072 to give 128Meg instead of 64Meg... and it will start to compile.

The code needs some cleaning, and humanised labels. There are some labels in the "undefined" allocated space in the exe that have no definition. It's easy, you look at those addresses in Olly and see how big they are, then define a "db x DUP (?)" where x is the number of bytes between that label and the next one.

You also need to fix imports and exports listed in the "Imports.txt" and "Exports.txt" files in FASM syntax.

macro.inc fixes some common MASM syntax that is meaningless to FASM, and I've done some extensive Search & Replace to fix "F8h" which is invalid in FASM, as you can say "0F8h" or "$F8" or "0xF8" but anything starting with a non-numeric character is a label, even if it ends with "h". And fixed the fmul, fmulp syntax from MASM style "fmul ST,ST(0)" to FASM "fmul st0,st0" and such.

MASM doesn't seem to cope with the source as well as FASM (In my tests) even though the syntax was produced to match MASM. :s

I've fixed at least one Korean text string which the disassembler can't recognise as anything other than plain bytes of data... it misses some references DWords too.

Anyway... so it needs some fixing. I have the source for the .res which still has some missing Korean text because I can't quite get an accurate decompilation of Korean "forms" yet... but that I built with GoRC so... Again, it's not hard.

If you want to create complete "compilable" source code for a PT server (or client) this is really the way to go. Once it builds, you can start re-writing routines in C or C++ and create .lib files from them that you can import into this, until such time as there is no pure x86 dependant assembler left.

BTW... from the point of view of an x64 (AMD64) or Linux build, FASM will build PE+ (Win x64) and Linux from the same source... you would have to use some "ifdef" type statements and write / re-write OS calls to equivalent routines. But this is not so difficult either... Time consuming, but not difficult.

For the client, it would be much harder, because nothing (OpenGL, Quartz Extreme, Core Services, Software Direct Layer etc.) works like DirectX, and PT doesn't use DirectX in any way Microsoft documents, so it's calls are very hard to understand.

Oh yes; Okay so the source packs to 1.2Meg from a 3.07Meg executable!!! :eek: However, using the same compression the binary compresses to 776Kb so, it's not so impressive. :wink:

I also used LZMA, not LZMA2 in this 7zip since the new compression method seems to cause people so much trouble with their "old archivers". (poke poke :wink:)
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
Playing with pseudo code giving a lot of information, like:
Code:
/날린다뇨!
/Blowing DAVID! <-- this command must rock, whatever it do lol
because right after it is txt:
}
Code:
T.T 흑흑 난 이제  틀렸어 ~~~
{
Boo-hoo ~ ~ ~ now I was wrong T.T

@_@ But who would be so crazy to fix ~389314 lines of code? Anyone Crazy here XD?
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
@_@ But who would be so crazy to fix ~389314 lines of code? Anyone Crazy here XD?

My x86 source is weighing in at 1'554'842 lines of code without the resource section. XD Once it works, I can define the string data the disassembler couldn't "guess" and the number of lines will reduce by the number of characters in each misidentified string... and once it works, we can if-def out the client code and imports from a server build, so I think it's well worth the effort.

I've got my x86 code to a point where it "compiles"... but it doesn't run yet, because the load time linking for DLLs isn't being filled in. ^_^ So yea... It looks like I'm that crazy, provided the errors are simple syntax variation.

A little search and replace, and a few macros go a long way.

The translation I get for "/날린다뇨!" is "/snowed!" or Yahoo! says "/Distinguishes the [nyo]! which"

Those strings can all be seen in Olly if your system codepage is set to Korean. :wink:

The "MrLee" commands are tantalizing too.
Code:
          db    '이방범: 스킬ShortKey 초기화',0
          Align    4
 SSZ005EBD44__LeeShotKeyReset:
          db    '/LeeShotKeyReset',0
          Align    4
 SSZ005EBD58__________________:
          db    '/이방범숏키초기화',0
          Align    4
 SSZ005EBD6C_MrLee__I_like_force_________:
          db    'MrLee: I like force /(-_-)/ ',0
          Align    4
 SSZ005EBD8C__LeeForce:
          db    '/LeeForce',0
          Align    4
 SSZ005EBD98____________:
          db    '/이방범포스:진행중인퀘스트초기화',0
 SSZ005EBDA4_____________________________:
          db    '/이방범퀘스트초기화',0
          Align    4
 SSZ005EBDC4____________________:
          db    '/이방범전업퀘스트',0
 SSZ005EBDD8_MrLee_Reconnect_again___:
          db    'MrLee:Reconnect again!! ',0
          Align    4
 SSZ005EBDF4_MrLee__Clear_Job_Quest_of_3th_:
          db    'MrLee: Clear Job Quest of 3th ',0
          Align    4
 SSZ005EBE14_MrLee__Clear_Job_Quest_of_Moryon:
          db    'MrLee: Clear Job Quest of Moryon 2th',0
          Align    4
 SSZ005EBE3C_MrLee__Clear_Job_Quest_of_Temscr:
          db    'MrLee: Clear Job Quest of Temscron 2th',0
          Align    4
 SSZ005EBE64__LeeResetRankUp:
          db    '/LeeResetRankUp',0
 SSZ005EBE74__________________:
          db    '/이방범전업퀘스트',0
          Align    4
 SSZ005EBE88_MeLee__it_s_good_________:
          db    'MeLee: it',27h,'s good /(-_-)/ ',0
          Align    4
 SSZ005EBEA4__PassRankUp:
          db    '/PassRankUp',0
 SSZ005EBEB0____________:
          db    /이방범전업',0
 SSZ005EBEBC______________________:
          db    '잘쓰게(-_-)/ ',0
          Align    4
 SSZ005EBED4__________________:
          db    '/이방범증정아이템',0
          Align    4
 SSZ005EBEE8___________________________:
          db    '이방범: 스탯초기화/(-_-)/ ',0
          Align    4
 SSZ005EBF04__LeeHelpMeStat:
          db    '/LeeHelpMeStat',0
          Align    4
 SSZ005EBF14____________________:
          db    '/이방범도와줘요스탯',0
 SSZ005EBF28___________________________:
          db    '이방범: 스킬초기화/(-_-)/ ',0
          Align    4
 SSZ005EBF44__LeeHelpMeSkill:
          db    '/LeeHelpMeSkill',0
 SSZ005EBF54____________________:
          db    '/이방범도와줘요스킬',0
 SSZ005EBF68_MrLee__OK__finished_Level_UP____:
          db    'MrLee: OK! finished Level UP /(-_-)/ ',0
          Align    4
 SSZ005EBF90__LeeWhereIs:
          db    '/LeeWhereIs',0
 SSZ005EBF9C________________:
          db    '/이방범순찰갔네',0
 SSZ005EBFAC_MrLee__Try_again_Quest_:
          db    'MrLee: Try again Quest~',0
 SSZ005EBFC4_MrLee__Clear_90th_Quest__:
          db    'MrLee: Clear 90th Quest ~',0
          Align    4
 SSZ005EBFE0_MrLee__Clear_80_2th_Quest__:
          db    'MrLee: Clear 80_2th Quest ~',0
 SSZ005EBFFC_MrLee__Clear_90_2th_Quest__:
          db    'MrLee: Clear 90_2th Quest ~',0
 SSZ005EC018_MrLee__Clear_85th_Quest__:
          db    'MrLee: Clear 85th Quest ~',0
          Align    4
 SSZ005EC034_MrLee__Clear_80th_Quest__:
          db    'MrLee: Clear 80th Quest ~',0
          Align    4
 SSZ005EC050_MrLee__Clear_70th_Quest__:
          db    'MrLee: Clear 70th Quest ~',0
          Align    4
 SSZ005EC06C_MrLee__Clear_55th_Quest__:
          db    'MrLee: Clear 55th Quest ~',0
          Align    4
 SSZ005EC088_MrLee__Clear_30th_Quest__:
          db    'MrLee: Clear 30th Quest ~',0
          Align    4
 SSZ005EC0A4__LeeResetQuest:
          db    '/LeeResetQuest',0
          Align    4
 SSZ005EC0B4__________________:
          db    '/이방범레벨퀘스트',0
          Align    4
 SSZ005EC0C8_MrLee_Retry_change_Job_Quest__:
          db    'MrLee:Retry change Job Quest~ ',0
          Align    4
 SSZ005EC0E8__Lee3thRankUp:
          db    '/Lee3thRankUp',0
          Align    4
 SSZ005EC0F8________3________:
          db    '/이방범3차퀘스트',0
          Align    4
 SSZ005EC10C__Lee4thRankUp:
          db    '/Lee4thRankUp',0
          Align    4
 SSZ005EC11C________4________:
          db    '/이방범4차퀘스트',0
          Align    4
 SSZ005EC130__________________________:
          db    '임군:초기화해주는 센스!! ',0
          Align    4
 SSZ005EC14C________________:
          db    '/임군초보퀘스트',0
 SSZ005EC15C_________________________________:
          db    '임군:머 그까이것 그냥 대충 해주지.. !! ',0
 SSZ005EC184______100______:
          db    '/임군100퀘스트',0
          Align    4
 SSZ005EC194__s__s:
          db    '%s %s',0
          Align    4
 SSZ005EC19C__T_T_________________________:
          db    'T.T 흑흑 난 이제  틀렸어 ~~~',0
          Align    4
 SSZ005EC1BC___________:
          db    '/날린다뇨!',0
          Align    4
 SSZ005EC1C8__________________:
          db    '/마군오오오오에요',0
 
Last edited:
Newbie Spellweaver
Joined
May 21, 2010
Messages
51
Reaction score
7
I really enjoy reading your posts bobsobol you explain an incredible way, I always added a. dll directly by adding the entry point, after starting the operation, i demand free memory, add the calls correctly etc. Finally, you explained in an easier way to show how to give the function. dll, very good
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
Thank you Exellsior, both for caring to read, and for reminding me of this guide so I can add bits I've decided are easier along the way and fix my awful spellink. :eek:tt1:
 
Back
Top