예제 #1
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.CraftFromChest.IsEnabled || Configuration.Current.CraftFromChest.disableCookingStation)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();
            int endIdx = -1;

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].opcode == OpCodes.Ldnull)
                {
                    il[i] = new CodeInstruction(OpCodes.Ldarg_0)
                    {
                        labels = il[i].labels
                    };
                    il.Insert(++i, new CodeInstruction(OpCodes.Call, method_PullCookableItemFromNearbyChests));
                    il.Insert(++i, new CodeInstruction(OpCodes.Stloc_3));
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldloc_3));
                    endIdx = i;
                    break;
                }
            }
            if (endIdx == -1)
            {
                ZLog.LogError("Failed to apply CookingStation_FindCookableItem_Transpiler");
                return(instructions);
            }

            return(il.AsEnumerable());
        }
예제 #2
0
    // Token: 0x06000924 RID: 2340 RVA: 0x00043DD4 File Offset: 0x00041FD4
    private void PkgSizeReceived(IAsyncResult res)
    {
        int num;

        try
        {
            num = this.m_socket.EndReceive(res);
        }
        catch (Exception)
        {
            this.Disconnect();
            return;
        }
        this.m_totalRecv += num;
        if (num != 4)
        {
            this.Disconnect();
            return;
        }
        int num2 = BitConverter.ToInt32(this.m_recvSizeBuffer, 0);

        if (num2 == 0 || num2 > 10485760)
        {
            ZLog.LogError("Invalid pkg size " + num2);
            return;
        }
        this.m_lastRecvPkgSize = num2;
        this.m_recvOffset      = 0;
        this.m_lastRecvPkgSize = num2;
        if (this.m_recvBuffer == null)
        {
            this.m_recvBuffer = new byte[ZSocket.m_maxRecvBuffer];
        }
        this.m_socket.BeginReceive(this.m_recvBuffer, this.m_recvOffset, this.m_lastRecvPkgSize, SocketFlags.None, new AsyncCallback(this.PkgReceived), this.m_socket);
    }
예제 #3
0
파일: ILPatches.cs 프로젝트: fclante/VAC
        private static IEnumerable <CodeInstruction> SendPeerInfo_Transpile(
            IEnumerable <CodeInstruction> instructions)
        {
            if ((object)ILPatches._zpackageConstructor == null || (object)ILPatches._zpackageWriteStr == null || (object)ILPatches._zpackageWriteLong == null)
            {
                ZLog.LogError((object)"[AntiMods] Could not find ZPackage:ZPackage, ZPackage:Write(string) or ZPackage:Write(long)!");
                return(instructions);
            }
            List <CodeInstruction> codeInstructionList = new List <CodeInstruction>(instructions);
            int lastIndex = codeInstructionList.FindLastIndex((Predicate <CodeInstruction>)(x => x.Calls(ILPatches._zpackageWriteByteArray)));

            if (lastIndex == -1)
            {
                ZLog.LogError((object)"[AntiMods] Could not get ZPackage:ZPackage() instruction!");
                return((IEnumerable <CodeInstruction>)codeInstructionList);
            }
            codeInstructionList.InsertRange(lastIndex + 1, (IEnumerable <CodeInstruction>) new CodeInstruction[3]
            {
                new CodeInstruction(OpCodes.Ldloc, (object)0),
                new CodeInstruction(OpCodes.Ldstr, (object)VACPlugin.PluginsHash),
                new CodeInstruction(OpCodes.Callvirt, (object)ILPatches._zpackageWriteStr)
            });
            if (VACPlugin.debugmode.Value)
            {
                codeInstructionList.ForEach((Action <CodeInstruction>)(x => ZLog.Log((object)string.Format("[{0}] {1} -> {2}", (object)"AntiCheat", (object)x.opcode, (object)(x.operand?.ToString() ?? "<none>")))));
            }
            return((IEnumerable <CodeInstruction>)codeInstructionList);
        }
