Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Bannerlord Fix IndexOutOfRangeException at TaleWorlds.CampaignSystem.Roster.TroopRoster.AddToCountsAtIndex
- 1. Get dnSpy here:
- https://github.com/dnSpy/dnSpy/releases
- 2. Extract and run dnSpy.exe.
- 3. Go to
- C:\Program Files (x86)\Steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client
- 4. Make a copy of TaleWorlds.CampaignSystem.dll just in case.
- 5. Drag relevant libraries into dnSpy (left window thing), we want to edit TaleWorlds.CampaignSystem.dll so drag that in, might have to drag other ones in as well, I forgot.
- 6. In the toolbar at the top, go Edit -> Search Assemblies. Search for AddToCountsAtIndex and double click the result.
- 7. Right click on AddToCountsAtIndex and press Edit Method (C#)...
- 8. Replace the text with this:
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using TaleWorlds.CampaignSystem.Party;
- using TaleWorlds.Core;
- using TaleWorlds.Library;
- using TaleWorlds.SaveSystem;
- namespace TaleWorlds.CampaignSystem.Roster
- {
- // Token: 0x0200028C RID: 652
- public partial class TroopRoster : ISerializableObject
- {
- // Token: 0x06002222 RID: 8738
- public int AddToCountsAtIndex(int index, int countChange, int woundedCountChange = 0, int xpChange = 0, bool removeDepleted = true)
- {
- try
- {
- this.UpdateVersion();
- bool heroCountChanged = false;
- CharacterObject character = this.data[index].Character;
- bool isHero = character.IsHero;
- TroopRosterElement[] array = this.data;
- int num = index;
- array[num].Number = array[num].Number + countChange;
- int num2 = this.data[index].WoundedNumber + woundedCountChange;
- if (num2 > this.data[index].Number)
- {
- woundedCountChange += this.data[index].Number - num2;
- }
- else if (num2 < 0)
- {
- TaleWorlds.Library.Debug.FailedAssert("false", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Roster\\TroopRoster.cs", "AddToCountsAtIndex", 426);
- }
- TroopRosterElement[] array2 = this.data;
- int num3 = index;
- array2[num3].WoundedNumber = array2[num3].WoundedNumber + woundedCountChange;
- if (xpChange != 0)
- {
- TroopRosterElement[] array3 = this.data;
- int num4 = index;
- array3[num4].Xp = array3[num4].Xp + xpChange;
- }
- if (this.IsPrisonRoster)
- {
- this.ClampConformity(index);
- }
- else
- {
- this.ClampXp(index);
- }
- if (isHero)
- {
- this._totalHeroes += countChange;
- if (character.HeroObject.IsWounded)
- {
- this._totalWoundedHeroes += countChange;
- }
- if (countChange != 0)
- {
- heroCountChanged = true;
- }
- }
- else
- {
- this._totalWoundedRegulars += woundedCountChange;
- this._totalRegulars += countChange;
- }
- if (removeDepleted && this.data[index].Number == 0)
- {
- this.RemoveRange(index, index + 1);
- index = -1;
- }
- if (this.OwnerParty != null && isHero)
- {
- if (countChange > 0)
- {
- if (!this.IsPrisonRoster)
- {
- this.OwnerParty.OnHeroAdded(character.HeroObject);
- }
- else
- {
- this.OwnerParty.OnHeroAddedAsPrisoner(character.HeroObject);
- }
- }
- else if (countChange < 0)
- {
- if (!this.IsPrisonRoster)
- {
- this.OwnerParty.OnHeroRemoved(character.HeroObject);
- }
- else
- {
- this.OwnerParty.OnHeroRemovedAsPrisoner(character.HeroObject);
- }
- }
- }
- if (countChange != 0 || woundedCountChange != 0)
- {
- this.OnNumberChanged(countChange != 0, woundedCountChange != 0, heroCountChanged);
- }
- }
- catch (IndexOutOfRangeException)
- {
- string troops = "Empty";
- int len = this.data.GetLength(0);
- if (len > 0)
- {
- troops = "";
- for (int i = 0; i < len; i++)
- {
- troops += string.Format("[{0}] = {1}, ", i, this.data[i].ToString());
- }
- }
- InformationManager.DisplayMessage(new InformationMessage(string.Format("Caught IndexOutOfRangeException, index = {0}, countChange = {1}, TroopRoster = {2}", index, countChange, troops)));
- }
- return index;
- }
- }
- }
- 9. Press Compile.
- 10. Go to File -> Save Module, make sure the Filename is
- C:\Program Files (x86)\Steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll
- 11. Press Ok.
- 11. Verify the dll is patched by looking Date Modified.
- When the fix is triggered, it'll say something in the Combat Log (bottom left text thing) like:
- Caught IndexOutOfRange Exception, index = -1, countChange = -1, TroopRoster = [0] = 9 Looter, [1] = 0, [2] = 0, [3] = 0,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement