public CabFile(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (MemoryStream data = new MemoryStream())
            {
                stream.CopyTo(data);
                _data = data.ToArray();
            }
            _erf     = new ERF();
            _alloc   = new FNALLOC(FnAlloc);
            _free    = new FNFREE(FnFree);
            _close   = new FNCLOSE(FnClose);
            _open    = new FNOPEN(FnOpen);
            _read    = new FNREAD(FnRead);
            _write   = new FNWRITE(FnWrite);
            _seek    = new FNSEEK(FnSeek);
            _extract = new FNFDINOTIFY(FnNotifyExtract);

            _erfHandle = GCHandle.Alloc(_erf, GCHandleType.Pinned);
            _hfdi      = FDICreate(
                Marshal.GetFunctionPointerForDelegate(_alloc),
                Marshal.GetFunctionPointerForDelegate(_free),
                Marshal.GetFunctionPointerForDelegate(_open),
                Marshal.GetFunctionPointerForDelegate(_read),
                Marshal.GetFunctionPointerForDelegate(_write),
                Marshal.GetFunctionPointerForDelegate(_close),
                Marshal.GetFunctionPointerForDelegate(_seek)
                , -1, _erfHandle.AddrOfPinnedObject());
        }
Пример #2
0
        public void MeshLoads()
        {
            Settings.initializeSettings();
            String meshERFPath = "E:\\Program Files (x86)\\Steam\\steamapps\\common\\dragon age origins\\packages\\core\\data\\modelmeshdata.erf";

            ERF meshes = new ERF(meshERFPath);

            meshes.readKeyData();
            Assert.Greater(meshes.resourceCount, 0);
            int failures = 0;

            for (int i = 0; i < meshes.resourceCount; i++)
            {
                GFF temp = IO.findFile <GFF>(meshes.resourceNames[i]);
                Assert.NotNull(temp, "Not found: |" + meshes.resourceNames[i] + "|" + i);
                if (Path.GetExtension(meshes.resourceNames[i]) == ".msh")
                {
                    try
                    {
                        ModelMesh tempH = new ModelMesh(temp);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine(meshes.resourceNames[i]);
                        failures++;
                    }
                }
            }
            Assert.AreEqual(0, failures);
        }
Пример #3
0
 public static extern IntPtr FDICreate(
     FdiAllocFn pfna,
     FdiFreeFn pfnf,
     FdiOpenFn pfnopen,
     FdiReadFn pfnread,
     FdiWriteFn pfnwrite,
     FdiCloseFn pfnclose,
     FdiSeekFn pfnseek,
     int cputype,
     ref ERF perf);
Пример #4
0
        protected CabBase()
        {
            this.streamHandles = new HandleManager();
            this.erf           = new ERF();
            this.status        = new CabinetStatus();

            // 32K seems to be the size of the largest chunks processed by cabinet.dll.
            // But just in case, this buffer will auto-enlarge.
            this.buf = new byte[32768];
        }
Пример #5
0
 public static extern IntPtr FDICreate(
     FNALLOC pfnalloc,
     FNFREE pfnfree,
     FNOPEN pfnopen,
     FNREAD pfnread,
     FNWRITE pfnwrite,
     FNCLOSE pfnclose,
     FNSEEK pfnseek,
     int cpuType,
     ref ERF perf);
        //Returns a string listing all the contents of the ERF file with sizes and offsets
        public static String getERFContents(ERF file)
        {
            StringBuilder contents = new StringBuilder();

            contents.AppendFormat("{0} contains {1} files.{2}", file.path, file.resourceCount, Environment.NewLine);
            for (int i = 0; i < file.resourceCount; i++)
            {
                contents.AppendFormat("\t{0}: {1} at offset {2}{3}", file.resourceNames[i], IOUtilities.ToByteString(file.resourceLengths[i]), file.resourceOffsets[i], Environment.NewLine);
            }

            return(contents.ToString());
        }
Пример #7
0
 public static extern int FCICreate(
     ref ERF perf,
     FciFilePlacedFn pfnfcifp,
     FciAllocFn pfna,
     FciFreeFn pfnf,
     FciOpenFn pfnopen,
     FciReadFn pfnread,
     FciWriteFn pfnwrite,
     FciCloseFn pfnclose,
     FciSeekFn pfnseek,
     FciDeleteFn pfndelete,
     FciGetTempFileFn pfnfcigtf,
     ref CCAB pccab,
     IntPtr pv);
