Exemplo n.º 1
0
        public static void ApplyAudio(TrainCar car)
        {
            var soundSet = Registry.Get(car);

            Main.DebugLog(() => $"Applying sounds for {car.ID}");
            switch (car.carType)
            {
            case TrainCarType.LocoDiesel:
                DieselAudio.Apply(car, soundSet);
                break;

            case TrainCarType.LocoShunter:
                ShunterAudio.Apply(car, soundSet);
                break;

            case TrainCarType.LocoSteamHeavy:
                SteamAudio.Apply(car, soundSet);
                break;

            default:
                if (UnityModManager.FindMod("DVCustomCarLoader").Loaded)
                {
                    CCLAudio.Apply(car, soundSet);
                }
                break;
            }
        }
Exemplo n.º 2
0
        private IEnumerator SearchForTablet()
        {
            while (tablet == null)
            {
                yield return(WaitFor.Seconds(1f));

                if (!UnityModManager.FindMod("DERAILDigital").Enabled)
                {
                    continue;
                }
                var tabletControllerType = FindTabletControllerType();
                if (tabletControllerType == null)
                {
                    Main.DebugLog("Could not find type Cybex.TabletController");
                    continue;
                }
                var getInstance = AccessTools.PropertyGetter(tabletControllerType, "Instance");
                if (getInstance == null)
                {
                    Main.DebugLog("Could not find property getter Instance");
                    continue;
                }
                var tabletController = getInstance.Invoke(null, null);
                if (tabletController == null)
                {
                    Main.DebugLog("null returned from Instance");
                    continue;
                }
                tablet = new TabletWrapper(tabletController);
            }
            StartCoroutine(Pusher());
        }
Exemplo n.º 3
0
 private static Settings GetDefaultSettings(LocoTrainAudio audio)
 {
     if (audio is LocoAudioShunter audioShunter)
     {
         return(new Settings
         {
             fadeInStart = audioShunter.engineOnClip.length * 0.15f,
             fadeOutStart = audioShunter.engineOffClip.length * 0.10f,
         });
     }
     else if (audio is LocoAudioDiesel audioDiesel)
     {
         return(new Settings
         {
             fadeInStart = audioDiesel.engineOnClip.length * 0.15f,
             fadeOutStart = audioDiesel.engineOffClip.length * 0.10f,
         });
     }
     else if ((UnityModManager.FindMod("DVCustomCarLoader")?.Loaded ?? false) && audio is CustomLocoAudioDiesel audioCustom)
     {
         return(new Settings
         {
             fadeInStart = audioCustom.engineOnClip.length * 0.15f,
             fadeOutStart = audioCustom.engineOffClip.length * 0.10f,
         });
     }
     else
     {
         throw new System.Exception($"{audio.GetType().Name} received by EngineFade");
     }
 }
Exemplo n.º 4
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.modEntry = modEntry;
            if (enabled == value)
            {
                return(true);
            }
            enabled = value;

            if (enabled)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }
                harmony = new Harmony(modEntry.Info.Id);
                harmony.PatchAll(Assembly.GetExecutingAssembly());
                if (areYouSure == null)
                {
                    areYouSure = new GameObject().AddComponent <AreYouSure>();
                    GameObject.DontDestroyOnLoad(areYouSure.gameObject);
                }
            }
            else
            {
                harmony.UnpatchAll(harmony.Id);
                GameObject.Destroy(areYouSure.gameObject);
                areYouSure = null;
            }
            return(true);
        }
Exemplo n.º 5
0
            public static IEnumerable <MethodBase> TargetMethods()
            {
                yield return(AccessTools.Method(typeof(LocoControllerDiesel), nameof(LocoControllerBase.GetTractionForce)));

                yield return(AccessTools.Method(typeof(LocoControllerShunter), nameof(LocoControllerBase.GetTractionForce)));

                yield return(AccessTools.Method(typeof(LocoControllerSteam), nameof(LocoControllerBase.GetTractionForce)));

                if (UnityModManager.FindMod("DVCustomCarLoader")?.Assembly is Assembly assembly && assembly != null)
                {
                    var typeNames = new string[]
                    {
                        "DieselElectric.CustomLocoControllerDiesel",
                        "Steam.CustomLocoControllerSteam",
                    };
                    var methods = typeNames
                                  .Select(n => assembly.GetType($"DVCustomCarLoader.LocoComponents.{n}"))
                                  .OfType <Type>()
                                  .Where(typeof(LocoControllerBase).IsAssignableFrom)
                                  .Select(t => t.GetMethod("GetTractionForce"))
                                  .OfType <MethodBase>();
                    foreach (var method in methods)
                    {
                        yield return(method);
                    }
                }
            }
