diff --git a/.build.yml b/.build.yml index b132bc5..680d514 100644 --- a/.build.yml +++ b/.build.yml @@ -8,9 +8,9 @@ tasks: curl -L https://nixos.org/nix/install | sh -s echo 'source $HOME/.nix-profile/etc/profile.d/nix.sh' >> $HOME/.buildenv - build: | - cd remote-party-finder + cd remote-party-finder/server nix-shell --command 'cargo build --release' strip -s target/release/remote-party-finder nix-shell --command 'patchelf --remove-rpath --set-interpreter /usr/lib64/ld-linux-x86-64.so.2 target/release/remote-party-finder' artifacts: - - remote-party-finder/target/release/remote-party-finder + - remote-party-finder/server/target/release/remote-party-finder diff --git a/csharp/.gitignore b/csharp/.gitignore new file mode 100644 index 0000000..1db30bf --- /dev/null +++ b/csharp/.gitignore @@ -0,0 +1,365 @@ +## 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 + +# Packaging +pack/ + +# 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 +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.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 + +# 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 diff --git a/csharp/RemotePartyFinder.sln b/csharp/RemotePartyFinder.sln new file mode 100644 index 0000000..ae91c21 --- /dev/null +++ b/csharp/RemotePartyFinder.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemotePartyFinder", "RemotePartyFinder\RemotePartyFinder.csproj", "{3B6A57E7-EC71-4E5B-87F0-A110078F125D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGenerator", "SourceGenerator\SourceGenerator.csproj", "{B92F3AC2-2E24-4EB1-BE4D-A41E6216EA20}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3B6A57E7-EC71-4E5B-87F0-A110078F125D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B6A57E7-EC71-4E5B-87F0-A110078F125D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B6A57E7-EC71-4E5B-87F0-A110078F125D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B6A57E7-EC71-4E5B-87F0-A110078F125D}.Release|Any CPU.Build.0 = Release|Any CPU + {B92F3AC2-2E24-4EB1-BE4D-A41E6216EA20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B92F3AC2-2E24-4EB1-BE4D-A41E6216EA20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B92F3AC2-2E24-4EB1-BE4D-A41E6216EA20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B92F3AC2-2E24-4EB1-BE4D-A41E6216EA20}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/csharp/RemotePartyFinder/Gatherer.cs b/csharp/RemotePartyFinder/Gatherer.cs new file mode 100644 index 0000000..d34f71f --- /dev/null +++ b/csharp/RemotePartyFinder/Gatherer.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Dalamud.Game; +using Dalamud.Game.Gui.PartyFinder.Types; +using Dalamud.Logging; +using Newtonsoft.Json; + +namespace RemotePartyFinder { + internal class Gatherer : IDisposable { + #if DEBUG + private const string UploadUrl = "http://192.168.174.240:7878/contribute/multiple"; + #elif RELEASE + private const string UploadUrl = "https://rpf.annaclemens.io/contribute/multiple"; + #endif + + private Plugin Plugin { get; } + + private ConcurrentDictionary> Batches { get; } = new(); + private Stopwatch UploadTimer { get; } = new(); + private HttpClient Client { get; } = new(); + + internal Gatherer(Plugin plugin) { + this.Plugin = plugin; + + this.UploadTimer.Start(); + + this.Plugin.PartyFinderGui.ReceiveListing += this.OnListing; + this.Plugin.Framework.Update += this.OnUpdate; + } + + public void Dispose() { + this.Plugin.Framework.Update -= this.OnUpdate; + this.Plugin.PartyFinderGui.ReceiveListing -= this.OnListing; + } + + private void OnListing(PartyFinderListing listing, PartyFinderListingEventArgs args) { + if (!this.Batches.ContainsKey(args.BatchNumber)) { + this.Batches[args.BatchNumber] = new List(); + } + + this.Batches[args.BatchNumber].Add(listing); + } + + private void OnUpdate(Framework framework) { + if (this.UploadTimer.Elapsed < TimeSpan.FromSeconds(10)) { + return; + } + + this.UploadTimer.Restart(); + + foreach (var (batch, listings) in this.Batches.ToList()) { + this.Batches.Remove(batch, out _); + Task.Run(async () => { + var uploadable = listings + .Select(listing => new UploadableListing(listing)) + .ToList(); + var json = JsonConvert.SerializeObject(uploadable); + var resp = await this.Client.PostAsync(UploadUrl, new StringContent(json) { + Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") }, + }); + var output = await resp.Content.ReadAsStringAsync(); + PluginLog.Log(output); + }); + } + } + } +} diff --git a/csharp/RemotePartyFinder/Plugin.cs b/csharp/RemotePartyFinder/Plugin.cs new file mode 100644 index 0000000..5e363db --- /dev/null +++ b/csharp/RemotePartyFinder/Plugin.cs @@ -0,0 +1,26 @@ +using Dalamud.Game; +using Dalamud.Game.Gui.PartyFinder; +using Dalamud.IoC; +using Dalamud.Plugin; + +namespace RemotePartyFinder { + public class Plugin : IDalamudPlugin { + public string Name => "Remote Party Finder"; + + [PluginService] + internal Framework Framework { get; private init; } + + [PluginService] + internal PartyFinderGui PartyFinderGui { get; private init; } + + private Gatherer Gatherer { get; } + + public Plugin() { + this.Gatherer = new Gatherer(this); + } + + public void Dispose() { + this.Gatherer.Dispose(); + } + } +} diff --git a/csharp/RemotePartyFinder/RemotePartyFinder.csproj b/csharp/RemotePartyFinder/RemotePartyFinder.csproj new file mode 100644 index 0000000..2152d37 --- /dev/null +++ b/csharp/RemotePartyFinder/RemotePartyFinder.csproj @@ -0,0 +1,37 @@ + + + + 1.0.1 + net5.0-windows + false + + + + $(AppData)\XIVLauncher\addon\Hooks\dev + + + + + $(Dalamud)\Dalamud.dll + false + + + $(Dalamud)\Lumina.dll + false + + + $(Dalamud)\Lumina.Excel.dll + false + + + $(Dalamud)\Newtonsoft.Json.dll + false + + + + + + + + + diff --git a/csharp/RemotePartyFinder/RemotePartyFinder.yaml b/csharp/RemotePartyFinder/RemotePartyFinder.yaml new file mode 100644 index 0000000..3ea7d30 --- /dev/null +++ b/csharp/RemotePartyFinder/RemotePartyFinder.yaml @@ -0,0 +1,11 @@ +author: ascclemens +name: Remote Party Finder Uploader +description: |- + Uploads the PF listings you retrieve to the crowdsourced Remote + Party Finder website (https://rpf.annaclemens.io/). + + THIS IS BETA AF AND DEFINITELY NOT PRODUCTION QUALITY + + PLEASE NO REPORT SHIT +punchline: '[Extreme Beta] Crowdsourced PF website' +repo_url: https://git.sr.ht/~jkcclemens/RemotePartyFinder diff --git a/csharp/RemotePartyFinder/UploadableListing.cs b/csharp/RemotePartyFinder/UploadableListing.cs new file mode 100644 index 0000000..f16e0ed --- /dev/null +++ b/csharp/RemotePartyFinder/UploadableListing.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Dalamud.Game.Gui.PartyFinder.Types; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace RemotePartyFinder { + [Serializable] + [JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))] + internal class UploadableListing { + public uint Id { get; } + public uint ContentIdLower { get; } + public byte[] Name { get; } + public byte[] Description { get; } + public byte CreatedWorld { get; } + public byte HomeWorld { get; } + public byte CurrentWorld { get; } + public DutyCategory Category { get; } + public ushort Duty { get; } + public DutyType DutyType { get; } + public bool BeginnersWelcome { get; } + public ushort SecondsRemaining { get; } + public ushort MinItemLevel { get; } + public byte NumParties { get; } + public byte SlotsAvailable { get; } + public uint LastServerRestart { get; } + public ObjectiveFlags Objective { get; } + public ConditionFlags Conditions { get; } + public DutyFinderSettingsFlags DutyFinderSettings { get; } + public LootRuleFlags LootRules { get; } + public SearchAreaFlags SearchArea { get; } + public List Slots { get; } + public List JobsPresent { get; } + + internal UploadableListing(PartyFinderListing listing) { + this.Id = listing.Id; + this.ContentIdLower = listing.ContentIdLower; + this.Name = listing.Name.Encode(); + this.Description = listing.Description.Encode(); + this.CreatedWorld = (byte) listing.World.Value.RowId; + this.HomeWorld = (byte) listing.HomeWorld.Value.RowId; + this.CurrentWorld = (byte) listing.CurrentWorld.Value.RowId; + this.Category = listing.Category; + this.Duty = listing.RawDuty; + this.DutyType = listing.DutyType; + this.BeginnersWelcome = listing.BeginnersWelcome; + this.SecondsRemaining = listing.SecondsRemaining; + this.MinItemLevel = listing.MinimumItemLevel; + this.NumParties = listing.Parties; + this.SlotsAvailable = listing.SlotsAvailable; + this.LastServerRestart = listing.LastPatchHotfixTimestamp; + this.Objective = listing.Objective; + this.Conditions = listing.Conditions; + this.DutyFinderSettings = listing.DutyFinderSettings; + this.LootRules = listing.LootRules; + this.SearchArea = listing.SearchArea; + this.Slots = listing.Slots.Select(slot => new UploadableSlot(slot)).ToList(); + this.JobsPresent = listing.RawJobsPresent.ToList(); + } + } + + [Serializable] + [JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))] + internal class UploadableSlot { + public JobFlags Accepting { get; } + + internal UploadableSlot(PartyFinderSlot slot) { + this.Accepting = slot.Accepting.Aggregate((JobFlags) 0, ((agg, flag) => agg | flag)); + } + } +} diff --git a/csharp/SourceGenerator/Program.cs b/csharp/SourceGenerator/Program.cs new file mode 100644 index 0000000..8b77607 --- /dev/null +++ b/csharp/SourceGenerator/Program.cs @@ -0,0 +1,290 @@ +using System.IO; +using System.Text; +using Lumina; +using Lumina.Excel.GeneratedSheets; + +namespace SourceGenerator { + internal class Program { + private static void Main(string[] args) { + var data = new GameData(args[0]); + var prog = new Program(data); + + File.WriteAllText(Path.Join(args[1], "duties.rs"), prog.GenerateDuties()); + File.WriteAllText(Path.Join(args[1], "jobs.rs"), prog.GenerateJobs()); + File.WriteAllText(Path.Join(args[1], "roulettes.rs"), prog.GenerateRoulettes()); + File.WriteAllText(Path.Join(args[1], "worlds.rs"), prog.GenerateWorlds()); + File.WriteAllText(Path.Join(args[1], "territory_names.rs"), prog.GenerateTerritoryNames()); + File.WriteAllText(Path.Join(args[1], "auto_translate.rs"), prog.GenerateAutoTranslate()); + File.WriteAllText(Path.Join(args[1], "treasure_maps.rs"), prog.GenerateTreasureMaps()); + } + + private GameData Data { get; } + + private Program(GameData data) { + this.Data = data; + } + + private static StringBuilder DefaultHeader() { + return new StringBuilder("use std::collections::HashMap;\n"); + } + + private string GenerateDuties() { + var sb = DefaultHeader(); + sb.Append('\n'); + + sb.Append("#[derive(Debug)]\n"); + sb.Append("pub struct DutyInfo {\n"); + sb.Append(" pub name: &'static str,\n"); + sb.Append(" pub high_end: bool,\n"); + sb.Append(" pub content_kind: ContentKind,\n"); + sb.Append("}\n\n"); + + sb.Append("#[derive(Debug, Clone, Copy)]\n"); + sb.Append("#[allow(unused)]\n"); + sb.Append("#[repr(u32)]\n"); + sb.Append("pub enum ContentKind {\n"); + foreach (var kind in this.Data.GetExcelSheet()!) { + var name = kind.Name.TextValue().Replace(" ", ""); + if (name.Length > 0) { + sb.Append($" {name} = {kind.RowId},\n"); + } + } + + sb.Append(" Other(u32),\n"); + sb.Append("}\n\n"); + + sb.Append("impl ContentKind {\n"); + + sb.Append(" fn from_u32(kind: u32) -> Self {\n"); + sb.Append(" match kind {\n"); + foreach (var kind in this.Data.GetExcelSheet()!) { + var name = kind.Name.TextValue().Replace(" ", ""); + if (name.Length > 0) { + sb.Append($" {kind.RowId} => Self::{name},\n"); + } + } + + sb.Append(" x => Self::Other(x),\n"); + sb.Append(" }\n"); + sb.Append(" }\n\n"); + + sb.Append(" pub fn as_u32(self) -> u32 {\n"); + sb.Append(" match self {\n"); + foreach (var kind in this.Data.GetExcelSheet()!) { + var name = kind.Name.TextValue().Replace(" ", ""); + if (name.Length > 0) { + sb.Append($" Self::{name} => {kind.RowId},\n"); + } + } + + sb.Append(" Self::Other(x) => x,\n"); + sb.Append(" }\n"); + sb.Append(" }\n"); + + sb.Append("}\n\n"); + + sb.Append("lazy_static::lazy_static! {\n"); + sb.Append(" pub static ref DUTIES: HashMap = maplit::hashmap! {\n"); + + foreach (var cfc in this.Data.GetExcelSheet()!) { + if (cfc.RowId == 0) { + continue; + } + + var name = cfc.Name.TextValue(); + if (name.Length <= 0) { + continue; + } + + name = name[..1].ToUpperInvariant() + name[1..]; + var highEnd = cfc.HighEndDuty ? "true" : "false"; + var contentType = cfc.ContentType.Value; + var contentKind = contentType?.Name?.TextValue()?.Replace(" ", ""); + if (string.IsNullOrEmpty(contentKind)) { + contentKind = $"Other({contentType?.RowId ?? 0})"; + } + + sb.Append($" {cfc.RowId} => DutyInfo {{\n"); + sb.Append($" name: \"{name}\",\n"); + sb.Append($" high_end: {highEnd},\n"); + sb.Append($" content_kind: ContentKind::{contentKind},\n"); + sb.Append(" },\n"); + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateJobs() { + var sb = DefaultHeader(); + sb.Append("use ffxiv_types::jobs::{ClassJob, Class, Job, NonCombatJob};\n\n"); + sb.Append("lazy_static::lazy_static! {\n"); + sb.Append(" pub static ref JOBS: HashMap = maplit::hashmap! {\n"); + + foreach (var cj in this.Data.GetExcelSheet()!) { + if (cj.RowId == 0) { + continue; + } + + var name = cj.NameEnglish.TextValue().Replace(" ", ""); + if (name.Length <= 0) { + continue; + } + + var isCombat = cj.Role != 0; + var isClass = cj.JobIndex == 0; + + string value; + if (isCombat) { + value = isClass + ? $"ClassJob::Class(Class::{name})" + : $"ClassJob::Job(Job::{name})"; + } else { + value = $"ClassJob::NonCombat(NonCombatJob::{name})"; + } + + sb.Append($" {cj.RowId} => {value},\n"); + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateRoulettes() { + var sb = DefaultHeader(); + sb.Append('\n'); + sb.Append("#[derive(Debug)]\n"); + sb.Append("pub struct RouletteInfo {\n"); + sb.Append(" pub name: &'static str,\n"); + sb.Append(" pub pvp: bool,\n"); + sb.Append("}\n\n"); + + sb.Append("lazy_static::lazy_static! {\n"); + sb.Append(" pub static ref ROULETTES: HashMap = maplit::hashmap! {\n"); + + foreach (var cr in this.Data.GetExcelSheet()!) { + if (cr.RowId == 0) { + continue; + } + + var name = cr.Name.TextValue(); + if (name.Length <= 0) { + continue; + } + + var pvp = cr.Unknown28 == 6 + ? "true" + : "false"; + + sb.Append($" {cr.RowId} => RouletteInfo {{\n"); + sb.Append($" name: \"{name}\",\n"); + sb.Append($" pvp: {pvp},\n"); + sb.Append(" },\n"); + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateWorlds() { + var sb = DefaultHeader(); + sb.Append("use ffxiv_types::World;\n\n"); + sb.Append("lazy_static::lazy_static! {\n"); + sb.Append(" pub static ref WORLDS: HashMap = maplit::hashmap! {\n"); + + foreach (var world in this.Data.GetExcelSheet()!) { + if (world.RowId == 0 || !world.IsPublic || world.DataCenter.Row == 0) { + continue; + } + + var name = world.Name.TextValue(); + if (name.Length <= 0) { + continue; + } + + sb.Append($" {world.RowId} => World::{name},\n"); + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateTerritoryNames() { + var sb = DefaultHeader(); + sb.Append("\nlazy_static::lazy_static! {\n"); + sb.Append(" pub static ref TERRITORY_NAMES: HashMap = maplit::hashmap! {\n"); + + foreach (var tt in this.Data.GetExcelSheet()!) { + if (tt.RowId == 0 || tt.PlaceName.Row == 0) { + continue; + } + + var name = tt.PlaceName.Value!.Name.TextValue().Replace("\"", "\\\""); + if (name.Length <= 0) { + continue; + } + + sb.Append($" {tt.RowId} => \"{name}\",\n"); + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateAutoTranslate() { + var sb = DefaultHeader(); + sb.Append("\nlazy_static::lazy_static! {\n"); + sb.Append(" pub static ref AUTO_TRANSLATE: HashMap<(u32, u32), &'static str> = maplit::hashmap! {\n"); + + foreach (var row in this.Data.GetExcelSheet()!) { + var lookup = row.LookupTable.TextValue(); + if (lookup is not ("" or "@")) { + // TODO: do lookup + } else { + var text = row.Text.TextValue(); + sb.Append($" ({row.Group}, {row.RowId}) => \"{text}\",\n"); + } + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + + private string GenerateTreasureMaps() { + var sb = DefaultHeader(); + sb.Append("\nlazy_static::lazy_static! {\n"); + sb.Append(" pub static ref TREASURE_MAPS: HashMap = maplit::hashmap! {\n"); + sb.Append(" 0 => \"All Levels\",\n"); + + var i = 1; + foreach (var row in this.Data.GetExcelSheet()!) { + // IS THIS RIGHT? + if (row.TreasureHuntTexture != 0) { + continue; + } + + var name = row.KeyItemName.Value?.Name.TextValue(); + if (!string.IsNullOrEmpty(name)) { + sb.Append($" {i++} => \"{name}\",\n"); + } + } + + sb.Append(" };\n"); + sb.Append("}\n"); + + return sb.ToString(); + } + } +} diff --git a/csharp/SourceGenerator/SeStringExtensions.cs b/csharp/SourceGenerator/SeStringExtensions.cs new file mode 100644 index 0000000..7afdad8 --- /dev/null +++ b/csharp/SourceGenerator/SeStringExtensions.cs @@ -0,0 +1,36 @@ +using System.Linq; +using Lumina.Text; +using Lumina.Text.Payloads; + +namespace SourceGenerator { + internal static class SeStringExtensions { + internal static string TextValue(this SeString str) { + var payloads = str.Payloads + .Select(p => { + if (p is TextPayload text) { + return text.RawString; + } + + return p.Data.Length > 1 && p.Data[1] == 0x1F ? "-" : ""; + }); + // Produces: + // MainCommand[col-,1-36,41-42,44-44,56-62,64-70,72-82,84-99] + // TextCommand[col-,col-,1-31,33-211,213-321,323-455,459-611,613-629,632-632] + // TextCommand[col-,col-,1-31,33-211,213-321,323-455,459-611,613-629,632-632] + // Pet[,1-8,10-10,14-15,17-19] + // PetMirage[col-♥] + // + // foreach (var payload in str.Payloads) { + // if (payload is TextPayload) { + // continue; + // } + // + // if (payload.Data.Length > 1 && payload.Data[1] == 0x20) { + // Console.WriteLine(string.Join("", payloads)); + // } + // } + + return string.Join("", payloads); + } + } +} diff --git a/csharp/SourceGenerator/SourceGenerator.csproj b/csharp/SourceGenerator/SourceGenerator.csproj new file mode 100644 index 0000000..8cb84db --- /dev/null +++ b/csharp/SourceGenerator/SourceGenerator.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + + + + + + + + diff --git a/.envrc b/server/.envrc similarity index 100% rename from .envrc rename to server/.envrc diff --git a/.gitignore b/server/.gitignore similarity index 100% rename from .gitignore rename to server/.gitignore diff --git a/Cargo.lock b/server/Cargo.lock similarity index 100% rename from Cargo.lock rename to server/Cargo.lock diff --git a/Cargo.toml b/server/Cargo.toml similarity index 100% rename from Cargo.toml rename to server/Cargo.toml diff --git a/assets/icons.svg b/server/assets/icons.svg similarity index 100% rename from assets/icons.svg rename to server/assets/icons.svg diff --git a/assets/listings.css b/server/assets/listings.css similarity index 100% rename from assets/listings.css rename to server/assets/listings.css diff --git a/assets/listings.js b/server/assets/listings.js similarity index 100% rename from assets/listings.js rename to server/assets/listings.js diff --git a/assets/minireset.css b/server/assets/minireset.css similarity index 100% rename from assets/minireset.css rename to server/assets/minireset.css diff --git a/config.example.toml b/server/config.example.toml similarity index 100% rename from config.example.toml rename to server/config.example.toml diff --git a/default.nix b/server/default.nix similarity index 100% rename from default.nix rename to server/default.nix diff --git a/nix/sources.json b/server/nix/sources.json similarity index 100% rename from nix/sources.json rename to server/nix/sources.json diff --git a/nix/sources.nix b/server/nix/sources.nix similarity index 100% rename from nix/sources.nix rename to server/nix/sources.nix diff --git a/src/base64_sestring.rs b/server/src/base64_sestring.rs similarity index 100% rename from src/base64_sestring.rs rename to server/src/base64_sestring.rs diff --git a/src/config.rs b/server/src/config.rs similarity index 100% rename from src/config.rs rename to server/src/config.rs diff --git a/src/ffxiv.rs b/server/src/ffxiv.rs similarity index 100% rename from src/ffxiv.rs rename to server/src/ffxiv.rs diff --git a/src/ffxiv/auto_translate.rs b/server/src/ffxiv/auto_translate.rs similarity index 100% rename from src/ffxiv/auto_translate.rs rename to server/src/ffxiv/auto_translate.rs diff --git a/src/ffxiv/duties.rs b/server/src/ffxiv/duties.rs similarity index 100% rename from src/ffxiv/duties.rs rename to server/src/ffxiv/duties.rs diff --git a/src/ffxiv/jobs.rs b/server/src/ffxiv/jobs.rs similarity index 100% rename from src/ffxiv/jobs.rs rename to server/src/ffxiv/jobs.rs diff --git a/src/ffxiv/roulettes.rs b/server/src/ffxiv/roulettes.rs similarity index 100% rename from src/ffxiv/roulettes.rs rename to server/src/ffxiv/roulettes.rs diff --git a/src/ffxiv/territory_names.rs b/server/src/ffxiv/territory_names.rs similarity index 100% rename from src/ffxiv/territory_names.rs rename to server/src/ffxiv/territory_names.rs diff --git a/src/ffxiv/treasure_maps.rs b/server/src/ffxiv/treasure_maps.rs similarity index 100% rename from src/ffxiv/treasure_maps.rs rename to server/src/ffxiv/treasure_maps.rs diff --git a/src/ffxiv/worlds.rs b/server/src/ffxiv/worlds.rs similarity index 100% rename from src/ffxiv/worlds.rs rename to server/src/ffxiv/worlds.rs diff --git a/src/listing.rs b/server/src/listing.rs similarity index 100% rename from src/listing.rs rename to server/src/listing.rs diff --git a/src/listing_container.rs b/server/src/listing_container.rs similarity index 100% rename from src/listing_container.rs rename to server/src/listing_container.rs diff --git a/src/main.rs b/server/src/main.rs similarity index 100% rename from src/main.rs rename to server/src/main.rs diff --git a/src/sestring_ext.rs b/server/src/sestring_ext.rs similarity index 100% rename from src/sestring_ext.rs rename to server/src/sestring_ext.rs diff --git a/src/template/listings.rs b/server/src/template/listings.rs similarity index 100% rename from src/template/listings.rs rename to server/src/template/listings.rs diff --git a/src/template/mod.rs b/server/src/template/mod.rs similarity index 100% rename from src/template/mod.rs rename to server/src/template/mod.rs diff --git a/src/test.rs b/server/src/test.rs similarity index 100% rename from src/test.rs rename to server/src/test.rs diff --git a/src/web.rs b/server/src/web.rs similarity index 100% rename from src/web.rs rename to server/src/web.rs diff --git a/templates/_frame.html b/server/templates/_frame.html similarity index 100% rename from templates/_frame.html rename to server/templates/_frame.html diff --git a/templates/listings.html b/server/templates/listings.html similarity index 100% rename from templates/listings.html rename to server/templates/listings.html