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());
                }
            }));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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("rocks.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("rocks.xml Load Failed!");
                        DebugLog.Error(e.ToString());
                    }
                }
                if (resource.EndsWith("soul_lore.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("soul_lore.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());
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        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;
                    }
                }
            }
        }