예제 #4
0
파일: ILPatches.cs 프로젝트: fclante/VAC
        private static IEnumerable <CodeInstruction> ShowConnectError_Transpile(
            IEnumerable <CodeInstruction> instructions)
        {
            if ((object)ILPatches._zpackageConstructor == null || (object)ILPatches._zpackageWriteStr == null || (object)ILPatches._zpackageWriteLong == null)
            {
                ZLog.LogError((object)"[AntiMods] Could not find ZPackage:ZPackage, ZPackage:Write(string) or ZPackage:Write(long)!");
                return(instructions);
            }
            List <CodeInstruction> codeInstructionList = new List <CodeInstruction>(instructions);
            int lastIndex = codeInstructionList.FindLastIndex((Predicate <CodeInstruction>)(x => (int)x.opcode.Value == (int)OpCodes.Ret.Value));

            if (lastIndex == -1)
            {
                ZLog.LogError((object)"[AntiMods] Could not get FejdStartup:ShowConnectError() instruction!");
                return((IEnumerable <CodeInstruction>)codeInstructionList);
            }
            codeInstructionList.InsertRange(lastIndex, (IEnumerable <CodeInstruction>) new CodeInstruction[5]
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, (object)VACPlugin.PluginsHash),
                new CodeInstruction(OpCodes.Ldstr, (object)VACPlugin.AntiModsKickServer.Value),
                new CodeInstruction(OpCodes.Callvirt, (object)ILPatches._uiSetText),
                new CodeInstruction(OpCodes.Ret)
            });
            if (VACPlugin.debugmode.Value)
            {
                codeInstructionList.ForEach((Action <CodeInstruction>)(x => ZLog.Log((object)string.Format("[{0}] {1} -> {2}", (object)"AntiCheat", (object)x.opcode, (object)(x.operand?.ToString() ?? "<none>")))));
            }
            return((IEnumerable <CodeInstruction>)codeInstructionList);
        }
예제 #5
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.Fermenter.IsEnabled || !Configuration.Current.Fermenter.autoDeposit)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();

            int brFalsePos = -1;

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].opcode == OpCodes.Brfalse)
                {
                    brFalsePos = i;
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldarg_0));
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldloca, 0));
                    il.Insert(++i, new CodeInstruction(OpCodes.Call, method_DropItemToNearbyChest));
                    il.Insert(++i, new CodeInstruction(OpCodes.Brtrue, il[brFalsePos].operand));

                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply Fermenter_DelayedTap_Transpiler");

            return(instructions);
        }
예제 #6
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.Kiln.IsEnabled)
            {
                return(instructions);
            }

            int pos = -1;

            List <CodeInstruction> il = instructions.ToList();

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].opcode == OpCodes.Stloc_1)
                {
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldarg_0));
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldloc_1));
                    il.Insert(++i, new CodeInstruction(OpCodes.Call, method_PreventUsingSpecificWood));
                    pos = i;
                }
                else if (pos != -1 && il[i].opcode == OpCodes.Brfalse)
                {
                    il.Insert(++pos, new CodeInstruction(OpCodes.Brtrue, il[i].operand));
                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply Smelter_FindCookableItem_Transpiler");

            return(instructions);
        }
        public static bool ParseServerArguments_modded(FejdStartup __instance, ref bool __result)
        {
            __instance.m_minimumPasswordLength = -1;

            string location = config.Location;

            if (!location.IsNullOrWhiteSpace())
            {
                Utils.SetSaveDataPath(location);
            }

            World createWorld = World.GetCreateWorld(config.WorldName);

            string serverName = config.ServerName;
            string password   = config.Password;

            if (!helper.isPasswordValid(password, createWorld, serverName))
            {
                ZLog.LogError("Error bad password because its displayd in server/map name or seed");
                Application.Quit();

                __result = false;
                return(false);
            }

            bool publiclyVisable = config.Visable;

            ZNet.SetServer(true, true, publiclyVisable, serverName, password, createWorld);
            ZNet.ResetServerHost();
            ZSteamSocket.SetDataPort(config.ServerPort);
            SteamManager.SetServerPort(config.ServerPort);

            __result = true;
            return(false);
        }
