API Reference



Mod Fix


RaidenBossFixService

class RaidenBossFixService(path: Optional[str] = None, keepBackups: bool = True, fixOnly: bool = False, undoOnly: bool = False, readAllInis: bool = False, log: bool = False, verbose: bool = True, handleExceptions: bool = False)

The overall class for fixing the Raiden Shogun Boss for Raiden Shogun mods

Parameters
  • path (Optional[str]) –

    The file location of where to run the fix.

    If this attribute is set to None, then will run the fix from wherever this class is called

    Default: None

  • keepBackups (bool) –

    Whether to keep backup versions of any .ini files that the script fixes

    Default: True

  • fixOnly (bool) –

    Whether to only fix the mods without removing any previous changes this fix script may have made

    Warning

    if this is set to True and undoOnly is also set to True, then the fix will not run and will throw a ConflictingOptions exception


    Default: False

  • undoOnly (bool) –

    Whether to only undo the fixes previously made by the fix

    Warning

    if this is set to True and fixOnly is also set to True, then the fix will not run and will throw a ConflictingOptions exception


    Default: True

  • readAllInis (bool) –

    Whether to read all the .ini files that the fix encounters

    Default: False

  • log (bool) –

    Whether to log the run of the fix in a seperate text file

    Default: False

  • verbose (bool) –

    Whether to print the progress for fixing mods

    Default: True

  • handleExceptions (bool) –

    When an exception is caught, whether to silently stop running the fix

    Default: False

log

Whether to log the run of the fix in a seperate text file

Type

bool

_loggerBasePrefix

The prefix string for the logger used when the fix returns back to the original directory that it started to run

Type

str

logger

The logger used to pretty print messages

Type

Logger

_path

The file location of where to run the fix.

Type

str

keepBackups

Whether to keep backup versions of any .ini files that the script fixes

Type

bool

fixOnly

Whether to only fix the mods without removing any previous changes this fix script may have made

Type

bool

undoOnly

Whether to only undo the fixes previously made by the fix

Type

bool

readAllInis

Whether to read all the .ini files that the fix encounters

Type

bool

verbose

Whether to print the progress for fixing mods

Type

bool

handleExceptions

When an exception is caught, whether to silently stop running the fix

Type

bool

_logFile

The file path of where to generate a log .txt file

Type

str

_pathIsCWD

Whether the filepath that the program runs from is the current directory where this module is loaded

Type

bool

modsFixed

The number of mods that have been fixed

Type

int

skippedMods

All the mods that have been skipped

The keys are the absolute path to the mod folder and the values are the exception that caused the mod to be skipped

Type

Dict[str, BaseException]

blendsFound

The number of Blend.buf files found within the found mods

Type

int

blendsFixed

The absolute paths to all the Blend.buf files that have been fixed

Type

Set[str]

skippedBlends

The Blend.buf files that got skipped

  • The outer key is the absolute path to the mod folder

  • The inner key is the absolute path to the Blend.buf file

  • The value in the inner dictionary is the exception that caused the Blend.buf file to be skipped

Type

Dict[str, Dict[str, BaseException]]

skippedBlendsCount

The count for how many Blend.buf files got skipped

Type

int

inisFixed

The absolute paths to the fixed .ini files

Type

Set[str]

inisSkipped

The .ini files that got skipped

The keys are the absolute file paths to the .ini files and the values are exceptions that caused the .ini file to be skipped

Type

Dict[str, BaseException]

_fix()

The overall logic for fixing a bunch of mods

For finding out which folders may contain mods, this function:
  1. recursively searches all folders from where the RaidenBossFixService.path is located

  2. for every .ini file in a valid mod and every Blend.buf file encountered that is encountered, recursively search all the folders from where the .ini file or Blend.buf file is located

Note

For more info about how we define a ‘mod’, go to Mod

_setupModPath()

Sets the filepath of where the fix will run from

addTips()

Prints out any useful tips for the user to know

createLog()

Creates a log text file that contains all the text printed on the command line

createMod(path: Optional[str] = None, files: Optional[List[str]] = None) Mod

Creates a mod

Note

For more info about how we define a ‘mod’, go to Mod

Parameters
  • path (Optional[str]) –

    The absolute path to the mod folder.

    If this argument is set to None, then will use the current directory of where this module is loaded

  • files (Optional[List[str]]) –

    The direct children files to the mod folder (does not include files located in a folder within the mod folder).

    If this parameter is set to None, then the module will search the folders for you

Returns

The mod that has been created

Return type

Mod

fix()

Fixes a bunch of mods

see _fix() for more info

fixIni(ini: IniFile, mod: Mod, fixedRemapBlends: Dict[str, RemapBlendModel]) bool

Fixes an individual .ini file for a particular mod

Note

For more info about how we define a ‘mod’, go to Mod

Parameters
  • ini (IniFile) – The .ini file to fix

  • mod (Mod) – The mod being fixed

  • fixedRemapBlends (Dict[str, RemapBlendModel]) – All of the RemapBlend.buf files that have already been fixed.

    The keys are the absolute filepath to the fixed RemapBlend.buf file and the values contains the data related to the fixed RemapBlend.buf file

Returns

Whether the particular .ini file has been fixed

Return type

bool

fixMod(mod: Mod, fixedRemapBlends: Dict[str, RemapBlendModel]) bool

Fixes a particular mod

Note

For more info about how we define a ‘mod’, go to Mod

Parameters
  • mod (Mod) – The mod being fixed

  • fixedRemapBlends (Dict[str, RemapBlendModel]) – all of the RemapBlend.buf files that have already been fixed.

    The keys are the absolute filepath to the fixed RemapBlend.buf files and the values contains the data related to the fixed RemapBlend.buf file

Returns

Whether the particular mod has been fixed

Return type

bool

property path: str

The filepath of where the fix is running from

Getter

Returns the path of where the fix is running

Setter

Sets the path for where the fix runs

Type

str

property pathIsCwd

Whether the filepath that the program runs from is the current directory where this module is loaded

Getter

Returns whether the filepath that the program runs from is the current directory of where the module is loaded

Type

bool

reportSkippedAsset(assetName: str, assetDict: Dict[str, BaseException], warnStrFunc: Callable[[str], str])

Prints out the exception message for why a particular .ini file or Blend.buf file has been skipped

