internal InteractionObject(Project p, int i) : base(p, i) { try { objectData = p.GetData("interactionData", ID * 3); // If this points to more data, follow the pointer if (objectData.GetNumValues() == 1) { string label = objectData.GetValue(0); objectData = p.GetData(label); int count = SubID; while (count > 0 && (objectData.GetIntValue(1) & 0x80) == 0) { count--; objectData = objectData.NextData; } } b0 = (byte)objectData.GetIntValue(0); b1 = (byte)objectData.GetIntValue(1); b2 = (byte)objectData.GetIntValue(2); } catch (InvalidLookupException) { objectData = null; } catch (FormatException) { objectData = null; } }
internal PartObject(Project p, int i) : base(p, i) { try { objectData = p.GetData("partData", ID * 8); Data data = objectData; _objectGfxHeaderIndex = (byte)data.GetIntValue(0); for (int j = 0; j < 5; j++) { data = data.NextData; } _tileIndexBase = (byte)data.GetIntValue(0); data = data.NextData; _oamFlagsBase = (byte)data.GetIntValue(0); } catch (InvalidLookupException e) { Console.WriteLine(e.ToString()); objectData = null; } catch (FormatException e) { Console.WriteLine(e.ToString()); objectData = null; } }
public virtual int GetIntValue() { switch (ValueType) { case DataValueType.ByteBits: { int andValue = (1 << (endBit - startBit + 1)) - 1; return((data.GetIntValue(valueIndex) >> startBit) & andValue); } case DataValueType.ByteBit: return((data.GetIntValue(valueIndex) >> startBit) & 1); default: return(data.GetIntValue(valueIndex)); } }
internal EnemyObject(Project p, int i) : base(p, i) { try { objectData = p.GetData("enemyData", ID * 4); _objectGfxHeaderIndex = (byte)objectData.GetIntValue(0); _collisionReactionSet = (byte)objectData.GetIntValue(1); byte lookupIndex; // TODO: use this byte b3; if (objectData.GetNumValues() == 4) { lookupIndex = (byte)objectData.GetIntValue(2); b3 = (byte)(objectData.GetIntValue(3)); } else { Data subidData = Project.GetData(objectData.GetValue(2)); int count = SubID; while (count > 0 && (subidData.GetIntValue(0) & 0x80) == 0x80) { subidData = subidData.NextData; subidData = subidData.NextData; count--; } lookupIndex = (byte)subidData.GetIntValue(0); b3 = (byte)(subidData.NextData.GetIntValue(0)); } _tileIndexBase = (byte)((b3 & 0xf) * 2); _oamFlagsBase = (byte)(b3 >> 4); } catch (InvalidLookupException e) { Console.WriteLine(e.ToString()); objectData = null; } catch (FormatException e) { Console.WriteLine(e.ToString()); objectData = null; } }
/// <summary> /// Will throw InvalidAnimationException if initialization failed earlier... /// </summary> public void Draw(Graphics g, int xPos, int yPos) { if (bitmaps == null) { throw new InvalidAnimationException(); } int _numSprites = _oamData.GetIntValue(0); // Draw sprites in backwards order to respect priority properly for (int i = _numSprites - 1; i >= 0; i--) { Tuple <Bitmap, int, int> tup = bitmaps[i]; Bitmap bitmap = tup.Item1; int x = tup.Item2 + xPos; int y = tup.Item3 + yPos; g.DrawImage(bitmap, x, y); } }
/// <summary> /// Will throw InvalidAnimationException if initialization failed earlier... /// TODO: does drawing code really belong here? /// </summary> public void Draw(Cairo.Context cr, int xPos, int yPos) { if (bitmaps == null) { throw new InvalidAnimationException(); } int _numSprites = _oamData.GetIntValue(0); // Draw sprites in backwards order to respect priority properly for (int i = _numSprites - 1; i >= 0; i--) { Tuple <Bitmap, int, int> tup = bitmaps[i]; Bitmap bitmap = tup.Item1; int x = tup.Item2 + xPos; int y = tup.Item3 + yPos; using (Cairo.Surface s = CairoHelper.LockBitmap(bitmap)) { cr.SetSourceSurface(s, x, y); cr.Paint(); CairoHelper.UnlockBitmap(bitmap); } } }
public ObjectAnimationFrame(ObjectAnimation anim, Data animData) { _animation = anim; _animData = animData; Color[][] palettes = anim.GetPalettes(); try { // Note: this "index" is more like index*2, since it's added directly to the offset // without being multiplied first int oamIndex = (byte)_animData.NextData.GetIntValue(0); // Get entry in oam table for this object Data oamPtr = Project.GetData(_animation.OamTableName, oamIndex); _oamData = Project.GetData(oamPtr.GetValue(0)); // Load sprite images int _numSprites = _oamData.GetIntValue(0); Data data = _oamData.NextData; for (int i = 0; i < _numSprites; i++) { int y = (sbyte)data.GetIntValue(0) - 16; data = data.NextData; int x = (sbyte)data.GetIntValue(0) - 8; data = data.NextData; int tileIndex = data.GetIntValue(0) + _animation.TileIndexBase; data = data.NextData; byte flags = (byte)(data.GetIntValue(0) | _animation.OamFlagsBase); data = data.NextData; ObjectGfxHeaderData gfxHeader = _animation.ObjectGfxHeaderData; int origTileIndex = tileIndex; while (tileIndex >= 0x20) { if (gfxHeader.ShouldHaveNext) { gfxHeader = gfxHeader.NextGfxHeader; tileIndex -= 0x20; } else { throw new InvalidAnimationException("Tileindex out of range (" + tileIndex + ")"); } } int tileOffset = (tileIndex & 0xfe) * 16; Stream gfxStream = gfxHeader.GfxStream; if (gfxStream.Length - tileOffset < 0x20) { throw new InvalidAnimationException("Sprite not defined in gfx data"); } gfxStream.Seek(tileOffset, SeekOrigin.Begin); byte[] gfxData = new byte[0x20]; gfxStream.Read(gfxData, 0, 0x20); Bitmap bitmap = GbGraphics.TileToBitmap(gfxData, palettes[flags & 7], flags); bitmaps.Add(new Tuple <Bitmap, int, int>(bitmap, x, y)); } } catch (InvalidLookupException e) { bitmaps = null; throw new InvalidAnimationException(e); } catch (FormatException e) { bitmaps = null; throw new InvalidAnimationException(e); } }