static StructRegistry() { addStruct("Vector", binaryConstructorFunction <StructVector>(), jsonConstructorFunction <StructVector>()); addStruct("Vector2D", binaryConstructorFunction <StructVector2D>(), jsonConstructorFunction <StructVector2D>()); addStruct("Quat", binaryConstructorFunction <StructQuat>(), jsonConstructorFunction <StructQuat>()); addStruct("Color", binaryConstructorFunction <StructColor>(), jsonConstructorFunction <StructColor>()); addStruct("LinearColor", binaryConstructorFunction <StructLinearColor>(), jsonConstructorFunction <StructLinearColor>()); addStruct("Rotator", binaryConstructorFunction <StructVector>(), jsonConstructorFunction <StructVector>()); addStruct("UniqueNetIdRepl", binaryConstructorFunction <StructUniqueNetIdRepl>(), jsonConstructorFunction <StructUniqueNetIdRepl>()); nameTypeMap.Add(ArkName.ConstantPlain("CustomColors"), ArkName.ConstantPlain("Color")); nameTypeMap.Add(ArkName.ConstantPlain("CustomColours_60_7D3267C846B277953C0C41AEBD54FBCB"), ArkName.ConstantPlain("LinearColor")); }
public StructPropertyList(ArkArchive archive, ArkName structType, ArkNameTree exclusivePropertyNameTree = null) : this(structType) { Properties = new Dictionary <ArkName, IProperty>(); var property = PropertyRegistry.readProperty(archive, exclusivePropertyNameTree); while (property != null) { if (property != ExcludedProperty.Instance) { Properties.Add(ArkName.Create(property.Name.Token, property.Index), property); } property = PropertyRegistry.readProperty(archive, exclusivePropertyNameTree); } }
public DroppedItem(GameObject droppedItem, GameObjectContainer container) { className = droppedItem.ClassName; CreatureData structureData = ArkDataManager.GetStructure(droppedItem.ClassString); type = structureData != null ? structureData.Name : droppedItem.ClassString; location = droppedItem.Location; myItem = droppedItem.GetPropertyValue <ObjectReference, GameObject>("MyItem", map: reference => container[reference]); droppedByName = droppedItem.GetPropertyValue <string>("DroppedByName", defaultValue: string.Empty); targetingTeam = droppedItem.GetPropertyValue <int>("TargetingTeam"); originalCreationTime = droppedItem.GetPropertyValue <double>("OriginalCreationTime"); initialLifeSpan = droppedItem.GetPropertyValue <float>("InitialLifeSpan", defaultValue: float.PositiveInfinity); }
public ArkName[] GetNames(long position) { var count = GetInt(position); var names = new ArkName[count]; var oldposition = _position; _position = position + 4; for (var i = 0; i < count; i++) { names[i] = GetName(); } _position = oldposition; return(names); }
public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName) { (GameObjectContainer gameObjectContainer, float gameTime) = await Task.Run(() => ReadSavegameFile(filename)); var ignoreClasses = Values.V.IgnoreSpeciesClassesOnImport; IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer .Where(o => o.IsCreature() && o.IsTamed() && !o.IsUnclaimedBaby() && !ignoreClasses.Contains(o.ClassString)); if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter)) { string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',') .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) .ToArray(); if (filters.Any()) { tamedCreatureObjects = tamedCreatureObjects.Where(o => { string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty); return(filters.Any(filter => tribeName.Contains(filter))); }); } } ImportSavegame importSavegame = new ImportSavegame(gameTime); int? wildLevelStep = creatureCollection.getWildLevelStep(); var creatures = tamedCreatureObjects.Select(o => importSavegame.ConvertGameObject(o, wildLevelStep)).Where(c => c != null).ToArray(); ArkName.ClearCache(); // if there are creatures with unknown species, check if the according mod-file is available var unknownSpeciesCreatures = creatures.Where(c => c.Species == null).ToArray(); if (!unknownSpeciesCreatures.Any() || Properties.Settings.Default.IgnoreUnknownBlueprintsOnSaveImport || MessageBox.Show("The species of " + unknownSpeciesCreatures.Length + " creature" + (unknownSpeciesCreatures.Length != 1 ? "s" : "") + " is not recognized, probably because they are from a mod that is not loaded.\n" + "The unrecognized species-classes are as follows, all the according creatures cannot be imported:\n\n" + string.Join("\n", unknownSpeciesCreatures.Select(c => c.name).Distinct().ToArray()) + "\n\nTo import the unrecognized creatures, you first need mod values-files, see Settings - Mod value manager… if the mod value is available\n\n" + "Do you want to import the recognized creatures? If you click no, nothing is imported.", "Unrecognized species while importing savegame", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes ) { ImportCollection(creatureCollection, creatures.Where(c => c.Species != null).ToList(), serverName); } }
public ObjectCollector(GameObjectContainer container, ArkName className, bool followReferences, bool withComponents) { Stack <IPropertyContainer> toVisit = new Stack <IPropertyContainer>(); startIndex = 0; foreach (GameObject gameObject in container) { if (gameObject.ClassName == className) { MappedObjects[gameObject.Id] = gameObject; toVisit.Push(gameObject); } } visit(toVisit, container, followReferences, withComponents); insertIndex = MappedObjects.Any() ? MappedObjects.Keys.Max() : 0; }
public Structure(GameObject structure, GameObjectContainer saveFile) { id = structure.Names[0].ToString(); className = structure.ClassName; CreatureData structureData = ArkDataManager.GetStructure(className.ToString()); type = structureData != null ? structureData.Name : className.ToString(); location = structure.Location; inventory = structure.GetPropertyValue <ObjectReference, GameObject>("MyInventoryComponent", map: reference => saveFile[reference]); containerActivated = structure.GetPropertyValue <bool>("bContainerActivated"); owningPlayerId = structure.GetPropertyValue <int>("OwningPlayerID"); owningPlayerName = structure.GetPropertyValue <string>("OwningPlayerName", defaultValue: string.Empty); ArkArrayObjectReference linkedStructuresReferences = structure.GetPropertyValue <ArkArrayObjectReference>("LinkedStructures"); if (linkedStructuresReferences != null) { linkedStructures = new int[linkedStructuresReferences.Count]; int index = 0; foreach (ObjectReference objectReference in linkedStructuresReferences) { linkedStructures[index++] = objectReference.ObjectId; } } placedOnFloorStructure = structure.GetPropertyValue <ObjectReference>("PlacedOnFloorStructure")?.ObjectId ?? -1; ownerName = structure.GetPropertyValue <string>("OwnerName", defaultValue: string.Empty); boxName = structure.GetPropertyValue <string>("BoxName", defaultValue: string.Empty); bedName = structure.GetPropertyValue <string>("BedName", defaultValue: string.Empty); maxHealth = structure.GetPropertyValue <float>("MaxHealth"); health = structure.GetPropertyValue <float>("Health", defaultValue: maxHealth); targetingTeam = structure.GetPropertyValue <int>("TargetingTeam"); }
public static IStruct read(ArkArchive archive, ArkName structType) { if (structType.Equals(_itemNetId) || structType.Equals(_transform) || structType.Equals(_primalPlayerDataStruct) || structType.Equals(_primalPlayerCharacterConfigStruct) || structType.Equals(_primalPersistentCharacterStatsStruct) || structType.Equals(_tribeData) || structType.Equals(_tribeGovernment) || structType.Equals(_terrainInfo) || structType.Equals(_itemNetInfo) || structType.Equals(_arkInventoryData) || structType.Equals(_dinoOrderGroup) || structType.Equals(_arkDinoData)) { return(new StructPropertyList(archive, structType)); } else if (structType.Equals(_vector) || structType.Equals(_rotator)) { return(new StructVector(archive, structType)); } else if (structType.Equals(_vector2d)) { return(new StructVector2d(archive, structType)); } else if (structType.Equals(_quat)) { return(new StructQuat(archive, structType)); } else if (structType.Equals(_color)) { return(new StructColor(archive, structType)); } else if (structType.Equals(_linearColor)) { return(new StructLinearColor(archive, structType)); } else if (structType.Equals(_uniqueNetIdRepl)) { return(new StructUniqueNetIdRepl(archive, structType)); } else { _logger.Warn($"Unknown Struct Type {structType} at {archive.Position:X} trying to read as StructPropertyList"); return(new StructPropertyList(archive, structType)); } }
public ArkArrayStruct(ArkArchive archive, int dataSize) { var size = archive.GetInt(); Capacity = size; ArkName structType; if (size * 4 + 4 == dataSize) { structType = ArkName.Create("Color"); } else if (size * 12 + 4 == dataSize) { structType = ArkName.Create("Vector"); } else if (size * 16 + 4 == dataSize) { structType = ArkName.Create("LinearColor"); } else { structType = null; } if (structType != null) { for (int n = 0; n < size; n++) { Add(StructRegistry.read(archive, structType)); } } else { for (int n = 0; n < size; n++) { Add(new StructPropertyList(archive, null)); } } }
public PropertyArray(ArkArchive archive, PropertyArgs args) : base(archive, args) { ArrayType = archive.GetName(); var position = archive.Position; try { _value = ArkArrayRegistry.read(archive, ArrayType, DataSize); if (_value == null) { throw new UnreadablePropertyException(); } } catch (UnreadablePropertyException) { archive.Position += DataSize; _logger.Error($"Unreadable ArrayProperty with name {Name}, skipping."); throw new UnreadablePropertyException(); } }
public override void Init(JArray node, PropertyArray property) { int size = property.DataSize; ArkName structType = StructRegistry.MapArrayNameToTypeName(property.Name); if (structType == null) { if (size * 4 + 4 == property.DataSize) { structType = color; } else if (size * 12 + 4 == property.DataSize) { structType = vector; } else if (size * 16 + 4 == property.DataSize) { structType = linearColor; } } AddRange(node.Select(v => StructRegistry.ReadJson(v, structType))); }
public StructQuat(ArkName structType) : base(structType) { }
public PropertyArray(string name, string typeName, int index, IArkArray value, ArkName arrayType) : base(name, typeName, index, value) { ArrayType = arrayType; }
public PropertyUnknown(ArkArchive archive, ArkName name) : base(name, 0, null) { base.Init(archive, name); Type = name; Value = archive.ReadBytes(DataSize); }
public bool Update(bool manualUpdate, IConfig fullconfig, ISavegameBackupService savegameBackupService, IProgress <string> progress, CancellationToken ct) { //backup this savegame if (!manualUpdate) { SavegameBackupResult result = null; try { if (fullconfig.BackupsEnabled) { result = savegameBackupService.CreateBackup(Config, _contextManager?.GetCluster(Config.Cluster)?.Config); if (result != null && result.ArchivePaths != null) { progress.Report($@"Server ({Config.Key}): Backup successfull ({(string.Join(", ", result.ArchivePaths.Select(x => $@"""{x}""")))})!"); } else { progress.Report($"Server ({Config.Key}): Backup failed..."); } } } catch (Exception ex) { Logging.LogException($"Server ({Config.Key}): Backup failed", ex, typeof(ArkServerContext), LogLevel.ERROR, ExceptionLevel.Ignored); } BackupCompleted?.Invoke(this, fullconfig.BackupsEnabled, result); } //todo: temp copy all var copy = true; var success = false; var cancelled = false; var tmppaths = new List <string>(); var gid = Guid.NewGuid().ToString(); var tempFileOutputDirPath = Path.Combine(fullconfig.TempFileOutputDirPath, gid); ArkSavegame save = null; var st = Stopwatch.StartNew(); try { progress.Report($"Server ({Config.Key}): Update started ({DateTime.Now:HH:mm:ss.ffff})"); var directoryPath = Path.GetDirectoryName(Config.SaveFilePath); if (copy) { //todo: if it exists get a new path if (!Directory.Exists(tempFileOutputDirPath)) { Directory.CreateDirectory(tempFileOutputDirPath); } } if (copy) { var saveFilePath = Path.Combine(tempFileOutputDirPath, Path.GetFileName(Config.SaveFilePath)); tmppaths.Add(saveFilePath); File.Copy(Config.SaveFilePath, saveFilePath); save = new ArkSavegame(saveFilePath); } else { save = new ArkSavegame(Config.SaveFilePath); } save.LoadEverything(); ct.ThrowIfCancellationRequested(); ArkSavegameToolkitNet.ArkTribe[] tribes = null; if (copy) { var tribePaths = new List <string>(); foreach (var tp in Directory.GetFiles(directoryPath, "*.arktribe", SearchOption.TopDirectoryOnly)) { var tribePath = Path.Combine(tempFileOutputDirPath, Path.GetFileName(tp)); tribePaths.Add(tp); tmppaths.Add(tribePath); File.Copy(tp, tribePath); } tribes = tribePaths.Select(x => new ArkSavegameToolkitNet.ArkTribe(x)).ToArray(); } else { tribes = Directory.GetFiles(directoryPath, "*.arktribe", SearchOption.TopDirectoryOnly).Select(x => new ArkSavegameToolkitNet.ArkTribe(x)).ToArray(); } ct.ThrowIfCancellationRequested(); ArkProfile[] profiles = null; if (copy) { var profilePaths = new List <string>(); foreach (var pp in Directory.GetFiles(directoryPath, "*.arkprofile", SearchOption.TopDirectoryOnly)) { var profilePath = Path.Combine(tempFileOutputDirPath, Path.GetFileName(pp)); profilePaths.Add(pp); tmppaths.Add(profilePath); File.Copy(pp, profilePath); } profiles = profilePaths.Select(x => new ArkProfile(x)).ToArray(); } else { profiles = Directory.GetFiles(directoryPath, "*.arkprofile", SearchOption.TopDirectoryOnly).Select(x => new ArkProfile(x)).ToArray(); } ct.ThrowIfCancellationRequested(); var _myCharacterStatusComponent = ArkName.Create("MyCharacterStatusComponent"); var statusComponents = save.Objects.Where(x => x.IsDinoStatusComponent).ToDictionary(x => x.Index, x => x); var tamed = save.Objects.Where(x => x.IsTamedCreature).Select(x => { GameObject status = null; statusComponents.TryGetValue(x.GetPropertyValue <ObjectReference>(_myCharacterStatusComponent).ObjectId, out status); return(x.AsTamedCreature(status, null, save.SaveState)); }).ToArray(); var wild = save.Objects.Where(x => x.IsWildCreature).Select(x => { GameObject status = null; statusComponents.TryGetValue(x.GetPropertyValue <ObjectReference>(_myCharacterStatusComponent).ObjectId, out status); return(x.AsWildCreature(status, null, save.SaveState)); }).ToArray(); var _myData = ArkName.Create("MyData"); var _playerDataID = ArkName.Create("PlayerDataID"); var _linkedPlayerDataID = ArkName.Create("LinkedPlayerDataID"); var playerdict = save.Objects.Where(x => x.IsPlayerCharacter).ToLookup(x => x.GetPropertyValue <ulong>(_linkedPlayerDataID), x => x); var duplicates = playerdict.Where(x => x.Count() > 1).ToArray(); var players = profiles.Select(x => { var mydata = x.GetPropertyValue <StructPropertyList>(_myData); var playerId = mydata.GetPropertyValue <ulong>(_playerDataID); var player = playerdict[playerId]?.FirstOrDefault(); return(x.Profile.AsPlayer(player, x.SaveTime, save.SaveState)); }).ToArray(); SaveState = save.SaveState; TamedCreatures = tamed; WildCreatures = wild; Players = players; Tribes = tribes.Select(x => x.Tribe.AsTribe(x.SaveTime)).ToArray(); Items = save.Objects.Where(x => x.IsItem).Select(x => x.AsItem(save.SaveState)).ToArray(); Structures = save.Objects.Where(x => x.IsStructure).Select(x => x.AsStructure(save.SaveState)).ToArray(); progress.Report($"Server ({Config.Key}): Update finished in {st.ElapsedMilliseconds:N0} ms"); IsInitialized = true; LastUpdate = DateTime.Now; success = true; } catch (OperationCanceledException) { progress.Report($"Server ({Config.Key}): Update was cancelled after {st.ElapsedMilliseconds:N0} ms"); cancelled = true; } catch (Exception ex) { Logging.LogException($"Failed to update server ({Config.Key})", ex, typeof(ArkServerContext), LogLevel.ERROR, ExceptionLevel.Ignored); progress.Report($"Server ({Config.Key}): Update failed after {st.ElapsedMilliseconds:N0} ms"); } finally { save?.Dispose(); if (copy) { try { foreach (var path in tmppaths) { File.Delete(path); } Directory.Delete(tempFileOutputDirPath); } catch { /* ignore exception */ } } UpdateCompleted?.Invoke(this, success, cancelled); } GC.Collect(); return(success); }
public virtual void Init(ArkArchive archive, ArkName name) { Name = name; DataSize = archive.ReadInt(); Index = archive.ReadInt(); }
public virtual void Init(JObject node) { Name = ArkName.From(node.Value <string>("name")); DataSize = node.Value <int>("size"); Index = node.Value <int>("index"); }
public StructPropertyList(ArkName structType) : base(structType) { }
public StructVector2d(ArkName structType, float x, float y) : base(structType) { X = x; Y = y; }
public StructPropertyList(ArkName structType, IDictionary <ArkName, IProperty> properties) : this(structType) { Properties = properties; }
public PropertyInt8(string name, int index, sbyte value) : base(ArkName.From(name), index, value) { }
private static void addStruct(string name, StructConstructor.Binary binaryConstructor, StructConstructor.Json jsonConstructor) { typeMap.Add(ArkName.ConstantPlain(name), new StructConstructor(binaryConstructor, jsonConstructor)); }
public PropertyInt8(string name, sbyte value) : base(ArkName.From(name), 0, value) { }
public static ArkName MapArrayNameToTypeName(ArkName arrayName) { return(arrayName != null && nameTypeMap.TryGetValue(arrayName, out ArkName result) ? result : null); }
public override void Init(ArkArchive archive, ArkName name) { base.Init(archive, name); Value = archive.ReadSByte(); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(ArkName.Create(JToken.Load(reader).ToString())); }
public StructVector2d(ArkName structType) : base(structType) { }
public PropertyArray(string name, int index, IArkArray value) : base(ArkName.From(name), index, value) { }
public StructVector2d(ArkArchive archive, ArkName structType) : base(structType) { X = archive.GetFloat(); Y = archive.GetFloat(); }
protected PropertyBase(ArkName name, int index, T value) { Name = name; Index = index; Value = value; }