Exemplo n.º 6
0
 public void Start()
 {
     if (UnityModManager.FindMod("DERAILDigital") == null)
     {
         Destroy(this);
     }
     else
     {
         StartCoroutine(SearchForTablet());
     }
 }
Exemplo n.º 7
0
        public static Type GetModType(string modID, string typeName)
        {
            var modEntry = UnityModManager.FindMod(modID);

            if (modEntry == null)
            {
                return(null);
            }

            return(modEntry.GetModType(typeName));
        }
Exemplo n.º 8
0
            public static MethodBase TargetMethod()
            {
                var cclModAssembly = UnityModManager.FindMod("DVCustomCarLoader")?.Assembly;

                if (cclModAssembly != null)
                {
                    var coroClass = System.Array.Find(cclModAssembly.GetTypes(), t => t.FullName.Contains("+<EngineStartupShutdown>"));
                    if (coroClass != null)
                    {
                        return(coroClass.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.NonPublic));
                    }
                }
                return(AccessTools.Method(typeof(object), nameof(object.ToString)));
            }
Exemplo n.º 9
0
        static IfRule()
        {
            foreach (TrainCarType trainCarType in Enum.GetValues(typeof(TrainCarType)))
            {
                trainCarTypes[Enum.GetName(typeof(TrainCarType), trainCarType)] = trainCarType;
            }

            if (UnityModManager.FindMod("DVCustomCarLoader")?.Loaded ?? false)
            {
                AddCustomCars();
            }

            Main.DebugLog(() => $"trainCarTypes:\n{string.Join("\n", trainCarTypes.Keys.Select(k => $"{k} -> {trainCarTypes[k]}"))}");
        }
Exemplo n.º 10
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.modEntry = modEntry;
            if (enabled == value)
            {
                return(true);
            }
            enabled = value;

            if (enabled)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }
                harmony = new Harmony(modEntry.Info.Id);
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                if (XLGraphicsMenu.Instance == null)
                {
                    if (uiBundle == null)
                    {
                        uiBundle = AssetBundle.LoadFromFile(modEntry.Path + "graphicsmenuassetbundle");
                    }

                    GameObject newMenuObject = GameObject.Instantiate(uiBundle.LoadAsset <GameObject>("Assets/Prefabs/Menu.prefab"));
                    GameObject.DontDestroyOnLoad(newMenuObject);

                    menu = XLGraphicsMenu.Instance;

                    xlGraphics = new GameObject().AddComponent <XLGraphics>();
                    GameObject.DontDestroyOnLoad(xlGraphics.gameObject);

                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                }
            }
            else
            {
                harmony.UnpatchAll(harmony.Id);
                GameObject.Destroy(xlGraphics.gameObject);
                xlGraphics = null;
            }
            return(true);
        }
Exemplo n.º 11
0
        static HandBrakeWheel()
        {
            var passengerCarPosition = (UnityModManager.FindMod("SlicedPassengerCars")?.Enabled ?? false) ? slicedPassengerPosition : passengerPosition;

            wheelPositions.Add(passengerCarPosition);
            foreach (TrainCarType carType in System.Enum.GetValues(typeof(TrainCarType)))
            {
                var name          = System.Enum.GetName(typeof(TrainCarType), carType);
                var wheelPosition = wheelPositions.FirstOrDefault(wp => wp.patterns.Any(name.StartsWith));
                if (wheelPosition != default)
                {
                    wheelPositionMap.Add(carType, wheelPosition);
                }
            }
        }
Exemplo n.º 12
0
 static HeadsUpDisplayBridge()
 {
     try
     {
         var hudMod = UnityModManager.FindMod("HeadsUpDisplay");
         if (hudMod?.Loaded != true)
         {
             return;
         }
         instance = new HeadsUpDisplayBridge(hudMod);
     }
     catch (System.IO.FileNotFoundException)
     {
     }
 }
Exemplo n.º 13
0
 public static void OnCarSpawned(TrainCar car)
 {
     if (CarTypes.IsAnyLocomotiveOrTender(car.carType))
     {
         return;
     }
     if (car.GetComponent <CabooseController>() == null)
     {
         var cabooseController = car.gameObject.AddComponent <CabooseController>();
         cabooseController.cabTeleportDestinationCollidersGO = new GameObject();
     }
     if (UnityModManager.FindMod("AirBrake")?.Enabled ?? false)
     {
         car.StartCoroutine(DelayedSetIndependent(car));
     }
 }
