/* * JAIV1 Velocity Region Structure * 0x00 byte baseVelocity; * 0x04 byte[0x03] unused; * 0x07 short wsysID; * 0x09 short waveID; * 0x0D float Volume; * 0x11 float Pitch; */ public JInstrumentKeyVelocity readKeyVelRegion(BeBinaryReader binStream, int Base) { JInstrumentKeyVelocity newReg = new JInstrumentKeyVelocity(); newReg.baseVel = binStream.ReadByte(); binStream.BaseStream.Seek(3, SeekOrigin.Current);; // Skip 3 bytes. newReg.velocity = newReg.baseVel; newReg.wsysid = binStream.ReadInt16(); newReg.wave = binStream.ReadInt16(); newReg.Volume = binStream.ReadSingle(); newReg.Pitch = binStream.ReadSingle(); return(newReg); }
public PlayerDef(BeBinaryReader br) { ID = br.ReadInt32(); MatchIndex = br.ReadInt32(); HiddenName = br.ReadInt32(); ShortName = br.ReadInt32(); FullName = br.ReadInt32(); Name = Encoding.ASCII.GetString(br.ReadBytes(24)); Gender = (Gender)br.ReadInt32(); IdleAnimation = br.ReadInt32(); Unk_34 = br.ReadInt32(); Description = br.ReadInt32(); Bodytype = (Bodytype)br.ReadInt32(); Scale = br.ReadInt32(); ShadowSize = br.ReadInt32(); TacticalAction = (TacticalAction)br.ReadInt32(); CourseAnimation = br.ReadInt32(); Team = br.ReadInt32(); Emblem = br.ReadInt32(); TeamPortrait = br.ReadInt32(); Position = br.ReadInt32(); MatchFaceModel = br.ReadInt32(); Facemodel = br.ReadInt32(); Facemodel2 = br.ReadInt32(); Bodymodel = br.ReadInt32(); Bodymodel2 = br.ReadInt32(); Unk_74 = br.ReadInt32(); Portrait = br.ReadInt32(); Unk_7C = br.ReadInt32(); LeftPortrait = br.ReadInt32(); RightPortrait = br.ReadInt32(); Equip = new string[2]; Equip[0] = Encoding.ASCII.GetString(br.ReadBytes(24)); Equip[1] = Encoding.ASCII.GetString(br.ReadBytes(24)); Unk_B8 = br.ReadBytes(48); SkinColor1 = Color.FromArgb(br.ReadInt32()); SkinColor2 = Color.FromArgb(br.ReadInt32()); Unk_F0 = br.ReadInt32(); Element = (Element)br.ReadInt32(); ChargeProfile = br.ReadInt32(); Unk_FC = br.ReadInt32(); Unk_100 = br.ReadInt32(); Voice = br.ReadInt32(); ArmedAttribution = br.ReadInt32(); Unk_10C = br.ReadInt32(); Price = br.ReadInt16(); ListPosition = br.ReadInt16(); TeamListPosition = br.ReadInt32(); Unk25 = br.ReadInt32(); Pad2 = br.ReadBytes(44); }
public Stats(BeBinaryReader br) { var pos = br.BaseStream.Position; Flag = br.ReadInt32(); Unknown = br.ReadInt32(); TP = br.ReadByte(); MaxTP = br.ReadByte(); Kick = br.ReadByte(); MaxKick = br.ReadByte(); Catch = br.ReadByte(); MaxCatch = br.ReadByte(); Body = br.ReadByte(); MaxBody = br.ReadByte(); Guard = br.ReadByte(); MaxGuard = br.ReadByte(); Control = br.ReadByte(); MaxControl = br.ReadByte(); Speed = br.ReadByte(); MaxSpeed = br.ReadByte(); Unk = br.ReadBytes(0xE); Kakusei = br.ReadInt32(); XP = br.ReadInt32(); MoveUnk = br.ReadInt16(); MoveKakusei2 = br.ReadInt16(); MoveKakusei2_2 = br.ReadInt16(); MoveKakusei2_3 = br.ReadInt16(); MoveKakusei3 = br.ReadInt16(); MoveKakusei3_2 = br.ReadInt16(); MoveKakusei3_3 = br.ReadInt16(); Unk2 = br.ReadInt16(); }
public static BSTWaveInfo readStream(BeBinaryReader br, int fmt) { var newWI = new BSTWaveInfo(); newWI.format = fmt; switch (fmt & 0xF0) { case 0x40: break; case 0x50: // Console.WriteLine($"{br.BaseStream.Position:X}"); newWI.wSoundID = br.ReadInt16(); // Console.WriteLine(newWI.wSoundID); break; case 0x60: break; case 0x70: newWI.streamFormat = br.ReadByte(); newWI.unk1 = br.ReadByte(); newWI.flags = br.ReadUInt16(); var namePointer = br.ReadInt32(); br.BaseStream.Position = namePointer; newWI.streamFilePath = JBST.readTerminated(br, 0x00); break; } return(newWI); }
private JC_DFEntry[] loadC_DF(BeBinaryReader binStream, int Base) { binStream.ReadInt32(); // should be C-DF. var count = binStream.ReadInt32(); // Read the count //Console.WriteLine("{0:X}" , binStream.BaseStream.Position); // DEBUG DEEEEBUG var Offsets = Helpers.readInt32Array(binStream, count); // Read all offsets, (count int32's) var idmap = new JC_DFEntry[count]; // New array to store all the waveid's in for (int i = 0; i < count; i++) { binStream.BaseStream.Position = Offsets[i] + Base; // Seek to each c_DF entry idmap[i] = new JC_DFEntry { mOffset = (int)binStream.BaseStream.Position, awid = binStream.ReadInt16(), // read AW ID -- A better name for this might be "SystemID" waveid = binStream.ReadInt16() // Read Wave ID }; } return(idmap); }
public Save(string name, int slot) { filename = name; BaseOffset = (uint)(0x2590 + slot * 0x68548); var file = File.OpenRead(filename); using (var br = new BeBinaryReader(file)) { br.BaseStream.Position = ONLINE_PROFILE; OnlineName = sjis.GetString(br.ReadBytes(16)); OnlineProfile = br.ReadUInt32(); br.BaseStream.Position = BaseOffset + 8; CreationDate = br.ReadUInt32(); CreationTime = br.ReadUInt32(); HoursPlayed = br.ReadUInt32(); MinutesPlayed = br.ReadUInt32(); br.BaseStream.Position = BaseOffset + INAZUMA_POINT_OFFSET; InazumaPoints = br.ReadUInt32(); br.BaseStream.Position = BaseOffset + PROFILENAME_OFFSET; ProfileName = sjis.GetString(br.ReadBytes(16)); for (var i = 0; i < 412; i++) { // Stats var player = new Player(); br.BaseStream.Position = BaseOffset + STATS_OFFSET + i * 0x3c; player.Stats = new Stats(br); // Moves br.BaseStream.Position = BaseOffset + WAZA_OFFSET + i * 0x22; player.MoveList = new MoveList(br); Players[i] = player; } br.BaseStream.Position = BaseOffset + TEAM_OFFSET; Team = new Team(br); br.BaseStream.Position = BaseOffset + PROFILENAME_OFFSET + 18; Team.Name = sjis.GetString(br.ReadBytes(16)); br.BaseStream.Position = BaseOffset + TEAM_EMBLEM_OFFSET; Team.Emblem = br.ReadInt16(); br.BaseStream.Position = BaseOffset + PROFILE_OFFSET; Profile = br.ReadUInt32(); } }
public static void Load(BeBinaryReader br, Save save) { save.Team = new Team(br); save.Team.Emblem = br.ReadInt16(); save.Team.Name = br.ReadString(); for (int i = 0; i < 16; i++) { var player = new Player(); player.MoveList = new MoveList(br); player.Stats = new Stats(br); var teamPlayer = save.Team.Players[i]; var id = teamPlayer.Id; save.Players[id] = player; } }
public Team(BeBinaryReader br) { br.BaseStream.Position += 2; Kit = br.ReadInt16(); Formation = br.ReadInt32(); Manager = br.ReadInt32(); Coach = br.ReadInt32(); Emblem = 0; //Placeholder Players = new TeamPlayer[16]; Name = ""; for (var i = 0; i < 16; i++) { Players[i] = new TeamPlayer(br); } }
/* * SAME AS JAIV1 * JAIV2 Oscillator Vector Structure * These are weird. so i'll just do it like this * short mode * short time * short value * * when you read anything over 8 for the mode, read the last two shorts then stop reading -- so the last value in the array would be * * 0x000F, 0x0000, 0x0000 */ public JEnvelope readEnvelope(BeBinaryReader binStream, int Base) { var len = 0; // This function cheats a little bit :) // We dive in not knowing the length of the table -- the table is stopped whenever one of the MODE bytes is more than 0xB. var seekBase = binStream.BaseStream.Position; for (int i = 0; i < 10; i++) { var mode = binStream.ReadInt16(); // reads the first 2 bytes of the table len++; // The reason we do this, is because we still need to read the loop flag, or stop flag. if (mode < 0xB) // This determines the mode, the mode will always be less than 0xB -- unless its telling the table to end. { // If it is, then we definitely want to read this entry, so we increment the counter binStream.ReadInt32(); // Then skip the actual entry data } else // The value was over 10 { break; // So we need to stop the loop } } binStream.BaseStream.Position = seekBase; // After we have an idea how big the table is -- we want to seek back to the beginning of it. JEnvelopeVector[] OscVecs = new JEnvelopeVector[len]; // And create an array the size of our length. for (int i = 0; i < len - 1; i++) // we read - 1 because we don't want to read the end value yet { var vector = new JEnvelopeVector { mode = (JEnvelopeVectorMode)binStream.ReadInt16(), // Read the values of each into their places time = binStream.ReadInt16(), // read time value = binStream.ReadInt16() // read value }; OscVecs[i] = vector; } // Go down below for the last vector, after sorting // todo: Figure out why this doesn't sort right? // -1 is so we don't sort the last object in the array, because its null. We're sorting from the bottom up. for (int i = 0; i < len - 1; i++) // a third __fucking iteration__ on these stupid vectors. { for (int j = 0; j < len - 1; j++) { var current = OscVecs[i]; // Grab current oscillator vector, notice the for loop starts at 1 var cmp = OscVecs[j]; // Grab the previous object if (cmp.time > current.time) // if its time is greater than ours { OscVecs[j] = current; // shift us down OscVecs[i] = cmp; // shift it up } } } //*/ // Now that we've sorted the vectors because nintendo packs them out of f*****g order. // We can add the hold / stop vector :D // We havent advanced any more bytes by the way, so we're still at the end of that vector array from before. var lastVector = OscVecs[OscVecs.Length - 2]; // -2 gets the last indexed object. // This is disgusting, i know. OscVecs[OscVecs.Length - 1] = new JEnvelopeVector { mode = (JEnvelopeVectorMode)binStream.ReadInt16(), // Read the values of each into their places time = (short)(lastVector.time), // read time value = lastVector.value // read value }; // Setting up references. // can only be done after sorting :v... for (int idx = 0; idx < OscVecs.Length - 1; idx++) { OscVecs[idx].next = OscVecs[idx + 1]; // current vector objects next is the one after it. } var ret = new JEnvelope(); ret.vectorList = OscVecs; return(ret); // finally, return. }
public JaiEventType loadNextOp() { if (OpcodeAddressStack.Count == 16) { OpcodeAddressStack.Dequeue(); } if (OpcodeHistory.Count == 16) { OpcodeHistory.Dequeue(); } OpcodeAddressStack.Enqueue((int)Sequence.BaseStream.Position); // push address to FIFO stack. State.current_address = (int)Sequence.BaseStream.Position; byte current_opcode = Sequence.ReadByte(); // Reads the current byte in front of the cursor. last_opcode = current_opcode; OpcodeHistory.Enqueue(current_opcode); // push opcode to FIFO stack if (current_opcode < 0x80) { State.note = current_opcode; // The note on event is laid out like a piano with 127 (0x7F1) keys. // So this means that the first 0x80 bytes are just pressing the individual keys. State.voice = Sequence.ReadByte(); // The next byte tells the voice, 0-8 State.vel = Sequence.ReadByte(); // And finally, the next byte will tell the velocity return(JaiEventType.NOTE_ON); // Return the note on event. } else if (current_opcode == (byte)JaiSeqEvent.WAIT_8) // Contrast to above, the opcode between these two is WAIT_U8 { State.delay += Sequence.ReadByte(); // Add u8 ticks to the delay. return(JaiEventType.DELAY); } else if (current_opcode < 0x88) // We already check if it's 0x80, so anything between here will be 0x81 and 0x87 { // Only the first 7 bits are going to determine which voice we're stopping. State.voice = (byte)(current_opcode & 0x7F); return(JaiEventType.NOTE_OFF); } else // Finally, we can fall into our CASE statement. { switch (current_opcode) { /* Delays and waits */ case (byte)JaiSeqEvent.WAIT_16: // Wait (UInt16) State.delay = Sequence.ReadUInt16(); // Add to the state delay return(JaiEventType.DELAY); case (byte)JaiSeqEvent.WAIT_VAR: // Wait (VLQ) see readVlq function. State.delay += Helpers.ReadVLQ(Sequence); return(JaiEventType.DELAY); /* Logical jumps */ case (byte)JaiSeqEvent.JUMP: // Unconditional jump State.jump_mode = 0; // Set jump mode to 0 State.jump_address = Sequence.ReadInt32(); // Absolute address. return(JaiEventType.JUMP); case (byte)JaiSeqEvent.JUMP_COND: // Jump based on mode State.jump_mode = Sequence.ReadByte(); State.jump_address = (int)Helpers.ReadUInt24BE(Sequence); // pointer return(JaiEventType.JUMP); case (byte)JaiSeqEvent.RET_COND: State.jump_mode = Sequence.ReadByte(); return(JaiEventType.RET); case (byte)JaiSeqEvent.CALL_COND: State.jump_mode = Sequence.ReadByte(); State.jump_address = (int)Helpers.ReadUInt24BE(Sequence); return(JaiEventType.CALL); case (byte)JaiSeqEvent.RET: return(JaiEventType.RET); /* Tempo Control */ case (byte)JaiSeqEvent.J2_SET_ARTIC: // The very same. { var type = Sequence.ReadByte(); var val = Sequence.ReadInt16(); if (type == 0x62) { State.ppqn = val; } return(JaiEventType.TIME_BASE); } case (byte)JaiSeqEvent.TIME_BASE: // Set ticks per quarter note. State.ppqn = (short)(Sequence.ReadInt16()); //State.bpm = 100; Console.WriteLine("Timebase ppqn set {0}", State.ppqn); return(JaiEventType.TIME_BASE); case (byte)JaiSeqEvent.J2_TEMPO: // Set BPM, Same format case (byte)JaiSeqEvent.TEMPO: // Set BPM State.bpm = (short)(Sequence.ReadInt16()); return(JaiEventType.TIME_BASE); /* Track Control */ case (byte)JaiSeqEvent.OPEN_TRACK: State.track_id = Sequence.ReadByte(); State.track_address = (int)Helpers.ReadUInt24BE(Sequence); // Pointer to track inside of BMS file (Absolute) return(JaiEventType.NEW_TRACK); case (byte)JaiSeqEvent.FIN: return(JaiEventType.HALT); case (byte)JaiSeqEvent.J2_SET_BANK: State.voice_bank = Sequence.ReadByte(); return(JaiEventType.BANK_CHANGE); case (byte)JaiSeqEvent.J2_SET_PROG: State.voice_program = Sequence.ReadByte(); return(JaiEventType.PROG_CHANGE); /* Parameter control */ case (byte)JaiSeqEvent.J2_SET_PERF_8: State.param = Sequence.ReadByte(); State.param_value = Sequence.ReadByte(); return(JaiEventType.PARAM); case (byte)JaiSeqEvent.J2_SET_PERF_16: State.param = Sequence.ReadByte(); State.param_value = Sequence.ReadInt16(); return(JaiEventType.PARAM); case (byte)JaiSeqEvent.PARAM_SET_8: // Set track parameters (Usually used for instruments) State.param = Sequence.ReadByte(); State.param_value = Sequence.ReadByte(); if (State.param == 0x20) // 0x20 is bank change { State.voice_bank = (byte)State.param_value; return(JaiEventType.BANK_CHANGE); } if (State.param == 0x21) // 0x21 is program change { State.voice_program = (byte)State.param_value; return(JaiEventType.PROG_CHANGE); } return(JaiEventType.PARAM); case (byte)JaiSeqEvent.PARAM_SET_16: // Set track parameters (Usually used for instruments) State.param = Sequence.ReadByte(); State.param_value = Sequence.ReadInt16(); if (State.param == 0x20) // 0x20 is bank change { State.voice_bank = (byte)State.param_value; return(JaiEventType.BANK_CHANGE); } if (State.param == 0x21) // 0x21 is program change { State.voice_program = (byte)State.param_value; return(JaiEventType.PROG_CHANGE); } return(JaiEventType.PARAM); case (byte)JaiSeqEvent.PRINTF: var lastread = -1; string v = ""; while (lastread != 0) { lastread = Sequence.ReadByte(); v += (char)lastread; } // Sequence.ReadByte(); Console.WriteLine(v); return(JaiEventType.UNKNOWN); /* PERF Control*/ /* Perf structure is as follows * <byte> type * <?> val * (<?> dur) */ case (byte)JaiSeqEvent.PERF_U8_NODUR: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadByte(); State.perf_duration = 0; State.perf_type = 1; State.perf_decimal = ((double)State.perf_value / 0xFF); return(JaiEventType.PERF); case (byte)JaiSeqEvent.PERF_U8_DUR_U8: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadByte(); State.perf_duration = Sequence.ReadByte(); State.perf_type = 1; State.perf_decimal = ((double)State.perf_value / 0xFF); return(JaiEventType.PERF); case (byte)JaiSeqEvent.PERF_U8_DUR_U16: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadByte(); State.perf_duration = Sequence.ReadUInt16(); State.perf_type = 1; State.perf_decimal = ((double)State.perf_value / 0xFF); return(JaiEventType.PERF); case (byte)JaiSeqEvent.PERF_S8_NODUR: { State.perf = Sequence.ReadByte(); var b = Sequence.ReadByte(); // Lazy byte signage, apparently C#'s SByte is broken. State.perf_value = (b > 0x7F) ? b - 0xFF : b; State.perf_duration = 0; State.perf_type = 2; State.perf_decimal = ((double)(State.perf_value) / 0x7F); return(JaiEventType.PERF); } case (byte)JaiSeqEvent.PERF_S8_DUR_U8: { State.perf = Sequence.ReadByte(); var b = Sequence.ReadByte(); // Lazy byte signage, apparently C#'s SByte is broken. State.perf_value = (b > 0x7F) ? b - 0xFF : b; State.perf_duration = Sequence.ReadByte(); State.perf_type = 2; State.perf_decimal = ((double)(State.perf_value) / 0x7F); return(JaiEventType.PERF); } case (byte)JaiSeqEvent.PERF_S8_DUR_U16: { State.perf = Sequence.ReadByte(); var b = Sequence.ReadByte(); // Lazy byte signage, apparently C#'s SByte is broken. State.perf_value = State.perf_value = (b > 0x7F) ? b - 0xFF : b; State.perf_duration = Sequence.ReadUInt16(); State.perf_type = 2; State.perf_decimal = ((double)(State.perf_value) / 0x7F); return(JaiEventType.PERF); } case (byte)JaiSeqEvent.PERF_S16_NODUR: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadInt16(); State.perf_duration = 0; State.perf_type = 3; State.perf_decimal = ((double)(State.perf_value) / 0x7FFF); return(JaiEventType.PERF); case (byte)JaiSeqEvent.PERF_S16_DUR_U8: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadInt16(); State.perf_duration = Sequence.ReadByte(); State.perf_type = 3; State.perf_decimal = ((double)(State.perf_value) / 0x7FFF); return(JaiEventType.PERF); case (byte)JaiSeqEvent.PERF_S16_DUR_U16: State.perf = Sequence.ReadByte(); State.perf_value = Sequence.ReadInt16(); State.perf_duration = Sequence.ReadUInt16(); State.perf_type = 3; State.perf_decimal = ((double)(State.perf_value) / 0x7FFF); return(JaiEventType.PERF); /* J2 Opcodes */ /* Unsure as of yet, but we have to keep alignment */ case 0xE7: skip(2); // Console.WriteLine(Sequence.ReadByte()); //Console.WriteLine(Sequence.ReadByte()); return(JaiEventType.DEBUG); case 0xDD: case 0xED: skip(3); return(JaiEventType.UNKNOWN); case 0xEF: case 0xF9: case 0xE6: skip(2); return(JaiEventType.UNKNOWN); case 0xA0: case (byte)JaiSeqEvent.ADDR: // skip(2); return(JaiEventType.UNKNOWN); case 0xA3: skip(2); return(JaiEventType.UNKNOWN); case 0xA5: skip(2); return(JaiEventType.UNKNOWN); case 0xA7: skip(2); return(JaiEventType.UNKNOWN); case 0xA9: skip(4); return(JaiEventType.UNKNOWN); case 0xAA: skip(4); return(JaiEventType.UNKNOWN); case 0xAD: // State.delay += 0xFFFF; // Add (byte) register. + (short) value // skip(3); return(JaiEventType.UNKNOWN); case 0xAE: return(JaiEventType.UNKNOWN); case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7: int flag = Sequence.ReadByte(); if (flag == 0x40) { skip(2); } if (flag == 0x80) { skip(4); } return(JaiEventType.UNKNOWN); case 0xDB: case 0xDF: skip(4); return(JaiEventType.UNKNOWN); case 0xCB: case 0xBE: skip(2); return(JaiEventType.UNKNOWN); case 0xCC: skip(2); return(JaiEventType.UNKNOWN); case 0xCF: skip(1); return(JaiEventType.UNKNOWN); case 0xD0: case 0xD1: case 0xD2: case 0xD5: case 0xD9: case 0xDE: case 0xDA: skip(1); return(JaiEventType.UNKNOWN); case 0xF1: case 0xF4: case 0xD6: skip(1); //Console.WriteLine(Sequence.ReadByte()); return(JaiEventType.DEBUG); case 0xBC: return(JaiEventType.UNKNOWN); } } return(JaiEventType.UNKNOWN_ALIGN_FAIL); }
public static void Unpack(string xgr, string dir) { string imgb = Path.Combine(Path.GetDirectoryName(xgr), $"{Path.GetFileNameWithoutExtension(xgr)}.imgb"); if (!File.Exists(imgb)) { throw new Exception("IMGB file not found."); } FileStream stream = File.OpenRead(xgr); FileStream imgbStream = File.OpenRead(imgb); BeBinaryReader reader = new BeBinaryReader(stream); BinaryReader imgbReader = new BinaryReader(imgbStream); if (reader.ReadInt32() == 0x57504400) { uint fileCount = reader.ReadUInt32(); reader.BaseStream.Position += 8; //zeroes for (int i = 0; i < fileCount; i++) { string fileName = Encoding.ASCII.GetString(reader.ReadBytes(16)).Replace($"{(char)0}", string.Empty); uint infoOffset = reader.ReadUInt32(); uint infoSize = reader.ReadUInt32(); string fileExt = Encoding.ASCII.GetString(reader.ReadBytes(8)).Replace($"{(char)0}", string.Empty); string filePath = Path.Combine(dir, $"{fileName}.{fileExt}"); long current = reader.BaseStream.Position; reader.BaseStream.Position = infoOffset; if (fileExt == "txbh") { string magicWord = Encoding.ASCII.GetString(reader.ReadBytes(8)).Replace($"{(char)0}", string.Empty); reader.BaseStream.Position += 56; //unknow string fileType = Encoding.ASCII.GetString(reader.ReadBytes(4)).Replace($"{(char)0}", string.Empty); reader.BaseStream.Position += 2; //unknow GTEXFormat.GtexPixelFormat format = (GTEXFormat.GtexPixelFormat)reader.ReadByte(); byte mimapCount = reader.ReadByte(); reader.ReadByte(); //unknow bool isCubeMap = reader.ReadBoolean(); ushort width = reader.ReadUInt16(); ushort height = reader.ReadUInt16(); short depth = reader.ReadInt16(); int linerSize = reader.ReadInt32(); reader.BaseStream.Position += 4; uint offsetImgb = reader.ReadUInt32(); uint size = reader.ReadUInt32(); imgbReader.BaseStream.Position = offsetImgb; byte[] raw = imgbReader.ReadBytes((int)size); byte[] result = DDS.Create(width, height, format, mimapCount, depth, linerSize, raw); File.WriteAllBytes($"{filePath}.dds", result); } else { byte[] bytes = reader.ReadBytes((int)infoSize); File.WriteAllBytes($"{filePath}.{fileExt}", bytes); } Console.WriteLine($"Unpacked: {fileName}.{fileExt}"); reader.BaseStream.Position = current; } } else { throw new Exception("File is not a XGR file."); } reader.Close(); stream.Close(); imgbReader.Close(); imgbStream.Close(); }
private int back = 0; // utility public void LoadWSYS(BeBinaryReader WSYSReader) { BaseAddress = WSYSReader.BaseStream.Position; waves = new WSYSWave[32768]; // TEMPORARY. Fix WSYS Loading! current_header = WSYSReader.ReadInt32(); if (current_header != WSYS) { Console.WriteLine("Error: Section base at {0} is not WSYS, is instead {1:X}", BaseAddress, current_header); return; } size = WSYSReader.ReadInt32(); id = WSYSReader.ReadInt32(); WSYSReader.ReadUInt32(); // 4 bytes, not used. .. I think // A little messy, but both of these need to be loaded before we can continue. var winfo_offset = WSYSReader.ReadInt32(); // relative offset to wave info offset pointer table. var wbct_offset = WSYSReader.ReadInt32(); // relative offset to wave info offset pointer table. int[] winfOffsets; int[] wbctOffsets; { // Load WINF offsets. WSYSReader.BaseStream.Position = BaseAddress + winfo_offset; current_header = WSYSReader.ReadInt32(); // Should be WINF winfOffsets = new int[WSYSReader.ReadInt32()]; // 4 bytes count for (int i = 0; i < winfOffsets.Length; i++) { winfOffsets[i] = WSYSReader.ReadInt32(); // Int32's following the length. } // Load WBCT data WSYSReader.BaseStream.Position = BaseAddress + wbct_offset; current_header = WSYSReader.ReadInt32(); // Should be WBCT WSYSReader.ReadUInt32(); // 4 bytes unused? wbctOffsets = new int[WSYSReader.ReadInt32()]; // 4 bytes count for (int i = 0; i < wbctOffsets.Length; i++) { wbctOffsets[i] = WSYSReader.ReadInt32(); // Int32's following the length. } } groups = new WSYSGroup[winfOffsets.Length]; for (int i = 0; i < winfOffsets.Length; i++) { /* This is loading the data for a WINF */ WSYSReader.BaseStream.Position = BaseAddress + winfOffsets[i]; var Group = new WSYSGroup(); Group.path = Helpers.readArchiveName(WSYSReader); var fobj = File.OpenRead("./Banks/" + Group.path); // Open the .AW file (AW contains only ADPCM data, nothing else.) var fobj_reader = new BeBinaryReader(fobj); // Create a reader for it. int waveInfoCounts = WSYSReader.ReadInt32(); // 4 byte count int[] info_offsets = new int[waveInfoCounts]; for (int q = 0; q < waveInfoCounts; q++) { info_offsets[q] = WSYSReader.ReadInt32(); } Group.IDMap = new int[UInt16.MaxValue]; // We have to initialize the containers for the wave information Group.Waves = new WSYSWave[waveInfoCounts]; /* Since the count should be equal, we're loading the info for the WBCT in he re as well */ WSYSReader.BaseStream.Position = BaseAddress + wbctOffsets[i]; // The first several bytes of the WBCT are uselss, a WBCT points directly to a SCNE. current_header = WSYSReader.ReadInt32(); // This should be SCNE. WSYSReader.ReadUInt64(); // The next 8 bytes are useless. var cdf_offset = WSYSReader.ReadInt32(); // However, the next 4 contain the pointer to c_DF relative to our base. WSYSReader.BaseStream.Position = BaseAddress + cdf_offset; current_header = WSYSReader.ReadInt32(); // Should be C_DF. int waveid_count = WSYSReader.ReadInt32(); // Count of our WAVE ID int[] waveid_offsets = new int[waveid_count]; // Be ready to store them for (int q = 0; q < waveid_count; q++) { waveid_offsets[q] = WSYSReader.ReadInt32(); // Read each waveid } // Finally, we're going to get our wave data. for (int wav = 0; wav < waveInfoCounts; wav++) { var o_Wave = new WSYSWave(); WSYSReader.BaseStream.Position = BaseAddress + waveid_offsets[wav]; var aw_id = WSYSReader.ReadInt16(); // Strangely enough, it has an AW_ID here. This tells which file it sits in? I guess they're normally loaded separately. o_Wave.id = WSYSReader.ReadInt16(); // This is the waveid for this wave, it's normally globally unique, but some games hot-load banks. WSYSReader.BaseStream.Position = BaseAddress + info_offsets[wav]; // Seek to the offset of the actual wave parameters. WSYSReader.ReadByte(); // I have no clue what the first byte does. o_Wave.format = WSYSReader.ReadByte(); // Tells what format it's in, usually type 5 AFC (ADPCM) o_Wave.key = WSYSReader.ReadByte(); // Tells the base key for this wave (0-127 usually) WSYSReader.ReadByte(); // I have no clue what this byte does. //var srate = WSYSReader.ReadBytes(4); o_Wave.sampleRate = WSYSReader.ReadSingle(); /* * oh. its a float. * oops * if (o_Wave.format == 5) * { * o_Wave.sampleRate = 32000; /// ???? * } * * if (o_Wave.sampleRate == 5666) // What the actual f**k. Broken value, can't figure out why. * { * o_Wave.sampleRate = 44100; // I guess set the srate to 44100? * } */ o_Wave.w_start = WSYSReader.ReadUInt32(); // 4 byte start in AW o_Wave.w_size = WSYSReader.ReadUInt32(); // 4 byte size in AW var b = WSYSReader.ReadUInt32(); o_Wave.loop = b == UInt32.MaxValue ? true : false; // Weird looping flag? o_Wave.loop_start = (int)Math.Floor(((WSYSReader.ReadInt32() / 8f)) * 16f); o_Wave.loop_end = (int)Math.Floor(((WSYSReader.ReadInt32() / 8f)) * 16f); o_Wave.sampleCount = WSYSReader.ReadInt32(); // 4 byte sample cont // Console.WriteLine("L {0:X} (0x{1:X}), LS {2:X} , LE {3:X}, SC {4:X} SZ {5:X}", o_Wave.loop, b, o_Wave.loop_start, o_Wave.loop_end,o_Wave.sampleCount,o_Wave.w_size); //Console.ReadLine(); var name = string.Format("0x{0:X}.wav", o_Wave.id); var name2 = string.Format("0x{0:X}.par", o_Wave.id); if (!Directory.Exists("./WSYS_CACHE")) { Directory.CreateDirectory("./WSYS_CACHE"); } if (!Directory.Exists("./WSYS_CACHE/AW_" + Group.path)) { Directory.CreateDirectory("./WSYS_CACHE/AW_" + Group.path); } o_Wave.pcmpath = "./WSYS_CACHE/AW_" + Group.path + "/" + name; Group.Waves[wav] = o_Wave; // We're done with just about everything except the PCM data now (ADPCM / AFC conversion) Group.IDMap[o_Wave.id] = wav; waves[o_Wave.id] = o_Wave; // TEMPORARY, FIX WSYS LOADING! fobj_reader.BaseStream.Position = o_Wave.w_start; var adpcm = fobj_reader.ReadBytes((int)o_Wave.w_size); if (!File.Exists(o_Wave.pcmpath)) { Helpers.AFCtoPCM16(adpcm, o_Wave.sampleRate, (int)o_Wave.w_size, o_Wave.format, o_Wave.pcmpath); } } } }
private void BtnLoadCHA_Click(object sender, win.RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Photoshop RGB Channel Mixer Preset (.cha)|*.cha"; float[,] PSmatrix = new float[3, 3]; int[] useless = new int[3]; // I think these are for CMYK int[] constant = new int[3]; if (ofd.ShowDialog() == true) { string filename = ofd.FileName; using (FileStream fs = File.Open(filename, FileMode.Open)) { using (BeBinaryReader binReader = new BeBinaryReader(fs)) { uint version = binReader.ReadUInt16(); uint monochrome = binReader.ReadUInt16(); PSmatrix[0, 0] = binReader.ReadInt16() / 100f; PSmatrix[0, 1] = binReader.ReadInt16() / 100f; PSmatrix[0, 2] = binReader.ReadInt16() / 100f; useless[0] = binReader.ReadInt16(); constant[0] = binReader.ReadInt16(); PSmatrix[1, 0] = binReader.ReadInt16() / 100f; PSmatrix[1, 1] = binReader.ReadInt16() / 100f; PSmatrix[1, 2] = binReader.ReadInt16() / 100f; useless[1] = binReader.ReadInt16(); constant[1] = binReader.ReadInt16(); PSmatrix[2, 0] = binReader.ReadInt16() / 100f; PSmatrix[2, 1] = binReader.ReadInt16() / 100f; PSmatrix[2, 2] = binReader.ReadInt16() / 100f; useless[2] = binReader.ReadInt16(); constant[2] = binReader.ReadInt16(); } } setStatus(Helpers.matrixToString <float>(PSmatrix)); SetSlidersToMatrix(PSmatrix); RegradeImage(PSmatrix); } }
public MoveList(BeBinaryReader br) { Lv1 = br.ReadInt16(); Lv2 = br.ReadInt16(); Lv3 = br.ReadInt16(); unk1 = br.ReadInt16(); Dribble = br.ReadInt16(); unk2 = br.ReadInt16(); unk3 = br.ReadInt16(); unk4 = br.ReadInt16(); Defense = br.ReadInt16(); unk5 = br.ReadInt16(); unk6 = br.ReadInt16(); unk7 = br.ReadInt16(); Catch1 = br.ReadInt16(); Catch2 = br.ReadInt16(); Catch3 = br.ReadInt16(); unk8 = br.ReadInt16(); SP = br.ReadInt16(); }