Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client #14

Merged
merged 78 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9a97bef
Moved stuff around
kaczy93 Jun 9, 2023
ac41dda
Extra assert during LoadBlock
kaczy93 Jun 10, 2023
0789fcb
wip
kaczy93 Jun 16, 2023
5dea041
[Client] fix OnBlockPacket
kaczy93 Jul 21, 2023
b4a057a
[Client] Fix resizing block cache
kaczy93 Jul 21, 2023
225afc5
Fix compressed and large packets handling
kaczy93 Jul 21, 2023
c9451fb
Beginning of CentrED#
kaczy93 Jul 21, 2023
f549c05
Fix depth for UI
kaczy93 Jul 25, 2023
59d9a68
Optimal packets compression
kaczy93 Jul 25, 2023
37e86c0
Embedded server
kaczy93 Jul 25, 2023
2e49fdb
Better LoadBlocks + allowed cache resize
kaczy93 Jul 25, 2023
1ba74cc
Reworked StaticBlock tiles handling + slight optimizations
kaczy93 Jul 27, 2023
a72cf93
better packet logging
kaczy93 Aug 1, 2023
5b95e18
wip
kaczy93 Aug 2, 2023
0e0a2df
Updated renderer
kaczy93 Aug 2, 2023
73e45f6
debug ui
kaczy93 Aug 3, 2023
756d450
register land packet + noop on no activity + fixed loading blocks
kaczy93 Aug 3, 2023
29e984b
update lastActivity on flush
kaczy93 Aug 3, 2023
fb2f3a2
Rework camera
kaczy93 Aug 3, 2023
71a170b
Hues support
kaczy93 Aug 7, 2023
54ac475
client landscape packet handlers
kaczy93 Aug 7, 2023
ac2a6df
Removed shadowRenderer leftovers
kaczy93 Aug 7, 2023
3f22ff6
Let server manage client lastpos
kaczy93 Aug 7, 2023
3cce7ad
Bring back old billboard rendering
kaczy93 Aug 7, 2023
c88a2b3
Mouse selection + some fixes
kaczy93 Aug 9, 2023
1210aa7
Resizable window
kaczy93 Aug 9, 2023
a7930ae
No inheritance for tiles and blocks
kaczy93 Aug 17, 2023
ced5a93
Made client changes work + aligned server
kaczy93 Aug 18, 2023
c2a3124
WIP, unified tiledata with classicuo struct, Works on CentrED UI of s…
kaczy93 Aug 19, 2023
1abb0b5
Start/Stop local server actually works
kaczy93 Aug 19, 2023
6eca824
LandTiles selection, basic tools, better tiles preparation
kaczy93 Aug 24, 2023
2ebd5dd
TileSelection tool
kaczy93 Aug 24, 2023
94658d4
Preload art, refactor, scrolling tiles with arrows
kaczy93 Aug 26, 2023
24221dd
Replaced Tiles tabBar with checkbox
kaczy93 Aug 26, 2023
ffffaf3
Hues window, real art bounds, better info tool, pointClamp sampler fo…
kaczy93 Aug 26, 2023
aa24fc7
Small fixes
kaczy93 Aug 27, 2023
a09b09f
Fix tiles filtering
kaczy93 Aug 27, 2023
711084f
Beginning of hues manager
kaczy93 Aug 28, 2023
be37f25
Small improfement for radarmap init
kaczy93 Aug 28, 2023
f8ebac5
Hues filtering
kaczy93 Aug 28, 2023
904b307
Small clienup of landRenderInfo
kaczy93 Aug 28, 2023
a24ad46
Draw UI on Draw phase to get rid of unresponsive UI
kaczy93 Aug 29, 2023
620c246
Optimise the rendering
kaczy93 Aug 29, 2023
b351f3d
FPS and resolution in debug window
kaczy93 Aug 30, 2023
d8d0f81
fix selection
kaczy93 Aug 30, 2023
d74022c
fix info tool
kaczy93 Aug 30, 2023
8407bdc
preload texmap
kaczy93 Aug 30, 2023
50008f0
MapRenderer cleanup
kaczy93 Aug 30, 2023
a87cccc
Static HuesManager instance, cleanup in tools,
kaczy93 Aug 30, 2023
492f282
MapManager reset function
kaczy93 Aug 30, 2023
54efabd
New Tools interface, RemoveTool, disabled inputs when app is not active
kaczy93 Aug 30, 2023
1f3a6e2
Transparency as indicator for tile removal
kaczy93 Aug 30, 2023
b6af6ab
Fix map persistence
kaczy93 Sep 1, 2023
3a0cca2
Updated ElevateTool + beginning of DrawTool
kaczy93 Sep 1, 2023
f5d466c
Fix client on insert packet
kaczy93 Sep 1, 2023
cdcb0a3
InfoWindow, InfoTool=>SelectTool, Basic inheritance in tiles, working…
kaczy93 Sep 1, 2023
a9688a4
MoveTool, explicitly update static hue after change
kaczy93 Sep 1, 2023
5d3a5b7
Fix UpdateRadar
kaczy93 Sep 3, 2023
8dbd611
DrawTool for land
kaczy93 Sep 3, 2023
9ec406b
Elevate land kind of working
kaczy93 Sep 3, 2023
f5ef147
Basic crashlog
kaczy93 Sep 3, 2023
da83605
Basic config
kaczy93 Sep 3, 2023
b0ab6d3
Load only what's needed
kaczy93 Sep 3, 2023
7b5c00e
Don't preload all the graphics
kaczy93 Sep 3, 2023
56c0f3c
Fix solution for VisualStudio
kaczy93 Sep 4, 2023
64aa4a9
Merge remote-tracking branch 'origin/master' into client
kaczy93 Sep 4, 2023
c334be6
Added output to gitignore
kaczy93 Sep 4, 2023
02fd07b
Fix UOP support
kaczy93 Sep 4, 2023
6902d21
Fix: incorrect cache size when moving or zooming (#11)
Blade12629 Sep 5, 2023
71a5ebb
Fix default selected tile
kaczy93 Sep 5, 2023
53f2816
Background image for the application
kaczy93 Sep 5, 2023
2e4a0b6
Do not request invalid blocks
kaczy93 Sep 5, 2023
a2f67a2
Request more blocks than are in view range
kaczy93 Sep 5, 2023
32d6237
Prevent crash when creating password (#12)
Blade12629 Sep 7, 2023
596974e
Forgot the braces (#13)
Blade12629 Sep 7, 2023
bf8a7e3
Quit, Options placehoder, Server Sort tiles before sending to client,…
kaczy93 Sep 25, 2023
048774d
Merge branch 'master' into client
kaczy93 Oct 21, 2023
d40192c
Fix after merging master :)
kaczy93 Oct 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin/
obj/
output/
/packages/
riderModule.iml
/_ReSharper.Caches/
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "FNA"]
path = external/FNA
url = https://github.com/fna-xna/fna
[submodule "fna-libs"]
path = external/fna-libs
url = https://github.com/deccer/fna-libs
[submodule "ImGui"]
path = external/ImGui.NET
url = https://github.com/ImGuiNET/ImGui.NET
73 changes: 73 additions & 0 deletions CentrED/Camera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.Xna.Framework;

namespace CentrED;

public class Camera
{
// 1.0 is standard. Large zooms in, smaller zooms out.
public float Zoom = 1.0f;

// Camera rotation around the Z axis, in degrees
public float Rotation = 0;

public Rectangle ScreenSize;

private Matrix _mirrorX = Matrix.CreateReflection(new Plane(-1, 0, 0, 0));

private Vector3 _up = new(-1, -1, 0);

/* This takes the coordinates (x, y, z) and turns it into the screen point (x, y + z, z) */
private Matrix _oblique = new Matrix(
1, 0, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 1);

private Matrix _translation = Matrix.CreateTranslation(new Vector3(0, 128 * 4, 0));

public Vector3 Position = new(0, 0, 128 * 4);

//Look directly below camera
public Vector3 LookAt => new(Position.X, Position.Y, 0);

public Matrix world;
public Matrix view;
public Matrix proj;

public Matrix WorldViewProj { get; private set; }

public bool Moved;

public void Move(float xDelta, float yDelta) {
Position.X += xDelta;
Position.Y += yDelta;
Moved = true;
}

public void ZoomIn(float delta) {
Zoom += delta;
Moved = true;
}

public void Update()
{
//Tiles are in world coordinates
world = Matrix.Identity;

var up = Vector3.Transform(_up, Matrix.CreateRotationZ(MathHelper.ToRadians(Rotation)));

view = Matrix.CreateLookAt(Position, LookAt, up);

Matrix ortho = Matrix.CreateOrthographic(ScreenSize.Width, ScreenSize.Height, 0, 128 * 8);

Matrix scale = Matrix.CreateScale(Zoom, Zoom, 1f);

proj = _mirrorX * _oblique * _translation * ortho * scale;

Matrix.Multiply(ref world, ref view, out var worldView);
Matrix.Multiply(ref worldView, ref proj, out var worldViewProj);

WorldViewProj = worldViewProj;
Moved = false;
}
}
111 changes: 111 additions & 0 deletions CentrED/CentrED.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using CentrED.Client;
using CentrED.Server;
using Microsoft.Xna.Framework;

namespace CentrED;

public class CentrED {

static private AssemblyLoadContext _loadContext;
static private string? _rootDir;

static private Assembly? LoadFromResource(string resourceName)
{
Console.WriteLine($"Loading resource {resourceName}");

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
var name = $"{assembly.GetName().Name}.{resourceName}.dll";
if (name.StartsWith("System."))
continue;

using Stream? s = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{resourceName}.dll");

if (s == null || s.Length == 0)
continue;

return _loadContext.LoadFromStream(s);
}

return null;
}

static private Assembly? ResolveAssembly(AssemblyLoadContext loadContext, AssemblyName assemblyName)
{
Console.WriteLine($"Resolving assembly {assemblyName}");

if (loadContext != _loadContext)
{
throw new Exception("Mismatched load contexts!");
}

if (assemblyName == null || assemblyName.Name == null)
{
throw new Exception("Unable to load null assembly");
}

/* Wasn't in same directory. Try to load it as a resource. */
return LoadFromResource(assemblyName.Name);
}

static private IntPtr ResolveUnmanagedDll(Assembly assembly, string unmanagedDllName)
{
Console.WriteLine($"Loading unmanaged DLL {unmanagedDllName} for {assembly.GetName().Name}");

/* Try the correct native libs directory first */
string osDir = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
osDir = "x64";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
osDir = "osx";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
osDir = "lib64";
}

var libraryPath = Path.Combine(_rootDir, osDir, unmanagedDllName);

Console.WriteLine($"Resolved DLL to {libraryPath}");

if (File.Exists(libraryPath))
return NativeLibrary.Load(libraryPath);

return IntPtr.Zero;
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetDllDirectory(string lpPathName);

public static CEDServer? Server;
public static readonly CentrEDClient Client = new();

[STAThread]
public static void Main(string[] args)
{
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

_rootDir = AppContext.BaseDirectory;
Console.WriteLine($"Root Dir: {_rootDir}");

_loadContext = AssemblyLoadContext.Default;
_loadContext.ResolvingUnmanagedDll += ResolveUnmanagedDll;
_loadContext.Resolving += ResolveAssembly;

using Game g = new CentrEDGame();
try {
g.Run();
}
catch (Exception e) {
File.WriteAllText("Crash.log", e.ToString());
}
}
}
58 changes: 56 additions & 2 deletions CentrED/CentrED.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,67 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Platforms>x64</Platforms>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>

