Exemplo n.º 1
0
        public bool LoadFromJson(JsonParser.ObjectValue jsonOb)
        {
            bool hasLoaded = false;

            try
            {
                HasDescriptionOverride = (JsonParser.BoolValue)jsonOb["hasName"];
                Description            = jsonOb["name"];

                string colorHex = "0x" + jsonOb["color"];
                Color  color    = Color.FromArgb(Convert.ToInt32(colorHex, 16));
                Pen = new Pen(color);

                Mode = (GameData.OverlaySettings.DisplayMode)((JsonParser.IntValue)jsonOb["mode"]).IntNumber;

                UseMatchType = (JsonParser.BoolValue)jsonOb["hasType"];
                MatchType    = UseMatchType ? (MemoryLayout.ActorType)((JsonParser.IntValue)jsonOb["matchType"]).IntNumber : 0;

                UseMatchNpcId = (JsonParser.BoolValue)jsonOb["hasNpcId"];
                MatchNpcId    = UseMatchNpcId ? (uint)((JsonParser.IntValue)jsonOb["matchNpcId"]).IntNumber : 0;

                hasLoaded = true;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Failed to load filter '" + jsonOb + "', exception:" + ex);
            }

            return(hasLoaded);
        }
Exemplo n.º 2
0
        private static MemoryPath CreateMemoryPath(JsonParser.ObjectValue jsonOb)
        {
            JsonParser.ArrayValue offsetsArr = (JsonParser.ArrayValue)jsonOb["offsets"];
            long[] offsetValues = new long[offsetsArr.entries.Count];
            for (int idx = 0; idx < offsetValues.Length; idx++)
            {
                JsonParser.IntValue intV = (JsonParser.IntValue)offsetsArr.entries[idx];
                offsetValues[idx] = intV;
            }

            string pathType = jsonOb["type"];

            if (pathType == "sig")
            {
                string pattern = jsonOb["sig"];
                return(new MemoryPathSignature(pattern, offsetValues));
            }
            else if (pathType == "fixed")
            {
                string pattern           = jsonOb["fixed"];
                long[] offsetValuesFixed = new long[offsetValues.Length + 1];
                offsetValuesFixed[0] = Convert.ToInt64(pattern, 16);

                for (int idx = 0; idx < offsetValues.Length; idx++)
                {
                    offsetValuesFixed[idx + 1] = offsetValues[idx];
                }

                return(new MemoryPath(offsetValuesFixed));
            }

            return(null);
        }
