[How do I?] replace client functions without breaking forward compatibility

syntronikssyntroniks Join Date: 2012-10-18 Member: 162662Members
edited October 2012 in Modding
Hello, unfortunately this is my first post. I've been in the pre-release for quite some time now and I am so happy with how far the game has come in just one year!!

To my question/situation:
I am able to replace existing classes and edit functionality -- that is fine, but I feel that when the game development progresses, some things I rely on may break in the future.

For an example, let's say I want to subclass the player and implement different functionality for one of the methods, say
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Player:GetCanClimb()
    return true
end<!--c2--></div><!--ec2-->
and I want to force players to be ground-dwellers by removing their ability to climb anything.

<b>Can I do this in a separate file for just the changed functions?</b> Can I subclass the player/marine/alien and override that function without copying and pasting code from the current release (potentially requiring a mod update every time the game updates)

I hope this was clear, thank you for any help you can provide.

Comments

  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    Use the hooking function!

    Example from the SoulCatcherMod:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script.Load("lua/Class.lua")
    Script.Load("lua/Player_Client.lua")

    local kSoulEffect = PrecacheAsset("cinematics/soul.cinematic")

    local originalPlayerOnKillClient

    originalPlayerOnKillClient = Class_ReplaceMethod( "Player", "OnKillClient",
        function(self)

            local cinematic = Client.CreateCinematic(RenderScene.Zone_Default)
            cinematic:SetCinematic(kSoulEffect)
            cinematic:SetCoords(self:GetCoords())
            
            originalPlayerOnKillClient(self)
            
        end
    )<!--c2--></div><!--ec2-->
  • VitdomVitdom Join Date: 2012-04-30 Member: 151345Members, Reinforced - Supporter, Reinforced - Silver, Reinforced - Gold, Reinforced - Diamond, Reinforced - Shadow, WC 2013 - Shadow
    edited October 2012
    Hooking a method manually is very good practice! It also ensures mods' compatibility with OTHER mods.
  • syntronikssyntroniks Join Date: 2012-10-18 Member: 162662Members
    edited October 2012
    After re-reading, I wanted to delete this post, but I couldn't find that on the forum options!

    Having this much lua inside a game is as interesting & fun as it is confusing at times :O
    [I'm slowly making headway]
  • MaxMax Technical Director, Unknown Worlds Entertainment Join Date: 2002-03-15 Member: 318Super Administrators, Retired Developer, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, Subnautica Developer, Pistachionauts, Future Perfect Developer
    In addition to the suggestions posted here, there is a new feature coming in 224 where a mod can specify which version of the game code it requires. When the mod is loaded, that version of the game code will be loaded alongside it. This way you don't have to worry about changes breaking your mod.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    <!--quoteo(post=1993739:date=Oct 19 2012, 04:06 PM:name=Max)--><div class='quotetop'>QUOTE (Max @ Oct 19 2012, 04:06 PM) <a href="index.php?act=findpost&pid=1993739"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->In addition to the suggestions posted here, there is a new feature coming in 224 where a mod can specify which version of the game code it requires. When the mod is loaded, that version of the game code will be loaded alongside it. This way you don't have to worry about changes breaking your mod.<!--QuoteEnd--></div><!--QuoteEEnd-->

    This is what I have been waiting for!!!

    Thank You. The only questions is, does this only start with build 224? Or can we go back a couple versions to resurrect our currently broken mods without updates? I have 2 big mods, and a number of smaller mods, so making these constant changes has meant only 1 mod getting updated per build :P

    Hard to build a playerbase when the mod only works every other NS2 release, hahah :D
  • JibrailJibrail Join Date: 2009-04-16 Member: 67200Members
    awsome work Max I know our mod collective programmers have been waiting long time for this one.
  • MCMLXXXIVMCMLXXXIV Join Date: 2010-04-14 Member: 71400Members
    Wow.. This is great news! Thanks for all your hard work on the mod support everyone at UWE - I think we'll definitely be taking advantage of this feature...
  • syntronikssyntroniks Join Date: 2012-10-18 Member: 162662Members
    This is great news, things are working together nicely, but I've come up against a prediction barrier.
    Suppose I want to write something on the client that alters input. In other words, something that could mask a jump clientside so you can not jump as often.

    Normally I'd just input.commands = bit.band(input.commands, bit.bnot(Move.Jump))
    But it looks like the input is getting to the server unmodified and prediction is overwriting what I want to do.

    Where/how is the correct way/place to modify/mask user input clientside?
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    You need todo it in the entitys OverrideInput function on the client
  • syntronikssyntroniks Join Date: 2012-10-18 Member: 162662Members
    edited October 2012
    I've only made slight progress. I am able to hook this function, but it seems to not be called.
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local originalScriptActorOverrideInput
    originalScriptActorOverrideInput= Class_ReplaceMethod( "ScriptActor", "OverrideInput",
        function(self, input)
        Shared.Message("OverrideInput called!")
            originalScriptActorOverrideInput(self, input)
        end
    )<!--c2--></div><!--ec2-->
    In console, there is no output and changing the contents of this function does nothing. The "ReplaceMethodInDerivedClasses" function DOES iterate over all child classes so that seems in order. I could not find references in the lua files for something that calls OverrideInput at the player level (aside from its children).

    Using the handy find . | xargs grep 'searchstring' to scour /ns2/lua
    {btw: TY}
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    Replacing it in ScriptActor won't work because it overridden in Player and more derived class's.

    Class_ReplaceMethod won't replace the function in child class's if its been overrided in child class's
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local function ReplaceMethodInDerivedClasses(className, methodName, method, original)

        if _G[className][methodName] ~= original then
            return
        end<!--c2--></div><!--ec2-->
  • WilsonWilson Join Date: 2010-07-26 Member: 72867Members
    <!--quoteo(post=1993739:date=Oct 19 2012, 04:06 PM:name=Max)--><div class='quotetop'>QUOTE (Max @ Oct 19 2012, 04:06 PM) <a href="index.php?act=findpost&pid=1993739"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->In addition to the suggestions posted here, there is a new feature coming in 224 where a mod can specify which version of the game code it requires. When the mod is loaded, that version of the game code will be loaded alongside it. This way you don't have to worry about changes breaking your mod.<!--QuoteEnd--></div><!--QuoteEEnd-->

    How do I specify the version I want my mod to use?
  • MaxMax Technical Director, Unknown Worlds Entertainment Join Date: 2002-03-15 Member: 318Super Administrators, Retired Developer, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, Subnautica Developer, Pistachionauts, Future Perfect Developer
    <!--quoteo(post=1996877:date=Oct 25 2012, 05:47 AM:name=Wilson)--><div class='quotetop'>QUOTE (Wilson @ Oct 25 2012, 05:47 AM) <a href="index.php?act=findpost&pid=1996877"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->How do I specify the version I want my mod to use?<!--QuoteEnd--></div><!--QuoteEEnd-->
    It is in the publisher UI. I'm not going to start including the archived builds until the final release though, since so much is still in flux with the SDK at the moment that it wouldn't work anyway (since the SDK isn't versioned, only the game code).
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited October 2012
    Max, my mods are changing so much, I don't upload them to the workshop to test them. Can you advise how I'd take advantage of this while my mods are in non-published state? Is there a command line parameter such as -version that can be used?

    I understand it's not available yet....
  • MaxMax Technical Director, Unknown Worlds Entertainment Join Date: 2002-03-15 Member: 318Super Administrators, Retired Developer, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, Subnautica Developer, Pistachionauts, Future Perfect Developer
    <!--quoteo(post=1996926:date=Oct 25 2012, 07:00 AM:name=Soul_Rider)--><div class='quotetop'>QUOTE (Soul_Rider @ Oct 25 2012, 07:00 AM) <a href="index.php?act=findpost&pid=1996926"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Max, my mods are changing so much, I don't upload them to the workshop to test them. Can you advise how I'd take advantage of this while my mods are in non-published state? Is there a command line parameter such as -version that can be used?

    I understand it's not available yet....<!--QuoteEnd--></div><!--QuoteEEnd-->
    That would be an interesting feature even outside of the context of mods (since you could go back and play older builds). I will discuss it with the team.
Sign In or Register to comment.