• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Romulien

Lt. General
19 Badges
Jul 2, 2013
1.404
309
  • Crusader Kings II
  • Major Wiki Contributor
Portrait Builder is a tool for Windows that allows to render CK2 portraits outside of the game.

This is a fork and continuation of Measter's original tool, for which the development stopped end of 2012, but whose code was open-sourced.

Features:
  • Read portraits definitions from vanilla, portrait DLC zip archives, or flat mods
  • Preview character portraits based on portraitTypes (ethnicity, sex, age, year), dna, properties, rank and government.
    • Merchant republic and religious special clothing frames are supported via a government drop-down.
    • Societies clothing override is supported via an optional dropdown to replace sprites used by culture-indexed layers (c0->c7)
  • Auto-watch for modifications on loaded mod files while editing, to automatically reload the mod data and refresh current portrait
  • Randomize values for selected characteristics
  • Import/export DNA and properties strings
  • Save current character portrait as png image
  • Disabling of the characteristics that are not used by the selected portrait type, or that have only one frame.
  • Read the user mod folder location via a userdir.txt file in Steam directory (if any)
Limitations:
  • Only works on Windows, compatibility for Linux/Mac with Mono is not working.
    • Note: the tool has some rendering issues with HIP/CPR+ mod on Win7.
  • Does not support archived mods (the ones downloaded from Steam Workshop as .zip)
  • Load order of gfx files is hardcoded to vanilla -> DLCs (alphabetical) -> mods (alphabetical), i.e. "dependencies" of .mod files is not taken into account for overridden files. If you need this for a mod, report it here so it gets supported.
  • Government list is hardcoded with vanilla governments (no parsing of governments from mods)
PortraitBuilder-2.5.0.jpg


Installation:
  • Download PortraitBuilder-2.5.0.zip and unzip it somewhere.
  • Download and install required .NET 4.5 library (in case not already installed)
  • Start PortraitBuilder.exe
  • Select the location of your CK2game.exe (for instance: C:\Program Files (x86)\Steam\SteamApps\common\Crusader Kings II\CK2game.exe) - You can get it from Steam, by right-clicking the game in the library, then Properties / Local Files / Browse Local Files. This value will be kept into a gamedir file.
  • Wait 20-30s for the DLCs to unzip, then the UI should show up.
  • In case of crash, look into the log.txt file for details.
Notes:
Full changelog:

By Romulien:

Version 2.5.0 - 2018-01-27

- Add labels for new vanilla 2.8 properties (p14 makeup, p15 makeup2, p16 jewelry and p17 immortality)
- Add new 2.8 government frames
- Allow selection of characteristics to update when clicking randomize button
- Read mod directory from userdir.txt file in Steam CK2 folder, if any
- Prevent crash when mod directory doesn't exist
- Support unquoted values for spriteType name and texturefile
- Show incompatible mods as disabled in the list, with the reason in tooltip (archived mods, no portrait data or invalid path)

Version 2.4.0 - 2017-04-07

- Support for clothing propertyType override, replacing sprites used by culture-indexed layers (c0->c5)
- Support for a variable number of properties, with dynamic creation of characteristic comboboxes in the UI
- Improve error reporting when parsing portraits.gfx when parsing string into integer or byte
- Allow non-ordered flags in propertyType layers
- Fix randomization that was never using the last frame
- Solve some eye-related rendering issues caused by attempting to read pixels outside of the width/height of the source image

Version 2.3.0 - 2016-09-03

- Support for mask (p12) and eyepatch (p13) new characteristics
- Add dropdowns for head (p2), d5 and d10 characteristics, in case used by mods
- Disable dropdown if sprite has only 1 frame (e.g. p2)
- Remove randomization when dna/properties 'letter' is 0 , and use index 0 instead
- 'letter' 0 is now used in output dna/properties strings with index 0, instead of (max - 1)

Version 2.2.0 - 2016-07-03

UI:
- Add government dropdown
- Add some tooltips to UI controls

Engine:
- Implement override logic for religious and merchant special sprites
- Add file watchers to mod content, in order to auto-refresh in case of changes
- Add some safeties to .mod file parsing
- Add unhandled exceptions handlers in application

Code re-factoring:
- Upgrade dependencies and use NuGet to retrieve them
- Switch DDS lib from DevIL to CSharpImageLibrary
- Generate .pdb to always have line numbers for exceptions
- Use Costura.Fody to embed dependencies in assembly

