Пример #1
0
    // Terrain Texture Parser //
    private static void ParseADT_Tex(string Path, string MapName, Vector2 coords)
    {
        StreamTools s          = new StreamTools();
        ADTTex      t          = new ADTTex();
        string      ADTtexPath = Path + MapName + "_" + coords.x + "_" + coords.y + "_tex0" + ".adt";
        string      path       = Casc.GetFile(ADTtexPath);

        byte[] ADTtexData = File.ReadAllBytes(path);

        int  MCNKchunkNumber = 0;
        long streamPosition  = 0;

        using (MemoryStream ms = new MemoryStream(ADTtexData))
        {
            while (streamPosition < ms.Length)
            {
                ms.Position = streamPosition;
                int chunkID   = s.ReadLong(ms);
                int chunkSize = s.ReadLong(ms);
                streamPosition = ms.Position + chunkSize;

                switch (chunkID)
                {
                case (int)ChunkID.ADT.MVER:
                    t.ReadMVER(ms);     // ADT file version
                    break;

                case (int)ChunkID.ADT.MAMP:
                    t.ReadMAMP(ms);     // Single value - texture size = 64
                    break;

                case (int)ChunkID.ADT.MTEX:
                    t.ReadMTEX(ms, chunkSize);     // Texture Paths
                    break;

                case (int)ChunkID.ADT.MCNK:
                {
                    t.ReadMCNKtex(ms, MapName, MCNKchunkNumber, chunkSize);         // Texture Data - 256chunks
                    MCNKchunkNumber++;
                }
                break;

                case (int)ChunkID.ADT.MTXF:
                    t.ReadMTXF(ms, chunkSize);     // Texture Paths
                    break;

                case (int)ChunkID.ADT.MTXP:
                    t.ReadMTXP(ms, chunkSize);     // Texture Paths
                    break;

                default:
                    t.SkipUnknownChunk(ms, chunkID, chunkSize);
                    break;
                }
            }
        }
        ADTtexData = null;
    }
Пример #2
0
    ////////////////////////////
    ////// MCNK Subchunks //////
    ////////////////////////////

    public void ReadMCVT(MemoryStream ADTstream, ADTRootData.MeshChunkData chunkData)
    {
        StreamTools s = new StreamTools();

        for (int v = 1; v <= 145; v++)
        {
            chunkData.VertexHeights.Add(s.ReadFloat(ADTstream));
        }
    }
Пример #3
0
    public byte[] AlphaMap_Compressed(MemoryStream ADTtexstream) // compressed
    {
        StreamTools s = new StreamTools();

        byte[] textureArray = new byte[4096];
        int    alphaOffset  = 0;

        while (alphaOffset < 4096)
        {
            //read a byte//
            byte onebyte = (byte)ADTtexstream.ReadByte();
            //translate byte to 8 bits//
            byte[] bytearr = new byte[1];
            bytearr[0] = onebyte;
            BitArray bitarr = new BitArray(bytearr);
            //is first bit true?//
            bool fc = bitarr.Get(7); //true=fill, false=copy
            //next 7 bits determine how many times we fill/copy, max 127
            int[]  array    = new int[1];
            bool[] bitArray = new bool[7];
            for (int i = 0; i < 7; i++)
            {
                bitArray[i] = bitarr.Get(6 - i);
            }
            int times = s.BoolArrayToInt(bitArray);
            if (times == 0)
            {
                alphaOffset = 4096;
                break;
            }
            if (times != 0)
            {
                //fill mode//
                if (fc == true) // repeat the byte following the one we just read *count* number of times into the alpha map
                {
                    byte secondbytefill = (byte)ADTtexstream.ReadByte();
                    for (int j = 0; j < times; j++)
                    {
                        textureArray[alphaOffset] = secondbytefill;
                        alphaOffset++;
                    }
                }
                //copy mode//
                if (fc == false)  //  read *count* number of following bytes into the alpha map
                {
                    for (int jc = 0; jc < times; jc++)
                    {
                        byte secondbytecopy = (byte)ADTtexstream.ReadByte();
                        textureArray[alphaOffset] = secondbytecopy;
                        alphaOffset++;
                    }
                }
            }
        }
        alphaOffset = 0;
        return(textureArray);
    }
Пример #4
0
    // List of offsets of WMO filenames in the MWMO chunk. //
    public void ReadMWID(MemoryStream ADTobjstream, int MWIDsize)
    {
        StreamTools s          = new StreamTools();
        long        currentPos = ADTobjstream.Position;

        while (ADTobjstream.Position < currentPos + MWIDsize)
        {
            ADTObjData.modelBlockData.WMOOffsets.Add(s.ReadLong(ADTobjstream));
        }
    }
