yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::core::PatchManager Class Reference

Manages a collection of ZScream-compatible ASM patches. More...

#include <patch_manager.h>

Public Member Functions

 PatchManager ()=default
 
absl::Status LoadPatches (const std::string &patches_dir)
 Load all patches from a directory structure.
 
absl::Status ReloadPatches ()
 Reload patches from the current directory.
 
const std::vector< std::string > & folders () const
 Get list of patch folder names.
 
std::vector< AsmPatch * > GetPatchesInFolder (const std::string &folder)
 Get all patches in a specific folder.
 
AsmPatchGetPatch (const std::string &folder, const std::string &filename)
 Get a specific patch by folder and filename.
 
const std::vector< std::unique_ptr< AsmPatch > > & patches () const
 Get all loaded patches.
 
int GetEnabledPatchCount () const
 Get count of enabled patches.
 
absl::Status ApplyEnabledPatches (Rom *rom)
 Apply all enabled patches to a ROM.
 
absl::Status GenerateCombinedPatch (const std::string &output_path)
 Generate a combined .asm file that includes all enabled patches.
 
absl::Status SaveAllPatches ()
 Save all patches to their files.
 
absl::Status CreatePatchFolder (const std::string &folder_name)
 Create a new patch folder.
 
absl::Status RemovePatchFolder (const std::string &folder_name)
 Remove a patch folder and all its contents.
 
absl::Status AddPatchFile (const std::string &source_path, const std::string &target_folder)
 Add a patch file from an external source.
 
absl::Status RemovePatchFile (const std::string &folder, const std::string &filename)
 Remove a patch file.
 
const std::string & patches_directory () const
 Get the patches directory path.
 
bool is_loaded () const
 Check if patches have been loaded.
 

Private Member Functions

void ScanDirectory (const std::string &dir_path, const std::string &folder_name)
 Scan a directory for .asm files.
 

Private Attributes

std::vector< std::string > folders_
 
std::vector< std::unique_ptr< AsmPatch > > patches_
 
std::string patches_directory_
 
bool is_loaded_ = false
 

Detailed Description

Manages a collection of ZScream-compatible ASM patches.

PatchManager handles patch discovery, loading, organization, and application. It expects patches to be organized in a directory structure like:

patches_dir/
├── Misc/
│ ├── IntroSkip.asm
│ └── ...
├── Sprites/
│ ├── Spike Damage.asm
│ └── ...
├── Hex Edits/
│ └── ...
└── UNPATCHED/ (ignored)

Definition at line 36 of file patch_manager.h.

Constructor & Destructor Documentation

◆ PatchManager()

yaze::core::PatchManager::PatchManager ( )
default

Member Function Documentation

◆ LoadPatches()

absl::Status yaze::core::PatchManager::LoadPatches ( const std::string & patches_dir)

Load all patches from a directory structure.

Parameters
patches_dirPath to the patches root directory
Returns
Status indicating success or failure

Definition at line 17 of file patch_manager.cc.

References folders_, is_loaded_, patches_, patches_directory_, and ScanDirectory().

Referenced by yaze::editor::SettingsPanel::DrawPatchSettings(), and ReloadPatches().

Here is the call graph for this function:

◆ ReloadPatches()

absl::Status yaze::core::PatchManager::ReloadPatches ( )

Reload patches from the current directory.

Definition at line 65 of file patch_manager.cc.

References LoadPatches(), and patches_directory_.

Here is the call graph for this function:

◆ folders()

const std::vector< std::string > & yaze::core::PatchManager::folders ( ) const
inline

Get list of patch folder names.

Definition at line 55 of file patch_manager.h.

References folders_.

Referenced by yaze::editor::SettingsPanel::DrawPatchSettings().

◆ GetPatchesInFolder()

std::vector< AsmPatch * > yaze::core::PatchManager::GetPatchesInFolder ( const std::string & folder)

Get all patches in a specific folder.

Parameters
folderThe folder name (e.g., "Sprites")
Returns
Vector of pointers to patches in that folder

Definition at line 85 of file patch_manager.cc.

References patches_.

Referenced by yaze::editor::SettingsPanel::DrawPatchList().

◆ GetPatch()

AsmPatch * yaze::core::PatchManager::GetPatch ( const std::string & folder,
const std::string & filename )

Get a specific patch by folder and filename.

Parameters
folderThe folder name
filenameThe filename (e.g., "Spike Damage.asm")
Returns
Pointer to the patch, or nullptr if not found

Definition at line 99 of file patch_manager.cc.

References patches_.

◆ patches()

const std::vector< std::unique_ptr< AsmPatch > > & yaze::core::PatchManager::patches ( ) const
inline