예제 #8
0
    // Token: 0x0600107E RID: 4222 RVA: 0x00074C6C File Offset: 0x00072E6C
    private static List <DungeonDB.RoomData> SetupRooms()
    {
        GameObject[] array      = Resources.FindObjectsOfTypeAll <GameObject>();
        GameObject   gameObject = null;

        foreach (GameObject gameObject2 in array)
        {
            if (gameObject2.name == "_Rooms")
            {
                gameObject = gameObject2;
                break;
            }
        }
        if (gameObject == null || (DungeonDB.m_instance && gameObject.activeSelf))
        {
            if (DungeonDB.m_instance)
            {
                DungeonDB.m_instance.m_error = true;
            }
            ZLog.LogError("Rooms are f****d, missing _Rooms or its enabled");
        }
        List <DungeonDB.RoomData> list = new List <DungeonDB.RoomData>();

        for (int j = 0; j < gameObject.transform.childCount; j++)
        {
            Room component = gameObject.transform.GetChild(j).GetComponent <Room>();
            DungeonDB.RoomData roomData = new DungeonDB.RoomData();
            roomData.m_room = component;
            ZoneSystem.PrepareNetViews(component.gameObject, roomData.m_netViews);
            ZoneSystem.PrepareRandomSpawns(component.gameObject, roomData.m_randomSpawns);
            list.Add(roomData);
        }
        return(list);
    }
예제 #9
0
    private ZPackage LoadPlayerDataFromDisk()
    {
        string     path = Utils.GetSaveDataPath() + "/characters/" + this.m_filename + ".fch";
        FileStream fileStream;

        try
        {
            fileStream = File.OpenRead(path);
        }
        catch
        {
            ZLog.Log((object)("  failed to load " + path));
            return((ZPackage)null);
        }
        byte[] data;
        try
        {
            BinaryReader binaryReader = new BinaryReader((Stream)fileStream);
            data = binaryReader.ReadBytes(binaryReader.ReadInt32());
            binaryReader.ReadBytes(binaryReader.ReadInt32());
        }
        catch
        {
            ZLog.LogError((object)"  error loading player.dat");
            fileStream.Dispose();
            return((ZPackage)null);
        }
        fileStream.Dispose();
        return(new ZPackage(data));
    }
예제 #10
0
    // Token: 0x06000B64 RID: 2916 RVA: 0x0005260C File Offset: 0x0005080C
    private ZPackage LoadPlayerDataFromDisk()
    {
        string     text = Utils.GetSaveDataPath() + "/characters/" + this.m_filename + ".fch";
        FileStream fileStream;

        try
        {
            fileStream = File.OpenRead(text);
        }
        catch
        {
            ZLog.Log("  failed to load " + text);
            return(null);
        }
        byte[] data;
        try
        {
            BinaryReader binaryReader = new BinaryReader(fileStream);
            int          count        = binaryReader.ReadInt32();
            data = binaryReader.ReadBytes(count);
            int count2 = binaryReader.ReadInt32();
            binaryReader.ReadBytes(count2);
        }
        catch
        {
            ZLog.LogError("  error loading player.dat");
            fileStream.Dispose();
            return(null);
        }
        fileStream.Dispose();
        return(new ZPackage(data));
    }
예제 #11
0
            public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
            {
                if (!Configuration.Current.FireSource.IsEnabled || !Configuration.Current.FireSource.autoFuel)
                {
                    return(instructions);
                }

                List <CodeInstruction> il = instructions.ToList();

                for (int i = 0; i < il.Count; i++)
                {
                    if (il[i].Calls(method_ZNetView_IsOwner))
                    {
                        ++i;
                        il.Insert(++i, new CodeInstruction(OpCodes.Ldarg_0));
                        il.Insert(++i, new CodeInstruction(OpCodes.Call, method_addFuelFromNearbyChests));

                        return(il.AsEnumerable());
                    }
                }

                ZLog.LogError("Failed to apply Fireplace_UpdateFireplace_Transpiler");

                return(instructions);
            }
예제 #12
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.CraftFromChest.IsEnabled)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].Calls(method_Inventory_HaveItem)) // look for the last access to user
                {
                    il[i - 6] = new CodeInstruction(OpCodes.Ldloca, 0);
                    il[i]     = new CodeInstruction(OpCodes.Call, method_ReplaceInventoryRefByChest);
                    il.RemoveRange(i - 2, 2);
                    il.Insert(i - 2, new CodeInstruction(OpCodes.Ldarg_0));

                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply Fireplace_Interact_Transpiler");

            return(instructions);
        }
