Permissions do not work properlySolved

First in

public void IndexSkins()
            {
                IndexedSkins.Clear();

                foreach (var item in Skins)
                {
                    
                    if (!string.IsNullOrEmpty(item.Permission) && !_ins.permission.PermissionExists(item.Permission))
                        _ins.permission.RegisterPermission(item.Permission, _ins);
​

_ins is null.  there comes always a NullReferenceException

I have added the following line to the LoadConfig function that it work

_ins = this;

But the rights are not synchronized, I have to reload the plugin every time.

 

hope the description helps :)

br Bacardi Adi

hey, thank you for the report!

Merged post

what do you mean by "not synchronized"?

BacardiAdi means that the plugin must be unloaded and reloaded again for the specified skin permissions to start working as expected.

It is kind of similar to the other error where every time a skin is added using the "/skin add" command that the plugin breaks and you get an error in the server console when trying to skin an item using the /skin command as reported here. Each time a skin is added, an admin with console access needs to reload the Skins plugin manually for this plugin to start working again or this error will not go away.

it was fixed anyways wasn't it

Actually no, this is still not fixed. I'm using the latest version (2.2.2) of this plugin and just tested the skin permissions again, and it is still a problem, and actually its worse than described in the first post of this thread because of how both bugs actually complement each other, it still breaks the plugin completely, preventing any further skinning of items until the plugin is reloaded.

Let me try and describe the steps to both bugs in much more detail than in any other posts I've seen about this.
For this example we're gonna start fresh (deleted Skins.json so it gets recreated) and use the Armored Double Door item:
1. Add the skin through the RustAdmin console: skin add door.double.hinged.toptier 2413395186 skins.category.workshop
2. Console displays: Skin was successfully added.
3. Go back to Rust client and type /skin in the chat (so that the skin UI will open)
4. Put the Armored Double Door in the skin slot
5. No available skins show up at all and in the RustAdmin console the following error shows up:

Failed to call hook 'OnItemAddedToContainer' on plugin 'Skins v2.2.2' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.Skins+ContainerController.DrawUI (System.Int32 page) [0x0003f] in <8a8abffda52e420f9f8e695d8a71c2e7>:0
at Oxide.Plugins.Skins+ContainerController.UpdateContent (System.Int32 page) [0x00205] in <8a8abffda52e420f9f8e695d8a71c2e7>:0
at Oxide.Plugins.Skins.OnItemAddedToContainer (ItemContainer itemContainer, Item item) [0x000a2] in <8a8abffda52e420f9f8e695d8a71c2e7>:0
at Oxide.Plugins.Skins.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002f3] in <8a8abffda52e420f9f8e695d8a71c2e7>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <60c318df79ed41688ea59335e48d61ad>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <9882f28dc2204b4dba514a9ad18f5042>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <9882f28dc2204b4dba514a9ad18f5042>:0
6. To temporarily fix this error we need to reload the plugin: oxide.reload Skins
7. Observe a new error in the console now because we specified a permission in the "skin add" command in step 1:
Unloaded plugin Skins v2.2.2 by misticos
[Skins] Your configuration file contains an error. Using default configuration values.
Loaded plugin Skins v2.2.2 by misticos
8. This error is now appearing because we specified the "skins.category.workshop" permission in the "skin add" command earlier in step 1
9. The first post of this thread by BacardiAdi says to add this code to the plugin to fix the error message in step 7:
_ins = this;​

Since it wasn't specified exactly where in LoadConfig() to put this line I did it like this:

@@ -210,7 +210,8 @@
                 _config = Config.ReadObject<Configuration>();
                 if (_config == null) throw new Exception();
                 SaveConfig();
-                
+
+                _ins = this;
                 _config.IndexSkins();
             }
             catch