Exemplo n.º 14
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.Logger.Log("OnToggle " + value.ToString());
            if (enabled == value)
            {
                return(true);
            }

            enabled = value;

            if (value)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }

                // create harmony instance
                harmony = new Harmony(modEntry.Info.Id);

                // patch
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                // instantiate menu and XLGraphics monobehaviour
                GameObject menuGO = GameObject.Instantiate(menuObjectAsset);
                menu       = XLGraphicsMenu.Instance;
                xlGraphics = new GameObject().AddComponent <XLGraphics>();
                GameObject.DontDestroyOnLoad(menuGO);
                GameObject.DontDestroyOnLoad(xlGraphics.gameObject);
            }
            else
            {
                // unpatch
                harmony.UnpatchAll(harmony.Id);

                // destroy menu and XLGraphics monobehaviour
                GameObject.DestroyImmediate(menu.gameObject);
                GameObject.DestroyImmediate(xlGraphics.gameObject);
            }
            Main.Logger.Log("Loaded");
            return(true);
        }
Exemplo n.º 15
0
        private static void SearchForNamedTrains()
        {
            string smFolder        = UnityModManager.FindMod("SkinManagerMod").Path;
            string skinsFolderPath = Path.Combine(smFolder, "Skins");
            var    skinsDir        = new DirectoryInfo(skinsFolderPath);

            foreach (var passCarFolder in skinsDir.GetDirectories("CarPassenger*"))
            {
                foreach (var carSkinFolder in passCarFolder.GetDirectories())
                {
                    string configPath = Path.Combine(carSkinFolder.FullName, "pj_specials.xml");
                    if (File.Exists(configPath))
                    {
                        SpecialConsistManager.LoadConfig(configPath);
                    }
                }
            }
        }
Exemplo n.º 16
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.modEntry = modEntry;
            if (enabled == value)
            {
                return(true);
            }
            enabled = value;

            if (enabled)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }

                harmony = new Harmony(modEntry.Info.Id);
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                babboSettings = new GameObject().AddComponent <BabboSettings>();
                GameObject.DontDestroyOnLoad(babboSettings.gameObject);

                // if the replay_presetOrder is empty and the other is not, it means it's moving to the new version
                // therefore, copy presetOrder to replay_presetOrder
                // also copy the enabled state
                if (settings.presetOrder.Count > 0 && settings.replay_presetOrder.Count == 0)
                {
                    settings.replay_presetOrder.names.AddRange(settings.presetOrder.names);
                    settings.replay_presetOrder.enables.AddRange(settings.presetOrder.enables);
                    settings.replay_presetOrder.map_enabled = settings.presetOrder.map_enabled;
                }

                // if no Presets folder, create it and move presets there
                if (!Directory.Exists(modEntry.Path + "Presets"))
                {
                    Directory.CreateDirectory(modEntry.Path + "Presets");
                }
                var oldPaths = Directory.GetFiles(modEntry.Path, "*.preset.json");
                foreach (var filePath in oldPaths)
                {
                    var fileName = Path.GetFileName(filePath);
                    File.Move(filePath, modEntry.Path + "\\Presets\\" + fileName);
                }

                // load presets from files
                presets = new Dictionary <string, Preset>();
                string[] filePaths = Directory.GetFiles(modEntry.Path + "Presets\\", "*.preset.json");
                foreach (var filePath in filePaths)
                {
                    try {
                        var json   = File.ReadAllText(filePath);
                        var preset = Preset.Load(json);
                        if (!preset.isMapPreset)
                        {
                            // avoid adding map preset to presetOrder
                            presets.Add(preset.name, preset);
                            if (!settings.presetOrder.names.Contains(preset.name))
                            {
                                settings.presetOrder.Add(preset.name, false);
                            }
                            if (!settings.replay_presetOrder.names.Contains(preset.name))
                            {
                                settings.replay_presetOrder.Add(preset.name, false);
                            }
                            Logger.Log("preset: " + preset.name + " loaded");
                        }
                    }
                    catch (Exception e) {
                        Logger.Log($"ex: {e}");
                    }
                }

                // if there are no presets, add the default one
                if (presets.Count == 0)
                {
                    var default_preset = new Preset(default_name);
                    default_preset.Save();
                    presets.Add(default_preset.name, default_preset);
                    if (!settings.presetOrder.names.Contains(default_preset.name))
                    {
                        settings.presetOrder.Add(default_preset.name, false);
                    }
                    if (!settings.replay_presetOrder.names.Contains(default_preset.name))
                    {
                        settings.replay_presetOrder.Add(default_preset.name, false);
                    }
                }

                // remove presets that were not found
                foreach (var name in settings.presetOrder.names)
                {
                    if (!presets.ContainsKey(name))
                    {
                        settings.presetOrder.Remove(name);
                    }
                }
                foreach (var name in settings.replay_presetOrder.names)
                {
                    if (!presets.ContainsKey(name))
                    {
                        settings.replay_presetOrder.Remove(name);
                    }
                }
                Logger.Debug("Toggle enabled");
            }
            else
            {
                harmony.UnpatchAll(harmony.Id);
                GameObject.Destroy(babboSettings.gameObject);
                babboSettings = null;
                Logger.Debug("Toggle disabled");
            }
            return(true);
        }
