mirror of
				https://github.com/chev2/botw-toolset.git
				synced 2025-10-30 08:12:17 +00:00 
			
		
		
		
	Update TSCB methods
FromBytes replaces ReadFile & uses a byte array instead of filename. GetBytes is renamed to ToBytes.
This commit is contained in:
		
							parent
							
								
									6d6e9f4749
								
							
						
					
					
						commit
						f19f94f459
					
				
					 2 changed files with 132 additions and 139 deletions
				
			
		|  | @ -306,7 +306,7 @@ namespace BOTWToolset.Control | |||
| 
 | ||||
|                 BOTWConsole.Log("Opening file"); | ||||
| 
 | ||||
|                 TSCB t = TSCB.ReadFile(openFileDialog.FileName); | ||||
|                 TSCB t = TSCB.FromBytes(File.ReadAllBytes(openFileDialog.FileName)); | ||||
| 
 | ||||
|                 // Set the current file location to the chosen file's location | ||||
|                 fileLocation = openFileDialog.FileName; | ||||
|  | @ -365,7 +365,7 @@ namespace BOTWToolset.Control | |||
| 
 | ||||
|             if ((bool)saveFileDialog.ShowDialog()) | ||||
|             { | ||||
|                 File.WriteAllBytes(saveFileDialog.FileName, TSCB.GetBytes(currentTSCB)); | ||||
|                 File.WriteAllBytes(saveFileDialog.FileName, TSCB.ToBytes(currentTSCB)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -52,14 +52,12 @@ namespace BOTWToolset.IO.TSCB | |||
|         /// </summary> | ||||
|         /// <param name="file">The .tscb file.</param> | ||||
|         /// <returns></returns> | ||||
|         public static TSCB ReadFile(string file) | ||||
|         { | ||||
|             if (File.Exists(file)) | ||||
|         public static TSCB FromBytes(byte[] bytes) | ||||
|         { | ||||
|             TSCB t = new TSCB(); | ||||
| 
 | ||||
|             // Use big-endian | ||||
|                 using (var r = new BinaryReaderBig(File.Open(file, FileMode.Open))) | ||||
|             using (var r = new BinaryReaderBig(new MemoryStream(bytes))) | ||||
|             { | ||||
|                 // Set header info from file on the new TSCBInfo | ||||
|                 t.Signature = new string(r.ReadChars(4)); | ||||
|  | @ -174,8 +172,8 @@ namespace BOTWToolset.IO.TSCB | |||
|                         } | ||||
|                         else //If the length is 4 | ||||
|                         { | ||||
|                                 var bytes = r.ReadBytes(16).ToArray(); | ||||
|                                 if (bytes[7] == 0) //If byte 7 equals 0 | ||||
|                             var areabytes = r.ReadBytes(16).ToArray(); | ||||
|                             if (areabytes[7] == 0) //If byte 7 equals 0 | ||||
|                                 areaInfo.HasGrass = true; | ||||
|                             else //Else if the 2nd byte should be anything else (should always be 1) | ||||
|                                 areaInfo.HasWater = true; | ||||
|  | @ -210,18 +208,13 @@ namespace BOTWToolset.IO.TSCB | |||
| 
 | ||||
|             return t; | ||||
|         } | ||||
|             else | ||||
|             { | ||||
|                 throw new FileNotFoundException("Cannot find .tscb file to read."); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Writes TSCB data to a byte array. | ||||
|         /// </summary> | ||||
|         /// <param name="tscb"><see cref="TSCB"/> that contains data to write.</param> | ||||
|         /// <returns>Byte array containing the TSCB data.</returns> | ||||
|         public static byte[] GetBytes(TSCB tscb) | ||||
|         public static byte[] ToBytes(TSCB tscb) | ||||
|         { | ||||
|             List<byte> b = new List<byte>(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Chev
						Chev