예제 #13
0
 public static void Postfix(FejdStartup __instance)
 {
     if (ZNet.GetConnectionStatus() != (ZNet.ConnectionStatus) 99)
     {
         return;
     }
     __instance.m_connectionFailedError.text = VACPlugin.AntiModsKickClient.Value;
     ZLog.LogError("Player Found with Cheats in Folder or Running.");
     ZLog.LogError("Sending player information to the server...");
     ZLog.LogError("Player disconnected from server for using improper programs...");
 }
예제 #14
0
    // Token: 0x06000940 RID: 2368 RVA: 0x00044658 File Offset: 0x00042858
    private void PkgSizeReceived(IAsyncResult res)
    {
        if (this.m_socket == null || !this.m_socket.Connected)
        {
            ZLog.LogWarning("PkgSizeReceived socket closed");
            this.Close();
            return;
        }
        int num;

        try
        {
            num = this.m_socket.GetStream().EndRead(res);
        }
        catch (Exception ex)
        {
            ZLog.LogWarning("PkgSizeReceived exception " + ex.ToString());
            this.Close();
            return;
        }
        if (num == 0)
        {
            ZLog.LogWarning("PkgSizeReceived Got 0 bytes data,closing socket");
            this.Close();
            return;
        }
        this.m_gotData         = true;
        this.m_recvSizeOffset += num;
        if (this.m_recvSizeOffset < this.m_recvSizeBuffer.Length)
        {
            int count = this.m_recvSizeBuffer.Length - this.m_recvOffset;
            this.m_socket.GetStream().BeginRead(this.m_recvSizeBuffer, this.m_recvSizeOffset, count, new AsyncCallback(this.PkgSizeReceived), this.m_socket);
            return;
        }
        int num2 = BitConverter.ToInt32(this.m_recvSizeBuffer, 0);

        if (num2 == 0 || num2 > 10485760)
        {
            ZLog.LogError("PkgSizeReceived Invalid pkg size " + num2);
            return;
        }
        this.m_lastRecvPkgSize = num2;
        this.m_recvOffset      = 0;
        this.m_lastRecvPkgSize = num2;
        if (this.m_recvBuffer == null)
        {
            this.m_recvBuffer = new byte[ZSocket2.m_maxRecvBuffer];
        }
        this.m_socket.GetStream().BeginRead(this.m_recvBuffer, this.m_recvOffset, this.m_lastRecvPkgSize, new AsyncCallback(this.PkgReceived), this.m_socket);
    }
예제 #15
0
파일: Test.cs 프로젝트: SendSi/ZLog
    private void OnGUI()
    {
        if (GUILayout.Button("双击Log时,定位在到此,且用Notepad++打开了文本内容", GUILayout.Height(40)))
        {
            ZLog.Log("我的Log");
        }
        if (GUILayout.Button("方法使用了 #if UNITY_EDITOR", GUILayout.Height(40)))
        {
            ZLog.LogError("发布时 就没有log了");
        }

        if (GUILayout.Button("方法使用了 #if UNITY_EDITOR", GUILayout.Height(40)))
        {
            ZEvent.Instance.Fire("T1", 100);
        }
    }
