Skip to main content

rpfm_ipc/
messages.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! # IPC Messages Module
12//!
13//! This module defines the core IPC protocol structures used for communication between the RPFM
14//! frontend and backend server.
15//!
16//! ## Overview
17//!
18//! The protocol is built around three main types:
19//!
20//! - [`Message<T>`]: A generic wrapper that adds request-response correlation via unique IDs.
21//! - [`Command`]: An enum defining all actions the frontend can request from the server.
22//! - [`Response`]: An enum defining all possible results the server can return.
23//!
24//! ## Message Correlation
25//!
26//! Every message includes a unique `id` field that allows the frontend to match responses to their
27//! original requests. This enables:
28//!
29//! - **Asynchronous communication**: Multiple requests can be in flight simultaneously.
30//! - **Non-blocking UI**: The frontend doesn't need to wait for responses before sending new requests.
31//! - **Error handling**: Responses can be matched back to the context that initiated them.
32//!
33//! ## Command Categories
34//!
35//! Commands are organized into logical groups:
36//!
37//! - **PackFile Operations**: Open, save, close, and modify PackFiles.
38//! - **PackedFile Operations**: Create, delete, extract, rename, and decode individual files.
39//! - **Dependency Operations**: Query and manage game dependencies.
40//! - **Search Operations**: Global search and reference lookups.
41//! - **Schema Operations**: Load, save, and update table schemas.
42//! - **Settings Operations**: Get and set application settings.
43//! - **Update Operations**: Check for and apply updates to schemas, translations, etc.
44//! - **Diagnostics**: Run diagnostic checks on PackFiles.
45//! - **Navigation**: Go-to-definition and reference search features.
46//!
47//! ## Response Types
48//!
49//! Responses are typically named after the types they contain (e.g., `Response::Bool(bool)`,
50//! `Response::String(String)`). For complex operations, specialized responses like
51//! `Response::DBRFileInfo` or `Response::ContainerInfoVecRFileInfo` carry domain-specific data.
52//!
53//! Each [`Command`] variant's documentation specifies which [`Response`] variant(s) it returns.
54
55use serde::{Serialize, Deserialize};
56
57use std::collections::{BTreeMap, HashMap, HashSet};
58use std::fmt::Debug;
59use std::path::PathBuf;
60
61use rpfm_extensions::dependencies::TableReferences;
62use rpfm_extensions::diagnostics::Diagnostics;
63use rpfm_extensions::merge::{MergeConflict, MergeOptions};
64use rpfm_extensions::optimizer::OptimizerOptions;
65use rpfm_extensions::search::{GlobalSearch, MatchHolder};
66use rpfm_extensions::translator::PackTranslation;
67
68use rpfm_lib::compression::CompressionFormat;
69use rpfm_lib::files::{
70    anim_fragment_battle::AnimFragmentBattle, anims_table::AnimsTable, atlas::Atlas, audio::Audio,
71    bmd::Bmd, db::DB, esf::ESF, group_formations::GroupFormations, image::Image, loc::Loc,
72    matched_combat::MatchedCombat, pack::PackSettings, portrait_settings::PortraitSettings,
73    rigidmodel::RigidModel, text::Text, uic::UIC, unit_variant::UnitVariant,
74    video::SupportedFormats, ContainerPath, RFile, RFileDecoded,
75};
76use rpfm_lib::games::pfh_file_type::PFHFileType;
77use rpfm_lib::integrations::git::GitResponse;
78use rpfm_lib::notes::Note;
79use rpfm_lib::schema::{Definition, DefinitionPatch, Field, Schema};
80
81use crate::helpers::*;
82use crate::settings_keys::SettingsSnapshot;
83
84//-------------------------------------------------------------------------------//
85//                              Enums & Structs
86//-------------------------------------------------------------------------------//
87
88/// This struct is a wrapper for all messages (commands and responses) sent between the UI and the server.
89///
90/// It includes a unique ID to correlate responses with their original requests.
91#[derive(Debug, Serialize, Deserialize)]
92pub struct Message<T: Debug> {
93    pub id: u64,
94    pub data: T,
95}
96
97/// This enum represents the current operational mode for a pack.
98///
99/// A pack can either be in normal mode or in MyMod mode, which links it to
100/// a specific game folder and mod name for import/export operations.
101#[derive(Debug, Default, Clone, Serialize, Deserialize)]
102pub enum OperationalMode {
103
104    /// MyMod mode enabled. Contains the game folder name (e.g. "warhammer_2") and the MyMod pack name.
105    MyMod(String, String),
106
107    /// Normal mode - no MyMod association.
108    #[default]
109    Normal,
110}
111
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct CeoEntryData {
115    pub name: String,
116    pub option: String,
117    pub element: String,
118    pub gender: String,
119    pub traits: Vec<(String, String)>, // (uuid, internal_key)
120    pub expanded: bool,
121}
122
123/// This enum defines the commands (messages) you can send to the background thread in order to execute actions.
124///
125/// Each command should include the data needed for his own execution. For a more detailed explanation, check the
126/// docs of each command.
127#[derive(Debug, Serialize, Deserialize)]
128pub enum Command {
129
130    /// Close the background thread. Do not use this command directly.
131    ///
132    /// Response: None (breaks the loop).
133    Exit,
134
135    /// Signal that the client is intentionally disconnecting.
136    ///
137    /// This allows the server to immediately clean up the session's resources instead of
138    /// waiting for the timeout. If this was the last active session, the server will also
139    /// shut down.
140    ///
141    /// Response: [`Response::Success`] (sent before cleanup begins).
142    ClientDisconnecting,
143
144    //-----------------------------------------------------------------------//
145    // PackFile Operations
146    //-----------------------------------------------------------------------//
147
148    /// Closes a specific open Pack identified by its pack key.
149    ///
150    /// Response: [`Response::Success`].
151    ClosePack(String),
152
153    /// Closes all currently open Packs.
154    ///
155    /// Response: [`Response::Success`].
156    CloseAllPacks,
157
158    /// Clean a specific open Pack from corrupted/undecoded files and try to save it to disk.
159    /// First field is the pack key, second is the destination path.
160    ///
161    /// Only use this command if your Pack is not save-able otherwise.
162    ///
163    /// Response:
164    /// - [`Response::ContainerInfo`] on success.
165    /// - [`Response::Error`] on failure.
166    CleanAndSavePackAs(String, PathBuf),
167
168    /// List all currently open packs with their keys and metadata.
169    ///
170    /// Response: [`Response::VecStringContainerInfo`].
171    ListOpenPacks,
172
173    /// Creates a new empty Pack.
174    ///
175    /// Response: [`Response::String`] with the assigned pack key.
176    NewPack,
177
178    /// Save a specific open Pack to disk. The field is the pack key.
179    ///
180    /// Response:
181    /// - [`Response::ContainerInfo`] on success.
182    /// - [`Response::Error`] on failure.
183    SavePack(String),
184
185    /// Save a specific open Pack to a new path.
186    /// First field is the pack key, second is the destination path.
187    ///
188    /// Response:
189    /// - [`Response::ContainerInfo`] on success.
190    /// - [`Response::Error`] on failure.
191    SavePackAs(String, PathBuf),
192
193    /// Get the data used to build the `TreeView` for a specific pack.
194    /// The field is the pack key.
195    ///
196    /// Response:
197    /// - [`Response::ContainerInfoVecRFileInfo`].
198    GetPackFileDataForTreeView(String),
199
200    /// Open one or more `PackFiles` and merge them. Requires the paths of the `PackFiles`].
201    ///
202    /// Response:
203    /// - [`Response::StringContainerInfo`] (pack_key, info) on success.
204    /// - [`Response::Error`] on failure.
205    OpenPackFiles(Vec<PathBuf>),
206
207    /// Open all the CA PackFiles for the selected game as one merged PackFile.
208    ///
209    /// Response:
210    /// - [`Response::StringContainerInfo`] (pack_key, info) on success.
211    /// - [`Response::Error`] on failure.
212    LoadAllCAPackFiles,
213
214    /// Get the `RFileInfo` of one or more `PackedFiles` from a specific pack.
215    /// First field is the pack key, second is the list of file paths.
216    ///
217    /// Response: [`Response::VecRFileInfo`].
218    GetPackedFilesInfo(String, Vec<String>),
219
220    /// Perform a `Global Search` on a specific pack. Requires the pack key and search configuration.
221    ///
222    /// Response:
223    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
224    /// - [`Response::Error`] if no schema.
225    GlobalSearch(String, GlobalSearch),
226
227    /// Change the `Game Selected`]. Contains the game key and whether to rebuild dependencies.
228    ///
229    /// Response:
230    /// - [`Response::CompressionFormatDependenciesInfo`] on success.
231    /// - [`Response::Error`] if game not supported.
232    SetGameSelected(String, bool),
233
234    /// Get the currently selected game key.
235    ///
236    /// Response: [`Response::String`].
237    GetGameSelected,
238
239    /// Change the `Type` of a specific open Pack.
240    /// First field is the pack key, second is the new type.
241    ///
242    /// Response: [`Response::Success`].
243    SetPackFileType(String, PFHFileType),
244
245    /// Generate the dependencies cache for the selected game.
246    ///
247    /// Response:
248    /// - [`Response::DependenciesInfo`] on success.
249    /// - [`Response::Error`] on failure.
250    GenerateDependenciesCache,
251
252    /// Update the currently loaded Schema with data from the game's Assembly Kit.
253    ///
254    /// Response:
255    /// - [`Response::Success`] on success.
256    /// - [`Response::Error`] on failure.
257    UpdateCurrentSchemaFromAssKit,
258
259    /// Trigger an optimization pass over a specific open Pack.
260    /// First field is the pack key, second is the optimizer options.
261    ///
262    /// Response:
263    /// - [`Response::HashSetStringHashSetString`] (deleted paths, added paths) on success.
264    /// - [`Response::Error`] on failure.
265    OptimizePackFile(String, OptimizerOptions),
266
267    /// Patch the SiegeAI of a Siege Map for Warhammer games in a specific pack.
268    /// The field is the pack key.
269    ///
270    /// Response:
271    /// - [`Response::StringVecContainerPath`] on success.
272    /// - [`Response::Error`] on failure.
273    PatchSiegeAI(String),
274
275    /// Change the `Index Includes Timestamp` flag in a specific open Pack.
276    /// First field is the pack key, second is the flag value.
277    ///
278    /// Response: [`Response::Success`].
279    ChangeIndexIncludesTimestamp(String, bool),
280
281    /// Change the compression format of a specific open Pack.
282    /// First field is the pack key, second is the compression format.
283    ///
284    /// Response:
285    /// - [`Response::CompressionFormat`] (the actual format set, may differ if unsupported).
286    ChangeCompressionFormat(String, CompressionFormat),
287
288    /// Get the current path of a specific open Pack.
289    /// The field is the pack key.
290    ///
291    /// Response: [`Response::PathBuf`].
292    GetPackFilePath(String),
293
294    /// Get the info of a single `PackedFile` from a specific pack.
295    /// First field is the pack key, second is the file path.
296    ///
297    /// Response: [`Response::OptionRFileInfo`].
298    GetRFileInfo(String, String),
299
300    //-----------------------------------------------------------------------//
301    // Update Commands
302    //-----------------------------------------------------------------------//
303
304    /// Check if there is an RPFM update available.
305    ///
306    /// Response:
307    /// - [`Response::APIResponse`] on success.
308    /// - [`Response::Error`] on failure.
309    CheckUpdates,
310
311    /// Check if there is a Schema update available.
312    ///
313    /// Response:
314    /// - [`Response::APIResponseGit`] on success.
315    /// - [`Response::Error`] on failure.
316    CheckSchemaUpdates,
317
318    /// Update the schemas from the remote repository.
319    ///
320    /// Response:
321    /// - [`Response::Success`] on success.
322    /// - [`Response::Error`] on failure.
323    UpdateSchemas,
324
325    /// Check if there is a Dependency Database loaded in memory.
326    /// Pass true to ensure dependencies were built with the AssKit.
327    ///
328    /// Response: [`Response::Bool`].
329    IsThereADependencyDatabase(bool),
330
331    //-----------------------------------------------------------------------//
332    // PackedFile Operations
333    //-----------------------------------------------------------------------//
334
335    /// Create a new `PackedFile` inside a specific open Pack.
336    /// First field is the pack key, then path and NewFile info.
337    ///
338    /// Response:
339    /// - [`Response::Success`] on success.
340    /// - [`Response::Error`] on failure.
341    NewPackedFile(String, String, NewFile),
342
343    /// Add one or more Files to a specific open Pack.
344    /// First field is the pack key, then source filesystem paths, destination container paths, optional paths to ignore.
345    ///
346    /// Response:
347    /// - [`Response::VecContainerPathOptionString`] (added paths, optional error message).
348    AddPackedFiles(String, Vec<PathBuf>, Vec<ContainerPath>, Option<Vec<PathBuf>>),
349
350    /// Decode a PackedFile to be shown on the UI.
351    /// First field is the pack key, then the path of the file and its data source.
352    ///
353    /// Response:
354    /// - [`Response::AnimFragmentBattleRFileInfo`] for AnimFragmentBattle files.
355    /// - [`Response::AnimPackRFileInfo`] for AnimPack files.
356    /// - [`Response::AnimsTableRFileInfo`] for AnimsTable files.
357    /// - [`Response::AtlasRFileInfo`] for Atlas files.
358    /// - [`Response::AudioRFileInfo`] for Audio files.
359    /// - [`Response::BmdRFileInfo`] for BMD files.
360    /// - [`Response::DBRFileInfo`] for DB table files.
361    /// - [`Response::ESFRFileInfo`] for ESF files.
362    /// - [`Response::GroupFormationsRFileInfo`] for GroupFormations files.
363    /// - [`Response::ImageRFileInfo`] for Image files.
364    /// - [`Response::LocRFileInfo`] for Loc files.
365    /// - [`Response::MatchedCombatRFileInfo`] for MatchedCombat files.
366    /// - [`Response::PortraitSettingsRFileInfo`] for PortraitSettings files.
367    /// - [`Response::RigidModelRFileInfo`] for RigidModel files.
368    /// - [`Response::TextRFileInfo`] for Text files.
369    /// - [`Response::UICRFileInfo`] for UIC files.
370    /// - [`Response::UnitVariantRFileInfo`] for UnitVariant files.
371    /// - [`Response::VideoInfoRFileInfo`] for Video files.
372    /// - [`Response::VMDRFileInfo`] for VMD files.
373    /// - [`Response::WSModelRFileInfo`] for WSModel files.
374    /// - [`Response::Text`] for pack notes.
375    /// - [`Response::Unknown`] for unsupported types.
376    /// - [`Response::Error`] on failure.
377    DecodePackedFile(String, String, DataSource),
378
379    /// Save an edited `PackedFile` back to a specific Pack.
380    /// First field is the pack key, then path and decoded file data.
381    ///
382    /// Response: [`Response::Success`].
383    SavePackedFileFromView(String, String, RFileDecoded),
384
385    /// Add PackedFiles from one open pack into another.
386    /// First field is the target pack key, second is the source pack key, third is the paths to copy.
387    ///
388    /// Response:
389    /// - [`Response::VecContainerPath`] on success.
390    /// - [`Response::Error`] if source pack not found.
391    AddPackedFilesFromPackFile(String, String, Vec<ContainerPath>),
392
393    /// Add PackedFiles from a specific pack to an AnimPack, which may live in a different pack.
394    /// Fields are the source pack key, the pack key that owns the AnimPack, the animpack path,
395    /// and the container paths to copy.
396    ///
397    /// Response:
398    /// - [`Response::VecContainerPath`] on success.
399    /// - [`Response::Error`] on failure.
400    AddPackedFilesFromPackFileToAnimpack(String, String, String, Vec<ContainerPath>),
401
402    /// Add PackedFiles from an AnimPack to a specific pack, which may differ from the AnimPack's own.
403    /// Fields are the pack key that owns the AnimPack (only used when the data source is a PackFile),
404    /// the destination pack key, the data source, the animpack path, and the container paths.
405    ///
406    /// Response:
407    /// - [`Response::VecContainerPath`] on success.
408    /// - [`Response::Error`] on failure.
409    AddPackedFilesFromAnimpack(String, String, DataSource, String, Vec<ContainerPath>),
410
411    /// Delete PackedFiles from an AnimPack in a specific pack.
412    /// First field is the pack key, then animpack path and container paths.
413    ///
414    /// Response:
415    /// - [`Response::Success`] on success.
416    /// - [`Response::Error`] on failure.
417    DeleteFromAnimpack(String, String, Vec<ContainerPath>),
418
419    /// Delete one or more PackedFiles from a specific pack.
420    /// First field is the pack key, second is the paths to delete.
421    ///
422    /// Response:
423    /// - [`Response::VecContainerPath`] (deleted paths).
424    DeletePackedFiles(String, Vec<ContainerPath>),
425
426    /// Copy one or more PackedFiles to the internal clipboard.
427    /// The field is a map of pack key to the paths to copy from that pack.
428    /// This stores path references in a server-side clipboard for later pasting.
429    ///
430    /// Response:
431    /// - [`Response::Success`] on success.
432    /// - [`Response::Error`] on failure.
433    CopyPackedFiles(BTreeMap<String, Vec<ContainerPath>>),
434
435    /// Cut one or more PackedFiles to the internal clipboard.
436    /// Same as copy, but the files will be removed from the source pack on paste.
437    /// The field is a map of pack key to the paths to cut from that pack.
438    ///
439    /// Response:
440    /// - [`Response::Success`] on success.
441    /// - [`Response::Error`] on failure.
442    CutPackedFiles(BTreeMap<String, Vec<ContainerPath>>),
443
444    /// Paste PackedFiles from the internal clipboard into a pack.
445    /// First field is the target pack key, second is the destination folder path.
446    ///
447    /// Response:
448    /// - [`Response::VecContainerPathVecContainerPathString`] (added paths, cut-deleted paths, source pack key) on success.
449    /// - [`Response::Error`] on failure.
450    PastePackedFiles(String, String),
451
452    /// Duplicate one or more PackedFiles in-place within the same pack.
453    /// First field is the pack key, second is the paths to duplicate.
454    /// Files are cloned with a numeric suffix added to avoid name collisions.
455    ///
456    /// Response:
457    /// - [`Response::VecContainerPath`] (new duplicated paths) on success.
458    /// - [`Response::Error`] on failure.
459    DuplicatePackedFiles(String, Vec<ContainerPath>),
460
461    /// Extract one or more PackedFiles from a pack.
462    /// First field is the pack key, then paths by data source, extraction path, whether to export tables as TSV.
463    ///
464    /// Response:
465    /// - [`Response::StringVecPathBuf`] on success.
466    /// - [`Response::Error`] on failure.
467    ExtractPackedFiles(String, BTreeMap<DataSource, Vec<ContainerPath>>, PathBuf, bool),
468
469    /// Rename one or more PackedFiles in a specific pack.
470    /// First field is the pack key, second is a Vec with original and new ContainerPaths.
471    ///
472    /// Response:
473    /// - [`Response::VecContainerPathContainerPath`] on success.
474    /// - [`Response::Error`] on failure.
475    RenamePackedFiles(String, Vec<(ContainerPath, ContainerPath)>),
476
477    /// Check if a folder exists in a specific open PackFile.
478    /// First field is the pack key, second is the folder path.
479    ///
480    /// Response: [`Response::Bool`].
481    FolderExists(String, String),
482
483    /// Check if a PackedFile exists in a specific open PackFile.
484    /// First field is the pack key, second is the file path.
485    ///
486    /// Response: [`Response::Bool`].
487    PackedFileExists(String, String),
488
489    //-----------------------------------------------------------------------//
490    // Dependency Commands
491    //-----------------------------------------------------------------------//
492
493    /// Get the table names of all DB files in dependency PackFiles.
494    ///
495    /// Response: [`Response::VecString`].
496    GetTableListFromDependencyPackFile,
497
498    /// Get custom table names (start_pos_, twad_ prefixes) from the schema.
499    ///
500    /// Response:
501    /// - [`Response::VecString`] on success.
502    /// - [`Response::Error`] if no schema.
503    GetCustomTableList,
504
505    /// Get local art set IDs from campaign_character_arts_tables in a specific pack.
506    /// The field is the pack key.
507    ///
508    /// Response: [`Response::HashSetString`].
509    LocalArtSetIds(String),
510
511    /// Get art set IDs from dependencies' campaign_character_arts_tables.
512    ///
513    /// Response: [`Response::HashSetString`].
514    DependenciesArtSetIds,
515
516    /// Get the version of a table from the dependency database.
517    ///
518    /// Response:
519    /// - [`Response::I32`] on success.
520    /// - [`Response::Error`] if not found or dependencies not loaded.
521    GetTableVersionFromDependencyPackFile(String),
522
523    /// Get the definition of a table from the dependency database.
524    ///
525    /// Response:
526    /// - [`Response::Definition`] on success.
527    /// - [`Response::Error`] if not found.
528    GetTableDefinitionFromDependencyPackFile(String),
529
530    /// Merge multiple compatible tables into one in a specific pack.
531    /// First field is the pack key, then paths to merge, merged file path, delete source flag, merge options.
532    ///
533    /// If [`MergeOptions::delta_merge`] is set and merging by key leaves unresolved conflicts, nothing is
534    /// written and the conflicts are returned instead; call this again with the same arguments plus
535    /// [`MergeOptions::resolutions`] filled in to finish the merge.
536    ///
537    /// Response:
538    /// - [`Response::String`] (merged path) on success.
539    /// - [`Response::MergeConflicts`] if delta merging left unresolved conflicts.
540    /// - [`Response::Error`] on failure.
541    MergeFiles(String, Vec<ContainerPath>, String, bool, MergeOptions),
542
543    /// Update a table to a newer version in a specific pack.
544    /// First field is the pack key, second is the container path.
545    ///
546    /// Response:
547    /// - [`Response::I32I32VecStringVecString`] (old_version, new_version, deleted_fields, added_fields) on success.
548    /// - [`Response::Error`] on failure.
549    UpdateTable(String, ContainerPath),
550
551    //-----------------------------------------------------------------------//
552    // Search Commands
553    //-----------------------------------------------------------------------//
554
555    /// Replace specific matches in a Global Search on a specific pack.
556    /// First field is the pack key, then search config and match holders.
557    ///
558    /// Response:
559    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
560    /// - [`Response::Error`] if no schema.
561    GlobalSearchReplaceMatches(String, GlobalSearch, Vec<MatchHolder>),
562
563    /// Replace all matches in a Global Search on a specific pack.
564    /// First field is the pack key, second is the search config.
565    ///
566    /// Response:
567    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
568    /// - [`Response::Error`] if no schema.
569    GlobalSearchReplaceAll(String, GlobalSearch),
570
571    /// Get reference data for columns in a definition from a specific pack.
572    /// First field is the pack key, then table name, definition, force flag.
573    ///
574    /// Response: [`Response::HashMapI32TableReferences`].
575    GetReferenceDataFromDefinition(String, String, Definition, bool),
576
577    /// Get the list of PackFiles marked as dependencies of a specific pack.
578    /// The field is the pack key.
579    ///
580    /// Response: [`Response::VecBoolString`].
581    GetDependencyPackFilesList(String),
582
583    /// Set the list of PackFiles marked as dependencies of a specific pack.
584    /// First field is the pack key, second is the dependency list.
585    ///
586    /// Response: [`Response::Success`].
587    SetDependencyPackFilesList(String, Vec<(bool, String)>),
588
589    /// Get PackedFiles from all known sources (PackFile, GameFiles, ParentFiles).
590    /// Requires: paths to get, whether to lowercase paths.
591    ///
592    /// Response: [`Response::HashMapDataSourceHashMapStringRFile`].
593    GetRFilesFromAllSources(Vec<ContainerPath>, bool),
594
595    //-----------------------------------------------------------------------//
596    // Video Commands
597    //-----------------------------------------------------------------------//
598
599    /// Change the format of a ca_vp8 video PackedFile in a specific pack.
600    /// First field is the pack key, then file path and format.
601    ///
602    /// Response:
603    /// - [`Response::Success`] on success.
604    /// - [`Response::Error`] on failure.
605    SetVideoFormat(String, String, SupportedFormats),
606
607    //-----------------------------------------------------------------------//
608    // Schema Commands
609    //-----------------------------------------------------------------------//
610
611    /// Save the provided schema to disk.
612    ///
613    /// Response:
614    /// - [`Response::Success`] on success.
615    /// - [`Response::Error`] on failure.
616    SaveSchema(Schema),
617
618    /// Encode and clean the cache for the provided paths in a specific pack.
619    /// First field is the pack key, second is the paths to clean.
620    ///
621    /// Response: [`Response::Success`].
622    CleanCache(String, Vec<ContainerPath>),
623
624    //-----------------------------------------------------------------------//
625    // TSV Commands
626    //-----------------------------------------------------------------------//
627
628    /// Export a table as TSV from a specific pack.
629    /// First field is the pack key, then internal path, destination path, data source.
630    ///
631    /// Response:
632    /// - [`Response::Success`] on success.
633    /// - [`Response::Error`] on failure.
634    ExportTSV(String, String, PathBuf, DataSource),
635
636    /// Import a TSV as a table into a specific pack.
637    /// First field is the pack key, then internal path, source TSV path.
638    ///
639    /// Response:
640    /// - [`Response::RFileDecoded`] on success.
641    /// - [`Response::Error`] on failure.
642    ImportTSV(String, String, PathBuf),
643
644    //-----------------------------------------------------------------------//
645    // External Program Commands
646    //-----------------------------------------------------------------------//
647
648    /// Open the folder containing a specific open PackFile in the file manager.
649    /// The field is the pack key.
650    ///
651    /// Response:
652    /// - [`Response::Success`] on success.
653    /// - [`Response::Error`] if pack doesn't exist on disk.
654    OpenContainingFolder(String),
655
656    /// Open a PackedFile in an external program.
657    /// First field is the pack key, then data source and container path.
658    ///
659    /// Response:
660    /// - [`Response::PathBuf`] (extracted path) on success.
661    /// - [`Response::Error`] on failure.
662    OpenPackedFileInExternalProgram(String, DataSource, ContainerPath),
663
664    /// Save a PackedFile from an external program to a specific pack.
665    /// First field is the pack key, then internal path, external file path.
666    ///
667    /// Response:
668    /// - [`Response::Success`] on success.
669    /// - [`Response::Error`] on failure.
670    SavePackedFileFromExternalView(String, String, PathBuf),
671
672    //-----------------------------------------------------------------------//
673    // Program Update Commands
674    //-----------------------------------------------------------------------//
675
676    /// Update the program to the latest version available.
677    ///
678    /// Response:
679    /// - [`Response::Success`] on success.
680    /// - [`Response::Error`] on failure.
681    UpdateMainProgram,
682
683    /// Trigger an autosave to a backup for a specific pack.
684    /// The field is the pack key.
685    ///
686    /// Response: [`Response::Success`].
687    TriggerBackupAutosave(String),
688
689    //-----------------------------------------------------------------------//
690    // Diagnostics Commands
691    //-----------------------------------------------------------------------//
692
693    /// Trigger a full diagnostics check over all open Packs.
694    /// First field is ignored diagnostics, then check AK-only references.
695    ///
696    /// Response: [`Response::Diagnostics`].
697    DiagnosticsCheck(Vec<String>, bool),
698
699    /// Trigger a partial diagnostics update over all open packs.
700    /// First field is existing diagnostics, then paths to check, check AK-only references.
701    ///
702    /// Response: [`Response::Diagnostics`].
703    DiagnosticsUpdate(Diagnostics, Vec<ContainerPath>, bool),
704
705    //-----------------------------------------------------------------------//
706    // Pack Settings Commands
707    //-----------------------------------------------------------------------//
708
709    /// Get the settings of a specific open PackFile.
710    /// The field is the pack key.
711    ///
712    /// Response: [`Response::PackSettings`].
713    GetPackSettings(String),
714
715    /// Set the settings of a specific open PackFile.
716    /// First field is the pack key, second is the settings.
717    ///
718    /// Response: [`Response::Success`].
719    SetPackSettings(String, PackSettings),
720
721    //-----------------------------------------------------------------------//
722    // Debug Commands
723    //-----------------------------------------------------------------------//
724
725    /// Export missing table definitions from a specific pack to a file (for debugging).
726    /// The field is the pack key.
727    ///
728    /// Response: [`Response::Success`].
729    GetMissingDefinitions(String),
730
731    //-----------------------------------------------------------------------//
732    // Dependencies Commands
733    //-----------------------------------------------------------------------//
734
735    /// Rebuild the dependencies.
736    /// Pass true to rebuild all dependencies, false for mod-specific only.
737    ///
738    /// Response:
739    /// - [`Response::DependenciesInfo`] on success.
740    /// - [`Response::Error`] if no schema.
741    RebuildDependencies(bool),
742
743    //-----------------------------------------------------------------------//
744    // Cascade Edition Commands
745    //-----------------------------------------------------------------------//
746
747    /// Trigger a cascade edition on all referenced data in a specific pack.
748    /// First field is the pack key, then table name, definition, list of (field, old_value, new_value).
749    ///
750    /// Response: [`Response::VecContainerPathVecRFileInfo`].
751    CascadeEdition(String, String, Definition, Vec<(Field, String, String)>),
752
753    //-----------------------------------------------------------------------//
754    // Navigation Commands
755    //-----------------------------------------------------------------------//
756
757    /// Go to the definition of a reference in a specific pack.
758    /// First field is the pack key, then table, column, values to search.
759    ///
760    /// Response:
761    /// - [`Response::DataSourceStringUsizeUsize`] on success.
762    /// - [`Response::Error`] if not found.
763    GoToDefinition(String, String, String, Vec<String>),
764
765    /// Get the source data of a loc key from a specific pack.
766    /// First field is the pack key, second is the loc key.
767    ///
768    /// Response: [`Response::OptionStringStringVecString`].
769    GetSourceDataFromLocKey(String, String),
770
771    /// Go to a loc key's location in a specific pack.
772    /// First field is the pack key, second is the loc key to search.
773    ///
774    /// Response:
775    /// - [`Response::DataSourceStringUsizeUsize`] on success.
776    /// - [`Response::Error`] if not found.
777    GoToLoc(String, String),
778
779    /// Find all references to a value in a specific pack.
780    /// First field is the pack key, then map of table -> columns to search, value to search.
781    ///
782    /// Response: [`Response::VecDataSourceStringStringStringUsizeUsize`].
783    SearchReferences(String, HashMap<String, Vec<String>>, String),
784
785    /// Get the name of a specific open PackFile.
786    /// The field is the pack key.
787    ///
788    /// Response: [`Response::String`].
789    GetPackFileName(String),
790
791    /// Get the raw binary data of a PackedFile from a specific pack.
792    /// First field is the pack key, second is the file path.
793    ///
794    /// Response:
795    /// - [`Response::VecU8`] on success.
796    /// - [`Response::Error`] on failure.
797    GetPackedFileRawData(String, String),
798
799    /// Import files from dependencies into a specific open PackFile.
800    /// First field is the pack key, second is the paths by data source.
801    ///
802    /// Response:
803    /// - [`Response::VecContainerPathVecString`] (added paths, failed paths).
804    /// - [`Response::Error`] on failure.
805    ImportDependenciesToOpenPackFile(String, BTreeMap<DataSource, Vec<ContainerPath>>),
806
807    /// Save PackedFiles to a specific PackFile and optionally optimize.
808    /// First field is the pack key, then files to save, whether to optimize.
809    ///
810    /// Response:
811    /// - [`Response::VecContainerPathVecContainerPath`] (added paths, deleted paths) on success.
812    /// - [`Response::Error`] on failure.
813    SavePackedFilesToPackFileAndClean(String, Vec<RFile>, bool),
814
815    /// Get all file names under a path in all dependencies.
816    ///
817    /// Response: [`Response::HashMapDataSourceHashSetContainerPath`].
818    GetPackedFilesNamesStartingWitPathFromAllSources(ContainerPath),
819
820    //-----------------------------------------------------------------------//
821    // Notes Commands
822    //-----------------------------------------------------------------------//
823
824    /// Get all notes under a path in a specific pack.
825    /// First field is the pack key, second is the path.
826    ///
827    /// Response: [`Response::VecNote`].
828    NotesForPath(String, String),
829
830    /// Add a note to a specific pack.
831    /// First field is the pack key, second is the note.
832    ///
833    /// Response: [`Response::Note`].
834    AddNote(String, Note),
835
836    /// Delete a note from a specific pack.
837    /// First field is the pack key, then path and note ID.
838    ///
839    /// Response: [`Response::Success`].
840    DeleteNote(String, String, u64),
841
842    //-----------------------------------------------------------------------//
843    // Schema Patch Commands
844    //-----------------------------------------------------------------------//
845
846    /// Save local schema patches.
847    ///
848    /// Response:
849    /// - [`Response::Success`] on success.
850    /// - [`Response::Error`] on failure.
851    SaveLocalSchemaPatch(HashMap<String, DefinitionPatch>),
852
853    /// Remove local schema patches for a table.
854    ///
855    /// Response:
856    /// - [`Response::Success`] on success.
857    /// - [`Response::Error`] on failure.
858    RemoveLocalSchemaPatchesForTable(String),
859
860    /// Remove local schema patches for a specific field in a table.
861    ///
862    /// Response:
863    /// - [`Response::Success`] on success.
864    /// - [`Response::Error`] on failure.
865    RemoveLocalSchemaPatchesForTableAndField(String, String),
866
867    /// Import a schema patch into the local schema patches.
868    ///
869    /// Response:
870    /// - [`Response::Success`] on success.
871    /// - [`Response::Error`] on failure.
872    ImportSchemaPatch(HashMap<String, DefinitionPatch>),
873
874    //-----------------------------------------------------------------------//
875    // Loc Generation Commands
876    //-----------------------------------------------------------------------//
877
878    /// Generate all missing loc entries for a specific open PackFile.
879    /// The field is the pack key.
880    ///
881    /// Response:
882    /// - [`Response::VecContainerPath`] on success.
883    /// - [`Response::Error`] on failure.
884    GenerateMissingLocData(String),
885
886    //-----------------------------------------------------------------------//
887    // Lua Autogen Commands
888    //-----------------------------------------------------------------------//
889
890    /// Check for updates on the tw_autogen repository.
891    ///
892    /// Response:
893    /// - [`Response::APIResponseGit`] on success.
894    /// - [`Response::Error`] on failure.
895    CheckLuaAutogenUpdates,
896
897    /// Update the tw_autogen repository.
898    ///
899    /// Response:
900    /// - [`Response::Success`] on success.
901    /// - [`Response::Error`] on failure.
902    UpdateLuaAutogen,
903
904    //-----------------------------------------------------------------------//
905    // MyMod Commands
906    //-----------------------------------------------------------------------//
907
908    /// Initialize a MyMod folder.
909    /// Requires: mod name, game key, sublime support, vscode support, git support (gitignore content).
910    ///
911    /// Response:
912    /// - [`Response::PathBuf`] (path to the new pack) on success.
913    /// - [`Response::Error`] on failure.
914    InitializeMyModFolder(String, String, bool, bool, Option<String>),
915
916    /// Live export a specific PackFile to the game folder.
917    /// The field is the pack key.
918    ///
919    /// Response:
920    /// - [`Response::Success`] on success.
921    /// - [`Response::Error`] on failure.
922    LiveExport(String),
923
924    /// Set the operational mode for a specific pack.
925    /// First field is the pack key, second is the new operational mode.
926    ///
927    /// Response: [`Response::Success`].
928    SetPackOperationalMode(String, OperationalMode),
929
930    /// Get the operational mode for a specific pack.
931    /// The field is the pack key.
932    ///
933    /// Response: [`Response::OperationalMode`].
934    GetPackOperationalMode(String),
935
936    //-----------------------------------------------------------------------//
937    // Map Packing Commands
938    //-----------------------------------------------------------------------//
939
940    /// Pack map tiles into a specific PackFile.
941    /// First field is the pack key, then tile map paths, list of (tile path, name).
942    ///
943    /// Response:
944    /// - [`Response::VecContainerPathVecContainerPath`] (added paths, deleted paths) on success.
945    /// - [`Response::Error`] on failure.
946    PackMap(String, Vec<PathBuf>, Vec<(PathBuf, String)>),
947
948    //-----------------------------------------------------------------------//
949    // Diagnostics Ignore Commands
950    //-----------------------------------------------------------------------//
951
952    /// Add a line to a specific pack's ignored diagnostics.
953    /// First field is the pack key, second is the diagnostic line.
954    ///
955    /// Response: [`Response::Success`].
956    AddLineToPackIgnoredDiagnostics(String, String),
957
958    //-----------------------------------------------------------------------//
959    // Empire/Napoleon AK Commands
960    //-----------------------------------------------------------------------//
961
962    /// Check for updates on the old AK files repository.
963    ///
964    /// Response:
965    /// - [`Response::APIResponseGit`] on success.
966    /// - [`Response::Error`] on failure.
967    CheckEmpireAndNapoleonAKUpdates,
968
969    /// Update the old AK files repository.
970    ///
971    /// Response:
972    /// - [`Response::Success`] on success.
973    /// - [`Response::Error`] on failure.
974    UpdateEmpireAndNapoleonAK,
975
976    //-----------------------------------------------------------------------//
977    // Translation Commands
978    //-----------------------------------------------------------------------//
979
980    /// Get pack translation data for a language from a specific pack.
981    /// First field is the pack key, second is the language.
982    ///
983    /// Response:
984    /// - [`Response::PackTranslation`] on success.
985    /// - [`Response::Error`] on failure.
986    GetPackTranslation(String, String),
987
988    /// Check for translation updates.
989    ///
990    /// Response:
991    /// - [`Response::APIResponseGit`] on success.
992    /// - [`Response::Error`] on failure.
993    CheckTranslationsUpdates,
994
995    /// Update the translations repository.
996    ///
997    /// Response:
998    /// - [`Response::Success`] on success.
999    /// - [`Response::Error`] on failure.
1000    UpdateTranslations,
1001
1002    //-----------------------------------------------------------------------//
1003    // Starpos Commands
1004    //-----------------------------------------------------------------------//
1005
1006    /// Build starpos (pre-processing step) for a specific pack.
1007    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1008    ///
1009    /// Response:
1010    /// - [`Response::Success`] on success.
1011    /// - [`Response::Error`] on failure.
1012    BuildStarpos(String, String, bool),
1013
1014    /// Build starpos (post-processing step) for a specific pack.
1015    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1016    ///
1017    /// Response:
1018    /// - [`Response::VecContainerPath`] on success.
1019    /// - [`Response::Error`] on failure.
1020    BuildStarposPost(String, String, bool),
1021
1022    /// Clean up starpos temporary files for a specific pack.
1023    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1024    ///
1025    /// Response:
1026    /// - [`Response::Success`] on success.
1027    /// - [`Response::Error`] on failure.
1028    BuildStarposCleanup(String, String, bool),
1029
1030    /// Get campaign IDs for starpos building from a specific pack.
1031    /// The field is the pack key.
1032    ///
1033    /// Response: [`Response::HashSetString`].
1034    BuildStarposGetCampaingIds(String),
1035
1036    /// Check if victory conditions file exists in a specific pack (required for some games).
1037    /// The field is the pack key.
1038    ///
1039    /// Response:
1040    /// - [`Response::Success`] if exists or not needed.
1041    /// - [`Response::Error`] if missing.
1042    BuildStarposCheckVictoryConditions(String),
1043
1044
1045    //-----------------------------------------------------------------------//
1046    // CEO Commands
1047    //-----------------------------------------------------------------------//
1048
1049    BuildCeo(String, String, String),
1050
1051    /// Import ceo_data.ccd into the open pack after BOB has run.
1052    /// Field is the pack key.
1053    ///
1054    /// Response:
1055    /// - [`Response::VecContainerPath`] on success.
1056    /// - [`Response::Error`] on failure.
1057    BuildCeoPost(String, String),  // pack_key, akit_path
1058
1059    BuildCeoEntries(String, Vec<CeoEntryData>),  // pack_key, entries
1060
1061
1062    GetTraitCeos,
1063
1064    //-----------------------------------------------------------------------//
1065    // Animation Commands
1066    //-----------------------------------------------------------------------//
1067
1068    /// Update animation IDs with offset in a specific pack.
1069    /// First field is the pack key, then starting ID, offset.
1070    ///
1071    /// Response:
1072    /// - [`Response::VecContainerPath`] on success.
1073    /// - [`Response::Error`] on failure.
1074    UpdateAnimIds(String, i32, i32),
1075
1076    /// Get animation paths by skeleton name.
1077    ///
1078    /// Response: [`Response::HashSetString`].
1079    GetAnimPathsBySkeletonName(String),
1080
1081    //-----------------------------------------------------------------------//
1082    // Table Commands
1083    //-----------------------------------------------------------------------//
1084
1085    /// Get tables from dependencies by table name.
1086    ///
1087    /// Response:
1088    /// - [`Response::VecRFile`] on success.
1089    /// - [`Response::Error`] on failure.
1090    GetTablesFromDependencies(String),
1091
1092    /// Get table paths by table name from a specific PackFile.
1093    /// First field is the pack key, second is the table name.
1094    ///
1095    /// Response: [`Response::VecString`].
1096    GetTablesByTableName(String, String),
1097
1098    /// Add keys to the key_deletes table in a specific pack.
1099    /// First field is the pack key, then table file name, key table name, keys to add.
1100    ///
1101    /// Response: [`Response::OptionContainerPath`].
1102    AddKeysToKeyDeletes(String, String, String, HashSet<String>),
1103
1104    //-----------------------------------------------------------------------//
1105    // 3D Export Commands
1106    //-----------------------------------------------------------------------//
1107
1108    /// Export a RigidModel to glTF format.
1109    /// Requires: RigidModel, output path.
1110    ///
1111    /// Response:
1112    /// - [`Response::Success`] on success.
1113    /// - [`Response::Error`] on failure.
1114    ExportRigidToGltf(RigidModel, String),
1115
1116    //-----------------------------------------------------------------------//
1117    // Settings Getter Commands
1118    //-----------------------------------------------------------------------//
1119
1120    /// Get a boolean setting value.
1121    ///
1122    /// Response: [`Response::Bool`].
1123    SettingsGetBool(String),
1124
1125    /// Get an i32 setting value.
1126    ///
1127    /// Response: [`Response::I32`].
1128    SettingsGetI32(String),
1129
1130    /// Get an f32 setting value.
1131    ///
1132    /// Response: [`Response::F32`].
1133    SettingsGetF32(String),
1134
1135    /// Get a string setting value.
1136    ///
1137    /// Response: [`Response::String`].
1138    SettingsGetString(String),
1139
1140    /// Get a PathBuf setting value.
1141    ///
1142    /// Response: [`Response::PathBuf`].
1143    SettingsGetPathBuf(String),
1144
1145    /// Get a `Vec<String>` setting value.
1146    ///
1147    /// Response: [`Response::VecString`].
1148    SettingsGetVecString(String),
1149
1150    /// Get raw data setting value.
1151    ///
1152    /// Response: [`Response::VecU8`].
1153    SettingsGetVecRaw(String),
1154
1155    /// Get all settings at once (for batch loading).
1156    ///
1157    /// This is much more efficient than calling individual SettingsGet* commands
1158    /// when you need multiple settings, as it requires only one IPC round-trip.
1159    ///
1160    /// Response: [`Response::SettingsAll`].
1161    SettingsGetAll,
1162
1163    //-----------------------------------------------------------------------//
1164    // Settings Setter Commands
1165    //-----------------------------------------------------------------------//
1166
1167    /// Set a boolean setting value.
1168    ///
1169    /// Response:
1170    /// - [`Response::Success`] on success.
1171    /// - [`Response::Error`] on failure.
1172    SettingsSetBool(String, bool),
1173
1174    /// Set an i32 setting value.
1175    ///
1176    /// Response:
1177    /// - [`Response::Success`] on success.
1178    /// - [`Response::Error`] on failure.
1179    SettingsSetI32(String, i32),
1180
1181    /// Set an f32 setting value.
1182    ///
1183    /// Response:
1184    /// - [`Response::Success`] on success.
1185    /// - [`Response::Error`] on failure.
1186    SettingsSetF32(String, f32),
1187
1188    /// Set a string setting value.
1189    ///
1190    /// Response:
1191    /// - [`Response::Success`] on success.
1192    /// - [`Response::Error`] on failure.
1193    SettingsSetString(String, String),
1194
1195    /// Set a PathBuf setting value.
1196    ///
1197    /// Response:
1198    /// - [`Response::Success`] on success.
1199    /// - [`Response::Error`] on failure.
1200    SettingsSetPathBuf(String, PathBuf),
1201
1202    /// Set a `Vec<String>` setting value.
1203    ///
1204    /// Response:
1205    /// - [`Response::Success`] on success.
1206    /// - [`Response::Error`] on failure.
1207    SettingsSetVecString(String, Vec<String>),
1208
1209    /// Set raw data setting value.
1210    ///
1211    /// Response:
1212    /// - [`Response::Success`] on success.
1213    /// - [`Response::Error`] on failure.
1214    SettingsSetVecRaw(String, Vec<u8>),
1215
1216    //-----------------------------------------------------------------------//
1217    // Path Commands
1218    //-----------------------------------------------------------------------//
1219
1220    /// Get the config path.
1221    ///
1222    /// Response:
1223    /// - [`Response::PathBuf`] on success.
1224    /// - [`Response::Error`] on failure.
1225    ConfigPath,
1226
1227    /// Get the Assembly Kit path for the current game.
1228    ///
1229    /// Response:
1230    /// - [`Response::PathBuf`] on success.
1231    /// - [`Response::Error`] on failure.
1232    AssemblyKitPath,
1233
1234    /// Get the backup autosave path.
1235    ///
1236    /// Response:
1237    /// - [`Response::PathBuf`] on success.
1238    /// - [`Response::Error`] on failure.
1239    BackupAutosavePath,
1240
1241    /// Get the old AK data path.
1242    ///
1243    /// Response:
1244    /// - [`Response::PathBuf`] on success.
1245    /// - [`Response::Error`] on failure.
1246    OldAkDataPath,
1247
1248    /// Get the schemas path.
1249    ///
1250    /// Response:
1251    /// - [`Response::PathBuf`] on success.
1252    /// - [`Response::Error`] on failure.
1253    SchemasPath,
1254
1255    /// Get the table profiles path.
1256    ///
1257    /// Response:
1258    /// - [`Response::PathBuf`] on success.
1259    /// - [`Response::Error`] on failure.
1260    TableProfilesPath,
1261
1262    /// Get the translations local path.
1263    ///
1264    /// Response:
1265    /// - [`Response::PathBuf`] on success.
1266    /// - [`Response::Error`] on failure.
1267    TranslationsLocalPath,
1268
1269    /// Get the dependencies cache path.
1270    ///
1271    /// Response:
1272    /// - [`Response::PathBuf`] on success.
1273    /// - [`Response::Error`] on failure.
1274    DependenciesCachePath,
1275
1276    /// Clear a config path.
1277    ///
1278    /// Response:
1279    /// - [`Response::Success`] on success.
1280    /// - [`Response::Error`] on failure.
1281    SettingsClearPath(PathBuf),
1282
1283    /// Get the user-configured custom config folder (empty path if RPFM uses the default one).
1284    ///
1285    /// Response:
1286    /// - [`Response::PathBuf`] on success.
1287    /// - [`Response::Error`] on failure.
1288    CustomConfigPath,
1289
1290    /// Set the custom config folder, or clear it when given an empty path. Takes effect on restart.
1291    ///
1292    /// Response:
1293    /// - [`Response::Success`] on success.
1294    /// - [`Response::Error`] on failure.
1295    SetCustomConfigPath(PathBuf),
1296
1297    //-----------------------------------------------------------------------//
1298    // Settings Backup Commands
1299    //-----------------------------------------------------------------------//
1300
1301    /// Backup the current settings to memory.
1302    ///
1303    /// Response: [`Response::Success`].
1304    BackupSettings,
1305
1306    /// Clear settings and reset to defaults.
1307    ///
1308    /// Response:
1309    /// - [`Response::Success`] on success.
1310    /// - [`Response::Error`] on failure.
1311    ClearSettings,
1312
1313    /// Restore settings from the backup.
1314    ///
1315    /// Response: [`Response::Success`].
1316    RestoreBackupSettings,
1317
1318    /// Get the optimizer options.
1319    ///
1320    /// Response: [`Response::OptimizerOptions`].
1321    OptimizerOptions,
1322
1323    //-----------------------------------------------------------------------//
1324    // Schema Query Commands
1325    //-----------------------------------------------------------------------//
1326
1327    /// Check if a schema is loaded.
1328    ///
1329    /// Response: [`Response::Bool`].
1330    IsSchemaLoaded,
1331
1332    /// Get all definitions for a table name.
1333    ///
1334    /// Response:
1335    /// - [`Response::VecDefinition`] on success.
1336    /// - [`Response::Error`] if no schema.
1337    DefinitionsByTableName(String),
1338
1339    /// Get columns that reference a table's definition.
1340    ///
1341    /// Response:
1342    /// - [`Response::HashMapStringHashMapStringVecString`] on success.
1343    /// - [`Response::Error`] if no schema.
1344    ReferencingColumnsForDefinition(String, Definition),
1345
1346    /// Get the current schema.
1347    ///
1348    /// Response:
1349    /// - [`Response::Schema`] on success.
1350    /// - [`Response::Error`] if no schema.
1351    Schema,
1352
1353    /// Get a specific definition by table name and version.
1354    ///
1355    /// Response:
1356    /// - [`Response::Definition`] on success.
1357    /// - [`Response::Error`] if not found or no schema.
1358    DefinitionByTableNameAndVersion(String, i32),
1359
1360    /// Delete a definition by table name and version.
1361    ///
1362    /// Response: [`Response::Success`].
1363    DeleteDefinition(String, i32),
1364
1365    /// Get the processed fields from a definition (bitwise expansion, enum conversion, colour merging applied).
1366    ///
1367    /// Response: [`Response::VecField`].
1368    FieldsProcessed(Definition),
1369
1370    /// List the user plugin scripts available under the config `scripts` folder.
1371    ///
1372    /// Response: [`Response::VecString`] with the absolute path of each script.
1373    GetPluginScripts,
1374
1375    /// Run a plugin script against a selection of files/folders from an open Pack.
1376    ///
1377    /// First field is the pack key, then the absolute path of the script to run, then the
1378    /// selected container paths. The selected files are extracted to a temp folder mirroring
1379    /// their in-pack structure (DB/Loc tables as TSV, everything else as raw binary), the script
1380    /// is run with those file paths as arguments, and their (possibly modified) contents are read
1381    /// back into the Pack afterwards.
1382    ///
1383    /// Response:
1384    /// - [`Response::VecContainerPathOptionString`] (re-imported paths, optional script output/error message).
1385    /// - [`Response::Error`] on failure.
1386    RunPluginScript(String, PathBuf, Vec<ContainerPath>),
1387}
1388
1389/// This enum defines the responses (messages) you can send to the UI thread as result of a command.
1390///
1391/// Each response is named after the types of the items it carries, making them self-documenting.
1392/// For example, `VecString` returns a `Vec<String>`, and `DBRFileInfo` returns a `(DB, RFileInfo)` tuple.
1393#[derive(Debug, Serialize, Deserialize)]
1394pub enum Response {
1395    /// Generic response for situations of success where no data needs to be returned.
1396    Success,
1397
1398    /// Generic response for situations that returned an error, containing the error message.
1399    Error(String),
1400
1401    /// Response sent by the server immediately after a WebSocket connection is established.
1402    /// Contains the session ID that the client is connected to.
1403    SessionConnected(u64),
1404
1405    #[allow(dead_code)]BmdRFileInfo(Box<Bmd>, RFileInfo),
1406    AnimFragmentBattleRFileInfo(AnimFragmentBattle, RFileInfo),
1407    AnimPackRFileInfo(Vec<RFileInfo>, RFileInfo),
1408    AnimsTableRFileInfo(AnimsTable, RFileInfo),
1409    APIResponse(APIResponse),
1410    APIResponseGit(GitResponse),
1411    AtlasRFileInfo(Atlas, RFileInfo),
1412    AudioRFileInfo(Audio, RFileInfo),
1413    Bool(bool),
1414    CompressionFormat(CompressionFormat),
1415    CompressionFormatDependenciesInfo(CompressionFormat, Option<DependenciesInfo>),
1416    ContainerInfo(ContainerInfo),
1417    ContainerInfoVecRFileInfo((ContainerInfo, Vec<RFileInfo>)),
1418    StringContainerInfo(String, ContainerInfo),
1419    DataSourceStringUsizeUsize(DataSource, String, usize, usize),
1420    DBRFileInfo(DB, RFileInfo),
1421    Definition(Definition),
1422    DependenciesInfo(DependenciesInfo),
1423    Diagnostics(Diagnostics),
1424    ESFRFileInfo(ESF, RFileInfo),
1425    F32(f32),
1426    GlobalSearchVecRFileInfo(Box<GlobalSearch>, Vec<RFileInfo>),
1427    GroupFormationsRFileInfo(GroupFormations, RFileInfo),
1428    HashMapDataSourceHashMapStringRFile(HashMap<DataSource, HashMap<String, RFile>>),
1429    HashMapDataSourceHashSetContainerPath(HashMap<DataSource, HashSet<ContainerPath>>),
1430    HashMapI32TableReferences(HashMap<i32, TableReferences>),
1431    HashMapStringHashMapStringVecString(HashMap<String, HashMap<String, Vec<String>>>),
1432    HashSetString(HashSet<String>),
1433    HashSetStringHashSetString(HashSet<String>, HashSet<String>),
1434    I32(i32),
1435    I32I32(i32, i32),
1436    I32I32VecStringVecString(i32, i32, Vec<String>, Vec<String>),
1437    ImageRFileInfo(Image, RFileInfo),
1438    LocRFileInfo(Loc, RFileInfo),
1439    MatchedCombatRFileInfo(MatchedCombat, RFileInfo),
1440    MergeConflicts(Vec<MergeConflict>),
1441    Note(Note),
1442    OperationalMode(OperationalMode),
1443    OptimizerOptions(OptimizerOptions),
1444    OptionContainerPath(Option<ContainerPath>),
1445    OptionRFileInfo(Option<RFileInfo>),
1446    OptionStringStringVecString(Option<(String, String, Vec<String>)>),
1447    PackSettings(PackSettings),
1448    PackTranslation(PackTranslation),
1449    PathBuf(PathBuf),
1450    PortraitSettingsRFileInfo(PortraitSettings, RFileInfo),
1451    RFileDecoded(RFileDecoded),
1452    RigidModelRFileInfo(RigidModel, RFileInfo),
1453    Schema(Schema),
1454    String(String),
1455    StringVecContainerPath(String, Vec<ContainerPath>),
1456    StringVecPathBuf(String, Vec<PathBuf>),
1457    Text(Text),
1458    TextRFileInfo(Text, RFileInfo),
1459    UICRFileInfo(UIC, RFileInfo),
1460    UnitVariantRFileInfo(UnitVariant, RFileInfo),
1461    Unknown,
1462    VecBoolString(Vec<(bool, String)>),
1463    VecContainerPath(Vec<ContainerPath>),
1464    VecContainerPathContainerPath(Vec<(ContainerPath, ContainerPath)>),
1465    VecContainerPathOptionString(Vec<ContainerPath>, Option<String>),
1466    VecContainerPathVecContainerPath(Vec<ContainerPath>, Vec<ContainerPath>),
1467    VecContainerPathBTreeMapStringVecContainerPath(Vec<ContainerPath>, BTreeMap<String, Vec<ContainerPath>>),
1468    VecContainerPathVecContainerPathString(Vec<ContainerPath>, Vec<ContainerPath>, String),
1469    VecContainerPathVecRFileInfo(Vec<ContainerPath>, Vec<RFileInfo>),
1470    VecContainerPathVecString(Vec<ContainerPath>, Vec<String>),
1471    VecDataSourceStringStringStringUsizeUsize(Vec<(DataSource, String, String, String, usize, usize)>),
1472    VecDefinition(Vec<Definition>),
1473    VecField(Vec<Field>),
1474    VecNote(Vec<Note>),
1475    VecRFile(Vec<RFile>),
1476    VecRFileInfo(Vec<RFileInfo>),
1477    VecString(Vec<String>),
1478    VecStringTuples(Vec<(String, String)>),
1479    VecStringContainerInfo(Vec<(String, ContainerInfo)>),
1480    VecU8(Vec<u8>),
1481    VideoInfoRFileInfo(VideoInfo, RFileInfo),
1482    VMDRFileInfo(Text, RFileInfo),
1483    WSModelRFileInfo(Text, RFileInfo),
1484
1485    /// All settings in one response (for batch loading).
1486    SettingsAll(SettingsSnapshot),
1487}