Jump to content

Overriding Vanilla Content?


FriarChris

Recommended Posts

Yeah overriding classes seems to be pretty situational. My last attempt was to override XGBattle_SP to hook PostLevelLoaded() and attach the new ability directly onto the units, bypassing the usual template scheme. But again, no dice. Looking again I think this is because XGBattle_SP is not a leaf class; all the various mission types subclass it and I don't want to have to subclass each of those.

 

I think the item scheme might be the best approach, but can we transparently add a new item to every soldier without the player needing to do anything?

Link to comment
Share on other sites

Major mods are free to modify base game packages, small mods are bigger problem.

 

I was thinking about how to properly make mission timers configurable. I know how to access kismet variables and that's still not a problem in XCOM2. But there's no tactical hook for doing such things and we can't override kismet related classes nor core gameplay classes. Probably something else we can't override either. :smile: So I decided to make a hidden ability and make it a listener to an event. With no luck, as many others, because we can't silently add an ability to soldier. Now I decided to try it with cheater item. :smile: Not that I need timers, but it was a good problem to learn from.

 

Hex editing was actually easier :smile:

Edited by wghost81
Link to comment
Share on other sites

Haha yeah. My first attempt was to adjust the soldier emotions on the dropship to be "Sad" if you had any KIA on the mission instead of just > 50% KIA. I'm always sad if I lose someone, and my team should be upset too. That's all kismet based too, but the setup for this is all handled in XComPlayerController.

 

Currently trying to add a new item based on the 'XPad' item that seems to be added to every soldier to handle hack abilities.

Link to comment
Share on other sites

FriarChris: Only one mod can override a class, so there will be huge conflicts if every mod that wants to add a base ability needs to override the same class. For "Big mods" that do total overhaul stuff is probably OK, but for the little things we want to do right now it seems silly to have mods conflict that do completely unrelated things just because they all happen to need to hook the same base class.

 

EDIT: and it looks like yes, we could in theory rebuild all of XComGame.upk, but even if we can get that working that's an enormous hammer.

Edited by tracktwo
Link to comment
Share on other sites

It is possible to overwrite data in templates. Two of the three release-day mods do this. SMGs do so with templates without difficulty variants, while the Officer mod does so with templates that *DO* have difficulty variants. However it's kind of a dirty hack...

 

Below is a simplified example class that should change the Conventional Assault Rifle's number of upgrades from 1 to 2. The hack is necessary because weapons have difficulty variants, so we have to be sure to update them for all difficulties. If you don't do this, if the user changes difficulty, suddenly the mod has bugs. :smile:

//---------------------------------------------------------------------------------------
//  FILE:    UIStrategyScreenListener_Example
//  AUTHOR:  Amineri / Long War Studios
//
//  PURPOSE: This class updates templates with difficulty variants
//--------------------------------------------------------------------------------------- 
 
class UIStrategyScreenListener_Example extends UIScreenListener;
 
var bool UpdatedTemplates;
 