Version 2.1.0 - 2016-06-25

UI:
- Use better icon
- Add DLC/mod tabs
- Add "Toggle All" and "Reload" buttons for content.
- Keep selected portraitType when enabling DLC/mod
- Use 2 tabs instead of 3, and move hair/eye color to DNA tab
- Move PORTRAIT_ prefix as a label for portraitType dropdown
- Add d/p codes in labels
- Add warning for properties overridden via portrait_properties.txt
- Rename Earl to Count
- Add dropdown for Player (p11), used in certain mods
- Disable dropdown when a dna/property is not used by any portraitType layer, rather than adding index 0-26.

Engine:
- Split DLCs so they can be activated separately
- Support rendering from multiple mods
- Parse vanilla/DLCs/mods portrait data only once during startup
- Avoid unzipping DLCs at startup if not needed (use Reload button to force refresh)
- Filter files to unzip from DLC, to reduce loading time & size.
- Allow content to only contain sprites in gfx/characters/, without portraitTypes
- Fix bug were duplicate portraitType definition would not override previous one (byzantinegfx)
- Fix load order of assets that was using vanilla instead of mod
- Optimize memory usage, by unloading assets when reloading/unchecking content
- Catch parsing failures at spriteType / portraitType level

Code re-factoring:
- Simplify code structure within a single project
- Separate class concerns to have smaller files
- Adapt class namespaces to match new folder structure
- Replace redundant CustomFlags by proper characteristics

Version 2.0.0 - 2016-04-04
- Compatibility with vanilla 2.5.2
- Update lookup of ck2.exe to CK2game.exe
- Support for offsets (inline and external)
- Support for extra proprty p11 (player overlay)
- Support for DLCs. Disable buggy mod loading, for now.
- Replace poorly usable BrowseFolderDialog by an OpenFileDialog, to locate CK2 .exe
- Rework the logging, using log4net, with various log levels
- Append the version to the window title
- Add an icon to the .exe
- Remove code duplication, and general cleanup of the code
- Fix some gfx parsing errors
- Try/catch around some bad .dds files like western_male_eyes2.dds that cause exceptions

By Measter:

Version 1.1.7 - 2012-11-24
- Added logging. Outputs log on error, and can be forced to output with -log.
- Now attempts to load portrait info from all .gfx files in \interface.
- Can now load mods from My Documents folder.
- Fixed crash when trying to parse a portrait type which already exists.

Version 1.1.6
- Fixed bug in import validation.
- Changed notice text in import dialog to specify 11 digits.

Version 1.1.5
- Updated for CKUtils 1.8.
- Now loads portrait sprites from portrait_sprites.gfx.
- Added selector for the 11th property digit.
- Importing now requires 11 digits for property code.

Version 1.1.4
- Changed UI setup to not be dependent on certain keywords.

Version 1.1.3
- Fixed bug in Muslim hair rendering in vanilla files.

Version 1.1.2
- Added digit to DNA code output to prevent game crash(again).
- Fixed bug when importing DNA codes when using a female portrait set.
- DNA and Property codes are now no longer randomized when changing portrait sets.

Version 1.1.1
- Fixed bug causing crash due to lack of beard on females.

Version 1.1
- Rewrote the program to use CK2s portrait.gfx file instead of .portset files.

Version 1.0.3
- Added randomization button.

Version 1.0.2
- Fixed bug causing the first tile to have the wrong index.

Version 1.0.1
- Changed the DNA output to match the length of that in the game's character definition.
 

Attachments

  • PortraitBuilder-2.0.0.zip
    884,8 KB · Views: 154
  • PortraitBuilder-2.1.0.zip
    890,7 KB · Views: 116
  • PortraitBuilder-2.2.0.zip
    525,5 KB · Views: 225
  • PortraitBuilder-2.3.0.zip
    526,4 KB · Views: 840
  • PortraitBuilder-2.4.0.zip
    523,6 KB · Views: 1.428
  • PortraitBuilder-2.5.0.zip
    520 KB · Views: 3.630
  • PortraitBuilder-3.0.0.1.zip
    281,5 KB · Views: 303
  • PortraitBuilder-3.0.0.2.zip
    292,4 KB · Views: 1.274
Last edited:
  • 20
  • 3
Reactions:
Portrait Builder utility is back in business ! :cool:

