Esempio n. 1
0
        public SoundPlayer(CASCFile file)
        {
            InitializeComponent();

            this.file = file;
            localPath = Path.Combine(Constants.TEMP_DIRECTORY, file.FullName);

            player = new ZPlay();
            if (!File.Exists(localPath))
            {
                EventManager.FileExtractComplete += OnFileExtractComplete;

                RunnerExtractItem extract = new RunnerExtractItem(file);
                runnerID = extract.runnerID;
                extract.Begin();

                SetState("Extracting file...");
            }
            else
            {
                ready = true;
                Play();
            }

            UI_TrackTitle.Text = file.Name;
            Text = file.Name + " - W3DT";

            UI_VolumeBar.Value = Program.Settings.SoundPlayerVolume;
            player.SetPlayerVolume(UI_VolumeBar.Value, UI_VolumeBar.Value);
        }
Esempio n. 2
0
        private void LoadSelectedImage()
        {
            TreeNode selected = UI_FileList.SelectedNode;

            if (selected.Tag != null && selected.Tag is CASCFile)
            {
                CASCFile file = (CASCFile)selected.Tag;
                if (extractRunner != null)
                {
                    extractRunner.Kill();
                    extractRunner = null;
                }

                ClearImagePreview();

                UI_PreviewStatus.Text = "Loading...";
                UI_PreviewStatus.Show();

                string fullPath = Path.Combine(Constants.TEMP_DIRECTORY, file.FullName);
                if (File.Exists(fullPath))
                {
                    displayImage(fullPath);
                }
                else
                {
                    extractRunner = new RunnerExtractItem(file);
                    runnerID      = extractRunner.runnerID;
                    extractRunner.Begin();
                }
            }
        }
Esempio n. 3
0
        private void UI_FileList_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (UI_FileList.SelectedNode != null && UI_FileList.SelectedNode.Tag is CASCFile)
            {
                selectedFile    = null;
                selectedDbcFile = null;

                CASCFile cascFile = (CASCFile)UI_FileList.SelectedNode.Tag;
                string   tempPath = Path.Combine(Constants.TEMP_DIRECTORY, cascFile.FullName);
                selectedFile = cascFile;

                if (!File.Exists(tempPath))
                {
                    extractRunner = new RunnerExtractItem(cascFile);
                    runnerID      = extractRunner.runnerID;
                    extractRunner.Begin();

                    loadingWindow = new LoadingWindow("Loading DBC file: " + cascFile.Name, "Life advice: Avoid dragon's breath.", true, cancelCallback);
                    loadingWindow.ShowDialog();
                }
                else
                {
                    ShowDBCFile(tempPath);
                }
            }
        }
Esempio n. 4
0
        private void Explore(CASCFolder folder)
        {
            foreach (KeyValuePair <string, ICASCEntry> node in folder.Entries)
            {
                ICASCEntry entry = node.Value;

                if (entry is CASCFolder)
                {
                    Explore((CASCFolder)entry);
                }
                else if (entry is CASCFile)
                {
                    CASCFile file = (CASCFile)entry;

                    // Check we have a valid extension.
                    if (!IsValidExtension(file))
                    {
                        continue;
                    }

                    // Ensure the file matches the filter.
                    if (!MatchesFilter(file.FullName))
                    {
                        continue;
                    }

                    EventManager.Trigger_FileExploreHit(id, file);
                }

                Thread.Sleep(2);
            }
        }
Esempio n. 5
0
        private void OnExploreHit(CASCFile file)
        {
            string[] parts = file.FullName.Split(new char[] { '/', '\\' });

            // Ignore noLiquid tiles.
            string fileName = parts[parts.Length - 1];

            if (fileName.StartsWith("noLiquid"))
            {
                return;
            }

            string mapName = parts[2];

            if (!mapName.ToLower().Equals("wmo"))
            {
                if (!maps.ContainsKey(mapName))
                {
                    UI_FileList.Nodes.Add(mapName);
                    maps.Add(mapName, new List <CASCFile>());
                }

                maps[mapName].Add(file);
                UpdateSearchState(Constants.SEARCH_STATE_SEARCHING);

                // "Cheap" way to find the map entry point without
                // reading DBC files. Used by exporter for non-full exports.
                Point point;

                if (!mapStartPoints.ContainsKey(mapName))
                {
                    point = new Point(63, 63);
                    mapStartPoints.Add(mapName, point);
                }
                else
                {
                    point = mapStartPoints[mapName];
                }

                Match match = mapTilePattern.Match(fileName);
                if (match.Success)
                {
                    int lowX = int.Parse(match.Groups[1].Value);
                    int lowY = int.Parse(match.Groups[2].Value);

                    if (lowX < point.X)
                    {
                        point.X = lowX;
                    }
                    if (lowY < point.Y)
                    {
                        point.Y = lowY;
                    }

                    mapStartPoints[mapName] = point;
                }
            }
        }
