Register for your free account! | Forgot your password?

Go Back   elitepvpers > Silkroad Online > SRO Coding Corner
You last visited: Today at 05:40

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


[WIP] Get SRO Source Code - by re-writing it

Discussion on [WIP] Get SRO Source Code - by re-writing it within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
elite*gold: 100
Join Date: Apr 2008
Posts: 548
Received Thanks: 697
[WIP] Get SRO Source Code - by re-writing it

Hello beloved, greedy, dead, click-baited community,

MeGaMaX recently claimed the title "Leader of the reversing field"... you guessed it ... I'm here to get my title back!

Attempt to claim the title

I've been playing with this for a while now and I think its ready for you to play with it. This simple task required only 3500 lines of code and roughly 3 years of my life. Hopefully @ won't find it as "ussles" as my other release.

Silkroad has a dynamic type system which allows creating instances from classes by only knowing the classes name or type-descriptor. This is necessary for the UI-System to work. As you might have noticed, the class-names of the UI-elements is written in plaintext in the resinfo files.

In case you don't know C++ very well: Literally every C++ developer will kill you for implementing something like this.

The main thing in this release is object insertion. You now can insert new classes. Wow ... such great ... "ussles" ( @).

This allows creation of fully customized dialogs. Only the CIF-ones, not the CNIF-ones. But's its something to work with. I have included an example dialog created by me. Currently, only a few controls are supported.
  • CIFStatic
  • CIFButton

Wow ... only two controls ... so "ussles" ( @).

You can also mess with the process (see my CPSQuickStart release) and create completely new processes for e.h. customizing login, character selection or creation.

This project is explicit marked as "work in progress". It's not finished. It requires a lot of work. But you can help. By contributing your time. Your precious time you would usually spend on convincing people to do your stuff instead of learning new skills. Your precious time you would otherwise spend on making excuses on how you don't have time to learn and do things yourself. Stop complaining. Start doing.

The source code fairly clean. No scary assembly shit. No dirty hooks. Every method has a comment describing where to find it in the binary using a debugger. And the best thing is: I tried to mimic silkroads original source code.

I'm sorry to tell you that I'm still using Visual Studio 2005 & 2010. I've tried using Visual Studio 2017 and it's still broken. So no upgrade this year, sorry. But since I'm now using the proper allocator for the STL Joymax also used ... maybe it works in newer versions aswell. Maybe. No waranties whatsoever.

Lets be honest: None of you is going to contribute anyways. So instead of trying to motivate you to learn something, I'll better tell you how to create your own windows. Because thats what you're here for.

1. An interface definition file (Media/resinfo/ifflorian0.txt)

This file describes how your interface is going to look. The CIFFrame is necessary to make your window look less shitty and CIFNormalTile will render over the hole in the middle of the interface. Please note that every ID has to be unique for your window and the IDs 1,2,3 and probably more are reserved. So just start at 5 and you are safe. The names seem to be irrelevant.

To layout your window, use the "Rect"-option. The format is as follows: "x, y, width, height"

Code:
Interface Text


