public NIFReference(DB db, long key) { CObject nifObj = db.toObj(7305, key); baseName = nifObj.getMember(2).convert().ToString(); if (nifObj.hasMember(5)) { Dictionary <int, CObject> dict = nifObj.getMember(5).asDict(); foreach (int race in dict.Keys) { CObject nifRaceObj = dict[race]; nifs[race] = new Dictionary <int, string>(); string malenif = nifRaceObj.getMember(0).convert().ToString(); if (nifRaceObj.hasMember(2)) { string femalenif = nifRaceObj.getMember(2).convert().ToString(); nifs[race][2] = femalenif; } nifs[race][0] = malenif; } } }
private void updateAnimDropbox() { animationSetDropdown.ClearOptions(); List <DOption> options = new List <DOption>(); options.Add(new DOption("unarmed", null)); HashSet <string> done = new HashSet <string>(); foreach (entry e in db.getEntriesForID(230)) { CObject _250 = db.toObj(e.id, e.key); if (_250.hasMember(7)) { string animation = _250.getStringMember(7); if (!done.Contains(animation) && !animation.Contains("crossbow") && !animation.Contains("shared")) { DOption option = new DOption(animation, e); options.Add(option); done.Add(animation); } } } options.Sort((a, b) => string.Compare(a.text, b.text)); animationSetDropdown.AddOptions(options.Cast <Dropdown.OptionData>().ToList()); }
public static void getMinMax(string worldName_, ref int x, ref int y) { string worldName = worldName_; if (!worldName_.Contains("cdr")) { worldName = worldName + "_map.cdr"; } AssetDatabase adb = AssetDatabaseInst.DB; System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); if (!adb.getManifest().containsHash(Util.hashFileName(worldName))) { throw new Exception("Unable to find world name:" + worldName); } byte[] data = adb.extractUsingFilename(worldName); //Debug.Log("extract in " + watch.ElapsedMilliseconds + " ms"); watch.Reset(); watch.Start(); CObject obj = Parser.processStreamObject(data); //Debug.Log("processStreamObject in " + watch.ElapsedMilliseconds + " ms"); watch.Reset(); watch.Start(); //Debug.Log("got world name:" + worldName); y = obj.getIntMember(3) * 256; if (obj.hasMember(2)) { x = obj.getIntMember(2) * 256; } else { x = y; } //Debug.Log("get min max in " + watch.ElapsedMilliseconds + " ms"); watch.Stop(); }
public ClothingItem(DB db, long id, long key) { this.key = key; this.id = id; try { CObject gearDef = db.toObj(id, key); if (id == 7629) { this.name = gearDef.getMember(0).convert() + ""; if (gearDef.hasMember(1)) { this.langKey = gearDef.getMember(1).getIntMember(0); } if (gearDef.hasMember(4)) { icon = db.toObj(6009, gearDef.getIntMember(4)).getStringMember(1); } if (gearDef.hasMember(5)) { CObject allowedSlotsArray = gearDef.getMember(5); foreach (CObject o in allowedSlotsArray.members) { int slot = int.Parse(o.convert() + ""); allowedSlots.Add(WardrobeStuff.getSlot(slot)); } } if (gearDef.hasMember(6)) { type = WardrobeStuff.getGearType(gearDef.getIntMember(6)); } if (gearDef.hasMember(7)) { hidden = gearDef.getBoolMember(7, false); } nifKey = gearDef.getIntMember(2); nifRef = new NIFReference(db, nifKey); } else if (id == 7305) { nifRef = new NIFReference(db, key); nifKey = key; if (gearDef.hasMember(2)) { string nifPath = gearDef.getMember(2).convert() + ""; this.name = System.IO.Path.GetFileName(nifPath); if (nifPath.Contains(@"\player\") && nifPath.Contains(@"\wings\")) { allowedSlots.Add(GearSlot.CAPE); } } if (gearDef.hasMember(15)) { CObject allowedSlotsArray = gearDef.getMember(15); foreach (CObject o in allowedSlotsArray.members) { int slot = int.Parse(o.convert() + ""); allowedSlots.Add(WardrobeStuff.getSlot(slot)); } } else { } } else { throw new Exception("Bad id:" + id); } } catch (Exception ex) { Debug.Log("Unable to process [" + this + "] nif reference:" + ex); } }
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; }