Parameters
  • assetName (str) – The name for the type of asset (files, folders, mods, etc…) that was skipped

  • assetDict (Dict[str, BaseException]) –

    Locations of where exceptions have occured for the particular asset

    The keys are the absolute folder paths to where the exception occured

  • wantStrFunc (Callable[[str], str]) –

    Function for how we want to print out the warning for each exception

    Takes in the folder location of where the exception occured as a parameter

reportSkippedMods()

Prints out all of the mods that were skipped due to exceptions

Note

For more info about how we define a ‘mod’, go to Mod

warnSkippedBlends(modPath: str)

Prints out all of the Blend.buf files that were skipped due to exceptions

Parameters

modPath (str) – The absolute path to a particular folder


Mod

class Mod(path: Optional[str] = None, files: Optional[List[str]] = None, logger: Optional[Logger] = None)

This Class inherits from Model

Used for handling a mod

Note

We define a mod based off the following criteria:

  • A folder that contains at least 1 .ini file

  • At least 1 of the .ini files in the folder contains:

Parameters
  • path (Optional[str]) –

    The file location to the mod folder.

    If this value is set to None, then will use the current directory of where this module is loaded.

    Default: None

  • files (Optional[List[str]]) –

    The direct children files to the mod folder (does not include files located in a folder within the mod folder).

    If this parameter is set to None, then the class will search the files for you when the class initializes

    Default: None

  • logger (Optional[Logger]) –

    The logger used to pretty print messages

    Default: None

path

The file location to the mod folder

Type

Optional[str]

_files

The direct children files to the mod folder (does not include files located in a folder within the mod folder).

Type

List[str]

logger

The logger used to pretty print messages

Type

Optional[Logger]

inis

The .ini files found for the mod

Type

List[str]

remapBlend

The RemapBlend.buf files found for the mod

Type

List[str]

backupInis

The DISABLED_RSFixBackup.txt files found for the mod

Type

List[str]

backupDups

The DISABLED_RSDup.txt files found for the mod

Warning

This attribute is now DEPRECATED. Now, the fix does not care whether there are duplicate .ini files or Blend.buf files

Type

List[str]

_setupFiles()

Searches the direct children files to the mod folder if Mod.files is set to None

classmethod blendCorrection(blendFile: Union[str, bytes], fixedBlendFile: Optional[str] = None) Union[str, bytes]

Fixes a Blend.buf file

Parameters
  • blendFile (Union[str, bytes]) – The file path to the Blend.buf file to fix

  • fixedBlendFile (Optional[str]) –

    The file path for the fixed Blend.buf file

    Default: None

Raises

BlendFileNotRecognized – If the original Blend.buf file provided by the parameter blendFile cannot be read

Returns

If the argument fixedBlendFile is None, then will return bytes for the fixed Blend.buf file

Otherwise will return the filename fo the fixed RemapBlend.buf file

Return type

Union[str, bytes]

correctBlend(fixedRemapBlends: Dict[str, RemapBlendModel])

Fixes all the Blend.buf files reference by the mod

Requires all the .ini files in the mod to have ran their IniFile.parse() function

Parameters

fixedRemapBlends (Dict[str, RemapBlendModel]) – All of the RemapBlend.buf files that have already been fixed.

The keys are the absolute filepath to the fixed RemapBlend.buf file and the values contains the data related to the fixed RemapBlend.buf file

property files

The direct children files to the mod folder (does not include files located in a folder within the mod folder).

Getter

Returns the files to the mod

Setter

Sets up the files for the mod

Type

Optional[List[str]]

getOptionalFiles() List[Optional[str]]

Retrieves a list of each type of files that are not mandatory for the mod

Returns

The resultant files found for the following file categories (listed in the same order as the return type):

  1. .ini files

  2. .RemapBlend.buf files

  3. DISABLED_RSFixBackup.txt files

  4. DISABLED_RSDup.txt files

Note

See Mod.isIni(), Mod.isRemapBlend(), Mod.isBackupIni() or Mod.isBackupDupFile() for the specifics of each type of file

Return type

[ List[str], List[str], List[str], List[str] ]

classmethod isBackupDupFile(file: str) bool

Warning

This function is now DEPRECATED. Now, the fix does not care whether there are duplicate .ini files or Blend.buf files

Determines whether the file is a DISABLED_RSDup.txt file that is used to disable duplicate .ini files or Blend.buf files

Parameters

file (str) – The file path to check

Returns

Whether the passed in file is a DISABLED_RSDup.txt file

Return type

bool

classmethod isBackupIni(file: str) bool

Determines whether the file is a DISABLED_RSFixBackup.txt file that is used to make backup copies of .ini files

Parameters

file (str) – The file path to check

Returns

Whether the passed in file is a DISABLED_RSFixBackup.txt file

Return type

bool

classmethod isBlend(file: str) bool

Determines whether the file is a Blend.buf file which is the original blend file provided in the mod

Parameters

file (str) – The file path to check

Returns

Whether the passed in file is a Blend.buf file

Return type

bool

classmethod isIni(file: str) bool

Determines whether the file is a .ini file which is the file used to control how a mod behaves

Parameters

file (str) – The file path to check

Returns

Whether the passed in file is a .ini file

Return type

bool

classmethod isRemapBlend(file: str) bool

Determines whether the file is a RemapBlend.buf file which is the fixed Blend.buf file created by this fix

Parameters

file (str) – The file path to check

Returns

Whether the passed in file is a RemapBlend.buf file

Return type

bool

print(funcName: str, *args, **kwargs)

Prints out output

Parameters
  • funcName (str) – The name of the function in the logger for printing out the output

  • *args (List[str]) – Arguments to pass to the function in the logger

  • **kwargs (Dict[str, Any]) – Keyword arguments to pass to the function in the logger

Returns

The return value from running the corresponding function in the logger

Return type

Any

removeBackupDups()

Removes all DISABLED_RSDup.txt contained in the mod

removeBackupInis()

Removes all DISABLED_RSFixBackup.txt contained in the mod

removeFix(fixedBlends: Set[str], fixedInis: Set[str], keepBackups: bool = True, fixOnly: bool = False)

Removes any previous changes done by this module’s fix