<EnableSingleFileAnalysis>true</EnableSingleFileAnalysis>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

<OutDir>../output</OutDir>
<PublishDir>../publish</PublishDir>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Client\Client.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Client\Client.csproj" />
<ProjectReference Include="..\Server\Server.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\external\FNA\FNA.Core.csproj" />
<ProjectReference Include="..\external\ImGui.NET\src\ImGui.NET\ImGui.NET.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="..\external\ImGui.NET\deps\cimgui\win-x64\cimgui.dll" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Renderer\Effects\Shaders\*.fxc" />
</ItemGroup>

<ItemGroup>
<DataFiles_libs Include="..\external\fna-libs\**" />
<DataFiles_libs Include="..\lib\**" />
</ItemGroup>

<ItemGroup>
<Reference Include="ClassicUO.Assets">
<HintPath>..\lib\x64\ClassicUO.Assets.dll</HintPath>
</Reference>
<Reference Include="ClassicUO.IO">
<HintPath>..\lib\x64\ClassicUO.IO.dll</HintPath>
</Reference>
<Reference Include="ClassicUO.Utility">
<HintPath>..\lib\x64\ClassicUO.Utility.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="background.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="CopyExternalDeps_build" AfterTargets="Build">
<Copy SourceFiles="@(DataFiles_libs)" DestinationFiles="@(DataFiles_libs->'$(OutDir)/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>