예제 #16
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.Fermenter.IsEnabled)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();

            int  hitCount = 0;
            bool found    = false;

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].Calls(method_GameObject_SetActive))
                {
                    hitCount++;
                }
                if (hitCount == 3)
                {
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldarg_0));
                    il.Insert(++i, new CodeInstruction(OpCodes.Call, method_AddItemFromNearbyChests));
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                ZLog.LogError("Failed to apply Fermenter_SlowUpdate_Transpiler 1");
                return(instructions);
            }
            found = false;
            for (int i = il.Count - 1; i >= 0; i--)
            {
                if (il[i].Calls(method_GameObject_SetActive))
                {
                    il.Insert(++i, new CodeInstruction(OpCodes.Ldarg_0));
                    il.Insert(++i, new CodeInstruction(OpCodes.Call, method_InvokeRPCTap));

                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply Fermenter_SlowUpdate_Transpiler 2");

            return(instructions);
        }
예제 #17
0
        public static bool Execute(HitData hit)
        {
            if (VACPlugin.AntiParams_IsEnabled.Value)
            {
                if (!VACPlugin.anti_debug_mode.Value &&
                    !VACPlugin.anti_damage_boost.Value)
                {
                    return(true);
                }

                Character senderChar = hit.GetAttacker();

                if (senderChar != null)
                {
                    if (VACPlugin.debugmode.Value)
                    {
                        ZLog.LogError("Send Char" + senderChar);
                    }
                }

                if (senderChar != null && senderChar.IsPlayer())
                {
                    ZNetPeer peer = ZNet.instance.GetPeer(senderChar.GetInstanceID());
                    if (VACPlugin.debugmode.Value)
                    {
                        ZLog.LogError("Player Detected, player:" + senderChar.GetInstanceID());
                        ZLog.LogError("Damage = " + hit.GetTotalDamage());
                    }

                    float damage = hit.GetTotalDamage();
                    if (peer != null &&
                        (!VACPlugin.admins_bypass.Value ||
                         !ZNet.instance.m_adminList.Contains(peer.m_rpc.GetSocket().GetHostName())) && damage > 1000f)
                    {
                        if (VACPlugin.debugmode.Value)
                        {
                            ZLog.LogError("Player Detected with Damage Boost.");
                        }
                        VACPlugin.toKick.Add(peer);
                    }
                }
            }
            return(true);
        }
예제 #18
0
        Heightmap.Biome AssignSwitch(string biome)
        {
            switch (biome.ToLower())
            {
            case "ashlands":
            case "ash lands":
                return(Heightmap.Biome.AshLands);

            case "blackforest":
            case "black forest":
                return(Heightmap.Biome.BlackForest);

            case "deepnorth":
            case "deep north":
                return(Heightmap.Biome.DeepNorth);

            case "meadows":
            case "meadow":
                return(Heightmap.Biome.Meadows);

            case "plains":
            case "plain":
                return(Heightmap.Biome.Plains);

            case "swamp":
            case "swamps":
                return(Heightmap.Biome.Swamp);

            case "mistlands":
            case "mistland":
            case "mist lands":
            case "mist land":
                return(Heightmap.Biome.Mistlands);

            case "mountain":
            case "mountains":
                return(Heightmap.Biome.Mountain);

            default:
                ZLog.LogError(biome + " is an incorrect biome name!");
                return(Heightmap.Biome.Meadows);
            }
        }
예제 #19
0
    // Token: 0x06000944 RID: 2372 RVA: 0x00044954 File Offset: 0x00042B54
    public void Send(ZPackage pkg)
    {
        if (pkg.Size() == 0)
        {
            return;
        }
        if (this.m_socket == null || !this.m_socket.Connected)
        {
            return;
        }
        byte[] array  = pkg.GetArray();
        byte[] bytes  = BitConverter.GetBytes(array.Length);
        byte[] array2 = new byte[array.Length + bytes.Length];
        bytes.CopyTo(array2, 0);
        array.CopyTo(array2, 4);
        this.m_sendMutex.WaitOne();
        if (!this.m_isSending)
        {
            if (array2.Length > 10485760)
            {
                ZLog.LogError("Too big data package: " + array2.Length);
            }
            try
            {
                this.m_totalSent += array2.Length;
                this.m_socket.GetStream().BeginWrite(array2, 0, array2.Length, new AsyncCallback(this.PkgSent), this.m_socket);
                this.m_isSending = true;
                goto IL_E6;
            }
            catch (Exception arg)
            {
                ZLog.Log("Handled exception in ZSocket:Send:" + arg);
                this.Close();
                goto IL_E6;
            }
        }
        this.m_sendQueue.Enqueue(array2);
IL_E6:
        this.m_sendMutex.ReleaseMutex();
    }
예제 #20
0
        public static void LoadMapDataFromDisk()
        {
            //TODO: Optimize / Improve on disk format for exploration data. (JSON?)

            if (ServerMapData == null)
            {
                return;
            }

            //Load map data
            if (File.Exists(ValheimPlusPlugin.VPlusDataDirectoryPath +
                            Path.DirectorySeparatorChar +
                            ZNet.instance.GetWorldName() + "_mapSync.dat"))
            {
                try
                {
                    string mapData = File.ReadAllText(ValheimPlusPlugin.VPlusDataDirectoryPath +
                                                      Path.DirectorySeparatorChar +
                                                      ZNet.instance.GetWorldName() + "_mapSync.dat");

                    string[] dataPoints = mapData.Split(',');

                    foreach (string dataPoint in dataPoints)
                    {
                        if (int.TryParse(dataPoint, out int result))
                        {
                            VPlusMapSync.ServerMapData[result] = true;
                        }
                    }

                    ZLog.Log($"Loaded {dataPoints.Length} map points from disk.");
                }
                catch (Exception ex)
                {
                    ZLog.LogError("Failed to load synchronized map data.");
                    ZLog.LogError(ex);
                }
            }
        }
예제 #21
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.Items.IsEnabled)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].opcode == OpCodes.Ldc_R8)
                {
                    il[i] = new CodeInstruction(OpCodes.Call, method_SetDroppedItemDestroyDuration);
                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply ItemDrop_TimedDestruction_Patch");

            return(instructions);
        }
