Exemple #1
0
        public void testInit()
        {
            EdataManager dataManager = new EdataManager(NDF_PATH);

            dataManager.ParseEdataFile();
            NdfbinManager everything = dataManager.ReadNdfbin(EVERYTHING_NDFBIN);

            List <NdfObject> unitInstances = everything.GetClass("TUniteAuSolDescriptor").Instances;

            // setup localisation/unites.dic reader
            EdataManager dataManager2 = new EdataManager(ZZ_PATH);

            dataManager2.ParseEdataFile();
            TradManager dict = dataManager2.ReadDictionary(UNITES_DIC);

            // unit icons
            EdataManager zz4File = new EdataManager(ZZ4_PATH);

            zz4File.ParseEdataFile();
            EdataManager iconPackage = zz4File.ReadPackage(ICON_PACKAGE);

            UnitDatabase unitDatabase = new UnitDatabase(unitInstances, dict, iconPackage, PACT_ICONS_DIRPREFIX, NATO_ICONS_DIRPREFIX);

            List <String> countries = unitDatabase.getAllCountries();

            CollectionAssert.AllItemsAreUnique(countries);
            Assert.IsTrue(countries.Count > 0);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);
        }
Exemple #3
0
        public void LoadNdfbin()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);

            Assert.IsTrue(ndfbin.Classes.Count > 0);
        }
Exemple #4
0
        public UnitDatabase getUnitDatabase(Form1 caller, String version)
        {
            // We deregister the requesting form from whatever previous version it was using,
            // register it with the new version and create or find a database for it.


            // deregister
            foreach (List <Form1> item in databaseIndex.Values)
            {
                item.Remove(caller);
            }

            // Check if a database exists or if we will have to create:
            List <Form1> val = null;

            if (databaseIndex.TryGetValue(version, out val) && val.Any())
            {
                UnitDatabase result = val.First().unitDatabase.clone();

                // register
                val.Add(caller);

                return(result);
            }
            else
            {
                // register
                val = new List <Form1>();
                val.Add(caller);
                databaseIndex.Remove(version);
                databaseIndex.Add(version, val);

                // create
                EdataManager dataManager = new EdataManager(singleton.paths.getNdfPath(version));
                try {
                    dataManager.ParseEdataFile();
                }
                catch (System.IO.IOException) {
                    Program.warning("IOException thrown, could not parse " + singleton.paths.getNdfPath()
                                    + ".\nIf wargame is running, you'll have to close it to use the tool. You can avoid this by copying the files listed in settings.ini and then editing settings.ini to point to the copies.");
                }

                NdfbinManager    everything    = dataManager.ReadNdfbin(EVERYTHING_NDFBIN);
                List <NdfObject> unitInstances = everything.GetClass("TUniteAuSolDescriptor").Instances;

                UnitDatabase database = new UnitDatabase(unitInstances, dict, iconPackage, PACT_ICONS_DIRPREFIX, NATO_ICONS_DIRPREFIX);
                // Transfer weapon lock
                if (caller.unitDatabase != null && caller.unitDatabase.getLockIndexedWeapon() != null)
                {
                    database.setCurrentWeapon(caller.unitDatabase.getLockIndexedWeapon());
                    database.lockWeapon();
                }

                return(database);
            }
        }
Exemple #5
0
        public void LoadClass()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass      claass = ndfbin.GetClass(className);

            Assert.IsTrue(claass.Instances.Count > 0);
        }
Exemple #6
0
        public void LoadInstance()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass      claass = ndfbin.GetClass(className);
            NdfObject     obj    = claass.Instances[0];

            Assert.IsTrue(obj.PropertyValues.Count > 0);
        }
Exemple #7
0
        public void ReadCost()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass      claass = ndfbin.GetClass("TUniteDescriptor");
            NdfObject     obj    = claass.Instances[1];
            NdfUInt32     refef;

            Assert.IsTrue(obj.TryGetValueFromQuery <NdfUInt32>(UNIT_REA_COST, out refef));
        }
Exemple #8
0
        public void LoadProperty()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass      claass = ndfbin.GetClass(className);
            NdfObject     obj    = claass.Instances[1];

            NdfString uint32;

            obj.TryGetValueFromQuery <NdfString>(UNIT_ICON, out uint32);
        }