function bool IsInStrategy()
{
    return `HQGAME  != none && `HQPC != None && `HQPRES != none;
}
 
// This event is triggered after a screen is initialized
event OnInit(UIScreen Screen)
{
    local X2ItemTemplateManager ItemTemplateManager;
    local X2WeaponTemplate Template;
    local int DifficultyIndex, OriginalDifficulty, OriginalLowestDifficulty;
    local XComGameState_CampaignSettings Settings;
    local XComGameStateHistory History;
 
    if(IsInStrategy() && !UpdatedTemplates)
    {
 
        History = `XCOMHISTORY;
        Settings = XComGameState_CampaignSettings(History.GetSingleGameStateObjectForClass(class'XComGameState_CampaignSettings'));
 
        OriginalDifficulty = Settings.DifficultySetting;
        OriginalLowestDifficulty = Settings.LowestDifficultySetting;
 
        //get access to item element template manager
        ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
        if (ItemTemplateManager == none) 
        {
            `Redscreen("LW Example : failed to retrieve ItemTemplateManager");
            return;
        }
 
        for( DifficultyIndex = `MIN_DIFFICULTY_INDEX; DifficultyIndex <= `MAX_DIFFICULTY_INDEX; ++DifficultyIndex )
        {
            Settings.SetDifficulty(DifficultyIndex, true);
 
            //update weapon templates as desired
            Template = X2WeaponTemplate(ItemTemplateManager.FindItemTemplate('AssaultRifle_CV'));
            if(Template != none)
            {
                Template.NumUpgradeSlots = 2;
                ItemTemplateManager.AddItemTemplate(Template, true);
            }
        }
 
        //restore difficulty settings
        Settings.SetDifficulty(OriginalLowestDifficulty, true);
        Settings.SetDifficulty(OriginalDifficulty, false);      
    }
    UpdatedTemplates = true;
}
 
// This event is triggered after a screen receives focus
event OnReceiveFocus(UIScreen Screen);
 
// This event is triggered after a screen loses focus
event OnLoseFocus(UIScreen Screen);
 
// This event is triggered when a screen is removed
event OnRemoved(UIScreen Screen);
 
defaultproperties
{
    // Leaving this assigned to none will cause every screen to trigger its signals on this class
    ScreenClass = none;
}

The trigger to execute the code is done by putting it in a class that extends UIScreenListener, but not attached to any screen, so any UIScreen will trigger it.

 

When the OnInit event is triggered, the code retrieves the appropriate TemplateManager, then loops over all difficulties, setting to each in turn. It then retrieves the template (which in native code retrieves the template for the current difficulty), makes changes, then stores it back in the TemplateManager.

 

I haven't actually compiled/executed the above code, but it's a simplified version of some code that does indeed work.

Link to comment
Share on other sites

It is possible to overwrite data in templates. Two of the three release-day mods do this. SMGs do so with templates without difficulty variants, while the Officer mod does so with templates that *DO* have difficulty variants. However it's kind of a dirty hack...

 

Below is a simplified example class that should change the Conventional Assault Rifle's number of upgrades from 1 to 2. The hack is necessary because weapons have difficulty variants, so we have to be sure to update them for all difficulties. If you don't do this, if the user changes difficulty, suddenly the mod has bugs. :smile:


When the OnInit event is triggered, the code retrieves the appropriate TemplateManager, then loops over all difficulties, setting to each in turn. It then retrieves the template (which in native code retrieves the template for the current difficulty), makes changes, then stores it back in the TemplateManager.

 

I haven't actually compiled/executed the above code, but it's a simplified version of some code that does indeed work.

 

Thank you based Amineri! :laugh: This is, incidentally, exactly what I've been trying to do as my first test,

Link to comment
Share on other sites

 

 

Thank you based Amineri! :laugh: This is, incidentally, exactly what I've been trying to do as my first test,

 

 

Well you won't need to do this for the SMG mod, as I exposed the number of upgrade slots at each tier as config variables instead of hard-coding them into the template. Similarly the schematic costs are exposed. But then, I have a bit of a mania for putting stuff into config files, I suppose :D

Link to comment
Share on other sites

 

 

 

Thank you based Amineri! :laugh: This is, incidentally, exactly what I've been trying to do as my first test,

 

 

Well you won't need to do this for the SMG mod, as I exposed the number of upgrade slots at each tier as config variables instead of hard-coding them into the template. Similarly the schematic costs are exposed. But then, I have a bit of a mania for putting stuff into config files, I suppose :D

 

 

I've worked on some projects which have their gamedata and mods in XML and I share the same mania. Anything that can be devolved to the config/XML MUST GO THERE. What do you mean you don't need to configure how many individual asteroids there are in that asteroid belt? Nonsense.

Link to comment
Share on other sites

Well at least I can edit items now.

 

But seriously, in terms of putting together a mod which would change how drops work, change how enemies behave - modify anything of the base game meaningfully - how do I go about that in general? The 'big vs small' mod dichotomy is irrelevant, A) because pls educate meh and B) if you're committing to making such changes then you're making it a 'big'/conversion mod anyway.

 

 

Also, that compiles fine but it doesn't actually change the slots :/

Edited by FriarChris
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...