From 040e6825fc3889fdb41ffa1554b74c2cf5857a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Mon, 20 Dec 2021 00:23:38 +0100 Subject: [PATCH] Initial commit --- .gitignore | 679 ++++++++++++++++++ .gitmodules | 6 + .../Client/BaseNostaleClient.cs | 49 ++ Core/NosSmooth.Core/Client/INostaleClient.cs | 65 ++ .../Commands/CommandProcessor.cs | 50 ++ Core/NosSmooth.Core/Commands/ICommand.cs | 6 + .../Commands/ICommandHandler.cs | 13 + Core/NosSmooth.Core/Commands/WalkCommand.cs | 9 + .../Errors/CommandHandlerNotFound.cs | 11 + .../Extensions/ServiceCollectionExtensions.cs | 145 ++++ Core/NosSmooth.Core/NosSmooth.Core.csproj | 17 + Core/NosSmooth.Core/Packets/IPacketHandler.cs | 28 + .../Packets/IPacketResponder.cs | 28 + .../Packets/IPacketSerializer.cs | 12 + Core/NosSmooth.Core/Packets/PacketHandler.cs | 74 ++ .../Packets/PacketSerializer.cs | 43 ++ .../Packets/PacketSerializerProvider.cs | 42 ++ Core/NosSmooth.Core/RecordFix.cs | 4 + .../Events/GMJoinedMap.cs | 7 + .../NosSmooth.Extensions.csproj | 13 + Core/NosSmooth.Game/NosSmooth.Game.csproj | 10 + .../NosSmooth.Language.csproj | 10 + DllExport.bat | 509 +++++++++++++ .../CommandHandlers/WalkCommandHandler.cs | 12 + .../Extensions/ServiceCollectionExtensions.cs | 20 + .../NosSmooth.LocalClient.csproj | 19 + .../NostaleLocalClient.cs | 71 ++ Local/NosSmooth.LocalClient/NostaleWindow.cs | 6 + Local/NosSmooth.LocalCore/Character.cpp | 47 ++ Local/NosSmooth.LocalCore/Character.h | 26 + Local/NosSmooth.LocalCore/ModuleHook.cpp | 49 ++ Local/NosSmooth.LocalCore/ModuleHook.h | 19 + Local/NosSmooth.LocalCore/ModuleHook.ixx | 3 + Local/NosSmooth.LocalCore/Network.cpp | 40 ++ Local/NosSmooth.LocalCore/Network.h | 42 ++ .../NosSmooth.LocalCore/NetworkUnmanaged.cpp | 153 ++++ Local/NosSmooth.LocalCore/NetworkUnmanaged.h | 61 ++ .../NosSmooth.LocalCore.vcxproj | 195 +++++ .../NosSmooth.LocalCore.vcxproj.filters | 57 ++ Local/NosSmooth.LocalCore/NosSmoothCore.cpp | 33 + Local/NosSmooth.LocalCore/NosSmoothCore.h | 24 + Local/NosSmooth.LocalCore/NostaleString.h | 104 +++ Local/NosSmooth.LocalCore/packages.config | 4 + NosSmooth.sln | 195 +++++ .../EncryptionProvider.cs | 24 + Remote/NosSmooth.Cryptography/IDecryptor.cs | 6 + Remote/NosSmooth.Cryptography/IEncryptor.cs | 6 + .../NosSmooth.Cryptography.csproj | 9 + .../NosSmooth.Cryptography/WorldDecryptor.cs | 6 + .../NosSmooth.Cryptography/WorldEncryptor.cs | 6 + .../NosSmooth.RemoteClient.csproj | 52 ++ .../Properties/AssemblyInfo.cs | 35 + Samples/DamageCounter/App.xaml | 9 + Samples/DamageCounter/App.xaml.cs | 17 + Samples/DamageCounter/AssemblyInfo.cs | 10 + Samples/DamageCounter/DamageCounter.csproj | 10 + Samples/DamageCounter/MainWindow.xaml | 12 + Samples/DamageCounter/MainWindow.xaml.cs | 28 + .../PacketInterceptor/DummyNostaleClient.cs | 38 + .../PacketInterceptor.csproj | 15 + Samples/PacketInterceptor/Program.cs | 42 ++ Samples/PacketInterceptor/TestResponder.cs | 22 + Samples/PacketLogger/App.xaml | 9 + Samples/PacketLogger/App.xaml.cs | 17 + Samples/PacketLogger/AssemblyInfo.cs | 10 + Samples/PacketLogger/MainWindow.xaml | 12 + Samples/PacketLogger/MainWindow.xaml.cs | 28 + Samples/PacketLogger/PacketLogger.csproj | 18 + .../Packets/PacketLoggerResponder.cs | 27 + Samples/Test/DllMain.cs | 56 ++ Samples/Test/Test - Backup.csproj | 63 ++ Samples/Test/Test.csproj | 71 ++ Samples/testapp/Program.cs | 28 + Samples/testapp/testapp.csproj | 15 + libs/NosCore.Packets | 1 + libs/NosCore.Shared | 1 + 76 files changed, 3713 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Core/NosSmooth.Core/Client/BaseNostaleClient.cs create mode 100644 Core/NosSmooth.Core/Client/INostaleClient.cs create mode 100644 Core/NosSmooth.Core/Commands/CommandProcessor.cs create mode 100644 Core/NosSmooth.Core/Commands/ICommand.cs create mode 100644 Core/NosSmooth.Core/Commands/ICommandHandler.cs create mode 100644 Core/NosSmooth.Core/Commands/WalkCommand.cs create mode 100644 Core/NosSmooth.Core/Errors/CommandHandlerNotFound.cs create mode 100644 Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs create mode 100644 Core/NosSmooth.Core/NosSmooth.Core.csproj create mode 100644 Core/NosSmooth.Core/Packets/IPacketHandler.cs create mode 100644 Core/NosSmooth.Core/Packets/IPacketResponder.cs create mode 100644 Core/NosSmooth.Core/Packets/IPacketSerializer.cs create mode 100644 Core/NosSmooth.Core/Packets/PacketHandler.cs create mode 100644 Core/NosSmooth.Core/Packets/PacketSerializer.cs create mode 100644 Core/NosSmooth.Core/Packets/PacketSerializerProvider.cs create mode 100644 Core/NosSmooth.Core/RecordFix.cs create mode 100644 Core/NosSmooth.Extensions/Events/GMJoinedMap.cs create mode 100644 Core/NosSmooth.Extensions/NosSmooth.Extensions.csproj create mode 100644 Core/NosSmooth.Game/NosSmooth.Game.csproj create mode 100644 Core/NosSmooth.Language/NosSmooth.Language.csproj create mode 100644 DllExport.bat create mode 100644 Local/NosSmooth.LocalClient/CommandHandlers/WalkCommandHandler.cs create mode 100644 Local/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs create mode 100644 Local/NosSmooth.LocalClient/NosSmooth.LocalClient.csproj create mode 100644 Local/NosSmooth.LocalClient/NostaleLocalClient.cs create mode 100644 Local/NosSmooth.LocalClient/NostaleWindow.cs create mode 100644 Local/NosSmooth.LocalCore/Character.cpp create mode 100644 Local/NosSmooth.LocalCore/Character.h create mode 100644 Local/NosSmooth.LocalCore/ModuleHook.cpp create mode 100644 Local/NosSmooth.LocalCore/ModuleHook.h create mode 100644 Local/NosSmooth.LocalCore/ModuleHook.ixx create mode 100644 Local/NosSmooth.LocalCore/Network.cpp create mode 100644 Local/NosSmooth.LocalCore/Network.h create mode 100644 Local/NosSmooth.LocalCore/NetworkUnmanaged.cpp create mode 100644 Local/NosSmooth.LocalCore/NetworkUnmanaged.h create mode 100644 Local/NosSmooth.LocalCore/NosSmooth.LocalCore.vcxproj create mode 100644 Local/NosSmooth.LocalCore/NosSmooth.LocalCore.vcxproj.filters create mode 100644 Local/NosSmooth.LocalCore/NosSmoothCore.cpp create mode 100644 Local/NosSmooth.LocalCore/NosSmoothCore.h create mode 100644 Local/NosSmooth.LocalCore/NostaleString.h create mode 100644 Local/NosSmooth.LocalCore/packages.config create mode 100644 NosSmooth.sln create mode 100644 Remote/NosSmooth.Cryptography/EncryptionProvider.cs create mode 100644 Remote/NosSmooth.Cryptography/IDecryptor.cs create mode 100644 Remote/NosSmooth.Cryptography/IEncryptor.cs create mode 100644 Remote/NosSmooth.Cryptography/NosSmooth.Cryptography.csproj create mode 100644 Remote/NosSmooth.Cryptography/WorldDecryptor.cs create mode 100644 Remote/NosSmooth.Cryptography/WorldEncryptor.cs create mode 100644 Remote/NosSmooth.RemoteClient/NosSmooth.RemoteClient.csproj create mode 100644 Remote/NosSmooth.RemoteClient/Properties/AssemblyInfo.cs create mode 100644 Samples/DamageCounter/App.xaml create mode 100644 Samples/DamageCounter/App.xaml.cs create mode 100644 Samples/DamageCounter/AssemblyInfo.cs create mode 100644 Samples/DamageCounter/DamageCounter.csproj create mode 100644 Samples/DamageCounter/MainWindow.xaml create mode 100644 Samples/DamageCounter/MainWindow.xaml.cs create mode 100644 Samples/PacketInterceptor/DummyNostaleClient.cs create mode 100644 Samples/PacketInterceptor/PacketInterceptor.csproj create mode 100644 Samples/PacketInterceptor/Program.cs create mode 100644 Samples/PacketInterceptor/TestResponder.cs create mode 100644 Samples/PacketLogger/App.xaml create mode 100644 Samples/PacketLogger/App.xaml.cs create mode 100644 Samples/PacketLogger/AssemblyInfo.cs create mode 100644 Samples/PacketLogger/MainWindow.xaml create mode 100644 Samples/PacketLogger/MainWindow.xaml.cs create mode 100644 Samples/PacketLogger/PacketLogger.csproj create mode 100644 Samples/PacketLogger/Packets/PacketLoggerResponder.cs create mode 100644 Samples/Test/DllMain.cs create mode 100644 Samples/Test/Test - Backup.csproj create mode 100644 Samples/Test/Test.csproj create mode 100644 Samples/testapp/Program.cs create mode 100644 Samples/testapp/testapp.csproj create mode 160000 libs/NosCore.Packets create mode 160000 libs/NosCore.Shared diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3f5c28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,679 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/csharp,c++,visualstudio,rider +# Edit at https://www.toptal.com/developers/gitignore?templates=csharp,c++,visualstudio,rider + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.iobj +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Nuget personal access tokens and Credentials +# nuget.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +.idea/ +*.sln.iml + +### Rider ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### VisualStudio ### + +# User-specific files + +# User-specific files (MonoDevelop/Xamarin Studio) + +# Mono auto generated files + +# Build results + +# Visual Studio 2015/2017 cache/options directory +# Uncomment if you have tasks that create the project's static files in wwwroot + +# Visual Studio 2017 auto generated files + +# MSTest test Results + +# NUnit + +# Build Results of an ATL Project + +# Benchmark Results + +# .NET Core + +# ASP.NET Scaffolding + +# StyleCop + +# Files built by Visual Studio + +# Chutzpah Test files + +# Visual C++ cache files + +# Visual Studio profiler + +# Visual Studio Trace Files + +# TFS 2012 Local Workspace + +# Guidance Automation Toolkit + +# ReSharper is a .NET coding add-in + +# TeamCity is a build add-in + +# DotCover is a Code Coverage Tool + +# AxoCover is a Code Coverage Tool + +# Coverlet is a free, cross platform Code Coverage Tool + +# Visual Studio code coverage results + +# NCrunch + +# MightyMoose + +# Web workbench (sass) + +# Installshield output folder + +# DocProject is a documentation generator add-in + +# Click-Once directory + +# Publish Web Output +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted + +# NuGet Packages +# NuGet Symbol Packages +# The packages folder can be ignored because of Package Restore +# except build/, which is used as an MSBuild target. +# Uncomment if necessary however generally it will be regenerated when needed +# NuGet v3's project.json files produces more ignorable files + +# Nuget personal access tokens and Credentials +# nuget.config + +# Microsoft Azure Build Output + +# Microsoft Azure Emulator + +# Windows Store app package directories and files + +# Visual Studio cache files +# files ending in .cache can be ignored +# but keep track of directories ending in .cache + +# Others + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) + +# RIA/Silverlight projects + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) + +# SQL Server files + +# Business Intelligence projects + +# Microsoft Fakes + +# GhostDoc plugin setting file + +# Node.js Tools for Visual Studio + +# Visual Studio 6 build log + +# Visual Studio 6 workspace options file + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) + +# Visual Studio LightSwitch build output + +# Paket dependency manager + +# FAKE - F# Make + +# CodeRush personal settings + +# Python Tools for Visual Studio (PTVS) + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio + +# Telerik's JustMock configuration file + +# BizTalk build output + +# OpenCover UI analysis results + +# Azure Stream Analytics local run output + +# MSBuild Binary and Structured Log + +# NVidia Nsight GPU debugger configuration file + +# MFractors (Xamarin productivity tool) working folder + +# Local History for Visual Studio + +# BeatPulse healthcheck temp database + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 + +# Ionide (cross platform F# VS Code tools) working folder + +# Fody - auto-generated XML schema + +# VS Code files for those working on multiple tools + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs + +# JetBrains Rider + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/csharp,c++,visualstudio,rider diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..560e288 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "libs/NosCore.Packets"] + path = libs/NosCore.Packets + url = https://github.com/Rutherther/NosCore.Packets.git +[submodule "libs/NosCore.Shared"] + path = libs/NosCore.Shared + url = https://github.com/Rutherther/NosCore.Shared.git diff --git a/Core/NosSmooth.Core/Client/BaseNostaleClient.cs b/Core/NosSmooth.Core/Client/BaseNostaleClient.cs new file mode 100644 index 0000000..288da73 --- /dev/null +++ b/Core/NosSmooth.Core/Client/BaseNostaleClient.cs @@ -0,0 +1,49 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using NosCore.Packets; +using NosCore.Packets.Interfaces; +using NosCore.Packets.ServerPackets.Event; +using NosSmooth.Core.Commands; +using NosSmooth.Core.Packets; +using Remora.Results; + +namespace NosSmooth.Core.Client; + +public abstract class BaseNostaleClient : INostaleClient +{ + protected readonly CommandProcessor _commandProcessor; + protected readonly IPacketSerializer _packetSerializer; + + protected BaseNostaleClient(CommandProcessor commandProcessor, IPacketSerializer packetSerializer) + { + _commandProcessor = commandProcessor; + _packetSerializer = packetSerializer; + } + + public abstract Task RunAsync(CancellationToken stopRequested = default); + + public virtual Task SendPacketAsync(IPacket packet, CancellationToken ct = default) + { + var serialized = _packetSerializer.Serialize(packet); + + return serialized.IsSuccess + ? SendPacketAsync(serialized.Entity, ct) + : Task.FromResult(Result.FromError(serialized)); + } + + public abstract Task SendPacketAsync(string packetString, CancellationToken ct = default); + public abstract Task ReceivePacketAsync(string packetString, CancellationToken ct = default); + + public virtual Task ReceivePacketAsync(IPacket packet, CancellationToken ct = default) + { + var serialized = _packetSerializer.Serialize(packet); + + return serialized.IsSuccess + ? ReceivePacketAsync(serialized.Entity, ct) + : Task.FromResult(Result.FromError(serialized)); + } + + public Task SendCommandAsync(ICommand command, CancellationToken ct = default) => + _commandProcessor.ProcessCommand(command, ct); +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Client/INostaleClient.cs b/Core/NosSmooth.Core/Client/INostaleClient.cs new file mode 100644 index 0000000..7f6f416 --- /dev/null +++ b/Core/NosSmooth.Core/Client/INostaleClient.cs @@ -0,0 +1,65 @@ +using System.Threading; +using System.Threading.Tasks; +using NosCore.Packets.Interfaces; +using NosSmooth.Core.Commands; +using Remora.Results; + +namespace NosSmooth.Core.Client; + +/// +/// Class representing nostale client that may send and receive packets as well as process commands. +/// +public interface INostaleClient +{ + /// + /// Starts the client. + /// + /// A cancellation token for stopping the client. + /// The result that may or may not have succeeded. + public Task RunAsync(CancellationToken stopRequested = default); + + /// + /// Sends the given packet to the server. + /// + /// The packet to send. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task SendPacketAsync(IPacket packet, CancellationToken ct = default); + + /// + /// Sends the given raw packet string. + /// + /// The packed string to send in plain text. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task SendPacketAsync(string packetString, CancellationToken ct = default); + + /// + /// Receives the given raw packet string. + /// + /// The packet to receive in plain text. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task ReceivePacketAsync(string packetString, CancellationToken ct = default); + + /// + /// Receives the given packet. + /// + /// The packet to receive. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task ReceivePacketAsync(IPacket packet, CancellationToken ct = default); + + /// + /// Sends the given command to the client. + /// + /// + /// Commands can be used for doing complex operations like walking that require sending multiple packets + /// and/or calling some functions of the local client. + /// This method will not return until the command is finished or it failed. + /// + /// The command to send. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task SendCommandAsync(ICommand command, CancellationToken ct = default); +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Commands/CommandProcessor.cs b/Core/NosSmooth.Core/Commands/CommandProcessor.cs new file mode 100644 index 0000000..d12dd2f --- /dev/null +++ b/Core/NosSmooth.Core/Commands/CommandProcessor.cs @@ -0,0 +1,50 @@ +using System; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using NosSmooth.Core.Errors; +using Remora.Results; + +namespace NosSmooth.Core.Commands; + +public class CommandProcessor +{ + private readonly IServiceProvider _provider; + + public CommandProcessor(IServiceProvider provider) + { + _provider = provider; + } + + public Task ProcessCommand(ICommand command, CancellationToken ct = default) + { + var processMethod = GetType().GetMethod + ( + nameof(DispatchCommandHandler), + BindingFlags.NonPublic | BindingFlags.Instance + ); + + if (processMethod is null) + { + throw new InvalidOperationException("Could not find process command generic method in command processor."); + } + + var boundProcessMethod = processMethod.MakeGenericMethod(command.GetType()); + + return (Task)boundProcessMethod.Invoke(this, new object[] { command, ct })!; + } + + private Task DispatchCommandHandler(TCommand command, CancellationToken ct = default) + where TCommand : class, ICommand + { + using var scope = _provider.CreateScope(); + var commandHandler = scope.ServiceProvider.GetService>(); + if (commandHandler is null) + { + return Task.FromResult(Result.FromError(new CommandHandlerNotFound(command.GetType()))); + } + + return commandHandler.HandleCommand(command, ct); + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Commands/ICommand.cs b/Core/NosSmooth.Core/Commands/ICommand.cs new file mode 100644 index 0000000..482692d --- /dev/null +++ b/Core/NosSmooth.Core/Commands/ICommand.cs @@ -0,0 +1,6 @@ +namespace NosSmooth.Core.Commands; + +public interface ICommand +{ + +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Commands/ICommandHandler.cs b/Core/NosSmooth.Core/Commands/ICommandHandler.cs new file mode 100644 index 0000000..f87df94 --- /dev/null +++ b/Core/NosSmooth.Core/Commands/ICommandHandler.cs @@ -0,0 +1,13 @@ +using System.Threading; +using System.Threading.Tasks; +using Remora.Results; + +namespace NosSmooth.Core.Commands; + +public interface ICommandHandler {} + +public interface ICommandHandler : ICommandHandler + where TCommand : ICommand +{ + public Task HandleCommand(TCommand command, CancellationToken ct = default); +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Commands/WalkCommand.cs b/Core/NosSmooth.Core/Commands/WalkCommand.cs new file mode 100644 index 0000000..3e8f48e --- /dev/null +++ b/Core/NosSmooth.Core/Commands/WalkCommand.cs @@ -0,0 +1,9 @@ +namespace NosSmooth.Core.Commands; + +/// +/// Command that moves the player to the specified target position. +/// May be used only in world. +/// +/// The x coordinate of the target position to move to. +/// The y coordinate of the target position to move to. +public record WalkCommand(int TargetX, int TargetY) : ICommand; \ No newline at end of file diff --git a/Core/NosSmooth.Core/Errors/CommandHandlerNotFound.cs b/Core/NosSmooth.Core/Errors/CommandHandlerNotFound.cs new file mode 100644 index 0000000..9800f56 --- /dev/null +++ b/Core/NosSmooth.Core/Errors/CommandHandlerNotFound.cs @@ -0,0 +1,11 @@ +using System; +using Remora.Results; + +namespace NosSmooth.Core.Errors; + +/// +/// Represents an error that tells the user there is no handler for the specified command so it cannot be processed. +/// +/// The type of the command. +public record CommandHandlerNotFound(Type CommandType) : ResultError( + $"Could not process the command of type {CommandType.FullName}, because there is not a handler for it."); \ No newline at end of file diff --git a/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs b/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..39abf94 --- /dev/null +++ b/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,145 @@ +using System; +using System.Linq; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using NosCore.Packets; +using NosCore.Packets.Attributes; +using NosCore.Packets.Enumerations; +using NosCore.Packets.Interfaces; +using NosSmooth.Core.Client; +using NosSmooth.Core.Commands; +using NosSmooth.Core.Packets; + +namespace NosSmooth.Core.Extensions; + +public static class ServiceCollectionExtensions +{ + /// + /// Adds base packet and command handling for nostale client. + /// + /// The service collection to register the responder to. + /// Custom types of packets to serialize and deserialize. + /// The collection. + public static IServiceCollection AddNostaleCore(this IServiceCollection serviceCollection, + params Type[] additionalPacketTypes) + { + serviceCollection + .TryAddSingleton(); + + var clientPacketTypes = typeof(IPacket).Assembly.GetTypes() + .Where(p => (p.Namespace?.Contains("Client") ?? false) && p.GetInterfaces().Contains(typeof(IPacket)) && p.IsClass && !p.IsAbstract).ToList(); + var serverPacketTypes = typeof(IPacket).Assembly.GetTypes() + .Where(p => (p.Namespace?.Contains("Server") ?? false) && p.GetInterfaces().Contains(typeof(IPacket)) && p.IsClass && !p.IsAbstract).ToList(); + + if (additionalPacketTypes.Length != 0) + { + clientPacketTypes.AddRange(additionalPacketTypes); + } + + serviceCollection.AddSingleton(_ => + new PacketSerializerProvider(clientPacketTypes, serverPacketTypes)); + serviceCollection.AddSingleton(p => p.GetRequiredService().GetServerSerializer()); + + serviceCollection.AddSingleton(); + + return serviceCollection; + } + + /// + /// Adds the specified packet responder that will be called upon receiving the given event. + /// + /// The service collection to register the responder to. + /// The type of the responder. + /// Thrown if the type of the responder is incorrect. + /// The collection. + public static IServiceCollection AddPacketResponder( + this IServiceCollection serviceCollection) + where TPacketResponder : class, IPacketResponder + { + return serviceCollection.AddPacketResponder(typeof(TPacketResponder)); + } + + /// + /// Adds the specified packet responder that will be called upon receiving the given event. + /// + /// The service collection to register the responder to. + /// The type of the responder. + /// The collection. + /// Thrown if the type of the responder is incorrect. + public static IServiceCollection AddPacketResponder(this IServiceCollection serviceCollection, Type responderType) + { + if (responderType.GetInterfaces().Any(i => i == typeof(IEveryPacketResponder))) + { + return serviceCollection.AddScoped(typeof(IEveryPacketResponder), responderType); + } + + if (!responderType.GetInterfaces().Any( + i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketResponder<>) + )) + { + throw new ArgumentException( + $"{nameof(responderType)} should implement IPacketResponder.", + nameof(responderType)); + } + + var responderTypeInterfaces = responderType.GetInterfaces(); + var responderInterfaces = responderTypeInterfaces.Where + ( + r => r.IsGenericType && r.GetGenericTypeDefinition() == typeof(IPacketResponder<>) + ); + + foreach (var responderInterface in responderInterfaces) + { + serviceCollection.AddScoped(responderInterface, responderType); + } + + return serviceCollection; + } + + /// + /// Adds the specified command handler. + /// + /// The service collection to register the responder to. + /// The type of the command. + /// Thrown if the type of the responder is incorrect. + /// The collection. + public static IServiceCollection AddCommandHandler( + this IServiceCollection serviceCollection) + where TCommandHandler : class, ICommandHandler + { + return serviceCollection.AddCommandHandler(typeof(TCommandHandler)); + } + + /// + /// Adds the specified command handler. + /// + /// The service collection to register the responder to. + /// The type of the command handler. + /// The collection. + /// Thrown if the type of the responder is incorrect. + public static IServiceCollection AddCommandHandler(this IServiceCollection serviceCollection, Type commandHandlerType) + { + if (!commandHandlerType.GetInterfaces().Any( + i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler<>) + )) + { + throw new ArgumentException( + $"{nameof(commandHandlerType)} should implement ICommandHandler.", + nameof(commandHandlerType)); + } + + var handlerTypeInterfaces = commandHandlerType.GetInterfaces(); + var handlerInterfaces = handlerTypeInterfaces.Where + ( + r => r.IsGenericType && r.GetGenericTypeDefinition() == typeof(ICommandHandler<>) + ); + + foreach (var handlerInterface in handlerInterfaces) + { + serviceCollection.AddScoped(handlerInterface, commandHandlerType); + } + + return serviceCollection; + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/NosSmooth.Core.csproj b/Core/NosSmooth.Core/NosSmooth.Core.csproj new file mode 100644 index 0000000..eb756c8 --- /dev/null +++ b/Core/NosSmooth.Core/NosSmooth.Core.csproj @@ -0,0 +1,17 @@ + + + + enable + 10 + net6.0;netstandard2.0 + + + + + + + + + + + diff --git a/Core/NosSmooth.Core/Packets/IPacketHandler.cs b/Core/NosSmooth.Core/Packets/IPacketHandler.cs new file mode 100644 index 0000000..c6fa059 --- /dev/null +++ b/Core/NosSmooth.Core/Packets/IPacketHandler.cs @@ -0,0 +1,28 @@ +using System.Threading; +using System.Threading.Tasks; +using NosCore.Packets.Interfaces; +using Remora.Results; + +namespace NosSmooth.Core.Packets; + +/// +/// Calls registered responders for the packet that should be handled. +/// +public interface IPacketHandler +{ + /// + /// Calls a responder for the given packet. + /// + /// The packet. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task HandleReceivedPacketAsync(IPacket packet, CancellationToken ct = default); + + /// + /// Calls a responder for the given packet. + /// + /// The packet. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task HandleSentPacketAsync(IPacket packet, CancellationToken ct = default); +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Packets/IPacketResponder.cs b/Core/NosSmooth.Core/Packets/IPacketResponder.cs new file mode 100644 index 0000000..0b8cd0c --- /dev/null +++ b/Core/NosSmooth.Core/Packets/IPacketResponder.cs @@ -0,0 +1,28 @@ +using System.Threading; +using System.Threading.Tasks; +using NosCore.Packets.Interfaces; +using Remora.Results; + +namespace NosSmooth.Core.Packets; + +public interface IPacketResponder +{ +} + +public interface IPacketResponder : IPacketResponder + where TPacket : IPacket +{ + /// + /// Respond to the given packet. + /// + /// The packet to respond to. + /// The cancellation token for cancelling the operation. + /// + public Task Respond(TPacket packet, CancellationToken ct = default); +} + +public interface IEveryPacketResponder : IPacketResponder +{ + public Task Respond(TPacket packet, CancellationToken ct = default) + where TPacket : IPacket; +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Packets/IPacketSerializer.cs b/Core/NosSmooth.Core/Packets/IPacketSerializer.cs new file mode 100644 index 0000000..e4ddbc2 --- /dev/null +++ b/Core/NosSmooth.Core/Packets/IPacketSerializer.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; +using NosCore.Packets.Interfaces; +using Remora.Results; + +namespace NosSmooth.Core.Packets; + +public interface IPacketSerializer +{ + public Result Serialize(IPacket packet); + + public Result Deserialize(string packetString); +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Packets/PacketHandler.cs b/Core/NosSmooth.Core/Packets/PacketHandler.cs new file mode 100644 index 0000000..f8f530d --- /dev/null +++ b/Core/NosSmooth.Core/Packets/PacketHandler.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using NosCore.Packets.Interfaces; +using Remora.Results; + +namespace NosSmooth.Core.Packets; + +/// +public class PacketHandler : IPacketHandler +{ + private readonly IServiceProvider _provider; + + public PacketHandler(IServiceProvider provider) + { + _provider = provider; + } + + /// + public Task HandleReceivedPacketAsync(IPacket packet, CancellationToken ct) => HandlePacketAsync(packet, ct); + + /// + public Task HandleSentPacketAsync(IPacket packet, CancellationToken ct) => HandlePacketAsync(packet, ct); + + private Task HandlePacketAsync(IPacket packet, CancellationToken ct = default) + { + var processMethod = GetType().GetMethod + ( + nameof(DispatchResponder), + BindingFlags.NonPublic | BindingFlags.Instance + ); + + if (processMethod is null) + { + throw new InvalidOperationException("Could not find process command generic method in command processor."); + } + + var boundProcessMethod = processMethod.MakeGenericMethod(packet.GetType()); + return (Task)boundProcessMethod.Invoke(this, new object[] { packet, ct })!; + } + + private async Task DispatchResponder(TPacket packet, CancellationToken ct) + where TPacket : class, IPacket + { + using var scope = _provider.CreateScope(); + var packetResponders = scope.ServiceProvider.GetServices>(); + var genericPacketResponders = scope.ServiceProvider.GetServices(); + + var tasks = packetResponders.Select(responder => responder.Respond(packet, ct)).ToList(); + tasks.AddRange(genericPacketResponders.Select(responder => responder.Respond(packet, ct))); + + var results = await Task.WhenAll(tasks); + + var errors = new List(); + foreach (var result in results) + { + if (!result.IsSuccess) + { + errors.Add(result); + } + } + + return errors.Count switch + { + 0 => Result.FromSuccess(), + 1 => errors[0], + _ => new AggregateError(errors.Cast().ToList()) + }; + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Packets/PacketSerializer.cs b/Core/NosSmooth.Core/Packets/PacketSerializer.cs new file mode 100644 index 0000000..df17404 --- /dev/null +++ b/Core/NosSmooth.Core/Packets/PacketSerializer.cs @@ -0,0 +1,43 @@ +using System; +using System.Threading.Tasks; +using NosCore.Packets; +using NosCore.Packets.Interfaces; +using Remora.Results; + +namespace NosSmooth.Core.Packets; + +public class PacketSerializer : IPacketSerializer +{ + private readonly Serializer _serializer; + private readonly Deserializer _deserializer; + + public PacketSerializer(Serializer serializer, Deserializer deserializer) + { + _serializer = serializer; + _deserializer = deserializer; + } + + public Result Serialize(IPacket packet) + { + try + { + return _serializer.Serialize(packet); + } + catch (Exception e) + { + return e; + } + } + + public Result Deserialize(string packetString) + { + try + { + return Result.FromSuccess(_deserializer.Deserialize(packetString)); + } + catch (Exception e) + { + return e; + } + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/Packets/PacketSerializerProvider.cs b/Core/NosSmooth.Core/Packets/PacketSerializerProvider.cs new file mode 100644 index 0000000..f42f28e --- /dev/null +++ b/Core/NosSmooth.Core/Packets/PacketSerializerProvider.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using NosCore.Packets; + +namespace NosSmooth.Core.Packets; + +public class PacketSerializerProvider +{ + private readonly List _clientPacketTypes; + private readonly List _serverPacketTypes; + + private IPacketSerializer? _serverSerializer; + private IPacketSerializer? _clientSerializer; + + public PacketSerializerProvider(List clientPacketTypes, List serverPacketTypes) + { + _clientPacketTypes = clientPacketTypes; + _serverPacketTypes = serverPacketTypes; + } + + public IPacketSerializer GetServerSerializer() + { + if (_serverSerializer is null) + { + _serverSerializer = + new PacketSerializer(new Serializer(_serverPacketTypes), new Deserializer(_serverPacketTypes)); + } + + return _serverSerializer; + } + + public IPacketSerializer GetClientSerializer() + { + if (_clientSerializer is null) + { + _clientSerializer = + new PacketSerializer(new Serializer(_clientPacketTypes), new Deserializer(_clientPacketTypes)); + } + + return _clientSerializer; + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Core/RecordFix.cs b/Core/NosSmooth.Core/RecordFix.cs new file mode 100644 index 0000000..46aeec9 --- /dev/null +++ b/Core/NosSmooth.Core/RecordFix.cs @@ -0,0 +1,4 @@ +namespace System.Runtime.CompilerServices +{ + public class IsExternalInit { } +} \ No newline at end of file diff --git a/Core/NosSmooth.Extensions/Events/GMJoinedMap.cs b/Core/NosSmooth.Extensions/Events/GMJoinedMap.cs new file mode 100644 index 0000000..9c6c81a --- /dev/null +++ b/Core/NosSmooth.Extensions/Events/GMJoinedMap.cs @@ -0,0 +1,7 @@ +namespace NosSmooth.Extensions.Events +{ + public class GMJoinedMap + { + + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Extensions/NosSmooth.Extensions.csproj b/Core/NosSmooth.Extensions/NosSmooth.Extensions.csproj new file mode 100644 index 0000000..84b8ca8 --- /dev/null +++ b/Core/NosSmooth.Extensions/NosSmooth.Extensions.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Core/NosSmooth.Game/NosSmooth.Game.csproj b/Core/NosSmooth.Game/NosSmooth.Game.csproj new file mode 100644 index 0000000..76b9f93 --- /dev/null +++ b/Core/NosSmooth.Game/NosSmooth.Game.csproj @@ -0,0 +1,10 @@ + + + + enable + enable + 10 + net6.0;netstandard2.0 + + + diff --git a/Core/NosSmooth.Language/NosSmooth.Language.csproj b/Core/NosSmooth.Language/NosSmooth.Language.csproj new file mode 100644 index 0000000..76b9f93 --- /dev/null +++ b/Core/NosSmooth.Language/NosSmooth.Language.csproj @@ -0,0 +1,10 @@ + + + + enable + enable + 10 + net6.0;netstandard2.0 + + + diff --git a/DllExport.bat b/DllExport.bat new file mode 100644 index 0000000..c62293f --- /dev/null +++ b/DllExport.bat @@ -0,0 +1,509 @@ +@echo off +:: Copyright (c) 2016-2021 Denis Kuzmin [x-3F@outlook.com] github/3F +:: https://github.com/3F/DllExport +if "%~1"=="/?" goto bq +set "aa=%~dpnx0" +set ab=%* +set ac=%* +if defined ab ( +if defined __p_call ( +set ac=%ac:^^=^% +) else ( +set ab=%ab:^=^^% +) +) +set wMgrArgs=%ac% +set ad=%ab:!=^!% +setlocal enableDelayedExpansion +set "ae=^" +set "ad=!ad:%%=%%%%!" +set "ad=!ad:&=%%ae%%&!" +set "af=1.7.4" +set "wAction=Configure" +set "ag=DllExport" +set "ah=tools/net.r_eg.DllExport.Wizard.targets" +set "ai=packages" +set "aj=https://www.nuget.org/api/v2/package/" +set "ak=build_info.txt" +set "al=!aa!" +set "wRootPath=!cd!" +set /a wDxpOpt=0 +set "am=" +set "an=" +set "ao=" +set "ap=" +set "aq=" +set "ar=" +set "as=" +set "at=" +set "au=" +set "av=" +set /a aw=0 +if not defined ab ( +if defined wAction goto br +goto bq +) +call :bs bk !ad! bl +goto bt +:bq +echo. +@echo .NET DllExport v1.7.4.29858+c1cc52f +@echo Copyright (c) 2009-2015 Robert Giesecke +@echo Copyright (c) 2016-2021 Denis Kuzmin ^ github/3F +echo. +echo MIT License +@echo https://github.com/3F/DllExport +echo Based on hMSBuild, MvsSln, +GetNuTool: https://github.com/3F +echo. +@echo. +@echo Usage: DllExport [args to DllExport] [args to GetNuTool] [args to hMSBuild] +echo ------ +echo. +echo Arguments +echo --------- +echo -action {type} - Specified action for Wizard. Where {type}: +echo * Configure - To configure DllExport for specific projects. +echo * Update - To update pkg reference for already configured projects. +echo * Restore - To restore configured DllExport. +echo * Export - To export configured projects data. +echo * Recover - To re-configure projects via predefined/exported data. +echo * Unset - To unset all data from specified projects. +echo * Upgrade - Aggregates an Update action with additions for upgrading. +echo. +echo -sln-dir {path} - Path to directory with .sln files to be processed. +echo -sln-file {path} - Optional predefined .sln file to be processed. +echo -metalib {path} - Relative path to meta library. +echo -metacor {path} - Relative path to meta core library. +echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core. +echo -dxp-version {num} - Specific version of DllExport. Where {num}: +echo * Versions: 1.7.3 ... +echo * Keywords: +echo `actual` - Unspecified local/latest remote version; +echo ( Only if you know what you are doing ) +echo. +echo -msb {path} - Full path to specific msbuild. +echo -hMSBuild {args} - Access to hMSBuild tool (packed) https://github.com/3F/hMSBuild +echo -packages {path} - A common directory for packages. +echo -server {url} - Url for searching remote packages. +echo -proxy {cfg} - To use proxy. The format: [usr[:pwd]@]host[:port] +echo -pkg-link {uri} - Direct link to package from the source via specified URI. +echo -force - Aggressive behavior, e.g. like removing pkg when updating. +echo -no-mgr - Do not use %~nx0 for automatic restore the remote package. +echo -mgr-up - Updates %~nx0 to version from '-dxp-version'. +echo -wz-target {path} - Relative path to entrypoint wrapper of the main wizard. +echo -pe-exp-list {module} - To list all available exports from PE32/PE32+ module. +echo -eng - Try to use english language for all build messages. +echo -GetNuTool {args} - Access to GetNuTool (integrated) https://github.com/3F/GetNuTool +echo -debug - To show additional information. +echo -version - Displays version for which (together with) it was compiled. +echo -build-info - Displays actual build information from selected DllExport. +echo -help - Displays this help. Aliases: -help -h +echo. +echo Flags +echo ----- +echo __p_call - To use the call-type logic when invoking %~nx0 +echo. +echo Samples +echo ------- +echo DllExport -action Configure -force -pkg-link http://host/v1.7.3.nupkg +echo DllExport -action Restore -sln-file "Conari.sln" +echo DllExport -proxy guest:1234@10.0.2.15:7428 -action Configure +echo. +echo DllExport -mgr-up -dxp-version 1.7.3 +echo DllExport -action Upgrade -dxp-version 1.7.3 +echo. +echo DllExport -GetNuTool /p:ngpackages="Conari;regXwild" +echo DllExport -pe-exp-list bin\Debug\regXwild.dll +goto bu +:bt +set /a ax=0 +:bv +set ay=!bk[%ax%]! +if [!ay!]==[-help] ( goto bq ) else if [!ay!]==[-h] ( goto bq ) else if [!ay!]==[-?] ( goto bq ) +if [!ay!]==[-debug] ( +set am=1 +goto bw +) else if [!ay!]==[-action] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wAction=!v! +for %%g in (Restore, Configure, Update, Export, Recover, Unset, Upgrade, Default) do ( +if "!v!"=="%%g" goto bw +) +echo Unknown -action !v! +exit/B 1 +) else if [!ay!]==[-sln-dir] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wSlnDir=!v! +goto bw +) else if [!ay!]==[-sln-file] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wSlnFile=!v! +goto bw +) else if [!ay!]==[-metalib] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wMetaLib=!v! +goto bw +) else if [!ay!]==[-metacor] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wMetaCor=!v! +goto bw +) else if [!ay!]==[-dxp-target] ( set /a "ax+=1" & call :bx bk[!ax!] v +set wDxpTarget=!v! +goto bw +) else if [!ay!]==[-dxp-version] ( set /a "ax+=1" & call :bx bk[!ax!] v +set af=!v! +goto bw +) else if [!ay!]==[-msb] ( set /a "ax+=1" & call :bx bk[!ax!] v +set ao=!v! +goto bw +) else if [!ay!]==[-packages] ( set /a "ax+=1" & call :bx bk[!ax!] v +set ai=!v! +goto bw +) else if [!ay!]==[-server] ( set /a "ax+=1" & call :bx bk[!ax!] v +set aj=!v! +goto bw +) else if [!ay!]==[-proxy] ( set /a "ax+=1" & call :bx bk[!ax!] v +set at=!v! +set wProxy=!v! +goto bw +) else if [!ay!]==[-pkg-link] ( set /a "ax+=1" & call :bx bk[!ax!] v +set ap=!v! +set af=!ay! +goto bw +) else if [!ay!]==[-force] ( +set ar=1 +goto bw +) else if [!ay!]==[-no-mgr] ( +set /a wDxpOpt^|=1 +goto bw +) else if [!ay!]==[-mgr-up] ( +set as=1 +goto bw +) else if [!ay!]==[-wz-target] ( set /a "ax+=1" & call :bx bk[!ax!] v +set ah=!v! +goto bw +) else if [!ay!]==[-pe-exp-list] ( set /a "ax+=1" & call :bx bk[!ax!] v +set aq=!v! +goto bw +) else if [!ay!]==[-eng] ( +chcp 437 >nul +goto bw +) else if [!ay!]==[-GetNuTool] ( +call :by -GetNuTool 10 +set /a aw=!ERRORLEVEL! & goto bu +) else if [!ay!]==[-hMSBuild] ( +set av=1 & goto br +) else if [!ay!]==[-version] ( +@echo v1.7.4.29858+c1cc52f %__dxp_pv% +goto bu +) else if [!ay!]==[-build-info] ( +set an=1 +goto bw +) else if [!ay!]==[-tests] ( set /a "ax+=1" & call :bx bk[!ax!] v +set au=!v! +goto bw +) else ( +echo Incorrect key: !ay! +set /a aw=1 +goto bu +) +:bw +set /a "ax+=1" & if %ax% LSS !bl! goto bv +:br +call :bz "dxpName = " ag +call :bz "dxpVersion = " af +call :bz "-sln-dir = " wSlnDir +call :bz "-sln-file = " wSlnFile +call :bz "-metalib = " wMetaLib +call :bz "-metacor = " wMetaCor +call :bz "-dxp-target = " wDxpTarget +call :bz "-wz-target = " ah +call :bz "#opt " wDxpOpt +if defined af ( +if "!af!"=="actual" ( +set "af=" +) +) +set wPkgVer=!af! +if z%wAction%==zUpgrade ( +call :bz "Upgrade is on" +set as=1 +set ar=1 +) +call :b0 ai +set "ai=!ai!\\" +set "az=!ag!" +set "wPkgPath=!ai!!ag!" +if defined af ( +set "az=!az!/!af!" +set "wPkgPath=!wPkgPath!.!af!" +) +if defined ar ( +if exist "!wPkgPath!" ( +call :bz "Removing old version before continue. '-force' key rule. " wPkgPath +rmdir /S/Q "!wPkgPath!" +) +) +set a0="!wPkgPath!\\!ah!" +call :bz "wPkgPath = " wPkgPath +if not exist !a0! ( +if exist "!wPkgPath!" ( +call :bz "Trying to replace obsolete version ... " wPkgPath +rmdir /S/Q "!wPkgPath!" +) +call :bz "-pkg-link = " ap +call :bz "-server = " aj +if defined ap ( +set aj=!ap! +if "!aj::=!"=="!aj!" ( +set aj=!cd!/!aj! +) +if "!wPkgPath::=!"=="!wPkgPath!" ( +set "a1=../" +) +set "az=:!a1!!wPkgPath!|" +) +if defined ao ( +set a2=-msbuild "!ao!" +) +set a3=!a2! /p:ngserver="!aj!" /p:ngpackages="!az!" /p:ngpath="!ai!" /p:proxycfg="!at! " +call :bz "GetNuTool call: " a3 +if defined am ( +call :b1 !a3! +) else ( +call :b1 !a3! >nul +) +) +if defined av ( +call :by -hMSBuild 9 +set /a aw=!ERRORLEVEL! & goto bu +) +if defined aq ( +"!wPkgPath!\\tools\\PeViewer.exe" -list -pemodule "!aq!" +set /a aw=%ERRORLEVEL% +goto bu +) +if defined an ( +call :bz "buildInfo = " wPkgPath ak +if not exist "!wPkgPath!\\!ak!" ( +echo information about build is not available. +set /a aw=2 +goto bu +) +type "!wPkgPath!\\!ak!" +goto bu +) +if not exist !a0! ( +echo Something went wrong. Try to use another keys. +set /a aw=2 +goto bu +) +call :bz "wRootPath = " wRootPath +call :bz "wAction = " wAction +call :bz "wMgrArgs = " wMgrArgs +if defined ao ( +call :bz "Use specific MSBuild tools: " ao +set a4="!ao!" +goto b2 +) +call :b3 bm & set a4="!bm!" +if "!ERRORLEVEL!"=="0" goto b2 +echo MSBuild tools was not found. Try with `-msb` key. +set /a aw=2 +goto bu +:b2 +if not defined a4 ( +echo Something went wrong. Use `-debug` key for details. +set /a aw=2 +goto bu +) +if not defined au ( +if not defined ao if defined wPkgPath ( +set a4="!wPkgPath!\\hMSBuild" +for /f "tokens=*" %%i in ('!a4! -version') do set a5=%%i +call :b4 !a5! bn +call :bz "hMSBuild -v" a5 bn +if !bn! GEQ 230 ( +call :bz "2.3+" +set a4=!a4! -vsw-as "-requiresAny -requires Microsoft.NetCore.Component.SDK Microsoft.Net.Core.Component.SDK -products * -latest -prerelease" +) +) +call :bz "Target: " a4 a0 +call !a4! /nologo /v:m /m:4 !a0! +) +:bu +if defined au ( +echo Running Tests ... "!au!" +call :b3 bo +"!bo!" /nologo /v:m /m:4 "!au!" +exit/B 0 +) +if defined as ( +(copy /B/Y "!wPkgPath!\\DllExport.bat" "!al!" > nul) && ( echo Manager has been updated. & exit/B 0 ) || ( (echo -mgr-up failed:!aw! 1>&2) & exit/B 1 ) +) +exit/B !aw! +:b4 +set a6=%~1 +for /f "tokens=1,2 delims=." %%a in ("!a6!") do ( +set _=%%b & set /a _*=10 & set /a %2=%%a!_! +) +exit/B 0 +:by +set ay=%~1 +set /a a7=%~2 +call :bz "accessing to !ay! ..." +for /L %%p IN (0,1,8181) DO ( +if "!ad:~%%p,%a7%!"=="!ay!" ( +set a8=!ad:~%%p! +set a9=!a8:~%a7%! +if defined av ( +call "!wPkgPath!\\hMSBuild" !a9! +) else ( +call :b1 !a9! +) +exit/B !ERRORLEVEL! +) +) +call :bz "!ay! is corrupted: " ad +exit/B 1 +:b3 +call :bz "Searching from .NET Framework - .NET 4.0, ..." +for %%v in (4.0, 3.5, 2.0) do ( +call :b5 %%v Y & if defined Y ( +set %1=!Y! +exit/B 0 +) +) +call :bz "msb -netfx: not found" +set "%1=" +exit/B 2 +:b5 +call :bz "check %1" +for /F "usebackq tokens=2* skip=2" %%a in ( +`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%1" /v MSBuildToolsPath 2^> nul` +) do if exist %%b ( +set a_=%%~b +call :bz ":msbfound " a_ +call :b6 a_ bp +set %2=!bp! +exit/B 0 +) +set "%2=" +exit/B 0 +:b6 +set %2=!%~1!\MSBuild.exe +exit/B 0 +:bz +if defined am ( +set ba=%1 +set ba=!ba:~0,-1! +set ba=!ba:~1! +echo.[%TIME% ] !ba! !%2! !%3! +) +exit/B 0 +:b0 +call :b7 %1 +call :b8 %1 +exit/B 0 +:b7 +call :b9 %1 "-=1" +exit/B 0 +:b8 +call :b9 %1 "+=1" +exit/B 0 +:b9 +set bb=z!%1!z +if "%~2"=="-=1" (set "bc=1") else (set "bc=") +if defined bc ( +set /a "i=-2" +) else ( +set /a "i=1" +) +:b_ +if "!bb:~%i%,1!"==" " ( +set /a "i%~2" +goto b_ +) +if defined bc set /a "i+=1" +if defined bc ( +set "%1=!bb:~1,%i%!" +) else ( +set "%1=!bb:~%i%,-1!" +) +exit/B 0 +:bs +set "bd=%~1" +set /a ax=-1 +:ca +set /a ax+=1 +set %bd%[!ax!]=%~2 +shift & if not "%~3"=="" goto ca +set /a ax-=1 +set %1=!ax! +exit/B 0 +:bx +set %2=!%1! +exit/B 0 +:b1 +setlocal disableDelayedExpansion +@echo off +:: GetNuTool - Executable version +:: Copyright (c) 2015-2018,2020 Denis Kuzmin [ x-3F@outlook.com ] +:: https://github.com/3F/GetNuTool +set be=gnt.core +set bf="%temp%\%random%%random%%be%" +if "%~1"=="-unpack" goto cb +set bg=%* +if defined __p_call if defined bg set bg=%bg:^^=^% +set bh=%__p_msb% +if defined bh goto cc +if "%~1"=="-msbuild" goto cd +for %%v in (4.0, 14.0, 12.0, 3.5, 2.0) do ( +for /F "usebackq tokens=2* skip=2" %%a in ( +`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul` +) do if exist %%b ( +set bh="%%~b\MSBuild.exe" +goto cc +) +) +echo MSBuild was not found. Try -msbuild "fullpath" args 1>&2 +exit/B 2 +:cd +shift +set bh=%1 +shift +set bi=%bg:!= #__b_ECL## % +setlocal enableDelayedExpansion +set bi=!bi:%%=%%%%! +:ce +for /F "tokens=1* delims==" %%a in ("!bi!") do ( +if "%%~b"=="" ( +call :cf !bi! +exit/B %ERRORLEVEL% +) +set bi=%%a #__b_EQ## %%b +) +goto ce +:cf +shift & shift +set "bg=" +:cg +set bg=!bg! %1 +shift & if not "%~2"=="" goto cg +set bg=!bg: #__b_EQ## ==! +setlocal disableDelayedExpansion +set bg=%bg: #__b_ECL## =!% +:cc +call :ch +call %bh% %bf% /nologo /p:wpath="%cd%/" /v:m /m:4 %bg% +set "bh=" +set bj=%ERRORLEVEL% +del /Q/F %bf% +exit/B %bj% +:cb +set bf="%cd%\%be%" +echo Generating minified version in %bf% ... +:ch +%bf% +set a=PropertyGroup&set b=Condition&set c=ngpackages&set d=Target&set e=DependsOnTargets&set f=TaskCoreDllPath&set g=MSBuildToolsPath&set h=UsingTask&set i=CodeTaskFactory&set j=ParameterGroup&set k=Reference&set l=Include&set m=System&set n=Using&set o=Namespace&set p=IsNullOrEmpty&set q=return&set r=string&set s=delegate&set t=foreach&set u=WriteLine&set v=Combine&set w=Console.WriteLine&set x=Directory&set y=GetNuTool&set z=StringComparison&set _=EXT_NUSPEC +^ + + diff --git a/Remote/NosSmooth.RemoteClient/Properties/AssemblyInfo.cs b/Remote/NosSmooth.RemoteClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f019b39 --- /dev/null +++ b/Remote/NosSmooth.RemoteClient/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NosSmooth.RemoteClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NosSmooth.RemoteClient")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2A3EA9A8-5948-47FD-AD13-6E19540BDDFB")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Samples/DamageCounter/App.xaml b/Samples/DamageCounter/App.xaml new file mode 100644 index 0000000..3f594c2 --- /dev/null +++ b/Samples/DamageCounter/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Samples/DamageCounter/App.xaml.cs b/Samples/DamageCounter/App.xaml.cs new file mode 100644 index 0000000..71d160d --- /dev/null +++ b/Samples/DamageCounter/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace DamageCounter +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/Samples/DamageCounter/AssemblyInfo.cs b/Samples/DamageCounter/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/Samples/DamageCounter/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/Samples/DamageCounter/DamageCounter.csproj b/Samples/DamageCounter/DamageCounter.csproj new file mode 100644 index 0000000..86b3c42 --- /dev/null +++ b/Samples/DamageCounter/DamageCounter.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net5.0-windows + enable + true + + + diff --git a/Samples/DamageCounter/MainWindow.xaml b/Samples/DamageCounter/MainWindow.xaml new file mode 100644 index 0000000..fd01a93 --- /dev/null +++ b/Samples/DamageCounter/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Samples/DamageCounter/MainWindow.xaml.cs b/Samples/DamageCounter/MainWindow.xaml.cs new file mode 100644 index 0000000..a698104 --- /dev/null +++ b/Samples/DamageCounter/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DamageCounter +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Samples/PacketInterceptor/DummyNostaleClient.cs b/Samples/PacketInterceptor/DummyNostaleClient.cs new file mode 100644 index 0000000..6b1da45 --- /dev/null +++ b/Samples/PacketInterceptor/DummyNostaleClient.cs @@ -0,0 +1,38 @@ +using NosCore.Packets; +using NosCore.Packets.ServerPackets.MiniMap; +using NosSmooth.Core.Client; +using NosSmooth.Core.Commands; +using NosSmooth.Core.Packets; +using Remora.Results; + +namespace PacketInterceptor; + +public class DummyNostaleClient : BaseNostaleClient +{ + private readonly IPacketHandler _packetHandler; + + public DummyNostaleClient(CommandProcessor commandProcessor, IPacketSerializer packetSerializer, + IPacketHandler packetHandler) : base(commandProcessor, packetSerializer) + { + _packetHandler = packetHandler; + } + + public override async Task RunAsync(CancellationToken stopRequested = default) + { + await _packetHandler.HandleSentPacketAsync(new CMapPacket() + { Header = "t", Id = 2, IsValid = true, KeepAliveId = 123, MapType = true, Type = 0 }, stopRequested); + return Result.FromSuccess(); + } + + public override Task SendPacketAsync(string packetString, CancellationToken ct = default) + { + Console.WriteLine($"Sending packet {packetString}"); + return Task.FromResult(Result.FromSuccess()); + } + + public override Task ReceivePacketAsync(string packetString, CancellationToken ct = default) + { + Console.WriteLine($"Receiving packet {packetString}"); + return Task.FromResult(Result.FromSuccess()); + } +} \ No newline at end of file diff --git a/Samples/PacketInterceptor/PacketInterceptor.csproj b/Samples/PacketInterceptor/PacketInterceptor.csproj new file mode 100644 index 0000000..f0a0e2a --- /dev/null +++ b/Samples/PacketInterceptor/PacketInterceptor.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + 10 + + + + + + + diff --git a/Samples/PacketInterceptor/Program.cs b/Samples/PacketInterceptor/Program.cs new file mode 100644 index 0000000..af72e2f --- /dev/null +++ b/Samples/PacketInterceptor/Program.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.DependencyInjection; +using NosCore.Packets; +using NosSmooth.Core.Client; +using NosSmooth.Core.Extensions; +using NosSmooth.Core.Packets; +using PacketInterceptor; + +class Program +{ + public static async Task Main() + { + var provider = new ServiceCollection() + .AddNostaleCore() + .AddSingleton() + .AddPacketResponder() + .BuildServiceProvider(); + + var deserializerProvider = provider.GetRequiredService(); + + foreach (var line in File.ReadAllLines("packet.log")) + { + var packetString = string.Join("",line.Skip(8+10)); + try + { + var result = deserializerProvider.GetServerSerializer().Deserialize(packetString); + + if (!result.IsSuccess) + { + Console.WriteLine($"Could not deserialize packet {packetString}"); + } + } + catch (Exception e) + { + } + } + + var packet = deserializerProvider.GetServerSerializer().Deserialize("sayitemt 1 441092 17 1 4964 TrozZes {%s} e_info 0 4964 7 9 0 25 797 889 528 12 210 0 100 1200000 -1 0 441092 9 1.17.100 1.15.4 2.26.11 2.20.71 3.25.190 3.13.16 4.2.17 12.34.25 11.43.38 8 0 6 33.1.1600.0.2 44.1.-4.0.1 104.3.8.0.2 4.0.80.0.1 3.0.80.0.1 105.2.4.7640.1"); + + var client = provider.GetRequiredService(); + await client.RunAsync(); + } +} \ No newline at end of file diff --git a/Samples/PacketInterceptor/TestResponder.cs b/Samples/PacketInterceptor/TestResponder.cs new file mode 100644 index 0000000..6f46ef3 --- /dev/null +++ b/Samples/PacketInterceptor/TestResponder.cs @@ -0,0 +1,22 @@ +using NosCore.Packets.Interfaces; +using NosCore.Packets.ServerPackets.MiniMap; +using NosSmooth.Core.Client; +using NosSmooth.Core.Packets; +using Remora.Results; + +namespace PacketInterceptor; + +public class TestResponder : IEveryPacketResponder +{ + private readonly INostaleClient _client; + + public TestResponder(INostaleClient client) + { + _client = client; + } + + public async Task Respond(TPacket packet, CancellationToken ct = default) where TPacket : IPacket + { + return await _client.SendPacketAsync("test"); + } +} \ No newline at end of file diff --git a/Samples/PacketLogger/App.xaml b/Samples/PacketLogger/App.xaml new file mode 100644 index 0000000..8486a28 --- /dev/null +++ b/Samples/PacketLogger/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Samples/PacketLogger/App.xaml.cs b/Samples/PacketLogger/App.xaml.cs new file mode 100644 index 0000000..72f0c1b --- /dev/null +++ b/Samples/PacketLogger/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace PacketLogger +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/Samples/PacketLogger/AssemblyInfo.cs b/Samples/PacketLogger/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/Samples/PacketLogger/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/Samples/PacketLogger/MainWindow.xaml b/Samples/PacketLogger/MainWindow.xaml new file mode 100644 index 0000000..5f20bf8 --- /dev/null +++ b/Samples/PacketLogger/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Samples/PacketLogger/MainWindow.xaml.cs b/Samples/PacketLogger/MainWindow.xaml.cs new file mode 100644 index 0000000..9581893 --- /dev/null +++ b/Samples/PacketLogger/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace PacketLogger +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Samples/PacketLogger/PacketLogger.csproj b/Samples/PacketLogger/PacketLogger.csproj new file mode 100644 index 0000000..277ebcd --- /dev/null +++ b/Samples/PacketLogger/PacketLogger.csproj @@ -0,0 +1,18 @@ + + + + net6.0-windows + enable + true + 10 + + + + + + + + + + + diff --git a/Samples/PacketLogger/Packets/PacketLoggerResponder.cs b/Samples/PacketLogger/Packets/PacketLoggerResponder.cs new file mode 100644 index 0000000..bb58180 --- /dev/null +++ b/Samples/PacketLogger/Packets/PacketLoggerResponder.cs @@ -0,0 +1,27 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using NosCore.Packets; +using NosCore.Packets.Interfaces; +using NosSmooth.Core.Packets; +using Remora.Results; + +namespace PacketLogger.Packets; + +public class PacketLoggerResponder : IEveryPacketResponder +{ + private readonly ILogger _logger; + private readonly Serializer _serializer; + + public PacketLoggerResponder(ILogger logger, Serializer serializer) + { + _logger = logger; + _serializer = serializer; + } + + public Task Respond(TPacket packet, CancellationToken ct = default) where TPacket : IPacket + { + _logger.LogInformation(_serializer.Serialize(packet)); + return Task.FromResult(Result.FromSuccess()); + } +} \ No newline at end of file diff --git a/Samples/Test/DllMain.cs b/Samples/Test/DllMain.cs new file mode 100644 index 0000000..7751e8b --- /dev/null +++ b/Samples/Test/DllMain.cs @@ -0,0 +1,56 @@ +using System.Runtime.InteropServices; +using System.Text; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Win32.SafeHandles; +using NosSmooth.Core.Client; +using NosSmooth.Core.Extensions; +using NosSmooth.LocalClient.Extensions; + +namespace Test +{ + public class DllMain + { + public static void CreateConsole() + { + AllocConsole(); + } + + [DllImport("kernel32.dll", + EntryPoint = "GetStdHandle", + SetLastError = true, + CharSet = CharSet.Auto, + CallingConvention = CallingConvention.StdCall)] + private static extern IntPtr GetStdHandle(int nStdHandle); + [DllImport("kernel32.dll", + EntryPoint = "AllocConsole", + SetLastError = true, + CharSet = CharSet.Auto, + CallingConvention = CallingConvention.StdCall)] + private static extern int AllocConsole(); + + [DllExport] + public static int Main(IntPtr moduleHandle) + { + CreateConsole(); + + new Thread(async () => + { + var provider = new ServiceCollection() + .AddNostaleCore() + .AddLocalClient() + .AddLogging(b => b.AddSimpleConsole()) + .BuildServiceProvider(); + Console.WriteLine("Test"); + var logger = provider.GetRequiredService>(); + Console.WriteLine("Hell"); + logger.LogInformation("Built services"); + Thread.Sleep(1000); + + var client = provider.GetRequiredService(); + await client.RunAsync(); + }).Start(); + return 0; + } + } +} \ No newline at end of file diff --git a/Samples/Test/Test - Backup.csproj b/Samples/Test/Test - Backup.csproj new file mode 100644 index 0000000..a4af5d4 --- /dev/null +++ b/Samples/Test/Test - Backup.csproj @@ -0,0 +1,63 @@ + + + net6.0 + enable + enable + + + true + + + 8A46ECC7-E8CA-46E7-9B47-1F7C45D0A117 + DllExport.dll + Test + true + x86 + 1 + false + false + false + false + 30000 + 2 + 0 + 0 + 0 + + + + 1.7.4 + false + 1 + + + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)packages\DllExport.1.7.4\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName) + False + False + + + + + + + \ No newline at end of file diff --git a/Samples/Test/Test.csproj b/Samples/Test/Test.csproj new file mode 100644 index 0000000..a44cd09 --- /dev/null +++ b/Samples/Test/Test.csproj @@ -0,0 +1,71 @@ + + + net48 + enable + enable + 10 + + + true + + + true + + + true + true + 5F1D9960-ECF6-42DF-AB4D-7350CCF1165B + DllExport.dll + Test + true + x86 + 7 + false + false + false + false + 30000 + 2 + 0 + 0 + 0 + + + + 1.7.4 + false + 1 + + + + + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)packages\DllExport.1.7.4\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName) + False + False + + + + + + + \ No newline at end of file diff --git a/Samples/testapp/Program.cs b/Samples/testapp/Program.cs new file mode 100644 index 0000000..8abe335 --- /dev/null +++ b/Samples/testapp/Program.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Threading; + +namespace testapp +{ + internal class Program + { + static void Main(string[] args) + { + var provider = new ServiceCollection() + .AddLogging(b => + { + b.ClearProviders(); + b.AddConsole(); + b.SetMinimumLevel(LogLevel.Debug); + }) + .BuildServiceProvider(); + Console.WriteLine("Test"); + var logger = provider.GetRequiredService>(); + Console.WriteLine("Hell"); + logger.LogError("Built services"); + Console.WriteLine("Hello World!"); + Thread.Sleep(1000); + } + } +} diff --git a/Samples/testapp/testapp.csproj b/Samples/testapp/testapp.csproj new file mode 100644 index 0000000..907ef65 --- /dev/null +++ b/Samples/testapp/testapp.csproj @@ -0,0 +1,15 @@ + + + + Exe + net48 + + + + + + + + + + diff --git a/libs/NosCore.Packets b/libs/NosCore.Packets new file mode 160000 index 0000000..3b321dc --- /dev/null +++ b/libs/NosCore.Packets @@ -0,0 +1 @@ +Subproject commit 3b321dc6307a102c808eb37d3cc11890af3c6540 diff --git a/libs/NosCore.Shared b/libs/NosCore.Shared new file mode 160000 index 0000000..05c3880 --- /dev/null +++ b/libs/NosCore.Shared @@ -0,0 +1 @@ +Subproject commit 05c3880af07154903c294a9cf715025b8649ad85 -- 2.48.1