public static PartyMemberId FromDisk(int disk, AssetMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } var(enumType, enumValue) = mapping.IdToEnum(new PartyMemberId(AssetType.Party, disk)); return((PartyMemberId)AssetMapping.Global.EnumToId(enumType, enumValue)); }
public SpellData Serdes(SpellData existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } return(SpellData.Serdes(config.AssetId, existing, s)); }
public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } return(WaveLib.Serdes(null, s)); }
public SpellData Serdes(SpellData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } return(SpellData.Serdes(existing, info, s)); }
public WaveLib Serdes(WaveLib existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } return(WaveLib.Serdes(existing, s)); }
public static WaveLibraryId SerdesU8(string name, WaveLibraryId id, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } byte diskValue = (byte)id.ToDisk(mapping); diskValue = s.UInt8(name, diskValue); return(FromDisk(diskValue, mapping)); }
public static WordId SerdesU16BE(string name, WordId id, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } ushort diskValue = (ushort)id.ToDisk(mapping); diskValue = s.UInt16BE(name, diskValue); return(FromDisk(diskValue, mapping)); }
public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } return(new AlbionSample(s.ByteArray(null, null, (int)s.BytesRemaining))); }
public AlbionPalette Serdes(AlbionPalette existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } return(AlbionPalette.Serdes(existing, info, s)); }
public AlbionSample Serdes(AlbionSample existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } return(s.IsWriting() ? Write(existing, s) : Read(s)); }
static void MergeTypesToMapping(AssetMapping mapping, AssetConfig config, string assetConfigPath) { foreach (var assetType in config.Types) { var enumType = Type.GetType(assetType.Key); if (enumType == null) { throw new InvalidOperationException($"Could not load enum type \"{assetType.Key}\" defined in \"{assetConfigPath}\""); } mapping.RegisterAssetType(assetType.Key, assetType.Value.AssetType); } }
public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } s.Seek(WordLength * config.SubAssetId); return(s.FixedLengthString(null, null, WordLength)); }
public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var bytes = s.ByteArray(null, null, (int)s.BytesRemaining); var text = Encoding.UTF8.GetString(bytes); return (JsonConvert.DeserializeObject <IDictionary <Base.UAlbionString, string> >(text) .ToDictionary(x => TextId.From(x.Key), x => x.Value)); }
public BlockList Serdes(BlockList existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) throw new ArgumentNullException(nameof(info)); if (s == null) throw new ArgumentNullException(nameof(s)); if (jsonUtil == null) throw new ArgumentNullException(nameof(jsonUtil)); if (s.IsWriting()) { if (existing == null) throw new ArgumentNullException(nameof(existing)); var blockListId = (BlockListId)info.AssetId; var tilesetId = blockListId.ToTileset(); var tilesetPattern = info.Get(AssetProperty.TilesetPattern, "../Tilesets/{0}_{2}.tsx"); var tilesetPath = string.Format(CultureInfo.InvariantCulture, tilesetPattern, tilesetId.Id, 0, ConfigUtil.AssetName(tilesetId)); var tileset = new Tileset { Filename = tilesetPath, TileWidth = 16, TileHeight = 16, }; PackedChunks.Pack(s, existing.Count, stampNumber => { if (existing[stampNumber].Width == 0 || existing[stampNumber].Height == 0) return Array.Empty<byte>(); var stamp = new Stamp(stampNumber, existing[stampNumber], tileset); return Encoding.UTF8.GetBytes(stamp.Serialize(jsonUtil)); }); return existing; } var list = new BlockList(); foreach (var (jsonBytes, _) in PackedChunks.Unpack(s)) { var stamp = Stamp.Parse(jsonBytes, jsonUtil); var block = stamp != null ? stamp.ToBlock() : new Block(); list.Add(block); } while (list.Count < BlockList.MaxCount) list.Add(new Block()); return list; }
public static DoorEvent Serdes(DoorEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new DoorEvent(textSourceId); e.PickDifficulty = s.UInt8(nameof(PickDifficulty), e.PickDifficulty); e.Key = ItemId.SerdesU16(nameof(Key), e.Key, AssetType.Item, mapping, s); e.OpenedText = s.UInt8(nameof(OpenedText), e.OpenedText); e.UnlockedText = s.UInt8(nameof(UnlockedText), e.UnlockedText); e.DoorId = DoorId.SerdesU16(nameof(DoorId), e.DoorId, mapping, s); // Usually 100+ return(e); }
public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (jsonUtil == null) { throw new ArgumentNullException(nameof(jsonUtil)); } var bytes = s.Bytes(null, null, (int)s.BytesRemaining); return(jsonUtil.Deserialize <IntStringDictionary>(bytes)); }
public static ChestEvent Serdes(ChestEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new ChestEvent(textSourceId); e.PickDifficulty = s.UInt8(nameof(PickDifficulty), e.PickDifficulty); e.KeyItemId = ItemId.SerdesU16(nameof(KeyItemId), e.KeyItemId, AssetType.Item, mapping, s); e.UnlockedTextId = s.UInt8(nameof(UnlockedTextId), e.UnlockedTextId); e.InitialTextId = s.UInt8(nameof(InitialTextId), e.InitialTextId); e.ChestId = ChestId.SerdesU16(nameof(ChestId), e.ChestId, mapping, s); return(e); }
public static VisitedEventList Serdes(int _, VisitedEventList c, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } c ??= new VisitedEventList(); c.Size = s.UInt32(nameof(Size), c.Size); c.NumChunks = s.UInt16(nameof(NumChunks), c.NumChunks); ApiUtil.Assert(c.NumChunks == c.Size / VisitedEvent.SizeOnDisk); c.Contents ??= new VisitedEvent[(c.Size - 2) / VisitedEvent.SizeOnDisk]; s.List(nameof(c.Contents), c.Contents, mapping, c.Contents.Length, VisitedEvent.Serdes); return(c); }
public static MapChange Serdes(int i, MapChange u, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } u ??= new MapChange(); u.X = s.UInt8(nameof(X), u.X); u.Y = s.UInt8(nameof(Y), u.Y); u.ChangeType = s.EnumU8(nameof(ChangeType), u.ChangeType); u.Unk3 = s.EnumU8(nameof(Unk3), u.Unk3); u.Value = s.UInt16(nameof(Value), u.Value); u.MapId = MapId.SerdesU16(nameof(Overlay), u.MapId, mapping, s); return(u); }
public static TextId FromDisk(AssetType type, int disk, AssetMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (!(type == AssetType.None || type >= AssetType.EventText && type <= AssetType.Word || type == AssetType.Special)) { throw new ArgumentOutOfRangeException($"Tried to construct a TextId with a type of {type}"); } var(enumType, enumValue) = mapping.IdToEnum(new TextId(type, disk)); return((TextId)AssetMapping.Global.EnumToId(enumType, enumValue)); }
public static SetPartyLeaderEvent Serdes(SetPartyLeaderEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new SetPartyLeaderEvent(); e.Unk2 = s.UInt8(nameof(Unk2), e.Unk2); e.Unk3 = s.UInt8(nameof(Unk3), e.Unk3); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); e.PartyMemberId = PartyMemberId.SerdesU16(nameof(PartyMemberId), e.PartyMemberId, mapping, s); e.Unk8 = s.UInt16(nameof(Unk8), e.Unk8); return(e); }
public static CharacterId FromDisk(AssetType type, int disk, AssetMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (!(type == AssetType.None || type >= AssetType.Monster && type <= AssetType.Party)) { throw new ArgumentOutOfRangeException($"Tried to construct a CharacterId with a type of {type}"); } var(enumType, enumValue) = mapping.IdToEnum(new CharacterId(type, disk)); return((CharacterId)AssetMapping.Global.EnumToId(enumType, enumValue)); }
static void BuildEventHash(MapId mapId, IScriptable scriptable, AssetMapping mapping) { if (scriptable.Events == null) { return; } scriptable.EventBytes = FormatUtil.SerializeToBytes(s => { for (ushort i = 0; i < scriptable.Events.Count; i++) { scriptable.Events[i] = EventNode.Serdes(i, scriptable.Events[i], s, mapId, mapId.ToMapText(), mapping); } }); }
public static SimpleChestEvent Serdes(SimpleChestEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new SimpleChestEvent(); e.ChestType = s.EnumU8(nameof(ChestType), e.ChestType); uint padding = s.UInt32(nameof(padding), 0); ApiUtil.Assert(padding == 0); e.ItemId = ItemId.SerdesU16(nameof(e.ItemId), e.ItemId, AssetType.Item, mapping, s); e.Amount = s.UInt16(nameof(Amount), e.Amount); return(e); }
public static SpriteId FromDisk(AssetType type, int disk, AssetMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (!(type >= AssetType.None && type <= AssetType.WallOverlay)) { throw new ArgumentOutOfRangeException($"Tried to construct a SpriteId with a type of {type}"); } var(enumType, enumValue) = mapping.IdToEnum(new SpriteId(type, disk)); return((SpriteId)AssetMapping.Global.EnumToId(enumType, enumValue)); }
public static PlayAnimationEvent Serdes(PlayAnimationEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new PlayAnimationEvent(); e.VideoId = VideoId.SerdesU8(nameof(VideoId), e.VideoId, mapping, s); e.X = s.UInt8(nameof(X), e.X); e.Y = s.UInt8(nameof(Y), e.Y); e.Unk4 = s.UInt8(nameof(Unk4), e.Unk4); e.Unk5 = s.UInt8(nameof(Unk5), e.Unk5); e.Unk6 = s.UInt16(nameof(Unk6), e.Unk6); e.Unk8 = s.UInt16(nameof(Unk8), e.Unk8); return(e); }
public static EventExchange Setup( AssetMapping mapping, IFileSystem disk, IJsonUtil jsonUtil, GeneralConfig generalConfig, GeneralSettings settings, CoreConfig coreConfig, GameConfig gameConfig) { var configAndSettingsTask = Task.FromResult((generalConfig, settings)); var coreConfigTask = Task.FromResult(coreConfig); var gameConfigTask = Task.FromResult(gameConfig); var task = SetupCore(mapping, disk, jsonUtil, configAndSettingsTask, coreConfigTask, gameConfigTask); return(task.Result.Item1); }
public AssetConverter(AssetMapping mapping, IFileSystem disk, IJsonUtil jsonUtil, string[] fromMods, string toMod) { if (disk == null) { throw new ArgumentNullException(nameof(disk)); } if (jsonUtil == null) { throw new ArgumentNullException(nameof(jsonUtil)); } var baseDir = ConfigUtil.FindBasePath(disk); (_from, _fromExchange, _fromLoaderRegistry) = BuildModApplier(baseDir, fromMods, disk, jsonUtil, mapping); (_to, _toExchange, _toLoaderRegistry) = BuildModApplier(baseDir, new[] { toMod }, disk, jsonUtil, mapping); }
public static Overlay Serdes(int _, Overlay o, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } o ??= new Overlay(); o.SpriteId = SpriteId.SerdesU16(nameof(o.SpriteId), o.SpriteId, AssetType.WallOverlay, mapping, s); o.AnimationFrames = s.UInt8(nameof(o.AnimationFrames), o.AnimationFrames); o.WriteZero = s.UInt8(nameof(o.WriteZero), o.WriteZero); o.XOffset = s.UInt16(nameof(o.XOffset), o.XOffset); o.YOffset = s.UInt16(nameof(o.YOffset), o.YOffset); o.Width = s.UInt16(nameof(o.Width), o.Width); o.Height = s.UInt16(nameof(o.Height), o.Height); return(o); }
public static ChangeFoodEvent Serdes(ChangeFoodEvent e, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } e ??= new ChangeFoodEvent(); e.Operation = s.EnumU8(nameof(Operation), e.Operation); e.Unk3 = s.UInt8(nameof(Unk3), e.Unk3); int zeroed = s.UInt8(null, 0); s.Assert(zeroed == 0, "ChangeFoodEvent: Expected byte 4 to be 0"); e.PartyMemberId = PartyMemberId.SerdesU8(nameof(PartyMemberId), e.PartyMemberId, mapping, s); zeroed = s.UInt16(null, 0); s.Assert(zeroed == 0, "ChangeFoodEvent: Expected word 6 to be 0"); // TODO: Can be 1 e.Amount = s.UInt16(nameof(Amount), e.Amount); return(e); }