This is a fork and continuation of Measter's great tool (original thread: https://forum.paradoxplaza.com/forum/index.php?threads/utility-portrait-builder.604169/ ), for which the development stopped end of 2012.

It should now be compatible with vanilla 2.5.2 and all graphical DLCs.
Mod support has been disabled, until a solution is found to support DLCs + multiple (sub-)mods at the same time.

Installation:
  • Download and install required .NET 4.5 library (in case not already installed)
  • Download PortraitBuilder.zip and unzip it somewhere.
  • Start PortraitBuilder.exe
  • Select the location of your CK2game.exe (for instance: C:\Program Files (x86)\Steam\SteamApps\common\Crusader Kings II\CK2game.ex) - You can get it from Steam, by right-clicking the game in the library, then Properties / Local Files / Browse Local Files. This value will be kept into a gamedir file.
  • Wait 20-30s for the DLCs to unzip, then the UI should show up.
  • In case of crash, look into the log.txt file for details.

Changelog:

Does "Graphical DLC" include maybe mods in .zip format dropped in the main directory?

You have no idea how useful this program could be to me specifically. Also, excited to try it!
 
  • 1
Reactions:
Thank you for bringing this up to date, I'm sure it will be very helpful for the modding community!
 
  • 2
Reactions:
Does "Graphical DLC" include maybe mods in .zip format dropped in the main directory?

You have no idea how useful this program could be to me specifically. Also, excited to try it!

I can imagine the pain of waiting for the game to load every time...

Yes, that workaround will actually work :p
Drop the .zip and .mod file in \common\Crusader Kings II\DLC\, and adapt the .mod file:
- change the .mod file extension to .dlc
- change the archive path from
Code:
archive = "mod/mymod.zip"
to
Code:
archive = "dlc/mymod.zip"
- it's probably best to start the zip name with a letter after d, so that the mod is loaded last (in case it overrides DLC stuff)

For a more convenient solution, I'm thinking to expand the UI with a scrollable list of DLCs and mods, with check-boxes to activate/deactivate each one individually (i.e. similar to the game launcher) - if feasible. What do you think ?
 
Last edited:
  • 5
  • 1
Reactions:
Wouldn't it be archive = "dlc/mymod.dlc" since you're changing the filetype to .dlc?
 
I can imagine the pain of waiting for the game to load every time...

I've logged like 100 hours of play time just loading the game up to test something.

And that's just for when I haven't bothered to take the game files out and play outside of Steam.

For a more convenient solution, I'm thinking to expand the UI with a scrollable list of DLCs and mods, with check-boxes to activate/deactivate each one individually (i.e. similar to the game launcher) - if feasible. What do you think ?

I think that's great, personally.

Hardmode suggestions: Make it so that way you can modify the RGB values of the eye color and hair color and export them in the same way they are in the .gfx files to avoid the "type save overwrite reload" of customizing hair color. Or have the ability to pixel shift and export to create custom offset files. :)
 
  • 1
Reactions:
Wouldn't it be archive = "dlc/mymod.dlc" since you're changing the filetype to .dlc?

I've clarified my post, it is the .mod that needs to be renamed to .dlc, the zip archive remains as-is.

Hardmode suggestions: Make it so that way you can modify the RGB values of the eye color and hair color and export them in the same way they are in the .gfx files to avoid the "type save overwrite reload" of customizing hair color. Or have the ability to pixel shift and export to create custom offset files. :)

Would a "refresh/reload portrait" button, to quickly take into account latest changes in .gfx / offsets / assets files help ?
I'd prefer to keep the file editing and portrait rendering separate, due to the complexity of the UI that would be needed for proper editing.
 
  • 1
Reactions:
Would a "refresh/reload portrait" button, to quickly take into account latest changes in .gfx / offsets / assets files help ?
I'd prefer to keep the file editing and portrait rendering separate, due to the complexity of the UI that would be needed for proper editing.

Sure thing, that would work.
 
2.1.0
PortraitBuilder 2.1.0 is now released, and has mod support !
It also contains some UI and performance improvements.
See the first post for download and installation instruction.

Mods were tricky because they may contain bad syntax, empty or corrupted files, etc.
I've tested with a few of them, but feel free to report issues, by comparing the rendering in-game and with PortraitBuilder.
In particular I've noticed an issue in BLG with sprite betterlookinggarbs\gfx\characters\shared\imprisoned.dds, which seems corrupted (couldn't test if it's also broken in-game).

