コード例 #1
0
ファイル: cellDat.cs プロジェクト: bDekaru/Melt
        public void loadFromDat(cDatFile datFile)
        {
            Console.WriteLine("Reading map from dat file...");
            Stopwatch timer = new Stopwatch();

            timer.Start();

            int landBlockCounter     = 0;
            int landBlockInfoCounter = 0;

            foreach (KeyValuePair <uint, cDatFileEntry> entry in datFile.fileCache)
            {
                if ((entry.Value.fileId & 0x0000FFFF) == 0x0000FFFF)
                {
                    uint           x            = (uint)entry.Value.fileId >> 24;
                    uint           y            = (uint)(entry.Value.fileId & 0x00FF0000) >> 16;
                    cCellLandblock newLandblock = new cCellLandblock(entry.Value);
                    surfaceLandblocks[(int)x].Add((int)y, newLandblock);
                    landBlockCounter++;
                }
                else if ((entry.Value.fileId & 0x0000FFFE) == 0x0000FFFE)
                {
                    uint           x = (uint)entry.Value.fileId >> 24;
                    uint           y = (uint)(entry.Value.fileId & 0x00FF0000) >> 16;
                    cLandblockInfo newLandblockInfo = new cLandblockInfo(entry.Value);
                    landblockInfo[(int)x].Add((int)y, newLandblockInfo);
                    landBlockInfoCounter++;
                }
            }

            timer.Stop();
            Console.WriteLine("{0} landblocks and {1} landblockInfos read in {2} seconds.", landBlockCounter, landBlockInfoCounter, timer.ElapsedMilliseconds / 1000f);
        }