Parameters
  • fixedBlend (Set[str]) – The file paths to the RemapBlend.buf files that we do not want to remove

  • fixedInis (Set[str]) – The file paths to the .ini files that we do not want to remove

  • keepBackups (bool) –

    Whether to create or keep DISABLED_RSFixBackup.txt files in the mod

    Default: True

  • fixOnly (bool) –

    Whether to not undo any changes created in the .ini files

    Default: False



Ini Files


IniFile

class IniFile(file: Optional[str] = None, logger: Optional[Logger] = None, txt: str = '', mustBeRaiden: bool = True)

This class inherits from Model

Class for handling .ini files


Note

We analyse the .ini file using Regex which is NOT the right way to do things since the modified .ini language that GIMI interprets is a CFG (context free grammer) and NOT a regular language.

But since we are lazy and don’t want make our own compiler with tokenizers, parsing algorithms (eg. SLR(1)), type checking, etc… this module should handle regular cases of .ini files generated using existing scripts (assuming the user does not do anything funny…)


Parameters
  • file (Optional[str]) –

    The file path to the .ini file

    Default: None

  • logger (Optional[Logger]) – The logger to print messages if necessary

  • txt (str) –

    Used as the text content of the .ini file if IniFile.file is set to None

    Default: “”

  • mustBeRaiden (bool) –

    Whether the .ini file has to be used for a Raiden mod

    Default: True

file

The file path to the .ini file

Type

str

_parser

Parser used to parse very basic cases in a .ini file

Type

ConfigParser

_fileLines

The file lines read from the .ini file

Type

List[str]

_fileLinesRead

Whether the file for the .ini file has been read

Type

bool

_isRaidenFixed

Whether the .ini file has already been fixed

Type

bool

_isRaidenIni

Whether the .ini file is used for a Raiden mod

Type

bool

mustBeRaiden

Whether the .ini file has to be used for a Raiden mod

Type

bool

_textureOverrideBlendRoot

The name for the section containing the keywords: [.*TextureOverride.*Blend.*]

Type

Optional[str]

_sectionIfTemplates

All the sections in the .ini file that can be parsed into an IfTemplate

For more info see IfTemplate

Warning

The modified .ini language that GIMI uses introduces keywords that can be used before the key of a key-value pair

eg. defining constants

1[Constants]
2global persist $swapvar = 0
3global persist $swapscarf = 0
4global $active
5global $creditinfo = 0


Sections containing this type of pattern will not be parsed. But generally, these sections are irrelevant to fixing the Raiden Boss

Type

Dict[str, IfTemplate]

_resourceBlends

Sections that are linked to 1 or more Blend.buf files.

The keys are the name of the sections.

Type

Dict[str, IfTemplate]

_blendCommands

All the sections that use some [Resource.*Blend.*] section.

The keys are the name of the sections.

Type

Dict[str, IfTemplate]

_blendCommandsRemapNames

The new names for the sections that use some [Resource.*Blend.*] section that will be used in the fix.

The keys are the original names of the sections in the .ini file

Type

Dict[:class`str`, str]

_blendCommandsTuples

All the sections that use some [Resource.*Blend.*] section while maitaining the order that sections have been called

Note

This attribute is the same as IniFile._blendCommands except that the order that sections are called in the call stack is preserved

Type

List[Tuple[str, IfTemplate]]

_resourceCommands

All the related sections to the [Resource.*Blend.*] sections that are used by sections related to the [TextureOverride.*Blend.*] sections. The keys are the name of the sections.

Type

Dict[str, IfTemplate]

_resourceCommandsRemapNames

The new names to be used in the fix for all the related sections to the [Resource.*Blend.*] sections that are used by sections related to [TextureOverride.*Blend.*] sections.

The keys are the original names of the sections in the .ini file

Type

Dict[str, str]

_resouceCommandsTuples

All the related sections to the [Resource.*Blend.*] sections that are used by sections related to [TextureOverride.*Blend.*] sections while maitaining the order that the sections have been called

Note

This attribute is the same as IniFile._resourceCommands except that the order that sections are called in the call stack is preserved

Type

List[Tuple[str, IfTemplate]]

remapBlendModelsDict

The data for the [Resource.*RemapBlend.*] sections used in the fix

The keys are the original names of the resource with the pattern [Resource.*Blend.*]

Type

Dict[str, RemapBlendModel]

remapBlendModels

The data for the [Resource.*RemapBlend.*] sections used in the fix

Note

This attribute is the same as the values of IniFile.remapBlendModelsDict by calling:

1list(remapBlendModelsDict.values())
Type

List[RemapBlendModel]

_addFixBoilerPlate()

Decorator used to add the boilerplate code to identify a code section has been changed by this fix in the .ini file

Examples

1@_addFixBoilerPlate
2def helloWorld(self) -> str:
3    return "Hello World"
_checkRaidenFixed(line: str)

Checks if a line of text matches the regex, [.*TextureOverride.*RemapBlend.*] ,to identify whether the .ini file has been fixed

Parameters

line (str) – The line of text to check

_checkRaidenIni(line: str)

Checks if a line of text contains the keywords to identify whether the .ini file is a Raiden mod

  • If IniFile.mustBeRaiden is True, then will see if the line matches with the regex, [.*TextureOverride.*(Raiden|Shogun).*Blend.*]

  • Otherwise, will see if the line matches with the regex, [.*TextureOverride.*Blend.*]

Parameters

line (str) – The text to check

_getBlendResources(sectionName: str, blendResources: Set[str], subCommands: Set[str], subCommandLst: List[str])

Low level function for retrieving all the referenced resources that were called by sections related to the [TextureOverride.*Blend.*] sections

Parameters
  • sectionName (str) – The name of the section in the .ini file that we want to get the blend resources from

  • blendResources (Set[str]) – The result for all the resource sections that were referenced

  • subCommands (Set[str]) – The result for all of the sub-sections that were called from the [TextureOverride.*Blend.*] section

  • subCommandLst (List[str]) – The result for all of the sub-sections that were called from the [TextureOverride.*Blend.*] section that maintains the order the sections are called in the call stack

Raises

KeyError – If the IfTemplate is not found for some section related to the [TextureOverride.*Blend.*] section

_getCommandIfTemplate(sectionName: str, raiseException: bool = True) Optional[IfTemplate]

Low level function for retrieving the IfTemplate for a certain section from IniFile._sectionIfTemplate

Parameters
  • sectionName (str) – The name of the section

  • raiseException (bool) – Whether to raise an exception when the section’s IfTemplate is not found

Raises