Get all loaded patches.

Definition at line 75 of file patch_manager.h.

References patches_.

Referenced by yaze::editor::SettingsPanel::DrawPatchSettings().

◆ GetEnabledPatchCount()

int yaze::core::PatchManager::GetEnabledPatchCount ( ) const

Get count of enabled patches.

Definition at line 109 of file patch_manager.cc.

References patches_.

Referenced by ApplyEnabledPatches(), and yaze::editor::SettingsPanel::DrawPatchSettings().

◆ ApplyEnabledPatches()

absl::Status yaze::core::PatchManager::ApplyEnabledPatches ( Rom * rom)

Apply all enabled patches to a ROM.

Parameters
romThe ROM to patch
Returns
Status indicating success or failure

Definition at line 119 of file patch_manager.cc.

References yaze::core::AsarWrapper::ApplyPatch(), GenerateCombinedPatch(), GetEnabledPatchCount(), yaze::core::AsarWrapper::Initialize(), yaze::Rom::is_loaded(), yaze::Rom::mutable_vector(), and patches_directory_.

Referenced by yaze::editor::SettingsPanel::DrawPatchSettings().

◆ GenerateCombinedPatch()

absl::Status yaze::core::PatchManager::GenerateCombinedPatch ( const std::string & output_path)

Generate a combined .asm file that includes all enabled patches.

Parameters
output_pathPath to write the combined patch file
Returns
Status indicating success or failure

The generated file can be applied using Asar directly. It uses incsrc directives to include each enabled patch file.

Definition at line 176 of file patch_manager.cc.

References patches_.

Referenced by ApplyEnabledPatches().

◆ SaveAllPatches()

absl::Status yaze::core::PatchManager::SaveAllPatches ( )

Save all patches to their files.

Returns
Status indicating success or failure

Definition at line 225 of file patch_manager.cc.

References patches_.

Referenced by yaze::editor::SettingsPanel::DrawPatchSettings().

◆ CreatePatchFolder()

absl::Status yaze::core::PatchManager::CreatePatchFolder ( const std::string & folder_name)

Create a new patch folder.

Parameters
folder_nameThe name of the new folder
Returns
Status indicating success or failure

Definition at line 245 of file patch_manager.cc.

References folders_, and patches_directory_.

◆ RemovePatchFolder()

absl::Status yaze::core::PatchManager::RemovePatchFolder ( const std::string & folder_name)

Remove a patch folder and all its contents.

Parameters
folder_nameThe folder to remove
Returns
Status indicating success or failure

Definition at line 273 of file patch_manager.cc.

References folders_, patches_, and patches_directory_.

◆ AddPatchFile()

absl::Status yaze::core::PatchManager::AddPatchFile ( const std::string & source_path,
const std::string & target_folder )

Add a patch file from an external source.

Parameters
source_pathPath to the source .asm file
target_folderFolder to add the patch to
Returns
Status indicating success or failure

Definition at line 313 of file patch_manager.cc.

References folders_, patches_, and patches_directory_.

◆ RemovePatchFile()

absl::Status yaze::core::PatchManager::RemovePatchFile ( const std::string & folder,
const std::string & filename )

Remove a patch file.

Parameters
folderThe folder containing the patch
filenameThe patch filename
Returns
Status indicating success or failure

Definition at line 354 of file patch_manager.cc.

References patches_, and patches_directory_.

◆ patches_directory()

const std::string & yaze::core::PatchManager::patches_directory ( ) const
inline

Get the patches directory path.

Definition at line 142 of file patch_manager.h.

References patches_directory_.

◆ is_loaded()

bool yaze::core::PatchManager::is_loaded ( ) const
inline

Check if patches have been loaded.

Definition at line 147 of file patch_manager.h.

References is_loaded_.

◆ ScanDirectory()

void yaze::core::PatchManager::ScanDirectory ( const std::string & dir_path,
const std::string & folder_name )
private

Scan a directory for .asm files.

Parameters
dir_pathPath to the directory
folder_nameName to assign to patches found

Definition at line 72 of file patch_manager.cc.

References patches_.

Referenced by LoadPatches().

Member Data Documentation

◆ folders_

std::vector<std::string> yaze::core::PatchManager::folders_
private

◆ patches_

std::vector<std::unique_ptr<AsmPatch> > yaze::core::PatchManager::patches_
private

◆ patches_directory_

std::string yaze::core::PatchManager::patches_directory_
private

◆ is_loaded_

bool yaze::core::PatchManager::is_loaded_ = false
private

Definition at line 160 of file patch_manager.h.

Referenced by is_loaded(), and LoadPatches().


The documentation for this class was generated from the following files: