API Reference
Mod Fix
BossFixService
- def_fix
- def_printModsToFix
- def_setupDefaultModType
- def_setupLogPath
- def_setupModPath
- def_setupModTypes
- defaddTips
- defclear
- defcreateLog
- defcreateMod
- deffix
- deffixIni
- deffixMod
- defreportSkippedAsset
- defreportSkippedMods
- defwarnSkippedBlends
- class BossFixService(path: Optional[str] = None, keepBackups: bool = True, fixOnly: bool = False, undoOnly: bool = False, readAllInis: bool = False, types: Optional[str] = None, defaultType: Optional[str] = None, log: Optional[str] = None, verbose: bool = True, handleExceptions: bool = False)
The overall class for fixing bosses for particular 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:
NonekeepBackups (
bool) –Whether to keep backup versions of any .ini files that the script fixes
Default:
TruefixOnly (
bool) –Whether to only fix the mods without removing any previous changes this fix script may have made
Warning
if this is set to
TrueandundoOnlyis also set toTrue, then the fix will not run and will throw aConflictingOptionsexceptionDefault:
FalseundoOnly (
bool) –Whether to only undo the fixes previously made by the fix
Warning
if this is set to
TrueandfixOnlyis also set toTrue, then the fix will not run and will throw aConflictingOptionsexceptionDefault:
TruereadAllInis (
bool) –Whether to read all the .ini files that the fix encounters
Default:
Falsetypes (Optional[
str]) –A string containing the names for all the types of mods to fix. Each type of mod is seperated using a comma (,)
If this argument is the empty string or this argument is
None, then will fix all the types of mods supported by this fix
Default:
NonedefaultType (Optional[
str]) –The name for the type to use if a mod has an unidentified type
If this value is
None, then mods with unidentified types will be skipped
Default:
Nonelog (Optional[
str]) –The folder location to log the run of the fix into a seperate text file
If this value is
None, then will not log the fix
Default:
Noneverbose (
bool) –Whether to print the progress for fixing mods
Default:
TruehandleExceptions (
bool) –When an exception is caught, whether to silently stop running the fix
Default:
False
- _loggerBasePrefix
The prefix string for the logger used when the fix returns back to the original directory that it started to run
- Type
- fixOnly
Whether to only fix the mods without removing any previous changes this fix script may have made
- Type
- _pathIsCWD
Whether the filepath that the program runs from is the current directory where this module is loaded
- Type
- 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
- skippedBlendsByMods
The RemapBlend.buf files that got skipped :raw-html for each mod
The outer key is the absolute path to the mod folder
The inner key is the absolute path to the RemapBlend.buf file
The value in the inner dictionary is the exception that caused the RemapBlend.buf file to be skipped
- skippedBlends
The RemapBlend.buf files that got skipped
The keys are the absolute path to the RemapBlend.buf file and the values are the exception that caused the RemapBlend.buf file to be skipped
- 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
- undoedInis
.ini files that got cleared out of any traces of previous fixes
Note
These .ini files may or may not have been previously fixed. A path to some .ini file in this attribute DOES NOT imply that the .ini file previously had a fix
- Type
Set[
str]
- _fix()
The overall logic for fixing a bunch of mods
- For finding out which folders may contain mods, this function:
recursively searches all folders from where the
BossFixService.pathis locatedfor 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
- _printModsToFix()
Prints out the types of mods that will be fixed
- _setupDefaultModType()
Sets the default mod type to be used for an unidentified mod
- _setupLogPath()
Sets the folder path for where the log file will be stored
- _setupModPath()
Sets the filepath of where the fix will run from
- _setupModTypes()
Sets the types of mods that will be fixed
- addTips()
Prints out any useful tips for the user to know
- clear(clearLog: bool = True)
Clears up all the saved data
Paramters
- clearLog:
bool Whether to also clear out any saved data in the logger
- clearLog:
- 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 loadedfiles (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
- 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 fixmod (
Mod) – The mod being fixedfixedRemapBlends (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 just been fixed
- Return type
- 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 fixedfixedRemapBlends (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 just been fixed
- Return type
- property log: str
The folder location to log the run of the fix into a seperate text file
- Getter
Returns the file path to the log
- Setter
Sets the path for the log
- Type
- 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
- 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
- reportSkippedAsset(assetName: str, assetDict: Dict[str, Exception], 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 skippedassetDict (Dict[
str,Exception]) –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
Mod
- clsMod.blendCorrection
- clsMod.isBackupIni
- clsMod.isBlend
- clsMod.isIni
- clsMod.isRemapBlend
- def_setupFiles
- defcorrectBlend
- defgetOptionalFiles
- defprint
- defremoveBackupInis
- defremoveFix
- class Mod(path: Optional[str] = None, files: Optional[List[str]] = None, logger: Optional[Logger] = None, types: Optional[Set[ModType]] = None, defaultType: Optional[ModType] = None)
This Class inherits from
ModelUsed 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:
a section with the regex
[TextureOverride.*Blend]ifBossFixService.readAllInisis set toTrueor the script is ran with the--allflag
OR
a section that meets the criteria of one of the mod types defined
Mod._typesby running the mod types’ModType.isType()function
SeeModTypesfor some predefined types of mods- 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:
Nonefiles (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:
Nonelogger (Optional[
Logger]) –The logger used to pretty print messages
Default:
Nonetypes (Optional[Set[
ModType]]) –The types of mods this mod should be.
If this argument is empty or isNone, then all the .ini files in this mod will be parsed
Default:
NonedefaultType (Optional[
ModType]) –The type of mod to use if a mod has an unidentified type
If this argument isNone, then will skip the mod with an identified type
Default:
None
- _files
The direct children files to the mod folder (does not include files located in a folder within the mod folder).
- 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]
- classmethod blendCorrection(blendFile: Union[str, bytes], modType: ModType, fixedBlendFile: Optional[str] = None) Union[str, None, bytearray]
Fixes a Blend.buf file
Note
We observe that a Blend.buf file is a binary file defined as:
each line contains 32 bytes (256 bits)
each line uses little-endian mode (MSB is to the right while LSB is to the left)
the first 16 bytes of a line are for the blend weights, each weight is 4 bytes or 32 bits (4 weights/line)
the last 16 bytes of a line are for the corresponding indices for the blend weights, each index is 4 bytes or 32 bits (4 indices/line)
the blend weights are floating points while the blend indices are unsigned integers
- Parameters
- Raises
BlendFileNotRecognized – If the original Blend.buf file provided by the parameter
blendFilecannot be readBadBlendData – If the bytes passed into this function do not correspond to the format defined for a Blend.buf file
- Returns
If the argument
fixedBlendFileisNone, then will return an array of bytes for the fixed Blend.buf file
Otherwise will return the filename to the fixed RemapBlend.buf file if the provided Blend.buf file got corrected- Return type
- correctBlend(fixedRemapBlends: Dict[str, RemapBlendModel], skippedBlends: Dict[str, Exception], fixOnly: bool = False) List[Union[Set[str], Dict[str, Exception]]]
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
skippedBlends (Dict[
str,Exception]) –All of the RemapBlend.buf files that have already been skipped due to some error when trying to fix them
The keys are the absolute filepath to the RemapBlend.buf file that was attempted to be fixed and the values are the exception encountered
fixOnly (
bool) –Whether to not correct some Blend.buf file if its corresponding RemapBlend.buf already exists
Default:
True
- Returns
The absolute file paths of the RemapBlend.buf files that were fixed
The exceptions encountered when trying to fix some RemapBlend.buf files
The keys are absolute filepath to the RemapBlend.buf file and the values are the exception encountered
- Return type
- 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):
.ini files
.RemapBlend.buf files
DISABLED_BossFixBackup.txt files
Note
See
Mod.isIni(),Mod.isRemapBlend(),Mod.isBackupIni()for the specifics of each type of file- Return type
- classmethod isBackupIni(file: str) bool
Determines whether the file is a DISABLED_BossFixBackup.txt file that is used to make backup copies of .ini files
- classmethod isBlend(file: str) bool
Determines whether the file is a Blend.buf file which is the original blend file provided in the mod
- classmethod isIni(file: str) bool
Determines whether the file is a .ini file which is the file used to control how a mod behaves
- 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
- print(funcName: str, *args, **kwargs)
Prints out output
- Parameters
- Returns
The return value from running the corresponding function in the logger
- Return type
Any
- removeBackupInis()
Removes all DISABLED_BossFixBackup.txt contained in the mod
- removeFix(fixedBlends: Set[str], fixedInis: Set[str], visitedRemapBlendsAtRemoval: Set[str], inisSkipped: Dict[str, Exception], keepBackups: bool = True, fixOnly: bool = False) List[Set[str]]
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 removefixedInis (Set[
str]) – The file paths to the .ini files that we do not want to removevisitedRemapBlendsAtRemoval (Set[
str]) – The file paths to the RemapBlend.buf that have already been attempted to be removedinisSkipped (Dict[
str,Exception]) – The file paths to the .ini files that are skipped due to errorskeepBackups (
bool) –Whether to create or keep DISABLED_BossFixBackup.txt files in the mod
Default:
TruefixOnly (
bool) –Whether to not undo any changes created in the .ini files
Default:
False
- Returns
The removed files that have their fix removed, where the types of files for the return value is based on the list below:
.ini files with their fix removed
RemapBlend.buf files that got deleted
- Return type
ModType
- class ModType(name: str, check: Union[str, Pattern, Callable[[str], bool]], bossHash: str, aliases: Optional[List[str]] = None, vgRemap: Optional[Dict[int, int]] = None)
Class for defining a generic type of mod
- Parameters
name (
str) – The default name for the type of modcheck (Union[
str, Pattern, Callable[[str],bool]]) –The specific check used to identify the .ini file belongs to the specific type of mod when checking arbitrary line in a .ini file
If this argument is a string, then will check if a line in the .ini file equals to this argument
If this argument is a regex pattern, then will check if a line in the .ini file matches this regex pattern
If this argument is a function, then will check if a line in the .ini file will make the function for this argument return True
bossHash (
str) – The hash for the Vertex Group Blend of the bossaliases (Optional[List[
str]]) –Other alternative names for the type of mod
Default:
NonevgRemap (Optional[Dict[int, int]]) –
Maps the blend indices from the vertex group of the mod’s blend to the blend indices for the vertex group of the boss
If this value isNone, then the blend indices of the mod and the boss are one-to-oneThe keys are the blend indices in the mod and the values are the blend indices in the boss
Default:
None
- check
The specific check used to identify the .ini file belongs to the specific type of mod when checking arbitrary line in a .ini file
- isName(name: str) bool
Determines whether a certain name matches with the names defined for this type of mod
- property maxVgIndex: Optional[int]
The max vertex group blend index of the mod (key of the mapping) in
ModType.vgRemap- Getter
Returns the following index
- Type
Optional[
int]
Ini Files
IniFile
- _blendCommands
- _blendCommandsRemapNames
- _blendCommandsTuples
- _parser
- _resouceCommandsTuples
- _resourceBlends
- _resourceCommands
- _resourceCommandsRemapNames
- _sectionIfTemplates
- _textureOverrideBlendRoot
- defaultModType
- file
- fileLines
- fileLinesRead
- fileTxt
- isFixed
- isModIni
- modTypes
- remapBlendModels
- remapBlendModelsDict
- type
- clsIniFile.getFixedBlendFile
- clsIniFile.getMergedResourceIndex
- clsIniFile.getRemapName
- clsIniFile.getRemapResourceName
- clsIniFile.getResourceName
- clsIniFile.removeResourceName
- def_addFixBoilerPlate
- def_checkFixed
- def_checkModType
- def_compareResources
- def_fillRemapResource
- def_fillTextureOverrideRemapBlend
- def_getBlendResources
- def_getCommandIfTemplate
- def_getCommands
- def_getIfTemplateResourceName
- def_getIfTemplateSubCommand
- def_isIfTemplateDraw
- def_isIfTemplateResource
- def_isIfTemplateSubCommand
- def_makeRemapModels
- def_parseSection
- def_processIfTemplate
- def_readLines
- def_removeFix
- def_removeSection
- defcheckIsMod
- defclear
- defclearRead
- defdisIni
- deffillIfTemplate
- deffix
- defgetFixCredit
- defgetFixFooter
- defgetFixHeader
- defgetFixModTypeHeadingname
- defgetFixModTypeName
- defparse
- defread
- defreadFileLines
- defremoveSectionOptions
- defwrite
- class IniFile(file: Optional[str] = None, logger: Optional[Logger] = None, txt: str = '', modTypes: Optional[Set[ModType]] = None, defaultModType: Optional[ModType] = None)
This class inherits from
ModelClass 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:
Nonelogger (Optional[
Logger]) – The logger to print messages if necessarytxt (
str) –Used as the text content of the .ini file if
IniFile.fileis set toNone
Default: “”
modTypes (Optional[Set[
ModType]]) –The types of mods that the .ini file should belong to
Default:
NonedefaultModType (Optional[
ModType]) –The type of mod to use if the .ini file has an unidentified mod type
If this value isNone, then will skip the .ini file with an unidentified mod type
Default:
None
- _parser
Parser used to parse very basic cases in a .ini file
- Type
- defaultModType
The type of mod to use if the .ini file has an unidentified mod type
- Type
Optional[
ModType]
- _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
IfTemplateFor more info see
IfTemplateWarning
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 calledNote
This attribute is the same as
IniFile._blendCommandsexcept 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
- _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 calledNote
This attribute is the same as
IniFile._resourceCommandsexcept 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 fixThe 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 fixNote
This attribute is the same as the values of
IniFile.remapBlendModelsDictby 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"
- _checkFixed(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
- _checkModType(line: str)
Checks if a line of text contains the keywords to identify whether the .ini file belongs to the types of mods in
IniFile.modTypes
If
IniFile.modTypesis not empty, then will find the firstModTypethat where the line makesModType.isType()returnTrueOtherwise, will see if the line matches with the regex,
[.*TextureOverride.*Blend.*]
- Parameters
line (
str) – The text to check
- _compareResources(resourceTuple1: Tuple[str, Optional[int]], resourceTuple2: Tuple[str, Optional[int]]) int
Compare function used for sorting resources
The order for sorting is the resources is:
Resources that do are not suffixed by an index number
Resource that are suffixed by an index number (see
IniFile.getMergedResourceIndex()for more info)
- Parameters
resourceTuple1 (Tuple[
str, Optional[int]]) –Data for the first resource in the compare function, contains:
Name of the resource
The index for the resource
resourceTuple2 (Tuple[
str, Optional[int]]) –Data for the second resource in the compare function, contains:
Name of the resource
The index for the resource
- Returns
The result for a typical compare function used in sorting
returns -1 if
resourceTuple1should come beforeresourceTuple2returns 1 if
resourceTuple1should come afterresourceTuple2returns 0 if
resourceTuple1is equal toresourceTuple2
- Return type
- _fillRemapResource(sectionName: str, part: Dict[str, Any], partIndex: int, linePrefix: str, origSectionName: str)
Creates the content part of an
IfTemplatefor the new sections created by this fix related to the[Resource.*Blend.*]sectionsNote
For more info about an ‘IfTemplate’, see
IfTemplate- Parameters
part (Dict[
str, Any]) – The content part of theIfTemplateof the original[Resource.*Blend.*]sectionpartIndex (
int) – The index of where the content part appears in theIfTemplateof the original sectionlinePrefix (
str) – The text to prefix every line of the created content part
- Returns
The created content part
- Return type
- _fillTextureOverrideRemapBlend(sectionName: str, part: Dict[str, Any], partIndex: int, linePrefix: str, origSectionName: str) str
Creates the content part of an
IfTemplatefor the new sections created by this fix related to the[TextureOverride.*Blend.*]sectionsNote
For more info about an ‘IfTemplate’, see
IfTemplate- Parameters
sectionName (
str) – The new name for the sectionpart (Dict[
str, Any]) – The content part of theIfTemplateof the original [TextureOverrideBlend] sectionpartIndex (
int) – The index of where the content part appears in theIfTemplateof the original sectionlinePrefix (
str) – The text to prefix every line of the created content part
- Returns
The created content part
- Return type
- _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 fromblendResources (Set[
str]) – The result for all the resource sections that were referencedsubCommands (Set[
str]) – The result for all of the sub-sections that were called from the[TextureOverride.*Blend.*]sectionsubCommandLst (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
IfTemplateis 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
IfTemplatefor a certain section from IniFile._sectionIfTemplate- Parameters
raiseException (
bool) – Whether to raise an exception when the section’sIfTemplateis not found
- Raises
KeyError – If the
IfTemplatefor the section is not found andraiseExceptionis set to True- Returns
The corresponding
IfTemplatefor 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
- Raises
KeyError – If the
IfTemplateis not found for some section
- _getIfTemplateResourceName(ifTemplatePart: Dict[str, Any]) Any
Retrieves the value from the key, ‘vb1’, for some part of a section
- _getIfTemplateSubCommand(ifTemplatePart: Dict[str, Any]) Any
Retrieves the value from the key, ‘run’, for some part of a section
- _isIfTemplateDraw(ifTemplatePart: Dict[str, Any]) bool
Whether the content for some part of a section contains the key ‘draw’
- _isIfTemplateResource(ifTemplatePart: Dict[str, Any]) bool
Whether the content for some part of a section contains the key ‘vb1’
- _isIfTemplateSubCommand(ifTemplatePart: Dict[str, Any]) bool
Whether the content for some part of a section contains the key ‘run’
- _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
- Returns
The result from parsing the section
Note
If ConfigParser is unable to parse the section, then
Noneis returned- Return type
- _processIfTemplate(startInd: int, endInd: int, fileLines: List[str], sectionName: str, srcTxt: str) IfTemplate
Parses a section in the .ini file as an
IfTemplateNote
See
IfTemplateto see how we define an ‘IfTemplate’- Parameters
- Returns
The generated
IfTemplatefrom the section- Return type
- _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._fileLinesExamples
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:
All code surrounded by the ‘—…— . Boss Fix —…—-’* header/footer
All sections containing the keywords
RemapBlend
- Returns
The new text content of the .ini file with the changes removed
- Return type
- _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
- Returns
The starting line index and the ending line index of the section to remove
- Return type
- checkIsMod() bool
Reads the entire .ini file and checks whether the .ini file belongs to a mod
Note
If the .ini file has already been parsed (eg. calling
IniFile.checkModType()orIniFile.parse()), thenyou only need to read
IniFile.isModIni()- Returns
Whether the .ini file is a .ini file that belongs to some mod
- Return type
- clear(eraseSourceTxt: bool = False)
Clears all the saved data for the .ini file
Note
Please see the note at
IniFile.clearRead()- Parameters
eraseSourceTxt (
bool) –Whether to erase the only data source for this class if
IniFile.fileis set toNone, see the note atIniFile.clearRead()for more info
Default:
False
- clearRead(eraseSourceTxt: bool = False)
Clears the saved text read in from the .ini file
Note
If
IniFile.fileis set toNone, then the default run of this function with the argumenteraseSourceTxtset toFalsewill have no effect since the provided text fromIniFile._fileTxtis the only source of data for theIniFileIf you also want to clear the above source text data, then run this function with the
eraseSourceTxtargument set toTrue- Parameters
eraseSourceTxt (
bool) –Whether to erase the only data source for this class if
IniFile.fileis set toNone, see the note above for more info
Default:
False
- disIni()
Disables the .ini file
Note
For more info, see
FileService.disableFile()
- property fileLines: List[str]
The text lines of the .ini file
Note
For the setter, each line must end with a newline character (same behaviour as readLines)
- Getter
Returns the text lines of the .ini file
- Setter
Reads the new value for both the text lines of the .ini file and the text content of the .ini file
- Type
List[
str]
- property fileLinesRead: bool
Whether the .ini file has been read
- Getter
Determines whether the .ini file has been read
- Type
- property fileTxt: str
The text content of the .ini file
- Getter
Returns the content of the .ini file
- Setter
Reads the new value for both the text content of the .ini file and the text lines of the .ini file
- Type
- 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
IfTemplatefor an existing section in the .ini file- Parameters
ifTemplate (
IfTemplate) – TheIfTemplateof the orginal sectionfillFunc (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:The new section name
The corresponding content part in the original
IfTemplateThe index for the content part in the original
IfTemplateThe string to prefix every line in the content part of the
IfTemplateThe 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 forsectionName
Default:
None
- Returns
The text for the newly created
IfTemplate- Return type
- getFixCredit() str
Retrieves the credit text for the code generated in the .ini file
- Returns
The credits to be displayed in the .ini file
- Return type
Retrieves the footer text used to identify a code section has been changed by this fix in the .ini file
- Returns
The footer section comment to be used in the .ini file
- Return type
- getFixHeader() str
Retrieves the header text used to identify a code section has been changed by this fix in the .ini file
- Returns
The header section comment to be used in the .ini file
- Return type
- getFixModTypeHeadingname()
Retrieves the name of the type of mod corresponding to the .ini file to be used in the header/footer divider comment of the fix
- Returns
The name for the type of mod to be displayed in the header/footer divider comment
- Return type
Optional[
str]
- getFixModTypeName() Optional[str]
Retrieves the name of the type of mod corresponding to the .ini file to be used for the comment of the fix
- Returns
The name for the type of mod corresponding to the .ini file
- Return type
Optional[
str]
- classmethod getFixedBlendFile(blendFile: str) str
Retrieves the file path for the fixed RemapBlend.buf file
- classmethod getMergedResourceIndex(mergedResourceName: str) Optional[int]
Retrieves the index number of a resource created by GIMI’s
genshin_merge_mods.pyscriptExamples
>>> IniFile.getMergedResourceIndex("ResourceCuteLittleEiBlend.8") 8
>>> IniFile.getMergedResourceIndex("ResourceCuteLittleEiBlend.Score.-100") -100
>>> IniFile.getMergedResourceIndex("ResourceCuteLittleEiBlend.UnitTests") None
>>> IniFile.getMergedResourceIndex("ResourceCuteLittleEiBlend") None
- classmethod getRemapName(name: str) str
Changes a section name to have the keyword ‘RemapBlend’ to identify that the section is created by this fix
Examples
>>> IniFile.getRemapName("EiTriesToUseBlenderAndFails") "EiTriesToUseRemapBlenderAndFails"
>>> IniFile.getRemapName("EiBlendsTheBlender") "EiBlendsTheRemapBlender"
>>> IniFile.getRemapName("ResourceCuteLittleEi") "ResourceCuteLittleEiRemapBlend"
>>> IniFile.getRemapName("ResourceCuteLittleEiRemapRemapBlend") "ResourceCuteLittleEiRemapRemapBlend"
- classmethod getRemapResourceName(name: str) str
Changes the name of a section to be a new resource that this fix will create
Note
See
IniFile.getResourceName()andIniFile.getRemapName()for more info
- 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"
>>> IniFile.getResourceName("ResourceCuteLittleEi") "ResourceCuteLittleEi"
- property isFixed: bool
Whether the .ini file has already been fixed
- Getter
Returns whether the .ini file has already been fixed
- Type
- property isModIni: bool
Whether the .ini file belongs to a mod
- Getter
Returns whether the .ini file belongs to a mod
- Type
- parse()
Parses the .ini file
- read() str
Reads the .ini file
If
IniFile.fileis set toNone, then will read the existing value fromIniFile.fileTxt- Returns
The text content of the .ini file
- Return type
- readFileLines() List[str]
Reads each line in the .ini file
If
IniFile.fileis set toNone, then will read the existing value fromIniFile.fileLines- Returns
All the lines read from the .ini file
- Return type
List[
str]
- classmethod removeResourceName(name: str) str
Removes the ‘Resource’ prefix from a section’s name
Examples
>>> IniFile.removeResourceName("ResourceCuteLittleEi") "CuteLittleEi"
>>> IniFile.removeResourceName("LittleMissGanyu") "LittleMissGanyu"
- removeSectionOptions(section: Union[str, Pattern, Callable[[str], bool]])
Removes a certain type of section from the .ini file
IfTemplate
- 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
IfTemplatehave 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:
An If Part: a single line containing the keywords “if”, “else” or “endif”
ORA Content Part: a group of lines that “does stuff”
Note that: an
ifTemplatedoes 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 sectionBased on the above assumptions, we can assume that every
[section]in a .ini file contains thisIfTemplateSupported Operations:
- for element in x
Iterates over all the parts of the
IfTemplate,x
- x[num]
Retrieves the part from the
IfTemplate,x, at indexnum
- x[num] = newPart
Sets the part at index
numof theIfTemplate,x, to have the value ofnewPart
- Parameters
parts (List[Union[
str, Dict[str, Any]]]) – The individual parts of how we divided anIfTemplatedescribed abovecalledSubCommands (Optional[Dict[
int,str]]) –Any other sections that this
IfTemplatereferences
The keys are the indices to the part in theIfTemplatethat the section is called
Default:
None
- parts
The individual parts of how we divided an
IfTemplatedescribed above
- calledSubCommands
Any other sections that this
IfTemplatereferences
The keys are the indices to the part in theIfTemplatethat the section is called
- 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 theIfTemplate
- 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
IfTemplatefor 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:
NonepostProcessor (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
- Returns
The filtered parts that meet the search condition
The keys are the index locations of the parts and the values are the found parts
- Return type
Dict[
int, Any]
Models
Model
- 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
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 locatedfixedBlendName (
str) – The new name of the resource once all the Blend.buf files for the resource has been fixedfixedBlendPaths (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 theIfTemplatefor some resourceorigBlendName (Optional[
str]) –The original name of the resource in the .ini file
Default:
NoneorigBlendPaths (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 theIfTemplatefor some resource
Default:
None
- fixedBlendName
The new name of the resource once all the Blend.buf files for the resource has been fixed
- Type
- 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 theIfTemplatefor the resource
- 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
IfTemplatefor the resource
- 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
IfTemplatefor the resource
- 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
IfTemplatefor the resource
Views
Logger
- clsLogger.getBulletStr
- clsLogger.getNumberedStr
- def_addLogTxt
- def_setDefaultHeadingAtts
- defbox
- defbulletPoint
- defclear
- defcloseHeading
- deferror
- defgetStr
- defhandleException
- definput
- deflist
- deflog
- defopenHeading
- defspace
- defsplit
- defwaitExit
- class Logger(prefix: str = '', logTxt: bool = False, verbose: bool = True)
Class for pretty printing output to display on the console
- Parameters
- _headings
A stack of headings that have been opened (by calling
Heading.open()), but have not been closed yet (have not calledHeading.close()yet)- Type
Deque[
Heading]
- _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
- bulletPoint(txt: str)
Prints out an item in an unordered list
- Parameters
txt (
str) – The message we want to print out
- clear()
Clears out any saved text from the logger
- closeHeading()
Prints out a closing heading that corresponds to a previous opening heading printed (see line 3 of the example at
Heading)
- error(message: str)
Prints an error message
- Parameters
message (
str) – The message we want to print out
- handleException(exception: Exception)
Prints the message for an error
- Parameters
exception (
Exception) – The error we want to handle
- list(lst: List[str], transform: Optional[Callable[[str], str]] = None)
Prints out an ordered list
- Parameters
- log(message: str)
Regularly prints text onto the console
- 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 outsideLen (
int) –How many characters we want for the side border of the heading
(see line 1 of the example atHeading)
Default: 2
headingChar (
str) –The type of character used to print the side border of the heading
(see line 3 of the example atHeading)
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
- space()
Prints out a space
- split()
Prints out a new line
- waitExit()
Prints the message used when the script finishes running
Heading
- class Heading(title: str = '', sideLen: int = 0, sideChar: str = '=')
Class for handling information about a heading for pretty printing
Examples
1======= Title: Fix Raiden Boss 2 ======= 2... 3========================================
- Parameters
- sideLen
The number of characters we want one side for the border of the opening heading to have
- Type
Enums
ModTypes
- class ModTypes(value)
The supported types of mods that can be fixed
- Raiden
Raiden mods
Checks if the .ini file contains a section with the regex
[TextureOverride.*(Raiden|Shogun).*Blend]- Type
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
- classmethod disableFile(file: str, filePrefix: str = 'DISABLED_BossFixBackup_')
Marks a file as ‘DISABLED’ and changes the file to a .txt file
- classmethod getFiles(path: Optional[str] = None, filters: Optional[List[Callable[[str], bool]]] = None, files: Optional[List[str]] = None) Union[List[str], List[List[str]]]
Retrieves many different types of files within a folder
Note
Only retrieves files that are the direct children of the folder (will not retrieve files nested in a folder within the folder we are searching)
- 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:
Nonefilters (Optional[List[Callable[[
str],bool]]]) –Different filter functions for each type of file we are trying to get. If this values is either
Noneor[], then will default to a filter to get all the files
Default:
Nonefiles (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
- classmethod getFilesAndDirs(path: Optional[str] = None, recursive: bool = False) List[List[str]]
Retrieves the files and folders contained in a certain folder
- Parameters
- Returns
The files and directories within the folder. The order for the result is:
files
folders
- Return type
- 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)
- classmethod getSingleFiles(path: Optional[str] = None, filters: Optional[Dict[str, Callable[[str], bool]]] = None, 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:
Nonefilters (Optional[Dict[str, Callable[[
str],bool]]]) –Different filter functions for each type of file we are trying to get. If this value is
Noneor{}, then will default to use a filter to get all filesThe keys are the names for the file type
Default:
Nonefiles (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:
Noneoptional (
bool) –Whether we want to send an exception if there is not exactly 1 file for a certain type of file
If this value is
Falseand there are no files for a certain type of file, then will raise aMissingFileExceptionIf this value is
Falseand there are more than 1 file for a certain type of file, then will raise aDuplicateFileExceptionIf this value is
Trueand there are no files for a certain type of file, then the file for that type of file will beNoneIf this value is
Trueand 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
optionalis set toFalseand there are not files for a certain type of fileDuplicateFileException – if
optionalis set toFalseand there are more than 1 file for a certain type of file
- Returns
The files partitioned for each type of file
- Return type
- 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
- 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:
utf-8
latin1
- Parameters
file (
str) – The file we are trying to read fromfileCode (
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
DictTools
- class DictTools
Tools for handling with Dictionaries
- classmethod combine(dict1: Dict[Hashable, Any], dict2: Dict[Hashable, Any], combineDuplicate: Optional[Callable[[Any, Any], Any]] = None) Dict[Hashable, Any]
Combines 2 dictionaries
- Parameters
dict1 (Dict[Hashable, Any]) – The destination of where we want the combined dictionaries to be stored
dict2 (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 ‘dict2’
Default:
None
Exceptions
Error
- class Error(message: str)
The base exception used by this module
- Parameters
message (
str) – the error message to print out
FileException
- class FileException(message: str, path: Optional[str] = None)
This Class inherits from
ErrorExceptions relating to files
- Parameters
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
DuplicateFileException
- class DuplicateFileException(files: List[str], fileType: str = 'file', path: Optional[str] = None)
This Class inherits from
FileExceptionException when there are multiple files of the same type in a folder
- Parameters
files (List[
str]) – The files that triggered the exceptionfileType (
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
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
MissingFileException
- class MissingFileException(fileType: str = 'file', path: Optional[str] = None)
This Class inherits from
FileExceptionException when a certain type of file is missing from a folder
- Parameters
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
RemapMissingBlendFile
- class RemapMissingBlendFile(remapBlend: str)
This Class inherits from
FileExceptionException when a RemapBlend.buf file is missing its corresponding Blend.buf file
- Parameters
remapBlend (
str) – The path to the RemapBlend.buf file
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
BlendFileNotRecognized
- class BlendFileNotRecognized(blendFile: str)
This Class inherits from
FileExceptionException when a Blend.buf file cannot be read
- Parameters
blendFile (
str) – The file path to the Blend.buf file
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
BadBlendData
- class BadBlendData
This Class inherits from
ErrorException when certain bytes do not correspond to the format defined for a Blend.buf file
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
ConflictingOptions
- class ConflictingOptions(options: List[str])
This Class inherits from
ErrorException when the script or
BossFixServiceis ran with options that cannot be used together- Parameters
options (List[
str]) – The options that cannot be used together
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
InvalidModType
- class InvalidModType(type: str)
This Class inherits from
ErrorException when the type of mod specified to fix is not found
- Parameters
type (
str) – The name for the type of mod specified
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.