Jump to content

Adding Additional Perks to Aliens


Krazyguy75

Recommended Posts

Hello,

 

I've been working on a mod that makes it much harder for me to win, via giving the Aliens additional abilities. But I wanted something more than that: I wanted additional perks.

 

I was wondering if anyone has gathered research on how to add perks to Alien types. I see a lot of research on giving your soldier cool new perk trees, but I have yet to find any code on giving Aliens perks.

 

Is it possible to do this?

Link to comment
Share on other sites

It is possible, with some substantial hex editing. Generally you should only give the aliens 'passive' perks, not ones (like Run N' Gun) that would require additional AI for them to utilize.

 

This thread has a few of the basics

  Quote

 

What we've done in Long War is take over and rewrite a debugging function to grant perks to semi-randomly to aliens after a certain amount of time has passed. Unfortunately, in Long War it is integrated with several other features (like larger pods and alien research) so I'm not sure sharing only the specific perk-granting code would help you very much, but I'd be happy to if you'd like.

Link to comment
Share on other sites

I created a simplified version of what was done in Long War, calling the XGUnit.DebugAnims function that was taken over in order to assign perks to aliens from the XGUnit.Init instead of from the pod creation.

 

I also set up a basic ternary hex template which can be more easily duplicated to assign new perks to aliens without having to calculate jump offsets, so it's a bit more friendly for novice hex coders.

 

The prototype ternary hex looks like so:

(Offset == ## ? m_kCharacter.GivePerk(##) : nothing) (40 bytes perk added)
45 9A 00 97 B5 00 00 2C ## 16 21 00 19 01 0A 31 00 00 0C 00 EA A2 00 00 00 1B B7 35 00 00 00 00 00 00 2C ## 16 01 00 0B 

Offset is the holder of the alien's pawn type. Pawn types can be looked up using Bertilsson's excellent reverse lookup tool : http://hem.bredband.net/bertrich/XCOM/ReverseLookup.htm

 

I also have a "cheatsheet" of alien pawntypes:

 

  Reveal hidden contents

 

 

So there's really two parts to this.

 

The first is to apply the hex change the causes XGUnit.Init to call DebugAnims for alien units:

 

 

  Reveal hidden contents

 

 

This changes the lines:

    if(IsAI())
    {
        InitBehavior();
    }
    else // 3 bytes
    {
        if(isHuman()) 
        {
        }
    }

to:

    if(IsAI())
    {
        InitBehavior();
        DebugAnims(local1, local2);
    }

The second step is re-building the DebugAnims function to assign perks to aliens based on pawn type.

 

Here's some example broken down hex lines that illustrate how a variety of perks are given to different aliens in DebugAnims :

 

  Reveal hidden contents

 

 

One slightly tricky bit is updating the function header based on the number of perk lines added. Each new ternary operator line assigning a new perk adds 40 file bytes and 52 memory bytes (so +12 memory bytes). This means that the memory size in the function header has to be increased by 12 = 0x0C for every line added.

 

Here's an example of before / after code including the different headers. The before section is the original vanilla code for DebugAnims (which is being entirely replaced).

 

  Reveal hidden contents

 

 

The original function's header is:

header:
B3 B5 00 00 50 55 00 00 00 00 00 00 93 B5 00 00 00 00 00 00 00 00 00 00 9E B5 00 00 00 00 00 00 FE 23 00 00 84 8D 04 00 B2 0E 00 00 02 0A 00 00 

The key parts here are the last two 4 byte words, 0xEB2 and 0xA02. 0xEB2 is the memory size of the function and 0xA02 is the file size of the function. If these don't match the game will CTD on startup.

 

The new function's header is:

B3 B5 00 00 50 55 00 00 00 00 00 00 93 B5 00 00 00 00 00 00 00 00 00 00 9E B5 00 00 00 00 00 00 FE 23 00 00 84 8D 04 00 96 0A 00 00 02 0A 00 00 

Note that the file size of 0xA02 is unchanged, but the memory size declared has been reduced to 0x48D.

 

The first line assigning the pawntype to the variable Offset adds 4 memory bytes. There are 12 perks being assigned, and each adds 12 memory bytes. This results in 12 * 12 + 4 = 148 = 0x94 additional required memory bytes above the basic file size. 0xA02 + 0x94 = 0xA96, which is the new function's declared memory size.

Link to comment
Share on other sites

Wow, I can't believe I missed that with all my searching...

 

But thank you all for your help, it's been very useful!

 

Now the Ethereal Uber should have Vengeance shots for the non-deflected attacks (of course, there were other changes, but this is my favorite; hopefully vengeance works with the Elder Weapon).

Link to comment
Share on other sites

  On 8/5/2013 at 3:57 AM, Krazyguy75 said:
Now the Ethereal Uber should have Vengeance shots for the non-deflected attacks (of course, there were other changes, but this is my favorite; hopefully vengeance works with the Elder Weapon).

Very unlikely, because Vengeance force unit to take reaction shot against attacker, and it seems like Elder Weapon cannot do overwatch/reaction shots at all. Or any shots at all. While Psi-Lance is treated like normal shot (hit percentages affected by cover and all), but ultimately is an ability of Ethereal itself (ie character ability), and Elder Weapon is needed to launch those Psi-Lances in similar way, how Heavy needs his rocket lancher to fire rockets.

Edited by Tycus
Link to comment
Share on other sites

  On 8/5/2013 at 8:14 AM, Tycus said:

 

  On 8/5/2013 at 3:57 AM, Krazyguy75 said:
Now the Ethereal Uber should have Vengeance shots for the non-deflected attacks (of course, there were other changes, but this is my favorite; hopefully vengeance works with the Elder Weapon).

Very unlikely, because Vengeance force unit to take reaction shot against attacker, and it seems like Elder Weapon cannot do overwatch/reaction shots at all. Or any shots at all. While Psi-Lance is treated like normal shot (hit percentages affected by cover and all), but ultimately is an ability of Ethereal itself (ie character ability), and Elder Weapon is needed to launch those Psi-Lances in similar way, how Heavy needs his rocket lancher to fire rockets.

 

I'm slightly confused. Would adding the ShotStandard and Overwatch abilities to the item allow it to be used for reaction? I lack much experience with the games coding, so I'm not quite sure why it would be very different from, say, the Sectopods overwatch cannon. It doesn't have CantReact..? Is it because it lacks a Rifle or Secondary, or etc? Or is there some other variable which determines which items can be used for reaction?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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