KeyError – If the IfTemplate for the section is not found and raiseException is set to True

Returns

The corresponding IfTemplate for the section

Return type

Optional[IfTemplate]

_getCommands(sectionName: str, subCommands: Set[str], subCommandLst: List[str])

Low level function for retrieving all the commands/sections that are called from a certain section in the .ini file

Parameters
  • sectionName (str) – The name of the section we are starting from

  • subCommands (Set[str]) – The result for all of the sections that were called

  • subCommandLst (List[str]) – The result for all of the sections that were called while maintaining the order the sections are called in the call stack

Raises

KeyError – If the IfTemplate is not found for some section

_getIfTemplateResourceName(ifTemplatePart: Dict[str, Any]) Any

Retrieves the value from the key, ‘vb1’, for some part of a section

Parameters

ifTemplatePart (Dict[str, Any]) – The key-value pairs for some part in a section

Returns

The corresponding value for the key ‘vb1’

Return type

Any

_getIfTemplateSubCommand(ifTemplatePart: Dict[str, Any]) Any

Retrieves the value from the key, ‘run’, for some part of a section

Parameters

ifTemplatePart (Dict[str, Any]) – The key-value pairs for some part in a section

Returns

The corresponding value for the key ‘run’

Return type

Any

_getResourceSortKey(resourceTuple: Tuple[str, Any]) int

Retrieves the index number of a resource created by GIMI’s genshin_merge_mods.py script as an integer

Note

See IniFile.getMergedResourceIndex() for more info

Parameters

resourceTuple (Tuple[str, Any]) – The name of the resource section and its content

Returns

The index for the resource section

Return type

int

_isIfTemplateDraw(ifTemplatePart: Dict[str, Any]) bool

Whether the content for some part of a section contains the key ‘draw’

Parameters

ifTemplatePart (Dict[str, Any]) – The key-value pairs for some part in a section

Returns

Whether ‘draw’ is contained in the part

Return type

bool

_isIfTemplateResource(ifTemplatePart: Dict[str, Any]) bool

Whether the content for some part of a section contains the key ‘vb1’

Parameters

ifTemplatePart (Dict[str, Any]) – The key-value pairs for some part in a section

Returns

Whether ‘vb1’ is contained in the part

Return type

bool

_isIfTemplateSubCommand(ifTemplatePart: Dict[str, Any]) bool

Whether the content for some part of a section contains the key ‘run’

Parameters

ifTemplatePart (Dict[str, Any]) – The key-value pairs for some part in a section

Returns

Whether ‘run’ is contained in the part

Return type

bool

_makeRemapModels() Dict[str, RemapBlendModel]

Low level function to create all the data needed for fixing the [Resource.*Blend.*] sections in the .ini file

Returns

The data for fixing the resource sections

The keys are the names for the resource sections and the values are the required data for fixing the sections

Return type

Dict[str, RemapBlendModel]

_parseSection(sectionName: str, srcTxt: str, save: Optional[Dict[str, Any]] = None) Optional[Dict[str, str]]

Regularly parses the key-value pairs of a certain section

The function parses uses ConfigParser to parse the section.

Parameters
  • sectionName (str) – The name of the section

  • srcTxt (str) – The text containing the entire section

  • save (Optional[Dict[str, Any]]) –

    Place to save the parsed result for the section

    The result for the parsed section will be saved as a value in the dictionary while section’s name will be used in the key for the dictionary

    Default: None

Returns

The result from parsing the section

Note

If ConfigParser is unable to parse the section, then None is returned

Return type

Optional[Dict[str, str]]

_processIfTemplate(startInd: int, endInd: int, fileLines: List[str], sectionName: str, srcTxt: str) IfTemplate

Parses a section in the .ini file as an IfTemplate

Note

See IfTemplate to see how we define an ‘IfTemplate’

Parameters
  • startInd (int) – The starting line index of the section

  • endInd (int) – The ending line index of the section

  • fileLines (List[str]) – All the file lines read from the .ini file

  • sectionName (str) – The name of the section

  • srcTxt (str) – The text content of the section

Returns

The generated IfTemplate from the section

Return type

IfTemplate

_readLines()

Decorator to read all the lines in the .ini file first before running a certain function

All the file lines will be saved in IniFile._fileLines

Examples

1@_readLines
2def printLines(self):
3    for line in self._fileLines:
4        print(f"LINE: {line}")
_removeFix() str

Removes any previous changes that were probably made by this script

For the .ini file will remove:

  1. All code surrounded by the ‘—…— Raiden Boss Fix —…—-’ header/footer

  2. All sections containing the keywords RemapBlend

Returns

The new text content of the .ini file with the changes removed

Return type

str

_removeSection(startInd: int, endInd: int, fileLines: List[str], sectionName: str, srcTxt: str) Tuple[int, int]

Retrieves the starting line index and ending line index of where to remove a certain section from the read lines of the .ini file

Parameters
  • startInd (int) – The starting line index of the section

  • endInd (int) – The ending line index of the section

  • fileLines (List[str]) – All the file lines read from the .ini file

  • sectionName (str) – The name of the section

  • srcTxt (str) – The text content of the section

Returns

The starting line index and the ending line index of the section to remove

Return type

Tuple[int, int]

checkRaidenIni(mustBeRaiden: Optional[bool] = None) bool

Reads the entire .ini file and checks whether the .ini file is a Raiden mod that needs to be fixed

Note

If the .ini file has already been parsed (eg. calling IniFile.checkRaidenIni() or IniFile.parse()), then

you only need to read the IniFile._isRaidenIni

Parameters

mustBeRaiden (Optional[bool]) – Whether the .ini file being checked has to be a Raiden mod

Returns

Whether the .ini file is a .ini file that needs to be fixed

Return type

bool

clearRead()

Clears all the saved text read in from the .ini file

disIni()

Disables the .ini file

Note

For more info, see FileService.disableFile()

fillIfTemplate(sectionName: str, ifTemplate: IfTemplate, fillFunc: Callable[[str, Union[str, Dict[str, Any]], int, int, str], str], origSectionName: Optional[str] = None) str

Creates a new IfTemplate for an existing section in the .ini file

