public static TriggerXfer FromStream(Stream mstream, short ParsingRule) { TriggerXfer result = GetDefault(); NoxBinaryReader br = new NoxBinaryReader(mstream); // collisionbox result.SizeX = br.ReadInt32(); result.SizeY = br.ReadInt32(); if (result.SizeX > 60) result.SizeX = 60; if (result.SizeY > 60) result.SizeY = 60; // цвета заливки и граней для PressurePlate result.EdgeColor = br.ReadColor(); result.BackColor = br.ReadColor(); result.UnkInt1 = br.ReadInt32(); // обработчики событий result.ScriptOnPressed = br.ReadScriptEventString(); result.ScriptOnReleased = br.ReadScriptEventString(); result.ScriptOnCollided = br.ReadScriptEventString(); // кто может активировать result.AllowedObjClass = br.ReadInt32(); result.IgnoredObjClass = br.ReadInt32(); result.AllowedTeamID = br.ReadByte(); result.IgnoredTeamID = br.ReadByte(); if (ParsingRule >= 61) { result.TriggerState = br.ReadByte(); result.Unk7 = br.ReadByte(); result.UnkInt2 = br.ReadInt32(); } return result; }
public int UnknownVal; // 0x94 #endregion Fields #region Methods public static InvisibleLightXfer FromMapObject(Map.Object obj) { InvisibleLightXfer result = new InvisibleLightXfer(); using (NoxBinaryReader br = new NoxBinaryReader(new MemoryStream(obj.modbuf))) { result.StateMB = br.ReadInt32(); // 2 normally result.LightIntensity = br.ReadSingle(); result.LightRadius = br.ReadInt32(); result.UnknownVal = br.ReadInt32(); // unused? result.BaseColor = br.ReadColor(); // ChangeColors is used normally result.Unknown3 = br.ReadInt16(); // Color Flags? result.Unknown4 = br.ReadInt16(); result.Unknown5 = br.ReadInt32(); // Flags2? result.Unknown6 = br.ReadInt16(); // Some flag result.ChangeColors = new Color[16]; for (int i = 0; i < 16; i++) result.ChangeColors[i] = br.ReadColor(); result.ChangeIntensity = new byte[16]; for (int i = 0; i < 16; i++) result.ChangeIntensity[i] = br.ReadByte(); result.ChangeRadius = new byte[16]; for (int i = 0; i < 16; i++) result.ChangeRadius[i] = br.ReadByte(); result.ColorChangeIndex = br.ReadInt16(); result.IntensityChangeIndex = br.ReadInt16(); result.RadiusChangeIndex = br.ReadInt16(); result.ObjExtentID = br.ReadInt32(); result.Unknown13 = br.ReadInt16(); // some flags result.Unknown14 = br.ReadInt16(); result.Unknown15 = br.ReadByte(); if (obj.ReadRule1 > 40) { if (obj.ReadRule1 < 42) br.ReadByte(); else result.Unknown16 = br.ReadInt32(); // unused? } } return result; }
public void ReadFile() { NoxBinaryReader rdr = new NoxBinaryReader(File.Open(filename, FileMode.Open), CryptApi.NoxCryptFormat.PLR); //find out what kind of file we got FileType = (PlrFileType) rdr.ReadInt64(); //switch for different formats switch (FileType) { case PlrFileType.SOLO: System.Windows.Forms.MessageBox.Show("Sorry, solo/quest player files are not yet supported.", "Error"); ReadSPHeader(rdr); //ReadSpellset(rdr); rdr.BaseStream.Seek(0, SeekOrigin.End); break; case PlrFileType.MULTI: ReadSpellset(rdr); rdr.ReadInt32();//TODO: dunno what this int is doing hangin out here, always 0x00000001? rdr.SkipToNextBoundary(); ReadCharacterInfo(rdr); rdr.ReadBytes(4);//(TODO) 0c 00 00 00 -- this occupies unaccounted-for space and is post-padded rdr.SkipToNextBoundary(); rdr.ReadBytes((int) rdr.ReadInt64());//skip the next section (the 3byte one) rdr.SkipToNextBoundary(); break; default: throw new IOException("Unknown player file format"); } System.Diagnostics.Debug.Assert(rdr.BaseStream.Position == rdr.BaseStream.Length, "Wrong number of total bytes read."); rdr.Close(); }
public void ReadFile() { NoxBinaryReader rdr = new NoxBinaryReader(File.Open(filename, FileMode.Open), CryptApi.NoxCryptFormat.PLR); //find out what kind of file we got FileType = (PlrFileType)rdr.ReadInt64(); //switch for different formats switch (FileType) { case PlrFileType.SOLO: System.Windows.Forms.MessageBox.Show("Sorry, solo/quest player files are not yet supported.", "Error"); ReadSPHeader(rdr); //ReadSpellset(rdr); rdr.BaseStream.Seek(0, SeekOrigin.End); break; case PlrFileType.MULTI: ReadSpellset(rdr); rdr.ReadInt32(); //TODO: dunno what this int is doing hangin out here, always 0x00000001? rdr.SkipToNextBoundary(); ReadCharacterInfo(rdr); rdr.ReadBytes(4); //(TODO) 0c 00 00 00 -- this occupies unaccounted-for space and is post-padded rdr.SkipToNextBoundary(); rdr.ReadBytes((int)rdr.ReadInt64()); //skip the next section (the 3byte one) rdr.SkipToNextBoundary(); break; default: throw new IOException("Unknown player file format"); } System.Diagnostics.Debug.Assert(rdr.BaseStream.Position == rdr.BaseStream.Length, "Wrong number of total bytes read."); rdr.Close(); }
public static SpellRewardXfer FromMapObject(Map.Object obj) { SpellRewardXfer result = new SpellRewardXfer(); using (NoxBinaryReader br = new NoxBinaryReader(new MemoryStream(obj.modbuf))) { result.SpellName = br.ReadString(); } return result; }
public static FieldGuideXfer FromMapObject(Map.Object obj) { FieldGuideXfer result = new FieldGuideXfer(); using (NoxBinaryReader br = new NoxBinaryReader(new MemoryStream(obj.modbuf))) { result.MonsterSID = br.ReadString(); } return result; }
public static HoleXfer FromStream(Stream mstream, short ParsingRule) { HoleXfer result = new HoleXfer(); NoxBinaryReader br = new NoxBinaryReader(mstream); if (ParsingRule < 42) throw new NotSupportedException("Where did you find this map?"); result.ScriptActivated = br.ReadInt32(); // какой-то скриптовый обработчик result.UnknownScriptHandler = br.ReadScriptEventString(); // координаты места падения result.FallX = br.ReadInt32(); result.FallY = br.ReadInt32(); // таймаут вызова скрипта result.ScriptTime1 = br.ReadInt32(); result.ScriptTimeout = br.ReadInt16(); return result; }
public static GlyphXfer FromStream(Stream stream, short ParsingRule) { GlyphXfer result = new GlyphXfer(); NoxBinaryReader br = new NoxBinaryReader(stream); if (ParsingRule < 41) br.ReadInt32(); result.Angle = br.ReadByte(); result.TargX = br.ReadSingle(); result.TargY = br.ReadSingle(); byte spells = br.ReadByte(); while (spells > 0) { result.Spells.Add(br.ReadString()); spells--; } return result; }
public static RewardMarkerXfer FromStream(Stream stream, short ParsingRule) { RewardMarkerXfer result = new RewardMarkerXfer(); NoxBinaryReader br = new NoxBinaryReader(stream); result.RewardType = (RewardFlags) br.ReadUInt32(); result.Unknown1 = br.ReadInt32(); // spells short count = br.ReadInt16(); result.Spells = new List<string>(count); while (count > 0) { result.Spells.Add(br.ReadString()); count--; } // abilities count = br.ReadInt16(); result.Abilities = new List<string>(count); while (count > 0) { result.Abilities.Add(br.ReadString()); count--; } // monster scrolls count = br.ReadInt16(); result.Monsters = new List<string>(count); while (count > 0) { result.Monsters.Add(br.ReadString()); count--; } result.Unknown2 = br.ReadInt32(); result.Unknown3 = br.ReadInt32(); result.Unknown4 = br.ReadInt32(); result.Unknown5 = br.ReadInt32(); result.Unknown6 = br.ReadInt32(); if (ParsingRule >= 62) result.ActivateChance = br.ReadInt32(); if (ParsingRule >= 63) result.RareOrSpecial = br.ReadBoolean(); return result; }
protected void ReadCharacterInfo(NoxBinaryReader rdr) { long finish = rdr.ReadInt64() + rdr.BaseStream.Position; rdr.ReadBytes(6); //UNKNOWN header seems to always = 0c 00 02 00 00 00 SavePath = rdr.ReadString(System.Type.GetType("System.Int16")); rdr.ReadByte(); //terminating null not included in length //the time this file was written FileTime = new DateTime( rdr.ReadInt16(), //year rdr.ReadInt32() & 0xFFFF, //month --skip the next 16bytes //rdr.ReadInt16(),//day of the week (not needed) rdr.ReadInt16(), //day rdr.ReadInt16(), //hour rdr.ReadInt16(), //minute rdr.ReadInt16(), //seconds rdr.ReadInt16() //milliseconds ); //these colors are RGB HairColor = rdr.ReadColor(); SkinColor = rdr.ReadColor(); MustacheColor = rdr.ReadColor(); BeardColor = rdr.ReadColor(); SideburnsColor = rdr.ReadColor(); PantsColor = rdr.ReadUserColor(); ShirtColor = rdr.ReadUserColor(); ShirtTrimColor = rdr.ReadUserColor(); ShoesColor = rdr.ReadUserColor(); ShoesTrimColor = rdr.ReadUserColor(); Name = rdr.ReadUnicodeString(); Class = (CharacterClass)rdr.ReadByte(); rdr.ReadBytes(2); //UNKNOWN: always 00 0A? LastMapPlayed = rdr.ReadString(); rdr.ReadByte(); //null terminator not included in string length System.Diagnostics.Debug.Assert(rdr.BaseStream.Position == finish, "Bad CharacterInfo length"); }
static NoxDb() { RegistryKey installPathKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Westwood\\Nox"); if (installPathKey == null) { MessageBox.Show("Could not find Nox's install path in the registry. Reinstall Nox to fix this.", "Error"); return; } noxPath = (string) installPathKey.GetValue("InstallPath"); noxPath = noxPath.Substring(0, noxPath.LastIndexOf("\\")+1); string filePath = noxPath + "thing.bin"; NoxBinaryReader rdr = null; try { rdr = new NoxBinaryReader(File.OpenRead(filePath), CryptApi.NoxCryptFormat.THING); } catch (FileNotFoundException) { MessageBox.Show(String.Format("Could not access database '{0}' in the Nox game directory.", dbFile), "Error"); return; } }
public static NPCXfer FromStream(Stream mstream, ThingDb.Thing tt, short ParsingRule) { NPCXfer result = new NPCXfer(); NoxBinaryReader br = new NoxBinaryReader(mstream); result.Direction = (MonsterXfer.DirectionEncoded) br.ReadUInt64(); result.ScriptEvents = new string[10]; // Читаем имена обработчиков скриптовых событий for (int i = 0; i < 10; i++) { if (i == 2) result.DetectEventTimeout = br.ReadUInt16(); result.ScriptEvents[i] = br.ReadScriptEventString(); } // Пропуск (0) br.ReadInt32(); // цвета result.NPCColors = new Color[6]; byte R, G, B; for (int i = 0; i < 6; i++) { R = br.ReadByte(); G = br.ReadByte(); B = br.ReadByte(); result.NPCColors[i] = Color.FromArgb(R, G, B); } // основной блок инфы if (ParsingRule >= 32) { result.ActionRoamPathFlag = br.ReadByte(); if (ParsingRule < 49) result.StatusFlags = (NoxEnums.MonsterStatus) br.ReadUInt16(); else result.StatusFlags = (NoxEnums.MonsterStatus) br.ReadUInt32(); result.HealthMultiplier = br.ReadSingle(); result.RetreatRatio = br.ReadSingle(); result.ResumeRatio = br.ReadSingle(); result.SightRange = br.ReadSingle(); result.Health = br.ReadInt16(); result.Aggressiveness = br.ReadSingle(); if (ParsingRule < 35) result.DefaultAction = br.ReadInt32(); result.EscortObjName = br.ReadString(); if (ParsingRule >= 34) { int spells = br.ReadInt32(); result.KnownSpells = new List<MonsterXfer.SpellEntry>(); string spellName = null; uint spellFlags = 0; for (int i = 0; i < spells; i++) { spellName = br.ReadString(); spellFlags = br.ReadUInt32(); if (ThingDb.thingdb.Spells.Keys.Contains(spellName)) result.KnownSpells.Add(new MonsterXfer.SpellEntry(spellName, spellFlags)); } } else br.BaseStream.Seek(0x224, SeekOrigin.Current); // Задержки между заклинаниями if (ParsingRule < 47) { result.ReactionCastingDelayMin = (ushort) br.ReadByte(); result.ReactionCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.BuffCastingDelayMin = (ushort) br.ReadByte(); result.BuffCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.DebuffCastingDelayMin = (ushort) br.ReadByte(); result.DebuffCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.OffensiveCastingDelayMin = (ushort) br.ReadByte(); result.OffensiveCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.BlinkCastingDelayMin = (ushort) br.ReadByte(); result.BlinkCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); } else { result.ReactionCastingDelayMin = br.ReadUInt16(); result.ReactionCastingDelayMax = br.ReadUInt16(); result.BuffCastingDelayMin = br.ReadUInt16(); result.BuffCastingDelayMax = br.ReadUInt16(); result.DebuffCastingDelayMin = br.ReadUInt16(); result.DebuffCastingDelayMax = br.ReadUInt16(); result.OffensiveCastingDelayMin = br.ReadUInt16(); result.OffensiveCastingDelayMax = br.ReadUInt16(); result.BlinkCastingDelayMin = br.ReadUInt16(); result.BlinkCastingDelayMax = br.ReadUInt16(); } if (ParsingRule < 34) result.MagicNumber = br.ReadUInt32(); if (ParsingRule >= 33) result.LockPathDistance = br.ReadSingle(); if (ParsingRule >= 34) { result.SpellPowerLevel = br.ReadInt32(); result.NPCStrength = br.ReadByte(); result.NPCSpeed = br.ReadSingle(); result.AimSkillLevel = br.ReadSingle(); if (ParsingRule < 42) { if (br.ReadInt16() == 0) result.Immortal = true; } result.TrapSpell1 = br.ReadString(); result.TrapSpell2 = br.ReadString(); result.TrapSpell3 = br.ReadString(); } if (ParsingRule >= 35) { string action = br.ReadString(); result.DefaultAction = Array.IndexOf(NoxEnums.AIActionStrings, action); } if (ParsingRule >= 41) { // здесь придётся читать просто огромное кол-во инфы // однако она используется очень редко, обычно entryType = 4; forced = 0 short entryType = br.ReadInt16(); if (entryType <= 4) { byte forced = 1; if (entryType >= 2) forced = br.ReadByte(); if (forced == 1 || entryType < 2) { return result; // TODO для ПОЛНОЙ совместимости, придётся } } } if (ParsingRule >= 42) result.Immortal = br.ReadBoolean(); if (ParsingRule >= 44) result.MagicNumber = br.ReadUInt32(); if (ParsingRule >= 45) result.MaxHealth = (short) br.ReadInt32(); if (ParsingRule >= 46) result.AddedSubclass = br.ReadUInt32(); if (ParsingRule >= 48) result.Health = br.ReadInt16(); if (ParsingRule >= 51) result.Experience = br.ReadSingle(); if (ParsingRule >= 52) result.NPCVoiceSet = br.ReadString(); if (ParsingRule < 61) return result; // энчанты short buffsType = br.ReadInt16(); if (buffsType > 2 || buffsType <= 0) return result; byte count = br.ReadByte(); result.BuffList = new MonsterXfer.BuffEntry[count]; while (count > 0) { MonsterXfer.BuffEntry be = new MonsterXfer.BuffEntry(); be.Name = br.ReadString(); be.Power = br.ReadByte(); be.Duration = br.ReadInt32(); if (be.Name == ENCHANT_SHIELD && buffsType >= 2) be.ShieldHealth = br.ReadInt32(); result.BuffList[count] = be; count--; } Array.Reverse(result.BuffList); if (ParsingRule >= 62) result.PoisonLevel = br.ReadByte(); } return result; }
protected void ReadSPHeader(NoxBinaryReader rdr) { //long finish = rdr.ReadInt64() + rdr.BaseStream.Position; //TODO: skip for now rdr.ReadBytes((int) rdr.ReadInt64()); }
protected void ReadCharacterInfo(NoxBinaryReader rdr) { long finish = rdr.ReadInt64() + rdr.BaseStream.Position; rdr.ReadBytes(6);//UNKNOWN header seems to always = 0c 00 02 00 00 00 SavePath = rdr.ReadString(System.Type.GetType("System.Int16")); rdr.ReadByte();//terminating null not included in length //the time this file was written FileTime = new DateTime( rdr.ReadInt16(),//year rdr.ReadInt32() & 0xFFFF,//month --skip the next 16bytes //rdr.ReadInt16(),//day of the week (not needed) rdr.ReadInt16(),//day rdr.ReadInt16(),//hour rdr.ReadInt16(),//minute rdr.ReadInt16(),//seconds rdr.ReadInt16()//milliseconds ); //these colors are RGB HairColor = rdr.ReadColor(); SkinColor = rdr.ReadColor(); MustacheColor = rdr.ReadColor(); BeardColor = rdr.ReadColor(); SideburnsColor = rdr.ReadColor(); PantsColor = rdr.ReadUserColor(); ShirtColor = rdr.ReadUserColor(); ShirtTrimColor = rdr.ReadUserColor(); ShoesColor = rdr.ReadUserColor(); ShoesTrimColor = rdr.ReadUserColor(); Name = rdr.ReadUnicodeString(); Class = (CharacterClass) rdr.ReadByte(); rdr.ReadBytes(2);//UNKNOWN: always 00 0A? LastMapPlayed = rdr.ReadString(); rdr.ReadByte();//null terminator not included in string length System.Diagnostics.Debug.Assert(rdr.BaseStream.Position == finish, "Bad CharacterInfo length"); }
private ThingToken NextToken(NoxBinaryReader rdr) { ThingToken result = (ThingToken) 0xFFFFFFFF; if (rdr.BaseStream.Position < rdr.BaseStream.Length) { result = (ThingToken) rdr.ReadUInt32(); rdr.BaseStream.Seek(-4, SeekOrigin.Current); } return result; }
public static ThingDb thingdb; //stupid hack public ThingDb() { thingdb = this; dbFile = "thing.bin"; NoxBinaryReader rdr = new NoxBinaryReader(GetStream(), CryptApi.NoxCryptFormat.THING); int floorId = 0, edgeId = 0, wallId = 0; for (ThingToken token = NextToken(rdr); Enum.IsDefined(typeof(ThingToken), token); token = NextToken(rdr)) { if (token == ThingToken.FLOR) { Tile tile = new Tile(rdr.BaseStream); tile.Id = floorId++; FloorTiles.Add(tile); } else if (token == ThingToken.EDGE) { Tile tile = new Tile(rdr.BaseStream); tile.Id = edgeId++; EdgeTiles.Add(tile); } else if (token == ThingToken.WALL) { Wall wall = new Wall(rdr.BaseStream); wall.Id = wallId++; Walls.Add(wall); } else if (token == ThingToken.AUD) ReadEntries(rdr); else if (token == ThingToken.AVNT) { Avnt avnt = new Avnt(rdr.BaseStream); Avnts.Add(avnt.Name, avnt); } else if (token == ThingToken.SPEL) ReadEntries(rdr); else if (token == ThingToken.ABIL) ReadEntries(rdr); else if (token == ThingToken.IMAG) ReadEntries(rdr); else if (token == ThingToken.THNG) { Thing thing = new Thing(rdr.BaseStream); if (!Things.ContainsKey(thing.Name))//there are a few duplicates, but they seem to be identical Things.Add(thing.Name, thing); } else Debug.Fail("Encountered unkown token while reading thing.bin"); } Debug.Assert(rdr.BaseStream.Length - rdr.BaseStream.Position < 8, "Error reading thing.bin", "Could not parse entire file"); }
public static MonsterXfer FromStream(Stream mstream, ThingDb.Thing tt, short ParsingRule) { MonsterXfer result = new MonsterXfer(); NoxBinaryReader br = new NoxBinaryReader(mstream); result.Direction = (DirectionEncoded) br.ReadUInt64(); result.ScriptEvents = new string[10]; // Читаем имена обработчиков скриптовых событий for (int i = 0; i < 10; i++) { if (i == 2) result.DetectEventTimeout = br.ReadUInt16(); result.ScriptEvents[i] = br.ReadScriptEventString(); } // Пропуск (0) if (ParsingRule >= 11) br.ReadInt32(); if (ParsingRule >= 31) { result.ActionRoamPathFlag = br.ReadByte(); if (ParsingRule < 51) result.StatusFlags = (NoxEnums.MonsterStatus) br.ReadUInt16(); else result.StatusFlags = (NoxEnums.MonsterStatus) br.ReadUInt32(); result.HealthMultiplier = br.ReadSingle(); result.RetreatRatio = br.ReadSingle(); result.ResumeRatio = br.ReadSingle(); result.SightRange = br.ReadSingle(); if (ParsingRule < 33) br.BaseStream.Seek(2, SeekOrigin.Current); result.Aggressiveness = br.ReadSingle(); if (ParsingRule < 34) result.DefaultAction = br.ReadInt32(); result.EscortObjName = br.ReadString(); if (ParsingRule >= 34) { int spells = br.ReadInt32(); result.KnownSpells = new List<SpellEntry>(); string spellName = null; uint spellFlags = 0; for (int i = 0; i < spells; i++) { spellName = br.ReadString(); spellFlags = br.ReadUInt32(); if (ThingDb.thingdb.Spells.Keys.Contains(spellName)) result.KnownSpells.Add(new SpellEntry(spellName, spellFlags)); } } else br.BaseStream.Seek(0x224, SeekOrigin.Current); // Задержки между заклинаниями if (ParsingRule < 46) { result.ReactionCastingDelayMin = (ushort) br.ReadByte(); result.ReactionCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.BuffCastingDelayMin = (ushort) br.ReadByte(); result.BuffCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.DebuffCastingDelayMin = (ushort) br.ReadByte(); result.DebuffCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.OffensiveCastingDelayMin = (ushort) br.ReadByte(); result.OffensiveCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); result.BlinkCastingDelayMin = (ushort) br.ReadByte(); result.BlinkCastingDelayMax = (ushort) br.ReadByte(); if (ParsingRule <= 32) br.ReadInt32(); } else { result.ReactionCastingDelayMin = br.ReadUInt16(); result.ReactionCastingDelayMax = br.ReadUInt16(); result.BuffCastingDelayMin = br.ReadUInt16(); result.BuffCastingDelayMax = br.ReadUInt16(); result.DebuffCastingDelayMin = br.ReadUInt16(); result.DebuffCastingDelayMax = br.ReadUInt16(); result.OffensiveCastingDelayMin = br.ReadUInt16(); result.OffensiveCastingDelayMax = br.ReadUInt16(); result.BlinkCastingDelayMin = br.ReadUInt16(); result.BlinkCastingDelayMax = br.ReadUInt16(); } if (ParsingRule > 32) result.LockPathDistance = br.ReadSingle(); if (ParsingRule >= 33) { result.SpellPowerLevel = br.ReadInt32(); result.AimSkillLevel = br.ReadSingle(); if (ParsingRule < 42) { if (br.ReadInt16() == 0) result.Immortal = true; } if (ParsingRule < 53) { int spellIndex = br.ReadInt32(); result.TrapSpell1 = ThingDb.thingdb.Spells.Values[spellIndex].Name; spellIndex = br.ReadInt32(); result.TrapSpell2 = ThingDb.thingdb.Spells.Values[spellIndex].Name; spellIndex = br.ReadInt32(); result.TrapSpell3 = ThingDb.thingdb.Spells.Values[spellIndex].Name; } else { result.TrapSpell1 = br.ReadString(); result.TrapSpell2 = br.ReadString(); result.TrapSpell3 = br.ReadString(); } } if (ParsingRule >= 34) { string action = br.ReadString(); result.DefaultAction = Array.IndexOf(NoxEnums.AIActionStrings, action); } if (ParsingRule >= 41) { // здесь придётся читать просто огромное кол-во инфы // однако она используется очень редко, обычно entryType = 4; forced = 0 short entryType = br.ReadInt16(); if (entryType <= 4) { byte forced = 1; if (entryType >= 2) forced = br.ReadByte(); if (forced == 1 || entryType < 2) { return result; // TODO для ПОЛНОЙ совместимости, придётся } } } if (ParsingRule >= 42) { result.Immortal = br.ReadBoolean(); } if (ParsingRule >= 43 && tt.Subclass[(int) ThingDb.Thing.SubclassBitIndex.SHOPKEEPER]) { // Информация о содержании магазина ShopkeeperInfoStruct si = new ShopkeeperInfoStruct(); if (ParsingRule >= 50) si.BuyValueMultiplier = br.ReadSingle(); if (ParsingRule >= 61) si.SellValueMultiplier = br.ReadSingle(); if (ParsingRule >= 48) si.ShopkeeperGreetingText = br.ReadString(); byte items = br.ReadByte(); si.ShopItems = new ShopItemInfo[items]; for (int i = 0; i < items; i++) { ShopItemInfo item = new ShopItemInfo(); if (ParsingRule < 50) br.ReadInt32(); item.Count = br.ReadByte(); item.Name = br.ReadString(); if (ParsingRule >= 47) { item.SpellID = br.ReadString(); item.Ench1 = br.ReadString(); item.Ench2 = br.ReadString(); item.Ench3 = br.ReadString(); item.Ench4 = br.ReadString(); } si.ShopItems[i] = item; } result.ShopkeeperInfo = si; } if (ParsingRule >= 44) result.MagicNumber = br.ReadUInt32(); if (ParsingRule >= 45) result.AddedSubclass = br.ReadUInt32(); if (ParsingRule >= 49) result.Health = br.ReadInt16(); if (ParsingRule >= 51) { result.SetDefaultResumeRatio = br.ReadBoolean(); result.SetDefaultRetreatRatio = br.ReadBoolean(); result.SetDefaultMonsterStatus = br.ReadBoolean(); result.LearnDefaultSpells = br.ReadBoolean(); } if (ParsingRule >= 54 && tt.Subclass[(int) ThingDb.Thing.SubclassBitIndex.FEMALE_NPC]) { result.MaidenBodyColors = new Color[6]; byte R, G, B; for (int i = 0; i < 6; i++) { R = br.ReadByte(); G = br.ReadByte(); B = br.ReadByte(); result.MaidenBodyColors[i] = Color.FromArgb(R, G, B); } if (ParsingRule >= 55) result.MaidenVoiceSet = br.ReadString(); } if (ParsingRule >= 62) { short entryType = br.ReadInt16(); if (entryType > 2 || entryType <= 0) return result; byte count = br.ReadByte(); result.BuffList = new BuffEntry[count]; while (count > 0) { BuffEntry be = new BuffEntry(); be.Name = br.ReadString(); be.Power = br.ReadByte(); be.Duration = br.ReadInt32(); if (be.Name == ENCHANT_SHIELD && entryType >= 2) be.ShieldHealth = br.ReadInt32(); result.BuffList[count] = be; count--; } Array.Reverse(result.BuffList); } if (ParsingRule >= 63 && tt.Subclass[(int) ThingDb.Thing.SubclassBitIndex.WOUNDED_NPC]) result.WoundedNPCVoiceSet = br.ReadString(); if (ParsingRule >= 64) result.PoisonLevel = br.ReadByte(); } return result; }
void LoadNewMap() { // System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow)); // Stream strm = resources.GetStream("BlankMap.map"); Stream strm; Assembly asm = Assembly.GetExecutingAssembly(); string fullName = null; foreach (string str in asm.GetManifestResourceNames()) { if (str.EndsWith("BlankMap.map")) { fullName = str; break; } } if (fullName == null) throw new Exception("Can not find " + "Blank Map" + " resource in container file"); strm = asm.GetManifestResourceStream(fullName); if( strm == null ) throw new Exception("Could not load " + "Blank Map"); // MessageBox.Show("it worked"); NoxBinaryReader rdr = new NoxBinaryReader(strm, CryptApi.NoxCryptFormat.MAP); map.FileName = ""; myMap.ClearMap(); //TODO: check for changes and prompt to save before opening another map map = new Map(rdr); //questTitle.DataBindings.Clear(); //questTitle.DataBindings.Add(new Binding("Text", map.Info, "QIntroTitle")); mapView.Map = map; mapView.SelectedObject = null; mapType.SelectedIndex = Map.MapInfo.MapTypeNames.IndexOfKey(map.Info.Type); mapSummary.Text = map.Info.Summary; mapDescription.Text = map.Info.Description; mapAuthor.Text = map.Info.Author; mapEmail.Text = map.Info.Email; mapAuthor2.Text = map.Info.Author2; mapEmail2.Text = map.Info.Email2; mapVersion.Text = map.Info.Version; mapCopyright.Text = map.Info.Copyright; mapDate.Text = map.Info.Date; mapMinRec.Text = String.Format("{0}", map.Info.RecommendedMin); mapMaxRec.Text = String.Format("{0}", map.Info.RecommendedMax); questTitle.Text = map.Info.QIntroTitle; questGraphic.Text = map.Info.QIntroGraphic; foreach (Map.Tile tile in map.Tiles.Values) { unsafe { IntPtr ptr = Marshal.StringToHGlobalAnsi(tile.Graphic); myMap.AddTile(ptr.ToPointer(), tile.Location.Y, tile.Location.X, (int)tile.Variation); } } foreach (Map.Object obj in map.Objects) { unsafe { obj.UniqueID = mapView.IdCount++; IntPtr ptr = Marshal.StringToHGlobalAnsi(obj.Name); int val = obj.UniqueID; myMap.AddObject(ptr.ToPointer(), (int)obj.Location.X, (int)obj.Location.Y, val); } } myMap.SetXY(1, 1); Invalidate(true); //map = new Map(fd.FileName); }
private static ThingToken NextToken(NoxBinaryReader rdr) { try { if (rdr.BaseStream.Position < rdr.BaseStream.Length) { char[] tokenChars = rdr.ReadChars(4); Array.Reverse(tokenChars); string token = new string(tokenChars); rdr.BaseStream.Seek(-4, SeekOrigin.Current); return (ThingToken) Enum.Parse(typeof(ThingToken), token); } } catch (ArgumentException) {} return (ThingToken) 0xFFFFFFFF; }
protected void ReadSPHeader(NoxBinaryReader rdr) { //long finish = rdr.ReadInt64() + rdr.BaseStream.Position; //TODO: skip for now rdr.ReadBytes((int)rdr.ReadInt64()); }