예제 #22
0
    // Token: 0x0600092A RID: 2346 RVA: 0x000440C8 File Offset: 0x000422C8
    public void Send(ZPackage pkg)
    {
        if (pkg.Size() == 0)
        {
            return;
        }
        if (this.m_socket == null || !this.m_socket.Connected)
        {
            return;
        }
        byte[] array = pkg.GetArray();
        byte[] bytes = BitConverter.GetBytes(array.Length);
        this.m_sendMutex.WaitOne();
        if (!this.m_isSending)
        {
            if (array.Length > 10485760)
            {
                ZLog.LogError("Too big data package: " + array.Length);
            }
            try
            {
                this.m_totalSent += bytes.Length;
                this.m_socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(this.PkgSent), null);
                this.m_isSending = true;
                this.m_sendQueue.Enqueue(array);
                goto IL_DA;
            }
            catch (Exception arg)
            {
                ZLog.Log("Handled exception in ZSocket:Send:" + arg);
                this.Disconnect();
                goto IL_DA;
            }
        }
        this.m_sendQueue.Enqueue(bytes);
        this.m_sendQueue.Enqueue(array);
IL_DA:
        this.m_sendMutex.ReleaseMutex();
    }
예제 #23
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.CraftFromChest.IsEnabled)
            {
                return(instructions);
            }

            List <CodeInstruction> il = instructions.ToList();

            int thisIdx = -1;
            int callIdx = -1;

            for (int i = 0; i < il.Count; ++i)
            {
                if (il[i].opcode == OpCodes.Ldarg_0)
                {
                    thisIdx = i;
                }
                else if (il[i].Calls(method_Inventory_RemoveItem))
                {
                    callIdx = i;
                    break;
                }
            }

            if (thisIdx == -1 || callIdx == -1)
            {
                ZLog.LogError("Failed to apply Player_ConsumeResources_Transpiler");
                return(instructions);
            }
            il.RemoveRange(thisIdx + 1, callIdx - thisIdx);

            il.Insert(++thisIdx, new CodeInstruction(OpCodes.Ldloc_2));
            il.Insert(++thisIdx, new CodeInstruction(OpCodes.Ldloc_3));
            il.Insert(++thisIdx, new CodeInstruction(OpCodes.Call, method_RemoveItemsFromInventoryAndNearbyChests));

            return(il.AsEnumerable());
        }