This indeed makes the error not appear anymore
10. I applied this code change to Skins.cs and the plugin was reloaded with the following message:
Unloaded plugin Skins v2.2.2 by misticos
[Skins] Item with shortname "shortname" does not exist. Please review your Skins configuration.
Loaded plugin Skins v2.2.2 by misticos
11. Observe that the error from step 7 is no longer appearing, thus seemingly fixing that specific error.
12. Now we assign the permission to ourselves: oxide.grant user HoRRoRiST skins.category.workshop
13. Now we try to skin the Armored Double Door again, type /skin in the chat and put the item in the skin slot
14. Observe that no available skins show up at all but also no error appears in the server console this time
15. To fix the skins not showing up we reload the plugin again: oxide.reload Skins
16. We try to skin it again and this time the available skin does shows up and now we can skin it without a problem
17. Now we add a new skin using the RustAdmin console: skin add door.double.hinged.toptier 2097638599 skins.category.workshop
18. Now we try to skin it again but now the error from step 5 shows up again:
Failed to call hook 'OnItemAddedToContainer' on plugin 'Skins v2.2.2' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.Skins+ContainerController.DrawUI (System.Int32 page) [0x0003f] in <7354a749baab4d3e9396eb1c900be1d9>:0
at Oxide.Plugins.Skins+ContainerController.UpdateContent (System.Int32 page) [0x00205] in <7354a749baab4d3e9396eb1c900be1d9>:0
at Oxide.Plugins.Skins.OnItemAddedToContainer (ItemContainer itemContainer, Item item) [0x000a2] in <7354a749baab4d3e9396eb1c900be1d9>:0
at Oxide.Plugins.Skins.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002f3] in <7354a749baab4d3e9396eb1c900be1d9>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <60c318df79ed41688ea59335e48d61ad>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <9882f28dc2204b4dba514a9ad18f5042>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <9882f28dc2204b4dba514a9ad18f5042>:0
19. Reload the plugin once again to fix the above error: oxide.reload Skins
20. Now all the available skins show up again when trying to skin the item

I hope this helps in getting both of these bugs fixed. If you need any further information or testing, please let me know.

Merged post

Follow-up of my previous post.

Note that removing a skin also results in the OnItemAddedToContainer error being shown in the server console and thus also breaks the plugin.

In the meantime I merged some more code changes from this thread by @ProNoob in an attempt to fix the OnItemAddedToContainer error.
Although that thread was only about fixing the error for adding skins, I also added the same code to the removing-part of the code, because it needed the same fix as well.

This is the full diff after merging the changes from both this thread and that thread:
--- Skins.cs.orig       2021-08-02 17:53:09.000000000 +0200
+++ Skins.cs 2021-12-21 02:55:34.138341075 +0100
@@ -210,7 +210,8 @@
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
SaveConfig();
-
+
+ _ins = this;
_config.IndexSkins();
}
catch
@@ -773,6 +774,10 @@
player.Reply(GetMsg("Skin Removed", player.Id));

SaveConfig();
+
+ GenerateUI();
+ PurgeAllCache();
+
break;
}

@@ -829,6 +834,10 @@
}

SaveConfig();
+
+ GenerateUI();
+ PurgeAllCache();
+
break;
}

@@ -1354,6 +1363,16 @@

private string GetMsg(string key, string userId = null) => lang.GetMessage(key, this, userId);

+ private void PurgeAllCache()
+ {
+ foreach (BasePlayer basePlayer in BasePlayer.activePlayerList) {
+ ContainerController container;
+ if (!_controllers.TryGetValue(basePlayer.userID, out container))
+ break;
+ container.TotalSkinsCache.Clear();
+ }
+ }
+
#endregion
}
-}
\ No newline at end of file
+}

The end result of all of these changes is that no error occurs anymore when adding or removing a skin.

However, if you add a new skin with a new not-yet-existing permission, you will still need to reload the plugin, because it seems that the Skins plugin isn't taking this into account and thus won't show the skins with that permission in the list of available skins, even if that person has the permission to access those skins. It also does not show any error in the console when this is happening. A reload of the plugin fixes this. This is actually what this thread is originally about, by the way.

indeed i do not think that it takes into account if a perm does not exist. also, if the perm exists, remember to purge the cache with the commands

Locked automatically