コード例 #2
0
ファイル: datFileUtilities.cs プロジェクト: bDekaru/Melt
        private bool compareLandblockInfo(cLandblockInfo thisLandblockInfo, cLandblockInfo otherLandblockInfo)
        {
            if (thisLandblockInfo.Id != otherLandblockInfo.Id)
            {
                return(false);
            }
            if (thisLandblockInfo.NumCells != otherLandblockInfo.NumCells)
            {
                return(false);
            }

            if (thisLandblockInfo.Objects.Count != otherLandblockInfo.Objects.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisLandblockInfo.Objects.Count; i++)
            {
                cStab thisStab  = thisLandblockInfo.Objects[i];
                cStab otherStab = otherLandblockInfo.Objects[i];
                //if (thisStab.id == otherStab.id) // this is what we're migrating
                //    return false;

                if (thisStab.frame.angles.x != otherStab.frame.angles.x)
                {
                    return(false);
                }
                if (thisStab.frame.angles.y != otherStab.frame.angles.y)
                {
                    return(false);
                }
                if (thisStab.frame.angles.z != otherStab.frame.angles.z)
                {
                    return(false);
                }
                if (thisStab.frame.angles.w != otherStab.frame.angles.w)
                {
                    return(false);
                }

                if (thisStab.frame.origin.x != otherStab.frame.origin.x)
                {
                    return(false);
                }
                if (thisStab.frame.origin.y != otherStab.frame.origin.y)
                {
                    return(false);
                }
                if (thisStab.frame.origin.z != otherStab.frame.origin.z)
                {
                    return(false);
                }
            }
            if (thisLandblockInfo.buildingFlags != otherLandblockInfo.buildingFlags)
            {
                return(false);
            }

            if (thisLandblockInfo.Buildings.Count != otherLandblockInfo.Buildings.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisLandblockInfo.Buildings.Count; i++)
            {
                //ignoring for now
            }

            if (thisLandblockInfo.RestrictionTables.Count != otherLandblockInfo.RestrictionTables.Count)
            {
                return(false);
            }
            for (int i = 0; i < thisLandblockInfo.RestrictionTables.Count; i++)
            {
                ///ignoring for now
            }
            if (thisLandblockInfo.totalObjects != otherLandblockInfo.totalObjects)
            {
                return(false);
            }
            if (thisLandblockInfo.bucketSize != otherLandblockInfo.bucketSize)
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
ファイル: datFileUtilities.cs プロジェクト: bDekaru/Melt
        public void exportCellJson(string outputPath)
        {
            Console.WriteLine("Writing cell.dat to json files...");
            Stopwatch timer = new Stopwatch();

            timer.Start();

            cellLandblockList = new List <cCellLandblock>();
            landblockInfoList = new List <cLandblockInfo>();
            envCellList       = new List <cEnvCell>();

            Console.WriteLine("Preparing files...");
            foreach (KeyValuePair <uint, cDatFileEntry> entry in fileCache)
            {
                if ((entry.Value.fileId & 0x0000FFFF) == 0x0000FFFF) //surface
                {
                    //StreamReader reader = new StreamReader(entry.Value.fileContent);
                    //cCellLandblock thisLandblock = new cCellLandblock(reader);

                    //cellLandblockList.Add(thisLandblock);
                }
                else if ((entry.Value.fileId & 0x0000FFFE) == 0x0000FFFE) //surface objects
                {
                    if ((entry.Value.fileId >> 16) != 0xC6A9)             //arwic
                    {
                        continue;
                    }

                    cLandblockInfo thisLandblockInfo = new cLandblockInfo(entry.Value);

                    landblockInfoList.Add(thisLandblockInfo);
                }
                else //dungeons and interiors
                {
                    if ((entry.Value.fileId >> 16) != 0xC6A9)//arwic
                    {
                        continue;
                    }

                    cEnvCell thisEnvCell = new cEnvCell(entry.Value);

                    envCellList.Add(thisEnvCell);
                }
            }

            JsonSerializerSettings settings = new JsonSerializerSettings();

            //settings.TypeNameHandling = TypeNameHandling.Auto;
            //settings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple;
            //settings.DefaultValueHandling = DefaultValueHandling.Ignore;

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            //Console.WriteLine("Exporting landblocks...");
            //foreach (cCellLandblock entry in cellLandblockList)
            //{
            //    string outputFilename = Path.Combine(outputPath, (entry.Id >> 16).ToString("x4"));
            //    if (!Directory.Exists(outputFilename))
            //        Directory.CreateDirectory(outputFilename);
            //    outputFilename = Path.Combine(outputFilename, $"{entry.Id.ToString("x8")}.json");

            //    StreamWriter outputFile = new StreamWriter(new FileStream(outputFilename, FileMode.Create, FileAccess.Write));

            //    string jsonString = JsonConvert.SerializeObject(entry, Formatting.Indented, settings);
            //    outputFile.Write(jsonString);
            //    outputFile.Close();
            //}

            Console.WriteLine("Exporting landblock info...");
            foreach (cLandblockInfo entry in landblockInfoList)
            {
                string outputFilename = Path.Combine(outputPath, (entry.Id >> 16).ToString("x4"));
                if (!Directory.Exists(outputFilename))
                {
                    Directory.CreateDirectory(outputFilename);
                }
                outputFilename = Path.Combine(outputFilename, $"{entry.Id.ToString("x8")}.json");

                StreamWriter outputFile = new StreamWriter(new FileStream(outputFilename, FileMode.Create, FileAccess.Write));

                string jsonString = JsonConvert.SerializeObject(entry, Formatting.Indented, settings);
                outputFile.Write(jsonString);
                outputFile.Close();
            }

            Console.WriteLine("Exporting envCells...");
            foreach (cEnvCell entry in envCellList)
            {
                string outputFilename = Path.Combine(outputPath, (entry.Id >> 16).ToString("x4"));
                if (!Directory.Exists(outputFilename))
                {
                    Directory.CreateDirectory(outputFilename);
                }
                outputFilename = Path.Combine(outputFilename, $"{entry.Id.ToString("x8")}.json");

                StreamWriter outputFile = new StreamWriter(new FileStream(outputFilename, FileMode.Create, FileAccess.Write));

                string jsonString = JsonConvert.SerializeObject(entry, Formatting.Indented, settings);
                outputFile.Write(jsonString);
                outputFile.Close();
            }

            timer.Stop();
            Console.WriteLine("Finished in {0} seconds.", timer.ElapsedMilliseconds / 1000f);
        }
コード例 #4
0
ファイル: datFileUtilities.cs プロジェクト: bDekaru/Melt
        public void buildObjectIdMigrationTable(cDatFile otherDat)
        {
            Dictionary <uint, cLandblockInfo> thisLandblockInfoMap  = new Dictionary <uint, cLandblockInfo>();
            Dictionary <uint, cLandblockInfo> otherLandblockInfoMap = new Dictionary <uint, cLandblockInfo>();

            Dictionary <uint, cEnvCell>   thisEnvCells     = new Dictionary <uint, cEnvCell>();
            Dictionary <uint, cEnvCell>   otherEnvCells    = new Dictionary <uint, cEnvCell>();
            SortedDictionary <uint, uint> idMigrationTable = new SortedDictionary <uint, uint>();

            SortedDictionary <uint, cAmbiguousUintValues> ambiguousList = new SortedDictionary <uint, cAmbiguousUintValues>();

            List <uint> allOldIds = new List <uint>();
            SortedDictionary <uint, uint> missingList = new SortedDictionary <uint, uint>();

            foreach (KeyValuePair <uint, cDatFileEntry> entry in fileCache)
            {
                if ((entry.Value.fileId & 0x0000FFFF) == 0x0000FFFF) //surface
                {
                }
                else if ((entry.Value.fileId & 0x0000FFFE) == 0x0000FFFE) //surface objects
                {
                    cLandblockInfo thisLandblockInfo = new cLandblockInfo(entry.Value);

                    thisLandblockInfoMap.Add(entry.Value.fileId, thisLandblockInfo);
                }
                else //dungeons and interiors
                {
                    cEnvCell thisEnvCell = new cEnvCell(entry.Value);

                    thisEnvCells.Add(entry.Value.fileId, thisEnvCell);
                }
            }

            foreach (KeyValuePair <uint, cDatFileEntry> entry in otherDat.fileCache)
            {
                if ((entry.Value.fileId & 0x0000FFFF) == 0x0000FFFF) //surface
                {
                }
                else if ((entry.Value.fileId & 0x0000FFFE) == 0x0000FFFE) //surface objects
                {
                    cLandblockInfo otherLandlockInfo = new cLandblockInfo(entry.Value);

                    otherLandblockInfoMap.Add(entry.Value.fileId, otherLandlockInfo);
                }
                else //dungeons and interiors
                {
                    cEnvCell otherEnvCell = new cEnvCell(entry.Value, false);

                    otherEnvCells.Add(entry.Value.fileId, otherEnvCell);
                }
            }

            foreach (KeyValuePair <uint, cLandblockInfo> entry in otherLandblockInfoMap)
            {
                cLandblockInfo thisLandblockInfo;
                cLandblockInfo otherLandblockInfo = entry.Value;

                if (!thisLandblockInfoMap.TryGetValue(otherLandblockInfo.Id, out thisLandblockInfo))
                {
                    continue;
                }

                for (int i = 0; i < otherLandblockInfo.Objects.Count; i++)
                {
                    uint oldId = otherLandblockInfo.Objects[i].id;
                    if (!allOldIds.Contains(oldId))
                    {
                        allOldIds.Add(oldId);
                    }
                }

                if (compareLandblockInfo(thisLandblockInfo, otherLandblockInfo))
                {
                    for (int i = 0; i < otherLandblockInfo.Objects.Count; i++)
                    {
                        uint oldId = otherLandblockInfo.Objects[i].id;
                        uint newId = thisLandblockInfo.Objects[i].id;

                        uint currentId = 0;

                        if (!idMigrationTable.TryGetValue(oldId, out currentId))
                        {
                            idMigrationTable.Add(oldId, newId);
                        }
                        else
                        {
                            if (newId != currentId)
                            {
                                cAmbiguousUintValues ambiguousId;
                                if (!ambiguousList.TryGetValue(oldId, out ambiguousId))
                                {
                                    ambiguousId                 = new cAmbiguousUintValues();
                                    ambiguousId.newId           = currentId;
                                    ambiguousId.alternateNewIds = new List <uint>();
                                    ambiguousList.Add(oldId, ambiguousId);
                                    ambiguousId.alternateNewIds.Add(newId);
                                }
                                else
                                {
                                    if (!ambiguousId.alternateNewIds.Contains(newId))
                                    {
                                        ambiguousId.alternateNewIds.Add(newId);
                                    }
                                }
                                //throw new Exception("ambiguous texture id migration");
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair <uint, cEnvCell> entry in otherEnvCells)
            {
                cEnvCell thisEnvCell;
                cEnvCell otherEnvCell = entry.Value;

                if (!thisEnvCells.TryGetValue(otherEnvCell.Id, out thisEnvCell))
                {
                    continue;
                }

                for (int i = 0; i < otherEnvCell.Stabs.Count; i++)
                {
                    uint oldId = otherEnvCell.Stabs[i].id;
                    if (!allOldIds.Contains(oldId))
                    {
                        allOldIds.Add(oldId);
                    }
                }

                if (compareEnvCells(thisEnvCell, otherEnvCell, true))
                {
                    for (int i = 0; i < otherEnvCell.Stabs.Count; i++)
                    {
                        uint oldId = otherEnvCell.Stabs[i].id;
                        uint newId = thisEnvCell.Stabs[i].id;

                        uint currentId = 0;

                        if (!idMigrationTable.TryGetValue(oldId, out currentId))
                        {
                            idMigrationTable.Add(oldId, newId);
                        }
                        else
                        {
                            if (newId != currentId)
                            {
                                cAmbiguousUintValues ambiguousId;
                                if (!ambiguousList.TryGetValue(oldId, out ambiguousId))
                                {
                                    ambiguousId                 = new cAmbiguousUintValues();
                                    ambiguousId.newId           = currentId;
                                    ambiguousId.alternateNewIds = new List <uint>();
                                    ambiguousList.Add(oldId, ambiguousId);
                                    ambiguousId.alternateNewIds.Add(newId);
                                }
                                else
                                {
                                    if (!ambiguousId.alternateNewIds.Contains(newId))
                                    {
                                        ambiguousId.alternateNewIds.Add(newId);
                                    }
                                }
                                //throw new Exception("ambiguous texture id migration");
                            }
                        }
                    }
                }
            }

            foreach (uint entry in allOldIds)
            {
                if (!idMigrationTable.ContainsKey(entry))
                {
                    missingList.Add(entry, entry);
                }
            }

            StreamWriter outputFile = new StreamWriter(new FileStream("objectIdMigrationTable.txt", FileMode.Create, FileAccess.Write));

            foreach (KeyValuePair <uint, uint> entry in idMigrationTable)
            {
                if (entry.Key == entry.Value)
                {
                    continue;
                }
                outputFile.WriteLine($"{entry.Key.ToString("x8")} {entry.Value.ToString("x8")}");
                outputFile.Flush();
            }
            outputFile.Close();

            outputFile = new StreamWriter(new FileStream("objectIdMigrationMissingConversions.txt", FileMode.Create, FileAccess.Write));
            foreach (KeyValuePair <uint, uint> entry in missingList)
            {
                outputFile.WriteLine(entry.Key.ToString("x8"));
                outputFile.Flush();
            }
            outputFile.Close();

            outputFile = new StreamWriter(new FileStream("objectIdMigrationTableAmbiguous.txt", FileMode.Create, FileAccess.Write));
            foreach (KeyValuePair <uint, cAmbiguousUintValues> entry in ambiguousList)
            {
                outputFile.Write($"{entry.Key.ToString("x8")} {entry.Value.newId.ToString("x8")}");
                bool first = true;
                foreach (uint value in entry.Value.alternateNewIds)
                {
                    if (first)
                    {
                        outputFile.Write("(");
                        first = false;
                    }
                    else
                    {
                        outputFile.Write(", ");
                    }
                    outputFile.Write(value.ToString("x8"));
                    outputFile.Flush();
                }
                outputFile.WriteLine(")");

                outputFile.Flush();
            }
            outputFile.Close();
        }