Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

PT Source x64 + DX11 + SLikeNet + RmlUI

Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Hello friends, enjoy it. :8:

  • Removed all korean comments
  • Common bugs fixed
  • Source migrated to use x64 instead of x86
  • All warnings solved (source using /w3)
  • Using safer functions for memory operations
  • Using Precompiled Header
  • Game and Server in different source files (same project)
  • Removed unused code and files
  • Source files organized in folders
  • Graphics Rendering rewrote and refactored to use Directx 11
  • Network rewrote to use SLikeNet library (UDP + Messages Stream etc)
  • Removed transformed vertices from rendering
  • Some rendering stuffs using DirectxTK (fonts etc)
  • All textures converted to DDS
  • Source using vcpkg to manage dependencies (lua, slikenet, rmlui, dxtk)
  • Source integrated with RmlUI (html rendering library)
  • Source integrated with Github actions to validate commits automatically
  • Input subsytem using DXTK
  • Network messages handler (handle and process your network messages dynamically)
  • Cursor rendering using Windows API
  • Network remote procedure call system (call a function with custom arguments over network)
  • Network properties replication draft (you can check it in `feature/property-replication` branch)

bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


If you really want to use it, you must have a good knowledge on PT, programming and a knowledge on graphics.
Even though I believe that almost no one can use it, I hope you can use it for study and take some knowledge.

If you really want to understand how everything was made, you can check the commits from code, since I am sharing the source with the git files included.

Thanks for #Cainankenji and #slave (me) for this source.

Also you can thank me reading my last posts and giving a reaction on it.











Handle a Network Message

The first thing you need to do to handle a Network Message, it is define an unique OpCode as identifier for this Network Message. This OpCode will be used to identify the Network Message through Network Socket and know which data struct should be used, which functions will handle it etc.

You must define your OpCode in the NetworkDef.h file, inside of enum class OpCode.

Code:
enum class OpCode
{
    MyCustomNetworkMessage
};

Network Message Data

To define a Network Message Data, you must create a file hpp inside the directory shared/Network/Messages specific for that Message.

Code:
#pragma once

#include "Network/NetworkDef.h"
#include "Network/NetworkMessage.h"

namespace Network
{
    class MyData : public Message
    {
    public:
        bool Loaded = false;
        int Other = 0;

        void Serialize(MessageStream& Message) override
        {
            Message.Write(Loaded);
            Message.Write(Other);
        }

        void Deserialize(MessageStream& Message) override
        {
            Message.Read(Loaded);
            Message.Read(Other);
        }

        bool Validate() override
        {
            // Ensure message can be handled. If this function wasn't implemented, the network message will always be handled
            if (Loaded)
                return true;

            return false;
        }
    };
    DECLARE_NETWORK_MESSAGE(MyData, OpCode::MyCustomNetworkMessage)

Handle Network Message

Code:
namespace Network
{
    class Foo
    {
    public:
        void Handle(Connection* Connection, MyData& Data)
        {
        }

        void HandleWithoutData(Connection* Connection)
        {
            // Since we don't have a Message Data for that OpCode, we just need the Connection pointer to Handle it
        }
    };

    ServerMessagesHandler::ServerMessagesHandler()
    {
        Foo foo;
        HANDLE_NETWORK_MESSAGE(OpCode::MyCustomNetworkMessage, ValidationType::Authed, ProcessingType::InPlace, &Foo::Handle, foo);
        HANDLE_NETWORK_MESSAGE(OpCode::MyCustomNetworkMessageWithoutData, ValidationType::Authed, ProcessingType::InPlace, &Foo::HandleWithoutData, foo);
    }
}



Remote Procedure Call

Code:
namespace Network
{
    class NetworkContext;

    enum class RemoteProcedureCallType : char
    {
        Request,
        Response
    };

    DECLARE_NETWORK_RPC(TestRPC1, int, char, std::string)
    DECLARE_NETWORK_RPC(TestRPC2)
}

Handle a Remote Procedure Call

Code:
class AnyClass
{
public:
    HANDLE_NETWORK_RPC(TestRPC1, AnyClass::Test)
    int Test(int a, char b, std::string c)
    {
         return 30;
    }

