Releases: riistar/LibLoader
Release list
LibLoader (v3) 3.4.1.1
Lib-Loader Rewrite (v2 → v3)
Overview
This release represents a major enhancement to the Lib-Loader unit. Building on version 2, this rewrite makes the loader smarter, more flexible, and easier to maintain. It now supports both immediate and delayed module loading, offers DLL injection options, and includes performance optimizations—all while keeping a fallback to the host application’s directory if a module isn’t found.
Key Changes and Improvements
-
Delayed Loading & Task Management:
The loader now supports delayed module loading. Modules can wait for a specified time, for another module to load, or for a target process to appear before being loaded. Background tasks with proper synchronization (using events and counters) ensure that these delayed operations complete reliably. -
Advanced Module Selection:
When multiple candidates exist, the loader now uses both version numbers and file dates to choose the best candidate. The enhanced retry mechanism further improves robustness under adverse conditions. -
DLL Injection Capability:
In addition to the standard LoadLibrary method, an injection option has been added. This allows DLLs to be injected into a target process when configured, providing added flexibility for different use cases. -
Performance Optimizations:
A directory caching mechanism has been implemented to reduce redundant file system searches. Detailed logging now includes timing metrics and thread identifiers to aid performance monitoring and troubleshooting. -
Enhanced Process and Module Verification:
New methods check if a module is already loaded in the host process, and the loader can monitor external processes before proceeding—ensuring improved reliability in complex scenarios. -
Refactored Code Structure:
The code has been reorganized and commented for better modularity, maintainability, and readability. Enhanced inline documentation further assists in future development and debugging.
Usage Instructions
Configuration File (Loader.cfg)
The configuration file remains the heart of the loader’s setup, and this version supports additional options for delayed loading, injection methods, and more granular control over the loading process. Below is a detailed explanation of each section and its parameters:
[Loader] Section:
- Enabled:
Set to1to enable the chain loading process; set to0to disable it. - Files:
A comma-separated list of DLLs to load. List the filenames (e.g.,MabiWnd.dll, BCGv2.dll). These are the modules that the loader will attempt to find and load. - ModFolders:
A comma-separated list of directories where the loader will recursively search (including subdirectories) for the DLLs specified in the Files list. If a module isn’t found in these folders, the loader will automatically check the host application’s directory.
[Debug] Section:
- Enabled:
Toggle detailed debug output by setting this to1(on) or0(off). When enabled, additional debug messages are logged. - Mode:
Specifies the debug output mode. For example,1outputs log messages only, while2outputs log messages along with additional debug information (e.g., via DebugView).
[Log] Section:
- Append:
Determines the log file write mode. Setting it to1will append new logs to the existing file, while0will overwrite the log file on startup.
Module-Specific Sections:
Each module can have its own section to define specific loading behavior. The following parameters are available:
- Delay:
The time (in milliseconds) to wait before attempting to load the module. This allows you to postpone the loading of certain modules until other conditions are met. - DelayPosition:
Defines when the delay should be applied relative to other waiting conditions.
Options:- None: The delay is applied immediately (or not used at all).
- Before: Apply the delay before checking for other waiting conditions (e.g., waiting for a process or another module).
- After: Apply the delay after the waiting conditions have been met.
- WaitForProcess:
The name of a process that the loader should wait for before loading the module. The loader will continuously check if this process is running before proceeding. - WaitForModule:
The name of another module (DLL) that must be loaded before this module is loaded. This helps enforce dependency order. - Method:
Specifies the method to use for loading the DLL:1: Normal LoadLibrary (standard dynamic loading).2: LoadLibrary injection (which attempts to load the DLL into a target process).- Additional options for reflective injection (into the current or a target process) may be defined as needed.
- Target:
If using an injection method (Method = 2 or similar), this parameter specifies the target process name for injection.
Updated Configuration File Example
Below is an example configuration file with inline comments explaining each parameter. (Note: Adjust file names and paths to suit your environment.)
[Loader]
; Enable Lib-Loader to run the chain loading process.
; 1 = On, 0 = Off
Enabled = 1
; Specify DLL libraries to find and load.
; Example: Files = MyModule.dll, ExtraModule.dll, AnotherMod.dll
Files = MyModule.dll, ExtraModule.dll
; Specify separate mod directories to recursively search (including sub-dirs)
; for the above-defined files. If not found in these directories,
; the loader will default to the application directory.
; Example: ModFolders = C:\Projects\Mods, D:\Builds\DLLs
ModFolders = C:\Projects\Mods, D:\Builds\DLLs
[Debug]
; Enables detailed debug output to the log file.
Enabled = 1
; Debug output mode: 1 = Log only, 2 = Log + DebugView
Mode = 1
[Log]
; Set the write mode for the log file.
; 0 = Overwrite the log on startup, 1 = Append to the existing log
Append = 0
;------------------------------------------------------------------------------------------------------------------------------
; Module-Specific Options: Configure individual DLL load options below.
;------------------------------------------------------------------------------------------------------------------------------
[MyModule.dll]
; Delay in milliseconds before attempting to load this module.
; This delay can be used to postpone the load operation.
Delay = 10000
; Determines when the delay is applied relative to other waiting conditions.
; Options:
; None - No special timing; delay is applied immediately (or not used).
; Before - Apply the delay before checking for WaitForProcess/WaitForModule conditions.
; After - Apply the delay after the waiting conditions are met.
DelayPosition = None
; Specify a process name that must be running before attempting to load this module.
WaitForProcess = SampleProcess.exe
; Specify an alternative method for loading the DLL.
; Options:
; 1 = Normal LoadLibrary
; 2 = LoadLibrary injection with a target process
; (Additional methods can be defined as needed.)
Method = 2
; If using an injection method, specify the target process name here.
Target = SampleProcess.exe
[ExtraModule.dll]
; Delay (in milliseconds) before attempting to load this module.
Delay = 5000
; Wait for another module to load before proceeding.
WaitForModule = MyModule.dll
; Use the normal LoadLibrary method for this module.
Method = 1LibLoader (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
IsHostX64andIsDllX64determine 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 = 0Lib-Loader v1.3.1.5
Refactored Core_LibLoader for improved file search, loading, and compatibility checks.
-
Removed WriteLog Function:
- Eliminated the
WriteLogfunction asCore_Logunit is imported for theLogclass. - Ensured all logging operations use the
Logclass directly.
- Eliminated the
-
Improved Recursive File Loading:
- Added
LoadFileFromFoldernested procedure withinLibLoader.Executeto 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
FilesLoadedlist.
- Added
-
Enhanced Error Handling:
- Logged errors for files not found in both mod directories and application/client directory.
- Prevented duplicate entries in the
FailedFileslist by checking if the file already exists in the list before adding. - Removed files from
FailedFilesif they were successfully loaded from the application/client directory.
-
Unified Loaded Files Tracking:
- Introduced a
FilesLoadedTStringList to maintain a list of all successfully loaded files across both the recursive search and application/client directory search. - Ensured
FilesLoadedis updated immediately when a file is successfully loaded from any directory. - Added checks to prevent duplicates in the
FilesLoadedlist.
- Introduced a
-
Managed TStringList Lifecycle:
- Created and properly freed all TStringLists (
ModFolders,FailedFiles,FilesToProcess,FilesToRemove,FilesLoaded) to avoid memory leaks and ensure stability. - Cleared
FilesToRemovebefore 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.CommaTextby checkingFiles2Load.Countbefore accessing it. - Ensured accurate reporting of loaded and failed files at the end of the operation.
- Fixed issue where
FilesLoadedlist had duplicate entries by checking for duplicates before adding.
-
Improved
LibLoader.WhereIsFunction:- Refactored
LibLoader.WhereIsto 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.ExecuteandLibLoader.WhereIsfunctions.
-
New Usage of Core_Log Unit:
- Utilized the
Core_Logunit for logging operations throughout the unit. - Ensured consistent logging format and levels using the
Logclass 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.