Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mechs that get knocked down after either getting hit in the head or losing their head causes an exception #14

Open
janxious opened this issue Sep 13, 2018 · 11 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@janxious
Copy link
Owner

No description provided.

@janxious janxious added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Sep 13, 2018
@gnivler
Copy link
Contributor

gnivler commented Sep 13, 2018

Hi. I'm trying to setup a savegame for testing so hoping to clarify a couple key points if you could. Do you know if the knockdown from head hit/destruction, throws on weapons fire or only melee? Do you know what is the exception? Thanks!

@janxious
Copy link
Owner Author

@gnivler Here's what I have right now

[5:37 PM] jo: @LadyAlekto was there any more context for that charlesb thing? I couldn't find any in the scrollback
[5:38 PM] LadyAlekto: when that stacktrace happens
[5:38 PM] LadyAlekto: the game freezes
[5:38 PM] LadyAlekto: or rather turndirector freezes
[5:38 PM] jo: sure but are there steps leading to it?
[5:38 PM] LadyAlekto: mech got knocked over
[5:39 PM] LadyAlekto: thats all the steps i could observe os far
[10:08 AM] Thegingermagician: @LadyAlekto same glitch again where the leader is dead but the computer still thinks he is alive
[10:09 AM] Arcanan: try doing using a called shot on that target
[10:09 AM] LadyAlekto: @jo got told of the stacktrace that caused the bug, do you have a way to reliably reproduce it to he may find what exactly goes wrong?
[10:09 AM] Thegingermagician: hes untargetable
[10:10 AM] Thegingermagician: i can give you my log but it only happens when he headshot and then knocked down
[4:34 PM] akodoreign: got an immortal unit. cannot target it to kill, someone said a way to finish it off, if someone could remind me :wink: (its dead but computer claimes its not quite dead yet)
[4:34 PM] LadyAlekto: and it happens when charlesb kills a unit on knockdown :/

@gnivler
Copy link
Contributor

gnivler commented Sep 14, 2018

Cool thanks. That looks a bit like #12 that I thought was just me.

Yesterday I was able to execute all test scenarios without reproducing a bug. I'll try again. I had knocked over opfor with melee, shooting, punching and DFA (I rigged the json to make all hits go to head).

Update: I've been unable to repro the issue at all.

@gnivler
Copy link
Contributor

gnivler commented Sep 25, 2018

I replicated it during normal play it appears.

I wonder if the trigger is actually the head being destroyed by a fall.

Update: confirmed this NRE occurs when a mech falls and Charles destroys the head

Easy to repro if you hardcode the mod to only destroy the head. First knockdown will throw.

NullReferenceException: Object reference not set to an instance of an object
at BattleTech.Mech.ApplyHeadStructureEffects (BattleTech.ChassisLocations,BattleTech.LocationDamageLevel,BattleTech.LocationDamageLevel,BattleTech.WeaponHitInfo) <0x000bc>
at BattleTech.Mech.ApplyStructureStatDamage (BattleTech.ChassisLocations,single,BattleTech.WeaponHitInfo) <0x004eb>
at BattleTech.Mech.DEBUG_DamageLocation (BattleTech.ArmorLocation,single,BattleTech.AbstractActor,BattleTech.DamageType) <0x00834>
at CharlesB.MechFallSequenceDamageAdder.ApplyFallingDamage (BattleTech.MechFallSequence,int,int) <0x006a3>
at (wrapper dynamic-method) BattleTech.MechFallSequence.setState_Patch0 (object,BattleTech.MechFallSequence/MechFallState) <0x00036>
at BattleTech.MechFallSequence.Update () <0x00203>
at BattleTech.MechFallSequence.OnUpdate () <0x0001c>
at BattleTech.MultiSequence.OnUpdate () <0x001ff>
at BattleTech.OrderSequence.OnUpdate () <0x00022>
at BattleTech.AttackStackSequence.OnUpdate () <0x0001c>
at BattleTech.StackManager.Update () <0x00482>
at BattleTech.CombatGameState.Update () <0x00035>
at BattleTech.GameInstance.Update (single) <0x00034>
at (wrapper dynamic-method) BattleTech.UnityGameInstance.Update_Patch1 (object) <0x0005c>

image

@gnivler
Copy link
Contributor

gnivler commented Sep 26, 2018

The issue appears to be that attackSequence is null. I have no ideas how to address this off the top of my head...
image

@gnivler
Copy link
Contributor

gnivler commented Sep 26, 2018

I don't know with any certainty but I'm tempted to call this a vanilla bug. I re-wrote the method in a patch and simply added a null check, which is present in related code. Just works now.

[HarmonyPatch(typeof(Mech), "ApplyHeadStructureEffects", MethodType.Normal)]
public static class Mech_ApplyHeadStructureEffects_Patch
{
    public static bool Prefix(
        Mech __instance,
        ChassisLocations location,
        LocationDamageLevel oldDamageLevel,
        LocationDamageLevel newDamageLevel,
        WeaponHitInfo hitInfo)
    {
        var mech = __instance;
        mech.pilot.SetNeedsInjury(InjuryReason.HeadHit);
        if (newDamageLevel == oldDamageLevel) return false;
        if (newDamageLevel == LocationDamageLevel.Destroyed)
        {
            AttackDirector.AttackSequence attackSequence =
                mech.Combat.AttackDirector.GetAttackSequence(hitInfo.attackSequenceId);
            if (attackSequence != null)
            {
                mech.pilot.LethalInjurePilot(
                    mech.Combat.Constants,
                    hitInfo.attackerId,
                    hitInfo.stackItemUID,
                    true,
                    DamageType.HeadShot,
                    attackSequence.GetWeapon(hitInfo.attackGroupIndex, hitInfo.attackWeaponIndex),
                    attackSequence.attacker);
            }
            mech.Combat.MessageCenter.PublishMessage(
                new AddSequenceToStackMessage(
                    new ShowActorInfoSequence(mech, "PILOT: LETHAL DAMAGE!", FloatieMessage.MessageNature.PilotInjury, true)))
        }
        return false;
    }
}

@janxious
Copy link
Owner Author

With that patch is the head still destroyed in the end?

@gnivler
Copy link
Contributor

gnivler commented Sep 27, 2018 via email

@gnivler
Copy link
Contributor

gnivler commented Oct 5, 2018

Frig, I forgot about this, sorry. Well more accurately procrastinated, then forgot.
Patch as-is is no good, leaves the pilot uninjured.

image

update: Tried a few things I could come up with but no joy. My thought is that checking for head destruction and doing it manually, by mimicking how the game does it, might do the trick.

if (locationTakingDamage == ArmorLocation.Head &&
   fallingDamageValue >= mech.GetCurrentArmor(ArmorLocation.Head) + mech.GetCurrentStructure(ChassisLocations.Head))
{
   mech.pilot.StatCollection.ModifyStat("", 0, "LethalInjury", StatCollection.StatOperation.Set, true);
}

is not enough not surprisingly 👎

@janxious
Copy link
Owner Author

janxious commented Oct 5, 2018

Don't worry about it. I have a fix mostly worked out, I think.The issue is primarily that the damage code expects a weapon to be involved, so I may create a new weapon called "TheGround" for this mod.

@gnivler
Copy link
Contributor

gnivler commented Oct 6, 2018

Ok right on I'm glad, was going to ask if you had ideas. I was thinking something might need to be created and had tried new Mech() and new Weapon() which compiled.. but yeah, didn't work :)

I've got the testing method more or less cased, if you want me to test your changes just lemme know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants