Пример #1
0
        public bool Init(string levelFilename, ConvertSettings settings, Action <string> log, ConvertStats stats, List <object[]> cmds)
        {
            this.settings = settings;
            this.log      = log;
            this.stats    = stats;

            if (settings.defaultProbeRemove)
            {
                foreach (var cmd in cmds)
                {
                    if ((VT)cmd[0] == VT.CmdGameObjectAddComponent && (string)cmd[3] == "ReflectionProbe")
                    {
                        RemoveObj.Add((Guid)cmd[1]);
                    }
                }
            }
            if (settings.boxLavaNormalProbe)
            {
                foreach (var cmd in cmds)
                {
                    if ((VT)cmd[0] == VT.CmdGetComponentAtRuntime)
                    {
                        compObj.Add((Guid)cmd[4], (Guid)cmd[3]);
                    }
                    else if ((VT)cmd[0] == VT.CmdGameObjectAddComponent)
                    {
                        compObj.Add((Guid)cmd[2], (Guid)cmd[1]);
                    }
                    else if ((VT)cmd[0] == VT.CmdGameObjectSetComponentProperty &&
                             (string)cmd[2] == "m_size" &&
                             cmd[5] is object[] val &&
                             (VT)val[0] == VT.Vector3b &&
                             compObj.TryGetValue((Guid)cmd[1], out Guid obj) &&
                             !objSize.ContainsKey(obj))
                    {
                        objSize.Add(obj, new Vector3()
                        {
                            x = (float)val[1], y = (float)val[2], z = (float)val[3]
                        });
                    }
                    else if ((VT)cmd[0] == VT.CmdGameObjectSetComponentProperty &&
                             (string)cmd[2] == "m_repeat_delay" &&
                             cmd[5] is float val2 &&
                             compObj.TryGetValue((Guid)cmd[1], out Guid obj2) &&
                             !objRptDelay.ContainsKey(obj2))
                    {
                        objRptDelay.Add(obj2, (int)val2);
                    }
Пример #2
0
        public bool Init(string levelFilename, ConvertSettings settings, Action <string> log, ConvertStats stats, List <object[]> cmds)
        {
            this.settings = settings;
            this.log      = log;
            this.stats    = stats;

            foreach (var cmd in cmds)
            {
                if ((VT)cmd[0] == VT.CmdMaterialSetTexture &&
                    (string)cmd[2] == "_MainTex")
                {
                    texMatIds.Add((Guid)cmd[3], (Guid)cmd[1]);
                }
            }

            return(true);
        }
Пример #3
0
 private void Convert(string filename, ConvertSettings settings)
 {
     converting = true;
     this.Dispatcher.Invoke(() => ConvertBtn.IsEnabled = false);
     try
     {
         var stats = LevelConvert.Convert(filename, settings, (cmsg) => AddMessage(cmsg));
         var msg   = "Converted " + filename + " changed " + stats.convertedTextures + " of " + stats.totalTextures + " textures";
         var emsg  = new List <string>();
         if (stats.builtInTextures != 0)
         {
             emsg.Add(stats.builtInTextures + " built-in");
         }
         if (stats.missingTextures != 0)
         {
             emsg.Add(stats.missingTextures + " missing");
         }
         if (stats.alreadyTextures != 0)
         {
             emsg.Add(stats.alreadyTextures + " already converted");
         }
         if (emsg.Count != 0)
         {
             msg += " (" + String.Join(", ", emsg.ToArray()) + ")";
         }
         if (stats.convertedEntities != 0)
         {
             msg += ", changed " + stats.convertedEntities + " entities";
         }
         AddMessage(msg);
         this.Dispatcher.Invoke(() => { if (DoneBeep.IsChecked == true)
                                        {
                                            SystemSounds.Beep.Play();
                                        }
                                });
     }
     catch (Exception ex)
     {
         AddMessage("Convert failed: " + ex.Message);
     }
     finally
     {
         converting = false;
         this.Dispatcher.Invoke(() => ConvertBtn.IsEnabled = true);
     }
 }
Пример #4
0
        public bool Init(string levelFilename, ConvertSettings settings, Action <string> log, ConvertStats stats, List <object[]> cmds)
        {
            this.settings = settings;
            this.log      = log;
            this.stats    = stats;

            var compObj = new Dictionary <Guid, Guid>();

            foreach (var cmd in cmds)
            {
                if ((VT)cmd[0] == VT.CmdGetComponentAtRuntime)
                {
                    compObj.Add((Guid)cmd[4], (Guid)cmd[3]);
                }
                else if ((VT)cmd[0] == VT.CmdGameObjectSetComponentProperty &&
                         (string)cmd[2] == "m_index" &&
                         cmd[5] is int &&
                         compObj.TryGetValue((Guid)cmd[1], out Guid obj))
                {
                    objIdx.Add(obj, (int)cmd[5]);
                }
            }
            return(true);
        }
Пример #5
0
 public void Init(ConvertSettings settings)
 {
     this.settings = settings;
 }
Пример #6
0
        private void ConvertCurrent(bool isAuto)
        {
            AddMessage(null);
            string filename = LvlFile.Text;

            if (Directory.Exists(filename))
            {
                AddMessage("Error: " + filename + " is a directory. Specify a single level file");
                return;
            }
            AddMessage((isAuto ? "Auto converting " : "Converting ") + filename);

            var dirs       = new List <string>();
            var ignoreDirs = new List <string>();

            string editorDir = EditorDir.Text;

            if (!editorDir.Equals(""))
            {
                if (!Directory.Exists(editorDir))
                {
                    AddMessage("Warning: ignoring non-existing level editor directory " + editorDir);
                }
                else
                {
                    foreach (var name in new string[] { "LevelTextures", "DecalTextures" })
                    {
                        string subdir = editorDir + @"\" + name;
                        if (Directory.Exists(subdir))
                        {
                            ignoreDirs.Add(subdir);
                        }
                    }
                }
            }

            for (int i = 1; i <= texDirCount; i++)
            {
                TextBox dir = (TextBox)this.FindName(String.Format("TexDir{0}", i));
                string  val = dir.Text;
                if (!val.Equals(""))
                {
                    if (!Directory.Exists(val))
                    {
                        AddMessage("Warning: ignoring non-existing directory " + val);
                        continue;
                    }
                    dirs.Add(val);
                }
            }

            int texPointPx = 0;

            Int32.TryParse(TexPointPx.Text, out texPointPx);

            ConvertSettings settings = new ConvertSettings()
            {
                texDirs       = dirs,
                ignoreTexDirs = ignoreDirs,
                texPointPx    = texPointPx
            };

            settings.defaultProbeHide   = DefaultProbes_ForceOn.IsChecked.Value;
            settings.defaultProbeRemove = DefaultProbes_Remove.IsChecked.Value;
            settings.boxLavaNormalProbe = BoxLavaNormalProbe.IsChecked.Value;
            settings.probeRes           = 256;
            foreach (var res in resArray)
            {
                if (((RadioButton)FindName("ProbeRes_" + res)).IsChecked.Value)
                {
                    settings.probeRes = res;
                }
            }

            var paths   = BundlesGet();
            var dupMats = new Dictionary <string, List <ConvertBundle> >(StringComparer.OrdinalIgnoreCase);
            var dupGOs  = new Dictionary <string, List <ConvertBundle> >(StringComparer.OrdinalIgnoreCase);

            foreach (var path in paths)
            {
                BundleInfo info;
                try
                {
                    info = bundleFiles.CachedBundleInfo(path);
                }
                catch (Exception ex)
                {
                    AddMessage("Error: cannot read bundle file: " + MsgAddFilename(ex.Message, paths.Count == 1 ? null : path));
                    return;
                }

                var f       = new DirectoryInfo(path);
                var convBun = new ConvertBundle()
                {
                    Name        = f.Name,
                    OS          = f.Parent.Name,
                    Dir         = f.Parent.Parent.Name,
                    Materials   = info.materials,
                    GameObjects = info.gameObjects
                };
                settings.bundles.Add(convBun);
                foreach (var mat in convBun.Materials)
                {
                    DictListAdd(dupMats, mat.Key, convBun);
                }
                foreach (var go in convBun.GameObjects)
                {
                    DictListAdd(dupGOs, go, convBun);
                }

                var parts = new List <string>();
                int n;
                if (convBun.Materials != null && (n = convBun.Materials.Count) != 0)
                {
                    parts.Add(FmtCount(n, "material", "materials") +
                              " (" + string.Join(", ", convBun.Materials.Keys.Take(5)) + (n > 5 ? ", ..." : "") + ")");
                }
                if (convBun.GameObjects != null && (n = convBun.GameObjects.Count) != 0)
                {
                    parts.Add(FmtCount(n, "entity", "entities"));
                }
                AddMessage("Using bundle " + convBun.BundleName +
                           (parts.Count != 0 ? ": " + String.Join(", ", parts) : ", but no materials or entities found!"));

                string levelDir       = new DirectoryInfo(filename).Parent.FullName;
                var    bundleLevelDir = f.Parent?.Parent?.Parent;
                if (bundleLevelDir == null || !bundleLevelDir.FullName.Equals(levelDir, StringComparison.OrdinalIgnoreCase))
                {
                    AddMessage("Warning: the bundle file is not in correct subdirectory of the level file!");
                    AddMessage("The bundle file must be at " + Path.Combine(levelDir, convBun.BundleName));
                }
            }
            ShowDups(dupMats, "material", "materials");
            ShowDups(dupGOs, "entity", "entities");

            new Task(() => Convert(filename, settings)).Start();
        }