internal WarpDestGroup(Project p, int id) : base(p,id) { fileParser = Project.GetFileWithLabel("warpDestTable"); Data tmp = fileParser.GetData("warpDestTable", id*2); string label = tmp.GetValue(0); WarpDestData data = fileParser.GetData(label) as WarpDestData; warpDestDataList = new List<WarpDestData>(); while (data != null) { data.DestGroup = this; data.DestIndex = warpDestDataList.Count; warpDestDataList.Add(data); FileComponent component = data.Next; data = null; while (component != null) { if (component is Label) { data = null; break; } else if (component is Data) { data = component as WarpDestData; break; } component = component.Next; } } }
public ConstantsMapping(FileParser parser, string[] prefixes) { this.parser = parser; Dictionary<string,string> definesDictionary = parser.DefinesDictionary; foreach (string key in definesDictionary.Keys) { bool acceptable = false; foreach (string prefix in prefixes) if (key.Substring(0, prefix.Length) == prefix) { acceptable = true; break; } if (acceptable) { byte tmp; if (!stringToByte.TryGetValue(key, out tmp)) { try { byte b = (byte)Project.EvalToInt(definesDictionary[key]); stringList.Add(key); stringToByte[key] = b; byteToString[b] = key; } catch (FormatException) {} } } } }
public FileComponent(FileParser parser, IList<int> spacing) { if (parser != null) _project = parser.Project; EndsLine = true; Fake = false; if (spacing != null) this.spacing = new List<int>(spacing); this.parser = parser; }
public WarpDestData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, 3, parser, spacing) { SetValueReferences(warpValueReferences); referenceSet = new HashSet<WarpSourceData>(); DestGroup = null; DestIndex = -1; }
internal ObjectGroup(Project p, String id) : base(p, id) { parser = Project.GetFileWithLabel(Identifier); ObjectData data = parser.GetData(Identifier) as ObjectData; while (data.GetObjectType() != ObjectType.End && data.GetObjectType() != ObjectType.EndPointer) { objectDataList.Add(data); data = data.NextData as ObjectData; } objectDataList.Add(data); }
public TilesetHeaderData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, 8, parser, spacing) { try { referencedData = Project.GetBinaryFile("tilesets/" + GetValue(1) + ".bin"); } catch (FileNotFoundException) { // Default is to copy from 00 I guess // TODO: copy this into its own file? string filename = GetValue(1).Substring(0, GetValue(1).Length-2); referencedData = Project.GetBinaryFile("tilesets/" + filename + "00.bin"); } }
PaletteHeaderGroup(Project project, int index) : base(project, index) { FileParser palettePointerFile = project.GetFileWithLabel("paletteHeaderTable"); Data headerPointerData = palettePointerFile.GetData("paletteHeaderTable", index * 2); FileParser paletteHeaderFile = project.GetFileWithLabel(headerPointerData.GetValue(0)); Data headerData = paletteHeaderFile.GetData(headerPointerData.GetValue(0)); if (!(headerData is PaletteHeaderData)) { throw new Exception("Expected palette header group " + index.ToString("X") + " to start with palette header data"); } firstPaletteHeader = (PaletteHeaderData)headerData; }
public FileComponent(FileParser parser, IList <int> spacing) { if (parser != null) { _project = parser.Project; } EndsLine = true; Fake = false; if (spacing != null) { this.spacing = new List <int>(spacing); } this.parser = parser; }
public Label(FileParser parser, string n, IList <string> spacing = null) : base(parser, spacing) { name = n; if (spacing == null) { this.spacing = new List <string> { "", "" }; } while (this.spacing.Count < 2) { this.spacing.Add(""); } }
public override string GetString() { if (FileParser.GetDataLabel(this) != null) { // If a label points directly to this data, it can't be // shortened Elongate(); } else { Shorten(); // Try to, anyway } return(base.GetString()); }
public Label(FileParser parser, string n, IList <int> spacing = null) : base(parser, spacing) { name = n; if (spacing == null) { this.spacing = new List <int> { 0, 0 }; } while (this.spacing.Count < 2) { this.spacing.Add(0); } }
internal Area(Project p, int i) : base(p, i) { areaFile = Project.GetFileWithLabel("areaData"); areaData = areaFile.GetData("areaData", Index * 8); // If this is Seasons, it's possible that areaData does not point to 8 bytes as // expected, but instead to an "m_SeasonalData" macro. if (areaData.CommandLowerCase == "m_seasonalarea") { int season = 0; areaData = Project.GetData(areaData.GetValue(0), season * 8); } // Initialize graphics state graphicsState = new GraphicsState(); // Global palettes PaletteHeaderGroup globalPaletteHeaderGroup = Project.GetIndexedDataType <PaletteHeaderGroup>(0xf); graphicsState.AddPaletteHeaderGroup(globalPaletteHeaderGroup, PaletteGroupType.Common); Data data = areaData; flags1 = p.EvalToInt(data.GetValue(0)); data = data.NextData; flags2 = p.EvalToInt(data.GetValue(0)); data = data.NextData; SetUniqueGfx(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetMainGfx(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetPaletteHeader(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetTileset(Project.EvalToInt(data.GetValue(0))); data = data.NextData; layoutGroup = Project.EvalToInt(data.GetValue(0)); data = data.NextData; SetAnimation((byte)Project.EvalToInt(data.GetValue(0))); }
internal WarpSourceGroup(Project p, int id) : base(p,id) { fileParser = Project.GetFileWithLabel("warpSourcesTable"); Data d = fileParser.GetData("warpSourcesTable", id*2); string label = d.GetValue(0); warpSourceDataList = new List<WarpSourceData>(); WarpSourceData warpData = fileParser.GetData(label) as WarpSourceData; while (warpData != null && warpData.WarpSourceType != WarpSourceType.WarpSourcesEnd) { warpSourceDataList.Add(warpData); warpData = warpData.NextData as WarpSourceData; } if (warpData != null) warpSourceDataList.Add(warpData); // WarpSourcesEnd }
public ConstantsMapping(FileParser _parser, string[] _prefixes) { this.parser = _parser; this.prefixes = _prefixes; Dictionary <string, Tuple <string, DocumentationFileComponent> > definesDictionary = parser.DefinesDictionary; foreach (string key in definesDictionary.Keys) { bool acceptable = false; foreach (string prefix in prefixes) { if (key.Substring(0, prefix.Length) == prefix) { acceptable = true; break; } } if (acceptable) { Entry tmp; if (!stringToByte.TryGetValue(key, out tmp)) { try { var tup = definesDictionary[key]; string val = tup.Item1; var docComponent = tup.Item2; // May be null byte b = (byte)Project.EvalToInt(val); stringList.Add(key); Documentation doc = null; if (docComponent != null) { doc = new Documentation(docComponent, key); } Entry ent = new Entry(key, b, doc); // TODO: remove doc from here stringToByte[key] = ent; byteToString[b] = ent; } catch (FormatException) {} } } } }
internal Animation(Project p, string label) : base(p, label) { FileParser parser = Project.GetFileWithLabel(label); Data data = parser.GetData(label); while (data != null && data.CommandLowerCase == ".db") { counters.Add(Project.EvalToInt(data.GetValue(0))); data = data.NextData; if (data.CommandLowerCase != ".db") { throw new Exception("Malformatted animation data"); } gfxHeaderIndices.Add(Project.EvalToInt(data.GetValue(0))); data = data.NextData; } }
public GfxHeaderData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <string> spacing) : base(p, command, values, 6, parser, spacing) { string filename = GetValue(0) + ".bin"; gfxFile = Project.FindGfxFile(filename); if (gfxFile == null) { throw new Exception("Could not find graphics file " + filename); } if (GetNumValues() > 3) { // Skip into part of gfx data gfxFile = new SubStream(gfxFile, p.EvalToInt(GetValue(3)), BlockCount * 16); } }
public bool SetNextWarp(WarpSourceData next) { if (!FileParser.InsertComponentAfter(this, next)) { return(false); } this.Opcode &= ~0x80; if (next.GetNextWarp() == null) { next.Opcode |= 0x80; } else { next.Opcode &= 0x80; } return(true); }
internal TilesetHeaderGroup(Project p, int i) : base(p, i) { FileParser tableFile = Project.GetFileWithLabel("tilesetHeaderGroupTable"); Data pointerData = tableFile.GetData("tilesetHeaderGroupTable", Index * 2); string labelName = pointerData.GetValue(0); FileParser headerFile = Project.GetFileWithLabel(labelName); TilesetHeaderData headerData = headerFile.GetData(labelName) as TilesetHeaderData; bool next = true; while (next) { if (headerData == null) { throw new Exception("Expected tileset header group " + Index.ToString("X") + " to reference tileset header data (m_TilesetHeader)"); } Stream dataFile = headerData.ReferencedData; dataFile.Position = 0; if (headerData.DestAddress == Project.EvalToInt("w3TileMappingIndices")) { // Mappings mappingsDataFile = dataFile; } else if (headerData.DestAddress == Project.EvalToInt("w3TileCollisions")) { // Collisions collisionsDataFile = dataFile; } if (headerData.ShouldHaveNext()) { headerData = headerData.NextData as TilesetHeaderData; if (headerData != null) { next = true; } } else { next = false; } } }
void UpdateRoomData() { // Get the tileDataFile int layoutGroup = area.LayoutGroup; string label = "room" + ((layoutGroup << 8) + (Index & 0xff)).ToString("X4").ToLower(); FileParser parserFile = Project.GetFileWithLabel(label); Data data = parserFile.GetData(label); if (data.CommandLowerCase != "m_roomlayoutdata") { throw new Exception("Expected label \"" + label + "\" to be followed by the m_RoomLayoutData macro."); } string roomString = data.GetValue(0) + ".bin"; try { tileDataFile = Project.GetBinaryFile( "rooms/" + Project.GameString + "/small/" + roomString); } catch (FileNotFoundException) { try { tileDataFile = Project.GetBinaryFile( "rooms/" + Project.GameString + "/large/" + roomString); } catch (FileNotFoundException) { throw new FileNotFoundException("Couldn't find \"" + roomString + "\" in \"rooms/small\" or \"rooms/large\"."); } } if (tileDataFile.Length == 80) // Small map { width = fileWidth = 10; height = 8; } else if (tileDataFile.Length == 176) // Large map { width = 0xf; fileWidth = 0x10; height = 0xb; } else { throw new Exception("Size of file \"" + tileDataFile.Name + "\" was invalid!"); } }
internal AnimationGroup(Project p, int i) : base(p, i) { FileParser parser = Project.GetFileWithLabel("animationGroupTable"); Data pointer = parser.GetData("animationGroupTable", 2 * Index); string label = pointer.GetValue(0); Data data = parser.GetData(label); int b1 = Project.EvalToInt(data.GetValue(0)); data = data.NextData; int bits = b1 & 0xf; if (bits >= 0xf) { _numAnimations = 4; } else if (bits >= 0x7) { _numAnimations = 3; } else if (bits >= 0x3) { _numAnimations = 2; } else if (bits >= 0x1) { _numAnimations = 1; } else { _numAnimations = 0; } for (int j = 0; j < NumAnimations; j++) { if (data.CommandLowerCase != ".dw") { throw new Exception("Malformatted animation group data (index 0x" + Index.ToString("x") + "\n"); } animations[j] = Project.GetDataType <Animation>(data.GetValue(0)); data = data.NextData; } }
public PaletteHeaderData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, 3, parser, spacing) { int dest = -1; try { dest = Project.EvalToInt(GetValue(2)); } catch(FormatException) { dest = -1; } if (dest != -1) sourceFromRam = true; else { paletteDataFile = Project.GetFileWithLabel(GetValue(2)); if (!(paletteDataFile.GetData(GetValue(2)) is RgbData)) throw new Exception("Label \"" + GetValue(2) + "\" was expected to reference data defined with m_RGB16"); } }
internal WarpSourceGroup(Project p, int id) : base(p, id) { fileParser = Project.GetFileWithLabel("warpSourcesTable"); Data d = fileParser.GetData("warpSourcesTable", id * 2); string label = d.GetValue(0); warpSourceDataList = new List <WarpSourceData>(); WarpSourceData warpData = fileParser.GetData(label) as WarpSourceData; while (warpData != null && warpData.WarpSourceType != WarpSourceType.WarpSourcesEnd) { warpSourceDataList.Add(warpData); warpData = warpData.NextData as WarpSourceData; } if (warpData != null) { warpSourceDataList.Add(warpData); // WarpSourcesEnd } }
// Constructor public Data(Project p, string command, IEnumerable<string> values, int size, FileParser parser, IList<int> spacing) : base(parser, spacing) { base.SetProject(p); this.command = command; if (values == null) this.values = new List<string>(); else this.values = new List<string>(values); this.size = size; if (this.spacing == null) this.spacing = new List<int>(); while (this.spacing.Count < this.values.Count+2) this.spacing.Add(0); PrintCommand = true; _modified = false; }
// Adds the given data to the end of the group and inserts the data // into the FileParser. public void AddWarpSourceData(WarpSourceData data) { if (warpSourceDataList.Contains(data)) { return; } // Assumes the last element of warpSourceDataList is always the // m_WarpSourcesEnd command fileParser.InsertComponentBefore(EndData, data); warpSourceDataList.Insert(warpSourceDataList.Count - 1, data); if (data.WarpSourceType == WarpSourceType.PointerWarp && data.PointerString == ".") { // Create a unique pointer after m_WarpSourcesEnd int nameIndex = 0; string name; do { name = "customWarpSource" + nameIndex.ToString("d2"); nameIndex++; }while (Project.HasLabel(name)); data.PointerString = name; Label newLabel = new Label(FileParser, name); // Insert label after m_WarpSourcesEnd FileParser.InsertComponentAfter(EndData, newLabel); // Create a blank PointedData to go after this label WarpSourceData pointedData = new WarpSourceData(Project, WarpSourceData.WarpCommands[(int)WarpSourceType.PointedWarp], WarpSourceData.DefaultValues[(int)WarpSourceType.PointedWarp], FileParser, new List <int> { -1 }); pointedData.Opcode = 0x80; pointedData.Transition = 4; FileParser.InsertComponentAfter(newLabel, pointedData); } }
public GfxHeaderData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, 6, parser, spacing) { string filename = GetValue(0) + ".bin"; gfxFile = null; foreach (string directory in gfxDirectories) { if (File.Exists(Project.BaseDirectory + directory + filename)) { gfxFile = Project.GetBinaryFile(directory + filename); if (CommandLowerCase == "m_gfxheader" && GetNumValues() > 3) // Skip into part of gfx data gfxFile = new SubStream(gfxFile, p.EvalToInt(GetValue(3)), GetBlockCount()*16); break; } } if (gfxFile == null) { throw new Exception("Could not find graphics file " + filename); } }
public WarpSourceData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <int> spacing) : base(p, command, values, -1, parser, spacing) { // Find type for (int i = 0; i < WarpCommands.Length; i++) { string s = WarpCommands[i]; if (this.CommandLowerCase == s.ToLower()) { _type = (WarpSourceType)i; break; } } SetValueReferences(warpValueReferences[(int)WarpSourceType]); referencedDestData = GetReferencedDestData(); if (referencedDestData != null) { referencedDestData.AddReference(this); } this.AddDataModifiedHandler(delegate(object sender, EventArgs e) { WarpDestData newDestData = GetReferencedDestData(); if (newDestData != referencedDestData) { // Update DestData reference if (referencedDestData != null) { referencedDestData.RemoveReference(this); } referencedDestData = newDestData; if (newDestData != null) { newDestData.AddReference(this); } } }); }
internal Area(Project p, int i) : base(p, i) { areaFile = Project.GetFileWithLabel("areaData"); areaData = areaFile.GetData("areaData", Index * 8); // Initialize graphics state graphicsState = new GraphicsState(); // Global palettes PaletteHeaderGroup globalPaletteHeaderGroup = Project.GetIndexedDataType<PaletteHeaderGroup>(0xf); graphicsState.AddPaletteHeaderGroup(globalPaletteHeaderGroup, PaletteGroupType.Common); Data data = areaData; flags1 = p.EvalToInt(data.GetValue(0)); data = data.NextData; flags2 = p.EvalToInt(data.GetValue(0)); data = data.NextData; SetUniqueGfx(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetMainGfx(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetPaletteHeader(Project.EvalToInt(data.GetValue(0))); data = data.NextData; SetTileset(Project.EvalToInt(data.GetValue(0))); data = data.NextData; layoutGroup = Project.EvalToInt(data.GetValue(0)); data = data.NextData; SetAnimation((byte)Project.EvalToInt(data.GetValue(0))); }
public StringFileComponent(FileParser parser, string s, IList<int> spacing) : base(parser, spacing) { str = s; if (this.spacing == null) this.spacing = new List<int>(); while (this.spacing.Count < 2) this.spacing.Add(0); }
public Label(FileParser parser, string n, IList<int> spacing=null) : base(parser, spacing) { name = n; if (spacing == null) { this.spacing = new List<int>{0,0}; } while (this.spacing.Count < 2) this.spacing.Add(0); }
public ObjectGfxHeaderData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <string> spacing) : base(p, command, values, 3, parser, spacing) { string filename = GetValue(0) + ".bin"; gfxFile = Project.FindGfxFile(filename); if (gfxFile == null) { throw new Exception("Could not find graphics file " + filename); } }
public WarpSourceData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, -1, parser, spacing) { // Find type for (int i=0; i<WarpCommands.Length; i++) { string s = WarpCommands[i]; if (this.CommandLowerCase == s.ToLower()) { _type = (WarpSourceType)i; break; } } SetValueReferences(warpValueReferences[(int)WarpSourceType]); referencedDestData = GetReferencedDestData(); if (referencedDestData != null) referencedDestData.AddReference(this); this.AddDataModifiedHandler(delegate(object sender, EventArgs e) { WarpDestData newDestData = GetReferencedDestData(); if (newDestData != referencedDestData) { // Update DestData reference if (referencedDestData != null) referencedDestData.RemoveReference(this); referencedDestData = newDestData; if (newDestData != null) newDestData.AddReference(this); } }); }
public PaletteHeaderData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <int> spacing) : base(p, command, values, 3, parser, spacing) { int dest = -1; try { dest = Project.EvalToInt(GetValue(2)); } catch (FormatException) { dest = -1; } if (dest != -1) { sourceFromRam = true; } else { paletteDataFile = Project.GetFileWithLabel(GetValue(2)); if (!(paletteDataFile.GetData(GetValue(2)) is RgbData)) { throw new Exception("Label \"" + GetValue(2) + "\" was expected to reference data defined with m_RGB16"); } } }
public ConstantsMapping(FileParser parser, string prefix) : this(parser, new string[] { prefix }) { }
public RgbData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <string> spacing) : base(p, command, values, 2, parser, spacing) { }
public ObjectData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing, ObjectType type) : base(p, command, values, -1, parser, spacing) { this.type = type; SetValueReferences(objectValueReferences[(int)type]); }
public TilesetHeaderData(Project p, string command, IEnumerable <string> values, FileParser parser, IList <int> spacing) : base(p, command, values, 8, parser, spacing) { try { referencedData = Project.GetBinaryFile("tilesets/" + Project.GameString + "/" + GetValue(1) + ".bin"); } catch (FileNotFoundException) { // Default is to copy from 00 I guess // TODO: copy this into its own file? string filename = GetValue(1).Substring(0, GetValue(1).Length - 2); referencedData = Project.GetBinaryFile("tilesets/" + Project.GameString + "/" + filename + "00.bin"); } }
// Constructor public Data(Project p, string command, IEnumerable <string> values, int size, FileParser parser, IList <string> spacing) : base(parser, spacing) { base.SetProject(p); this.command = command; if (values == null) { this.values = new List <string>(); } else { this.values = new List <string>(values); } this.size = size; if (this.spacing == null) { this.spacing = new List <string>(); } while (this.spacing.Count < this.values.Count + 2) { this.spacing.Add(""); } PrintCommand = true; _modified = false; }
public void SetFileParser(FileParser p) { parser = p; if (parser != null) _project = parser.Project; }
public RgbData(Project p, string command, IEnumerable<string> values, FileParser parser, IList<int> spacing) : base(p, command, values, 2, parser, spacing) { }