Parameters
  • sectionName (str) – The new name of the section

  • ifTemplate (IfTemplate) – The IfTemplate of the orginal section

  • fillFunc (Callable[[str, Union[str, Dict[str, Any], int, str, str], str]]) –

    The function to create a new content part for the new IfTemplate

    Note

    For more info about an ‘IfTemplate’, see IfTemplate


    The parameter order for the function is:

    1. The new section name

    2. The corresponding content part in the original IfTemplate

    3. The index for the content part in the original IfTemplate

    4. The string to prefix every line in the content part of the IfTemplate

    5. The original name of the section

  • origSectionName (Optional[str]) –

    The original name of the section.

    If this argument is set to None, then will assume this argument has the same value as the argument for sectionName

    Default: None

Returns

The text for the newly created IfTemplate

Return type

str

fillRemapResource(sectionName: str, part: Dict[str, Any], partIndex: int, linePrefix: str, origSectionName: str)

Creates the content part of an IfTemplate for the new sections created by this fix related to the [Resource.*Blend.*] sections

Note

For more info about an ‘IfTemplate’, see IfTemplate

Parameters
  • sectionName (str) – The new name for the section

  • part (Dict[str, Any]) – The content part of the IfTemplate of the original [Resource.*Blend.*] section

  • partIndex (int) – The index of where the content part appears in the IfTemplate of the original section

  • linePrefix (str) – The text to prefix every line of the created content part

  • origSectionName (str) – The name of the original section

Returns

The created content part

Return type

str

fillTextureOverrideRemapBlend(sectionName: str, part: Dict[str, Any], partIndex: int, linePrefix: str, origSectionName: str) str

Creates the content part of an IfTemplate for the new sections created by this fix related to the [TextureOverride.*Blend.*] sections

Note

For more info about an ‘IfTemplate’, see IfTemplate

Parameters
  • sectionName (str) – The new name for the section

  • part (Dict[str, Any]) – The content part of the IfTemplate of the original [TextureOverrideBlend] section

  • partIndex (int) – The index of where the content part appears in the IfTemplate of the original section

  • linePrefix (str) – The text to prefix every line of the created content part

  • origSectionName (str) – The name of the original section

Returns

The created content part

Return type

str

fix(keepBackup: bool = True, fixOnly: bool = False) str

Fixes the .ini file

Parameters
  • keepBackup (bool) –

    Whether we want to make a backup copy of the .ini file

    Default: True

  • fixOnly (bool) –

    Whether we are only fixing the .ini file without removing any previous changes

    Default: False

Returns

The new content of the .ini file which includes the fix

Return type

str

getFileLines() List[str]

Reads each line in the .ini file

Returns

All the lines of the .ini file

Return type

List[str]

classmethod getFixFooter() str

Retrieves the footer text used to identify a code section has been changed by this fix in the .ini file

classmethod getFixHeader() str

Retrieves the header text used to identify a code section has been changed by this fix in the .ini file

classmethod getFixedBlendFile(blendFile: str) str

Retrieves the file path for the fixed RemapBlend.buf file

Parameters

blendFile (str) – The file path to the original Blend.buf file

Returns

The file path of the fixed RemapBlend.buf file

Return type

str

classmethod getMergedResourceIndex(mergedResourceName: str) str

Retrieves the index number of a resource created by GIMI’s genshin_merge_mods.py script

Examples

>>> IniFile.getMergedResourceIndex("ResourceCuteLittleEiBlend.8")
8
Parameters

mergedResourceName (str) – The name of the section

Returns

The index for the resource section

Return type

str

classmethod getRemapName(name: str) str

Changes a section name to have the keyword ‘RemapBlend’ to identify that the section is created by this fix

This function either replace the keyword ‘Blend’ with ‘RemapBlend’ or adds ‘RemapBlend’

Examples

>>> IniFile.getRemapName("EiTriesToUseBlenderAndFails")
"EiTriesToUseRemapBlenderAndFails"
>>> IniFile.getRemapName("EiBlendsTheBlender")
"EiBlendsTheRemapBlender"
>>> IniFile.getRemapName("ResourceCuteLittleEi")
"ResourceCuteLittleEiRemapBlend"
Parameters

name (str) – The name of the section

Returns

The name of the section with the added ‘RemapBlend’ keyword

Return type

str

classmethod getRemapResourceName(name: str) str

Changes the name of a section to be a new resource that this fix will create

Parameters

name (str) – The name of the section

Returns

The name of the section with the prefix ‘Resource’ and the keyword ‘Remap’ added

Return type

str

classmethod getResourceName(name: str) str

Makes the name of a section to be used for the resource sections of a .ini file

Examples

>>> IniFile.getResourceName("CuteLittleEi")
"ResourceCuteLittleEi"
Parameters

name (str) – The name of the section

Returns

The name of the section as a resource in a .ini file

Return type

str

property isRaidenFixed

Whether the .ini file has already been fixed

Getter

Returns whether the .ini file has already been fixed

Type

bool

property isRaidenIni

Whether the .ini file is a for a Raiden mod

Getter

Returns whether the .ini file is a for a Raiden mod

Type

bool

parse()

Parses the .ini file

Raises

KeyError – If a certain resource section is not found

(either the name of the section is not found in the .ini file or the section was skipped due to some error when parsing the section)

read() str

Reads the .ini file

Returns

The text content of the .ini file

Return type

str

classmethod removeResourceName(name: str) str

Removes the ‘Resource’ prefix from a section’s name

Examples

>>> IniFile.removeResourceName("ResourceCuteLittleEi")
"CuteLittleEi"
>>> IniFile.removeResourceName("LittleMissGanyu")
"LittleMissGanyu"
Parameters

name (str) – The name of the section

Returns

The name of the section with the ‘Resource’ prefix removed

Return type

str

removeSectionOptions(section: Union[str, Pattern, Callable[[str], bool]])

Removes a certain type of section from the .ini file

Parameters

section (Union[str, Pattern, Callable[[str], bool]]) – The type of section to remove

write() str

Writes back into the .ini files based off the content in IniFile._fileLines

Returns

The text that is written to the .ini file

Return type

str


IfTemplate

Methods
class IfTemplate(parts: List[Union[str, Dict[str, Any]]], calledSubCommands: Optional[Dict[int, str]] = None)

Data for storing information about a section in a .ini file


Note

Assuming every if/else clause must be on its own line, we have that an IfTemplate have a form looking similar to this:

 1...(does stuff)...
 2...(does stuff)...
 3if ...(bool)...
 4    if ...(bool)...
 5        ...(does stuff)...
 6    else if ...(bool)...
 7        ...(does stuff)...
 8    endif
 9else ...(bool)...