Пример #5
0
    // Terrain Mesh Parser //
    private static void ParseADT_Main(string Path, string MapName, Vector2 coords)  // MS version
    {
        StreamTools s           = new StreamTools();
        ADTRoot     r           = new ADTRoot();
        ChunkID     c           = new ChunkID();
        string      ADTmainPath = Path + MapName + "_" + coords.x + "_" + coords.y + ".adt";
        string      path        = Casc.GetFile(ADTmainPath);

        byte[] ADTmainData = File.ReadAllBytes(path);

        int  MCNKchunkNumber = 0;
        long streamPosition  = 0;

        using (MemoryStream ms = new MemoryStream(ADTmainData))
        {
            while (streamPosition < ms.Length)
            {
                ms.Position = streamPosition;
                int chunkID   = s.ReadLong(ms);
                int chunkSize = s.ReadLong(ms);
                streamPosition = ms.Position + chunkSize;

                switch (chunkID)
                {
                case (int)ChunkID.ADT.MVER:
                    r.ReadMVER(ms);     // ADT file version
                    break;

                case (int)ChunkID.ADT.MHDR:
                    r.ReadMHDR(ms);     // Offsets for specific chunks 0000 if chunks don't exist.
                    break;

                case (int)ChunkID.ADT.MH2O:
                    r.ReadMH2O(ms, chunkSize);     // Water Data
                    break;

                case (int)ChunkID.ADT.MCNK:
                {
                    r.ReadMCNK(ms, MCNKchunkNumber, chunkSize);         // Terrain Data - 256chunks
                    MCNKchunkNumber++;
                }
                break;

                case (int)ChunkID.ADT.MFBO:
                    r.ReadMFBO(ms);     // FlightBounds plane & Death plane
                    break;

                default:
                    r.SkipUnknownChunk(ms, chunkID, chunkSize);
                    break;
                }
            }
        }
        ADTmainData = null;
    }
Пример #6
0
        public List <PersonFiles> SaveSplitDocument(Stream document)
        {
            List <PersonFiles> resultList = new List <PersonFiles>();

            byte[] byteArray = StreamTools.ReadFully(document);
            using (MemoryStream documentInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true))
            {
                foreach (OpenXMLDocumentPart <Sheet> element in DocumentElements)
                {
                    OpenXmlPowerToolsDocument docDividedPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream);
                    using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docDividedPowerTools))
                    {
                        SpreadsheetDocument excelDoc = streamDoc.GetSpreadsheetDocument();
                        excelDoc.WorkbookPart.Workbook.Sheets.RemoveAllChildren();
                        Sheets sheets = excelDoc.WorkbookPart.Workbook.Sheets;
                        foreach (Sheet compo in element.CompositeElements)
                        {
                            sheets.Append(compo.CloneNode(false));
                        }

                        excelDoc.WorkbookPart.Workbook.Save();

                        var person = new PersonFiles();
                        person.Person = element.PartOwner;
                        resultList.Add(person);
                        person.Name = element.Guid.ToString();
                        person.Data = streamDoc.GetModifiedDocument().DocumentByteArray;
                    }
                }

                OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docPowerTools))
                {
                    SpreadsheetDocument excelDoc = streamDoc.GetSpreadsheetDocument();

                    excelDoc.WorkbookPart.Workbook.Sheets.RemoveAllChildren();
                    excelDoc.WorkbookPart.Workbook.Save();

                    var person = new PersonFiles();
                    person.Person = "/";
                    resultList.Add(person);
                    person.Name = "template.xlsx";
                    person.Data = streamDoc.GetModifiedDocument().DocumentByteArray;
                }
            }

            var xmlPerson = new PersonFiles();

            xmlPerson.Person = "/";
            resultList.Add(xmlPerson);
            xmlPerson.Name = "mergeXmlDefinition.xml";
            xmlPerson.Data = CreateMergeXml();

            return(resultList);
        }
Пример #7
0
    // MCNK.nMapObjRefs into the file's MODF //
    public void ReadMCRW(MemoryStream ADTobjstream, int MCNKchunkNumber, int MCRWsize)
    {
        StreamTools s           = new StreamTools();
        List <int>  MODFentries = new List <int>();
        long        currentPos  = ADTobjstream.Position;

        while (ADTobjstream.Position < currentPos + MCRWsize)
        {
            MODFentries.Add(s.ReadLong(ADTobjstream));
        }
    }
Пример #8
0
    private T LoadRecords <T>(string path)  where T : new()
    {
        T t = StreamTools.DeserializeObject <T>(path);

        if (t == null)
        {
            Debug.Log("File : " + path + " does not exist, now create.");
            t = new T();
        }
        return(t);
    }
Пример #9
0
        public void should_be_able_to_read_entire_stream()
        {
            Assert.That(_subject.IsComplete(), Is.False);

            var ms = new MemoryStream();

            StreamTools.CopyBytesToTimeout(_subject, ms, null);
            var result = Encoding.UTF8.GetString(ms.ToArray());

            Assert.That(result, Is.EqualTo(expected));
            Assert.That(_subject.IsComplete(), Is.True);
        }