예제 #24
0
 // Token: 0x060006F2 RID: 1778 RVA: 0x00039334 File Offset: 0x00037534
 private void SetupRandomPrefab()
 {
     if (this.m_itemPrefab == null && this.m_randomItemPrefabs.Length != 0)
     {
         int @int = this.m_nview.GetZDO().GetInt("itemPrefab", 0);
         if (@int == 0)
         {
             if (this.m_nview.IsOwner())
             {
                 PickableItem.RandomItem randomItem = this.m_randomItemPrefabs[UnityEngine.Random.Range(0, this.m_randomItemPrefabs.Length)];
                 this.m_itemPrefab = randomItem.m_itemPrefab;
                 this.m_stack      = UnityEngine.Random.Range(randomItem.m_stackMin, randomItem.m_stackMax + 1);
                 int prefabHash = ObjectDB.instance.GetPrefabHash(this.m_itemPrefab.gameObject);
                 this.m_nview.GetZDO().Set("itemPrefab", prefabHash);
                 this.m_nview.GetZDO().Set("itemStack", this.m_stack);
                 return;
             }
             return;
         }
         else
         {
             GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(@int);
             if (itemPrefab == null)
             {
                 ZLog.LogError(string.Concat(new object[]
                 {
                     "Failed to find saved prefab ",
                     @int,
                     " in PickableItem ",
                     base.gameObject.name
                 }));
                 return;
             }
             this.m_itemPrefab = itemPrefab.GetComponent <ItemDrop>();
             this.m_stack      = this.m_nview.GetZDO().GetInt("itemStack", 0);
         }
     }
 }
예제 #25
0
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            if (!Configuration.Current.Game.IsEnabled)
            {
                return(instructions);
            }

            float range = Math.Min(Configuration.Current.Game.difficultyScaleRange, 2);

            List <CodeInstruction> il = instructions.ToList();

            for (int i = 0; i < il.Count; i++)
            {
                if (il[i].opcode == OpCodes.Ldc_R4)
                {
                    il[i].operand = range;
                    return(il.AsEnumerable());
                }
            }

            ZLog.LogError("Failed to apply Game_GetPlayerDifficulty_Patch.Transpiler");

            return(instructions);
        }
예제 #26
0
 private static void Postfix(ref ZNet __instance)
 {
     if (!((UnityEngine.Object)ZNet.instance != (UnityEngine.Object)null))
     {
         return;
     }
     if (ZNet.instance.IsServer() && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Null && (Player.m_players != null && Player.m_players.Count > 0))
     {
         foreach (Player player in Player.m_players)
         {
             ZNetPeer peerByPlayerName = ZNet.instance.GetPeerByPlayerName(player.name);
             if ((player.m_debugFly || player.m_noPlacementCost && VACPlugin.anti_debug_mode.Value) && (peerByPlayerName != null && !ZNet.instance.m_adminList.Contains(peerByPlayerName.m_rpc.GetSocket().GetHostName())))
             {
                 VACPlugin.toKick.Add(peerByPlayerName);
             }
             if (player.m_godMode && VACPlugin.anti_god_mode.Value && (peerByPlayerName != null && !ZNet.instance.m_adminList.Contains(peerByPlayerName.m_rpc.GetSocket().GetHostName())))
             {
                 VACPlugin.toKick.Add(peerByPlayerName);
             }
         }
     }
     if (ZNet.instance.m_peers.Count > 0)
     {
         foreach (ZNetPeer peer in ZNet.instance.m_peers)
         {
             if (VACPlugin.posMap[peer] == Vector3.zero)
             {
                 VACPlugin.posMap[peer] = peer.m_refPos;
             }
             else if (VACPlugin.anti_fly.Value)
             {
                 if (!ZNet.instance.m_adminList.Contains(peer.m_rpc.GetSocket().GetHostName()) && (double)Math.Abs(peer.m_refPos.x - VACPlugin.posMap[peer].x) > 15.0 || (double)Math.Abs(peer.m_refPos.y - VACPlugin.posMap[peer].y) > 15.0 || (double)Math.Abs(peer.m_refPos.y - VACPlugin.posMap[peer].y) > 15.0)
                 {
                     VACPlugin.toKick.Add(peer);
                 }
                 else
                 {
                     VACPlugin.posMap[peer] = peer.m_refPos;
                 }
             }
             if (peer.IsReady() && !peer.m_characterID.IsNone() && (ZNet.instance.m_zdoMan.GetZDO(peer.m_characterID).GetBool("DebugFly") && !ZNet.instance.m_adminList.Contains(peer.m_rpc.GetSocket().GetHostName())))
             {
                 VACPlugin.toKick.Add(peer);
             }
         }
     }
     if (VACPlugin.toKick.Count <= 0)
     {
         return;
     }
     foreach (ZNetPeer znetPeer in VACPlugin.toKick)
     {
         if (!VACPlugin.admins_bypass.Value || !ZNet.instance.m_adminList.Contains(znetPeer.m_rpc.GetSocket().GetHostName()))
         {
             if (VACPlugin.ban_on_trigger.Value)
             {
                 ZLog.LogError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! BAN");
                 __instance.Ban(znetPeer.m_playerName);
                 ZLog.LogWarning("Jogador: " + znetPeer.m_playerName + znetPeer.m_uid + znetPeer.m_characterID + " Banido por uso de Cheats.");
             }
             else
             {
                 ZLog.LogError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KICK");
                 __instance.Kick(znetPeer.m_playerName);
                 ZLog.LogWarning("Jogador" + znetPeer.m_playerName + znetPeer.m_uid + znetPeer.m_characterID + " Kickado por uso de Cheats.");
             }
         }
     }
     VACPlugin.toKick.Clear();
 }