10    if ...(bool)...
11        if ...(bool)...
12            ...(does stuff)...
13        endif
14    endif
15endif
16...(does stuff)...
17...(does stuff)...

We split the above structure into parts where each part is either:

  1. An If Part: a single line containing the keywords “if”, “else” or “endif”
    OR

  2. A Content Part: a group of lines that “does stuff”

Note that: an ifTemplate does not need to contain any parts containing the keywords “if”, “else” or “endif”. This case covers the scenario when the user does not use if..else statements for a particular section

Based on the above assumptions, we can assume that every [section] in a .ini file contains this IfTemplate


Supported Operations:

for element in x

Iterates over all the parts of the IfTemplate, x

x[num]

Retrieves the part from the IfTemplate, x, at index num

x[num] = newPart

Sets the part at index num of the IfTemplate, x, to have the value of newPart


Parameters
  • parts (List[Union[str, Dict[str, Any]]]) – The individual parts of how we divided an IfTemplate described above

  • calledSubCommands (Optional[Dict[int, str]]) –

    Any other sections that this IfTemplate references

    The keys are the indices to the part in the IfTemplate that the section is called

    Default: None

parts

The individual parts of how we divided an IfTemplate described above

Type

List[Union[str, Dict[str, Any]]]

calledSubCommands

Any other sections that this IfTemplate references

The keys are the indices to the part in the IfTemplate that the section is called

Type

Optional[Dict[int, str]]

add(part: Union[str, Dict[str, Any]])

Adds a part to the ifTemplate

Parameters

part (Union[str, Dict[str, Any]]) – The part to add to the IfTemplate

find(pred: Optional[Callable[[Union[str, Dict[str, Any]]], bool]] = None, postProcessor: Optional[Callable[[Union[str, Dict[str, Any]]], Any]] = None) Dict[int, Any]

Searches the IfTemplate for parts that meet a certain condition

Parameters
  • pred (Optional[Callable[[Union[str, Dict[str, Any]]], bool]]) –

    The predicate used to filter the parts

    If this value is None, then this function will return all the parts

    Default: None

  • postProcessor (Optional[Callable[[Union[str, Dict[str, Any]]], Any]]) –

    A function that performs any post-processing on the found part that meets the required condition

    Default: None



Model


Models

Attributes
Methods
class Model(logger: Optional[Logger] = None)

Generic class used for any data models in the fix

Parameters

logger (Optional[Logger]) –

The logger used to print messages to the console

Default: None

logger

The logger used to print messages to the console

Type

Optional[Logger]

print(funcName: str, *args, **kwargs)

Prints out output

Parameters
  • funcName (str) – The name of the function in the logger for printing out the output

  • *args (List[str]) – Arguments to pass to the function in the logger

  • **kwargs (Dict[str, Any]) – Keyword arguments to pass to the function in the logger

Returns

The return value from running the corresponding function in the logger

Return type

Any


RemapBlendModel

class RemapBlendModel(iniFolderPath: str, fixedBlendName: str, fixedBlendPaths: Dict[int, str], origBlendName: Optional[str] = None, origBlendPaths: Optional[Dict[int, str]] = None)

Contains data for fixing a particular resource in a .ini file

Parameters
  • iniFolderPath (str) – The folder path to where the .ini file of the resource is located

  • fixedBlendName (str) – The new name of the resource once all the Blend.buf files for the resource has been fixed

  • fixedBlendPaths (Dict[int, str]) – The file paths to the fixed RemapBlend.buf files for the resource

    The keys are the indices that the Blend.buf file appears in the IfTemplate for some resource

  • origBlendName (Optional[str]) –

    The original name of the resource in the .ini file

    Default: None

  • origBlendPaths (Optional[Dict[int, str]]) –

    The file paths to the Blend.buf files for the resource

    The keys are the indices that the Blend.buf file appears in the IfTemplate for some resource

    Default: None

iniFolderPath

The folder path to where the .ini file of the resource is located

Type

str

fixedBlendName

The new name of the resource once all the Blend.buf files for the resource has been fixed

Type

str

fixedBlendPaths

The file paths to the fixed RemapBlend.buf files for the resource

The keys are the indices that the Blend.buf file appears in the IfTemplate for the resource

Type

Dict[int, str]

origBlendName

The original name of the resource in the .ini file

Type

Optional[str]

origBlendPaths

The file paths to the Blend.buf files for the resource

The keys are the indices that the Blend.buf file appears in the IfTemplate for the resource

Type

Optional[Dict[int, str]]

fullPaths

The absolute paths to the fixed RemapBlend.buf files for the resource

The keys are the indices that the Blend.buf file appears in the IfTemplate for the resource

Type

Dict[int, str]

origFullPaths

The absolute paths to the Blend.buf files for the resource

The keys are the indices that the Blend.buf file appears in the IfTemplate for the resource

Type

Dict[int, str]



Views


Logger

class Logger(prefix: str = '', logTxt: bool = False, verbose: bool = True)

Class for pretty printing output to display on the console

Parameters
  • prefix (str) –

    line that is printed before any message is printed out

    Default: “”

  • logTxt (bool) –

    Whether to log all the printed messages into a .txt file once the fix is done

    Default: False

  • verbose (bool) –

    Whether to print out output

    Default: True

_prefix

line that is printed before any message is printed out

Type

str

_headingTxtLen

The number of characters used for the name of the opening heading

Type

int

_headingSideLen

The number of characters used to make side border of an opening/closing heading

Type

int

_headingChar

The character used to make the border of an opening/closing heading

Type

str

includePrefix

Whether to include the prefix string when printing out a message

Type

bool

verbose

Whether to print out output

Type

bool

logTxt

Whether to log all the printed messages into a .txt file once the fix is done

Type

bool

_loggedTxt

The text that will be logged into a .txt file

Type

str

_addLogTxt(txt: str)

Appends the text to the logged output to be printed to a .txt file

Parameters

txt (str) – The text to be added onto the logged output

_setDefaultHeadingAtts()

Sets the default attributes for printing out a header line

box(message: str, header: str)

Prints the message to be sandwiched by the text defined in the argument, header

Parameters
  • message (str) – The message we want to print out

  • header (str) – The string that we want to sandwich our message against

