public static JSONPkg GenerateJSONPkg(ulong key, Dictionary <ulong, Record> map, CASCHandler handler) { if (!map.ContainsKey(key)) { return(new JSONPkg { Name = null }); } STUD stud = new STUD(Util.OpenFile(map[key], handler)); if (stud.Instances == null) { return(new JSONPkg { Name = null }); } if (stud.Instances[0] == null) { return(new JSONPkg { Name = null }); } IInventorySTUDInstance instance = stud.Instances[0] as IInventorySTUDInstance; if (instance == null) { return(new JSONPkg { Name = null }); } JSONPkg pkg = new JSONPkg { }; pkg.Name = Util.GetString(instance.Header.name, map, handler); pkg.Description = ListInventory.GetDescription(instance, map, handler); pkg.Subline = Util.GetString(instance.Header.available_in, map, handler); pkg.Key = key; pkg.Rarity = instance.Header.rarity.ToString(); if (instance is CreditItem) { pkg.Description = $"{(instance as CreditItem).Data.value} Credits"; } else if (instance is PortraitItem) { PortraitItem portrait = instance as PortraitItem; string s = "s"; if (portrait.Data.star == 1) { s = ""; } pkg.Description = $"Tier {portrait.Data.tier} - At least level {(portrait.Data.bracket - 11) * 10 + 1} - {portrait.Data.star} star{s}"; } pkg.Type = instance.Name.ToUpperInvariant(); return(pkg); }
public static Tuple <string, STUD, IInventorySTUDInstance> GetInventoryName(ulong key, Dictionary <ulong, Record> map, CASCHandler handler) { if (!map.ContainsKey(key)) { return(null); } STUD stud = new STUD(Util.OpenFile(map[key], handler)); if (stud.Instances == null) { return(null); } if (stud.Instances[0] == null) { return(null); } IInventorySTUDInstance instance = stud.Instances[0] as IInventorySTUDInstance; if (instance == null) { return(null); } return(new Tuple <string, STUD, IInventorySTUDInstance>(Util.GetString(instance.Header.name.key, map, handler), stud, instance)); }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { bool ex = System.Diagnostics.Debugger.IsAttached || flags.Expert; Console.Out.WriteLine("Listing Achievements"); foreach (ulong key in track[0x68]) { if (!map.ContainsKey(key)) { continue; } using (Stream input = Util.OpenFile(map[key], handler)) { if (input == null) { continue; } STUD stud = new STUD(input); if (stud.Instances == null || stud.Instances[0] == null) { continue; } Achievement achieve = stud.Instances[0] as Achievement; if (achieve == null) { continue; } string achievementName = Util.GetString(achieve.Header.name, map, handler); string achievementDescription = Util.GetString(achieve.Header.description1, map, handler); // string description2 = Util.GetString(achieve.Header.description2, map, handler); // Fancy popup description, only used for level 25 comp enabled achievement Tuple <string, STUD, IInventorySTUDInstance> reward = GetRewardItem(achieve.Header.reward, map, handler); string rewardName = reward.Item1; STUD rewardStud = reward.Item2; IInventorySTUDInstance rewardInstance = reward.Item3; if (ex) { Console.Out.WriteLine("{0} ({1:X16})", achievementName, GUID.LongKey(key)); } else { Console.Out.WriteLine(achievementName); } if (rewardName != null) { Console.Out.WriteLine("\tReward: {0} ({1} {2})", rewardName, rewardInstance.Header.rarity, rewardStud.Instances[0].Name); } if (achievementDescription != null) { Console.Out.WriteLine("\tDescription: {0}", achievementDescription); } } } }
public static string GetDescription(IInventorySTUDInstance instance, Dictionary <ulong, Record> map, CASCHandler handler) { if (instance.Header.description != 0) { using (Stream descStream = Util.OpenFile(map[instance.Header.description], handler)) { STUD description = new STUD(descStream); if (description.Instances == null) { return(null); } InventoryDescription desc = description.Instances[0] as InventoryDescription; if (desc == null) { return(null); } return(Util.GetString(desc.Header.str, map, handler)); } } return(null); }
public static void GetInventoryName(ulong key, bool ex, Dictionary <ulong, Record> map, CASCHandler handler, string heroName) { Tuple <string, STUD, IInventorySTUDInstance> data = GetInventoryName(key, map, handler); if (data == null) { return; } string name = data.Item1; STUD stud = data.Item2; IInventorySTUDInstance instance = data.Item3; if (name == null && instance.Name != stud.Manager.GetName(typeof(CreditItem))) { Console.Out.WriteLine("\t\t(Untitled-{0:X12}) ({1} {2})", GUID.LongKey(key), instance.Header.rarity, stud.Instances[0].Name); return; } #if OUTPUT_STUDINVENTORY Stream studStream = Util.OpenFile(map[key], handler); string filename = string.Format("{0}_{1}", instance.Name, name); foreach (var c in Path.GetInvalidFileNameChars()) { filename = filename.Replace(c, '_'); } string outFilename = string.Format("./STUDs/Inventory/{0}/{1}.stud", heroName, filename); string putPathname = outFilename.Substring(0, outFilename.LastIndexOf('/')); Directory.CreateDirectory(putPathname); Stream OutWriter = File.Create(outFilename); studStream.CopyTo(OutWriter); OutWriter.Close(); studStream.Close(); #endif string addt = string.Empty; if (instance.Name == stud.Manager.GetName(typeof(CreditItem))) { CreditItem credits = (CreditItem)instance; name = $"{credits.Data.value} Credits"; } if (instance.Name == stud.Manager.GetName(typeof(WeaponSkinItem))) { WeaponSkinItem weapon = (WeaponSkinItem)instance; addt = $" Index {weapon.Data.index}"; } if (ex) { Console.Out.WriteLine("\t\t{0} ({1} {2} in file {3:X16}){4}", name, instance.Header.rarity, stud.Instances[0].Name, GUID.LongKey(key), addt); } else { Console.Out.WriteLine("\t\t{0} ({1} {2}){3}", name, instance.Header.rarity, stud.Instances[0].Name, addt); } if (instance.Header.description != 0) { using (Stream descStream = Util.OpenFile(map[instance.Header.description], handler)) { STUD description = new STUD(descStream); if (description.Instances == null) { return; } InventoryDescription desc = description.Instances[0] as InventoryDescription; if (desc == null) { return; } string descriptionStr = Util.GetString(desc.Header.str, map, handler); if (!string.IsNullOrEmpty(descriptionStr)) { Console.Out.WriteLine("\t\t\t{0}", descriptionStr); } } } }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { string output = flags.Positionals[2]; foreach (ulong key in track[0x54]) { if (!map.ContainsKey(key)) { continue; } Dictionary <OWRecord, string> items = new Dictionary <OWRecord, string>(); using (Stream input = Util.OpenFile(map[key], handler)) { if (input == null) { continue; } STUD stud = new STUD(input); if (stud.Instances == null || stud.Instances[0] == null) { continue; } GlobalInventoryMaster master = stud.Instances[0] as GlobalInventoryMaster; if (master == null) { continue; } foreach (OWRecord record in master.StandardItems) { items[record] = "ACHIEVEMENT"; } for (int i = 0; i < master.Generic.Length; ++i) { string name = $"STANDARD_{ItemEvents.GetInstance().GetEvent(master.Generic[i].@event)}"; for (int j = 0; j < master.GenericItems[i].Length; ++j) { items[master.GenericItems[i][j]] = name; } } for (int i = 0; i < master.Categories.Length; ++i) { string name = ItemEvents.GetInstance().GetEvent(master.Categories[i].@event); for (int j = 0; j < master.CategoryItems[i].Length; ++j) { items[master.CategoryItems[i][j]] = name; } } for (int i = 0; i < master.ExclusiveOffsets.Length; ++i) { string name = $"LOOTBOX_EXCLUSIVE_{i:X}"; for (int j = 0; j < master.LootboxExclusive[i].Length; ++j) { items[master.LootboxExclusive[i][j].item] = name; } } } foreach (KeyValuePair <OWRecord, string> recordname in items) { OWRecord record = recordname.Key; string itemGroup = recordname.Value; if (!map.ContainsKey(record.key)) { continue; } STUD stud = new STUD(Util.OpenFile(map[record.key], handler)); if (stud.Instances == null) { continue; } IInventorySTUDInstance instance = (IInventorySTUDInstance)stud.Instances[0]; string name = Util.GetString(instance.Header.name.key, map, handler); if (name == null) { name = $"{GUID.LongKey(key):X12}"; } switch (instance.Name) { case "Spray": Console.Out.WriteLine("Extracting spray {0}...", name); ExtractLogic.Spray.Extract(stud, output, "Generic", name, itemGroup, track, map, handler, quiet, flags); break; case "Icon": Console.Out.WriteLine("Extracting icon {0}...", name); ExtractLogic.Icon.Extract(stud, output, "Generic", name, itemGroup, track, map, handler, quiet, flags); break; case "Portrait": PortraitItem portrait = instance as PortraitItem; ExtractLogic.Portrait.Extract(stud, output, "Generic", $"Tier {portrait.Data.tier}", itemGroup, track, map, handler, quiet, flags); break; default: continue; } } } }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { string output = flags.Positionals[2]; string[] validCommands = new string[] { "skin", "spray", "icon", "victory pose", "emote", "heroic intro" }; bool typeWildcard = true; List <string> types = new List <string>(); if (flags.Positionals.Length > 3) { types.AddRange(flags.Positionals[3].ToLowerInvariant().Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)); typeWildcard = types.Contains("*"); types = types.FindAll((string it) => validCommands.Contains(it)).ToList(); } if (!typeWildcard && types.Count == 0) { string cmdlist = ""; for (int i = 0; i < validCommands.Length; i++) { if (i != 0) { cmdlist += ", "; if (i == validCommands.Length - 1) { cmdlist += "or "; } } cmdlist += validCommands[i].ToString().ToLower(); } Console.Out.WriteLine("The output type was not a valid option. ({0})", cmdlist); return; } Dictionary <string, List <string> > heroTypes = new Dictionary <string, List <string> >(); Dictionary <string, bool> heroWildcard = new Dictionary <string, bool>(); Dictionary <string, Dictionary <string, List <ulong> > > heroIgnore = new Dictionary <string, Dictionary <string, List <ulong> > >(); bool heroAllWildcard = false; if (flags.Positionals.Length > 4 && flags.Positionals[4] != "*") { foreach (string pair in flags.Positionals[4].ToLowerInvariant().Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)) { List <string> data = new List <string>(pair.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)); string name = data[0]; data.RemoveAt(0); if (!heroTypes.ContainsKey(name)) { heroTypes[name] = new List <string>(); heroIgnore[name] = new Dictionary <string, List <ulong> >(); heroWildcard[name] = false; } if (data.Count > 0) { foreach (string d in data) { List <string> subdata = new List <string>(d.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); string subn = subdata[0]; subdata.RemoveAt(0); heroTypes[name].Add(subn); heroIgnore[name][subn] = new List <ulong>(); if (subdata.Count > 0) { foreach (string sd in subdata) { try { heroIgnore[name][subn].Add(ulong.Parse(sd, System.Globalization.NumberStyles.HexNumber)); } catch { } } } } } if (data.Count == 0 || data.Contains("*")) { heroWildcard[name] = true; } } } else { heroAllWildcard = true; } int replacementIndex = flags.WeaponSkinIndex; List <ulong> masters = track[0x75]; foreach (ulong masterKey in masters) { if (!map.ContainsKey(masterKey)) { continue; } STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler)); if (masterStud.Instances == null) { continue; } HeroMaster master = (HeroMaster)masterStud.Instances[0]; if (master == null) { continue; } if (master.Header.itemMaster.key == 0) { continue; } string heroName = Util.GetString(master.Header.name.key, map, handler); if (heroName == null) { continue; } if (heroAllWildcard) { if (!heroTypes.ContainsKey(heroName.ToLowerInvariant())) { heroTypes.Add(heroName.ToLowerInvariant(), new List <string>()); } if (!heroWildcard.ContainsKey(heroName.ToLowerInvariant())) { heroWildcard.Add(heroName.ToLowerInvariant(), true); } } if (!heroTypes.ContainsKey(heroName.ToLowerInvariant())) { continue; } InventoryMaster inventory = OpenInventoryMaster(master, map, handler); if (inventory == null) { continue; } Dictionary <OWRecord, string> items = new Dictionary <OWRecord, string>(); foreach (OWRecord record in inventory.Achievables) { items[record] = "ACHIEVEMENT"; } for (int i = 0; i < inventory.DefaultGroups.Length; ++i) { string name = $"STANDARD_{ItemEvents.GetInstance().GetEvent(inventory.DefaultGroups[i].@event)}"; for (int j = 0; j < inventory.Defaults[i].Length; ++j) { items[inventory.Defaults[i][j]] = name; } } for (int i = 0; i < inventory.ItemGroups.Length; ++i) { string name = ItemEvents.GetInstance().GetEvent(inventory.ItemGroups[i].@event); for (int j = 0; j < inventory.Items[i].Length; ++j) { items[inventory.Items[i][j]] = name; } } foreach (KeyValuePair <OWRecord, string> recordname in items) { OWRecord record = recordname.Key; string itemGroup = recordname.Value; if (!map.ContainsKey(record.key)) { continue; } STUD stud = new STUD(Util.OpenFile(map[record.key], handler)); if (stud.Instances == null) { continue; } IInventorySTUDInstance instance = (IInventorySTUDInstance)stud.Instances[0]; if (!typeWildcard && !types.Contains(instance.Name.ToLowerInvariant())) { continue; } string name = Util.GetString(instance.Header.name.key, map, handler); if (name == null) { name = $"Untitled-{GUID.LongKey(instance.Header.name.key):X12}"; continue; } if (!heroWildcard[heroName.ToLowerInvariant()] && !heroTypes[heroName.ToLowerInvariant()].Contains(name.ToLowerInvariant())) { continue; } switch (instance.Name) { case "Spray": Console.Out.WriteLine("Extracting spray {0} for {1}...", name, heroName); ExtractLogic.Spray.Extract(stud, output, heroName, name, itemGroup, track, map, handler, quiet, flags); break; case "Skin": List <ulong> ignoreList = new List <ulong>(); try { ignoreList = heroIgnore[heroName.ToLowerInvariant()][name.ToLowerInvariant()]; } catch { } Console.Out.WriteLine("Extracting {0} models and textures for {1}", name, heroName); ExtractLogic.Skin.Extract(master, stud, output, heroName, name, itemGroup, ignoreList, track, map, handler, quiet, flags, masterKey, replacementIndex); break; case "Icon": Console.Out.WriteLine("Extracting icon {0} for {1}...", name, heroName); ExtractLogic.Icon.Extract(stud, output, heroName, name, itemGroup, track, map, handler, quiet, flags); break; case "Emote": case "Victory Pose": case "Heroic Intro": Console.Out.WriteLine("Extracting {2} {0} for {1}...", name, heroName, instance.Name); ExtractLogic.ItemAnimation.Extract(record.key, stud, output, heroName, name, itemGroup, track, map, handler, quiet, flags); break; case "Voice Line": //Console.Out.WriteLine("Extracting voice line {0} for {1}...", name, heroName); //ExtractLogic.VoiceLine.Extract(master, stud, output, heroName, name, track, map, handler); break; } } } }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { string output = flags.Positionals[2]; HashSet <string> heroes = new HashSet <string>(); HashSet <string> heroBlank = new HashSet <string>(); Dictionary <string, HashSet <string> > heroSkin = new Dictionary <string, HashSet <string> >(); bool heroAllWildcard = false; if (flags.Positionals.Length > 3 && flags.Positionals[1] != "*") { foreach (string name in flags.Positionals[3].ToLowerInvariant().Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)) { string[] data = name.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); string realname = data[0]; heroes.Add(realname); data = data.Skip(1).ToArray(); if (data.Length == 0) { heroBlank.Add(realname); continue; } heroSkin[realname] = new HashSet <string>(); foreach (string skin in data) { heroSkin[realname].Add(skin); } } } else { heroAllWildcard = true; } List <ulong> masters = track[0x75]; foreach (ulong masterKey in masters) { if (!map.ContainsKey(masterKey)) { continue; } STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler)); if (masterStud.Instances == null) { continue; } HeroMaster master = (HeroMaster)masterStud.Instances[0]; if (master == null) { continue; } if (master.Header.itemMaster.key == 0) { continue; } string heroName = Util.GetString(master.Header.name.key, map, handler); if (heroName == null) { continue; } if (heroAllWildcard) { heroes.Add(heroName.ToLowerInvariant()); heroBlank.Add(heroName.ToLowerInvariant()); } if (!heroes.Contains(heroName.ToLowerInvariant())) { continue; } InventoryMaster inventory = OpenInventoryMaster(master, map, handler); if (inventory == null) { continue; } Dictionary <OWRecord, string> items = new Dictionary <OWRecord, string>(); foreach (OWRecord record in inventory.Achievables) { items[record] = "ACHIEVEMENT"; } for (int i = 0; i < inventory.DefaultGroups.Length; ++i) { string name = $"STANDARD_{ItemEvents.GetInstance().GetEvent(inventory.DefaultGroups[i].@event)}"; for (int j = 0; j < inventory.Defaults[i].Length; ++j) { items[inventory.Defaults[i][j]] = name; } } for (int i = 0; i < inventory.ItemGroups.Length; ++i) { string name = ItemEvents.GetInstance().GetEvent(inventory.ItemGroups[i].@event); for (int j = 0; j < inventory.Items[i].Length; ++j) { items[inventory.Items[i][j]] = name; } } Dictionary <string, WeaponSkinItem> weaponskins = new Dictionary <string, WeaponSkinItem>(); Console.Out.WriteLine("Finding weapon skins for {0}", heroName); foreach (KeyValuePair <OWRecord, string> recordname in items) { OWRecord record = recordname.Key; string itemGroup = recordname.Value; if (!map.ContainsKey(record.key)) { continue; } STUD stud = new STUD(Util.OpenFile(map[record.key], handler)); if (stud.Instances == null) { continue; } IInventorySTUDInstance instance = (IInventorySTUDInstance)stud.Instances[0]; WeaponSkinItem weapon = instance as WeaponSkinItem; if (weapon == null) { continue; } if (weapon.Data.index == 0) { continue; } string name = Util.GetString(instance.Header.name.key, map, handler); if (name == null) { name = $"Untitled-{GUID.LongKey(instance.Header.name.key):X12}"; continue; } weaponskins[name] = weapon; Console.Out.WriteLine("Found data for weapon skin {0}", name); } foreach (KeyValuePair <OWRecord, string> recordname in items) { OWRecord record = recordname.Key; string itemGroup = recordname.Value; if (!map.ContainsKey(record.key)) { continue; } STUD stud = new STUD(Util.OpenFile(map[record.key], handler)); if (stud.Instances == null) { continue; } IInventorySTUDInstance instance = (IInventorySTUDInstance)stud.Instances[0]; SkinItem skin = instance as SkinItem; if (skin == null) { continue; } string name = Util.GetString(instance.Header.name.key, map, handler); if (name == null) { name = $"Untitled-{GUID.LongKey(instance.Header.name.key):X12}"; continue; } if (heroBlank.Contains(heroName.ToLowerInvariant()) || heroSkin[heroName.ToLowerInvariant()].Contains(name.ToLowerInvariant())) { Console.Out.WriteLine("Saving textures for skin {0}", name); foreach (KeyValuePair <string, WeaponSkinItem> pair in weaponskins) { string output_real = string.Format("{0}{1}{4}{1}Weapon Skin{1}{2}{1}{3}{1}", output, System.IO.Path.DirectorySeparatorChar, Util.SanitizePath(pair.Key), Util.SanitizePath(name), Util.SanitizePath(heroName)); Dictionary <ulong, ulong> replace = new Dictionary <ulong, ulong>(); ExtractLogic.Skin.FindReplacements(skin.Data.skin.key, (int)pair.Value.Data.index, replace, new HashSet <ulong>(), map, handler, master, skin, true); Dictionary <ulong, ulong> replace_blank = new Dictionary <ulong, ulong>(); ExtractLogic.Skin.FindReplacements(skin.Data.skin.key, -1, replace_blank, new HashSet <ulong>(), map, handler, master, skin, false); if (replace.Values.Count == 0) { continue; } Dictionary <ulong, List <ImageLayer> > layers = new Dictionary <ulong, List <ImageLayer> >(); Dictionary <ulong, List <ImageLayer> > layers_orig = new Dictionary <ulong, List <ImageLayer> >(); foreach (KeyValuePair <ulong, ulong> texture_pair in replace) { ushort type = GUID.Type(texture_pair.Key); switch (type) { case 0x1A: ExtractLogic.Skin.FindTextures(texture_pair.Value, layers, replace, new HashSet <ulong>(), map, handler); if (replace_blank.ContainsKey(texture_pair.Key)) { ExtractLogic.Skin.FindTextures(replace_blank[texture_pair.Key], layers_orig, replace_blank, new HashSet <ulong>(), map, handler); } else { ExtractLogic.Skin.FindTextures(texture_pair.Key, layers_orig, replace_blank, new HashSet <ulong>(), map, handler); } break; } } Dictionary <ulong, HashSet <ulong> > origTextures = new Dictionary <ulong, HashSet <ulong> >(); foreach (KeyValuePair <ulong, List <ImageLayer> > kv in layers_orig) { ulong materialId = kv.Key; List <ImageLayer> sublayers = kv.Value; HashSet <ulong> materialParsed = new HashSet <ulong>(); if (!origTextures.ContainsKey(materialId)) { origTextures[materialId] = new HashSet <ulong>(); } foreach (ImageLayer layer in sublayers) { origTextures[materialId].Add(layer.key); } } foreach (KeyValuePair <ulong, List <ImageLayer> > kv in layers) { ulong materialId = kv.Key; List <ImageLayer> sublayers = kv.Value; HashSet <ulong> materialParsed = new HashSet <ulong>(); foreach (ImageLayer layer in sublayers) { if (!materialParsed.Add(layer.key)) { continue; } if (origTextures.ContainsKey(materialId) && origTextures[materialId].Contains(layer.key)) { continue; } ExtractLogic.Skin.SaveTexture(layer.key, materialId, map, handler, output_real, quiet, ""); } } } } } } }