예제 #27
0
파일: VAC.cs 프로젝트: fclante/VAC
        public static void AntiMods()
        {
            PluginsHash = VAC.AntiMods.HashAlgorithmExtensions.CreateMd5ForFolder(Paths.PluginPath);
            ZLog.Log((object)("[AntiMods]: Computed hash: " + PluginsHash));
            if (Paths.ProcessName.Equals("valheim_server", StringComparison.OrdinalIgnoreCase))
            {
                MethodInfo methodInfo = AccessTools.Method(typeof(ZNet), "RPC_PeerInfo", new System.Type[2]
                {
                    typeof(ZRpc),
                    typeof(ZPackage)
                });

                if ((object)methodInfo == null)
                {
                    ZLog.LogError((object)"[AntiMods] Could not find ZNet:RPC_PeerInfo");
                    return;
                }

                harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(AccessTools.Method(
                                                                            typeof(AntiMods.GamePatches.ZNet_RPC_PeerInfoPatch), "Prefix", new System.Type[3]
                {
                    typeof(ZNet).MakeByRefType(),
                    typeof(ZRpc),
                    typeof(ZPackage)
                })));

                ZLog.Log((object)"[AntiMods] Patched server!");
            }
            else
            {
                MethodInfo methodInfo1 = AccessTools.Method(typeof(ZNet), "RPC_PeerInfo", new System.Type[2]
                {
                    typeof(ZRpc),
                    typeof(ZPackage)
                });
                if ((object)methodInfo1 == null)
                {
                    ZLog.LogError((object)"[AntiMods] Could not find ZNet:RPC_PeerInfo");
                    return;
                }

                MethodInfo methodInfo2 = AccessTools.Method(typeof(ZNet), "SendPeerInfo", new System.Type[2]
                {
                    typeof(ZRpc),
                    typeof(string)
                });
                if ((object)methodInfo2 == null)
                {
                    ZLog.LogError((object)"[AntiMods] Could not find ZNet:SendPeerInfo");
                    return;
                }

                harmony.Patch((MethodBase)methodInfo2, transpiler: new HarmonyMethod(AccessTools.Method(
                                                                                         typeof(AntiMods.ILPatches), "SendPeerInfo_Transpile", new System.Type[1]
                {
                    typeof(IEnumerable <CodeInstruction>)
                })));
                harmony.Patch((MethodBase)methodInfo1,
                              postfix: new HarmonyMethod(
                                  AccessTools.Method(typeof(AntiMods.GamePatches.ZNet_RPC_PeerInfoPatch), "Postfix")));
                ZLog.Log((object)"[AntiMods] Patched client!");
            }

            if (PluginsHash != "")
            {
                ZLog.LogWarning((object)VACPlugin.AntiModsActivated.Value);
            }
            else
            {
                ZLog.LogError(VACPlugin.AntiModsError.Value);
            }
        }