Пример #10
0
 private LevelDataIndex GetLevelDataIndex()
 {
     if (m_LevelDataIndex == null)
     {
         m_LevelDataIndex = Resources.LoadAssetAtPath <LevelDataIndex>(StreamTools.GetStreamingAssetsPathInEditor() + ConstantData.MissionLevelDataIndexPath);
         if (!m_LevelDataIndex)
         {
             m_LevelDataIndex = ScriptableObject.CreateInstance <LevelDataIndex>();
             AssetDatabase.CreateAsset(m_LevelDataIndex, StreamTools.GetStreamingAssetsPathInEditor() + ConstantData.MissionLevelDataIndexPath);
         }
     }
     return(m_LevelDataIndex);
 }
Пример #11
0
        /// <inheritdoc />
        public override void ReverseProcessDataStream(Stream inStream, Stream outStream, Dictionary <string, string> options, out long writtenBytes)
        {
            inStream.Seek(inStream.Length - 4, SeekOrigin.Begin);
            byte[] buffer = new byte[4];
            inStream.Read(buffer, 0, 4);
            inStream.Seek(0, SeekOrigin.Begin);

            //read the last 4 bytes from the input stream
            int padSize = BitConverter.ToInt32(buffer, 0);

            StreamTools.Write(inStream, 0, inStream.Length - padSize, outStream, 8192, double.MaxValue, int.MaxValue);
            writtenBytes = outStream.Length;
        }
        private void button_Click_4(object sender, RoutedEventArgs e)
        {
            MemoryStream inMemoryCopy = new MemoryStream();

            using (FileStream fs = File.OpenRead(@"C:\Users\drabiu\Documents\Testy\przykladowa-prezentacja.pptx"))
            {
                fs.CopyTo(inMemoryCopy);
            }

            MemoryStream inMemoryCopy2 = new MemoryStream();

            using (FileStream fs = File.OpenRead(@"C:\Users\drabiu\Documents\Testy\6.CGW15-prezentacja.pptx"))
            {
                fs.CopyTo(inMemoryCopy2);
            }

            byte[] byteArray  = StreamTools.ReadFully(inMemoryCopy);
            byte[] byteArray2 = StreamTools.ReadFully(inMemoryCopy2);
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                using (PresentationDocument preDoc =
                           PresentationDocument.Open(mem, true))
                {
                    using (MemoryStream mem2 = new MemoryStream())
                    {
                        mem2.Write(byteArray2, 0, (int)byteArray2.Length);
                        using (PresentationDocument pre2Doc =
                                   PresentationDocument.Open(mem2, true))
                        {
                            PresentationTools.InsertSlidesFromTemplate(preDoc, pre2Doc, new List <string>()
                            {
                                "rId13"
                            });
                        }
                    }
                }

                byteArray = mem.ToArray();
                //System.IO.File.WriteAllBytes(@"C:\Users\drabiu\Documents\Testy\przykladowa-prezentacja-test.pptx", mem.ToArray());
            }
            System.IO.File.WriteAllBytes(@"C:\Users\drabiu\Documents\Testy\przykladowa-prezentacja-test.pptx", byteArray);
            //System.IO.File.WriteAllBytes(@"C:\Users\drabiu\Documents\Testy\przykladowa-prezentacja-test.pptx", inMemoryCopy.ToArray());

            //using (FileStream file = new FileStream(@"C:\Users\drabiu\Documents\Testy\przykladowa-prezentacja.pptx", FileMode.Create, FileAccess.Write))
            //{
            //    inMemoryCopy.WriteTo(file);
            //}

            inMemoryCopy.Close();
        }
Пример #13
0
    public void ReadMCAL(MemoryStream ADTtexstream, string mapname, ADTTexData.TextureChunkData chunkData)
    {
        StreamTools s = new StreamTools();
        long        McalStartPosition = ADTtexstream.Position;
        int         numberofLayers    = chunkData.NumberOfTextureLayers;

        if (numberofLayers > 1)
        {
            chunkData.alphaLayers = new List <byte[]>();
            for (int l = 1; l < numberofLayers; l++)
            {
                if (WDT.Flags[mapname].adt_has_height_texturing == true)
                {
                    if (chunkData.alpha_map_compressed[l] == false)
                    {
                        chunkData.alphaLayers.Add(AlphaMap_UncompressedFullRes(ADTtexstream));
                    }
                    else if (chunkData.alpha_map_compressed[l] == true)
                    {
                        chunkData.alphaLayers.Add(AlphaMap_Compressed(ADTtexstream));
                    }
                }
                else if (WDT.Flags[mapname].adt_has_height_texturing == false)
                {
                    if (WDT.Flags[mapname].adt_has_big_alpha == false)
                    {
                        if (chunkData.alpha_map_compressed[l] == false)
                        {
                            chunkData.alphaLayers.Add(AlphaMap_UncompressedHalfRes(ADTtexstream));
                        }
                        else if (chunkData.alpha_map_compressed[l] == true)
                        {
                            chunkData.alphaLayers.Add(AlphaMap_Compressed(ADTtexstream));
                        }
                    }
                    else if (WDT.Flags[mapname].adt_has_big_alpha == true)
                    {
                        if (chunkData.alpha_map_compressed[l] == false)
                        {
                            chunkData.alphaLayers.Add(AlphaMap_UncompressedFullRes(ADTtexstream));
                        }
                        else if (chunkData.alpha_map_compressed[l] == true)
                        {
                            chunkData.alphaLayers.Add(AlphaMap_Compressed(ADTtexstream));
                        }
                    }
                }
            }
        }
    }
