コード例 #1
0
 public void Deserialize(byte[] bytes, ref int offset)
 {
     this.userCount            = ByteSerializer.DeserializeInt(bytes, ref offset);
     this.userCap              = ByteSerializer.DeserializeInt(bytes, ref offset);
     this.acceptingConnections = ByteSerializer.DeserializeBool(bytes, ref offset);
     this.lobbyMode            = (LobbyMode)ByteSerializer.DeserializeInt(bytes, ref offset);
     this.isFrozen             = ByteSerializer.DeserializeBool(bytes, ref offset);
     this.playerNames          = ByteSerializer.DeserializeStrings(bytes, ref offset);
 }
コード例 #2
0
        public static void patchDeserializerPostfix(SandboxLayoutData __instance, byte[] bytes, ref int offset, bool __state)
        {
            //ptfInstance.ptfLogger.LogMessage($"Layout version pre-load: {__instance.m_Version}");
            if (!__state)
            {
                return;
            }
            string[] strings = ByteSerializer.DeserializeStrings(bytes, ref offset);
            ptfInstance.ptfLogger.LogInfo($"Layout created with mod{(strings.Length > 1 ? "s" : "")}: ");
            foreach (string str in strings)
            {
                string[] partsOfMod = str.Split('\u058D');
                string   name       = partsOfMod.Length >= 1 ? partsOfMod[0] : null;
                string   version    = partsOfMod.Length >= 2 ? partsOfMod[1] : null;
                string   settings   = partsOfMod.Length >= 3 ? partsOfMod[2] : null;

                ptfInstance.ptfLogger.LogInfo($" -- {str.Replace("\u058D", " - v")}");

                var currMod = cheatMods.Where(p => p.Info.Metadata.Name == name).FirstOrDefault();
                if (currMod == null)
                {
                    currMod = noncheatMods.Where(p => p.Info.Metadata.Name == name).FirstOrDefault();
                }

                ptfInstance.checkMods(0, name, version, settings, currMod);
            }
            if (offset == bytes.Length)
            {
                return;
            }
            int extraSaveDataCount = ByteSerializer.DeserializeInt(bytes, ref offset);

            if (extraSaveDataCount == 0)
            {
                return;
            }

            ptfInstance.Logger.LogInfo($"Layout created with custom data from mods: ");

            for (int i = 0; i < extraSaveDataCount; i++)
            {
                string modIdentifier     = ByteSerializer.DeserializeString(bytes, ref offset);
                byte[] customModSaveData = ByteSerializer.DeserializeByteArray(bytes, ref offset);

                string[] partsOfMod = modIdentifier.Split('\u058D');
                string   name       = partsOfMod.Length >= 1 ? partsOfMod[0] : null;
                string   version    = partsOfMod.Length >= 2 ? partsOfMod[1] : null;

                ptfInstance.Logger.LogInfo($" -- {name} - v{version}");

                var currMod = cheatMods.Where(p => p.Info.Metadata.Name == name).FirstOrDefault();
                if (currMod == null)
                {
                    currMod = noncheatMods.Where(p => p.Info.Metadata.Name == name).FirstOrDefault();
                }

                if (currMod == null)
                {
                    return;
                }
                if (currMod.Info.Metadata.Version.ToString() != version)
                {
                    return;
                }

                currMod.loadData(customModSaveData);
            }
        }