static void Postfix(SGCaptainsQuartersStatusScreen __instance) { try { SimGameState simState = (SimGameState)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "simState").GetValue(__instance); if (Fields.Deployment && (simState.DayRemainingInQuarter <= Fields.DeploymentRemainingDays)) { ReflectionHelper.InvokePrivateMethode(__instance, "AddListLineItem", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesList"), "Deployment Salary", SimGameState.GetCBillString(0 - Fields.DeploymentSalary) }); TextMeshProUGUI SectionOneExpensesField = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesField"); int newTotal = int.Parse(SectionOneExpensesField.text.Replace("¢", "").Replace(",", "")); ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { SectionOneExpensesField, SimGameState.GetCBillString(newTotal - Fields.DeploymentSalary) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) }); } Fields.InvertCBills = false; SGFinancialForecastWidget FinanceWidget = (SGFinancialForecastWidget)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "FinanceWidget").GetValue(__instance); FinanceWidget.RefreshData(); TextMeshProUGUI EndOfQuarterFunds = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "EndOfQuarterFunds").GetValue(__instance); TextMeshProUGUI CurrentFunds = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "CurrentFunds").GetValue(__instance); if (simState.GetExpenditures(false) <= 0) { TextMeshProUGUI QuarterOperatingExpenses = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "QuarterOperatingExpenses").GetValue(__instance); UIColorRefTracker BR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BR")); BR.colorRef.UIColor = UIColor.Green; UIColorRefTracker BL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BL")); BL.colorRef.UIColor = UIColor.Green; UIColorRefTracker TL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TL")); TL.colorRef.UIColor = UIColor.Green; UIColorRefTracker TR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TR")); TR.colorRef.UIColor = UIColor.Green; UIColorRefTracker txt_opExpensesLabel = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesLabel")); txt_opExpensesLabel.colorRef.UIColor = UIColor.Green; UIColorRefTracker txt_opExpensesAmmount = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesAmmount")); txt_opExpensesAmmount.colorRef.UIColor = UIColor.Green; } ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { EndOfQuarterFunds, SimGameState.GetCBillString(simState.Funds + simState.GetExpenditures(false)) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) }); ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { CurrentFunds, SimGameState.GetCBillString(simState.Funds) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) }); } catch (Exception e) { Logger.LogError(e); } }
public static bool Prefix(SGCaptainsQuartersStatusScreen __instance, EconomyScale expenditureLevel, bool showMoraleChange, SimGameState ___simState, SGDifficultyIndicatorWidget ___ExpenditureLevelIndicatorWidget, LocalizableText ___ExpenditureLevelField, LocalizableText ___SectionOneExpenseLevel, LocalizableText ___SectionTwoExpenseLevel, SGFinancialForecastWidget ___FinanceWidget, LocalizableText ___MoraleValueField, SGMoraleBar ___MoralBar, Transform ___SectionOneExpensesList, LocalizableText ___SectionOneExpensesField, LocalizableText ___SectionTwoExpensesField, Transform ___SectionTwoExpensesList, LocalizableText ___EndOfQuarterFunds, LocalizableText ___QuarterOperatingExpenses, LocalizableText ___CurrentFunds, List <LocalizableText> ___ExpenditureLvlBtnMoraleFields, List <LocalizableText> ___ExpenditureLvlBtnCostFields) { if (__instance == null || ___simState == null) { return(true); } float expenditureCostModifier = ___simState.GetExpenditureCostModifier(expenditureLevel); Traverse methodSetField = Traverse.Create(__instance) .Method("SetField", new Type[] { typeof(LocalizableText), typeof(string) }); int expLevel = (int)Traverse.Create(__instance) .Method("GetExpendetureLevelIndexNormalized", new object[] { expenditureLevel }).GetValue(); ___ExpenditureLevelIndicatorWidget.SetDifficulty(expLevel * 2); methodSetField.GetValue(new object[] { ___ExpenditureLevelField, string.Format("{0}", (object)expenditureLevel) }); methodSetField.GetValue(new object[] { ___SectionOneExpenseLevel, string.Format("{0}", (object)expenditureLevel) }); methodSetField.GetValue(new object[] { ___SectionTwoExpenseLevel, string.Format("{0}", (object)expenditureLevel) }); ___FinanceWidget.RefreshData(expenditureLevel); int num1 = ___simState.ExpenditureMoraleValue[expenditureLevel]; methodSetField.GetValue(new object[] { ___MoraleValueField, string.Format("{0}{1}", num1 > 0 ? (object)"+" : (object)"", (object)num1) }); if (showMoraleChange) { int morale = ___simState.Morale; ___MoralBar.ShowMoraleChange(morale, morale + num1); } else { ___MoralBar.ShowCurrentMorale(); } Traverse.Create(__instance).Method("ClearListLineItems", new object[] { ___SectionOneExpensesList }).GetValue(); List <KeyValuePair <string, int> > keyValuePairList = new List <KeyValuePair <string, int> >(); int ongoingUpgradeCosts = 0; string key = ___simState.CurDropship == DropshipType.Leopard ? Strings.T("Bank Loan Interest Payment") : Strings.T("Argo Operating Costs"); int num2 = Mathf.RoundToInt(expenditureCostModifier * (float)___simState.GetShipBaseMaintenanceCost()); keyValuePairList.Add(new KeyValuePair <string, int>(key, num2)); foreach (ShipModuleUpgrade shipUpgrade in ___simState.ShipUpgrades) { float pilotQurikModifier = PilotQuirkManager.Instance.getArgoUpgradeCostModifier(___simState.PilotRoster.ToList(), shipUpgrade.Description.Id, true); float baseCost = (float)shipUpgrade.AdditionalCost * pilotQurikModifier; if (___simState.CurDropship == DropshipType.Argo && Mathf.CeilToInt((float)baseCost * ___simState.Constants.CareerMode.ArgoMaintenanceMultiplier) > 0) { string name = shipUpgrade.Description.Name; int num3 = Mathf.RoundToInt(expenditureCostModifier * (float)Mathf.CeilToInt((float)baseCost * ___simState.Constants.CareerMode.ArgoMaintenanceMultiplier)); keyValuePairList.Add(new KeyValuePair <string, int>(name, num3)); } } foreach (MechDef mechDef in ___simState.ActiveMechs.Values) { string name = mechDef.Name; int num3 = Mathf.RoundToInt(expenditureCostModifier * (float)___simState.Constants.Finances.MechCostPerQuarter); keyValuePairList.Add(new KeyValuePair <string, int>(name, num3)); } keyValuePairList.Sort((Comparison <KeyValuePair <string, int> >)((a, b) => b.Value.CompareTo(a.Value))); keyValuePairList.ForEach((Action <KeyValuePair <string, int> >)(entry => { ongoingUpgradeCosts += entry.Value; methodAddLineItem.Invoke(__instance, new object[] { ___SectionOneExpensesList, entry.Key, SimGameState.GetCBillString(entry.Value) }); })); methodSetField.GetValue(new object[] { ___SectionOneExpensesField, SimGameState.GetCBillString(ongoingUpgradeCosts) }); keyValuePairList.Clear(); Traverse.Create(__instance).Method("ClearListLineItems", new object[] { ___SectionTwoExpensesList }).GetValue(); int ongoingMechWariorCosts = 0; foreach (Pilot pilot in ___simState.PilotRoster) { string displayName = pilot.pilotDef.Description.DisplayName; int num3 = Mathf.CeilToInt(expenditureCostModifier * (float)___simState.GetMechWarriorValue(pilot.pilotDef)); keyValuePairList.Add(new KeyValuePair <string, int>(displayName, num3)); } keyValuePairList.Sort((Comparison <KeyValuePair <string, int> >)((a, b) => b.Value.CompareTo(a.Value))); keyValuePairList.ForEach((Action <KeyValuePair <string, int> >)(entry => { ongoingMechWariorCosts += entry.Value; methodAddLineItem.Invoke(__instance, new object[] { ___SectionTwoExpensesList, entry.Key, SimGameState.GetCBillString(entry.Value) }); })); methodSetField.GetValue(new object[] { ___SectionTwoExpensesField, SimGameState.GetCBillString(ongoingMechWariorCosts) }); methodSetField.GetValue(new object[] { ___EndOfQuarterFunds, SimGameState.GetCBillString(___simState.Funds + ___simState.GetExpenditures(false)) }); methodSetField.GetValue(new object[] { ___QuarterOperatingExpenses, SimGameState.GetCBillString(___simState.GetExpenditures(false)) }); methodSetField.GetValue(new object[] { ___CurrentFunds, SimGameState.GetCBillString(___simState.Funds) }); int index = 0; foreach (KeyValuePair <EconomyScale, int> keyValuePair in ___simState.ExpenditureMoraleValue) { ___ExpenditureLvlBtnMoraleFields[index].SetText(string.Format("{0}", (object)keyValuePair.Value), (object[])Array.Empty <object>()); ___ExpenditureLvlBtnCostFields[index].SetText(SimGameState.GetCBillString(___simState.GetExpenditures(keyValuePair.Key, false)), (object[])Array.Empty <object>()); ++index; } return(false); }