Пример #14
0
        public List <PersonFiles> SaveSplitDocument(Stream document)
        {
            List <PersonFiles> resultList = new List <PersonFiles>();

            byte[] byteArray = StreamTools.ReadFully(document);
            using (MemoryStream documentInMemoryStream = new MemoryStream(byteArray, 0, byteArray.Length, true, true))
            {
                OpenXmlPowerToolsDocument docPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream);
                using (OpenXmlMemoryStreamDocument streamTemplateDoc = new OpenXmlMemoryStreamDocument(docPowerTools))
                {
                    PresentationDocument templatePresentation = streamTemplateDoc.GetPresentationDocument();
                    foreach (OpenXMLDocumentPart <SlideId> element in DocumentElements)
                    {
                        OpenXmlPowerToolsDocument emptyDocPowerTools = new OpenXmlPowerToolsDocument(DocumentName, documentInMemoryStream);
                        using (OpenXmlMemoryStreamDocument streamDividedDoc = new OpenXmlMemoryStreamDocument(emptyDocPowerTools))
                        {
                            var relationshipIds = element.CompositeElements.Select(c => c.RelationshipId.Value).ToList();
                            PresentationDocument dividedPresentation = streamDividedDoc.GetPresentationDocument();
                            PresentationTools.InsertSlidesFromTemplate(PresentationTools.RemoveAllSlides(dividedPresentation), templatePresentation, relationshipIds);

                            var person = new PersonFiles();
                            person.Person = element.PartOwner;
                            resultList.Add(person);
                            person.Name = element.Guid.ToString();
                            person.Data = streamDividedDoc.GetModifiedDocument().DocumentByteArray;
                        }
                    }
                }

                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(docPowerTools))
                {
                    PresentationDocument preDoc = streamDoc.GetPresentationDocument();
                    PresentationTools.RemoveAllSlides(preDoc);

                    var person = new PersonFiles();
                    person.Person = "/";
                    resultList.Add(person);
                    person.Name = "template.pptx";
                    person.Data = streamDoc.GetModifiedDocument().DocumentByteArray;
                }

                var xmlPerson = new PersonFiles();
                xmlPerson.Person = "/";
                resultList.Add(xmlPerson);
                xmlPerson.Name = "mergeXmlDefinition.xml";
                xmlPerson.Data = CreateMergeXml();
            }

            return(resultList);
        }
Пример #15
0
        void SyncData()
        {
            System.IO.FileInfo[] fileInfos = StreamTools.GetAllFile(StreamTools.GetStreamingAssetsPathInEditor() + ConstantData.MissionLevelDataPath, "*-*");

            if (fileInfos.Length != m_LevelDataIndex.Count)
            {
                Debug.Log("Level data indexes need synchronized, now synchronizing");
                m_LevelDataIndex.Clear();
                foreach (var v in fileInfos)
                {
                    LevelData data = Resources.LoadAssetAtPath <LevelData>(StreamTools.GetStreamingAssetsPathInEditor() + ConstantData.MissionLevelDataPath + v.Name);
                    m_LevelDataIndex.Add(data);
                }
            }
        }
Пример #16
0
    public static PoolDataAsset GetPoolDatas()
    {
#if !UNITY_ANDROID || UNITY_EDITOR
        if (PoolDatas == null)
        {
            PoolDatas = StreamTools.DeserializeObject <PoolDataAsset>(StreamTools.GetStreamingAssetsPath() + PoolDataAssetsFile);
            if (PoolDatas == null)
            {
                UnityEngine.Debug.Log("Pool asset data is null");
                PoolDatas = new PoolDataAsset();
            }
        }
#endif
        return(PoolDatas);
    }
Пример #17
0
    // List of filenames for WMOs (world map objects) that appear in this map tile. //
    public void ReadMWMO(MemoryStream ADTobjstream, int MWMOsize)
    {
        StreamTools s          = new StreamTools();
        long        currentPos = ADTobjstream.Position;

        while (ADTobjstream.Position < currentPos + MWMOsize)
        {
            int    position = (int)(ADTobjstream.Position - currentPos);
            string path     = s.ReadNullTerminatedString(ADTobjstream);
            if (path != "")
            {
                ADTObjData.modelBlockData.WMOPaths.Add(position, path);
            }
        }
    }
