using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using I2.Loc; using Malee; using Microsoft.CodeAnalysis; using ShinyShoe; using ShinyShoe.Audio; using ShinyShoe.Logging; using SimpleInjector; using Spine; using Spine.Unity; using TrainworksReloaded.Base; using TrainworksReloaded.Base.Card; using TrainworksReloaded.Base.CardUpgrade; using TrainworksReloaded.Base.Challenges; using TrainworksReloaded.Base.Character; using TrainworksReloaded.Base.Class; using TrainworksReloaded.Base.Effect; using TrainworksReloaded.Base.Enums; using TrainworksReloaded.Base.Extensions; using TrainworksReloaded.Base.Localization; using TrainworksReloaded.Base.Map; using TrainworksReloaded.Base.Prefab; using TrainworksReloaded.Base.Pyre; using TrainworksReloaded.Base.Relic; using TrainworksReloaded.Base.Reward; using TrainworksReloaded.Base.Room; using TrainworksReloaded.Base.Scenarios; using TrainworksReloaded.Base.Sound; using TrainworksReloaded.Base.StatusEffects; using TrainworksReloaded.Base.Subtype; using TrainworksReloaded.Base.Tooltips; using TrainworksReloaded.Base.Trait; using TrainworksReloaded.Base.Trials; using TrainworksReloaded.Base.Trigger; using TrainworksReloaded.Core; using TrainworksReloaded.Core.Impl; using TrainworksReloaded.Core.Interfaces; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.AddressableAssets.ResourceLocators; using UnityEngine.ResourceManagement.ResourceProviders; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TrainworksReloaded.Plugin")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.7.17.0")] [assembly: AssemblyInformationalVersion("0.7.17+70425a1dcb597e90fd3db40c36bb4d19c1a44045")] [assembly: AssemblyProduct("TrainworksReloaded.Plugin")] [assembly: AssemblyTitle("TrainworksReloaded.Plugin")] [assembly: AssemblyVersion("0.7.17.0")] [module: RefSafetyRules(11)] [CompilerGenerated] internal sealed class <>z__ReadOnlyArray : IEnumerable, ICollection, IList, IEnumerable, IReadOnlyCollection, IReadOnlyList, ICollection, IList { int ICollection.Count => _items.Length; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int IReadOnlyCollection.Count => _items.Length; T IReadOnlyList.this[int index] => _items[index]; int ICollection.Count => _items.Length; bool ICollection.IsReadOnly => true; T IList.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } public <>z__ReadOnlyArray(T[] items) { _items = items; } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { ((ICollection)_items).CopyTo(array, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return ((IList)_items).Contains(value); } int IList.IndexOf(object value) { return ((IList)_items).IndexOf(value); } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return ((ICollection)_items).Contains(item); } void ICollection.CopyTo(T[] array, int arrayIndex) { ((ICollection)_items).CopyTo(array, arrayIndex); } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { return ((IList)_items).IndexOf(item); } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList : IEnumerable, ICollection, IList, IEnumerable, IReadOnlyCollection, IReadOnlyList, ICollection, IList { private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator { object IEnumerator.Current => _item; T IEnumerator.Current => _item; public Enumerator(T item) { _item = item; } bool IEnumerator.MoveNext() { if (!_moveNextCalled) { return _moveNextCalled = true; } return false; } void IEnumerator.Reset() { _moveNextCalled = false; } void IDisposable.Dispose() { } } int ICollection.Count => 1; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int IReadOnlyCollection.Count => 1; T IReadOnlyList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } } int ICollection.Count => 1; bool ICollection.IsReadOnly => true; T IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } public <>z__ReadOnlySingleElementList(T item) { _item = item; } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.CopyTo(Array array, int index) { array.SetValue(_item, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return EqualityComparer.Default.Equals(_item, (T)value); } int IList.IndexOf(object value) { if (!EqualityComparer.Default.Equals(_item, (T)value)) { return -1; } return 0; } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return EqualityComparer.Default.Equals(_item, item); } void ICollection.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { if (!EqualityComparer.Default.Equals(_item, item)) { return -1; } return 0; } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TrainworksReloaded.Plugin { [BepInPlugin("TrainworksReloaded.Plugin", "TrainworksReloaded.Plugin", "0.7.17")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger = new ManualLogSource("TrainworksReloaded"); internal static Lazy Container = new Lazy((Func)(() => Railend.GetContainer())); internal static Lazy Client = new Lazy((Func)(() => new GameDataClient())); public void Awake() { //IL_0148: Unknown result type (might be due to invalid IL or missing references) ConfigEntry obj = ((BaseUnityPlugin)this).Config.Bind("Tools", "Generate CSVs", false, "Enable to Generate the Games' CSV Files on Launch"); ConfigEntry val = ((BaseUnityPlugin)this).Config.Bind("Logs", "Include Game Logs", false, "Enable Game Logs to BepInEx Console"); if (obj.Value) { string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location); LocalizationManager.InitializeIfNeeded(); for (int i = 0; i < LocalizationManager.Sources.Count; i++) { LanguageSourceData val2 = LocalizationManager.Sources[i]; foreach (string category in val2.GetCategories(false, (List)null)) { string contents = val2.Export_CSV(category, ',', true, true, true, (DiffInfo)null, (ForceUnchanged)null, (ExportInfo)null); string path = $"{i}_{category}.csv"; File.WriteAllText(Path.Combine(directoryName, path), contents); } } } GameDataClient client = Client.Value; DepInjector.AddClient((IClient)(object)client); Logger = ((BaseUnityPlugin)this).Logger; if (val.Value) { Log.AddProvider((ILogProvider)(object)new ModLogger(Logger)); } Railend.ConfigurePreAction((Action)delegate(Container c) { c.RegisterInstance(Logger); c.RegisterInstance(client); c.RegisterSingleton(); c.Register(); c.Collection.Register(new Type[33] { typeof(AdditionalTooltipFinalizer), typeof(CardEffectFinalizer), typeof(CardTraitDataFinalizer), typeof(CardUpgradeFinalizer), typeof(CardUpgradeMaskFinalizer), typeof(ClassDataFinalizer), typeof(CharacterTriggerFinalizer), typeof(CardTriggerEffectFinalizer), typeof(VfxFinalizer), typeof(AtlasIconFinalizer), typeof(RoomModifierFinalizer), typeof(StatusEffectDataFinalizer), typeof(ScenarioDataFinalizer), typeof(TrialDataFinalizer), typeof(MapNodeFinalizer), typeof(RewardDataFinalizer), typeof(CardPoolFinalizer), typeof(EnhancerPoolFinalizer), typeof(RelicPoolFinalizer), typeof(SoulPoolFinalizer), typeof(CharacterTriggerTypeFinalizer), typeof(CardTriggerTypeFinalizer), typeof(CharacterChatterFinalizer), typeof(RelicDataFinalizer), typeof(RelicEffectDataFinalizer), typeof(RelicEffectConditionFinalizer), typeof(GameObjectFinalizer), typeof(ClassCardStyleFinalizer), typeof(SoundCueFinalizer), typeof(PyreHeartDataFinalizer), typeof(ChallengeDataFinalizer), typeof(CharacterDataFinalizer), typeof(CardDataFinalizer) }); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.RegisterConditional(typeof(ICache<>), typeof(Cache<>), (Lifestyle)(object)Lifestyle.Singleton, (Predicate)((PredicateContext val3) => !val3.Handled)); c.RegisterConditional(typeof(IModLogger<>), typeof(ModLogger<>), (Lifestyle)(object)Lifestyle.Singleton, (Predicate)((PredicateContext val3) => !val3.Handled)); c.RegisterConditional(typeof(IInstanceGenerator<>), typeof(ScriptableObjectInstanceGenerator<>), Lifestyle.Transient, (Predicate)((PredicateContext val3) => typeof(ScriptableObject).IsAssignableFrom(val3.ServiceType.GetGenericArguments()[0]))); c.RegisterConditional(typeof(IInstanceGenerator<>), typeof(InstanceGenerator<>), (Predicate)((PredicateContext val3) => !val3.Handled)); c.RegisterDecorator(typeof(IDataPipeline<, >), typeof(CacheDataPipelineDecorator<, >)); c.Register(); c.RegisterSingleton, GameObjectRegister>(); c.RegisterSingleton(); c.RegisterSingleton, AssetReferenceGameObjectRegister>(); c.RegisterSingleton(); c.RegisterInitializer((Action)delegate(GameObjectRegister x) { Addressables.ResourceLocators.Add((IResourceLocator)(object)x); Addressables.ResourceManager.ResourceProviders.Add((IResourceProvider)(object)x); }); c.RegisterInitializer>((Action>)delegate(IRegister x) { c.GetInstance, GameObject>>().Run(x); }); c.Register, GameObject>, GameObjectImportPipeline>(); c.RegisterDecorator, GameObject>, GameObjectCardArtDecorator>(); c.RegisterDecorator, GameObject>, GameObjectMapIconDecorator>(); c.RegisterDecorator, GameObject>, GameObjectBattleIconDecorator>(); c.RegisterDecorator(typeof(IDataFinalizer), typeof(GameObjectCharacterArtFinalizer), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(GameObjectFinalizer))); Plugin.RegisterPipeline(c); c.RegisterSingleton(); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.RegisterSingleton(); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.RegisterSingleton(); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.Collection.Register>((IEnumerable)new <>z__ReadOnlySingleElementList(typeof(RewardNodeDataFactory)), (Lifestyle)(object)Lifestyle.Singleton); c.RegisterDecorator, MapNodeData>, RewardNodeDataPipelineDecorator>(); c.RegisterDecorator, MapNodeData>, BucketMapNodePipelineDecorator>(); c.RegisterDecorator(typeof(IDataFinalizer), typeof(RewardNodeDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(MapNodeFinalizer))); c.RegisterSingleton(); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.Collection.Register>((IEnumerable)new <>z__ReadOnlyArray(new Type[2] { typeof(CardPoolRewardDataFactory), typeof(DraftRewardDataFactory) }), (Lifestyle)(object)Lifestyle.Singleton); c.RegisterDecorator(typeof(IDataFinalizer), typeof(CardPoolRewardDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RewardDataFinalizer))); c.RegisterDecorator(typeof(IDataFinalizer), typeof(DraftRewardDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RewardDataFinalizer))); c.RegisterDecorator(typeof(IDataFinalizer), typeof(GrantableRewardDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RewardDataFinalizer))); Plugin.RegisterPipeline(c); c.Collection.Register>((IEnumerable)new <>z__ReadOnlyArray(new Type[7] { typeof(CollectableRelicDataFactory), typeof(EnhancerDataFactory), typeof(MutatorDataFactory), typeof(PyreArtifactDataFactory), typeof(SinsDataFactory), typeof(SoulDataFactory), typeof(CovenantDataFactory) }), (Lifestyle)(object)Lifestyle.Singleton); c.RegisterDecorator(typeof(IDataPipeline, RelicData>), typeof(CollectableRelicDataPipelineDecorator)); c.RegisterDecorator(typeof(IDataFinalizer), typeof(CollectableRelicDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RelicDataFinalizer))); c.RegisterDecorator(typeof(IDataPipeline, RelicData>), typeof(MutatorDataPipelineDecorator)); c.RegisterDecorator(typeof(IDataPipeline, RelicData>), typeof(CovenantDataPipelineDecorator)); c.RegisterDecorator(typeof(IDataPipeline, RelicData>), typeof(EnhancerDataPipelineDecorator)); c.RegisterDecorator(typeof(IDataFinalizer), typeof(EnhancerDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RelicDataFinalizer))); c.RegisterDecorator(typeof(IDataPipeline, RelicData>), typeof(SoulDataPipelineDecorator)); c.RegisterDecorator(typeof(IDataFinalizer), typeof(SoulDataFinalizerDecorator), (Predicate)((DecoratorPredicateContext xs) => xs.ImplementationType == typeof(RelicDataFinalizer))); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); c.RegisterSingleton, BossVariantSpawnRegister>(); c.RegisterSingleton(); Plugin.RegisterPipeline(c); c.RegisterSingleton(); Plugin.RegisterPipeline(c); c.RegisterSingleton, TrialListRegister>(); c.RegisterSingleton(); c.RegisterSingleton, BackgroundRegister>(); c.RegisterSingleton(); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); Plugin.RegisterPipeline(c); }); new Harmony("TrainworksReloaded.Plugin").PatchAll(); Logger.LogInfo((object)"Plugin TrainworksReloaded.Plugin is loaded!"); } public static void RegisterPipeline(Container c) where Register : class, IRegister where Pipeline : class, IDataPipeline, DataType> { c.RegisterSingleton, Register>(); c.RegisterSingleton(); c.Register, DataType>, Pipeline>(); c.RegisterInitializer>((Action>)delegate(IRegister x) { c.GetInstance, DataType>>().Run(x); }); } private static object? DEBUG_GetInstance(string typeName) { Type type = AssemblyExtensions.FindTypeByClassName(typeof(VfxRegister).Assembly, typeName); if (type == null) { return null; } return Container.Value.GetInstance(type); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "TrainworksReloaded.Plugin"; public const string PLUGIN_NAME = "TrainworksReloaded.Plugin"; public const string PLUGIN_VERSION = "0.7.17"; } } namespace TrainworksReloaded.Plugin.Patches { [HarmonyPatch(typeof(BattleTriggeredEvents), "Init")] public class CustomBattleTriggeredEventsPatch { private static IRegister? triggerRegister; public static void Postfix(Dictionary ___teamTriggerDictionaries) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown if (triggerRegister == null) { triggerRegister = Railend.GetContainer().GetInstance>(); } foreach (Type value in Enum.GetValues(typeof(Type))) { TriggerDictionaries val = ___teamTriggerDictionaries[value]; foreach (Trigger value2 in ((IDictionary)triggerRegister).Values) { if (!val.triggerDictionary.ContainsKey(value2)) { val.triggerDictionary[value2] = new BattleTriggers(); } } } } } internal static class FixLighting { public static void SetupCullingLayer(GameObject envFx, Camera camera) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) camera.cullingMask |= 0x100000; GameObject val = new GameObject { name = "Light_Bright" }; Light obj = val.AddComponent(); obj.type = (LightType)1; obj.shape = (LightShape)0; obj.cullingMask = 1048576; obj.spotAngle = 30f; obj.innerSpotAngle = 21.80208f; obj.color = new Color(1f, 1f, 1f, 1f); obj.useColorTemperature = false; obj.intensity = 1f; obj.bounceIntensity = 1f; obj.useViewFrustumForShadowCasterCull = true; obj.shadowCustomResolution = -1; obj.shadowBias = 0.05f; obj.shadowNormalBias = 0.4f; obj.shadowNearPlane = 0.2f; obj.useShadowMatrixOverride = false; obj.range = 10f; val.transform.parent = envFx.transform; } } [HarmonyPatch(typeof(ChampionUpgradeScreen), "Initialize")] internal class ChampionUpgradeScreenLightingPatch { public static void Postfix(GameObject ___sceneRoot) { GameObject gameObject = ((Component)___sceneRoot.transform.Find("EnvFX_Lights")).gameObject; Camera component = ((Component)___sceneRoot.transform.Find("GameCamera")).GetComponent(); FixLighting.SetupCullingLayer(gameObject, component); } } [HarmonyPatch(typeof(GameScreen), "Initialize")] internal class GameScreenLightingPatch { public static void Postfix() { GameObject envFx = GameObject.Find("EnvFX_Lights"); Camera component = GameObject.Find("MainCamera/Shake1Layer/ShakeLayer2/GameCamera").GetComponent(); FixLighting.SetupCullingLayer(envFx, component); } } [HarmonyPatch(typeof(RewardItemUI), "TryOverrideDraftIcon")] internal class ClanCardDraftIconPatch { internal static Lazy classAssetsDelegator = new Lazy((Func)(() => Railend.GetContainer().GetInstance())); internal static Lazy SaveManager; private static void Prefix(RewardItemUI __instance, ref Sprite mainClassIcon, ref Sprite subClassIcon) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Invalid comparison between Unknown and I4 RewardState rewardState = ((RewardItemUIBase)__instance).rewardState; GrantableRewardData obj = ((rewardState != null) ? rewardState.RewardData : null); DraftRewardData val = (DraftRewardData)(object)((obj is DraftRewardData) ? obj : null); if (val == null) { return; } if ((int)val.ClassType == 1) { string name = ((Object)SaveManager.Value.GetMainClass()).name; Sprite cardDraftIcon = classAssetsDelegator.Value.GetCardDraftIcon(name); if ((Object)(object)cardDraftIcon != (Object)null) { mainClassIcon = cardDraftIcon; } } else if ((int)val.ClassType == 2) { string name2 = ((Object)SaveManager.Value.GetSubClass()).name; Sprite cardDraftIcon2 = classAssetsDelegator.Value.GetCardDraftIcon(name2); if ((Object)(object)cardDraftIcon2 != (Object)null) { subClassIcon = cardDraftIcon2; } } } static ClanCardDraftIconPatch() { SaveManager val = default(SaveManager); SaveManager = new Lazy((Func)(() => (SaveManager)((!Railend.GetContainer().GetInstance().TryGetProvider(ref val)) ? ((object)new SaveManager()) : ((object)val)))); } } [HarmonyPatch(typeof(ClassSpriteSelector), "GetSprite")] public class ClassCardStylePatch { internal static ClassCardStyleDelegator? delegator; public static bool Prefix(ref Sprite __result, CardType cardType, ClassCardStyle classCardStyle) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (delegator == null) { return true; } IDictionary classCardStyleSprites = delegator.GetClassCardStyleSprites(classCardStyle); if (classCardStyleSprites == null) { return true; } Sprite valueOrDefault = IEnumerableUtility.GetValueOrDefault(classCardStyleSprites, cardType, (Sprite)null); if ((Object)(object)valueOrDefault == (Object)null) { return true; } __result = valueOrDefault; return false; } } [HarmonyPatch(typeof(AppManager), "DoesThisBuildReportErrors")] internal class DisableErrorReportingPatch { public static void Postfix(ref bool __result) { __result = false; } } [HarmonyPatch(typeof(AssetLoadingManager), "Start")] internal class InitializationPatch { public static void Postfix(AssetLoadingData ____assetLoadingData) { //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown Container container = Railend.GetContainer(); InitializePatches(container); IModLogger instance = container.GetInstance>(); instance.Log((LogLevel)16, (object)"Starting TrainworksReloaded initialization..."); CardPool customCardPool = container.GetInstance().CustomCardPool; ____assetLoadingData.CardPoolsAll.Add(customCardPool); ClassDataRegister instance2 = container.GetInstance(); CardPoolRegister instance3 = container.GetInstance(); Dictionary.ValueCollection values = ((Dictionary)(object)instance2).Values; ((List)AccessTools.Field(typeof(BalanceData), "classDatas").GetValue(____assetLoadingData.BalanceData)).AddRange(values); instance.Log((LogLevel)16, (object)$"Added {((Dictionary)(object)instance2).Values.Count} custom classes"); instance.Log((LogLevel)16, (object)"Processing map data..."); MapNodeDelegator instance4 = container.GetInstance(); Dictionary dictionary = new Dictionary { { "primary", ____assetLoadingData.BalanceData.GetRunData(false, false, false) }, { "first_time", ____assetLoadingData.BalanceData.GetRunData(true, false, false) }, { "endless", ____assetLoadingData.BalanceData.GetRunData(false, true, false) }, { "soul_savior", ____assetLoadingData.BalanceData.GetRunData(false, false, true) } }; foreach (KeyValuePair item in dictionary) { string key = item.Key; ReorderableArray val = (ReorderableArray)AccessTools.Field(typeof(RunData), "mapNodeBucketLists").GetValue(item.Value); if (val == null) { continue; } foreach (MapNodeBucketList item2 in val) { foreach (MapNodeBucketContainer item3 in (ReorderableArray)(object)item2.BucketList) { string text = (string)AccessTools.Field(typeof(MapNodeBucketContainer), "id").GetValue(item3); if (!instance4.MapBucketToData.TryGetValue(new MapNodeKey(key, text), out var value)) { continue; } foreach (MapNodeBucketData item4 in (ReorderableArray)AccessTools.Field(typeof(MapNodeBucketContainer), "mapNodeBucketContainerList").GetValue(item3)) { item4.MapNodes.AddRange(value); } instance.Log((LogLevel)32, (object)$"Added {value.Count} map nodes to bucket: {text} in {key}"); } } } instance4.MapBucketToData.Clear(); foreach (ScenarioEntry scenario2 in container.GetInstance().Scenarios) { ScenarioEntry current3 = scenario2; int distance = ((ScenarioEntry)(ref current3)).Distance; string runType = ((ScenarioEntry)(ref current3)).RunType; ScenarioData scenario = ((ScenarioEntry)(ref current3)).Scenario; RunData val2 = dictionary[runType]; if ((Object)(object)val2 == (Object)null) { instance.Log((LogLevel)4, (object)("For scenario " + ((Object)scenario).name + " could not find run type: " + runType + " valid runTypes are first_time, primary, and endless ignoring...")); } else { NodeDistanceData distanceData = val2.GetDistanceData(distance); if (distanceData == null) { instance.Log((LogLevel)4, (object)$"For scenario {((Object)scenario).name} could not find NodeDistanceData for distance: {distance} in run_type: {runType} ignoring..."); continue; } ((List)AccessTools.Field(typeof(NodeDistanceData), "battleDatas").GetValue(distanceData)).Add(scenario); instance.Log((LogLevel)16, (object)$"Added scenario {((Object)scenario).name} to {distance} and run_type {runType} successfully."); } } instance.Log((LogLevel)16, (object)"Map data processing complete"); GlobalSoundCueDelegator instance5 = container.GetInstance(); container.GetInstance().RegisterGlobalSoundEffects(instance5.GetSounds()); instance.Log((LogLevel)16, (object)$"Added {instance5.GetSounds().Count} new global sounds."); instance.Log((LogLevel)16, (object)"Running finalization steps..."); container.GetInstance().FinalizeData(); CardPool valueOrDefault = IEnumerableUtility.GetValueOrDefault((IDictionary)instance3, "MegaPool", (CardPool)null); Dictionary> dictionary2 = new Dictionary>(); if ((Object)(object)valueOrDefault != (Object)null) { HashSet hashSet = new HashSet(); valueOrDefault.CollectAllCards(hashSet); HashSet hashSet2 = new HashSet(); customCardPool.CollectAllCards(hashSet2); foreach (CardData item5 in hashSet.Intersect(hashSet2)) { ClassData linkedClass = item5.GetLinkedClass(); if (!((Object)(object)linkedClass == (Object)null) && !item5.IsBannerUnit()) { if (!dictionary2.ContainsKey(linkedClass)) { dictionary2[linkedClass] = new List(); } dictionary2[linkedClass].Add(item5); } } foreach (KeyValuePair> item6 in dictionary2) { item6.Deconstruct(out var key2, out var value2); ClassData val3 = key2; List list = value2; CardPool bannerReplacementPool = instance3.GetBannerReplacementPool(((Object)val3).name); if ((Object)(object)bannerReplacementPool == (Object)null) { instance.Log((LogLevel)4, (object)"Clan doesn't have a Banner Replacement Pool registered, this shouldn't happen for modded clans."); continue; } ReorderableArray val4 = (ReorderableArray)AccessTools.Field(typeof(CardPool), "cardDataList").GetValue(bannerReplacementPool); foreach (CardData item7 in list) { val4.Add(item7); } } } instance.Log((LogLevel)16, (object)"Loading localization data..."); LanguageSourceRegister instance6 = container.GetInstance(); instance6.LoadData(); container.GetInstance().LoadData(((Dictionary)(object)instance6).Keys.ToList()); instance.Log((LogLevel)16, (object)"Localization data loaded"); instance.Log((LogLevel)16, (object)"Loading replacement strings..."); container.GetInstance().LoadData(); instance.Log((LogLevel)16, (object)"Replacement strings loaded"); instance.Log((LogLevel)16, (object)"TrainworksReloaded initialization complete!"); } private static void InitializePatches(Container container) { RunSetupScreenPatches.container = container; ClassCardStylePatch.delegator = container.GetInstance(); } } [HarmonyPatch(typeof(RunSetupScreen), "Initialize")] public class RunSetupScreenPatches { public static Container? container; private static FieldInfo fieldClanIndex = AccessTools.Field(typeof(ClassSelectCharacterDisplay), "clanIndex"); public static int RandomIndex = 10; public static void Prefix(GameObject ___characterDisplayRoot) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) if (container == null) { Plugin.Logger.LogError((object)"Did not find Container instance"); return; } ClassDataRegister instance = container.GetInstance(); container.GetInstance(); ClassAssetsDelegator instance2 = container.GetInstance(); Transform val = ___characterDisplayRoot.transform.Find("Random main"); int num = val.GetSiblingIndex(); foreach (KeyValuePair item in (Dictionary)(object)instance) { GameObject val2 = new GameObject { name = item.Value.GetTitle() + " main" }; val2.transform.SetParent(___characterDisplayRoot.transform, false); val2.transform.SetSiblingIndex(num); List obj = instance2.GetCharacterDisplays(((Object)item.Value).name) ?? new List(); ClassSelectCharacterDisplay obj2 = val2.AddComponent(); fieldClanIndex.SetValue(obj2, num); List list = new List(); foreach (GameObject item2 in obj) { GameObject val3 = Object.Instantiate(item2); val3.gameObject.SetActive(true); Transform obj3 = item2.transform.Find("CharacterScale/CharacterUI"); Vector3 localPosition = obj3.localPosition; Vector3 localScale = obj3.localScale; Transform val4 = val3.transform.Find("CharacterScale/CharacterUI"); CharacterUI component = ((Component)val4).GetComponent(); ((Component)component).gameObject.layer = LayerMask.NameToLayer("Character_Lights"); val3.transform.SetParent(val2.transform, false); Transform val5 = val3.transform.Find("CharacterScale/CharacterUI/Quad_Default"); if (val5 != null) { ((Component)val5).gameObject.SetActive(false); } if ((Object)(object)val5 != (Object)null) { val5.localPosition = localPosition; } Transform val6 = val3.transform.Find("CharacterScale/CharacterUI/SpineMeshes"); CharacterUIMeshSpine val7 = ((val6 != null) ? ((Component)val6).GetComponent() : null); if ((Object)(object)val7 != (Object)null) { val4.localScale = Vector3.one; val6.localPosition = localPosition; val6.localScale = localScale; } CharacterState componentInChildren = ((Component)val3.transform).GetComponentInChildren(); CharacterUIMesh componentInChildren2 = ((Component)val3.transform).GetComponentInChildren(true); AccessTools.Field(typeof(CharacterUI), "_characterMesh").SetValue(component, ((object)val7) ?? ((object)componentInChildren2)); AccessTools.Field(typeof(CharacterUI), "_characterState").SetValue(component, componentInChildren); list.Add(componentInChildren); } num++; } RandomIndex = num; ClassSelectCharacterDisplay component2 = ((Component)val).GetComponent(); fieldClanIndex.SetValue(component2, num); } } [HarmonyPatch(typeof(RunSetupScreen), "InitializeCharacters")] public static class Patch_InitializeCharacters { public static MethodInfo methodGetValue = AccessTools.Method(typeof(Patch_InitializeCharacters), "GetMainClanIndex", (Type[])null, (Type[])null); public static IEnumerable Transpiler(IEnumerable instructions) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown List list = new List(instructions); bool flag = false; bool flag2 = false; for (int i = 0; i < list.Count - 1; i++) { if (list[i].opcode == OpCodes.Ldarg_1 && list[i + 1].opcode == OpCodes.Ldnull && list[i + 2].opcode == OpCodes.Call && list[i + 3].opcode == OpCodes.Brfalse) { flag = true; } else if (flag && list[i].opcode == OpCodes.Stloc_0 && list[i - 1].opcode == OpCodes.Ldc_I4_S) { list[i - 1] = new CodeInstruction(OpCodes.Call, (object)methodGetValue); flag2 = true; break; } } if (!flag2) { Plugin.Logger.LogError((object)"Patch failed, did not find a mainClanIndex = 10 in the IL."); } return list; } public static int GetMainClanIndex() { return RunSetupScreenPatches.RandomIndex; } } [HarmonyPatch(typeof(SkeletonDataAsset), "ReadSkeletonData", new Type[] { typeof(byte[]), typeof(AttachmentLoader), typeof(float) })] public class SkeletonDataAssetPatch { private static bool Prefix(ref byte[] bytes) { string text = Encoding.UTF8.GetString(bytes); if (text.StartsWith("SPINE64|")) { bytes = Convert.FromBase64String(text.Substring("SPINE64|".Length)); } return true; } } }