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
        public static List <WorldSpawn> getSpawns(AssetDatabase adb, DB db, string world)
        {
            List <WorldSpawn>   worlds = new List <WorldSpawn>();
            IEnumerable <entry> keys   = db.getEntriesForID(4479);

            foreach (entry e in keys)
            {
                byte[] data = e.decompressedData;
                using (MemoryStream ms = new MemoryStream(data))
                {
                    CObject obj               = Parser.processStreamObject(ms);
                    string  worldName         = obj.getStringMember(0);
                    string  imagePath         = obj.getStringMember(5);
                    string  internalSpawnName = obj.getStringMember(1);
                    string  spawnName         = getLocalized(obj.getMember(10), internalSpawnName);
                    if (world != null)
                    {
                        if (!worldName.Equals(world))
                        {
                            continue;
                        }
                    }
                    try
                    {
                        Vector3 pos   = obj.getVector3Member(2);
                        float   angle = angle = obj.getFloatMember(3, 0);
                        pos.y += 2;

                        if (adb.filenameExists(worldName + "_map.cdr"))
                        {
                            WorldSpawn ws = new WorldSpawn(worldName, spawnName, pos, angle);
                            ws.imagePath = imagePath;
                            worlds.Add(ws);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("Unable to get position for spawn [" + e.id + "][" + e.key + "]" + ex);
                    }
                }
            }
            return(worlds);
        }
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;
        }