Esempio n. 6
0
    /// <summary>
    /// Create a Texture2D in memory from a BLP image file
    /// </summary>
    /// <param name="file"></param>
    public Texture2D BlpToTexture2d(CASCFile file)
    {
        Texture2D blpTex = null;

        using (var blp = new BlpFile(new MemoryStream(CascFileBytes(file)))) {
            blpTex = blp.GetTexture2d(0); // getting mipmap 0, TODO: get all mipmaps
        }
        return(blpTex);
    }
Esempio n. 7
0
        private bool IsValidExtension(CASCFile file)
        {
            foreach (string extension in extensions)
            {
                if (file.Name.ToLower().EndsWith(extension))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 8
0
        public void OnExploreHit(CASCFile file)
        {
            Match match = ignoreFilter.Match(file.Name);

            if (match.Success)
            {
                string nameBase = match.Groups[1].ToString();
                if (!groupFiles.ContainsKey(nameBase))
                {
                    groupFiles.Add(nameBase, new List <CASCFile>());
                }

                groupFiles[nameBase].Add(file);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Returns a byte array representing the bytes of a specific CASC file. Used to create new MemoryStreams.
 /// </summary>
 /// <param name="file">This CASCFile should come from the CASCFiles List.</param>
 /// <returns></returns>
 public byte[] CascFileBytes(CASCFile file)
 {
     try {
         var input = storage.OpenFile(file.FullPath);
         using (var output = new MemoryStream()) {
             System.IntPtr pspanPointer;
             CASCFunc.CASC_FILE_FULL_INFO fileInfo;
             if (input.GetInfo(out fileInfo, out pspanPointer))
             {
                 for (int i = 0; i < fileInfo.SpanCount; i++)
                 {
                     var pspan      = Marshal.PtrToStructure <CASCFunc.CASC_FILE_SPAN_INFO>(IntPtr.Add(pspanPointer, i * Marshal.SizeOf(typeof(CASCFunc.CASC_FILE_SPAN_INFO))));
                     int cbFileSpan = (int)(pspan.EndOffset - pspan.StartOffset);
                     if (cbFileSpan == 0)
                     {
                         continue;
                     }
                     byte[] buffer;
                     int    bytesRead;
                     bool   readOK = input.Read(out buffer, cbFileSpan, out bytesRead);
                     if (readOK)
                     {
                         output.Write(buffer, 0, bytesRead);
                         if (bytesRead < cbFileSpan)
                         {
                             break;
                         }
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             output.Position = 0;
             byte[] bytes = output.ToArray();
             return(bytes);
         }
     }
     catch (Exception ex) {
         Debug.LogError(ex);
         return(null);
     }
 }
Esempio n. 10
0
        private void Explore(CASCFolder folder)
        {
            foreach (KeyValuePair <string, ICASCEntry> node in folder.Entries)
            {
                ICASCEntry entry = node.Value;

                if (entry is CASCFolder)
                {
                    Explore((CASCFolder)entry);
                }
                else if (entry is CASCFile)
                {
                    CASCFile file = (CASCFile)entry;
                    if (file.Name.ToLower().Contains("illidan2"))
                    {
                        new RunnerExtractItem(file).Begin();
                        return;
                    }
                }
            }
        }
Esempio n. 11
0
        private void UI_FileList_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = UI_FileList.SelectedNode;

            if (node != null && node.Tag is CASCFile)
            {
                CASCFile file = (CASCFile)node.Tag;
                TerminateRunners();

                extractModelFile = null;
                extractSkinFile  = null;

                selectedFileName = file.Name;
                string skinFile = skinPattern.Replace(file.FullName, "00.skin");
                runner = new RunnerExtractItemUnsafe(file.FullName, skinFile);
                runner.Begin();

                loadingWindow = new LoadingWindow(string.Format("Loading {0} model...", Path.GetFileNameWithoutExtension(selectedFileName)), "Extracting from data source...", true, cancelCallback);
                loadingWindow.ShowDialog();
            }
        }
Esempio n. 12
0
        private void UI_FileList_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (UI_FileList.SelectedNode != null && UI_FileList.SelectedNode.Tag is CASCFile)
            {
                // Dispose current loaded file.
                if (loadedFile != null)
                {
                    loadedFile.flush();
                    loadedFile = null;
                }

                TerminateRunners();

                CASCFile entry    = (CASCFile)UI_FileList.SelectedNode.Tag;
                string   rootBase = Path.GetFileNameWithoutExtension(entry.FullName);

                currentFiles = new List <CASCFile>();
                currentFiles.Add(entry); // Root file.

                // Collect group files for extraction.
                if (groupFiles.ContainsKey(rootBase))
                {
                    foreach (CASCFile groupFile in groupFiles[rootBase])
                    {
                        currentFiles.Add(groupFile);
                    }
                }

                wmoDoneCount         = 0;
                wmoRunner            = new RunnerExtractItem(currentFiles.ToArray());
                wmoRunner.CacheCheck = true;
                wmoRunner.Begin();

                loadingWindow = new LoadingWindow("Loading WMO file: " + entry.Name, "No peons were harmed in the making of this software.", true, cancelCallback);
                loadingWindow.ShowDialog();
            }
        }
Esempio n. 13
0
 public FileExtractCompleteArgs(CASCFile file, bool success, int runnerID) : base(success, runnerID)
 {
     File = file;
 }
Esempio n. 14
0
    public (Mesh, Texture2D[]) M2ToMesh(CASCFile file)
    {
        Mesh         m2Mesh = new Mesh();
        BinaryReader br     = new BinaryReader(new MemoryStream(CascFileBytes(file))); // New BinaryReader for the file in MemoryStream

        br.BaseStream.Seek(0, SeekOrigin.Begin);                                       // Go the the beginning of the stream

        // Manually Parsing the File

        /*
         * while (br.BaseStream.Position < br.BaseStream.Length) {                      // Advance the reader position until the end of the file
         *  //string chunkID = System.Text.Encoding.UTF8.GetString(br.ReadBytes(4)); // Reading first 4 bytes of a chunk will give us the ID
         *  //int chunkID = (int)br.ReadUInt32();                                    // Maybe better to use INT for performance, opting for string for readability
         *  ChunkID chunkID = (ChunkID)br.ReadUInt32();
         *  long chunkSize = (long)br.ReadUInt32();                                  // Get the size in bytes of the current chunk
         *  long nextChunkPos = br.BaseStream.Position + chunkSize;                  // The next chunk will be from the current reader's position + size of current chunk
         *
         *  // Process current chunk
         *  switch (chunkID) {
         *      case ChunkID.MD21:  // MD21 Header
         *          ParseChunkMD21();
         *          break;
         *      case ChunkID.SFID:  // Skin File IDs
         *          ParseChunkSFID();
         *          break;
         *      case ChunkID.TXID:  // Texture File IDs
         *          ParseChunkTXID();
         *          break;
         *  }
         *  br.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin);  // Advance the reader position to the the next chunk and proceed with loop
         *  Debug.Log("Processed ChunkID: " + chunkID);          // Name of current chunk
         * }*/

        var model = new M2();

        model.Load(br);

        //Debug.Log(model.Name + " loaded");
        //Debug.Log(model.Version);
        Debug.Log("nViews: " + model.nViews);
        Debug.Log("Texture Count: " + model.Textures.Count);
        Texture2D[] textures = new Texture2D[model.Textures.Count];
        for (int i = 0; i < model.Textures.Count; i++)
        {
            Debug.Log("Texture File: " + model.Textures[i].Name + "FileDataID: " + model.Textures[i].FileDataID);
            Texture2D tex = BlpToTexture2d(GetCascFile(model.Textures[i].FileDataID));
            textures[i] = tex;
        }

        if (model.Views.Count > 0)
        {
            for (int i = 0; i < model.Views.Count; i++)
            {
                //var substream = stream.BaseStream as Substream;
                //var path = substream != null ? ((FileStream)substream.GetInnerStream()).Name : ((FileStream)stream.BaseStream).Name;
                //using (var skinFile = new BinaryReader(new FileStream(M2SkinProfile.SkinFileName(path, i), FileMode.Open)))
                using (var skinFile = new BinaryReader(new MemoryStream(CascFileBytes(GetCascFile(model.Views[i].FileDataID))))) {
                    model.Views[i].Load(skinFile, model.Version);
                    model.Views[i].LoadContent(skinFile, model.Version);
                }
                Debug.Log("Skin File: " + model.Views[i].FileDataID);
            }
        }

        Vector3[] vertices = new Vector3[model.GlobalVertexList.Count];
        Vector3[] normals  = new Vector3[model.GlobalVertexList.Count];
        Vector2[] uv1      = new Vector2[model.GlobalVertexList.Count];
        Vector2[] uv2      = new Vector2[model.GlobalVertexList.Count];

        int index = 0;

        foreach (M2Vertex v in model.GlobalVertexList)
        {
            vertices[index] = new Vector3(v.Position.y, v.Position.z, -v.Position.x);
            normals[index]  = new Vector3(v.Normal.y, v.Normal.z, -v.Normal.x);
            uv1[index]      = v.TexCoords[0];
            uv2[index]      = v.TexCoords[1];
            index++;
        }

        int[] triangles = new int[model.Views[0].Triangles.Count];
        for (int i = 0; i < model.Views[0].Triangles.Count; i++)
        {
            triangles[i] = (int)model.Views[0].Triangles[i];
        }

        // Compltely Wrong

        /*
         * for (int i = 0; i < model.Views[0].Submeshes.Count; i++) {
         *  M2SkinSection sub = model.Views[0].Submeshes[i];
         *  SubMeshDescriptor smd = new SubMeshDescriptor();
         *  smd.baseVertex = sub.StartVertex;
         *  Bounds bounds = new Bounds(sub.CenterBoundingBox, new Vector3(sub.Radius, sub.Radius, sub.Radius)); // radius isn't correct
         *  smd.bounds = bounds;
         *  smd.firstVertex = 0; ///?
         *  smd.indexCount = 3;
         *  smd.indexStart = sub.StartVertex;
         *  smd.topology = MeshTopology.Triangles;
         *  smd.vertexCount = sub.NVertices;
         *  m2Mesh.SetSubMesh(i, smd, MeshUpdateFlags.Default);
         * }*/

        m2Mesh.vertices  = vertices;
        m2Mesh.normals   = normals;
        m2Mesh.triangles = triangles.Reverse().ToArray(); // Reverses the faces
        m2Mesh.uv        = uv1;
        m2Mesh.uv2       = uv2;
        return(m2Mesh, textures);
    }
Esempio n. 15
0
        public override void Work()
        {
            if (!Program.IsCASCReady)
            {
                return;
            }

            positions = new MapTileXY[files.Length];
            MapTileBounds bounds = new MapTileBounds();

            for (int i = 0; i < files.Length; i++)
            {
                CASCFile file     = files[i];
                string   tileName = Path.GetFileNameWithoutExtension(file.FullName);
                Match    match    = pattern.Match(tileName);

                if (match.Success)
                {
                    int tileX = int.Parse(match.Groups[1].Value);
                    int tileY = int.Parse(match.Groups[2].Value);

                    // Update bounds.
                    if (bounds.LowX == -1 || tileX < bounds.LowX)
                    {
                        bounds.LowX = tileX;
                    }
                    if (bounds.HighX == -1 || tileX > bounds.HighX)
                    {
                        bounds.HighX = tileX;
                    }
                    if (bounds.LowY == -1 || tileY < bounds.LowY)
                    {
                        bounds.LowY = tileY;
                    }
                    if (bounds.HighY == -1 || tileY > bounds.HighY)
                    {
                        bounds.HighY = tileY;
                    }

                    positions[i] = new MapTileXY(tileX, tileY);
                }
                else
                {
                    // This should not happen.
                    positions[i] = new MapTileXY(0, 0);
                }
            }

            for (int i = 0; i < files.Length; i++)
            {
                CASCFile  file     = files[i];
                MapTileXY position = positions[i];

                string tempPath = Path.Combine(Constants.TEMP_DIRECTORY, file.FullName);

                // Extract the file if we don't already have it cached.
                if (!File.Exists(tempPath))
                {
                    try
                    {
                        Program.CASCEngine.SaveFileTo(file.FullName, Constants.TEMP_DIRECTORY);
                    }
                    catch (Exception e)
                    {
                        Log.Write("Warning: Unable to extract minimap tile {0} -> {1}", file.FullName, e.Message);
                    }
                }

                if (File.Exists(tempPath))
                {
                    EventManager.Trigger_MinimapTileDone(position, bounds, tempPath, Index);
                }
            }
        }
Esempio n. 16
0
 //public FileExploreHitArgs(string identifier, StringHashPair file)
 public FileExploreHitArgs(string identifier, CASCFile entry)
 {
     ID = identifier;
     //File = file;
     Entry = entry;
 }