public void Files_ContainGrfEntriesWithNames_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var expectedPathAndName = new List <(string, string)>() { ("data\\0_Tex1.bmp", "0_Tex1.bmp"), ("data\\11001.txt", "11001.txt"), ("data\\balls.wav", "balls.wav"), ("data\\idnum2itemdesctable.txt", "idnum2itemdesctable.txt"), ("data\\idnum2itemdisplaynametable.txt", "idnum2itemdisplaynametable.txt"), ("data\\loading00.jpg", "loading00.jpg"), ("data\\monstertalktable.xml", "monstertalktable.xml"), ("data\\resnametable.txt", "resnametable.txt"), ("data\\t2_¹è°æ1-1.bmp", "t2_¹è°æ1-1.bmp") }; var grf = Grf.FromFile(inputFile, mode); foreach (var(path, name) in expectedPathAndName) { var entryFound = grf.Find(path, out GrfEntry entry); Assert.IsTrue(entryFound); Assert.AreEqual(name, entry.Name); } }
public void Entries_ContainGrfEntriesWithPaths_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var expectedPaths = new List <string>() { "data\\0_Tex1.bmp", "data\\11001.txt", "data\\balls.wav", "data\\idnum2itemdesctable.txt", "data\\idnum2itemdisplaynametable.txt", "data\\loading00.jpg", "data\\monstertalktable.xml", "data\\resnametable.txt", "data\\t2_¹è°æ1-1.bmp" }; var grf = Grf.FromFile(inputFile, mode); foreach (var path in expectedPaths) { var entryFound = grf.Find(path, out GrfEntry entry); Assert.IsTrue(entryFound); Assert.AreEqual(path, entry.Path); } }
public void Load_ThrowsDirectoryNotFound_WhenPassingInvalidPath( [ValueSource("LoadingModes")] LoadingMode mode) { void throwingMethod() { Grf.FromFile("some/path/file.grf", mode); } Assert.Throws <DirectoryNotFoundException>(throwingMethod); }
public void Signature_ReturnsMasterOfMagic_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var expected = "Master of Magic"; var grf = Grf.FromFile(inputFile, mode); var actual = grf.Signature; Assert.AreEqual(expected, actual); }
public void EntryCount_ReturnsNine_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var expected = 9; var grf = Grf.FromFile(inputFile, mode); var actual = grf.Count; Assert.AreEqual(expected, actual); }
public static void LoadGRF(string rootPath, List <string> grfs) { GrfList = new List <Grf>(); foreach (var path in grfs) { var grf = Grf.grf_callback_open(rootPath + path, "r", null); GrfList.Add(grf); } Tables.Init(); }
public MapSelector(Grf grf) { mapList = new LinkedList <string>(); //build map list foreach (string key in grf.files.Keys) { if (key.EndsWith(".rsw", StringComparison.OrdinalIgnoreCase)) { mapList.AddLast(key); } } }
public Act GetBodySprite(Job job, string gender = "남") { var jobActionData = Grf.GetData(EncodingService.FromAnyToDisplayEncoding(@"data\sprite\인간족\몸통\" + gender + "\\" + job.GetSpriteName(Gender) + EncodingService.FromAnyToDisplayEncoding("_" + gender + ".act"))); var jobSpriteData = Grf.GetData(EncodingService.FromAnyToDisplayEncoding(@"data\sprite\인간족\몸통\" + gender + "\\" + job.GetSpriteName(Gender) + EncodingService.FromAnyToDisplayEncoding("_" + gender + ".spr"))); if (jobActionData == null || jobSpriteData == null) { AddError("resource error: sprite for job '" + job.Name + "' not found."); return(DefaultBodyReference); } return(new Act(jobActionData, new Spr(jobSpriteData))); }
public void UncompressedSize_ReturnsSameSizeAsExtractedData_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var grf = Grf.FromFile(inputFile, mode); Assert.IsTrue(grf.Count != 0); foreach (var path in grf.EntryNames) { var entryFound = grf.Find(path, out GrfEntry entry); Assert.IsTrue(entryFound); Assert.AreEqual(entry.Size, entry.GetUncompressedData().Length); } }
public void GetUncompressedData_DoesntChangeOriginalDataOnUncompressing_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var grf = Grf.FromFile(inputFile, mode); Assert.IsTrue(grf.Count != 0); foreach (var path in grf.EntryNames) { var entryFound = grf.Find(path, out GrfEntry entry); Assert.IsTrue(entryFound); Assert.AreEqual(entry.Size, entry.GetUncompressedData().Length); Assert.AreEqual(entry.Size, entry.GetUncompressedData().Length); } }
private static void test02() //****************************************************************************80 // // Purpose: // // TEST02 tests GRF_HEADER_READ and GRF_DATA_READ. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 13 January 2009 // // Author: // // John Burkardt // { int edge_num = 0; const string input_filename = "coxeter.grf"; int node_num = 0; Console.WriteLine(""); Console.WriteLine("TEST02"); Console.WriteLine(" GRF_HEADER_READ reads the header of a GRF file."); Console.WriteLine(" GRF_DATA_READ reads the data of a GRF file."); Console.WriteLine(""); Console.WriteLine(" Reading the GRF file \"" + input_filename + "\""); Grf.grf_header_read(input_filename, ref node_num, ref edge_num); Grf.grf_header_print(node_num, edge_num); int[] edge_pointer = new int[node_num + 1]; int[] edge_data = new int[edge_num]; double[] xy = new double[2 * node_num]; Grf.grf_data_read(input_filename, node_num, edge_num, ref edge_pointer, ref edge_data, ref xy); Grf.grf_data_print(node_num, edge_num, edge_pointer, edge_data, xy); }
private static void test01() //****************************************************************************80 // // Purpose: // // TEST01 tests GRF_HEADER_WRITE, GRF_DATA_WRITE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 12 January 2009 // // Author: // // John Burkardt // { int edge_num = 0; int node_num = 0; const string output_filename = "coxeter.grf"; Console.WriteLine(""); Console.WriteLine("TEST01"); Console.WriteLine(" GRF_HEADER_WRITE writes the header of a GRF file."); Console.WriteLine(" GRF_DATA_WRITE writes the data of a GRF file."); Grf.grf_example_size(ref node_num, ref edge_num); Grf.grf_header_print(node_num, edge_num); int[] edge_data = new int[edge_num]; int[] edge_pointer = new int[node_num + 1]; double[] xy = new double[2 * node_num]; Grf.grf_example(node_num, edge_num, ref edge_pointer, ref edge_data, ref xy); Grf.grf_write(output_filename, node_num, edge_num, edge_pointer, edge_data, xy); Console.WriteLine(""); Console.WriteLine(" Wrote the GRF file \"" + output_filename + "\","); }
public void EntryNames_ReturnsAllFilesFromTestGrf_AfterLoadingAFile( [ValueSource("InputFiles")] string inputFile, [ValueSource("LoadingModes")] LoadingMode mode) { var expected = new List <string>() { "data\\0_Tex1.bmp", "data\\11001.txt", "data\\balls.wav", "data\\idnum2itemdesctable.txt", "data\\idnum2itemdisplaynametable.txt", "data\\loading00.jpg", "data\\monstertalktable.xml", "data\\resnametable.txt", "data\\t2_¹è°æ1-1.bmp" }; var grf = Grf.FromFile(inputFile, mode); var actual = grf.EntryNames; Assert.AreEqual(expected, actual); }
public static void loadGrf(string grfPath) { grf = Grf.grf_callback_open(grfPath, "r", null); }
private void _updatePreview(string sprite) { byte[] headActionData; byte[] headSpriteData; _act = _emptyAct; _references.RemoveRange(2, _references.Count - 2); // Sprite has 3 states : // correct path - may not be found // null - do not update and show error // none - do not update and do not show error if (sprite == null) { AddError("Resource error : couldn't find the specified sprite."); } else if (sprite == SpriteDefault) { _bodyReference = DefaultBodyReference; } else if (sprite == SpriteNone) { } else { if (sprite.GetExtension() != null) { headActionData = Grf.GetData(sprite); headSpriteData = Grf.GetData(sprite.ReplaceExtension(".spr")); if (headActionData != null && headSpriteData != null) { _act = new Act(headActionData, new Spr(headSpriteData)); } if (headActionData == null || headSpriteData == null) { SetError(String.Format("Resource error : sprite(s) not found \n{0} - {1}\n{2} - {3}", sprite, headActionData == null ? "#MISSING" : "#FOUND", sprite.ReplaceExtension(".spr"), headSpriteData == null ? "#MISSING" : "#FOUND")); } //sprite = sprite.ReplaceExtension(EncodingService.FromAnyToDisplayEncoding("_검광.act")); //headActionData = Grf.GetData(sprite); //headSpriteData = Grf.GetData(sprite.ReplaceExtension(".spr")); // //if (headActionData != null && headSpriteData != null) { // Act act = new Act(headActionData, new Spr(headSpriteData)); // act.AnchoredTo = _bodyReference; // _references.Add(new ActReference { Act = act, Mode = ZMode.Front, Show = true }); //} } } _headReference.AnchoredTo = _bodyReference; _act.AnchoredTo = _headReference; _selector.Load(_act); _frameViewer.SetGarmentMode(false); _headReference.Commands.UndoAll(); _bodyReference.Commands.UndoAll(); if (_act != null) { _act.Commands.UndoAll(); } if (Job != null && Job.Name.StartsWith("Baby ")) { _headReference.Commands.Backup(a => a.Magnify(0.75f, true)); _bodyReference.Commands.Backup(a => a.Magnify(0.75f, true)); if (_act != null) { _act.Commands.Backup(a => a.Magnify(0.75f, true)); } } if (_lastMatch is GarmentPreview) { _frameViewer.SetGarmentMode(true); } _frameViewer.Update(); }
public static Grf grf_callback_open(string fname, string mode, GrfOpenCallback callback) { byte[] buf = new byte[GRF_HEADER_FULL_LEN]; uint i;//, zero_fcount = GrfSupport.ToLittleEndian32(7), create_ver = GrfSupport.ToLittleEndian32(0x0200); Grf grf; if (fname == null || mode == null) { throw new Exception("GE_BADARGS"); } /* Allocate memory for grf */ grf = new Grf(); /* Copy the filename */ grf.filename = fname; /* Open the file */ var fStream = FileManager.Load(grf.filename) as Stream; if (fStream == null) { throw new Exception("GE_ERRNO"); } using (var br = new System.IO.BinaryReader(fStream)) { grf.allowWrite = !mode.Contains("+") && mode.Contains("w"); //***skipped write***/ /* Read the header */ buf = br.ReadBytes(GRF_HEADER_FULL_LEN); /* Check the header */ string strA = Encoding.ASCII.GetString(buf); int v = string.Compare(strA, 0, GRF_HEADER, 0, GRF_HEADER_LEN); if (v != 0) { throw new Exception("GE_INVALID"); } /* Continued header check... * * GRF files that allow encryption of the files inside the archive * have a hex header following "Master of Magic" (not including * the nul-terminator) that looks like: * 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E * * GRF files that do not allow it have a hex header that looks like: * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * * GRF files that do not allow it are generally found after a * "Ragnarok.exe /repak" command has been issued */ if (buf[GRF_HEADER_LEN + 1] == 1) { grf.allowCrypt = 1; /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E */ for (i = 0; i < 0xF; i++) { if (buf[GRF_HEADER_LEN + i] != (int)i) { throw new Exception("GE_CORRUPTED"); } } } else if (buf[GRF_HEADER_LEN] == 0) { grf.allowCrypt = 0; /* 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */ for (i = 0; i < 0xF; i++) { if (buf[GRF_HEADER_LEN + i] != 0) { new Exception("GE_CORRUPTED"); } } } else { throw new Exception("GE_CORRUPTED"); } /* Okay, so we finally are sure that its a valid GRF/GPF file. * now its time to read info from it */ /* Set the type of archive this is */ grf.type = GRF_TYPE_GRF; /* Read the version */ grf.version = GrfSupport.LittleEndian32(buf, GRF_HEADER_MID_LEN + 0xC); /* Read the number of files */ grf.nfiles = GrfSupport.LittleEndian32(buf, GRF_HEADER_MID_LEN + 8); grf.nfiles -= GrfSupport.LittleEndian32(buf, GRF_HEADER_MID_LEN + 4) + 7; /* Create the array of files */ grf.files = new Hashtable(StringComparer.OrdinalIgnoreCase); /* Grab the filesize */ grf.len = (uint)fStream.Length; /* Seek to the offset of the file tables */ br.BaseStream.Seek(GrfSupport.LittleEndian32(buf, GRF_HEADER_MID_LEN) + GRF_HEADER_FULL_LEN, SeekOrigin.Begin); /* Run a different function to read the file information based on * the major version number */ switch (grf.version & 0xFF00) { case 0x0200: i = GRF_readVer2_info(br, grf, callback); break; default: throw new Exception("UNSUP_GRF_VERSION"); } if (i > 0) { return(null); } } return(grf); }
/*! \brief Private function to read GRF0x2xx headers * * Reads the information about files within the archive... * for archive versions 0x02xx * * \todo Find GRF versions other than just 0x200 (do any exist?) * * \param grf Pointer to the Grf struct to read to * \param error Pointer to a GrfErrorType struct/enum for error reporting * \param callback Function to call for each read file. It should return 0 if * everything is fine, 1 if everything is fine (but further * reading should stop), or -1 if there has been an error * \return 0 if everything went fine, 1 if something went wrong */ static uint GRF_readVer2_info(System.IO.BinaryReader br, Grf grf, GrfOpenCallback callback) { uint i, offset, len, len2; byte[] buf, zbuf; /* Check grf */ if (grf.version != 0x200) { throw new Exception("GE_NSUP"); } /* Read the original and compressed sizes */ buf = br.ReadBytes(8); /* Allocate memory and read the compressed file table */ len = GrfSupport.LittleEndian32(buf, 0); zbuf = br.ReadBytes((int)len); if (0 == (len2 = GrfSupport.LittleEndian32(buf, 4))) { return(0); } /* Allocate memory and uncompress the compressed file table */ Array.Resize(ref buf, (int)len2); var stream = new InflaterInputStream(new MemoryStream(zbuf)); stream.Read(buf, 0, buf.Length); stream.Close(); /* Read information about each file */ for (i = offset = 0; i < grf.nfiles; i++) { /* Grab the filename length */ len = GrfSupport.getCStringLength(buf, offset) + 1; /* Make sure its not too large */ if (len >= GrfTypes.GRF_NAMELEN) { throw new Exception("GE_CORRUPTED"); } /* Grab filename */ GrfFile file = new GrfFile(); file.name = GrfSupport.getCString(buf, offset); offset += len; /* Grab the rest of the information */ file.compressed_len = GrfSupport.LittleEndian32(buf, (int)offset); file.compressed_len_aligned = GrfSupport.LittleEndian32(buf, (int)offset + 4); file.real_len = GrfSupport.LittleEndian32(buf, (int)offset + 8); file.flags = buf[offset + 0xC]; file.pos = GrfSupport.LittleEndian32(buf, (int)(offset + 0xD)) + (uint)GRF_HEADER_FULL_LEN; file.hash = GrfSupport.GRF_NameHash(file.name); file.name = NormalizePath(file.name); grf.files.Add(file.name, file); /* Advance to the next file */ offset += 0x11; /* Run the callback, if we have one */ if (callback != null) { callback.doCallback(file); if (!callback.hasReturned()) { throw new Exception("NO_RETURN"); } if (callback.Response < 0) { /* Callback function had an error, so we * have an error */ return(1); } else if (callback.Response > 0) { /* Callback function found the file it needed, * just exit now */ return(0); } } } /* Calling functions will set success... * GRF_SETERR(error,GE_SUCCESS,GRF_readVer2_info); */ return(0); }