Exemplo n.º 3
0
        private static void UpdateMemoryLayout(JsonParser.ArrayValue jsonArr, Type structType)
        {
            List <Tuple <string, int> > layoutArr = new List <Tuple <string, int> >();

            for (int idx = 0; idx < jsonArr.entries.Count; idx++)
            {
                JsonParser.ObjectValue fieldOb = (JsonParser.ObjectValue)jsonArr.entries[idx];
                JsonParser.StringValue idV     = (JsonParser.StringValue)fieldOb["id"];
                JsonParser.IntValue    valueV  = (JsonParser.IntValue)fieldOb["v"];

                layoutArr.Add(new Tuple <string, int>(idV, valueV));
            }

            FieldInfo[] fields = structType.GetFields(BindingFlags.Public | BindingFlags.Static);
            foreach (FieldInfo prop in fields)
            {
                for (int idx = 0; idx < layoutArr.Count; idx++)
                {
                    if (prop.Name.Equals(layoutArr[idx].Item1, StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(null, layoutArr[idx].Item2);
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public bool LoadFromJson(JsonParser.ObjectValue jsonOb)
        {
            bool hasLoaded = false;

            try
            {
                Name             = jsonOb["name"];
                ShowOnlyMatching = (JsonParser.BoolValue)jsonOb["onlyMatching"];

                version = jsonOb.entries.ContainsKey("ver") ? (JsonParser.IntValue)jsonOb["ver"] : 1;

                JsonParser.ArrayValue arrFilters = (JsonParser.ArrayValue)jsonOb["filters"];
                foreach (JsonParser.Value v in arrFilters.entries)
                {
                    JsonParser.ObjectValue filterJsonOb = (JsonParser.ObjectValue)v;
                    ActorFilter            filterOb     = new ActorFilter();

                    bool loadedFilter = filterOb.LoadFromJson(filterJsonOb);
                    if (loadedFilter)
                    {
                        Filters.Add(filterOb);
                    }
                }

                hasLoaded = true;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Failed to load preset '" + jsonOb + "', exception:" + ex);
            }

            return(hasLoaded);
        }
Exemplo n.º 5
0
        public void Load()
        {
            string FilePath = CreateFilePath(DBPath);

            if (File.Exists(FilePath))
            {
                try
                {
                    using (StreamReader file = new StreamReader(FilePath))
                    {
                        string fileContent = file.ReadToEnd();
                        file.Close();

                        JsonParser.ObjectValue rootOb = JsonParser.ParseJson(fileContent);
                        LoadFromJson(rootOb);
                    }
                }
                catch (Exception) { }
            }

            if (Presets.Count == 0)
            {
                CreateDefaultPreset();
            }
        }
Exemplo n.º 6
0
        private bool LoadFromJson(JsonParser.ObjectValue jsonOb)
        {
            bool hasLoaded = false;

            try
            {
                FontSize = (JsonParser.FloatValue)jsonOb["fontSize"];
                MaxDistanceFromCenter = (JsonParser.FloatValue)jsonOb["maxCenterDist"];
                MaxDistanceFromCamera = (JsonParser.FloatValue)jsonOb["maxCameraDist"];

                FilterNearbyActors = jsonOb.entries.ContainsKey("filterNearby") ? (JsonParser.BoolValue)jsonOb["filterNearby"] : false;

                JsonParser.ArrayValue arrPresets = (JsonParser.ArrayValue)jsonOb["presets"];
                foreach (JsonParser.Value v in arrPresets.entries)
                {
                    JsonParser.ObjectValue presetJsonOb = (JsonParser.ObjectValue)v;
                    ActorFilterPreset      presetOb     = new ActorFilterPreset();

                    bool loadedPreset = presetOb.LoadFromJson(presetJsonOb);
                    if (loadedPreset)
                    {
                        Presets.Add(presetOb);
                    }
                }

                hasLoaded = true;
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Failed to load settings, exception:" + ex);
            }

            return(hasLoaded);
        }
Exemplo n.º 7
0
        public static bool DownloadAndUpdateLayout(out string statusMsg)
        {
            bool result = false;

            try
            {
                string jsonContent = DownloadLayoutFile("signatures.json");
                statusMsg = "downloaded memory layout";

                JsonParser.ObjectValue jsonOb     = JsonParser.ParseJson(jsonContent);
                JsonParser.ArrayValue  entriesArr = (JsonParser.ArrayValue)jsonOb["layout"];
                for (int idx = 0; idx < entriesArr.entries.Count; idx++)
                {
                    JsonParser.ObjectValue entryOb = (JsonParser.ObjectValue)entriesArr.entries[idx];
                    string typeStr = entryOb["id"];
                    if (typeStr == "actors")
                    {
                        MemoryLayout.memPathActors = CreateMemoryPath(entryOb);
                        UpdateMemoryLayout((JsonParser.ArrayValue)entryOb["fields"], typeof(MemoryLayout.ActorConsts));
                    }
                    else if (typeStr == "target")
                    {
                        MemoryLayout.memPathTarget = CreateMemoryPath(entryOb);
                        UpdateMemoryLayout((JsonParser.ArrayValue)entryOb["fields"], typeof(MemoryLayout.TargetConsts));
                    }
                    else if (typeStr == "camera")
                    {
                        MemoryLayout.memPathCamera = CreateMemoryPath(entryOb);
                        UpdateMemoryLayout((JsonParser.ArrayValue)entryOb["fields"], typeof(MemoryLayout.CameraConsts));
                    }
                    else
                    {
                        throw new Exception("Unexpected type: " + typeStr + " in entry " + idx);
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                statusMsg = "failed! " + ex;
            }

            return(result);
        }
Exemplo n.º 8
0
        private void MergeOnlinePresets(List <string> onlinePresets)
        {
            PlayerSettings settings   = PlayerSettings.Get();
            bool           hasChanges = false;

            for (int importIdx = 0; importIdx < onlinePresets.Count; importIdx++)
            {
                ActorFilterPreset testPreset = new ActorFilterPreset();
                bool isValid = false;
                try
                {
                    JsonParser.ObjectValue rootOb = JsonParser.ParseJson(onlinePresets[importIdx]);
                    isValid = testPreset.LoadFromJson(rootOb);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Failed to merge synced preset #" + importIdx + ": " + ex);
                }

                if (isValid)
                {
                    ActorFilterPreset existingPreset = settings.Presets.Find(x => x.Name == testPreset.Name);
                    if (existingPreset != null && existingPreset.version >= testPreset.version)
                    {
                        Logger.WriteLine("Ignoring online preset #" + importIdx + ": " + testPreset.Name + " (v" + testPreset.version + ") => local version: " + existingPreset.version);
                        continue;
                    }

                    if (existingPreset != null)
                    {
                        settings.Presets.Remove(existingPreset);
                    }

                    Logger.WriteLine("Using online preset #" + importIdx + ": " + testPreset.Name + " (v" + testPreset.version + ")");
                    settings.Presets.Add(testPreset);
                    hasChanges = true;
                }
            }

            if (hasChanges)
            {
                UpdatePresetList();
            }
        }
Exemplo n.º 9
0
        private void buttonImportPreset_Click(object sender, EventArgs e)
        {
            ActorFilterPreset loadedPreset = null;

            string importText = Clipboard.GetText();

            if (!string.IsNullOrEmpty(importText) && importText.Length > 2 && importText[0] == '{')
            {
                ActorFilterPreset preset = new ActorFilterPreset();
                try
                {
                    JsonParser.ObjectValue jsonOb = JsonParser.ParseJson(importText);
                    bool hasLoaded = preset.LoadFromJson(jsonOb);
                    if (hasLoaded)
                    {
                        loadedPreset = preset;
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Import failed text:'" + importText + "', exception:" + ex);
                }
            }

            if (loadedPreset != null)
            {
                PlayerSettings    settings       = PlayerSettings.Get();
                ActorFilterPreset existingPreset = settings.Presets.Find(x => (x.Name == loadedPreset.Name));
                bool bCanAdd = false;

                if (existingPreset != null)
                {
                    DialogResult dr = MessageBox.Show("Preset '" + existingPreset.Name + "' already exists, do you want to merge it?", Text, MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Yes)
                    {
                        // merge
                        existingPreset.Filters.AddRange(loadedPreset.Filters);
                    }
                    else if (dr == DialogResult.No)
                    {
                        // keep separate, create new name

                        string UseName = existingPreset.Name;
                        int    sepIdx  = UseName.LastIndexOf('#');
                        if (sepIdx > 0)
                        {
                            UseName = UseName.Substring(0, sepIdx);
                        }

                        for (int Idx = 2; Idx < 10000; Idx++)
                        {
                            string UniqueName    = UseName + "#" + Idx;
                            bool   alreadyExists = settings.Presets.Find(x => (x.Name == UniqueName)) != null;
                            if (!alreadyExists)
                            {
                                loadedPreset.Name = UniqueName;
                                bCanAdd           = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    bCanAdd = true;
                }

                if (bCanAdd)
                {
                    settings.Presets.Add(loadedPreset);

                    ListViewItem lvi = new ListViewItem(loadedPreset.Name);
                    lvi.Tag = loadedPreset;
                    listViewPresetManage.Items.Add(lvi);

                    int itemIdx = comboBoxPreset.Items.Add(loadedPreset);
                    comboBoxPreset.SelectedIndex = itemIdx;
                }
            }
        }