Пример #8
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed objects.
                if (this.erf != null)
                {
                    this.erf.Dispose();
                    this.erf = null;
                }
            }

            // Dispose unmanaged objects.
        }
        public static ERF getERF(String path)
        {
            ERF foundERF = null;

            foreach (ERF erf in erfFiles)
            {
                if (erf.path == path)
                {
                    foundERF = erf;
                    break;
                }
            }

            return(foundERF);
        }
Пример #10
0
        private static void HandleCategory(ERF e, Regex r, RandomizationLevel randomizationlevel)
        {
            switch (randomizationlevel)
            {
            default:
            case RandomizationLevel.None:
                break;     // Do nothing.

            case RandomizationLevel.Type:
                List <int> type = new List <int>(e.Key_List.Where(x => r.IsMatch(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                TypeLists.Add(type);
                break;

            case RandomizationLevel.Max:
                MaxRando.AddRange(e.Key_List.Where(x => r.IsMatch(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                break;
            }
        }
 public static void removeERF(ERF erf)
 {
     erfFileList.Remove(erf);
 }
Пример #12
0
        public static void texture_rando(KPaths paths)
        {
            // Prepare lists for new randomization.
            MaxRando.Clear();
            TypeLists.Clear();

            // Load in texture pack.
            string pack_name;

            switch (Properties.Settings.Default.TexturePack)
            {
            default:
            case TexturePack.HighQuality:
                pack_name = "\\swpc_tex_tpa.erf";
                break;

            case TexturePack.MedQuality:
                pack_name = "\\swpc_tex_tpb.erf";
                break;

            case TexturePack.LowQuality:
                pack_name = "\\swpc_tex_tpc.erf";
                break;
            }

            ERF e = new ERF(paths.TexturePacks + pack_name);

            foreach (var key in e.Key_List)
            {
                if (!NameLookup.ContainsKey(key.ResID))
                {
                    NameLookup.Add(key.ResID, key.ResRef);
                }
            }

            // Handle categories.
            HandleCategory(e, RegexCubeMaps, Properties.Settings.Default.TextureRandomizeCubeMaps);
            HandleCategory(e, RegexCreatures, Properties.Settings.Default.TextureRandomizeCreatures);
            HandleCategory(e, RegexEffects, Properties.Settings.Default.TextureRandomizeEffects);
            HandleCategory(e, RegexItems, Properties.Settings.Default.TextureRandomizeItems);
            HandleCategory(e, RegexPlanetary, Properties.Settings.Default.TextureRandomizePlanetary);
            HandleCategory(e, RegexNPC, Properties.Settings.Default.TextureRandomizeNPC);
            HandleCategory(e, RegexPlayHeads, Properties.Settings.Default.TextureRandomizePlayHeads);
            HandleCategory(e, RegexPlayBodies, Properties.Settings.Default.TextureRandomizePlayBodies);
            HandleCategory(e, RegexPlaceables, Properties.Settings.Default.TextureRandomizePlaceables);
            HandleCategory(e, RegexParty, Properties.Settings.Default.TextureRandomizeParty);
            HandleCategory(e, RegexStunt, Properties.Settings.Default.TextureRandomizeStunt);
            HandleCategory(e, RegexVehicles, Properties.Settings.Default.TextureRandomizeVehicles);
            HandleCategory(e, RegexWeapons, Properties.Settings.Default.TextureRandomizeWeapons);

            // Handle other.
            switch (Properties.Settings.Default.TextureRandomizeOther)
            {
            default:
            case RandomizationLevel.None:
                break;     // Do nothing.

            case RandomizationLevel.Type:
                List <int> type = new List <int>(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                TypeLists.Add(type);
                break;

            case RandomizationLevel.Max:
                MaxRando.AddRange(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                break;
            }

            // Max Rando.
            List <int> Max_Rando_Iterator = new List <int>(MaxRando);

            Randomize.FisherYatesShuffle(MaxRando);
            int j = 0;

            foreach (ERF.Key k in e.Key_List.Where(x => Max_Rando_Iterator.Contains(x.ResID)))
            {
                LookupTable.Add(k.ResID, MaxRando[j]);
                k.ResID = MaxRando[j];
                j++;
            }

            // Type Rando.
            foreach (List <int> li in TypeLists)
            {
                List <int> type_copy = new List <int>(li);
                Randomize.FisherYatesShuffle(type_copy);
                j = 0;
                foreach (ERF.Key k in e.Key_List.Where(x => li.Contains(x.ResID)))
                {
                    LookupTable.Add(k.ResID, type_copy[j]);
                    k.ResID = type_copy[j];
                    j++;
                }
            }

            e.WriteToFile(paths.TexturePacks + pack_name);
        }
Пример #13
0
 public static extern SafeHFDI FDICreate([In, MarshalAs(UnmanagedType.FunctionPtr)] PFNALLOC pfnalloc,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNFREE pfnfree,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNOPEN pfnopen,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNREAD pfnread,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNWRITE pfnwrite,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNCLOSE pfnclose,
                                         [In, MarshalAs(UnmanagedType.FunctionPtr)] PFNSEEK pfnseek, FDICPU cpuType, ref ERF perf);
Пример #14
0
 public static extern SafeHFCI FCICreate(ref ERF perf, [In] PFNFCIFILEPLACED pfnfcifp, [In] PFNALLOC pfna, [In] PFNFREE pfnf,
                                         [In] PFNFCIOPEN pfnopen, [In] PFNFCIREAD pfnread, [In] PFNFCIWRITE pfnwrite, [In] PFNFCICLOSE pfnclose, [In] PFNFCISEEK pfnseek,
                                         [In] PFNFCIDELETE pfndelete, [In] PFNFCIGETTEMPFILE pfnfcigtf, in CCAB pccab, [In, Optional] IntPtr pv);
Пример #15
0
 public static extern SafeHFDI FDICreate(PFNALLOC pfnalloc, PFNFREE pfnfree, PFNOPEN pfnopen, PFNREAD pfnread, PFNWRITE pfnwrite, PFNCLOSE pfnclose, PFNSEEK pfnseek, int cpuType, out ERF perf);
 private static void addERF(ERF erf)
 {
     erfFileList.Add(erf);
 }
Пример #17
0
 public static extern SafeHFCI FCICreate(out ERF perf, PFNFCIFILEPLACED pfnfcifp, PFNALLOC pfna, PFNFREE pfnf, PFNFCIOPEN pfnopen, PFNFCIREAD pfnread, PFNFCIWRITE pfnwrite, PFNFCICLOSE pfnclose, PFNFCISEEK pfnseek, PFNFCIDELETE pfndelete, PFNFCIGETTEMPFILE pfnfcigtf, in CCAB pccab, IntPtr pv);
 private void locationListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (locationListBox.SelectedItem != null)
     {
         String location = (String)locationListBox.SelectedItem;
         modelListBox.Items.Clear();
         if (Directory.Exists(location))
         {
             if (ResourceManager.filePaths.Contains(location))
             {
                 //Folder has been added, try to see if the erfs have been added, if not, throw error message. Then add all the contents of erf to modellist
                 foreach (String s in Directory.GetFiles(location, "*", SearchOption.AllDirectories))
                 {
                     if (Path.GetExtension(s) == ".erf")
                     {
                         ERF myErf = ResourceManager.getERF(s);
                         if (myErf != null)
                         {
                             foreach (String t in myErf.resourceNames)
                             {
                                 if (isDisplayableExtension(Path.GetExtension(t)))
                                 {
                                     modelListBox.Items.Add(t);
                                 }
                             }
                         }
                         else
                         {
                             Console.WriteLine("the given erf doens't exist in the erf list, the file path given is: {0}", s);
                         }
                     }
                     else if (isDisplayableExtension(Path.GetExtension(s)))
                     {
                         modelListBox.Items.Add(s);
                     }
                 }
             }
             else
             {
                 // If it appears in the location box, should be added already
                 Console.WriteLine("What're you doing here? This folder should be added already");
             }
         }
         else
         {
             // Not a direcotry, must be an ERF file
             ERF selectedERF = null;
             foreach (ERF erf in ResourceManager.erfFiles)
             {
                 if (erf.path == location)
                 {
                     selectedERF = erf;
                     break;
                 }
             }
             if (selectedERF == null)
             {
                 Console.WriteLine("SHIT");
             }
             else
             {
                 modelListBox.Items.Clear();
                 foreach (String s in selectedERF.resourceNames)
                 {
                     if (isDisplayableExtension(Path.GetExtension(s)))
                     {
                         modelListBox.Items.Add(s);
                     }
                 }
             }
         }
     }
 }