Пример #18
0
    // Placement information for WMOs. //
    // Additional to this, the WMOs to render are referenced in each MCRF chunk. (?) //
    public void ReadMODF(MemoryStream ADTobjstream, int MODFsize)
    {
        Flags       f = new Flags();
        StreamTools s = new StreamTools();

        ADTObjData.modelBlockData.WMOInfo = new List <ADTObjData.WMOPlacementInfo>();
        long currentPos = ADTobjstream.Position;

        while (ADTobjstream.Position < currentPos + MODFsize)
        {
            ADTObjData.WMOPlacementInfo data = new ADTObjData.WMOPlacementInfo();

            // references an entry in the MWID chunk, specifying the model to use.
            data.nameID = s.ReadLong(ADTobjstream);

            // this ID should be unique for all ADTs currently loaded. Best, they are unique for the whole map.
            data.uniqueID = s.ReadLong(ADTobjstream);

            // same as in MDDF.
            float Y = ((s.ReadFloat(ADTobjstream) - 17066) * -1) / Settings.worldScale; //-- pos X
            float Z = (s.ReadFloat(ADTobjstream)) / Settings.worldScale;                //-- Height
            float X = ((s.ReadFloat(ADTobjstream) - 17066) * -1) / Settings.worldScale; //-- pos Z
            data.position = new Vector3(X, Z, Y);

            // same as in MDDF.
            float rotX = s.ReadFloat(ADTobjstream);       //-- rot X
            float rotZ = 180 - s.ReadFloat(ADTobjstream); //-- rot Y
            float rotY = s.ReadFloat(ADTobjstream);       //-- rot Z
            data.rotation = Quaternion.Euler(new Vector3(rotX, rotZ, rotY));

            // position plus the transformed wmo bounding box. used for defining if they are rendered as well as collision.
            data.extents = s.ReadBoundingBox(ADTobjstream);

            // values from enum MODFFlags.
            data.flags = f.ReadMODFFlags(ADTobjstream);

            // which WMO doodad set is used.
            data.doodadSet = s.ReadShort(ADTobjstream);

            // which WMO name set is used. Used for renaming goldshire inn to northshire inn while using the same model.
            data.nameSet = s.ReadShort(ADTobjstream);

            // Legion(?)+: has data finally, looks like scaling (same as MDDF). Padding in 0.5.3 alpha.
            int unk = s.ReadShort(ADTobjstream);

            ADTObjData.modelBlockData.WMOInfo.Add(data);
        }
    }
Пример #19
0
        void DrawOtherGUI()
        {
            GUI.BeginGroup(new Rect(0, AreaHeight + 2 * m_GridSize + m_OutlineRect.height - m_BackgroundRect.height, AreaWidth + 2 * m_GridSize + 100, 350));
            m_CurrentLevelData = EditorGUILayout.ObjectField("关卡数据文件: ", m_CurrentLevelData, typeof(LevelData), false) as LevelData;
            m_ShotCount        = EditorGUILayout.IntField("击杆数:", m_ShotCount);
            m_DescripID        = EditorGUILayout.IntField("描述ID : ", m_DescripID);
            m_LevelName        = EditorGUILayout.TextField("关卡名称:", m_LevelName);
            CheckDataEquals();
            if (GUILayout.Button("保存") && !string.IsNullOrEmpty(m_LevelName))
            #region Save configuration
            {
                LevelData data = ScriptableObject.CreateInstance <LevelData>();
                data.cueBallData = new LevelData.BallData(m_CueBall.id, m_CueBall.transform.position, m_CueBall.rect, BallType.WHITE);
                foreach (KeyValuePair <int, TouchObject> k in m_Balls)
                {
                    LevelData.BallData d = new LevelData.BallData(k.Key, k.Value.transform.position, k.Value.rect, k.Value.type);
                    data.ballDatas.Add(d);
                }
                foreach (var v in m_Pockets)
                {
                    if (v.pocketType == PocketType.Punishment)
                    {
                        data.StartPunishmentPocket |= v.pocketIndexes;
                    }
                    else if (v.pocketType == PocketType.Reward)
                    {
                        data.StartRewardPocket |= v.pocketIndexes;
                    }
                    else if (v.pocketType == PocketType.BlockOff)
                    {
                        data.BlockPockets |= v.pocketIndexes;
                    }
                }
                data.shotCount     = m_ShotCount;
                data.FileName      = m_LevelName;
                data.DescriptionID = m_DescripID;
                AssetDatabase.CreateAsset(data, StreamTools.GetStreamingAssetsPathInEditor() + "LevelDatas/" + m_LevelName + ".asset");
                m_CurrentLevelData = data;
                m_LevelDataIndex.Add(data);
            }
            #endregion //Save configuration
            GUI.skin.label.fontSize = 18;
            GUILayout.Label("说明:右键点击台球桌添加球。 右键点击非白球删除球。右键点击袋口(黑色圆)设置球袋类型(提供色盲模式^-^)");
            GUI.skin.label.fontSize = 12;

            GUI.EndGroup();
        }
Пример #20
0
    IEnumerator LoadPoolAsset(Delegate1Args <PoolDataAsset> onloaded)
    {
        WWW www = new WWW(ConstantData.PoolDataAssetsFile);

        Debug.Log("load file : " + ConstantData.PoolDataAssetsFile);
        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            Debug.Log("load file success");
            onloaded(StreamTools.DeserializeObject <PoolDataAsset>(www.bytes));
        }
        else
        {
            Debug.LogError(www.error);
        }
    }