bulletPoint(txt: str)

Prints out an item in an unordered list

Parameters

txt (str) – The message we want to print out

closeHeading()

Prints out a closing heading that corresponds to a previous opening heading printed

error(message: str)

Prints an error message

Parameters

message (str) – The message we want to print out

classmethod getBulletStr(txt: str) str

Creates the string for an item in an unordered list

Parameters

txt (str) – The message we want to print out

Returns

The text formatted as an item in an unordered list

Return type

str

classmethod getNumberedStr(txt: str, num: int) str

Creates the string for an ordered list

Parameters
  • txt (str) – The message we want to print out

  • num (str) – The number we want to print out before the text for the ordered list

Returns

The text formatted as an item in an ordered list

Return type

str

getStr(message: str)

Retrieves the string to be printed out by the logger

Parameters

message (str) – The message we want to print out

Returns

The transformed text that the logger prints out

Return type

str

classmethod getWarnStr(exception: Error) str

Retrieves the string for a warning

Parameters

exception (Error) – The warning we want to handle

Returns

The warning string

Return type

str

handleException(exception: BaseException)

Prints the message for an error

Parameters

exception (BaseException) – The error we want to handle

input(desc: str) str

Handles user input from the console

Parameters

desc (str) – The question/description being asked to the user for input

Returns

The resultant input the user entered

Return type

str

list(lst: List[str], transform: Optional[Callable[[str], str]] = None)

Prints out an ordered list

Parameters
  • lst (List[str]) – The list of messages we want to print out

  • transform (Optional[Callable[[str], str]]) –

    A function used to do any processing on each message in the list of messages

    If this parameter is None, then the list of message will not go through any type of processing

    Default: None

log(message: str)

Regularly prints text onto the console

Parameters

message (str) – The message we want to print out

property loggedTxt

The text to be logged into a .txt file

Getter

Returns such a prefix

Type

str

note(message: str)

Prints an important note that the user should take note of

Parameters

message (str) – The message we want to print out

openHeading(txt: str, sideLen: int = 2, headingChar='=')

Prints out an opening heading

Parameters
  • txt (str) – The message we want to print out

  • sideLen (int) –

    How many characters we want for the side border of the heading

    Default: 2

  • headingChar (str) –

    The character used to print the side border of the heading

    Default: “=”

property prefix

The line of text that is printed before any message is printed out

Getter

Returns such a prefix

Setter

Sets up such a prefix for the logger

Type

str

space()

Prints out a space

split()

Prints out a new line

waitExit()

Prints the message used when the script finishes running

warn(exception: Error)

Prints a warning

Parameters

exception (Error) – The warning we want to handle



Utilities


FileService

class FileService

Tools for handling with files and folders

classmethod absPathOfRelPath(dstPath: str, relFolder: str) str

Retrieves the absolute path of the relative path of a file with respect to a certain folder

Parameters
  • dstPath (str) – The target file path we are working with

  • relFolder (str) – The folder that the target file path is relative to

Returns

The absolute path for the target file

Return type

str

classmethod changeExt(file: str, newExt: str) str

Changes the extension for a file

Parameters
  • file (str) – The file path to the file we are working with

  • newExt (str) – The name of the new extension for the file (without the dot at front)

Returns

the new file path with the extension changed

Return type

str

classmethod disableFile(file: str, filePrefix: str = 'DISABLED_RSFixBackup_')

Marks a file as ‘DISABLED’ and changes the file to a .txt file

Parameters
  • file (str) – The file path to the file we are working with

  • filePrefix (str) –

    Prefix name we want to add in front of the file name

    Default: “DISABLED_RSFixBackup_”

classmethod getFiles(path: Optional[str] = None, filters: List[Callable[[str], bool]] = [], files: Optional[List[str]] = None) Union[List[str], List[List[str]]]

Retrieves many different types of files within a folder

Parameters
  • path (Optional[str]) –

    The path to the target folder we are working with. If this value is set to None, then will use the current directory of where this module is loaded

    Default: None

  • filters (List[Callable[[str], bool]]) –

    Different filter functions for each type of file we are trying to get

    Default: []

  • files (Optional[List[str]]) –

    The files contained in the target folder

    If this value is set to None, then the function will search for the files

    Default: None

Returns

The files partitioned into the different types specified by the filters

If ‘filters’ only has 1 element, then the function returns List[str] Otherwise, will return List[List[str]]

Return type

Union[List[str], List[List[str]]]

classmethod getFilesAndDirs(path: Optional[str] = None, recursive: bool = False) List[List[str]]

Retrieves the files and folders contained in a certain folder

Parameters
  • path (Optional[str]) –

    The path to the target folder we are working with. If this argument is None, then will use the current directory of where this module is loaded

    Default: None

  • recursive (bool) –

    Whether to recursively check all the folders from our target folder

    Default: False

Returns

The files and directories within the folder. The order for the result is:

  1. files

  2. folders

Return type

[List[str], List[str]]

classmethod getRelPath(path: str, start: str) str

Tries to get the relative path of a file/folder relative to another folder, if possible.

If it is not possible to get the relative path, will return back the original file path

Note

An example where it would not be possible to get the relative path would be:

  • If the file is located in one mount (eg. C:/ drive) and the folder is located in another mount (eg. D:/ drive)

Parameters
  • path (str) – The path to the target file/folder we are working with

  • start (str) – The path that the target file/folder is relative to

Returns

Either the relative path or the original path if not possible to get the relative paths

Return type

str

classmethod getSingleFiles(path: Optional[str] = None, filters: Dict[str, Callable[[str], bool]] = {}, files: Optional[List[str]] = None, optional: bool = False) Union[str, None, List[str], List[Optional[str]]]

Retrieves exactly 1 of each type of file in a folder

Parameters
  • path (Optional[str]) –

    The path to the target folder we are searching.

    If this value is set to None, then will use the current directory of where this module is loaded

    Default: None

  • filters (Dict[str, Callable[[str], bool]]) –

    Different filter functions for each type of file we are trying to get.

    The keys are the names for the file type

    Default: {}

  • files (Optional[List[str]]) –

    The files contained in the target folder

    If this value is set to None, then the function will search for the files

    Default: None

  • optional (bool) –

    Whether we want to send an exception if there is not exactly 1 file for a certain type of file

    1. If this value is False and there are no files for a certain type of file, then will raise a MissingFileException

    2. If this value is False and there are more than 1 file for a certain type of file, then will raise a DuplicateFileException

    3. If this value is True and there are no files for a certain type of file, then the file for that type of file will be None

    4. If this value is True and there are more than 1 file for a certain type of file, then will retrieve the first file for that type of file

    Default: False

