Releases: riistar/LibLoader
LibLoader (v2) 2.0.1.4
Project rewrite
Started code from scratch, to improve code logic and eliminate errors that were introduced in v1 causing slow load/eternal loop/crashes.
Change Log: Core_LibLoader.pas (v1) to Loader.pas (v2)
Overview
This document outlines the significant changes and improvements made in the rewrite of the Lib-Loader
unit from version 1 (Core_LibLoader.pas
) to version 2 (Loader.pas
). The new version introduces enhancements in configuration handling, modular loading, compatibility checks, logging, and overall code structure.
Key Changes and Improvements
Configuration Handling
- Whitespace Handling:
- v1: Potential issues with parsing directories and file lists with whitespace.
- v2: Improved handling of whitespace in directory and file lists to prevent parsing errors.
Modular Loading
-
Modular Loading Process:
- v1: Basic modular loading with limited functionality.
- v2: Enhanced loading process with the ability to load multiple modules specified in the configuration file, and support for the newest version of modules when multiple versions are found.
-
Retry Logic:
- v1: No retry logic for loading modules.
- v2: Introduced retry logic with a configurable maximum number of retries for loading modules.
Compatibility Checks
- Architecture Compatibility:
- v1: Limited or no checks for architecture compatibility between the host and the modules.
- v2: Implemented comprehensive compatibility checks to ensure that only modules compatible with the host architecture (x86/x64) are loaded.
Logging Enhancements
-
Detailed and Structured Logs:
- v1: Introduced detailed logging with Indentation and other features to output a clean/readable log file.
- v2: Detailed logging with clear indentation and structure for readability. Cut back on too much debug details.
-
Customizable Debug Output:
- v1: No support for toggling debug messages.
- v2: Debug messages can be toggled on or off via the configuration file.
Code Structure and Maintenance
- Improved Code Structure:
- v1: Monolithic code structure with less modularity.
- v2: Refactored into a more modular and maintainable structure with clear separation of concerns.
Detailed Description of Changes
Modular Loading
- Enhanced Loading Process:
- Introduced a new method to identify and load the newest version of a module when multiple versions are found.
- Detailed logging of the module search and loading process.
- Retry logic for loading modules, with configurable maximum retries.
Compatibility Checks
- Implemented Architecture Compatibility:
- Functions
IsHostX64
andIsDllX64
determine the architecture of the host and modules. - Ensures that only modules compatible with the host architecture are loaded.
- Functions
Enhanced Logging usage
-
Detailed and Structured Logs:
- Logs include detailed information about each step of the loading process.
- Clear indentation and structure for readability.
- Headers and horizontal rules improve log readability.
-
Customizable Debug Output:
- Debug messages can be toggled via the configuration file, allowing for verbose logging during development and concise logging in production.
Code Structure and Maintenance
-
Refactored Code Structure:
- Improved modularity and maintainability.
- Clear separation of concerns, with each function and procedure handling specific tasks.
-
Enhanced Documentation:
- Added detailed comments and documentation for better code understanding and maintenance.
- Improved readability and maintainability of the code.
Usage Instructions
Configuration File (Loader.cfg)
The configuration file should be structured as follows:
[Loader]
Enabled = 1
Files = Test.dll, PEInfo_x64.dll
ModFolders = C:\GameFolder\mods, D:\Projects\Git\Test\Win64\Debug
[Debug]
Enabled = 1
[Log]
Append = 0
[Experimental]
ManualMap = 0
Lib-Loader v1.3.1.5
Refactored Core_LibLoader for improved file search, loading, and compatibility checks.
-
Removed WriteLog Function:
- Eliminated the
WriteLog
function asCore_Log
unit is imported for theLog
class. - Ensured all logging operations use the
Log
class directly.
- Eliminated the
-
Improved Recursive File Loading:
- Added
LoadFileFromFolder
nested procedure withinLibLoader.Execute
to handle file loading from a specified folder. - Ensured proper logging for each step in the recursive file search.
- Tracked successfully loaded files using a new
FilesLoaded
list.
- Added
-
Enhanced Error Handling:
- Logged errors for files not found in both mod directories and application/client directory.
- Prevented duplicate entries in the
FailedFiles
list by checking if the file already exists in the list before adding. - Removed files from
FailedFiles
if they were successfully loaded from the application/client directory.
-
Unified Loaded Files Tracking:
- Introduced a
FilesLoaded
TStringList to maintain a list of all successfully loaded files across both the recursive search and application/client directory search. - Ensured
FilesLoaded
is updated immediately when a file is successfully loaded from any directory. - Added checks to prevent duplicates in the
FilesLoaded
list.
- Introduced a
-
Managed TStringList Lifecycle:
- Created and properly freed all TStringLists (
ModFolders
,FailedFiles
,FilesToProcess
,FilesToRemove
,FilesLoaded
) to avoid memory leaks and ensure stability. - Cleared
FilesToRemove
before each new directory search to prevent carrying over entries.
- Created and properly freed all TStringLists (
-
General Code Cleanup:
- Improved readability and maintainability by organizing the code into nested procedures and clearly commenting on each significant operation.
- Removed redundant log messages and ensured consistency in logging format.
-
Bug Fixes:
- Fixed issue where files could be skipped or incorrectly removed during the search process.
- Ensured the application does not crash when accessing
Files2Load.CommaText
by checkingFiles2Load.Count
before accessing it. - Ensured accurate reporting of loaded and failed files at the end of the operation.
- Fixed issue where
FilesLoaded
list had duplicate entries by checking for duplicates before adding.
-
Improved
LibLoader.WhereIs
Function:- Refactored
LibLoader.WhereIs
to recursively search for a file in specified directories. - Added appropriate comments for better understanding and maintenance.
- Ensured proper returning of the result after the recursive search is complete.
- Refactored
-
Commented Code for Better Understanding:
- Added comments to all major code sections and procedures to explain their functionality and flow.
- Provided detailed comments in
LibLoader.Execute
andLibLoader.WhereIs
functions.
-
New Usage of Core_Log Unit:
- Utilized the
Core_Log
unit for logging operations throughout the unit. - Ensured consistent logging format and levels using the
Log
class fromCore_Log
.
- Utilized the
-
Compatibility Checks:
- Added checks to ensure DLL compatibility with the host architecture (x86/x64).
- Ensured only compatible DLLs are loaded to prevent runtime errors.
Lib-Loader v1.2.1.6
- Clean up and improve code base, merging config functions for better performance and reduce code size.
- Fixed issue with ModFolders string from config file, if it had spaces in the folder path it would break path into multiple items.
- Solved issue with recursive file search if the target files were all in the same directory.
Lib-Loader v1.1
Move to new DLL to reduce conflicts with other libs...
Proxy DLL is nps64.dll and original should be renamed to nps64.dat
Lib-Loader v1.0
Initial public build for MMO Mabinogi.
- Rename original dbghelp.dll to dbghelp.dat
- Open dbghelp.cfg in notepad to edit configuration.