Пример #21
0
    /////////////////////////////
    ///// MCNKtex Subchunks /////
    /////////////////////////////

    public void ReadMCLY(MemoryStream ADTtexstream, ADTTexData.TextureChunkData chunkData, int MCLYsize)
    {
        /*
         *  Texture layer definitions for this map chunk. 16 bytes per layer, up to 4 layers (thus, layer count = size / 16).
         *  Every texture layer other than the first will have an alpha map to specify blending amounts. The first layer is rendered with full opacity. To know which alphamap is used, there is an offset into the MCAL chunk. That one is relative to MCAL.
         *  You can animate these by setting the flags. Only simple linear animations are possible. You can specify the direction in 45° steps and the speed.
         *  The textureId is just the array index of the filename array in the MTEX chunk.
         *  For getting the right feeling when walking, you should set the effectId which links to GroundEffectTextureRec::m_ID. It defines the little detail doodads as well as the footstep sounds and if footprints are visible. You can set the id to -1 (int16!) to have no detail doodads and footsteps at all. Also, you need to define the currently on-top layer in the MCNK structure for the correct detail doodads to show up!
         *  Introduced in Wrath of the Lich King, terrain can now reflect a skybox. This is used for icecubes made out of ADTs to reflect something. You need to have the MTXF chunk in, if you want that. Look at an skybox Blizzard made to see how you should do it.
         */
        if (MCLYsize == 0)
        {
            return;
        }

        StreamTools s = new StreamTools();
        long        MCLYStartPosition = ADTtexstream.Position;
        int         numberOfLayers    = MCLYsize / 16;

        chunkData.NumberOfTextureLayers = numberOfLayers;
        chunkData.textureIds            = new int[numberOfLayers];
        chunkData.LayerOffsetsInMCAL    = new int[numberOfLayers];
        for (int l = 0; l < numberOfLayers; l++)
        {
            chunkData.textureIds[l] = s.ReadLong(ADTtexstream); // texture ID
            // <flags>
            byte[] arrayOfBytes = new byte[4];
            ADTtexstream.Read(arrayOfBytes, 0, 4);
            BitArray flags = new BitArray(arrayOfBytes);
            int      animation_rotation = (flags[0] ? 1 : 0) + (flags[1] ? 1 : 0) + (flags[2] ? 1 : 0); // each tick is 45°
            int      animation_speed    = (flags[3] ? 1 : 0) + (flags[4] ? 1 : 0) + (flags[5] ? 1 : 0); // 0 to 3
            bool     animation_enabled  = flags[6];
            bool     overbright         = flags[7];                                                     // This will make the texture way brighter. Used for lava to make it "glow".
            bool     use_alpha_map      = flags[8];                                                     // set for every layer after the first
            chunkData.alpha_map_compressed[l] = flags[9];                                               // see MCAL chunk description - MCLY_AlphaType_Flag
            bool use_cube_map_reflection = flags[10];                                                   // This makes the layer behave like its a reflection of the skybox. See below
            bool unknown_0x800           = flags[11];                                                   // WoD?+ if either of 0x800 or 0x1000 is set, texture effects' texture_scale is applied
            bool unknown_0x1000          = flags[12];                                                   // WoD?+ see 0x800
            // flags 13-32 unused
            // </flags>
            int layerOffset = s.ReadLong(ADTtexstream);
            chunkData.LayerOffsetsInMCAL[l] = layerOffset;
            int effectId = s.ReadLong(ADTtexstream); //foreign_keyⁱ <uint32_t, &GroundEffectTextureRec::m_ID>; // 0xFFFFFFFF for none, in alpha: uint16_t + padding
        }
    }
Пример #22
0
        public void OpenAndSearchDocument(Stream docxFile, Stream xmlFile)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Split));
            Split         splitXml   = (Split)serializer.Deserialize(xmlFile);

            byte[] byteArray = StreamTools.ReadFully(docxFile);
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, byteArray.Length);
                using (WordprocessingDocument wordDoc =
                           WordprocessingDocument.Open(mem, true))
                {
                    Body body = wordDoc.MainDocumentPart.Document.Body;
                    IMarkerMapper <OpenXmlElement> mapping = new MarkerWordMapper(DocumentName, splitXml, body);
                    DocumentElements = mapping.Run();
                }
            }
        }
Пример #23
0
    public static IEnumerator LoadBytes <T>(string filePath, Delegate1Args <T> onloaded) where T : new()
    {
        WWW www = new WWW(filePath);

        Debug.Log("Loading file : " + filePath);
        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            Debug.Log("Load file success : " + filePath);
            onloaded(StreamTools.DeserializeObject <T>(www.bytes));
        }
        else
        {
            Debug.Log(www.error);
            onloaded(default(T));
        }
    }