Raises
  • MissingFileException – if optional is set to False and there are not files for a certain type of file

  • DuplicateFileException – if optional is set to False and there are more than 1 file for a certain type of file

Returns

The files partitioned for each type of file

  • If filters only contains 1 element and optional is False, then will return str

  • If filters contains more than 1 element and optional is ``False`, then will return List[str]

  • If filters only contains 1 element and optional is True, then will return Optional[str]

  • Otherwise, returns List[Optional[str]]

Return type

Union[Optional[str], List[str], List[Optional[str]]]

classmethod isFile(path: str, file: str) bool

Checks whether a file path is a file

Parameters
  • path (str) – The file path to the folder where the file is contained

  • file (str) – The name of the file

Returns

Whether the combined file path is a file

Return type

bool

classmethod ntPathToPosix(path: str) str

Converts a file path from the ntpath library to a file path for the os library

Note

The character for the folder paths (/ or \) used in both libraries may be different depending on the OS

Parameters

path (str) – The file path we are working that is generated from the ‘ntpath’ library

Returns

The file path generated by the ‘os’ library

Return type

str

classmethod parseOSPath(path: str)

Retrieves a normalized file path from a string

Parameters

path (str) – The string containing some sort of file path

classmethod read(file: str, fileCode: str, postProcessor: Callable[[TextIoWrapper], Any]) Any

Tries to read a file using different file encodings

Will interact with the file using the following order of encodings:

  1. utf-8

  2. latin1

Parameters
  • file (str) – The file we are trying to read from

  • fileCode (str) – What file mode to interact with the file (eg. r, rb, r+, etc…)

  • postProcessor (Callable[[TextIoWrapper], Any]) – A function used to process the file pointer of the opened file

Returns

The result after processing the file pointer of the opened file

Return type

Any

classmethod rename(oldFile: str, newFile: str)

Renames a file

Warning

If the new name for the file already exists, then the function deletes the file with the new name and renames the target file with the new name

Parameters
  • oldFile (str) – file path to the target file we are working with

  • newFile (str) – new file path for the target file


ListTools

class ListTools

Tools for handling with lists

classmethod getDistinct(lst: List[T]) List[T]

Retrieves a list with distinct values

Parameters

lst (List[T]) – The list that we are working with

Returns

A list where all values are distinct

Return type

List[T]

classmethod to_dict(lst: List[T], get_id: Callable[[T], Hashable]) Dict[Hashable, T]

Turns a list into a dictionary

Parameters
  • lst (List[T]) – The list that we want to turn into a dictionary

  • get_id (Callable[[T], Hashable]) – The function for generating ids for the list

Returns

The transformed dictionary from the list

Return type

Dict[Hashable, T]


DictTools

class DictTools

Tools for handling with Dictionaries

classmethod combine(dst: Dict[Hashable, Any], src: Dict[Hashable, Any], combineDuplicate: Optional[Callable[[Any, Any], Any]] = None)

Combines 2 dictionaries

Parameters
  • dst (Dict[Hashable, Any]) – The destination of where we want the combined dictionaries to be stored

  • src (Dict[Hashable, Any]) – The that we want to combine values with

  • combineDuplicate (Optional[Callable[[Any, Any], Any]]) –

    Function for handling cases where there contains the same key in both dictionaries

    If this value is set to None, then will use the key from ‘dst’

    Default: None

classmethod getFirstKey(dict: Dict[Any, Any]) Any

Retrieves the first key in a dictionary

Parameters

dict (Dict[Any, Any]) – The dictionary we are working with

Returns

The first key of the dictionary

Return type

Any

classmethod getFirstValue(dict: Dict[Any, Any]) Any

Retrieves the first value in a dictionary

Parameters

dict (Dict[Any, Any]) – The dictionary we are working with

Returns

The first value of the dictionary

Return type

Any



Exceptions


Error

Methods
class Error(message: str)

The base exception used by this module

Parameters

message (str) – the error message to print out

warn()

Retrieves the warning message for the exception


FileException

Attributes
Methods
class FileException(message: str, path: Optional[str] = None)

This Class inherits from Error

Exceptions relating to files

Parameters
  • message (str) – The error message to print out

  • path (Optional[str]) –

    The path where the error for the file occured. If this value is None, then the path will be the current directory where this module is loaded

    Default: None

warn()

Retrieves the warning message for the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.


DuplicateFileException

Methods
class DuplicateFileException(files: List[str], fileType: str = 'file', path: Optional[str] = None)

This Class inherits from FileException

Exception when there are multiple files of the same type in a folder

Parameters
  • files (List[str]) – The files that triggered the exception

  • fileType (str) –

    The name for the type of files

    Default: “file”

  • path (Optional[str]) –

    The path to the folder where the files are located If this value is None, then the path will be the current directory where this module is loaded

    Default: None

files

The files that triggered the exception

Type

List[str]

fileType

The name for the type of files

Default: None

Type

str

warn()

Retrieves the warning message for the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.


MissingFileException

Methods
class MissingFileException(fileType: str = 'file', path: Optional[str] = None)

This Class inherits from FileException

Exception when a certain type of file is missing from a folder

Parameters
  • fileType (str) –

    The type of file searching in the folder

    Default: “file”

  • path (str) –

    The path to the folder that is being searched. If this value is None, then the path will be the current directory where this module is loaded

    Default: None

fileType

The type of file searching in the folder

Type

str

warn()

Retrieves the warning message for the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.


BlendFileNotRecognized

Attributes
Methods
class BlendFileNotRecognized(blendFile: str)

This Class inherits from FileException

Exception when a Blend.buf file cannot be read

Parameters

blendFile (str) – The file path to the Blend.buf file

warn()

Retrieves the warning message for the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.


ConflictingOptions

Attributes
Methods
class ConflictingOptions(options: List[str])

This Class inherits from Error

Exception when the script or RaidenBossFixService is ran with options that cannot be used together

Parameters

options (List[str]) – The options that cannot be used together

warn()

Retrieves the warning message for the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.