public bool Save(BIFFFile f) { byte[] buf = new byte[f.Buffer.Length + 4]; Buffer.BlockCopy(f.Buffer, 0, buf, 4, f.Buffer.Length); Buffer.BlockCopy(BitConverter.GetBytes((int)TypeID), 0, buf, 0, 4); Table.WriteFile(buf, "GameItem" + ID); return(true); }
void HashBIFFFile(string Name, ref HashAlgorithm Ha) { IList <CFItem> Lst = CF.GetAllNamedEntries(Name); foreach (CFItem Itm in Lst) { BIFFFile B = GetBIFF(Itm); B.IterateChunks(HashChunk); } }
//10 = Gate //1 = Flipper //7 = Light public BIFFFile GetFile() { BIFFFile B = Table.GetBIFFFile("GameItem" + ID); byte[] tmp = new byte[B.Buffer.Length - 4]; Buffer.BlockCopy(B.Buffer, 4, tmp, 0, tmp.Length); B.Buffer = tmp; return(B); }
public BIFFFile GetGameDataFile() { IList <CFItem> Lst = CF.GetAllNamedEntries("GameData"); foreach (CFItem Itm in Lst) { BIFFFile F = GetBIFF(Itm); return(F); } return(null); }
//Loads a table from a VPT file public void Load(string Filename) { CF = new CompoundFile(Filename); IList <CFItem> Lst = CF.GetAllNamedEntries("TableName"); foreach (CFItem Itm in Lst) { Name = ReadTextFileUnicode(Itm.Size, Itm); } Lst = CF.GetAllNamedEntries("AuthorName"); foreach (CFItem Itm in Lst) { Author = ReadTextFileUnicode(Itm.Size, Itm); } Lst = CF.GetAllNamedEntries("TableVersion"); foreach (CFItem Itm in Lst) { Version = ReadTextFileUnicode(Itm.Size, Itm); } Lst = CF.GetAllNamedEntries("TableDescription"); foreach (CFItem Itm in Lst) { Description = ReadTextFileUnicode(Itm.Size, Itm); } Lst = CF.GetAllNamedEntries("Version"); foreach (CFItem Itm in Lst) { m_VPVersion = ReadIntBinary(Itm) / 100; } Lst = CF.GetAllNamedEntries("MAC"); foreach (CFItem Itm in Lst) { MD5Hash = GetFile(Itm); } Lst = CF.GetAllNamedEntries("GameData"); foreach (CFItem Itm in Lst) { BIFFFile F = GetBIFF(Itm); F.IterateChunks(BlowChunk); } Script = GetScript(); GetScriptDetails(); if (ROMNameVar == "") { ROMNameVar = "\"" + ROM + "\""; } }
//Saves a modified script back to the GameData BIFF file. public void ModifyScript() { IList <CFItem> Lst = CF.GetAllNamedEntries("GameData"); foreach (CFItem Itm in Lst) { BIFFFile F = GetBIFF(Itm); F.SetChunk("CODE", Encoding.ASCII.GetBytes(Script.Script)); CFStream Strm = (CFStream)Itm; byte[] Buf = F.GetBuffer(); Strm.SetData(Buf); } }
//Loads the script from GameData public TableScript GetScript() { if (CF == null) { return(null); } IList <CFItem> Lst = CF.GetAllNamedEntries("GameData"); foreach (CFItem Itm in Lst) { BIFFFile F = GetBIFF(Itm); string Code = Encoding.ASCII.GetString(F.GetChunk("CODE")); TableScript TS = new TableScript(); TS.Script = Code; return(TS); } return(null); }
public GameItem(int TableID, VisualPinballTable Tbl) { ID = TableID; Table = Tbl; //Load Name... BIFFFile Fl = Table.GetBIFFFile("GameItem" + ID.ToString()); if (Fl == null) { Name = "[UNKNOWN]"; return; } //First, there's a LONG identifying the TYPE of game object... int Typ = BitConverter.ToInt32(Fl.Buffer, 0); TypeID = Typ; switch (Typ) { case 1: Type = TypeName.Flipper; break; case 9: Type = TypeName.Decal; break; case 0: Type = TypeName.Wall; break; case 10: Type = TypeName.Gate; break; case 7: Type = TypeName.Light; break; case 5: Type = TypeName.Bumper; break; case 8: Type = TypeName.Kicker; break; case 4: Type = TypeName.Text; break; case 3: Type = TypeName.Plunger; break; case 2: Type = TypeName.Timer; break; case 12: Type = TypeName.Ramp; break; } byte[] tmp = new byte[Fl.Buffer.Length - 4]; Buffer.BlockCopy(Fl.Buffer, 4, tmp, 0, tmp.Length); Fl.Buffer = tmp; byte[] Contents = Fl.GetChunk("NAME"); Name = Encoding.Unicode.GetString(Contents, 4, Contents.Length - 4); Fl = null; }
//Calculates the MD5 hash for the VPT file. //Note that order is important. //In BIFF files, the chunk length is NOT added to the hash, although the chunk //four-letter code and the contents of the chunk ARE. void CalculateHash() { //MD5 md5 = new MD5CryptoServiceProvider(); //Hasher = md5; byte[] bf = Encoding.ASCII.GetBytes("Visual Pinball"); HashData.AddRange(bf); HashRawFile("Version", ref Hasher); HashRawFile("TableName", ref Hasher); HashRawFile("AuthorName", ref Hasher); HashRawFile("TableVersion", ref Hasher); HashRawFile("ReleaseDate", ref Hasher); HashRawFile("AuthorEmail", ref Hasher); HashRawFile("AuthorWebSite", ref Hasher); HashRawFile("TableBlurb", ref Hasher); HashRawFile("TableDescription", ref Hasher); HashRawFile("TableRules", ref Hasher); HashRawFile("Screenshot", ref Hasher); HashBIFFFile("CustomInfoTags", ref Hasher); HashBIFFFile("GameData", ref Hasher); //Hasher.TransformFinalBlock(new byte[0], 0, 0); int Ttl = Int32.Parse(Properties["Total Objects"]); for (int x = 0; x < Ttl; x++) { IList <CFItem> Lstx = CF.GetAllNamedEntries("GameItem" + x); foreach (CFItem Itm in Lstx) { BIFFFile F = GetBIFF(Itm); byte[] NewBuffer = new byte[F.Buffer.Length - 4]; Buffer.BlockCopy(F.Buffer, 4, NewBuffer, 0, NewBuffer.Length); F.Buffer = NewBuffer; F.IterateChunks(HashChunk); //Console.WriteLine(" Hashed GameItem BFF File: " + Itm.Name); } } Ttl = Int32.Parse(Properties["Total Collections"]); for (int x = 0; x < Ttl; x++) { IList <CFItem> Lstx = CF.GetAllNamedEntries("Collection" + x); foreach (CFItem Itm in Lstx) { BIFFFile F = GetBIFF(Itm); F.IterateChunks(HashChunk); //Console.WriteLine(" Hashed GameItem BFF File: " + Itm.Name); } } var hash = HashFactory.Crypto.CreateMD2(); var result = hash.ComputeBytes(HashData.ToArray()); /*System.IO.BinaryWriter Wri = new System.IO.BinaryWriter(System.IO.File.Create("c:\\tmp\\hashb.bin")); * Wri.Write(HashData.ToArray(), 0, HashData.Count); * Wri.Flush(); * Wri.Close();*/ MD5Hash = result.GetBytes(); IList <CFItem> Lst = CF.GetAllNamedEntries("MAC"); foreach (CFItem Itm in Lst) { WriteBinaryFile(MD5Hash, Itm); } }