Section = Create,"0,0,0,0","0"
{
	GDR_FLORIAN0_LABEL:CIFStatic
	{
		ClientRect=RECT,"0,0,0,0"
		Color=COLOR,"255,214,171,46"
		DDJ=STRING,""
		FontColor=COLOR,"255,254,251,216"
		FontIndex=INTEGER,"2"
		HAlign=INTEGER,"1"
		ID=INTEGER,"10"
		Rect=RECT,"31,58,120,20"
		Style=INTEGER,"0"
		SubSection=STRING,""
		Text=STRING,""
		UV_LB=POINT,"0,1"
		UV_LT=POINT,"0,0"
		UV_RB=POINT,"1,1"
		UV_RT=POINT,"1,0"
		VAlign=INTEGER,"1"
	}
	GDR_FLORIAN0_BTN:CIFButton
	{
		ClientRect=RECT,"0,0,0,0"
		Color=COLOR,"255,73,102,178"
		DDJ=STRING,"interface\\system\\sys_button.ddj"
		FontColor=COLOR,"255,254,251,216"
		FontIndex=INTEGER,"0"
		HAlign=INTEGER,"1"
		ID=INTEGER,"11"
		Rect=RECT,"31,92,0,0"
		Style=INTEGER,"0"
		SubSection=STRING,""
		Text=STRING,"UIIT_STT_FLORIAN0_BTN"
		UV_LB=POINT,"0,1"
		UV_LT=POINT,"0,0"
		UV_RB=POINT,"1,1"
		UV_RT=POINT,"1,0"
		VAlign=INTEGER,"1"
	}
	GDR_FLORIAN0_LABEL_TIME:CIFStatic
	{
		ClientRect=RECT,"0,0,0,0"
		Color=COLOR,"255,214,171,46"
		DDJ=STRING,""
		FontColor=COLOR,"255,254,251,216"
		FontIndex=INTEGER,"1"
		HAlign=INTEGER,"1"
		ID=INTEGER,"13"
		Rect=RECT,"31,159,120,20"
		Style=INTEGER,"0"
		SubSection=STRING,""
		Text=STRING,""
		UV_LB=POINT,"0,1"
		UV_LT=POINT,"0,0"
		UV_RB=POINT,"1,1"
		UV_RT=POINT,"1,0"
		VAlign=INTEGER,"1"
	}
	GDR_FLORIAN0_FRAME:CIFFrame
	{
		ClientRect=RECT,"0,0,0,0"
		Color=COLOR,"255,108,205,164"
		DDJ=STRING,"interface\\inventory\\int_window_"
		FontColor=COLOR,"255,255,255,255"
		FontIndex=INTEGER,"0"
		HAlign=INTEGER,"2"
		ID=INTEGER,"6"
		Rect=RECT,"17,45,366,240"
		Style=INTEGER,"0"
		SubSection=STRING,""
		Text=STRING,""
		UV_LB=POINT,"0,1"
		UV_LT=POINT,"0,0"
		UV_RB=POINT,"1,1"
		UV_RT=POINT,"1,0"
		VAlign=INTEGER,"0"
	}
	GDR_FLORIAN0_BGTILE:CIFNormalTile
	{
		ClientRect=RECT,"0,0,0,0"
		Color=COLOR,"255,72,211,143"
		DDJ=STRING,"interface\\ifcommon\\bg_tile\\com_bg_tile_b.ddj"
		FontColor=COLOR,"255,255,255,255"
		FontIndex=INTEGER,"0"
		HAlign=INTEGER,"0"
		ID=INTEGER,"5"
		Rect=RECT,"22,50,355,230"
		Style=INTEGER,"0"
		SubSection=STRING,""
		Text=STRING,""
		UV_LB=POINT,"0,1"
		UV_LT=POINT,"0,0"
		UV_RB=POINT,"1,1"
		UV_RT=POINT,"1,0"
		VAlign=INTEGER,"0"
	}
}
2. Register your custom interface

For the normal ingame location, just use Media.pk2/resinfo/ginterface.txt. On other occasions like login or character select check out the ps*.txt files. As previously described, the ID has to be unique, in this case unique for the whole file.

Code:
GDR_FLORIAN0:CIFflorian0
{
	ClientRect=RECT,"0,0,0,0"
	Color=COLOR,"255,8,214,78"
	DDJ=STRING,"interface\\frame\\mframe_wnd_"
	FontColor=COLOR,"255,255,255,255"
	FontIndex=INTEGER,"0"
	HAlign=INTEGER,"0"
	ID=INTEGER,"1338"
	Rect=RECT,"300,200,400,300"
	Style=INTEGER,"0"
	SubSection=STRING,""
	Text=STRING,"UIIT_PAG_FLORIAN0"
	UV_LB=POINT,"0,1"
	UV_LT=POINT,"0,0"
	UV_RB=POINT,"1,1"
	UV_RT=POINT,"1,0"
	VAlign=INTEGER,"0"
}
3. Write some code