<Target Name="CopyExternalDeps_publish" AfterTargets="Publish">
<Copy SourceFiles="@(DataFiles_libs)" DestinationFiles="@(DataFiles_libs->'$(PublishDir)/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>

</Project>
107 changes: 107 additions & 0 deletions CentrED/CentrEDGame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Runtime.InteropServices;
using CentrED.Client;
using CentrED.Map;
using CentrED.UI;
using ClassicUO.Assets;
using ClassicUO.Utility;
using ClassicUO.Utility.Logging;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CentrED;

internal class CentrEDGame : Game
{
private readonly GraphicsDeviceManager _gdm;

private CentrEDClient _centredClient;
private MapManager _mapManager;
private UIManager _uiManager;
private HuesManager _huesManager;

public CentrEDGame()
{
_gdm = new GraphicsDeviceManager(this)
{
IsFullScreen = false,
PreferredDepthStencilFormat = DepthFormat.Depth24
};

_gdm.PreparingDeviceSettings += (sender, e) => { e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; };

IsMouseVisible = true;
Window.AllowUserResizing = true;
Window.ClientSizeChanged += OnWindowResized;
}

protected override unsafe void Initialize()
{
if (_gdm.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef))
{
_gdm.GraphicsProfile = GraphicsProfile.HiDef;
}

_gdm.ApplyChanges();

NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, "x64", "zlib.dll"));
Log.Start(LogTypes.All);
var version = ClientVersionHelper.IsClientVersionValid(Config.ClientVersion, out var clientVersion);
UOFileManager.BasePath = Config.ClientPath;
UOFileManager.Version = clientVersion;
UOFileManager.IsUOPInstallation = clientVersion >= ClientVersion.CV_7000 && File.Exists(UOFileManager.GetUOFilePath("MainMisc.uop"));

