// Token: 0x06001161 RID: 4449 RVA: 0x00078784 File Offset: 0x00076984 public void Deserialize(ZPackage pkg) { this.m_msgID = pkg.ReadLong(); this.m_senderPeerID = pkg.ReadLong(); this.m_targetPeerID = pkg.ReadLong(); this.m_targetZDO = pkg.ReadZDOID(); this.m_methodHash = pkg.ReadInt(); this.m_parameters = pkg.ReadPackage(); }
public static WorldPlayer Load(ZPackage pkg) { var worldPlayer = new WorldPlayer(); int num = pkg.ReadInt(); if (!ValheimVersion.IsPlayerVersionCompatible(num)) { return(null); } if (num >= 28) { worldPlayer.PlayerStats_kills = pkg.ReadInt(); worldPlayer.PlayerStats_deaths = pkg.ReadInt(); worldPlayer.PlayerStats_crafts = pkg.ReadInt(); worldPlayer.PlayerStats_builds = pkg.ReadInt(); } worldPlayer.WorldPlayerData.Clear(); int num2 = pkg.ReadInt(); for (int i = 0; i < num2; i++) { long key = pkg.ReadLong(); var worldPlayerData = new WorldPlayerData(); worldPlayerData.m_haveCustomSpawnPoint = pkg.ReadBool(); worldPlayerData.m_spawnPoint = pkg.ReadVector3(); worldPlayerData.m_haveLogoutPoint = pkg.ReadBool(); worldPlayerData.m_logoutPoint = pkg.ReadVector3(); if (num >= 30) { worldPlayerData.m_haveDeathPoint = pkg.ReadBool(); worldPlayerData.m_deathPoint = pkg.ReadVector3(); } worldPlayerData.m_homePoint = pkg.ReadVector3(); if (num >= 29 && pkg.ReadBool()) { worldPlayerData.m_mapData = pkg.ReadByteArray(); } worldPlayer.WorldPlayerData.Add(key, worldPlayerData); } worldPlayer.PlayerName = pkg.ReadString(); worldPlayer.PlayerId = pkg.ReadLong(); worldPlayer.StartSeed = pkg.ReadString(); if (pkg.ReadBool()) { var byteArray = pkg.ReadByteArray(); var playerPkg = new ZPackage(byteArray); worldPlayer.Player = PlayerReaderWriter.Load(playerPkg); } else { worldPlayer.Player = null; } return(worldPlayer); }
private bool LoadPlayerFromDisk() { try { ZPackage zpackage = this.LoadPlayerDataFromDisk(); if (zpackage == null) { ZLog.LogWarning((object)"No player data"); return(false); } int version = zpackage.ReadInt(); if (!Version.IsPlayerVersionCompatible(version)) { ZLog.Log((object)"Player data is not compatible, ignoring"); return(false); } if (version >= 28) { this.m_playerStats.m_kills = zpackage.ReadInt(); this.m_playerStats.m_deaths = zpackage.ReadInt(); this.m_playerStats.m_crafts = zpackage.ReadInt(); this.m_playerStats.m_builds = zpackage.ReadInt(); } this.m_worldData.Clear(); int num = zpackage.ReadInt(); for (int index = 0; index < num; ++index) { long key = zpackage.ReadLong(); PlayerProfile.WorldPlayerData worldPlayerData = new PlayerProfile.WorldPlayerData(); worldPlayerData.m_haveCustomSpawnPoint = zpackage.ReadBool(); worldPlayerData.m_spawnPoint = zpackage.ReadVector3(); worldPlayerData.m_haveLogoutPoint = zpackage.ReadBool(); worldPlayerData.m_logoutPoint = zpackage.ReadVector3(); if (version >= 30) { worldPlayerData.m_haveDeathPoint = zpackage.ReadBool(); worldPlayerData.m_deathPoint = zpackage.ReadVector3(); } worldPlayerData.m_homePoint = zpackage.ReadVector3(); if (version >= 29 && zpackage.ReadBool()) { worldPlayerData.m_mapData = zpackage.ReadByteArray(); } this.m_worldData.Add(key, worldPlayerData); } this.m_playerName = zpackage.ReadString(); this.m_playerID = zpackage.ReadLong(); this.m_startSeed = zpackage.ReadString(); this.m_playerData = !zpackage.ReadBool() ? (byte[])null : zpackage.ReadByteArray(); } catch (Exception ex) { ZLog.LogWarning((object)("Exception while loading player profile:" + this.m_filename + " , " + ex.ToString())); } return(true); }
public void Load(ZPackage pkg) { int propertyCount = pkg.ReadInt(); for (int i = 0; i < propertyCount; i++) { var key = pkg.ReadString(); var dataType = (TyrDataType)Enum.ToObject(typeof(TyrDataType), pkg.ReadInt()); if (dataType == TyrDataType.FLOAT) { var val = pkg.ReadSingle(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.INT) { var val = pkg.ReadInt(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.LONG) { var val = pkg.ReadLong(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.STRING) { var val = pkg.ReadString(); m_properties[key] = new TyrProperty(key, val, true); } } }
// Token: 0x0600072F RID: 1839 RVA: 0x0003A2D0 File Offset: 0x000384D0 private void RPC_ServerList(ZRpc rpc, ZPackage pkg) { this.m_haveServerlist = true; this.m_serverListRevision++; pkg.ReadInt(); int num = pkg.ReadInt(); this.m_servers.Clear(); for (int i = 0; i < num; i++) { ServerData serverData = new ServerData(); serverData.m_name = pkg.ReadString(); serverData.m_host = pkg.ReadString(); serverData.m_port = pkg.ReadInt(); serverData.m_password = pkg.ReadBool(); serverData.m_upnp = pkg.ReadBool(); pkg.ReadLong(); serverData.m_version = pkg.ReadString(); serverData.m_players = pkg.ReadInt(); if (this.m_nameFilter.Length <= 0 || serverData.m_name.Contains(this.m_nameFilter)) { this.m_servers.Add(serverData); } } if (this.m_onServerList != null) { this.m_onServerList(this.m_servers); } }
/// <summary> /// Sync Pin with clients via the server /// </summary> public static void RPC_VPlusMapPinSync(long sender, ZPackage mapPinPkg) { if (ZNet.m_isServer) //Server { if (sender == ZRoutedRpc.instance.GetServerPeerID()) { return; } if (mapPinPkg == null) { return; } foreach (ZNetPeer peer in ZRoutedRpc.instance.m_peers) { if (peer.m_uid != sender) { ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, "VPlusMapPinSync", new object[] { mapPinPkg }); } } ZLog.Log($"Sent map pin to all clients"); //VPlusAck.SendAck(sender); } else //Client { if (sender != ZRoutedRpc.instance.GetServerPeerID()) { return; //Only bother if it's from the server. } if (mapPinPkg == null) { ZLog.LogWarning("Warning: Got empty map pin package from server."); return; } long pinSender = mapPinPkg.ReadLong(); string senderName = mapPinPkg.ReadString(); if (senderName != Player.m_localPlayer.GetPlayerName() && pinSender != ZRoutedRpc.instance.m_id) { ZLog.Log("Checking sent pin"); Vector3 pinPos = mapPinPkg.ReadVector3(); int pinType = mapPinPkg.ReadInt(); string pinName = mapPinPkg.ReadString(); bool keepQuiet = mapPinPkg.ReadBool(); if (!Minimap.instance.HaveSimilarPin(pinPos, (Minimap.PinType)pinType, pinName, true)) { Minimap.PinData addedPin = Minimap.instance.AddPin(pinPos, (Minimap.PinType)pinType, pinName, true, false); if (!keepQuiet) { MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, $"Received map pin {pinName} from {senderName}!", 0, Minimap.instance.GetSprite((Minimap.PinType)pinType)); } ZLog.Log($"I got pin named {pinName} from {senderName}!"); } } //Send Ack //VPlusAck.SendAck(sender); } }
public static BountyInfo FromPackage(ZPackage pkg) { var result = new BountyInfo(); var version = pkg.ReadInt(); result.Interval = pkg.ReadInt(); result.PlayerID = pkg.ReadLong(); result.Biome = (Heightmap.Biome)pkg.ReadInt(); result.State = (BountyState)pkg.ReadInt(); result.Target = BountyTargetInfo.FromPackage(pkg); result.TargetName = pkg.ReadString(); result.RewardIron = pkg.ReadInt(); result.RewardGold = pkg.ReadInt(); result.Position = SerializableVector3.FromPackage(pkg); result.MinimapCircleOffset = SerializableVector3.FromPackage(pkg); var addsCount = pkg.ReadInt(); result.Adds = new List <BountyTargetInfo>(); for (var index = 0; index < addsCount; index++) { result.Adds.Add(BountyTargetInfo.FromPackage(pkg)); } result.Slain = pkg.ReadBool(); return(result); }
// Token: 0x06000C0A RID: 3082 RVA: 0x000559B8 File Offset: 0x00053BB8 public static World LoadWorld(string name) { FileStream fileStream = null; try { fileStream = File.OpenRead(World.GetMetaPath(name)); } catch { if (fileStream != null) { fileStream.Dispose(); } ZLog.Log(" failed to load " + name); return(new World(name, true, false)); } World result; try { BinaryReader binaryReader = new BinaryReader(fileStream); int count = binaryReader.ReadInt32(); ZPackage zpackage = new ZPackage(binaryReader.ReadBytes(count)); int num = zpackage.ReadInt(); if (!global::Version.IsWorldVersionCompatible(num)) { ZLog.Log("incompatible world version " + num); result = new World(name, false, true); } else { World world = new World(); world.m_name = zpackage.ReadString(); world.m_seedName = zpackage.ReadString(); world.m_seed = zpackage.ReadInt(); world.m_uid = zpackage.ReadLong(); if (num >= 26) { world.m_worldGenVersion = zpackage.ReadInt(); } result = world; } } catch { ZLog.LogWarning(" error loading world " + name); result = new World(name, true, false); } finally { if (fileStream != null) { fileStream.Dispose(); } } return(result); }
/// <summary> /// Receive and handle an incoming package /// </summary> /// <param name="sender"></param> /// <param name="package"></param> internal void ReceivePackage(long sender, ZPackage package) { if (package == null || package.Size() <= 0) { return; } Logger.LogDebug($"[{ID}] Received package"); try { CacheExpirations.RemoveAll(kv => { if (kv.Key < DateTimeOffset.Now.Ticks) { PackageCache.Remove(kv.Value); return(true); } return(false); }); byte packageFlags = package.ReadByte(); if ((packageFlags & FRAGMENTED_PACKAGE) != 0) { long uniqueIdentifier = package.ReadLong(); string cacheKey = sender.ToString() + uniqueIdentifier; int fragment = package.ReadInt(); int fragments = package.ReadInt(); if (!PackageCache.TryGetValue(cacheKey, out SortedDictionary <int, byte[]> dataFragments)) { dataFragments = new SortedDictionary <int, byte[]>(); PackageCache[cacheKey] = dataFragments; CacheExpirations.Add(new KeyValuePair <long, string>(DateTimeOffset.Now.AddSeconds(60).Ticks, cacheKey)); } dataFragments.Add(fragment, package.ReadByteArray()); if (dataFragments.Count < fragments) { return; } PackageCache.Remove(cacheKey); package = new ZPackage(dataFragments.Values.SelectMany(a => a).ToArray()); packageFlags = package.ReadByte(); } ZNet.instance.StartCoroutine(HandlePackageRoutine(sender, package, packageFlags)); } catch (Exception e) { Logger.LogWarning($"[{ID}] Error caught while applying package: {e}"); } }
// Token: 0x060006B0 RID: 1712 RVA: 0x000377B4 File Offset: 0x000359B4 public static Inventory Load(ZPackage pkg) { var inventory = new Inventory(); int num = pkg.ReadInt(); int num2 = pkg.ReadInt(); inventory.m_inventory.Clear(); for (int i = 0; i < num2; i++) { string text = pkg.ReadString(); int stack = pkg.ReadInt(); float durability = pkg.ReadSingle(); Vector2i pos = pkg.ReadVector2i(); bool equiped = pkg.ReadBool(); int quality = 1; if (num >= 101) { quality = pkg.ReadInt(); } int variant = 0; if (num >= 102) { variant = pkg.ReadInt(); } long crafterID = 0L; string crafterName = ""; if (num >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (text != "") { var item = new InventoryItem() { prefabName = text, m_stack = stack, m_durability = durability, m_gridPos = pos, m_equiped = equiped, m_quality = quality, m_variant = variant, m_crafterID = crafterID, m_crafterName = crafterName }; inventory.m_inventory.Add(item); } } return(inventory); }
public static void Deserialize(this PlayerProfile profile, ZPackage data) { Debug.Assert(data.ReadInt() <= Version.m_playerVersion); profile.m_playerStats.m_kills = data.ReadInt(); profile.m_playerStats.m_deaths = data.ReadInt(); profile.m_playerStats.m_crafts = data.ReadInt(); profile.m_playerStats.m_builds = data.ReadInt(); profile.m_worldData.Clear(); int num = data.ReadInt(); for (int i = 0; i < num; i++) { long key = data.ReadLong(); PlayerProfile.WorldPlayerData worldPlayerData = (PlayerProfile.WorldPlayerData)Activator.CreateInstance(typeof(PlayerProfile.WorldPlayerData), true); worldPlayerData.m_haveCustomSpawnPoint = data.ReadBool(); worldPlayerData.m_spawnPoint = data.ReadVector3(); worldPlayerData.m_haveLogoutPoint = data.ReadBool(); worldPlayerData.m_logoutPoint = data.ReadVector3(); worldPlayerData.m_haveDeathPoint = data.ReadBool(); worldPlayerData.m_deathPoint = data.ReadVector3(); worldPlayerData.m_homePoint = data.ReadVector3(); if (data.ReadBool()) { worldPlayerData.m_mapData = data.ReadByteArray(); } profile.m_worldData.Add(key, worldPlayerData); } profile.m_playerName = data.ReadString(); profile.m_playerID = data.ReadLong(); if (profile.m_playerID == 0L) { profile.m_playerID = Utils.GenerateUID(); } profile.m_startSeed = data.ReadString(); if (data.ReadBool()) { profile.m_playerData = data.ReadByteArray(); } }
public static object ReadVariable(this ZPackage zp, Type t) { if (t == typeof(int)) { return(zp.ReadInt()); } if (t == typeof(uint)) { return(zp.ReadUInt()); } if (t == typeof(bool)) { return(zp.ReadBool()); } if (t == typeof(char)) { return(zp.ReadChar()); } if (t == typeof(sbyte)) { return(zp.ReadSByte()); } if (t == typeof(long)) { return(zp.ReadLong()); } if (t == typeof(ulong)) { return(zp.ReadULong()); } if (t == typeof(float)) { return(zp.ReadSingle()); } if (t == typeof(double)) { return(zp.ReadDouble()); } if (t == typeof(string)) { return(zp.ReadString()); } return(null); }
// Token: 0x060006B8 RID: 1720 RVA: 0x00037B04 File Offset: 0x00035D04 public void Load(ZPackage pkg) { int num = pkg.ReadInt(); int num2 = pkg.ReadInt(); this.m_inventory.Clear(); for (int i = 0; i < num2; i++) { string text = pkg.ReadString(); int stack = pkg.ReadInt(); float durability = pkg.ReadSingle(); Vector2i pos = pkg.ReadVector2i(); bool equiped = pkg.ReadBool(); int quality = 1; if (num >= 101) { quality = pkg.ReadInt(); } int variant = 0; if (num >= 102) { variant = pkg.ReadInt(); } long crafterID = 0L; string crafterName = ""; if (num >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (text != "") { this.AddItem(text, stack, durability, pos, equiped, quality, variant, crafterID, crafterName); } } this.Changed(); }
// Token: 0x06000918 RID: 2328 RVA: 0x0004377C File Offset: 0x0004197C public static void Deserialize(ParameterInfo[] paramInfo, ZPackage pkg, ref List <object> parameters) { for (int i = 1; i < paramInfo.Length; i++) { ParameterInfo parameterInfo = paramInfo[i]; if (parameterInfo.ParameterType == typeof(int)) { parameters.Add(pkg.ReadInt()); } else if (parameterInfo.ParameterType == typeof(uint)) { parameters.Add(pkg.ReadUInt()); } else if (parameterInfo.ParameterType == typeof(long)) { parameters.Add(pkg.ReadLong()); } else if (parameterInfo.ParameterType == typeof(float)) { parameters.Add(pkg.ReadSingle()); } else if (parameterInfo.ParameterType == typeof(double)) { parameters.Add(pkg.ReadDouble()); } else if (parameterInfo.ParameterType == typeof(bool)) { parameters.Add(pkg.ReadBool()); } else if (parameterInfo.ParameterType == typeof(string)) { parameters.Add(pkg.ReadString()); } else if (parameterInfo.ParameterType == typeof(ZPackage)) { parameters.Add(pkg.ReadPackage()); } else if (parameterInfo.ParameterType == typeof(List <string>)) { int num = pkg.ReadInt(); List <string> list = new List <string>(num); for (int j = 0; j < num; j++) { list.Add(pkg.ReadString()); } parameters.Add(list); } else if (parameterInfo.ParameterType == typeof(Vector3)) { Vector3 vector = new Vector3(pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle()); parameters.Add(vector); } else if (parameterInfo.ParameterType == typeof(Quaternion)) { Quaternion quaternion = new Quaternion(pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle()); parameters.Add(quaternion); } else if (parameterInfo.ParameterType == typeof(ZDOID)) { parameters.Add(pkg.ReadZDOID()); } else if (parameterInfo.ParameterType == typeof(HitData)) { HitData hitData = new HitData(); hitData.Deserialize(ref pkg); parameters.Add(hitData); } } }
public bool LoadPlayerFromDisk(out string error) { error = string.Empty; ZPackage zPackage = LoadPlayerDataFromDisk(); //backup DirectoryInfo dir = Directory.CreateDirectory("backup"); File.WriteAllBytes($"{dir.FullName}/{m_filename}", zPackage.GetArray()); if (zPackage == null) { error = "No player data"; return(false); } m_version = zPackage.ReadInt(); if (!VersionInfo.IsPlayerVersionCompatible(m_version)) { error = "Player data is not compatible, ignoring"; return(false); } if (m_version >= 28) { m_playerStats.m_kills = zPackage.ReadInt(); m_playerStats.m_deaths = zPackage.ReadInt(); m_playerStats.m_crafts = zPackage.ReadInt(); m_playerStats.m_builds = zPackage.ReadInt(); } int num2 = zPackage.ReadInt(); for (int i = 0; i < num2; i++) { long key = zPackage.ReadLong(); WorldPlayerData worldPlayerData = new WorldPlayerData(); worldPlayerData.m_haveCustomSpawnPoint = zPackage.ReadBool(); worldPlayerData.m_spawnPoint = zPackage.ReadVector3(); worldPlayerData.m_haveLogoutPoint = zPackage.ReadBool(); worldPlayerData.m_logoutPoint = zPackage.ReadVector3(); if (m_version >= 30) { worldPlayerData.m_haveDeathPoint = zPackage.ReadBool(); worldPlayerData.m_deathPoint = zPackage.ReadVector3(); } worldPlayerData.m_homePoint = zPackage.ReadVector3(); if (m_version >= 29 && zPackage.ReadBool()) { worldPlayerData.m_mapData = zPackage.ReadByteArray(); } m_worldData.Add(key, worldPlayerData); } m_playerName = zPackage.ReadString(); m_playerID = zPackage.ReadLong(); m_startSeed = zPackage.ReadString(); m_playerData = null; if (zPackage.ReadBool()) { m_playerData = zPackage.ReadByteArray(); } return(true); }
// Token: 0x060007D3 RID: 2003 RVA: 0x0003D98C File Offset: 0x0003BB8C private void RPC_ZDOData(ZRpc rpc, ZPackage pkg) { ZDOMan.ZDOPeer zdopeer = this.FindPeer(rpc); if (zdopeer == null) { ZLog.Log("ZDO data from unkown host, ignoring"); return; } float time = Time.time; int num = 0; ZPackage pkg2 = new ZPackage(); int num2 = pkg.ReadInt(); for (int i = 0; i < num2; i++) { ZDOID id = pkg.ReadZDOID(); ZDO zdo = this.GetZDO(id); if (zdo != null) { zdo.InvalidateSector(); } } for (;;) { ZDOID zdoid = pkg.ReadZDOID(); if (zdoid.IsNone()) { break; } num++; uint num3 = pkg.ReadUInt(); uint num4 = pkg.ReadUInt(); long owner = pkg.ReadLong(); Vector3 vector = pkg.ReadVector3(); pkg.ReadPackage(ref pkg2); ZDO zdo2 = this.GetZDO(zdoid); bool flag = false; if (zdo2 != null) { if (num4 <= zdo2.m_dataRevision) { if (num3 > zdo2.m_ownerRevision) { zdo2.m_owner = owner; zdo2.m_ownerRevision = num3; zdopeer.m_zdos[zdoid] = new ZDOMan.ZDOPeer.PeerZDOInfo(num4, num3, time); continue; } continue; } } else { zdo2 = this.CreateNewZDO(zdoid, vector); flag = true; } zdo2.m_ownerRevision = num3; zdo2.m_dataRevision = num4; zdo2.m_owner = owner; zdo2.InternalSetPosition(vector); zdopeer.m_zdos[zdoid] = new ZDOMan.ZDOPeer.PeerZDOInfo(zdo2.m_dataRevision, zdo2.m_ownerRevision, time); zdo2.Deserialize(pkg2); if (ZNet.instance.IsServer() && flag && this.m_deadZDOs.ContainsKey(zdoid)) { zdo2.SetOwner(this.m_myid); this.DestroyZDO(zdo2); } } this.m_zdosRecv += num; }
// Token: 0x06000793 RID: 1939 RVA: 0x0003BE94 File Offset: 0x0003A094 public void Load(ZPackage pkg, int version) { this.m_ownerRevision = pkg.ReadUInt(); this.m_dataRevision = pkg.ReadUInt(); this.m_persistent = pkg.ReadBool(); this.m_owner = pkg.ReadLong(); this.m_timeCreated = pkg.ReadLong(); this.m_pgwVersion = pkg.ReadInt(); if (version >= 16 && version < 24) { pkg.ReadInt(); } if (version >= 23) { this.m_type = (ZDO.ObjectType)pkg.ReadSByte(); } if (version >= 22) { this.m_distant = pkg.ReadBool(); } if (version < 13) { pkg.ReadChar(); pkg.ReadChar(); } if (version >= 17) { this.m_prefab = pkg.ReadInt(); } this.m_sector = pkg.ReadVector2i(); this.m_position = pkg.ReadVector3(); this.m_rotation = pkg.ReadQuaternion(); int num = (int)pkg.ReadChar(); if (num > 0) { this.InitFloats(); for (int i = 0; i < num; i++) { int key = pkg.ReadInt(); this.m_floats[key] = pkg.ReadSingle(); } } else { this.ReleaseFloats(); } int num2 = (int)pkg.ReadChar(); if (num2 > 0) { this.InitVec3(); for (int j = 0; j < num2; j++) { int key2 = pkg.ReadInt(); this.m_vec3[key2] = pkg.ReadVector3(); } } else { this.ReleaseVec3(); } int num3 = (int)pkg.ReadChar(); if (num3 > 0) { this.InitQuats(); for (int k = 0; k < num3; k++) { int key3 = pkg.ReadInt(); this.m_quats[key3] = pkg.ReadQuaternion(); } } else { this.ReleaseQuats(); } int num4 = (int)pkg.ReadChar(); if (num4 > 0) { this.InitInts(); for (int l = 0; l < num4; l++) { int key4 = pkg.ReadInt(); this.m_ints[key4] = pkg.ReadInt(); } } else { this.ReleaseInts(); } int num5 = (int)pkg.ReadChar(); if (num5 > 0) { this.InitLongs(); for (int m = 0; m < num5; m++) { int key5 = pkg.ReadInt(); this.m_longs[key5] = pkg.ReadLong(); } } else { this.ReleaseLongs(); } int num6 = (int)pkg.ReadChar(); if (num6 > 0) { this.InitStrings(); for (int n = 0; n < num6; n++) { int key6 = pkg.ReadInt(); this.m_strings[key6] = pkg.ReadString(); } } else { this.ReleaseStrings(); } if (version < 17) { this.m_prefab = this.GetInt("prefab", 0); } }
// Token: 0x06000791 RID: 1937 RVA: 0x0003B918 File Offset: 0x00039B18 public void Deserialize(ZPackage pkg) { this.m_persistent = pkg.ReadBool(); this.m_distant = pkg.ReadBool(); this.m_timeCreated = pkg.ReadLong(); this.m_pgwVersion = pkg.ReadInt(); this.m_type = (ZDO.ObjectType)pkg.ReadSByte(); this.m_prefab = pkg.ReadInt(); this.m_rotation = pkg.ReadQuaternion(); int num = pkg.ReadInt(); if ((num & 1) != 0) { this.InitFloats(); int num2 = (int)pkg.ReadByte(); for (int i = 0; i < num2; i++) { int key = pkg.ReadInt(); this.m_floats[key] = pkg.ReadSingle(); } } else { this.ReleaseFloats(); } if ((num & 2) != 0) { this.InitVec3(); int num3 = (int)pkg.ReadByte(); for (int j = 0; j < num3; j++) { int key2 = pkg.ReadInt(); this.m_vec3[key2] = pkg.ReadVector3(); } } else { this.ReleaseVec3(); } if ((num & 4) != 0) { this.InitQuats(); int num4 = (int)pkg.ReadByte(); for (int k = 0; k < num4; k++) { int key3 = pkg.ReadInt(); this.m_quats[key3] = pkg.ReadQuaternion(); } } else { this.ReleaseQuats(); } if ((num & 8) != 0) { this.InitInts(); int num5 = (int)pkg.ReadByte(); for (int l = 0; l < num5; l++) { int key4 = pkg.ReadInt(); this.m_ints[key4] = pkg.ReadInt(); } } else { this.ReleaseInts(); } if ((num & 64) != 0) { this.InitLongs(); int num6 = (int)pkg.ReadByte(); for (int m = 0; m < num6; m++) { int key5 = pkg.ReadInt(); this.m_longs[key5] = pkg.ReadLong(); } } else { this.ReleaseLongs(); } if ((num & 16) != 0) { this.InitStrings(); int num7 = (int)pkg.ReadByte(); for (int n = 0; n < num7; n++) { int key6 = pkg.ReadInt(); this.m_strings[key6] = pkg.ReadString(); } return; } this.ReleaseStrings(); }
public void Deserialize(ZPackage pkg) { this.m_persistent = pkg.ReadBool(); this.m_distant = pkg.ReadBool(); this.m_timeCreated = pkg.ReadLong(); this.m_pgwVersion = pkg.ReadInt(); this.m_type = (ZDO.ObjectType)pkg.ReadSByte(); this.m_prefab = pkg.ReadInt(); this.m_rotation = pkg.ReadQuaternion(); int num1 = pkg.ReadInt(); if ((num1 & 1) != 0) { this.InitFloats(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_floats[pkg.ReadInt()] = pkg.ReadSingle(); } } else { this.ReleaseFloats(); } if ((num1 & 2) != 0) { this.InitVec3(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_vec3[pkg.ReadInt()] = pkg.ReadVector3(); } } else { this.ReleaseVec3(); } if ((num1 & 4) != 0) { this.InitQuats(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_quats[pkg.ReadInt()] = pkg.ReadQuaternion(); } } else { this.ReleaseQuats(); } if ((num1 & 8) != 0) { this.InitInts(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_ints[pkg.ReadInt()] = pkg.ReadInt(); } } else { this.ReleaseInts(); } if ((num1 & 64) != 0) { this.InitLongs(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_longs[pkg.ReadInt()] = pkg.ReadLong(); } } else { this.ReleaseLongs(); } if ((num1 & 16) != 0) { this.InitStrings(); int num2 = (int)pkg.ReadByte(); for (int index = 0; index < num2; ++index) { this.m_strings[pkg.ReadInt()] = pkg.ReadString(); } } else { this.ReleaseStrings(); } }
public void Load(ZPackage pkg, int version) { this.m_ownerRevision = pkg.ReadUInt(); this.m_dataRevision = pkg.ReadUInt(); this.m_persistent = pkg.ReadBool(); this.m_owner = pkg.ReadLong(); this.m_timeCreated = pkg.ReadLong(); this.m_pgwVersion = pkg.ReadInt(); if (version >= 16 && version < 24) { pkg.ReadInt(); } if (version >= 23) { this.m_type = (ZDO.ObjectType)pkg.ReadSByte(); } if (version >= 22) { this.m_distant = pkg.ReadBool(); } if (version < 13) { int num1 = (int)pkg.ReadChar(); int num2 = (int)pkg.ReadChar(); } if (version >= 17) { this.m_prefab = pkg.ReadInt(); } this.m_sector = pkg.ReadVector2i(); this.m_position = pkg.ReadVector3(); this.m_rotation = pkg.ReadQuaternion(); int num3 = (int)pkg.ReadChar(); if (num3 > 0) { this.InitFloats(); for (int index = 0; index < num3; ++index) { this.m_floats[pkg.ReadInt()] = pkg.ReadSingle(); } } else { this.ReleaseFloats(); } int num4 = (int)pkg.ReadChar(); if (num4 > 0) { this.InitVec3(); for (int index = 0; index < num4; ++index) { this.m_vec3[pkg.ReadInt()] = pkg.ReadVector3(); } } else { this.ReleaseVec3(); } int num5 = (int)pkg.ReadChar(); if (num5 > 0) { this.InitQuats(); for (int index = 0; index < num5; ++index) { this.m_quats[pkg.ReadInt()] = pkg.ReadQuaternion(); } } else { this.ReleaseQuats(); } int num6 = (int)pkg.ReadChar(); if (num6 > 0) { this.InitInts(); for (int index = 0; index < num6; ++index) { this.m_ints[pkg.ReadInt()] = pkg.ReadInt(); } } else { this.ReleaseInts(); } int num7 = (int)pkg.ReadChar(); if (num7 > 0) { this.InitLongs(); for (int index = 0; index < num7; ++index) { this.m_longs[pkg.ReadInt()] = pkg.ReadLong(); } } else { this.ReleaseLongs(); } int num8 = (int)pkg.ReadChar(); if (num8 > 0) { this.InitStrings(); for (int index = 0; index < num8; ++index) { this.m_strings[pkg.ReadInt()] = pkg.ReadString(); } } else { this.ReleaseStrings(); } if (version >= 17) { return; } this.m_prefab = this.GetInt("prefab", 0); }
private void Deserialize(ZPackage pkg) { Version = pkg.ReadInt(); if (Version > LatestVersion) { LogError($"BetterContinents mod is out of date: world expects config version {Version}, mod config version is {LatestVersion}"); throw new Exception($"BetterContinents mod is out of date: world expects config version {Version}, mod config version is {LatestVersion}"); } WorldUId = pkg.ReadLong(); EnabledForThisWorld = pkg.ReadBool(); if (EnabledForThisWorld) { GlobalScale = pkg.ReadSingle(); MountainsAmount = pkg.ReadSingle(); SeaLevelAdjustment = pkg.ReadSingle(); MaxRidgeHeight = pkg.ReadSingle(); RidgeScale = pkg.ReadSingle(); RidgeBlendSigmoidB = pkg.ReadSingle(); RidgeBlendSigmoidXOffset = pkg.ReadSingle(); var heightmapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(heightmapFilePath)) { Heightmap = new ImageMapFloat(heightmapFilePath, pkg.ReadByteArray()); if (Version <= 4 && !Heightmap.CreateMapLegacy() || Version > 4 && !Heightmap.CreateMap()) { Heightmap = null; } HeightmapAmount = pkg.ReadSingle(); HeightmapBlend = pkg.ReadSingle(); HeightmapAdd = pkg.ReadSingle(); } OceanChannelsEnabled = pkg.ReadBool(); if (Version >= 2) { RiversEnabled = pkg.ReadBool(); //LakesEnabled = pkg.ReadBool(); var biomemapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(biomemapFilePath)) { Biomemap = new ImageMapBiome(biomemapFilePath, pkg.ReadByteArray()); if (!Biomemap.CreateMap()) { Biomemap = null; } } ForestScale = pkg.ReadSingle(); ForestAmountOffset = pkg.ReadSingle(); OverrideStartPosition = pkg.ReadBool(); StartPositionX = pkg.ReadSingle(); StartPositionY = pkg.ReadSingle(); } else { RiversEnabled = true; ForestScale = 1; ForestAmountOffset = 0; OverrideStartPosition = false; StartPositionX = 0; StartPositionY = 0; //LakesEnabled = true; } // Version 3 if (Version >= 3) { var spawnmapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(spawnmapFilePath)) { Spawnmap = new ImageMapSpawn(spawnmapFilePath, pkg); } } // Version 4 // (nothing) // Version 5 if (Version >= 5) { var roughmapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(roughmapFilePath)) { Roughmap = new ImageMapFloat(roughmapFilePath, pkg.ReadByteArray()); if (!Roughmap.CreateMap()) { Roughmap = null; } RoughmapBlend = pkg.ReadSingle(); } UseRoughInvertedAsFlat = pkg.ReadBool(); FlatmapBlend = pkg.ReadSingle(); if (!UseRoughInvertedAsFlat) { var flatmapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(flatmapFilePath)) { Flatmap = new ImageMapFloat(flatmapFilePath, pkg.ReadByteArray()); if (!Flatmap.CreateMap()) { Flatmap = null; } } } var forestmapFilePath = pkg.ReadString(); if (!string.IsNullOrEmpty(forestmapFilePath)) { Forestmap = new ImageMapFloat(forestmapFilePath, pkg.ReadByteArray()); if (!Forestmap.CreateMap()) { Forestmap = null; } ForestmapMultiply = pkg.ReadSingle(); ForestmapAdd = pkg.ReadSingle(); } DisableMapEdgeDropoff = pkg.ReadBool(); MountainsAllowedAtCenter = pkg.ReadBool(); ForestFactorOverrideAllTrees = pkg.ReadBool(); } // Version 6 if (Version >= 6) { HeightmapOverrideAll = pkg.ReadBool(); HeightmapMask = pkg.ReadSingle(); } else { HeightmapOverrideAll = false; HeightmapMask = 0; } } }
static bool Load(ref Inventory __instance, ref ZPackage pkg) { int num = pkg.ReadInt(); int num2 = pkg.ReadInt(); __instance.m_inventory.Clear(); for (int i = 0; i < num2; i++) { string text = pkg.ReadString(); int stack = pkg.ReadInt(); float durability = pkg.ReadSingle(); Vector2i pos = pkg.ReadVector2i(); bool equiped = pkg.ReadBool(); int quality = 1; if (num >= 101) { quality = pkg.ReadInt(); } int variant = 0; if (num >= 102) { variant = pkg.ReadInt(); } long crafterID = 0L; string crafterName = ""; if (num >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (text != "") { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text); if (itemPrefab == null) { ZLog.Log("Failed to find item prefab " + text); continue; } ZNetView.m_forceDisableInit = true; GameObject gameObject = UnityEngine.Object.Instantiate(itemPrefab); ZNetView.m_forceDisableInit = false; ItemDrop component = gameObject.GetComponent <ItemDrop>(); if (component == null) { ZLog.Log("Missing itemdrop in " + text); UnityEngine.Object.Destroy(gameObject); continue; } component.m_itemData.m_stack = Mathf.Min(stack, component.m_itemData.m_shared.m_maxStackSize); component.m_itemData.m_durability = durability; component.m_itemData.m_equiped = equiped; component.m_itemData.m_quality = quality; component.m_itemData.m_variant = variant; component.m_itemData.m_crafterID = crafterID; component.m_itemData.m_crafterName = crafterName; if (num == 10000 && component.m_itemData is TyrData) { var tyrData = (TyrData)component.m_itemData; tyrData.Load(pkg); } __instance.AddItem(component.m_itemData, component.m_itemData.m_stack, pos.x, pos.y); UnityEngine.Object.Destroy(gameObject); } } __instance.Changed(); return(false); }
public static bool Prefix(Inventory __instance, ZPackage pkg) { var version = pkg.ReadInt(); var itemCount = pkg.ReadInt(); __instance.m_inventory.Clear(); OutsideItems.Clear(); GraveItems.Clear(); DroppedItems.Clear(); for (var index = 0; index < itemCount; ++index) { var name = pkg.ReadString(); var stack = pkg.ReadInt(); var durability = pkg.ReadSingle(); var pos = pkg.ReadVector2i(); var equiped = pkg.ReadBool(); var quality = 1; if (version >= 101) { quality = pkg.ReadInt(); } var variant = 0; if (version >= 102) { variant = pkg.ReadInt(); } long crafterID = 0; var crafterName = ""; if (version >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (name != "") { __instance.AddItem(name, stack, durability, pos, equiped, quality, variant, crafterID, crafterName); if (IsOutsideInventory(__instance, pos)) { Debug.LogWarning($"Item ({name}) was outside inventory ({pos}), finding new position."); var item = __instance.GetItemAt(pos.x, pos.y); OutsideItems.Add(item); } } } foreach (var item in OutsideItems) { var addedItem = __instance.AddItem(item); if (!addedItem) { Debug.LogWarning($"Could not add item ({item.m_shared.m_name}) to regular inventory, adding item to grave"); GraveItems.Add(item); } } if (GraveItems.Count > 0) { if (Player.m_localPlayer.GetInventory() == __instance) { var graveInventory = CreateTempGrave(Player.m_localPlayer); foreach (var item in GraveItems) { bool addedItem = graveInventory.AddItem(item); if (!addedItem) { Debug.LogWarning($"Could not add item ({item.m_shared.m_name}) to temp grave, dropping on ground"); DroppedItems.Add(item); } } } else { DroppedItems.AddRange(GraveItems); } } foreach (var item in DroppedItems) { if (Player.m_localPlayer.GetInventory() == __instance) { Player.m_localPlayer.DropItem(__instance, item, item.m_stack); } else { Debug.LogError($"Could not recover item from non-Player inventory ({__instance.GetName()}), dropping at origin?!?!"); ItemDrop.DropItem(item, item.m_stack, Vector3.zero + Vector3.up * 10, Quaternion.identity); } } __instance.Changed(); return(false); }