1. There is anyway to detect if the server was wipe, i mean a new world has been generated?
    Like if i delete the /save/ folder or the files on the /save/ folder.

    Like a hook or library?
     
  2. The loading and saving is all handled by the SaveRestore class, this class does not offer any methods we can use to check if a file exists which requires us to use the Systems.IO namespace for file operations (File.Exists). However we cannot use the Systems.IO namespace in Lua plugins so I'm afraid something like this is currently not possible (unless I missed something in the server files).

    Maybe someone could add a method to the Oxide Rust extension to check for the file or something and return true or false or something, as I can see the use of this to restore players with certain items after a wipe, or do certain other plugin actions after a wipe.
     
  3. I noticed the server generates a hash of the save file on startup. Any way we can access that information or add a hook to do so? Then you could check to see if the hash generated matches the previous one, unless the hash changes depending on structures/save data other than the world terrain information itself.
     
  4. You can add hook to SaveRestore::Load
     
  5. I ran the Oxide 2 Patcher and it listed a lot of hooks, and none have anything to do with SaveRestore.

    Where exactly you saw that hook? And what is the hook name?

    Anyway by the way you described it, I don't think that it would help detect if the server was wiped anyway.
     
  6. This is a list of already made hooks.
    In the program, go to the Assemblies -> Global -> SaveRestore (double click)
    In the new list, find and click on the 'public static void Load (string strFilename, bool allowOutOfDateSaves)' then click button 'Hook This Method'.
    You need to change 'Hook Settings'. Injection Index (line from MSIL Before) - the place where the method is to call the hook.
    Return Behavior - i think for you it 'Continue' and Argument Behaviour - All.
    Then press button 'Apply Changes'. If it's ok then press 'Patch' button from menu. And restart server.
    Now you can hook it in plugin by 'Hook Name'.

    P.S: This changes the Assembly-CSharp.dll, so that the plugin works on other servers must also replace their Assembly-CSharp.dll with a new one.
     
  7. So to i use that game hook, i need create a hook to patch the oxide to allow my plugin to use a custom hook.
    So would need distribute a custom oxide with the plugin, That does not seams very practical, And i would need to re-patch every time a oxide update is out.
     
  8. Wulf

    Wulf Community Admin

    Plugins shouldn't be distributing custom DLLs, and we generally do not allow that here. If a hook is PRed, we may pull it if it is appropriate.
     
  9. Indeed, that is not very viable.

    But would be a good thing if you guys gives us a way to detect if the server was wiped, Like a way to detect the date that the save was created or something like that.

    A lot of plugins could be benefited if we could determinate if the server was wiped.
     
  10. This is useful if you do only plugin for your server. Or you need to ask and wait for the new add hooks into Oxide by its author.
     
  11. So if we cant detect if the server was wiped, there is anyway to save a .txt file outside data folder and into save folder? So we can emulate a server wipe detection.
     
  12. Wulf

    Wulf Community Admin

    Not from a Lua plugin, but you could with a C# extension.
     
  13. So back to dlls, Damn it. :(
     
  14. does the server.seed or server.level fields change after a wipe?
     
  15. Wulf

    Wulf Community Admin

    Pretty sure there is a default seed, and most override that seed, so likely no for both.
     
  16. I'm working on hooking SaveRestore::Load() at the moment. Right now, the hook looks like this in the dll:

    Modified SaveRestore.Load() snippet:
    Code:
      Save save = null;
    try
    {
         save = Save.Deserialize(buffer);
    }
         catch (InvalidDataException)
    {
         Debug.LogWarning("This save is incompatible. Sorry.");
         return;
    }
    Save arg_EB_0 = save;
    Interface.CallHook("OnLoad", new object[]
    {
         save
    });
    if (arg_EB_0.protocol != 20)
    {
    if (!allowOutOfDateSaves)
    {
    Debug.LogWarning("This save is from an older version - and is incompatible.. sorry!");
    return;
    }
    Debug.LogWarning("This save is from an older (possibly incompatible) version!");
    }
    
    I'm still working on the placement, but it gets passed 'save' which is of type ProtoBuf.Save, so the save.worldchecksum string should be visible at that point. If it works properly, I'll submit a PR for the hook.
    [DOUBLEPOST=1421376904,1421363724][/DOUBLEPOST]LOL. Just noticed that the current experimental version of ProtoBuf.Save does NOT contain the worldchecksum string. I was using the latest dev version when I was at work earlier. Just got home and was taking a look at it using the current non-dev version and it doesn't have that variable. OOPS! Well... I'll continue working on it once this dev version moves to the current release. Should be pretty straightforward from there. Store the current world checksum in the plugin config by using the OnLoad hook I'm working on and getting the string from save.worldchecksum. If the checksum does not match the current World.checksum when the "OnLoad" hook is called, then the world data has changed (most likely meaning a wipe due to incompatible versions). In the meantime, I don't really want to take the time to figure out another method when it is most likely going to become obsolete in the very near future.
     
  17. Сall in this place already load save world:
    UnityEngine.Debug.Log("Loading Save From " + strFilename);

    Hook after this line enough. Like 'OnLoadSuccessfully'
     
  18. Like I mentioned above, the checksums are not available in the current version (not where I was looking for them anyway). It'll be much easier to do after the next update and I'll submit a pull request for the oxide patcher at that time to get the hook added into the official version of Oxide so after that, custom hooks and custom DLL's won't be necessary.