For next release, I'm planning to add support for religious & merchants clothing as well as government frames, probably via a dropdown with an hardcoded list of vanilla governments.

Changelog:
Version 2.1.0 - 2016-06-25

UI:
- Use better icon
- Add DLC/mod tabs
- Add "Toggle All" and "Reload" buttons for content.
- Keep selected portraitType when enabling DLC/mod
- Use 2 tabs instead of 3, and move hair/eye color to DNA tab
- Move PORTRAIT_ prefix as a label for portraitType dropdown
- Add d/p codes in labels
- Add warning for properties overridden via portrait_properties.txt
- Rename Earl to Count
- Add dropdown for Player (p11), used in certain mods
- Disable dropdown when a dna/property is not used by any portraitType layer, rather than adding index 0-26.

Engine:
- Split DLCs so they can be activated separately
- Support rendering from multiple mods
- Parse vanilla/DLCs/mods portrait data only once during startup
- Avoid unzipping DLCs at startup if not needed (use Reload button to force refresh)
- Filter files to unzip from DLC, to reduce loading time & size.
- Allow content to only contain sprites in gfx/characters/, without portraitTypes
- Fix bug were duplicate portraitType definition would not override previous one (byzantinegfx)
- Fix load order of assets that was using vanilla instead of mod
- Optimize memory usage, by unloading assets when reloading/unchecking content
- Catch parsing failures at spriteType / portraitType level

Code re-factoring:
- Simplify code structure within a single project
- Separate class concerns to have smaller files
- Adapt class namespaces to match new folder structure
- Replace redundant CustomFlags by proper characteristics

Would love mod portrait support though.

Done ! :)
 
  • 4
Reactions:
Nice, thanks for the hard work! I'll give the new version a try as soon as my next generation comes of age, no doubt. (If portraits/dna affected the "ugly" trait, all of my Genius/Quick/Strong dynasty members would have it...)
 
Hello ! your software seems to be great but it doesn't launch for me i check the log files and i do not found any errors. Can you help me ?:)
 
Hello ! your software seems to be great but it doesn't launch for me i check the log files and i do not found any errors. Can you help me ?:)

Sure, but I'll need a bit more info to be able to help ^^
Does it generate a log.txt next to PortraitBuilder.exe ?
If yes, can you show or PM me the content, to know which step it passed ?
If no, it means it doesn't succeed to launch the application at all, maybe some .dll from the .zip are missing or .NET 4.5 (which version of Windows do you have ?) ?
 
2.2.0
PortraitBuilder 2.2.0 is now released !
See the first post for download and installation instructions.

It adds support for governments, with the rendering of theocracy and merchant republic special clothing.
List of governments is hardcoded from vanilla (no parsing of government files / frame_suffix).

It also adds a "file watcher" on activated mods: changing any portraits .gfx, .dds assets or external offsets .txt, will trigger a refresh of mod data and re-draw of portrait.
Implementation is basic (whole mod data gets refreshed), but performances seem OK.

With this done, I'm hoping PortraitBuilder has all the important stuff in, and I don't plan any other releases, except for potential bugfixes or compatibility with a future vanilla patch.
Feel free to suggest other features though, if you feel something is missing !

Full changelog:
Version 2.2.0 - 2016-07-03

UI:
- Add government dropdown
- Add some tooltips to UI controls

Engine:
- Implement override logic for religious and merchant special sprites
- Add file watchers to mod content, in order to auto-refresh in case of changes
- Add some safeties to .mod file parsing
- Add unhandled exceptions handlers in application

Code re-factoring:
- Upgrade dependencies and use NuGet to retrieve them
- Switch DDS lib from DevIL to CSharpImageLibrary
- Generate .pdb to always have line numbers for exceptions
- Use Costura.Fody to embed dependencies in assembly

PortraitBuilder-2.2.0.jpg


Sure thing, that would work.

Done, using file watchers on active mods !

Hello ! your software seems to be great but it doesn't launch for me i check the log files and i do not found any errors. Can you help me ?:)

Based on your logs I couldn't identify the cause for certain, but I've made the .mod files parsing a bit more robust.
I've also added line numbers in exception stacktrace (.pdb file), so that if issue is still there with new version, new logs should allow to narrow it down !
 
Last edited:
  • 4
Reactions: