Wallpaper entity rule

Hi,

 

I have been using TruePVE from long time now,

I have never had this issue with other entities in the past, so I was wondering why the " wallpaper " entity rules does not work when asking the plugin to add it to nothing can hurt?

 

Here my config:

 

"nothing can hurt wallpaper",

 

{
"name": "wallpaper",
"members": "wallpaper",
"exclusions": ""
}

 

Display NameShort NameItem IDDescriptionStacksize
Wallpaperwallpaper-1501434104Transform your base from a rusty shack to a cozy hideout with this sleek wallpaper. A nice touch of style - until the next raid, at least.10

 

Thank you in advance

heya. wallpaper is not an entity (and you are trying to reference an item instead of an entity). it is part of the building block/wall. the necessary hooks are not implemented to block all forms of damage to wallpaper. harmony patches can be used until then.

save as WallpaperMax.cs

using HarmonyLib;
using System;
using System.Reflection;

namespace Oxide.Plugins
{
    [Info("Wallpaper Max", "nivex", "0.1.4")]
    [Description("Prevents wallpapers from being destroyed.")]
    class WallpaperMax : RustPlugin
    {
        private Harmony _harmony;

        private void Loaded()
        {
            _harmony = new Harmony(Name + "Patch");
            ApplyPatches();
        }

        private void Unload()
        {
            if (_harmony != null)
            {
                _harmony.UnpatchAll(_harmony.Id);
            }
        }

        private void ApplyPatches()
        {
            MethodInfo checkWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "CheckWallpaper", parameters: Type.EmptyTypes);
            if (ValidateMethod(checkWallpaperMethod, "CheckWallpaper", typeof(void), Type.EmptyTypes))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_CheckWallpaper), "Prefix");
                if (patch != null)
                {
                    _harmony.Patch(checkWallpaperMethod, new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Prefix method for CheckWallpaper patch.");
                }
            }

            MethodInfo setWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "SetWallpaper", new Type[] { typeof(ulong), typeof(int) });
            if (ValidateMethod(setWallpaperMethod, "SetWallpaper", typeof(void), new Type[] { typeof(ulong), typeof(int) }))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_SetWallpaper), "Postfix");
                if (patch != null)
                {
                    _harmony.Patch(setWallpaperMethod, postfix: new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Postfix method for SetWallpaper patch.");
                }
            }

            MethodInfo damageWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "DamageWallpaper", new Type[] { typeof(float), typeof(int) });
            if (ValidateMethod(damageWallpaperMethod, "DamageWallpaper", typeof(void), new Type[] { typeof(float), typeof(int) }))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_DamageWallpaper), "Prefix");
                if (patch != null)
                {
                    _harmony.Patch(damageWallpaperMethod, new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Prefix method for DamageWallpaper patch.");
                }
            }
        }

        private bool ValidateMethod(MethodInfo method, string methodName, Type expectedReturnType, Type[] expectedParameters)
        {
            if (method == null)
            {
                Puts($"Failed to find {methodName} method.");
                return false;
            }

            if (method.ReturnType != expectedReturnType)
            {
                Puts($"Method {methodName} has unexpected return type. Expected: {expectedReturnType}, Found: {method.ReturnType}");
                return false;
            }

            var parameters = method.GetParameters();
            if (parameters.Length != expectedParameters.Length)
            {
                Puts($"Method {methodName} has unexpected number of parameters. Expected: {expectedParameters.Length}, Found: {parameters.Length}");
                return false;
            }

            for (int i = 0; i < expectedParameters.Length; i++)
            {
                if (parameters[i].ParameterType != expectedParameters[i])
                {
                    Puts($"Parameter {i} of method {methodName} has unexpected type. Expected: {expectedParameters[i]}, Found: {parameters[i].ParameterType}");
                    return false;
                }
            }

            return true;
        }

        internal class BuildingBlock_CheckWallpaper
        {
            private static bool Prefix(BuildingBlock __instance) => false; // prevent the server from destroying the wallpaper when it is outside
        }

        internal class BuildingBlock_SetWallpaper
        {
            private static void Postfix(ulong id, int side, BuildingBlock __instance) // give the wallpaper max additional health
            {
                if (__instance != null && __instance.HasWallpaper())
                {
                    if (side == 0)
                        __instance.wallpaperHealth = int.MaxValue;
                    else
                        __instance.wallpaperHealth2 = int.MaxValue;
                }
            }
        }

        internal class BuildingBlock_DamageWallpaper // block damage to the wallpaper
        {
            private static bool Prefix(float totalDamage, int side, BuildingBlock __instance)
            {
                if (__instance != null && __instance.HasWallpaper(side))
                {
                    return false; // you could use protection properties but that won't block everything.
                }
                return true;
            }
        }
    }
}​
nivex

heya. wallpaper is not an entity (and you are trying to reference an item instead of an entity). it is part of the building block/wall. the necessary hooks are not implemented to block all forms of damage to wallpaper. harmony patches can be used until then.

save as WallpaperMax.cs

using HarmonyLib;
using System;
using System.Reflection;

namespace Oxide.Plugins
{
    [Info("Wallpaper Max", "nivex", "0.1.4")]
    [Description("Prevents wallpapers from being destroyed.")]
    class WallpaperMax : RustPlugin
    {
        private Harmony _harmony;

        private void Loaded()
        {
            _harmony = new Harmony(Name + "Patch");
            ApplyPatches();
        }

        private void Unload()
        {
            if (_harmony != null)
            {
                _harmony.UnpatchAll(_harmony.Id);
            }
        }

        private void ApplyPatches()
        {
            MethodInfo checkWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "CheckWallpaper", parameters: Type.EmptyTypes);
            if (ValidateMethod(checkWallpaperMethod, "CheckWallpaper", typeof(void), Type.EmptyTypes))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_CheckWallpaper), "Prefix");
                if (patch != null)
                {
                    _harmony.Patch(checkWallpaperMethod, new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Prefix method for CheckWallpaper patch.");
                }
            }

            MethodInfo setWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "SetWallpaper", new Type[] { typeof(ulong), typeof(int) });
            if (ValidateMethod(setWallpaperMethod, "SetWallpaper", typeof(void), new Type[] { typeof(ulong), typeof(int) }))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_SetWallpaper), "Postfix");
                if (patch != null)
                {
                    _harmony.Patch(setWallpaperMethod, postfix: new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Postfix method for SetWallpaper patch.");
                }
            }

            MethodInfo damageWallpaperMethod = AccessTools.Method(typeof(BuildingBlock), "DamageWallpaper", new Type[] { typeof(float), typeof(int) });
            if (ValidateMethod(damageWallpaperMethod, "DamageWallpaper", typeof(void), new Type[] { typeof(float), typeof(int) }))
            {
                var patch = AccessTools.Method(typeof(BuildingBlock_DamageWallpaper), "Prefix");
                if (patch != null)
                {
                    _harmony.Patch(damageWallpaperMethod, new HarmonyMethod(patch));
                }
                else
                {
                    Puts("Failed to find Prefix method for DamageWallpaper patch.");
                }
            }
        }

        private bool ValidateMethod(MethodInfo method, string methodName, Type expectedReturnType, Type[] expectedParameters)
        {
            if (method == null)
            {
                Puts($"Failed to find {methodName} method.");
                return false;
            }

            if (method.ReturnType != expectedReturnType)
            {
                Puts($"Method {methodName} has unexpected return type. Expected: {expectedReturnType}, Found: {method.ReturnType}");
                return false;
            }

            var parameters = method.GetParameters();
            if (parameters.Length != expectedParameters.Length)
            {
                Puts($"Method {methodName} has unexpected number of parameters. Expected: {expectedParameters.Length}, Found: {parameters.Length}");
                return false;
            }

            for (int i = 0; i < expectedParameters.Length; i++)
            {
                if (parameters[i].ParameterType != expectedParameters[i])
                {
                    Puts($"Parameter {i} of method {methodName} has unexpected type. Expected: {expectedParameters[i]}, Found: {parameters[i].ParameterType}");
                    return false;
                }
            }

            return true;
        }

        internal class BuildingBlock_CheckWallpaper
        {
            private static bool Prefix(BuildingBlock __instance) => false; // prevent the server from destroying the wallpaper when it is outside
        }

        internal class BuildingBlock_SetWallpaper
        {
            private static void Postfix(ulong id, int side, BuildingBlock __instance) // give the wallpaper max additional health
            {
                if (__instance != null && __instance.HasWallpaper())
                {
                    if (side == 0)
                        __instance.wallpaperHealth = int.MaxValue;
                    else
                        __instance.wallpaperHealth2 = int.MaxValue;
                }
            }
        }

        internal class BuildingBlock_DamageWallpaper // block damage to the wallpaper
        {
            private static bool Prefix(float totalDamage, int side, BuildingBlock __instance)
            {
                if (__instance != null && __instance.HasWallpaper(side))
                {
                    return false; // you could use protection properties but that won't block everything.
                }
                return true;
            }
        }
    }
}​

After the recent update, the explosion can damage the wallpaper, is there a way to fix it?

hi, it will be in the next update

nivex

hi, it will be in the next update

Hi, where can I get the latest version?

You can get the latest version from the plugin page.

You will need to wait if you want the next version.