if (!Task.WhenAll( new List<Task>
{
ArtLoader.Instance.Load(),
HuesLoader.Instance.Load(),
TileDataLoader.Instance.Load(),
TexmapsLoader.Instance.Load(),
}).Wait(TimeSpan.FromSeconds(10.0)))
Log.Panic("Loading files timeout.");

TextureAtlas.InitializeSharedTexture(_gdm.GraphicsDevice);
HuesManager.Initialize(_gdm.GraphicsDevice);
var background = Content.Load<Texture2D>("background");
_mapManager = new MapManager(_gdm.GraphicsDevice, background);
_uiManager = new UIManager(this, _gdm.GraphicsDevice, _mapManager);

base.Initialize();
}

protected override void LoadContent()
{
base.LoadContent();
}

protected override void UnloadContent()
{
base.UnloadContent();
}

protected override void Update(GameTime gameTime)
{
CentrED.Client.Update();
_uiManager.Update(gameTime, IsActive);
_mapManager.Update(gameTime, IsActive, !_uiManager.CapturingMouse, !_uiManager.CapturingKeyboard);

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
// if (!IsActive)
// return;

_mapManager.Draw();
_uiManager.Draw(gameTime);

base.Draw(gameTime);
}


private void OnWindowResized(object? sender, EventArgs e) {
GameWindow window = sender as GameWindow;
if (window != null)
_mapManager.OnWindowsResized(window);
}
}
Loading