public Condition Clone() { byte[] data = StructWriter.Convert(this); object obj = QuestFile.CreateObject(this.getConditionType()); StructReader.Convert(data, ref obj); return((Condition)obj); }
public Reward Clone() { byte[] data = StructWriter.Convert(this); object obj = QuestFile.CreateObject(this.getRewardType()); StructReader.Convert(data, ref obj); return((Reward)obj); }
public static object BytesToObject(byte[] data, ref int offs, Type dt) { if (dt == typeof(bool)) { return((bool)(data[FixAlignment(ref offs, dt)] != 0)); } else if (dt == typeof(sbyte)) { return((sbyte)data[FixAlignment(ref offs, dt)]); } else if (dt == typeof(byte)) { return((byte)data[FixAlignment(ref offs, dt)]); } else if (dt == typeof(short)) { return(BitConverter.ToInt16(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(int)) { return(BitConverter.ToInt32(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(long)) { return(BitConverter.ToInt64(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(ushort)) { return(BitConverter.ToUInt16(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(uint)) { return(BitConverter.ToUInt32(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(ulong)) { return(BitConverter.ToUInt64(data, FixAlignment(ref offs, dt))); } else if (dt == typeof(string)) { BitConverter.ToInt16(data, FixAlignment(ref offs, typeof(short))); // unused int length = 0; while (data[offs + length] != '\0') { length++; } string str = Encoding.GetEncoding("EUC-KR").GetString(data, offs, length); offs += length + 1; return(str); } else if (dt.IsArray) { int dataCount = BitConverter.ToInt32(data, FixAlignment(ref offs, typeof(int))); if (dataCount > 1 && data.Length <= 20) { dataCount = 1; // one file has a bugged action } Array arr = Array.CreateInstance(dt.GetElementType(), dataCount); for (int i = 0; i < dataCount; i++) { object o = Activator.CreateInstance(dt.GetElementType()); StructReader.GetFields(data, ref offs, ref o); arr.SetValue(o, i); } return(arr); } else if (dt.IsEnum) { object value = BytesToObject(data, ref offs, Enum.GetUnderlyingType(dt)); return(Enum.Parse(dt, value.ToString())); } else { throw new FooException("Reading Unknown DataType " + dt); } }
public void Load(string Filename) { this.FileName = Filename; FileHandler fh = new FileHandler(Filename, FileHandler.FileOpenMode.Reading, Encoding.GetEncoding("EUC-KR")); Version = fh.Read <int>(); int blockCount = fh.Read <int>(); Title = fh.Read <string>(fh.Read <short>()).Trim('\0'); for (int i = 0; i < blockCount; i++) { QuestBlock block = new QuestBlock(); int triggersCount = fh.Read <int>(); block.Name = fh.Read <string>(fh.Read <short>()).Trim('\0'); for (int j = 0; j < triggersCount; j++) { QuestTrigger trigger = new QuestTrigger(); trigger.CheckNext = (fh.Read <byte>() != 0); int ConditionsCount = fh.Read <int>(); int RewardsCount = fh.Read <int>(); trigger.Name = fh.Read <string>(fh.Read <short>()).Trim('\0'); for (int c = 0; c < ConditionsCount; c++) { int size = fh.Read <int>(); int type = fh.Read <int>(); byte[] data = fh.Read <byte[]>(size - 8); try { object obj = CreateObject((ConditionType)type); StructReader.Convert(data, ref obj); Condition condition = (Condition)obj; condition.setOriginalData(data); trigger.Conditions.Add(condition); } catch { object obj = CreateObject(ConditionType.COND000); Condition condition = (Condition)obj; condition.setOriginalData(data); trigger.Conditions.Add(condition); } } for (int c = 0; c < RewardsCount; c++) { int size = fh.Read <int>(); int type = fh.Read <int>() & 0x0ffff; byte[] data = fh.Read <byte[]>(size - 8); try { object obj = CreateObject((RewardType)type); StructReader.Convert(data, ref obj); Reward reward = (Reward)obj; reward.setOriginalData(data); trigger.Rewards.Add(reward); } catch { object obj = CreateObject(RewardType.REWD000); Reward reward = (Reward)obj; reward.setOriginalData(data); trigger.Rewards.Add(reward); } } block.Triggers.Add(trigger); } this.Blocks.Add(block); } fh.Close(); }