Exemplo n.º 17
0
        public static object GetModObject(string modID, string typeName, out UnityModManager.ModEntry modEntry, Func <Type, object> getValue)
        {
            modEntry = UnityModManager.FindMod(modID);

            return(modEntry?.GetModObject(typeName, getValue));
        }
Exemplo n.º 18
0
        public static Assembly GetModAssembly(string modID)
        {
            var mod = UnityModManager.FindMod(modID);

            return((mod != null) ? GetModAssembly(mod) : null);
        }
Exemplo n.º 19
0
 public static bool Prepare()
 {
     return(UnityModManager.FindMod("DVCustomCarLoader")?.Loaded ?? false);
 }
Exemplo n.º 20
0
        public bool TryGetErrorMods(string logString, string stackString, out Dictionary <UnityModManager.ModInfo, List <string> > result)
        {
            Dictionary <UnityModManager.ModInfo, List <string> > errorMods = new Dictionary <UnityModManager.ModInfo, List <string> >();

            try
            {
                List <string> modStr = new List <string>();
                foreach (var mod in UnityModManager.modEntries)
                {
                    modStr.Clear();
                    modStr = GetModStr(mod);
                    if (modStr.Count <= 0)
                    {
                        break;
                    }
                    foreach (var name in modStr)
                    {
                        if (logString.Contains(name))
                        {
                            ExceptionHelper.Instance.AddErrorMod(errorMods, mod.Info, name);
                        }
                        if (stackString.Contains(name))
                        {
                            ExceptionHelper.Instance.AddErrorMod(errorMods, mod.Info, name);
                        }
                    }
                }
                string pattern = @"(?<= )\S+?_Patch\d+";
                foreach (Match match in Regex.Matches(logString + stackString, pattern))
                {
                    string matchString = match.Groups[0].Value;
                    string fullName    = matchString.Substring(0, matchString.LastIndexOf('_'));
                    int    num         = fullName.LastIndexOf('.');
                    string methodName  = fullName.Substring(num + 1, fullName.Length - fullName.LastIndexOf('.') - 1);
                    string typeName    = fullName.Substring(0, fullName.LastIndexOf('.'));
                    string index       = matchString.Substring(matchString.LastIndexOf("_Patch") + 6, matchString.Length - (matchString.LastIndexOf("_Patch") + 6));
                    Type   classtyp    = AccessTools.TypeByName(typeName);
                    if (classtyp == null)
                    {
                        Main.Logger.Log($"无法获取到{fullName}的类型");
                        continue;
                    }
                    MethodInfo methodInfo = classtyp.GetMethod(methodName, AccessTools.all);
                    if (methodInfo == null)
                    {
                        Main.Logger.Log($"无法获取到{fullName}的方法");
                        continue;
                    }
                    var info = PatchProcessor.GetPatchInfo(methodInfo);
                    if (info == null)
                    {
                        Main.Logger.Log($"无法获取到对{fullName}的补丁");
                        continue;
                    }
                    int patchIndex = int.Parse(index);
                    foreach (var patch in info.Prefixes)
                    {
                        if (patch.index == patchIndex)
                        {
                            UnityModManager.ModInfo modInfo = UnityModManager.FindMod(patch.owner).Info;
                            ExceptionHelper.Instance.AddErrorMod(errorMods, modInfo, matchString + ".Prefix()");
                        }
                    }
                    foreach (var patch in info.Postfixes)
                    {
                        if (patch.index == patchIndex)
                        {
                            UnityModManager.ModInfo modInfo = UnityModManager.FindMod(patch.owner).Info;
                            ExceptionHelper.Instance.AddErrorMod(errorMods, modInfo, matchString + ".Postfix()");
                        }
                    }
                }
                result = errorMods;
                return(true);
            }
            catch (Exception e)
            {
                errorMods.Clear();
                errorMods.Add(Main.modEntry.Info, new List <string>()
                {
                    e.Message, e.StackTrace
                });
                result = errorMods;
                return(false);
            }
        }