    HANDLE_NETWORK_RPC(TestRPC2, AnyClass::Test2)
    void Test2()
    {
    }
};

Calling a Remote Procedure Call

Code:
std::function Response = [](int Value)
{
    LOG("Testing return data {0}", Value);
};

Connection->CallWithResponse<Network::TestRPC1>(Response, 30, 'a', std::string("Str"));

Code:
Connection->Call<Network::TestRPC2>();



Vcpkg

Code:
vcpkg install slikenet:x64-windows-static directxtk:x64-windows-static lua:x64-windows-static rmlui:x64-windows-static

Code:
vcpkg integrate install
 
Last edited:
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Default.hlsl

Code:
Texture2D DiffuseTexture : register(t0);

SamplerState DiffuseSampler : register(s0);


cbuffer CameraParameters : register(b0)
{
	float4x4 World;
    float4x4 ViewProjection;
}

cbuffer TextureBlendingParameters : register(b1)
{
	int Tex1ColorBlendOp;
	int Tex2ColorBlendOp;
	int Tex1AlphaBlendOp;
	int Tex2AlphaBlendOp;
}

struct VS_INPUT
{
    float4 Position : POSITION;
    float4 Color    : COLOR;
    float2 TexCoord : TEXCOORD;
};

struct PS_INPUT
{
    float4 Position : SV_POSITION;
	float4 Color    : COLOR;
	float2 TexCoord : TEXCOORD;
};

PS_INPUT VS(VS_INPUT Input)
{
	PS_INPUT Output = (PS_INPUT)0;

	// Fix for proper matrix calculations.
	Input.Position.w = 1.0f;

	Output.Position = mul(Input.Position, ViewProjection);
	Output.Color = Input.Color;
	Output.TexCoord = Input.TexCoord;

	return Output;
}

float4 PS(PS_INPUT Input) : SV_TARGET
{
	float4 TextureColor = DiffuseTexture.Sample(DiffuseSampler, Input.TexCoord);

	// Alpha Mask
	clip(TextureColor.a <= 0.5f ? -1 : 1);

	float4 FinalColor = TextureColor * Input.Color;

	return FinalColor;
}

UI.hlsl
Code:
Texture2D DiffuseTexture : register(t0);

SamplerState DiffuseSampler : register(s0);

cbuffer TextureParameters : register(b0)
{
	float4x4 Transform;
	float2 Translation;
	float2 ScreenSize;
}

struct VS_INPUT
{
    float4 Position : POSITION;
    float4 Color    : COLOR;
    float2 TexCoord : TEXCOORD;
};

struct PS_INPUT
{
    float4 Position : SV_POSITION;
	float4 Color    : COLOR;
	float2 TexCoord : TEXCOORD;
};

PS_INPUT VS(VS_INPUT Input)
{
	PS_INPUT Output = (PS_INPUT)0;

	Output.Position = mul(Input.Position, Transform);
	Output.Position.xy = (Output.Position.xy + Translation) * ScreenSize * 2; // from pixel to [0..2]
    Output.Position.xy -= 1; // to [-1..1]
    Output.Position.y *= -1; // because top left in texture space is bottom left in projective space
	Output.Position.zw = float2(0,1);
	Output.Color = Input.Color;
	Output.TexCoord = Input.TexCoord;

	return Output;
}

float4 PS(PS_INPUT Input) : SV_TARGET
{
	return DiffuseTexture.Sample(DiffuseSampler, Input.TexCoord) * Input.Color;
}
 
Newbie Spellweaver
Joined
Dec 23, 2013
Messages
56
Reaction score
2
this is cool Is it possible to make the graphics even more beautiful?
 
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Sure you can, but u will need a good knowledge on graphics rendering.



Ye, when I converted it didnt save many size, maybe u can compress textures even more..

Btw I've edited the original post including the download for client and server files. :):
 
Initiate Mage
Joined
Jul 28, 2020
Messages
3
Reaction score
0
Tankyou Igor.
I believe it will be very useful for those who want to study and learn about the content. Could you give me some private lessons on the subject. haha.Very good.
 
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Very nice release man! I pinned the thread.

Is it ready to go online or do we need to fix anything?

Not really, many things was removed from source bcoz we would rewrite in the future. It is a source that u surely can use it, but u would need to continue the work that we stopped. For this reason I mentioned you can use it for study and maybe implement what u want in a different source (you guys can check all source history using the git files, so many things u can study from a specific commit or branch).
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Can you tell us what was removed?

--- Edit

So, from what I can see, party system was removed. Maybe it has more stuff removed.
I was able to compile and will provide aditional info:


- Follow the steps and install vcpkg
In project configuration inside visual studio, change the installed directory according to where you installed vcpkg

bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


I did only for Shared project and it worked for the others. I also had to manually change game and gameserver.vcxproj because of some hardcoded paths to bocadecao's computer, so I changed those aswell.

Use the command to install the dependencies and compile it.

bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


When I have more time I will try to login.
 
Last edited:
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
I don't remember all systems removed, would be interesting to check commits history.

I did only for Shared project and it worked for the others. I also had to manually change game and gameserver.vcxproj because of some hardcoded paths to bocadecao's computer, so I changed those aswell.

Hmm really? Check if you are building the solution for x64 using Release / Debug mode. Should not have any hardcoded path because we use a Github action to build all projects and ensure they are building successfully (you can check the /.github/workflows/msbuild.yml file).

xiD1Ick - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums


To login you just need to execute the server and you will be able to connect with any account (any password), since we are not using database so far.
 

Attachments

You must be registered for see attachments list
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Yea, if you download the zip files you provided and open the vcxproj and search for "igorc" you'll find the hardcoded path that my visual studio was complaining about. =(

It is related to resource files of both projects, couldn't edit thhru visual studio options so I just used the good old notepad++ xD

Oh also there is no database, another good info.

Do you think it's possible to remove the need to create a window for the server? If I remember correctly, the WndProc is used by the socket, to send and receive messages. If the need for a window is gone and we find a way to remove every windows dependent function calls, we might be able to setup a docker environment for this and use cheaper host servers and get rid of annoying windows server. Just an idea. =D IDK if it is possible
 
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Ye, very possible. Our idea it was build server to Linux / Multiplatform (for this reason we are using libraries for networking and many windows functions were replaced to use C++ functions).

Also, the WndProc it is used to server logic loop (WM_UPDATE), but it is simpler to rewrite and refactor (I think FPT and UniquePT source are not using this WM_UPDATE anymore, Im not sure).
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Ye, very possible. Our idea it was build server to Linux / Multiplatform (for this reason we are using libraries for networking and many windows functions were replaced to use C++ functions).

Also, the WndProc it is used to server logic loop (WM_UPDATE), but it is simpler to rewrite and refactor (I think FPT and UniquePT source are not using this WM_UPDATE anymore, Im not sure).
Just for curiosity, how would you go to remove the WM_TIMER from WndProc? I don't develop C++ for years now, I have no clue xD

I think you meant WM_TIMER instead of WM_UPDATE?

If this was C# I'd be the happiest man in the world
 
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
Just for curiosity, how would you go to remove the WM_TIMER from WndProc? I don't develop C++ for years now, I have no clue xD

I think you meant WM_TIMER instead of WM_UPDATE?

If this was C# I'd be the happiest man in the world

Ooh sorry, ye, WM_TIMER. To remove this from WndProc we should implement a timer logic inside of an infinite loop on server side, very similar what happens on game side. Dno how exactly explain that, but you can read more about it here:

C++ with C# features :huh:
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
I work with C# for years now, can't even tell when I started. I'm way more used to C# than C++.. would take some time to get used to C++ xD Not that I can't learn it, but so much has changed in 10 years that I have a lot of things to catch up. =/

Anyways, really? Just a simple while(true) would do it? Sleeping for the right ammount of time and all that jazz... Seems pretty much simple. In C# I'd just use a Timer class, set the interval and sign a callback. Maybe need to deal with concurrency (trying to execute the update again while the other didnt finish yet and that stuff..) I dont really know how PT does it.

but pretty much all server magic happens in WM_TIMER I suppose. my least favorite packets 48470013 & 48470014 are mostly constructed there xD

One thing I can't understand is that crazy looping sleep they do with npc's for example.. you'll find some of them while you go trhu the functions WM_TIMER executes to update the monsters and npcs.

they have a fixed array of lets suppose "chrAutoPlayer[1000]" and outside the loop they use a counter: "srAutoPlayCount++".

Loop inside that array is only executed when srAutoPlayCount & 0x3F == 0 for example. Wtf is going on here, I don't know xD Math is not my strong subject. I know each call should be at 100ms since the SetTimer function, so I assume every +1 in srAutoPlayCount means 100ms. 0x3F = 63d. So, does it mean that this bitwise if is just a sleep for 63 * 100ms -> 6,3 seconds? Does not make any sense because packet 0x48470014 is sent something like each second, and it does have a similar logic to control the timing.

Could you explain that to me, and maybe others taht suck at math? xD

Game development is way crazier than the development we do at the fintech I work at lol
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
I also have the same error.
Can't see the cursor or even the textbox's for userid and password textures. Only the text I can see. Other textures are fine though. At least in login screen.
 
Junior Spellweaver
Joined
May 30, 2009
Messages
190
Reaction score
61
About srAutoPlayCount logic, you should check about bit masks and bit operations in C. I don't remember very well how this works on PT, but PT server works based on ticks and when you quote this srAutoPlayCount & 0x3F, it means every time when this variable reach to 63 the condition will be true and the code is executed (something like srAutoPlayCount mod 63). I know that isn't the better explanation for this, but sometimes PT is very confusing to understand.



It is just a warning, probably some asset that try to load some texture, but isn't used on anything.



I also have the same error.
Can't see the cursor or even the textbox's for userid and password textures. Only the text I can see. Other textures are fine though. At least in login screen.

Try it plz

bocadecao - PT Source x64 + DX11 + SLikeNet + RmlUI - RaGEZONE Forums
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Cursor is working fine now. The InputBox missing texture is "fine" then I suppose?

About that dataserver project, is it just a preparation for something that isn't removed from gameserver? I mean, does gameserver has what's necessary to support online players? (Assuming I already fixed the database and other stuff that you mentioned)

That srAutoPlayCount is really confusing. If it only executes each 63 additions to that variable, meaning each addition is 100ms, why didn't they just use sleep method or something?

--Editt

I tried to run the server with the provided server files and yet no NPC is visible. Anything to fix ?

Another bug I found for anyone willing to fix it: Something with directx window perspective is wrong. When you maximize the window, poop goes crazy. xD No clue how to fix it. Maybe somebody can =D
 
Last edited:
Back
Top