Skip to content

Commit

Permalink
Revert "Implemented Issue #783 - add DLC hook to modify generated uni…
Browse files Browse the repository at this point in the history
…t appearance."

This reverts commit d8b0784.
  • Loading branch information
Iridar51 committed May 28, 2021
1 parent d8b0784 commit c82bf5e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,43 +762,3 @@ final function string GetDisplayName()
return ModDependency.DisplayName;
}
/// End Issue #524

// Start Issue #783
// <summary>
/// Called from XGCharacterGenerator:CreateTSoldier
/// Has no return value, just modify the CharGen.kSoldier directly.
/// HL-Docs: feature:ModifyGeneratedUnitAppearance; issue:783; tags:customization,compatibility
/// ## Usage
/// This DLC hook allows mods to make arbitrary changes to unit appearance
/// after it has been generated by `XGCharacterGenerator::CreateTSoldier()`.
/// The generated appearance is stored in `CharGen.kSoldier`, which you can modify directly.
/// Other arguments are provided to you mostly for reference,
/// and presented to you as they were used by the `CreateTSoldier()` function.
/// The UnitState and the GameState will be passed to this hook
/// only if the `CreateTSoldier()` function was called from `CreateTSoldierFromUnit()`,
/// which normally happens only in the Shell code (TQL / Challenge Mode / Character Pool),
/// and will be `none` otherwise.
/// If you wish to "redo" some parts of the process of generating unit's appearance,
/// you can call various methods in the Character Generator,
/// but you must avoid calling the `CreateTSoldier()` and `CreateTSoldierFromUnit()` methods,
/// as that will retrigger the hook, potentially causing an inception loop and crashing the game.
/// ## Compatibility
/// Custom `XGCharacterGenerator` classes used by mods to generate appearance of custom units
/// can potentially interfere with the normal operation of this hook for themselves.
/// If the Character Generator implements a custom `CreateTSoldier()` function that
/// does not call `super.CreateTSoldier()`, then this DLC hook will not be called for that class.
/// If `super.CreateTSoldier()` *is* called, but the custom `CreateTSoldier()` function
/// makes changes to the generated appearance afterwards, it can potentially override
/// changes made by this hook.
/// For example, Character Generators for Faction Hero classes had to be adjusted
/// in the Highlander so that they do not override Country and Nickname after
/// calling `super.CreateTSoldier()`, and instead override the `SetCountry()` and
/// `GenerateName()` methods, which are called by `super.CreateTSoldier()`.
/// For best compatibility with this hook, mod-added `XGCharacterGenerator()` classes
/// should avoid making any appearance changes after calling `super.CreateTSoldier()`.
/// Ideally, that function should not be overridden at all, and the Character Generator
/// should rely on overriding other methods called by `CreateTSoldier()` as much as possible.
// </summary>
static function ModifyGeneratedUnitAppearance(XGCharacterGenerator CharGen, const name CharacterTemplateName, const EGender eForceGender, const name nmCountry, const int iRace, const name ArmorName, XComGameState_Unit UnitState, XComGameState UseGameState)
{}
/// End Issue #783
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ var config float DLCPartPackDefaultChance;
var int m_iHairType;

// temporary variable for soldier creation, used by TemplateMgr filter functions
// Start unprotect variables for issue #783
var /*protected*/ TSoldier kSoldier;
var /*protected*/ X2BodyPartTemplate kTorsoTemplate;
var /*protected*/ name MatchCharacterTemplateForTorso;
var /*protected*/ name MatchArmorTemplateForTorso;
var /*protected*/ array<name> DLCNames; //List of DLC packs to pull parts from for the currently generating soldier.
// End unprotect variables for issue #783
var protected TSoldier kSoldier;
var protected X2BodyPartTemplate kTorsoTemplate;
var protected name MatchCharacterTemplateForTorso;
var protected name MatchArmorTemplateForTorso;
var protected array<name> DLCNames; //List of DLC packs to pull parts from for the currently generating soldier.

// Store a country name to be use in bios for soldiers that force a unique country
var name BioCountryName;
Expand All @@ -141,11 +139,6 @@ var X2CharacterTemplate m_CharTemplate;
// New variable for issue #397
var config(Content) int iDefaultWeaponTint;

// Start issue #783
var XComGameState_Unit GenerateAppearanceForUnitState;
var XComGameState GenerateAppearanceForGameState;
// End issue #783

function GenerateName( int iGender, name CountryName, out string strFirst, out string strLast, optional int iRace = -1 )
{
local X2StrategyElementTemplateManager StratMgr;
Expand Down Expand Up @@ -301,26 +294,10 @@ function TSoldier CreateTSoldierFromUnit( XComGameState_Unit Unit, XComGameState
{
local XComGameState_Item ArmorItem;
local name ArmorName;
// Variable for issue #783
local TSoldier CreatedTSoldier;

ArmorItem = Unit.GetItemInSlot(eInvSlot_Armor, UseGameState, true);
ArmorName = ArmorItem == none ? '' : ArmorItem.GetMyTemplateName();

// Start issue #783
GenerateAppearanceForUnitState = Unit;
GenerateAppearanceForGameState = UseGameState;

CreatedTSoldier = CreateTSoldier( Unit.GetMyTemplateName(), EGender(Unit.kAppearance.iGender), Unit.kAppearance.nmFlag, Unit.kAppearance.iRace, ArmorName );

// Blank the properties just in case this instance of the Character Generator will be used to also call CreateTSoldier() separately,
// which would trigger the 'PostUnitAppearanceGenerated' event another time, but it would still pass the same Unit State and Game State from the time CreateTSoldierFromUnit()
// was called. So we blank them out to make sure we're not passing irrelevant information with the event.
GenerateAppearanceForUnitState = none;
GenerateAppearanceForGameState = none;

return CreatedTSoldier;
// End issue #783
return CreateTSoldier( Unit.GetMyTemplateName(), EGender(Unit.kAppearance.iGender), Unit.kAppearance.nmFlag, Unit.kAppearance.iRace, ArmorName );
}

delegate bool FilterCallback(X2BodyPartTemplate Template);
Expand Down Expand Up @@ -403,28 +380,9 @@ function TSoldier CreateTSoldier( optional name CharacterTemplateName, optional

BioCountryName = kSoldier.nmCountry;

// Start issue #783
ModifyGeneratedUnitAppearance(CharacterTemplateName, eForceGender, nmCountry, iRace, ArmorName);
// End issue #783

return kSoldier;
}

// Start issue #783
private function ModifyGeneratedUnitAppearance(optional name CharacterTemplateName, optional EGender eForceGender, optional name nmCountry = '', optional int iRace = -1, optional name ArmorName)
{
local array<X2DownloadableContentInfo> DLCInfos;
local int i;

/// HL-Docs: ref:ModifyGeneratedUnitAppearance; issue:783
DLCInfos = `ONLINEEVENTMGR.GetDLCInfos(false);
for (i = 0; i < DLCInfos.Length; i++)
{
DLCInfos[i].ModifyGeneratedUnitAppearance(self, CharacterTemplateName, eForceGender, nmCountry, iRace, ArmorName, GenerateAppearanceForUnitState, GenerateAppearanceForGameState);
}
}
// End issue #783

static function Name GetLanguageByString(optional string strLanguage="")
{
if (len(strLanguage) == 0)
Expand Down Expand Up @@ -1069,4 +1027,4 @@ function string GenerateNickname(X2SoldierClassTemplate Template, int iGender)
}

return "";
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit c82bf5e

Please sign in to comment.