Beispiel #1
0
        private static List <Vector3> getPoints(CObject cObject)
        {
            List <Vector3> p = new List <Vector3>();

            for (int i = 0; i < cObject.members.Count; i++)
            {
                CObject v = cObject.get(i);
                p.Add(v.getVector3Member(0));
            }
            return(p);
        }
Beispiel #2
0
        private static List <Zone> getZones(string worldNameNoCDR)
        {
            List <Zone> zones = new List <Zone>();

            try
            {
                string        worldName = worldNameNoCDR + "_map.cdr";
                AssetDatabase adb       = AssetDatabaseInst.DB;
                if (!adb.getManifest().containsHash(Util.hashFileName(worldName)))
                {
                    throw new Exception("Unable to find world name:" + worldName);
                }
                Debug.Log("loading world zones:" + worldName);
                byte[]  data = adb.extractUsingFilename(worldName);
                CObject obj  = Parser.processStreamObject(data);

                CObject zonesObj = obj.getMember(8);
                Debug.Log("found zones object with " + zonesObj.members.Count + " members");
                for (int i = 0; i < zonesObj.members.Count; i++)
                {
                    CObject zoneObj = zonesObj.get(i);
                    long    key     = zoneObj.getIntMember(0);
                    //Debug.Log("found zone with key:" + key);
                    List <Vector3> points = getPoints(zoneObj.getMember(3));
                    Zone           zone   = new WorldStuff.Zone();
                    zone._113Key = key;
                    zone.name    = getZoneName(key);
                    zone.points  = points;
                    //zone.sky = getSky(key);
                    zones.Add(zone);
                }
            }catch (Exception ex)
            {
                Debug.LogWarning(ex);
            }
            return(zones);
        }
Beispiel #3
0
        static void processCDR(Stream ms, string cdrName, Action <ObjectPosition> addFunc, DB db)
        {
            try
            {
                CObject obj = Parser.processStreamObject(ms);

                if (obj.type != 107)
                {
                    throw new Exception("CDR file was not class 107");
                }



                List <CObject> members = obj.members;
                if (members.Count > 0)
                {
                    CObject first = members[0];
                    if (first.type == 11)
                    {
                        foreach (CObject child in first.members)
                        {
                            if (child.type == 600)
                            {
                                if (child.members.Count > 1)
                                {
                                    string  oname = child.getStringMember(1);
                                    CObject ary   = child.getMember(4);

                                    // child members in ary 602 and 603 contain references into the database under id 623
                                    // they point to object 628 which contains references to the actual NIF/HKX files
                                    long    nif_hkx_ref = long.MaxValue;
                                    CObject _602        = findFirstType(ary, 602);
                                    if (_602 == null)
                                    {
                                        UnityEngine.Debug.Log("no nif ref found for :" + oname);
                                    }
                                    else
                                    {
                                        bool visible = true;
                                        // this is not a visibility property? _602.getBoolMember(2, true);

                                        try
                                        {
                                            nif_hkx_ref = Convert.ToInt64(_602.get(0).convert());
                                            CObject _603 = findFirstType(ary, 603);

                                            Quaternion qut         = _603.getMember(4).readQuat();
                                            float      scale       = _603.getFloatMember(5, 1.0f);
                                            Vector3    translation = _603.getVector3Member(3);
                                            Vector3    centroid    = translation;
                                            if (_603.hasMember(9))
                                            {
                                                centroid = _603.getVector3Member(9);
                                            }

                                            Vector3 min = translation;
                                            Vector3 max = centroid;

                                            if (nif_hkx_ref != long.MaxValue)
                                            {
                                                CObject dbObj = getDBObj(db, 623, nif_hkx_ref);
                                                if (dbObj != null)
                                                {
                                                    CObject dbAry = dbObj.getMember(4);
                                                    CObject _7319 = findFirstType(dbAry, 7319);
                                                    //CObject _7318 = findFirstType(dbAry, 7318);
                                                    if (_7319 != null)
                                                    {
                                                        if (_7319.members.Count == 0)
                                                        {
                                                            // Collision only NIF, ignore it
                                                            // Debug.Log("empty 7319 for nif ref 623:" + nif_hkx_ref);
                                                        }
                                                        else
                                                        {
                                                            long    nifKey   = Convert.ToInt64(_7319.get(0).convert());
                                                            CObject _7305Obj = getDBObj(db, 7305, nifKey);
                                                            String  nif      = "" + _7305Obj.members[0].convert();

                                                            string nifFile = Path.GetFileName(nif);

                                                            Assets.ObjectPosition op = new Assets.ObjectPosition(nifFile, min, qut, max, scale);
                                                            op.index      = child.index;
                                                            op.cdrfile    = cdrName;
                                                            op.visible    = visible;
                                                            op.entityname = oname;

                                                            addFunc.Invoke(op);
                                                        }
                                                    }
                                                }
                                            }
                                            // does it have a light source?
                                            if (_602.hasMember(3))
                                            {
                                                Vector3 color           = _602.getVector3Member(3);
                                                float   r               = color.x;
                                                float   g               = color.y;
                                                float   b               = color.z;
                                                float   range           = _602.getFloatMember(4, 2.0f);
                                                Assets.LightPosition lp = new Assets.LightPosition(range, r, g, b, min, qut, max, scale);
                                                lp.visible    = visible;
                                                lp.index      = child.index;
                                                lp.cdrfile    = cdrName;
                                                lp.entityname = oname;

                                                addFunc.Invoke(lp);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.Log(ex);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("exception trying to process CDR:" + cdrName);
                Debug.Log(ex);
            }
            finally
            {
                //Debug.Log("process cdr[" + cdrName + "]: done in " + watch.ElapsedMilliseconds + " ms");
            }
            return;
        }