示例#1
0
        public override void Initialize()
        {
            if (Instance != null)
            {
                DebugLog.Warn("Initialized twice... Stop that.");
                return;
            }
            Instance = this;
            DebugLog.Log("RandoMapMod Initializing...");

            Resources.Initialize();

            On.GameMap.Start           += this.GameMap_Start;                           //Set up custom pins
            On.GameMap.WorldMap        += this.GameMap_WorldMap;                        //Set big map boundaries
            On.GameMap.SetupMapMarkers += this.GameMap_SetupMapMarkers;                 //Enable the custom pins
            On.GameMap.DisableMarkers  += this.GameMap_DisableMarkers;                  //Disable the custom pins

            ModHooks.Instance.SavegameLoadHook += this.SavegameLoadHook;                //Load object name changes
            ModHooks.Instance.SavegameSaveHook += this.SavegameSaveHook;                //Load object name changes

            //Giveaway time
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += HandleSceneChanges;
            ModHooks.Instance.LanguageGetHook += HandleLanguageGet;

            DebugLog.Log("RandoMapMod Initialize complete!");
        }
 public void Show(HelperData helperData)
 {
     try
     {
         if (helperData == null)
         {
             return;                     //do nothing
         }
         string[] foo = helperData.reachable.Values
                        .Where((location) => location.items.Count > 0)
                        .OrderByDescending((location) => location.items.Count)
                        .Select((location) => $"{location.name} - {location.items.Count} reachable")
                        .ToArray();
         GetOrInitializeTextComponent().text = string.Join("\n", foo);
         GetOrInitializeTextObj().SetActive(true);
     }
     catch (Exception e)
     {
         logger.Warn($"Show failed: {e}");
     }
 }
        static ResourceHelper()
        {
            Assembly theDLL = typeof(MapMod).Assembly;

            _pSprites = new Dictionary <Sprites, Sprite>();
            foreach (string resource in theDLL.GetManifestResourceNames())
            {
                if (resource.EndsWith(".png"))
                {
                    //Load up all the one sprites!
                    Stream img  = theDLL.GetManifestResourceStream(resource);
                    byte[] buff = new byte[img.Length];
                    img.Read(buff, 0, buff.Length);
                    img.Dispose();

                    Texture2D texture = new Texture2D(1, 1);
                    texture.LoadImage(buff, true);
                    Sprites?key = resource switch {
                        "RandoMapMod.Resources.Map.old_prereqPin.png" => Sprites.old_prereq,

                        "RandoMapMod.Resources.Map.pinUnknown_GeoRock.png" => Sprites.oldGeoRock,
                        "RandoMapMod.Resources.Map.pinUnknown_Grub.png" => Sprites.oldGrub,
                        "RandoMapMod.Resources.Map.pinUnknown_Lifeblood.png" => Sprites.oldLifeblood,
                        "RandoMapMod.Resources.Map.pinUnknown_Totem.png" => Sprites.oldTotem,

                        "RandoMapMod.Resources.Map.pinUnknown_GeoRockInv.png" => Sprites.oldGeoRockInv,
                        "RandoMapMod.Resources.Map.pinUnknown_GrubInv.png" => Sprites.oldGrubInv,
                        "RandoMapMod.Resources.Map.pinUnknown_LifebloodInv.png" => Sprites.oldLifebloodInv,
                        "RandoMapMod.Resources.Map.pinUnknown_TotemInv.png" => Sprites.oldTotemInv,

                        "RandoMapMod.Resources.Map.pinUnknown.png" => Sprites.Unknown,
                        "RandoMapMod.Resources.Map.modPrereq.png" => Sprites.Prereq,

                        "RandoMapMod.Resources.Map.pinCharm.png" => Sprites.Charm,
                        "RandoMapMod.Resources.Map.pinCocoon.png" => Sprites.Cocoon,
                        "RandoMapMod.Resources.Map.pinDreamer.png" => Sprites.Dreamer,
                        "RandoMapMod.Resources.Map.pinEgg.png" => Sprites.Egg,
                        "RandoMapMod.Resources.Map.pinEssenceBoss.png" => Sprites.EssenceBoss,
                        "RandoMapMod.Resources.Map.pinFlame.png" => Sprites.Flame,
                        "RandoMapMod.Resources.Map.pinGeo.png" => Sprites.Geo,
                        "RandoMapMod.Resources.Map.pinGrub.png" => Sprites.Grub,
                        "RandoMapMod.Resources.Map.pinKey.png" => Sprites.Key,
                        "RandoMapMod.Resources.Map.pinLore.png" => Sprites.Lore,
                        "RandoMapMod.Resources.Map.pinMap.png" => Sprites.Map,
                        "RandoMapMod.Resources.Map.pinMask.png" => Sprites.Mask,
                        "RandoMapMod.Resources.Map.pinNotch.png" => Sprites.Notch,
                        "RandoMapMod.Resources.Map.pinOre.png" => Sprites.Ore,
                        "RandoMapMod.Resources.Map.pinRelic.png" => Sprites.Relic,
                        "RandoMapMod.Resources.Map.pinRock.png" => Sprites.Rock,
                        "RandoMapMod.Resources.Map.pinRoot.png" => Sprites.Root,
                        "RandoMapMod.Resources.Map.pinShop.png" => Sprites.Shop,
                        "RandoMapMod.Resources.Map.pinSkill.png" => Sprites.Skill,
                        "RandoMapMod.Resources.Map.pinStag.png" => Sprites.Stag,
                        "RandoMapMod.Resources.Map.pinTotem.png" => Sprites.Totem,
                        "RandoMapMod.Resources.Map.pinVessel.png" => Sprites.Vessel,

                        "RandoMapMod.Resources.Map.reqEssenceBoss.png" => Sprites.reqEssenceBoss,
                        "RandoMapMod.Resources.Map.reqGrub.png" => Sprites.reqGrub,
                        "RandoMapMod.Resources.Map.reqRoot.png" => Sprites.reqRoot,
                        _ => null
                    };
                    if (key == null)
                    {
                        DebugLog.Warn($"Found unrecognized sprite {resource}. Ignoring.");
                    }
                    else
                    {
                        _pSprites.Add(
                            (Sprites)key,
                            Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
                    }
                }
                else if (resource.EndsWith("pindata.xml"))
                {
                    //Load the pin-specific data; we'll follow up with the direct rando info later, so we don't duplicate defs...
                    try {
                        using (Stream stream = theDLL.GetManifestResourceStream(resource)) {
                            PinData = _LoadPinData(stream);
                        }
                    } catch (Exception e) {
                        DebugLog.Error("pindata.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
            }
示例#4
0
        private static DataStore _Parse(StreamReader reader)
        {
            DataStore newData = new DataStore();
            string    line;
            //Read until we see "REACHABLE ITEM LOCATIONS".
            bool sawReachableItemLocations = false;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals("REACHABLE ITEM LOCATIONS"))
                {
                    sawReachableItemLocations = true;
                    break;
                }
            }
            if (!sawReachableItemLocations)
            {
                throw new HelperLogException("Expected to see 'RECHABLE ITEM LOCATIONS' but hit end of file.");
            }
            line = reader.ReadLine();
            if (!Regex.Match(line, @"There are [0-9]+ unchecked reachable locations.", RegexOptions.None).Success)
            {
                throw new HelperLogException($"Expected to see 'There are N unchecked reachable locations.' but got {line}");
            }
            line = reader.ReadLine();
            if (!"".Equals(line))
            {
                throw new HelperLogException($"Expected a blank line but got {line}");
            }
            bool         sawCheckedItemLocations = false;
            Location     currentLocation         = null;
            const string itemPrefix = " - ";

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals("CHECKED ITEM LOCATIONS"))
                {
                    sawCheckedItemLocations = true;
                    break;
                }
                else if (line.Equals(""))
                {
                    if (currentLocation != null)
                    {
                        try {
                            newData.AddReachableLocation(currentLocation.Name, currentLocation);
                        } catch (ArgumentException e) {
                            DebugLog.Warn($"Ignoring duplicate entry for location {currentLocation.Name} (old value = {newData.GetReachableLocation(currentLocation.Name)}, new value = {currentLocation}) {e}");
                        }
                    }
                    currentLocation = null;
                }
                else if (line.StartsWith(itemPrefix))
                {
                    currentLocation.Items.Add(line.Substring(itemPrefix.Length));
                }
                else
                {
                    currentLocation = new Location(line);
                }
            }
            if (!sawCheckedItemLocations)
            {
                throw new HelperLogException("Expected to see 'CHECKED ITEM LOCATIONS' but reached end of file.");
            }
            while ((line = reader.ReadLine()) != null)
            {
                if (Regex.Match(line, @"Generated helper log in [0-9.]+ seconds\.", RegexOptions.None).Success)
                {
                    break;
                }
                else if (line.Equals(""))
                {
                    if (currentLocation != null)
                    {
                        try {
                            newData.AddCheckedLocation(currentLocation.Name, currentLocation);
                        } catch (ArgumentException e) {
                            DebugLog.Warn($"Ignoring duplicate entry for locationg {currentLocation.Name} (old value = {newData.GetCheckedLocation(currentLocation.Name)}, new value = {currentLocation}) {e}");
                        }
                    }
                    currentLocation = null;
                }
                else if (line.StartsWith(itemPrefix))
                {
                    currentLocation.Items.Add(line.Substring(itemPrefix.Length));
                }
                else
                {
                    currentLocation = new Location(line);
                }
            }
            return(newData);
        }
        public Resources()
        {
            Assembly theDLL = typeof(RandoMapMod).Assembly;

            pSprites = new Dictionary <SpriteId, Sprite>();
            foreach (string resource in theDLL.GetManifestResourceNames())
            {
                if (resource.EndsWith(".png"))
                {
                    //Load up all the one sprites!
                    Stream img  = theDLL.GetManifestResourceStream(resource);
                    byte[] buff = new byte[img.Length];
                    img.Read(buff, 0, buff.Length);
                    img.Dispose();

                    Texture2D texture = new Texture2D(1, 1);
                    texture.LoadImage(buff, true);
                    SpriteId?key = resource switch
                    {
                        "RandoMapMod.Resources.Map.prereqPin.png" => SpriteId.MissingPrereq,
                        "RandoMapMod.Resources.Map.randoPin.png" => SpriteId.Rando,
                        "RandoMapMod.Resources.Map.shopPin.png" => SpriteId.Shop,
                        _ => null
                    };
                    if (key == null)
                    {
                        logger.Warn($"Found unrecognized sprite {resource}. Ignoring.");
                    }
                    else
                    {
                        pSprites.Add(
                            (SpriteId)key,
                            UnityEngine.Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
                    }
                }
                else if (resource.EndsWith("pindata.xml"))
                {
                    //Load the pin-specific data; we'll follow up with the direct rando info later, so we don't duplicate defs...
                    try
                    {
                        using (Stream stream = theDLL.GetManifestResourceStream(resource))
                        {
                            pPinData = loadPinData(stream);
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Error("pindata.xml Load Failed!");
                        logger.Error(e.ToString());
                    }
                }
            }

            Assembly randoDLL = typeof(RandomizerMod.RandomizerMod).Assembly;
            Dictionary <String, Action <XmlDocument> > resourceProcessors = new Dictionary <String, Action <XmlDocument> >
            {
                {
                    "items.xml", (xml) => {
                        loadItemData(xml.SelectNodes("randomizer/item"));
                    }
                }
            };

            foreach (string resource in randoDLL.GetManifestResourceNames())
            {
                foreach (string resourceEnding in resourceProcessors.Keys)
                {
                    if (resource.EndsWith(resourceEnding))
                    {
                        logger.Log($"Loading data from {nameof(RandomizerMod)}'s {resource} file.");
                        try
                        {
                            using (Stream stream = randoDLL.GetManifestResourceStream(resource))
                            {
                                XmlDocument xml = new XmlDocument();
                                xml.Load(stream);
                                resourceProcessors[resourceEnding].Invoke(xml);
                            }
                        }
                        catch (Exception e)
                        {
                            logger.Error($"{resourceEnding} Load Failed!");
                            logger.Error(e.ToString());
                        }
                        break;
                    }
                }
            }
        }
        public void AddPinToRoom(PinData pinData, GameMap gameMap)
        {
            if (_pins.Any(pin => pin.PinData.ID == pinData.ID))
            {
                //Already in the list... Probably shouldn't add them.
                DebugLog.Warn($"Duplicate pin found for group: {pinData.ID} - Skipped.");
                return;
            }

            string roomName  = pinData.PinScene ?? ResourceHelper.PinData[pinData.ID].SceneName;
            Sprite pinSprite = pinData.IsShop ?
                               pinSprite                         = ResourceHelper.FetchSprite(ResourceHelper.Sprites.Shop) :
                                                       pinSprite = ResourceHelper.FetchSpriteByPool(pinData.Pool);

            GameObject newPin = new GameObject("pin_rando");

            if (pinSprite.name.StartsWith("req"))
            {
                if (HelperGroup == null)
                {
                    HelperGroup = new GameObject("Resource Helpers");
                    HelperGroup.transform.SetParent(this.transform);
                    //default to off
                    HelperGroup.SetActive(false);
                }

                newPin.transform.SetParent(HelperGroup.transform);
            }
            else
            {
                if (MainGroup == null)
                {
                    MainGroup = new GameObject("Main Group");
                    MainGroup.transform.SetParent(this.transform);
                    //default to off
                    MainGroup.SetActive(false);
                }

                newPin.transform.SetParent(MainGroup.transform);
            }
            newPin.layer = 30;
            newPin.transform.localScale *= 1.2f;

            SpriteRenderer sr = newPin.AddComponent <SpriteRenderer>();

            sr.sprite           = pinSprite;
            sr.sortingLayerName = "HUD";
            sr.size             = new Vector2(1f, 1f);

            Vector3 vec = __GetRoomPos() + pinData.Offset;

            newPin.transform.localPosition = new Vector3(vec.x, vec.y, vec.z - 1f + (vec.y / 100) + (vec.x / 100));

            //Disable to avoid the Pin component's OnEnable before setting the pindata...
            //   Yay Constructorless Components...
            newPin.SetActive(false);

            Pin pinC = newPin.AddComponent <Pin>();

            pinC.SetPinData(pinData);

            //Don't worry about this one. It just does some totally normal non-spoilery things.
            newPin.AddComponent <BoringPinThing>();

            newPin.SetActive(true);

            _pins.Add(pinC);

            Vector3 __GetRoomPos()
            {
                //@@OPTIMIZE: Should be indexed or hard-coded but it runs once per game session. Small gain.
                Vector3 pos      = new Vector3(-30f, -30f, -0.5f);
                bool    exitLoop = false;

                for (int index1 = 0; index1 < gameMap.transform.childCount; ++index1)
                {
                    GameObject areaObj = gameMap.transform.GetChild(index1).gameObject;
                    for (int index2 = 0; index2 < areaObj.transform.childCount; ++index2)
                    {
                        GameObject roomObj = areaObj.transform.GetChild(index2).gameObject;
                        if (roomObj.name == roomName)
                        {
                            pos      = roomObj.transform.position;
                            exitLoop = true;
                            break;
                        }
                    }
                    if (exitLoop)
                    {
                        break;
                    }
                }

                return(pos);
            }
        }
        public Either <string, HelperData> parse(System.IO.StreamReader reader)
        {
            HelperData retVal = new HelperData();
            string     line;
            //Read until we see "RECHABLE ITEM LOCATIONS".
            Boolean sawReachableItemLocations = false;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals("REACHABLE ITEM LOCATIONS"))
                {
                    sawReachableItemLocations = true;
                    break;
                }
            }
            if (!sawReachableItemLocations)
            {
                return(new Either.Left <string, HelperData>("Expected to see 'RECHABLE ITEM LOCATIONS' but hit end of file."));
            }
            line = reader.ReadLine();
            if (!Regex.Match(line, @"There are [0-9]+ unchecked reachable locations.", RegexOptions.None).Success)
            {
                return(new Either.Left <string, HelperData>($"Expected to see 'There are N unchecked reachable locations.' but got {line}"));
            }
            line = reader.ReadLine();
            if (!"".Equals(line))
            {
                return(new Either.Left <string, HelperData>($"Expected a blank line but got {line}"));
            }
            Boolean      sawCheckedItemLocations = false;
            Location     currentLocation         = null;
            const string itemPrefix = " - ";

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals("CHECKED ITEM LOCATIONS"))
                {
                    sawCheckedItemLocations = true;
                    break;
                }
                else if (line.Equals(""))
                {
                    if (currentLocation != null)
                    {
                        try
                        {
                            retVal.reachable.Add(currentLocation.name, currentLocation);
                        } catch (ArgumentException e)
                        {
                            logger.Warn($"Ignoring duplicate entry for locationg {currentLocation.name} (old value = {retVal.reachable[currentLocation.name]}, new value = {currentLocation}) {e.ToString()}");
                        }
                    }
                    currentLocation = null;
                }
                else if (line.StartsWith(itemPrefix))
                {
                    currentLocation.items.Add(line.Substring(itemPrefix.Length));
                }
                else
                {
                    currentLocation = new Location(line);
                }
            }
            if (!sawCheckedItemLocations)
            {
                return(new Either.Left <string, HelperData>("Expected to see 'CHECKED ITEM LOCATIONS' but reached end of file."));
            }
            while ((line = reader.ReadLine()) != null)
            {
                if (Regex.Match(line, @"Generated helper log in [0-9.]+ seconds\.", RegexOptions.None).Success)
                {
                    break;
                }
                else if (line.Equals(""))
                {
                    if (currentLocation != null)
                    {
                        try
                        {
                            retVal.checkedd.Add(currentLocation.name, currentLocation);
                        } catch (ArgumentException e)
                        {
                            logger.Warn($"Ignoring duplicate entry for locationg {currentLocation.name} (old value = {retVal.reachable[currentLocation.name]}, new value = {currentLocation}) {e.ToString()}");
                        }
                    }
                    currentLocation = null;
                }
                else if (line.StartsWith(itemPrefix))
                {
                    currentLocation.items.Add(line.Substring(itemPrefix.Length));
                }
                else
                {
                    currentLocation = new Location(line);
                }
            }
            return(new Either.Right <string, HelperData>(retVal));
        }