Пример #24
0
    public void ReadMTXP(MemoryStream ADTtexstream, int MTXPsize)  // 16 bytes per MTEX texture
    {
        StreamTools s = new StreamTools();
        Flags       f = new Flags();

        ADTTexData.textureBlockData.MTXP = true;
        for (int i = 0; i < MTXPsize / 16; i++)
        {
            ADTTexData.textureBlockData.textureFlags.Add(ADTTexData.textureBlockData.terrainTexturePaths[i], f.ReadTerrainTextureFlag(ADTtexstream));
            // default 0.0 -- the _h texture values are scaled to [0, value) to determine actual "height".
            // this determines if textures overlap or not (e.g. roots on top of roads).
            ADTTexData.textureBlockData.heightScales.Add(ADTTexData.textureBlockData.terrainTexturePaths[i], s.ReadFloat(ADTtexstream));
            // default 1.0 -- note that _h based chunks are still influenced by MCAL (blendTex below)
            ADTTexData.textureBlockData.heightOffsets.Add(ADTTexData.textureBlockData.terrainTexturePaths[i], s.ReadFloat(ADTtexstream));
            // no default, no non-zero values in 20490
            int padding = s.ReadLong(ADTtexstream);
        }
    }
Пример #25
0
    public void ReadMH2O(MemoryStream ADTstream, int MH2Osize)
    {
        StreamTools s = new StreamTools();
        long        chunkStartPosition = ADTstream.Position;

        // header - SMLiquidChunk
        for (int a = 0; a < 256; a++)
        {
            int offset_instances  = s.ReadLong(ADTstream);      // points to SMLiquidInstance[layer_count]
            int layer_count       = s.ReadLong(ADTstream);      // 0 if the chunk has no liquids. If > 1, the offsets will point to arrays.
            int offset_attributes = s.ReadLong(ADTstream);      // points to mh2o_chunk_attributes, can be ommitted for all-0
            if (offset_instances >= 0)
            {
                // instances @24bytes
                ADTstream.Seek(chunkStartPosition + offset_instances, SeekOrigin.Begin);
                int liquid_type          = s.ReadShort(ADTstream); //DBC - foreign_keyⁱ<uint16_t, &LiquidTypeRec::m_ID> liquid_type;
                int liquid_object_or_lvf = s.ReadShort(ADTstream); //DBC -  foreign_keyⁱ<uint16_t, &LiquidObjectRec::m_ID> liquid_object_or_lvf;
                                                                   // if > 41, an id into DB/LiquidObject. If below, LiquidVertexFormat, used in ADT/v18#instance_vertex_data Note hardcoded LO ids below.
                                                                   // if >= 42, look up via DB/LiquidType and DB/LiquidMaterial, otherwise use liquid_object_or_lvf as LVF
                                                                   // also see below for offset_vertex_data: if that's 0 and lt ≠ 2 → lvf = 2
                float min_height_level = s.ReadFloat(ADTstream);   // used as height if no heightmap given and culling ᵘ
                float max_height_level = s.ReadFloat(ADTstream);   // ≥ WoD ignores value and assumes to both be 0.0 for LVF = 2! ᵘ
                int   x_offset         = ADTstream.ReadByte();     // The X offset of the liquid square (0-7)
                int   y_offset         = ADTstream.ReadByte();     // The Y offset of the liquid square (0-7)
                int   width            = ADTstream.ReadByte();     // The width of the liquid square (1-8)
                int   height           = ADTstream.ReadByte();     // The height of the liquid square (1-8)
                                                                   // The above four members are only used if liquid_object_or_lvf <= 41. Otherwise they are assumed 0, 0, 8, 8. (18179)
                int offset_exists_bitmap = s.ReadLong(ADTstream);  // not all tiles in the instances need to be filled. always 8*8 bits.
                                                                   // offset can be 0 for all-exist. also see (and extend) Talk:ADT/v18#SMLiquidInstance
                int offset_vertex_data = s.ReadLong(ADTstream);    // actual data format defined by LiquidMaterialRec::m_LVF via LiquidTypeRec::m_materialID
                                                                   // if offset = 0 and liquidType ≠ 2, then let LVF = 2, i.e. some ocean shit
            }
            //attributes
            if (offset_attributes >= 0)
            {
                ADTstream.Seek(chunkStartPosition + offset_attributes, SeekOrigin.Begin);
                ulong fishable = s.ReadUint64(ADTstream);               // seems to be usable as visibility information.
                ulong deep     = s.ReadUint64(ADTstream);
            }
        }
        ADTstream.Seek(chunkStartPosition + MH2Osize, SeekOrigin.Begin); // set stream location to right after MH2O
    }
Пример #26
0
    // Placement information for doodads (M2 models). //
    // Additional to this, the models to render are referenced in each MCRF chunk. //
    public void ReadMDDF(MemoryStream ADTobjstream, int MDDFsize)
    {
        Flags       f = new Flags();
        StreamTools s = new StreamTools();

        ADTObjData.modelBlockData.M2Info = new List <ADTObjData.M2PlacementInfo>();
        long currentPos = ADTobjstream.Position;

        while (ADTobjstream.Position < currentPos + MDDFsize)
        {
            ADTObjData.M2PlacementInfo data = new ADTObjData.M2PlacementInfo();

            // References an entry in the MMID chunk, specifying the model to use.
            data.nameID = s.ReadLong(ADTobjstream);

            // This ID should be unique for all ADTs currently loaded.
            // Best, they are unique for the whole map. Blizzard has these unique for the whole game.
            data.uniqueID = s.ReadLong(ADTobjstream);

            // This is relative to a corner of the map. Subtract 17066 from the non vertical values and you should start to see
            // something that makes sense. You'll then likely have to negate one of the non vertical values in whatever coordinate
            // system you're using to finally move it into place.
            float Y = ((s.ReadFloat(ADTobjstream) - 17066) * -1) / Settings.worldScale; //-- pos X
            float Z = (s.ReadFloat(ADTobjstream)) / Settings.worldScale;                //-- Height
            float X = ((s.ReadFloat(ADTobjstream) - 17066) * -1) / Settings.worldScale; //-- pos Z
            data.position = new Vector3(X, Z, Y);

            // degrees. This is not the same coordinate system orientation like the ADT itself! (see history.)
            float rotX = s.ReadFloat(ADTobjstream);       //-- rot X
            float rotZ = 180 - s.ReadFloat(ADTobjstream); //-- rot Y
            float rotY = s.ReadFloat(ADTobjstream);       //-- rot Z
            data.rotation = Quaternion.Euler(new Vector3(rotX, rotZ, rotY));

            // 1024 is the default size equaling 1.0f.
            data.scale = s.ReadShort(ADTobjstream) / 1024.0f;

            // values from struct MDDFFlags.
            data.flags = f.ReadMDDFFlags(ADTobjstream);

            ADTObjData.modelBlockData.M2Info.Add(data);
        }
    }
Пример #27
0
    public byte[] AlphaMap_UncompressedHalfRes(MemoryStream ADTtexstream)
    {
        StreamTools s = new StreamTools();
        int         currentArrayPos = 0;

        byte[] textureArray = new byte[4096];
        for (int ux = 0; ux < 2048; ux++)
        {
            byte onebyte = (byte)ADTtexstream.ReadByte();
            byte nibble1 = (byte)(onebyte & 0x0F);
            byte nibble2 = (byte)((onebyte & 0xF0) >> 4);
            int  first   = s.NormalizeHalfResAlphaPixel(nibble2);
            int  second  = s.NormalizeHalfResAlphaPixel(nibble1);
            textureArray[ux + currentArrayPos + 0] = (byte)first;
            textureArray[ux + currentArrayPos + 1] = (byte)second;
            currentArrayPos = currentArrayPos + 1;
        }
        currentArrayPos = 0;
        return(textureArray);
    }
Пример #28
0
    public TerrainTextureFlag ReadTerrainTextureFlag(Stream stream)
    {
        StreamTools s = new StreamTools();

        byte[]             bytes = new byte[4];
        TerrainTextureFlag value = new TerrainTextureFlag();

        stream.Read(bytes, 0, 4);
        BitArray flags = new BitArray(bytes);

        value.do_not_load_specular_or_height_texture_but_use_cubemap = flags[0];
        bool[] texScaleBools = new bool[4];
        texScaleBools[3]    = flags[4];
        texScaleBools[2]    = flags[5];
        texScaleBools[1]    = flags[6];
        texScaleBools[0]    = flags[7];
        value.texture_scale = s.getUintFrom4Bits(texScaleBools);
        value.texture_scale = (int)Mathf.Pow(2, value.texture_scale);
        return(value);
    }
Пример #29
0
    public void ReadMCNKtex(MemoryStream ADTtexstream, string mapname, int MCNKchunkNumber, int MCNKsize)
    {
        if (ADTtexstream.Length == ADTtexstream.Position)
        {
            return;
        }

        StreamTools s = new StreamTools();

        ADTTexData.TextureChunkData chunkData = new ADTTexData.TextureChunkData();

        long MCNKchnkPos    = ADTtexstream.Position;
        long streamPosition = ADTtexstream.Position;

        while (streamPosition < MCNKchnkPos + MCNKsize)
        {
            ADTtexstream.Position = streamPosition;
            int chunkID   = s.ReadLong(ADTtexstream);
            int chunkSize = s.ReadLong(ADTtexstream);
            streamPosition = ADTtexstream.Position + chunkSize;
            switch (chunkID)
            {
            case (int)ChunkID.ADT.MCLY:
                ReadMCLY(ADTtexstream, chunkData, chunkSize);     // texture layers
                break;

            case (int)ChunkID.ADT.MCSH:
                ReadMCSH(ADTtexstream, chunkData);     // static shadow maps
                break;

            case (int)ChunkID.ADT.MCAL:
                ReadMCAL(ADTtexstream, mapname, chunkData);     // alpha layers
                break;

            default:
                SkipUnknownChunk(ADTtexstream, chunkID, chunkSize);
                break;
            }
        }
        ADTTexData.textureBlockData.textureChunksData.Add(chunkData);
    }
Пример #30
0
    public void ReadMFBO(MemoryStream ADTstream)
    {
        StreamTools s = new StreamTools();

        short[,] planeMax = new short[3, 3];
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                planeMax[x, y] = (short)s.ReadShort(ADTstream);
            }
        }
        short[,] planeMin = new short[3, 3];
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                planeMin[x, y] = (short)s.ReadShort(ADTstream);
            }
        }
    }