Phew. No code so far. Lets change that.

This is the absolute minimum code you can have. DYNCREATE is for allowing the class to be instanciated by Silkroad and MESSAGE_MAP is to handle messages (like Show/Hide/Click/etc).

Code:
#pragma once
#include "IFMainFrame.h"


class CIFflorian0 : public CIFMainFrame
{
	GFX_DECLARE_DYNCREATE(CIFflorian0)
	GFX_DECLARE_MESSAGE_MAP(CIFflorian0)

public:
	CIFflorian0(void);
	~CIFflorian0(void);

	bool OnCreate(long ln) override;
	
private:
	// no members
};
Code:
#include "IFflorian0.h"

#define GDR_FLORIAN0_BGTILE 5
#define GDR_FLORIAN0_FRAME 6
#define GDR_FLORIAN0_LABEL 10
#define GDR_FLORIAN0_BTN 11
#define GDR_FLORIAN0_LABEL_TIME 13

GFX_IMPLEMENT_DYNCREATE(CIFflorian0, CIFMainFrame)

GFX_BEGIN_MESSAGE_MAP(CIFflorian0, CIFMainFrame)
	// empty
GFX_END_MESSAGE_MAP()


CIFflorian0::CIFflorian0(void)
{
}


CIFflorian0::~CIFflorian0(void)
{
}

bool CIFflorian0::OnCreate(long ln)
{
	// Populate inherited members
	CIFMainFrame::OnCreate(ln);

	m_IRM.LoadFromFile("resinfo\\ifflorian0.txt");
	m_IRM.CreateInterfaceSection("Create", this);

	return true;
}

4. User interaction

Having a window is cool. But is pretty much "ussles" ( @) without any user interaction.

Add a method to handle your pressed button. Better make it private or protected to avoid some idiot (probably you) calling it out of context.

My code simply prints "Hello World" with a increasing counter to the label. The typename in the <> describes which type to expect to be returned. Make sure your type is correct. There is no parachute or safety net.

Code:
private:
	void On_BtnClick();
Code:
void CIFflorian0::On_BtnClick()
{
	static int i = 0;

	wchar_t buffer[80];
	swprintf(buffer, L"Hello World (%d)", i++);

	m_IRM.GetResObj<CIFStatic>(GDR_FLORIAN0_LABEL, 1)->SetText(buffer);
}
The last thing to do is tie the handler to the button. Thats what the message map is for.

Code:
GFX_BEGIN_MESSAGE_MAP(CIFflorian0, CIFMainFrame)
	ONG_COMMAND(GDR_FLORIAN0_BTN, &On_BtnClick)
GFX_END_MESSAGE_MAP()
Done. Now you have a cool button.

5. Background tasks

Your window can refresh it self on every redraw. Lets show that by implementing a simple clock.

This code takes the time and puts it into a string.

Code:
time_t rawtime;
struct tm * timeinfo;
wchar_t buffer[80];

time (&rawtime);
timeinfo = localtime(&rawtime);

wcsftime(buffer,sizeof(buffer),L"%d-%m-%Y %H:%M:%S",timeinfo);
To make that code run in the background, just implement OnUpdate

Code:
void OnUpdate() override;
Code:
void CIFflorian0::OnUpdate()
{
	// Code for getting the time
	time_t rawtime;
	struct tm * timeinfo;
	wchar_t buffer[80];

	time (&rawtime);
	timeinfo = localtime(&rawtime);

	wcsftime(buffer,sizeof(buffer),L"%d-%m-%Y %H:%M:%S",timeinfo);

	// Set label to the time string
	m_IRM.GetResObj<CIFStatic>(GDR_FLORIAN0_LABEL_TIME, 1)->SetText(buffer);
}
Thats all. Important note: Everything you do in here is executed syncronus once per frame. Everything you execute in here will lower your framerate and can cause lags. If you suffer from lags when your window is visible, check your code here.

