public static Sprite Sprite(string pSpriteName)
        {
            if (pSprites != null && pSprites.TryGetValue(pSpriteName, out Sprite sprite))
            {
                return(sprite);
            }

            DebugLog.Error("Failed to load sprite named '" + pSpriteName + "'");
            return(null);
        }
Ejemplo n.º 2
0
        public static void Refresh()
        {
            //The Either Monad was pretty cool I admit, but I feel like it goes against .net stuff.
            //The "Right" side was unintended or unexpected behavior of the code, which is what Exceptions are for. Eek -CDpr
            try {
                using StreamReader file = new StreamReader(Path.Combine(Application.persistentDataPath, "RandomizerHelperLog.txt"));

                Data = _Parse(file);
            } catch (HelperLogException e) {
                DebugLog.Error($"Failed to parse HelperLogData: {e}", e);
            } catch (Exception e) {
                DebugLog.Critical($"Failed to parse HelperLog data for unknown reason: {e}", e);
            }
        }
        public Sprite Sprite(SpriteId pSpriteName)
        {
            if (pSprites.TryGetValue(pSpriteName, out Sprite sprite))
            {
                return(sprite);
            }

            logger.Error("Failed to load sprite named '" + pSpriteName + "'");
            return(null);
        }
        private static PinData.Types selectCheckType(string text)
        {
            //There used to be more of these things... This is probably useless now.
            switch (text)
            {
            case "sceneData":
                return(global::RandoMapMod.PinData.Types.SceneData);

            case "playerData.bool":
                return(global::RandoMapMod.PinData.Types.PlayerBool);

            default:
                DebugLog.Error("Error parsing Pin Check Type. '" + text + "'");
                return(global::RandoMapMod.PinData.Types.PlayerBool);
            }
        }
        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());
                    }
                }
            }
        internal static void Initialize()
        {
            Assembly theDLL = typeof(RandoMapMod).Assembly;

            pSprites = new Dictionary <string, 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);

                    pSprites.Add(
                        Path.GetFileNameWithoutExtension(resource.Replace("RandoMapMod.Resources.", string.Empty)),
                        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)) {
                            loadPinData(stream);
                        }
                    } catch (Exception e) {
                        DebugLog.Error("pindata.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
            }

            //Dev.Log("Initialize macros");
            Assembly randoDLL = typeof(RandomizerMod.RandomizerMod).Assembly;

            foreach (string resource in randoDLL.GetManifestResourceNames())
            {
                //Dev.Log("Macro 1");
                if (resource.EndsWith("items.xml"))
                {
                    try {
                        //Dev.Log("Item 1");
                        using (Stream stream = randoDLL.GetManifestResourceStream(resource)) {
                            XmlDocument xml = new XmlDocument();
                            xml.Load(stream);
                            //Dev.Log("Item 2");
                            loadItemData(xml.SelectNodes("randomizer/item"));
                            //Dev.Log("Item 3");
                            //loadMacroData( xml.SelectNodes( "randomizer/macro" ), xml.SelectNodes( "randomizer/additiveItemSet" ) );
                        }
                    } catch (Exception e) {
                        DebugLog.Error("items.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
                if (resource.EndsWith("macros.xml"))
                {
                    try
                    {
                        //Dev.Log("Macro 1");
                        using (Stream stream = randoDLL.GetManifestResourceStream(resource))
                        {
                            XmlDocument xml = new XmlDocument();
                            xml.Load(stream);
                            //Dev.Log("Macro 2");
                            //loadItemData(xml.SelectNodes("randomizer/item"));
                            loadMacroData(xml.SelectNodes("randomizer/macro"));
                            //Dev.Log("Macro 3");
                        }
                    }
                    catch (Exception e)
                    {
                        DebugLog.Error("macros.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
                //if (resource.EndsWith("waypoints.xml"))
                //{
                //    try
                //    {
                //        //Dev.Log("Macro 1");
                //        using (Stream stream = randoDLL.GetManifestResourceStream(resource))
                //        {
                //            XmlDocument xml = new XmlDocument();
                //            xml.Load(stream);
                //            //Dev.Log("Macro 2");
                //            //loadItemData(xml.SelectNodes("randomizer/item"));
                //            loadMacroWaypointData(xml.SelectNodes("randomizer/item"));
                //            //Dev.Log("Macro 3");
                //        }
                //    }
                //    catch (Exception e)
                //    {
                //        DebugLog.Error("waypoints.xml Load Failed!");
                //        DebugLog.Error(e.ToString());
                //    }
                //}
                if (resource.EndsWith("additive.xml"))
                {
                    try
                    {
                        //Dev.Log("Macro 1");
                        using (Stream stream = randoDLL.GetManifestResourceStream(resource))
                        {
                            XmlDocument xml = new XmlDocument();
                            xml.Load(stream);
                            //Dev.Log("Macro 2");
                            //loadItemData(xml.SelectNodes("randomizer/item"));
                            loadAdditiveMacroData(xml.SelectNodes("randomizer/additiveItemSet"));
                            //Dev.Log("Macro 3");
                        }
                    }
                    catch (Exception e)
                    {
                        DebugLog.Error("macros.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
            }
        }
        private static void loadPinData(Stream stream)
        {
            pPinData = new Dictionary <string, PinData>();

            XmlDocument xml = new XmlDocument();

            xml.Load(stream);
            foreach (XmlNode node in xml.SelectNodes("randomap/pin"))
            {
                PinData newPin = new PinData();
                newPin.ID = node.Attributes["name"].Value;
                //Dev.Log("Load Pin Data: " + newPin.ID);
                string line = "";

                foreach (XmlNode chld in node.ChildNodes)
                {
                    switch (chld.Name)
                    {
                    case "pinScene":
                        line           += ", pinScene = " + chld.InnerText;
                        newPin.PinScene = chld.InnerText;
                        break;

                    case "checkType":
                        line            += ", checkType = " + chld.InnerText;
                        newPin.CheckType = selectCheckType(chld.InnerText);
                        break;

                    case "checkBool":
                        line            += ", checkBool = " + chld.InnerText;
                        newPin.CheckBool = chld.InnerText;
                        break;

                    case "prereq":
                        line            += ", prereq = " + chld.InnerText;
                        newPin.PrereqRaw = chld.InnerText;
                        break;

                    case "offsetX":
                        line          += ", offsetX = " + chld.InnerText;
                        newPin.OffsetX = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetY":
                        line          += ", offsetY = " + chld.InnerText;
                        newPin.OffsetY = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetZ":
                        line          += ", offsetZ = " + chld.InnerText;
                        newPin.OffsetZ = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "hasPrereq":
                        line            += ", hasPrereq = " + chld.InnerText;
                        newPin.hasPrereq = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    case "isShop":
                        line         += ", isShop = " + chld.InnerText;
                        newPin.isShop = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    default:
                        DebugLog.Error("Pin '" + newPin.ID + "' in XML had node '" + chld.Name + "' not parsable!");
                        break;
                    }
                }

                pPinData.Add(newPin.ID, newPin);
                //Dev.Log(newPin.ID + " Pin added: " + pPinData.ContainsKey(newPin.ID));
            }
        }
        private static void loadItemData(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                string itemName = node.Attributes["name"].Value;
                if (!pPinData.ContainsKey(itemName))
                {
                    DebugLog.Error("Could not find item '" + itemName + "' in PinData Dict!");
                    continue;
                }

                PinData pinD = pPinData[itemName];
                foreach (XmlNode chld in node.ChildNodes)
                {
                    if (chld.Name == "sceneName")
                    {
                        pinD.SceneName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "objectName")
                    {
                        pinD.OriginalName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "itemLogic")
                    {
                        pinD.LogicRaw = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "boolName")
                    {
                        pinD.ObtainedBool = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "inChest")
                    {
                        pinD.InChest = true;
                        continue;
                    }

                    if (chld.Name == "newShiny")
                    {
                        pinD.NewShiny = true;
                        continue;
                    }

                    if (chld.Name == "x")
                    {
                        pinD.NewX = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "y")
                    {
                        pinD.NewY = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "pool")
                    {
                        pinD.Pool = chld.InnerText;
                        continue;
                    }
                }
            }
        }
        public static void Load(int saveSlot)
        {
            /*
             * GOOD LORD WHY REMOVE THE STRINGVALUES
             * foreach ( string val in RandomizerMod.RandomizerMod.Instance.Settings.StringValues.Values ) {
             *      if ( val.Contains( "newShinyName" ) ) {
             *              ObjectName newONC = JsonUtility.FromJson<ObjectName>( val );
             *              Add( newONC );
             *      }
             */
            dict = new Dictionary <string, string>();

            Platform.Current.ReadSaveSlot(saveSlot, (Action <byte[]>)(fileBytes =>
            {
                try {
                    SaveGameData data = JsonUtility.FromJson <SaveGameData>(!GameManager.instance.gameConfig.useSaveEncryption || Platform.Current.IsFileSystemProtected ? Encoding.UTF8.GetString(fileBytes) : Encryption.Decrypt((string)new BinaryFormatter().Deserialize((Stream) new MemoryStream(fileBytes))));
                    foreach (string key in data.modData["RandomizerMod"].StringValues.Keys)
                    {
                        JSONAction.Type type = JSONAction.Type.NONE;
                        type = getActionType(key);
                        if (type == JSONAction.Type.NONE)
                        {
                            continue;
                        }

                        string val            = data.modData["RandomizerMod"].StringValues[key];
                        JSONAction actionData = JsonUtility.FromJson <JSONAction>(val);
                        PinData pinD          = null;
                        string newName        = "";
                        switch (type)
                        {
                        case JSONAction.Type.AddShinyToChest:
                        case JSONAction.Type.ReplaceObjectWithShiny:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.OriginalName == actionData.objectName
                                ).FirstOrDefault();
                            newName = actionData.newShinyName;
                            break;

                        case JSONAction.Type.CreateNewShiny:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.NewX == (int)actionData.x &&
                                pins.NewY == (int)actionData.y &&
                                pins.NewShiny == true
                                ).FirstOrDefault();
                            newName = actionData.newShinyName;
                            break;

                        case JSONAction.Type.ChangeChestGeo:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.InChest == true
                                ).FirstOrDefault();
                            newName = actionData.objectName;
                            break;

                        case JSONAction.Type.NONE:
                        default:
                            DebugLog.Error("What the crap just happened...? This enum is weeeeird.");
                            break;
                        }
                        if (pinD != null && newName != "")
                        {
                            //DebugLog.Write( "ONC Added: Item '" + pinD.ID + "' ObjectName '" + newName + "' Type '" + type + "'" );
                            Add(pinD.ID, newName);
                        }
                    }
                } catch (Exception ex) {
                    DebugLog.Error("Error trying to MANUALLY FREAKING LOAD the save data");
                    DebugLog.Error(ex.ToString());
                }
            }));
        }