yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::cli::agent::tools::CodeGenToolBase Class Reference

Base class for code generation tools. More...

#include <code_gen_tool.h>

Inherits yaze::cli::resources::CommandHandler.

Inherited by yaze::cli::agent::tools::CodeGenAsmHookTool, yaze::cli::agent::tools::CodeGenEventHandlerTool, yaze::cli::agent::tools::CodeGenFreespacePatchTool, and yaze::cli::agent::tools::CodeGenSpriteTemplateTool.

Collaboration diagram for yaze::cli::agent::tools::CodeGenToolBase:

Protected Member Functions

absl::Status ValidateHookAddress (Rom *rom, uint32_t address) const
 Validate that an address is safe for hooking.
 
std::vector< FreeSpaceRegionDetectFreeSpace (Rom *rom, size_t min_size=0x100) const
 Detect available free space regions in ROM.
 
std::string SubstitutePlaceholders (const std::string &template_code, const std::map< std::string, std::string > &params) const
 Substitute placeholders in template with parameter values.
 
absl::StatusOr< AsmTemplateGetTemplate (const std::string &name) const
 Get a built-in ASM template by name.
 
const std::vector< AsmTemplate > & GetAllTemplates () const
 Get all available built-in templates.
 
std::string FormatResultAsJson (const CodeGenerationResult &result) const
 Format code generation result as JSON.
 
std::string FormatResultAsText (const CodeGenerationResult &result) const
 Format code generation result as text.
 
bool IsKnownHookLocation (uint32_t address) const
 Check if an address is within a known safe hook location.
 
std::string GetHookLocationDescription (uint32_t address) const
 Get description of a known hook location.
 
- Protected Member Functions inherited from yaze::cli::resources::CommandHandler
virtual absl::Status ValidateArgs (const ArgumentParser &parser)=0
 Validate command arguments.
 
virtual absl::Status Execute (Rom *rom, const ArgumentParser &parser, OutputFormatter &formatter)=0
 Execute the command business logic.
 
virtual std::string GetDefaultFormat () const
 Get the default output format ("json" or "text")
 
virtual std::string GetOutputTitle () const
 Get the output title for formatting.
 

Static Private Member Functions

static std::vector< AsmTemplateInitializeTemplates ()
 

Static Private Attributes

static const std::vector< AsmTemplatekTemplates
 
static const std::map< std::string, uint32_t > kKnownHooks
 

Additional Inherited Members

- Public Member Functions inherited from yaze::cli::resources::CommandHandler
virtual ~CommandHandler ()=default
 
absl::Status Run (const std::vector< std::string > &args, Rom *rom_context, std::string *captured_output=nullptr)
 Execute the command.
 
virtual std::string GetName () const =0
 Get the command name.
 
virtual Descriptor Describe () const
 Provide metadata for TUI/help summaries.
 
virtual std::string GetUsage () const =0
 Get the command usage string.
 
virtual bool RequiresRom () const
 Check if the command requires a loaded ROM.
 
virtual bool RequiresLabels () const
 Check if the command requires ROM labels.
 
virtual void SetProjectContext (project::YazeProject *project)
 Set the YazeProject context. Default implementation does nothing, override if tool needs project info.
 
virtual void SetAsarWrapper (core::AsarWrapper *asar_wrapper)
 Set the AsarWrapper context. Default implementation does nothing, override if tool needs Asar access.
 
virtual void SetRomContext (Rom *rom)
 Set the ROM context for tools that need ROM access. Default implementation stores the ROM pointer for subclass use.
 
- Protected Attributes inherited from yaze::cli::resources::CommandHandler
Romrom_ = nullptr
 
project::YazeProjectproject_ = nullptr
 
core::AsarWrapperasar_wrapper_ = nullptr
 

Detailed Description

Base class for code generation tools.

Provides common functionality for ASM code generation:

  • Template management and substitution
  • Freespace detection and validation
  • Address validation
  • Hook location checking

Definition at line 106 of file code_gen_tool.h.

Member Function Documentation

◆ ValidateHookAddress()

absl::Status yaze::cli::agent::tools::CodeGenToolBase::ValidateHookAddress ( Rom * rom,
uint32_t address ) const
protected

Validate that an address is safe for hooking.

Definition at line 84 of file code_gen_tool.cc.

◆ DetectFreeSpace()

std::vector< FreeSpaceRegion > yaze::cli::agent::tools::CodeGenToolBase::DetectFreeSpace ( Rom * rom,
size_t min_size = 0x100 ) const
protected

Detect available free space regions in ROM.

Definition at line 121 of file code_gen_tool.cc.

◆ SubstitutePlaceholders()

std::string yaze::cli::agent::tools::CodeGenToolBase::SubstitutePlaceholders ( const std::string & template_code,
const std::map< std::string, std::string > & params ) const
protected

Substitute placeholders in template with parameter values.

Replaces {{PLACEHOLDER}} with corresponding values from params map.

Definition at line 178 of file code_gen_tool.cc.

◆ GetTemplate()

absl::StatusOr< AsmTemplate > yaze::cli::agent::tools::CodeGenToolBase::GetTemplate ( const std::string & name) const
protected

Get a built-in ASM template by name.

Definition at line 192 of file code_gen_tool.cc.

◆ GetAllTemplates()

const std::vector< AsmTemplate > & yaze::cli::agent::tools::CodeGenToolBase::GetAllTemplates ( ) const
protected

Get all available built-in templates.

Definition at line 203 of file code_gen_tool.cc.

◆ FormatResultAsJson()

◆ FormatResultAsText()

std::string yaze::cli::agent::tools::CodeGenToolBase::FormatResultAsText ( const CodeGenerationResult & result) const
protected

◆ IsKnownHookLocation()

bool yaze::cli::agent::tools::CodeGenToolBase::IsKnownHookLocation ( uint32_t address) const
protected

Check if an address is within a known safe hook location.

Definition at line 207 of file code_gen_tool.cc.

◆ GetHookLocationDescription()

std::string yaze::cli::agent::tools::CodeGenToolBase::GetHookLocationDescription ( uint32_t address) const
protected

Get description of a known hook location.

Definition at line 216 of file code_gen_tool.cc.

◆ InitializeTemplates()

std::vector< AsmTemplate > yaze::cli::agent::tools::CodeGenToolBase::InitializeTemplates ( )
staticprivate

Definition at line 39 of file code_gen_tool.cc.

Member Data Documentation

◆ kTemplates

const std::vector< AsmTemplate > yaze::cli::agent::tools::CodeGenToolBase::kTemplates
staticprivate
Initial value:

Definition at line 159 of file code_gen_tool.h.

◆ kKnownHooks

const std::map< std::string, uint32_t > yaze::cli::agent::tools::CodeGenToolBase::kKnownHooks
staticprivate
Initial value:
= {
{"EnableForceBlank", 0x00893D},
{"Overworld_LoadMapProperties", 0x02AB08},
{"Overworld_LoadSubscreenAndSilenceSFX1", 0x02AF19},
{"Sprite_OverworldReloadAll", 0x09C499},
}

Definition at line 162 of file code_gen_tool.h.


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