Where is the download, bro?



Don't be a dick

I finally found a license that fits this community just perfectly.
Code:
# DON'T BE A DICK PUBLIC LICENSE

> Version 1.1, December 2016

> Copyright (C) 2016-2018 florian0

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document.

> DON'T BE A DICK PUBLIC LICENSE
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

1. Do whatever you like with the original work, just don't be a dick.

   Being a dick includes - but is not limited to - the following instances:

 1a. Outright copyright infringement - Don't just copy this and change the name.
 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.

2. If you become rich through modifications, related works/services, or supporting the original work,
share the love. Only a dick would make loads off this work and not buy the original work's
creator(s) a pint.

3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
That being said: Merry christmas <3



florian0 is offline  
Thanks
41 Users
Old 12/24/2018, 01:50   #2
 
elite*gold: 77
Join Date: Oct 2017
Posts: 94
Received Thanks: 14
LOL, you did released your history dude anyway it’s looks cool maybe it’ll help to the developers for who wants to do stuff like that, as the flo said don’t use it completely guys xD just keep it as example base hehe let’s contribute dyed community xDD


FutureLogic is offline  
Old 12/24/2018, 06:01   #3
 
elite*gold: 950
Join Date: Aug 2015
Posts: 1,730
Received Thanks: 968
wow, that is simply amazing.

No scary assembly ****. No dirty hooks.
I wonder who does that
B1Q is offline  
Old 12/24/2018, 11:08   #4
 
elite*gold: 0
Join Date: Mar 2007
Posts: 53
Received Thanks: 16
Quote:
Originally Posted by FutureLogic View Post
LOL, you did released your history dude anyway itís looks cool maybe itíll help to the developers for who wants to do stuff like that, as the flo said donít use it completely guys xD just keep it as example base hehe letís contribute dyed community xDD
Did you have a stroke?


-- well done, Flo!


dipointed is offline  
Thanks
1 User
Old 12/24/2018, 11:18   #5
 
elite*gold: 95
Join Date: May 2015
Posts: 451
Received Thanks: 415
Well done boy, and Merry Christmas
$WeGs is offline  
Old 12/24/2018, 12:42   #6
 
elite*gold: 0
Join Date: Sep 2017
Posts: 577
Received Thanks: 164
You got it back already.

Quote:
Originally Posted by florian0 View Post
click-baited community,
TRUE AF
#HB is offline  
Old 12/24/2018, 17:37   #7
 
elite*gold: 0
Join Date: Apr 2017
Posts: 578
Received Thanks: 154
good work
Zoro.Sro is offline  
Old 12/25/2018, 04:58   #8
 
elite*gold: 0
Join Date: Apr 2009
Posts: 2,141
Received Thanks: 2,368
holy ****, why you got so triggered by a random guy's message?
sarkoplata is offline  
Thanks
1 User
Old 12/26/2018, 02:12   #9
 
elite*gold: 0
Join Date: Nov 2013
Posts: 121
Received Thanks: 60
O wow, didnt expect someone going that far, well done mate.

p.s. havent been on scene for years
Artuuro_lv is offline  
Thanks
1 User
Old 12/26/2018, 11:00   #10

 
elite*gold: 437
Join Date: Feb 2011
Posts: 720
Received Thanks: 209
Respekt
InPanic Kev is offline  
Old 12/27/2018, 02:16   #11
 
elite*gold: 6
Join Date: Oct 2013
Posts: 1,134
Received Thanks: 613
wow dude, that's impressive

I am glad i just started using c++ in league script development might be helpful here as well.
Syloxx is offline  
Old 12/27/2018, 12:34   #12
 
elite*gold: 10
Join Date: Jan 2010
Posts: 47
Received Thanks: 223
Dude, this is really great work, mad respect!

I know this can be a pain in the ass. Usually you reverse huge C++ executables like Silkroad to get a basic understanding of certain parts of a program, not to rebuild the entire source.

Some time ago I literally had the same idea but with the GameServer's code.
I spent several year's reversing the binary just to get an understanding of how Silkroad works in depth. How it does communicate with other modules, how the network processing works, etc.

That being said, I did get an understanding of it. I learned how the internal process and thread management works, how it makes use of Microsoft's IOCP and how it does implement it.
The idea was to rebuild parts of the C++ code and then use this knowledge and the C++ pseudo code to build an almost perfect working emulator.
An emulator with which I would climb the "legend of silkroad" again, starting with legend 1. I always thought such a project could revive the community.

Some examples of what I've converted to pseudo code. Its not complete, not much and not all I have. I just started to create some pseudo code, my IDA database would allow much more though!




Sadly, due to my real life job and the sheer endless task of rebuilding even just parts of the executable, this project was set to fail before it even started.
Finally I gave up on it and pretty much left silkroad. It was a fun experience though and it definitely boosted my assembly skills.

Nowadays I think the emulator was a stupid idea, the community wouldn't appreciate such a project and it's definitely dead!

Also great to see that I'm not alone with such crazy ideas
Stratti is offline  
Thanks
8 Users
Old 01/08/2019, 16:38   #13
 
elite*gold: 0
Join Date: Jan 2011
Posts: 121
Received Thanks: 38
Not exactly, I guess.
CPSCharacterSelect.cpp , .h missing.
paradise1992 is offline  
Old 01/12/2019, 13:14   #14
 
elite*gold: 0
Join Date: Jan 2011
Posts: 121
Received Thanks: 38
Quote:
Originally Posted by paradise1992 View Post
Not exactly, I guess.
CPSCharacterSelect.cpp , .h missing.
DC
paradise1992 is offline  
Old 01/12/2019, 15:28   #15
 
elite*gold: 100
Join Date: Apr 2008
Posts: 548
Received Thanks: 697
Quote:
Originally Posted by paradise1992 View Post
DC
0046EEDD is inside std::wstring:: operator=. It looks like you're not using VC80 / Visual Studio 2005 to compile.


florian0 is offline  
Reply



« vSro login character list not updating client | [PK2 TOOL] BMS Model converter »

Similar Threads
[Release/WIP]EP6 Source code
04/15/2018 - Shaiya PServer Guides & Releases - 34 Replies
Hi guys, First of all, I want to say that this release is not recommended for public servers yet. Shortly ago I changed my server to ep6 using shen1l's pet.dll, the server crashed every day, after checking the dump files I discovered that the problem was in pet.dll, but without the source code it would be harder to find the cause of the problem. So I decided to start a project and release the source code for everyone, so that everyone can solve their problems more easily, and also so that...
[Source] Fix the old exp bar - by writing code!
04/23/2017 - SRO PServer Guides & Releases - 14 Replies
Hello beloved, dead community, its time for another release. Its more of a proof of concept and I hope it might inspire people to continue working on it. You don't need the source to accomplish cool things. Just write your own source. http://i.epvpimg.com/d7hJbab.png Ye, its super ugly looking. I choose to be a coder, not a designer. I'd be happy, if someone supplies me a proper version of the 2dt and ddj files so I can update this embarrassing screenshot. Anyway. It allows you to...
[C++ Source] My Free Farm Bot [WIP]
06/28/2011 - Browsergames - 0 Replies
I decided to release this on here as i have no more use for it and no intention to continue the project. I am releasing 2 projects: One basic library for mff called libmff(although it is not really a library) there is an example on how to use it in the package. And a helper with a fancy gui. Note that there is almost no error checking on the helper and that it crashes if you for example forget to select a product. You need libcurl and boost for both and GWEN(the gui toolkit by garry) for...



All times are GMT +1. The time now is 05:40.


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

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