Exemple #9
0
        public void QueryReference()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager      ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass           claass = ndfbin.GetClass("TUniteDescriptor");
            NdfObject          obj    = claass.Instances[1];
            NdfObjectReference refef;

            string query = "Modules.TypeUnit.Default";

            Assert.IsTrue(obj.TryGetValueFromQuery <NdfObjectReference>(query, out refef));
        }
        public void TestGettingFile()
        {
            EdataManager datamanager = new EdataManager(Environment.CurrentDirectory + "/data/NDF_Win.dat");

            datamanager.ParseEdataFile();

            NdfbinManager ndfFile = datamanager.ReadNdfbin("pc\\ndf\\patchable\\gfx\\everything.ndfbin");

            Assert.IsNotNull(ndfFile);
            Assert.IsTrue(ndfFile.Classes.Count > 1);


            NdfClass ammoClass = ndfFile.GetClass("TAmmunition");

            foreach (NdfObject ammo in ammoClass.Instances)
            {
                NdfValueWrapper val;
                Assert.IsTrue(ammo.TryGetValueFromPath("TempsEntreDeuxTirs", out val));
            }
        }
Exemple #11
0
        public void ReadDictionaryEntry()
        {
            EdataManager datamana = new EdataManager(ndffile);

            datamana.ParseEdataFile();
            NdfbinManager       ndfbin = datamana.ReadNdfbin(ndfbinfile);
            NdfClass            claass = ndfbin.GetClass("TUniteDescriptor");
            NdfObject           obj    = claass.Instances[1];
            NdfLocalisationHash refef;
            string query = "Modules.TypeUnit.Default.DescriptionHintToken";

            Assert.IsTrue(obj.TryGetValueFromQuery <NdfLocalisationHash>(query, out refef));

            EdataManager dic = new EdataManager(trans);

            dic.ParseEdataFile();
            TradManager trad   = dic.ReadDictionary(transFile);
            string      output = string.Empty;

            Assert.IsTrue(trad.TryGetString(refef.Value, out output)); // get LOSAT's description
        }
Exemple #12
0
 public CollectionItemValueHolder(NdfValueWrapper value, NdfbinManager manager, long instanceOffset)
 {
     Value          = value;
     Manager        = manager;
     InstanceOffset = instanceOffset;
 }
        public bool TryGetNdfbinFileFromFolder(string folder, string filename, string ndfbinfile, out NdfbinManager ndfbin)
        {
            ndfbin = null;
            DirectoryInfo folderInfo = new DirectoryInfo(folder);
            FileInfo[] fileInfos = folderInfo.GetFiles(filename, SearchOption.TopDirectoryOnly);
            if (fileInfos.Length <= 0)
                return false;

            EdataManager dataManager = new EdataManager(fileInfos[0].FullName);
            dataManager.ParseEdataFile();
            try
            {
                ndfbin = dataManager.ReadNdfbin(ndfbinfile);
                return true;
            }
            catch
            {
                // TODO : Dump error to log
            }
            return false;
        }
 public MapValueHolder(NdfValueWrapper value, NdfbinManager manager, long instanceOffset) : base(value, manager, instanceOffset)
 {
 }
 public NdfClass(NdfbinManager mgr)
 {
     Manager = mgr;
 }
        public static NdfValueWrapper GetValue(byte[] data, NdfType type, NdfbinManager mgr, long pos)
        {
            //if (data.Length != SizeofType(type))
            //    return null;

            switch (type)
            {
            case NdfType.Boolean:
                return(new NdfBoolean(BitConverter.ToBoolean(data, 0), pos));

            case NdfType.Int8:
                return(new NdfInt8(data[0], pos));

            case NdfType.Int16:
                return(new NdfInt16(BitConverter.ToInt16(data, 0), pos));

            case NdfType.Int32:
                return(new NdfInt32(BitConverter.ToInt32(data, 0), pos));

            case NdfType.UInt32:
                return(new NdfUInt32(BitConverter.ToUInt32(data, 0), pos));

            case NdfType.Float32:
                return(new NdfSingle(BitConverter.ToSingle(data, 0), pos));

            case NdfType.Float64:
                return(new NdfDouble(BitConverter.ToDouble(data, 0), pos));

            case NdfType.Float64_2:
                return(new NdfDouble_2(BitConverter.ToDouble(data, 0), pos));

            case NdfType.TableStringFile:
                var id = BitConverter.ToInt32(data, 0);
                return(new NdfFileNameString(mgr.Strings[id], pos));

            case NdfType.TableString:
                var id2 = BitConverter.ToInt32(data, 0);
                return(new NdfString(mgr.Strings[id2], pos));

            case NdfType.Color32:
                return(new NdfColor32(Color.FromArgb(data[0], data[1], data[2], data[3]), pos));

            case NdfType.Color128:
                return(new NdfColor128(data, pos));

            case NdfType.Vector:
                var px = data.Take(4).ToArray();
                var py = data.Skip(4).Take(4).ToArray();
                var pz = data.Skip(8).ToArray();
                return(new NdfVector(new Point3D(BitConverter.ToSingle(px, 0),
                                                 BitConverter.ToSingle(py, 0),
                                                 BitConverter.ToSingle(pz, 0)), pos));

            case NdfType.ObjectReference:
                var instId = BitConverter.ToUInt32(data.Take(4).ToArray(), 0);
                var clsId  = BitConverter.ToUInt32(data.Skip(4).ToArray(), 0);
                var cls    = mgr.Classes.SingleOrDefault(x => x.Id == clsId);  // mgr.Classes[(int)clsId]; due to deadrefs...
                return(new NdfObjectReference(cls, instId, pos, cls == null));

            case NdfType.Map:
                return(new NdfMap(new MapValueHolder(null, mgr, 0), new MapValueHolder(null, mgr, 0), pos));

            case NdfType.Guid:
                return(new NdfGuid(new Guid(data), pos));

            case NdfType.WideString:
                return(new NdfWideString(Encoding.Unicode.GetString(data), 0));

            case NdfType.TransTableReference:
                var id3 = BitConverter.ToInt32(data, 0);
                return(new NdfTrans(mgr.Trans[id3], pos));

            case NdfType.LocalisationHash:
                return(new NdfLocalisationHash(data, 0));

            case NdfType.Unset:
                return(new NdfNull(pos));

            default:
                return(null);
            }
        }
Exemple #17
0
        static void Main()
        {
            // Print all uncaught exceptions.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(
                delegate(Object sender, UnhandledExceptionEventArgs e) {
                warning(e.ExceptionObject.ToString());
            }
                );

            // Free resources before exiting.
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(cleanup);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            PathFinder paths = new PathFinder();

            // setup everything.ndfbin reader
            // EdataManager dataManager = new EdataManager(AppDomain.CurrentDomain.BaseDirectory + "NDF_Win.dat");
            EdataManager dataManager = new EdataManager(paths.getNdfPath());

            try {
                dataManager.ParseEdataFile();
            }
            catch (System.IO.IOException) {
                warning("IOException thrown, could not parse " + paths.getNdfPath()
                        + ".\nIf wargame is running, you'll have to close it to use the tool. You can avoid this by copying the files listed in settings.ini and then editing settings.ini to point to the copies.");
                Application.Exit();
                Environment.Exit(0);
            }
            NdfbinManager everything = dataManager.ReadNdfbin(EVERYTHING_NDFBIN);

            List <NdfObject> unitInstances = everything.GetClass("TUniteAuSolDescriptor").Instances;

            // setup localisation/unites.dic reader
            EdataManager dataManager2 = new EdataManager(paths.getZzPath());

            try {
                dataManager2.ParseEdataFile();
            }
            catch (System.IO.IOException) {
                warning("IOException thrown, could not parse " + paths.getZzPath()
                        + ".\nIf wargame is running, you'll have to close it to use the tool. You can avoid this by copying the files listed in settings.ini and then editing settings.ini to point to the copies.");
                Application.Exit();
                Environment.Exit(0);
            }

            TradManager dict = null;

            try {
                dict = dataManager2.ReadDictionary(UNITES_DIC);
            } catch (Exception) {
                warning("Failed reading ZZ_Win.dat. May have selected an incomplete one - try pointing settings.ini to a complete ZZ_Win.dat file.");
                Application.Exit();
                Environment.Exit(0);
            }

            // unit icons
            EdataManager zz4File = new EdataManager(paths.getZz4Path());

            try {
                zz4File.ParseEdataFile();
            }
            catch (System.IO.IOException) {
                warning("IOException thrown, could not parse " + paths.getZz4Path()
                        + ".\nIf wargame is running, you'll have to close it to use the tool. You can avoid this by copying the files listed in settings.ini and then editing settings.ini to point to the copies.");
                Application.Exit();
                Environment.Exit(0);
            }

            EdataManager iconPackage = null;

            try {
                iconPackage = zz4File.ReadPackage(ICON_PACKAGE);
            } catch (Exception) {
                warning("Failed reading ZZ_4.dat. May have selected an incomplete one - try pointing settings.ini to a complete ZZ_4.dat file.");
                Application.Exit();
                Environment.Exit(0);
            }

            UnitDatabase unitDatabase = new UnitDatabase(unitInstances, dict, iconPackage, PACT_ICONS_DIRPREFIX, NATO_ICONS_DIRPREFIX);

            Application.Run(new Form1(unitDatabase, paths.autoUpdate));
        }