private static RGBColor <float> GetDifficultyColor(StarmapRenderer starmapRenderer, StarSystemNode starSystemNode)
            {
                SimGameState.SimGameType gameType = starmapRenderer.GetSimGameState().SimGameMode;
                int difficulty = starSystemNode.System.Def.GetDifficulty(gameType);

                return(GetDifficultyColor(difficulty));
            }
Esempio n. 2
0
        public static void OnMapRefresh(StarmapRenderer renderer)
        {
            // set the fov to our settings
            renderer.fovMin = Main.Settings.MinFov;
            renderer.fovMax = Main.Settings.MaxFov;

            ScaleMapBorders(renderer);
        }
Esempio n. 3
0
        public static void Postfix(StarmapRenderer __instance)
        {
            SmoothZoom.PostUpdate(__instance);

            // clamp camera position
            var cameraPosition = __instance.starmapCamera.transform.position;
            var fov            = __instance.starmapCamera.fieldOfView;
            var zPos           = __instance.starmapCamera.transform.position.z;

            __instance.starmapCamera.transform.position = ResizableMap.ClampCameraPosition(cameraPosition, fov, zPos);
        }
Esempio n. 4
0
 static void Postfix(StarmapRenderer __instance, FactionValue faction, GameObject logo)
 {
     try {
         if (logo.transform.localScale == Fields.originalTransform.localScale)
         {
             logo.transform.localScale += new Vector3(4f, 4f, 4f);
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
     }
 }
Esempio n. 5
0
        public static void PlaceLogos(StarmapRenderer renderer)
        {
            var factions = Enum.GetValues(typeof(Faction));
            var logos    = new Dictionary <Faction, GameObject>();

            foreach (Faction faction in factions)
            {
                var factionName = Enum.GetName(typeof(Faction), faction);
                if (factionName == null)
                {
                    continue;
                }

                // use the vanilla object if it exists, make our own if it doesn't
                GameObject logo = null;
                if (_vanillaLogoNames.ContainsKey(factionName))
                {
                    logo = GameObject.Find(_vanillaLogoNames[factionName]);
                }
                else if (Main.Settings.FactionLogoPaths.ContainsKey(factionName))
                {
                    var logoName = $"{factionName.ToLower()}Logo";

                    logo = GameObject.Find(logoName);
                    if (logo == null)
                    {
                        logo = GameObject.Instantiate(renderer.restorationLogo);
                        logo.transform.SetParent(renderer.restorationLogo.transform.parent);
                        logo.name = logoName;
                    }
                }

                if (logo == null)
                {
                    continue;
                }

                if (Main.Settings.FactionLogoPaths.ContainsKey(factionName))
                {
                    var path = Path.Combine(Main.ModDir, Main.Settings.FactionLogoPaths[factionName]);

                    // from https://answers.unity.com/questions/432655/loading-texture-file-from-pngjpg-file-on-disk.html
                    var texture2d = new Texture2D(2, 2);
                    texture2d.LoadImage(File.ReadAllBytes(path));

                    logo.GetComponent <Renderer>().material.mainTexture = texture2d;
                }

                logos.Add(faction, logo);
            }

            PlaceAndScaleLogos(logos, renderer);
        }
Esempio n. 6
0
            public static void Postfix(StarmapRenderer __instance)
            {
                if (Globals.WarStatusTracker == null || Globals.Sim.IsCampaign && !Globals.Sim.CompanyTags.Contains("story_complete"))
                {
                    return;
                }

                if (!Globals.Settings.ExpandedMap)
                {
                    DynamicLogos.PlaceAndScaleLogos(Globals.Settings.LogoNames, __instance);
                }
            }
Esempio n. 7
0
        public static void Postfix(StarmapRenderer __instance)
        {
            var sim = UnityGameInstance.BattleTechGame.Simulation;

            if (Core.WarStatus == null || (sim.IsCampaign && !sim.CompanyTags.Contains("story_complete")))
            {
                return;
            }

            if (!Core.Settings.ExpandedMap)
            {
                Galaxy_at_War.DynamicLogos.PlaceAndScaleLogos(Core.Settings.LogoNames, __instance);
            }
        }
Esempio n. 8
0
        static bool Prefix(StarmapRenderer __instance, Vector2 normalizedPos, ref Vector3 __result)
        {
            // Reminder -- normalizedPos is normalized between [0,1]
            // This normalizes it between [-100,100]
            Vector3 newResult = normalizedPos;

            newResult.x = (newResult.x * 2f - 1f) * InnerSphereMap.SETTINGS.MapWidth;
            newResult.y = (newResult.y * 2f - 1f) * InnerSphereMap.SETTINGS.MapHeight;
            newResult.z = 0f;

            __result = newResult;

            return(false);
        }
Esempio n. 9
0
        static void Postfix(StarmapRenderer __instance, ref Color __result, Faction thisFaction)
        {
            try {
                if (__result == __instance.nofactionColor || __result == __instance.directorateColor)
                {
                    switch (thisFaction)
                    {
                    case Faction.Kurita:
                        __result = new Color(0.863f, 0.078f, 0.235f, 1f);
                        break;

                    case Faction.Steiner:
                        __result = new Color(0.255f, 0.412f, 0.882f, 1f);
                        break;

                    case Faction.Betrayers:
                        __result = new Color(0.627f, 0.322f, 0.176f, 1f);
                        break;

                    case Faction.MagistracyCentrella:
                        __result = new Color(1f, 1f, 0f, 1f);
                        break;

                    case Faction.MajestyMetals:
                        __result = new Color(0.196f, 0.804f, 0.196f, 1f);
                        break;

                    case Faction.AuriganDirectorate:
                        __result = new Color(1f, 0.549f, 0f, 1f);
                        break;

                    case Faction.Nautilus:
                        __result = new Color(0.545f, 0f, 0f, 1f);
                        break;

                    case Faction.AuriganMercenaries:
                        __result = new Color(0.741f, 0.718f, 0.420f, 1f);
                        break;

                    default:
                        __result = __instance.nofactionColor;
                        break;
                    }
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Esempio n. 10
0
        public static void ScaleMapBorders(StarmapRenderer renderer)
        {
            var starmapBorders = renderer.gameObject.GetComponentInChildren <StarmapBorders>();

            if (starmapBorders == null)
            {
                return;
            }

            // set scale of region borders for our new size
            var borderTransform = starmapBorders.gameObject.transform;

            borderTransform.localScale = new Vector3(4f * Main.Settings.MapHeight, 4f * Main.Settings.MapWidth);

            // generate black texture to use for plusTex, so that we don't have a
            // stretched texture, it looked weird anyways
            const int textureSize  = 64;
            var       blackTexture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false);

            for (var x = 0; x < textureSize; x++)
            {
                for (var y = 0; y < textureSize; y++)
                {
                    blackTexture.SetPixel(x, y, Color.black);
                }
            }
            blackTexture.Apply();
            starmapBorders.plusTex = blackTexture;

            // change the map border edges
            var edgeLine = GameObject.Find("Edges")?.GetComponent <LineRenderer>();

            if (edgeLine != null)
            {
                var height = Main.Settings.MapHeight + Main.Settings.BorderMargin;
                var width  = Main.Settings.MapWidth + Main.Settings.BorderMargin;

                edgeLine.positionCount = 4;
                edgeLine.SetPositions(new []
                {
                    new Vector3(-height, -width),
                    new Vector3(-height, width),
                    new Vector3(height, width),
                    new Vector3(height, -width),
                });
            }
        }
Esempio n. 11
0
            public static void Prefix(StarmapRenderer __instance)
            {
                var sim = UnityGameInstance.BattleTechGame.Simulation;

                if (Globals.WarStatusTracker == null || (sim.IsCampaign && !sim.CompanyTags.Contains("story_complete")))
                {
                    return;
                }

                if (Globals.WarStatusTracker != null && !Globals.WarStatusTracker.StartGameInitialized)
                {
                    LogDebug($"Refreshing contracts at RefreshStarmap. ({Globals.Sim.CurSystem.Name})");
                    var cmdCenter = UnityGameInstance.BattleTechGame.Simulation.RoomManager.CmdCenterRoom;
                    sim.CurSystem.GenerateInitialContracts(() => cmdCenter.OnContractsFetched());
                    Globals.WarStatusTracker.StartGameInitialized = true;
                }
            }
Esempio n. 12
0
        public static void Prefix(StarmapRenderer __instance)
        {
            var sim = UnityGameInstance.BattleTechGame.Simulation;

            if (Core.WarStatus == null || (sim.IsCampaign && !sim.CompanyTags.Contains("story_complete")))
            {
                return;
            }

            if (Core.WarStatus != null && !Core.WarStatus.StartGameInitialized)
            {
                Core.NeedsProcessing = true;
                var cmdCenter = UnityGameInstance.BattleTechGame.Simulation.RoomManager.CmdCenterRoom;
                sim.CurSystem.GenerateInitialContracts(() => Traverse.Create(cmdCenter).Method("OnContractsFetched"));
                Core.WarStatus.StartGameInitialized = true;
                Core.NeedsProcessing = false;
            }
        }
Esempio n. 13
0
        public static void PostUpdate(StarmapRenderer renderer)
        {
            if (!Main.Settings.UseSmoothZoom)
            {
                return;
            }

            if (Mathf.Abs(_targetZoom - _currentZoom) > 0.01)
            {
                var smoothedZoom = Mathf.SmoothDamp(_currentZoom, _targetZoom, ref _zoomVelocity, Main.Settings.SmoothZoomTime);
                Traverse.Create(renderer).Field("zoomLevel").SetValue(smoothedZoom);

                var fakeCamera = Traverse.Create(renderer).Field("fakeCamera").GetValue <Camera>();
                var newFov     = Mathf.Lerp(Main.Settings.MinFov, Main.Settings.MaxFov, smoothedZoom);
                renderer.starmapCamera.fieldOfView = newFov;
                fakeCamera.fieldOfView             = newFov;
            }
        }
Esempio n. 14
0
        static bool Prefix(StarmapRenderer __instance)
        {
            __instance.starmapCamera.gameObject.SetActive(true);
            Dictionary <GameObject, StarmapSystemRenderer> systemDictionary = (Dictionary <GameObject, StarmapSystemRenderer>)ReflectionHelper.GetPrivateField(__instance, "systemDictionary");

            foreach (StarmapSystemRenderer starmapSystemRenderer in systemDictionary.Values)
            {
                ReflectionHelper.InvokePrivateMethode(__instance, "InitializeSysRenderer", new object[] { starmapSystemRenderer.system, starmapSystemRenderer });
                if (__instance.starmap.CurSelected != null && __instance.starmap.CurSelected.System.ID == starmapSystemRenderer.system.System.ID)
                {
                    starmapSystemRenderer.Selected();
                }
                else
                {
                    starmapSystemRenderer.Deselected();
                }
            }
            return(false);
        }
            public static bool Prefix(
                StarmapRenderer __instance,
                StarSystemNode node,
                StarmapSystemRenderer renderer)
            {
                return(HarmonyManager.PrefixLogExceptions(() =>
                {
                    bool flag = __instance.starmap.CanTravelToNode(node, false);
                    RGBColor <float> color = new RGBColor <float>(1, 1, 1);

                    VisitedColors visitedColors = HarmonyManager.Settings.VisitedColors;

                    switch (CurrentMapType)
                    {
                    case MapType.None:
                        return true;

                    case MapType.Difficulty:
                        color = GetDifficultyColor(__instance, node);
                        break;

                    case MapType.Visited:
                        color = __instance.starmap.HasStarSystemBeenVisited(node)
                                        ? visitedColors.VisitedColor
                                        : visitedColors.NotVisitedColor;
                        break;

                    case MapType.MaxContracts:
                        color = GetDifficultyColor((int)node.System.CurMaxContracts);
                        break;

                    default:
                        throw new InvalidEnumArgumentException("'CurrentMapType' has invalid value. This should never happen. Please report this as a bug.");
                    }
                    if (renderer.Init(node, flag ? color.FromRGBColor() : __instance.unavailableColor, flag))
                    {
                        __instance.RefreshBorders();
                    }

                    // Don't call the original method, we've replaced it.
                    return false;
                }));
            }
Esempio n. 16
0
        public static void Postfix(StarmapRenderer __instance, StarmapSystemRenderer __result)
        {
            try
            {
                if (Core.WarStatus == null || sim.IsCampaign && !sim.CompanyTags.Contains("story_complete"))
                {
                    return;
                }

                //Core.timer.Restart();
                if (Core.WarStatus != null)
                {
                    List <string> VisitedStarSystems = (List <string>)Traverse.Create(sim).Field("VisitedStarSystems").GetValue();
                    var           wasVisited         = VisitedStarSystems.Contains(__result.name);

                    if (Core.WarStatus.HomeContendedStrings.Contains(__result.name))
                    {
                        HighlightSystem(__result, wasVisited, Color.magenta, true);
                    }
                    else if (Core.WarStatus.LostSystems.Contains(__result.name))
                    {
                        HighlightSystem(__result, wasVisited, Color.yellow, false);
                    }
                    else if (Core.WarStatus.PirateHighlight.Contains(__result.name))
                    {
                        HighlightSystem(__result, wasVisited, Color.red, false);
                    }
                    else if (__result.systemColor == Color.magenta || __result.systemColor == Color.yellow)
                    {
                        MakeSystemNormal(__result, wasVisited);
                    }
                }

                //LogDebug(Core.timer.ElapsedTicks);
            }
            catch (Exception ex)
            {
                LogDebug(ex.ToString());
            }
        }
Esempio n. 17
0
        public static void Postfix(StarmapRenderer __instance, Dictionary <GameObject, StarmapSystemRenderer> ___systemDictionary)
        {
            var simGame = Traverse.Create(__instance.starmap).Field("sim").GetValue <SimGameState>();


            if (!Patches.Settings.CareerOnly || simGame.IsCareerMode())
            {
                var visitedSystems = Traverse.Create(simGame).Field("VisitedStarSystems").GetValue <List <string> >();

                mpb.Clear();
                foreach (var system in visitedSystems)
                {
                    var systemRenderer = __instance.GetSystemRenderer(system);
                    var starOuter      = Traverse.Create(systemRenderer).Field("starOuter").GetValue <Renderer>();
                    var newColor       = systemRenderer.systemColor / 3f;

                    // set outer color
                    mpb.SetColor("_Color", newColor);
                    starOuter.SetPropertyBlock(mpb);
                }
            }
        }
Esempio n. 18
0
        public static void PreUpdate(StarmapRenderer renderer)
        {
            if (!Main.Settings.UseSmoothZoom)
            {
                return;
            }

            _currentZoom = renderer.ZoomLevel;

            var scroll = -Input.GetAxis("Mouse ScrollWheel");

            if (Mathf.Abs(scroll) > 0.01f && !LazySingletonBehavior <UIManager> .Instance.DoesRaycastHitUI(UIManagerRootType.UIRoot))
            {
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (_startZoom == 0f || Mathf.Abs(_targetZoom - _currentZoom) < 0.01)
                {
                    _startZoom  = _currentZoom;
                    _targetZoom = _currentZoom;
                }

                _targetZoom = Mathf.Clamp01(_targetZoom + scroll * 1f);
            }
        }
Esempio n. 19
0
        public static void PlaceAndScaleLogos(Dictionary <FactionValue, GameObject> logos, StarmapRenderer renderer)
        {
            var boundingRects = new Dictionary <FactionValue, BoundingRect>();

            foreach (var starNode in renderer.starmap.VisisbleSystem)
            {
                var faction = starNode.System.OwnerValue;
                if (!logos.ContainsKey(faction))
                {
                    continue;
                }

                BoundingRect boundingRect;
                if (boundingRects.ContainsKey(faction))
                {
                    boundingRect = boundingRects[faction];
                }
                else
                {
                    boundingRect = new BoundingRect();
                    boundingRects.Add(faction, boundingRect);
                }

                boundingRect.MinX = Mathf.Min(boundingRect.MinX, starNode.NormalizedPosition.x);
                boundingRect.MaxX = Mathf.Max(boundingRect.MaxX, starNode.NormalizedPosition.x);
                boundingRect.MinY = Mathf.Min(boundingRect.MinY, starNode.NormalizedPosition.y);
                boundingRect.MaxY = Mathf.Max(boundingRect.MaxY, starNode.NormalizedPosition.y);
            }

            foreach (var faction in logos.Keys)
            {
                if (!boundingRects.ContainsKey(faction))
                {
                    continue;
                }

                var logo = logos[faction];

                var boundingRect = boundingRects[faction];
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (boundingRect.MinX == float.MaxValue)
                {
                    // there were no star systems
                    logo.SetActive(false);
                    continue;
                }

                logo.SetActive(true);

                // position is in the middle of the boundingRect
                var x             = (boundingRect.MaxX + boundingRect.MinX) / 2f;
                var y             = (boundingRect.MaxY + boundingRect.MinY) / 2f;
                var normalizedPos = new Vector2(x, y);
                logo.transform.position = StarmapRenderer.NormalizeToMapSpace(normalizedPos);

                // scale is based off of the width/height of the boundingRect
                var topRight   = StarmapRenderer.NormalizeToMapSpace(new Vector2(boundingRect.MaxX, boundingRect.MaxY));
                var bottomLeft = StarmapRenderer.NormalizeToMapSpace(new Vector2(boundingRect.MinX, boundingRect.MinY));
                var width      = topRight.x - bottomLeft.x;
                var height     = topRight.y - bottomLeft.y;

                var scale = Mathf.Min(Mathf.Min(width, height) * Main.Settings.LogoScalar, Main.Settings.LogoMaxSize);
                logo.transform.localScale = new Vector3(scale, scale);
            }
        }
Esempio n. 20
0
 public static void Prefix(StarmapRenderer __instance)
 {
     SmoothZoom.PreUpdate(__instance);
 }
Esempio n. 21
0
 public static void Postfix(StarmapRenderer __instance)
 {
     DynamicLogos.PlaceLogos(__instance);
     ResizableMap.OnMapRefresh(__instance);
 }
Esempio n. 22
0
        static void Postfix(StarmapRenderer __instance)
        {
            try {
                var davionLogo      = GameObject.Find("davionLogo");
                var marikLogo       = GameObject.Find("marikLogo");
                var directorateLogo = GameObject.Find("directorateLogo");
                directorateLogo?.SetActive(false);
                davionLogo?.SetActive(false);
                marikLogo?.SetActive(false);
                var liaoLogo = GameObject.Find("liaoLogo");
                liaoLogo?.SetActive(false);
                var taurianLogo = GameObject.Find("taurianLogo");
                taurianLogo?.SetActive(false);
                var magistracyLogo = GameObject.Find("magistracyLogo");
                magistracyLogo?.SetActive(false);
                var restorationLogo = GameObject.Find("restorationLogo");
                restorationLogo?.SetActive(false);

                Texture2D texture2D2 = new Texture2D(2, 2);
                byte[]    data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/davionLogo.png");
                texture2D2.LoadImage(data);
                GameObject go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Davion, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/liaoLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Liao, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/magistracyLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.MagistracyOfCanopus, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/marikLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Marik, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/restorationLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.AuriganRestoration, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/taurianLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.TaurianConcordat, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/steinerLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Steiner, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/draconisLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Kurita, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/circinusLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Nautilus, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/oberonLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.MagistracyCentrella, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/illyrianLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.AuriganMercenaries, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/lothianLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.MajestyMetals, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/marianLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.AuriganDirectorate, go });

                texture2D2 = new Texture2D(2, 2);
                data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/outworldsLogo.png");
                texture2D2.LoadImage(data);
                go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { Faction.Betrayers, go });
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Esempio n. 23
0
 public static SimGameState GetSimGameState(this StarmapRenderer starmapRenderer)
 {
     return(starmapRenderer.starmap.GetSimGameState());
 }
Esempio n. 24
0
        static void Postfix(StarmapRenderer __instance, ref Color __result, Faction thisFaction)
        {
            try {
                Settings settings = Helper.LoadSettings();
                switch (thisFaction)
                {
                case Faction.Kurita:
                    __result = new Color(settings.KuritaRGB[0], settings.KuritaRGB[1], settings.KuritaRGB[2], 1f);
                    break;

                case Faction.Steiner:
                    __result = new Color(settings.SteinerRGB[0], settings.SteinerRGB[1], settings.SteinerRGB[2], 1f);
                    break;

                case Faction.Betrayers:
                    __result = new Color(settings.OutworldsRGB[0], settings.OutworldsRGB[1], settings.OutworldsRGB[2], 1f);
                    break;

                case Faction.MagistracyCentrella:
                    __result = new Color(settings.OberonRGB[0], settings.OberonRGB[1], settings.OberonRGB[2], 1f);
                    break;

                case Faction.MajestyMetals:
                    __result = new Color(settings.LothianRGB[0], settings.LothianRGB[1], settings.LothianRGB[2], 1f);
                    break;

                case Faction.AuriganDirectorate:
                    __result = new Color(settings.MarianRGB[0], settings.MarianRGB[1], settings.MarianRGB[2], 1f);
                    break;

                case Faction.Nautilus:
                    __result = new Color(settings.CircinusRGB[0], settings.CircinusRGB[1], settings.CircinusRGB[2], 1f);
                    break;

                case Faction.AuriganMercenaries:
                    __result = new Color(settings.IllyrianRGB[0], settings.IllyrianRGB[1], settings.IllyrianRGB[2], 1f);
                    break;

                case Faction.Davion:
                    __result = new Color(settings.DavionRGB[0], settings.DavionRGB[1], settings.DavionRGB[2], 1f);
                    break;

                case Faction.Liao:
                    __result = new Color(settings.LiaoRGB[0], settings.LiaoRGB[1], settings.LiaoRGB[2], 1f);
                    break;

                case Faction.Marik:
                    __result = new Color(settings.MarikRGB[0], settings.MarikRGB[1], settings.MarikRGB[2], 1f);
                    break;

                case Faction.TaurianConcordat:
                    __result = new Color(settings.TaurianRGB[0], settings.TaurianRGB[1], settings.TaurianRGB[2], 1f);
                    break;

                case Faction.MagistracyOfCanopus:
                    __result = new Color(settings.MagistracyRGB[0], settings.MagistracyRGB[1], settings.MagistracyRGB[2], 1f);
                    break;

                case Faction.AuriganRestoration:
                    __result = new Color(settings.RestorationRGB[0], settings.RestorationRGB[1], settings.RestorationRGB[2], 1f);
                    break;

                default:
                    __result = __instance.nofactionColor;
                    break;
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Esempio n. 25
0
        static void Postfix(StarmapRenderer __instance)
        {
            try {
                var davionLogo      = GameObject.Find("davionLogo");
                var marikLogo       = GameObject.Find("marikLogo");
                var directorateLogo = GameObject.Find("directorateLogo");
                directorateLogo?.SetActive(false);
                davionLogo?.SetActive(false);
                marikLogo?.SetActive(false);
                var liaoLogo = GameObject.Find("liaoLogo");
                liaoLogo?.SetActive(false);
                var taurianLogo = GameObject.Find("taurianLogo");
                taurianLogo?.SetActive(false);
                var magistracyLogo = GameObject.Find("magistracyLogo");
                magistracyLogo?.SetActive(false);
                var restorationLogo = GameObject.Find("restorationLogo");
                restorationLogo?.SetActive(false);

                GameObject go;
                if (Fields.originalTransform == null)
                {
                    Fields.originalTransform = UnityEngine.Object.Instantiate(__instance.restorationLogo).transform;
                }
                Texture2D texture2D2;
                byte[]    data;

                foreach (LogoItem logoItem in InnerSphereMap.SETTINGS.logos)
                {
                    FactionValue factionValue = FactionEnumeration.GetFactionByName(logoItem.factionName);
                    if (factionValue.IsClan && InnerSphereMap.SETTINGS.reducedClanLogos)
                    {
                        continue;
                    }
                    string mapGoObject = logoItem.factionName + "Map";
                    if (GameObject.Find(mapGoObject) == null)
                    {
                        texture2D2 = new Texture2D(2, 2);
                        data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/{logoItem.logoImage}.png");
                        texture2D2.LoadImage(data);
                        go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                        go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                        go.name = mapGoObject;
                    }
                    else
                    {
                        go = GameObject.Find(mapGoObject);
                    }
                    ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { FactionEnumeration.GetFactionByName(logoItem.factionName), go });
                }

                if (InnerSphereMap.SETTINGS.reducedClanLogos)
                {
                    SimGameState        sim = (SimGameState)AccessTools.Field(typeof(Starmap), "sim").GetValue(__instance.starmap);
                    List <FactionValue> contestingFactions = new List <FactionValue>();
                    foreach (FactionValue faction in FactionEnumeration.FactionList)
                    {
                        if (faction.IsClan && faction.CanAlly)
                        {
                            contestingFactions.Add(faction);
                        }
                    }
                    Dictionary <FactionValue, int> ranking = new Dictionary <FactionValue, int>();
                    foreach (StarSystem system in sim.StarSystems)
                    {
                        if (contestingFactions.Contains(system.OwnerValue))
                        {
                            if (!ranking.ContainsKey(system.OwnerValue))
                            {
                                ranking.Add(system.OwnerValue, 0);
                            }
                            ranking[system.OwnerValue]++;
                        }
                    }
                    FactionValue invaderclan = FactionEnumeration.GetInvalidUnsetFactionValue();
                    if (ranking.Count > 0)
                    {
                        invaderclan = ranking.OrderByDescending(x => x.Value).First().Key;
                    }
                    if (invaderclan != FactionEnumeration.GetInvalidUnsetFactionValue())
                    {
                        if (GameObject.Find("ClansInvaderLogoMap") == null)
                        {
                            texture2D2 = new Texture2D(2, 2);
                            data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/" + invaderclan.Name + "Logo.png");
                            texture2D2.LoadImage(data);
                            go = UnityEngine.Object.Instantiate(__instance.restorationLogo);
                            go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                            go.name = "ClansInvaderLogoMap";
                        }
                        else
                        {
                            go         = GameObject.Find("ClansInvaderLogoMap");
                            data       = File.ReadAllBytes($"{InnerSphereMap.ModDirectory}/Logos/" + invaderclan.Name + "Logo.png");
                            texture2D2 = new Texture2D(2, 2);
                            texture2D2.LoadImage(data);
                            go.GetComponent <Renderer>().material.mainTexture = texture2D2;
                        }
                        ReflectionHelper.InvokePrivateMethode(__instance, "PlaceLogo", new object[] { invaderclan, go });
                    }
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Esempio n. 26
0
        static void Postfix(StarmapRenderer __instance)
        {
            try {
                // Two private fields
                Traverse travInstance = Traverse.Create(__instance);
                float    zoomLevel    = travInstance.Field("zoomLevel").GetValue <float>();
                bool     needsPan     = travInstance.Field("needsPan").GetValue <bool>();
                Camera   fakeCamera   = travInstance.Field("fakeCamera").GetValue <Camera>();

                // starMapCamera is public
                Camera starMapCamera = __instance.starmapCamera;

                // We want to readjust the field of view given our own min and max
                float newFov = Mathf.Lerp(InnerSphereMap.SETTINGS.MinFov, InnerSphereMap.SETTINGS.MaxFov, zoomLevel);
                starMapCamera.fieldOfView = newFov;
                fakeCamera.fieldOfView    = newFov;

                // Now we need to clamp the bounadries
                float verticalViewSize   = CameraHelper.GetViewSize(Mathf.Abs(starMapCamera.transform.position.z), newFov);
                float horizontalViewSize = CameraHelper.GetViewSize(Mathf.Abs(starMapCamera.transform.position.z), CameraHelper.GetHorizontalFov(newFov));

                Vector3 currentPosition = starMapCamera.transform.position;
                Vector3 clampedPosition = currentPosition;

                // The clamping boundaries are the map width / height + the buffers + the viewing distance created with the FOVs
                float leftBoundary   = -InnerSphereMap.SETTINGS.MapWidth - InnerSphereMap.SETTINGS.MapLeftViewBuffer + horizontalViewSize;
                float rightBoundary  = InnerSphereMap.SETTINGS.MapWidth + InnerSphereMap.SETTINGS.MapRightViewBuffer - horizontalViewSize;
                float bottomBoundary = -InnerSphereMap.SETTINGS.MapHeight - InnerSphereMap.SETTINGS.MapBottomViewBuffer + verticalViewSize;
                float topBoundary    = InnerSphereMap.SETTINGS.MapHeight + InnerSphereMap.SETTINGS.MapTopViewBuffer - verticalViewSize;

                float totalWidth  = InnerSphereMap.SETTINGS.MapWidth * 2f + InnerSphereMap.SETTINGS.MapLeftViewBuffer + InnerSphereMap.SETTINGS.MapRightViewBuffer;
                float totalHeight = InnerSphereMap.SETTINGS.MapHeight * 2f + InnerSphereMap.SETTINGS.MapTopViewBuffer + InnerSphereMap.SETTINGS.MapBottomViewBuffer;

                // We have to check for the FOV being larger than the whole map -- or it'll bounce around
                if (horizontalViewSize * 2f >= totalWidth)
                {
                    clampedPosition.x = 0f;
                    needsPan          = false;
                }
                else
                {
                    clampedPosition.x = Mathf.Clamp(currentPosition.x, leftBoundary, rightBoundary);
                }

                if (verticalViewSize * 2f >= totalHeight)
                {
                    clampedPosition.y = 0f;
                    needsPan          = false;
                }
                else
                {
                    clampedPosition.y = Mathf.Clamp(currentPosition.y, bottomBoundary, topBoundary);
                }

                // Check for boundaries conditions -- continue the previous HBS behavior of not panning
                if (clampedPosition.x == leftBoundary || clampedPosition.x == rightBoundary || clampedPosition.y == topBoundary || clampedPosition.y == bottomBoundary)
                {
                    needsPan = false;
                }
                starMapCamera.transform.position = clampedPosition;
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }