MOD works in unity, not stand alone

Show off your mod creations or just a work in progress.
l3lessed
Posts: 1406
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

MOD works in unity, not stand alone

Post by l3lessed »

So, I tested the dodge mod in the unity builder, and it seemed to be working and ready to go. I compile it, transfer it to DFU standalone, launch a game, and nothing.

For some reason, DFU standalone does not load the mod, but the unity builder will. Any ideas on what is going on? I'll drop the code below. I must be accessing something that is within the builder, but not within the stand alone game, right?

any assists would be helpful.

Code: Select all

using UnityEngine;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Utility.ModSupport;   //required for modding features
using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings;
using System.Collections;

namespace DaggerfallWorkshop.Game.DodgeMod
{
    public class DodgeMod : MonoBehaviour
    {
        //sets up script properties/variables.
        private PlayerMotor playerMotor;
        private GameObject mainCamera;
        private CharacterController playerController;
        private WeaponManager weaponManager;

        public float dodgingdistance;
        public float TimeCovered;
        float fractionOfJourney;
        int AvoidHitMod;
        float dodgetimer;
        float headDelta;
        float dodgeMaxTime;
        float dodgeDistanceMult;
        float dodgeTimeMult;

        bool touchingSides;
        bool touchingGround;
        bool dodging;
        bool sheathedState;

        string inputKey;

        Vector3 dodgeCamera;
        Vector3 dodgeDirection;
        Vector3 motion;

        static Mod mod;
        static DodgeMod instance;
        static ModSettings settings;

        //sets up different class properties.
        #region Properties
        //sets up player entity class for easy retrieval and manipulation of player character.
        PlayerEntity playerEntity;
        //sets up player class instance properties for manipulation.
        public PlayerEntity PlayerEntity
        {
            get { return (playerEntity != null) ? playerEntity : playerEntity = GameManager.Instance.PlayerEntity; }
        }
        #endregion

        //starts mod manager on game begin. Grabs mod initializing paramaters.
        //ensures SateTypes is set to .Start for proper save data restore values.
        [Invoke(StateManager.StateTypes.Start, 0)]
        public static void Init(InitParams initParams)
        {
            Debug.Log("DODGE MOD STARTED!");
            //sets up instance of class/script/mod.
            GameObject go = new GameObject("DodgeMod");
            instance = go.AddComponent<DodgeMod>();
            //initiates mod paramaters for class/script.
            mod = initParams.Mod;
            //initates mod settings
            settings = mod.GetSettings();
            //after finishing, set the mod's IsReady flag to true.
            mod.IsReady = true;
        }

        void Start()
        {
            //Sets up object instances for GameManager, so said scripts can be manipulated/accessed. Prints Message when done.
            playerMotor = GameManager.Instance.PlayerMotor;
            weaponManager = GameManager.Instance.WeaponManager;
            mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
            playerController = playerMotor.GetComponent<CharacterController>();
            //StartCoroutine(debug());

            dodgeDistanceMult = settings.GetValue<float>("Settings", "DodgeDistanceMult");
            dodgeTimeMult = settings.GetValue<float>("Settings", "DodgeTimeMult");

            DaggerfallUI.Instance.PopupMessage("Dodge Script Started:");
        }

        void Update()
        {
            //Checks if player is touching the ground or side. Used to stop dodging when player hits objects/walls or is in the air.
            touchingSides = (playerMotor.CollisionFlags & CollisionFlags.Sides) != 0;
            touchingGround = (playerMotor.CollisionFlags & CollisionFlags.Below) != 0;

            //put in for now to verify mod is active in stand alone game.
            DaggerfallUI.Instance.PopupMessage("Dodge Script Running:");

            //activates on frame of key press and player not attacking. Sets up vars for dodging routine below.
            if (Input.GetKeyDown(KeyCode.J) && weaponManager.IsAttacking == false)
            {
                //records players avoidhit modifier stat to reset to default after dodge is over.
                AvoidHitMod = PlayerEntity.BiographyAvoidHitMod;

                sheathedState = GameManager.Instance.WeaponManager.Sheathed;
                //Figures out fatigue cost. most is 20 at 0 agility and least is 10 at 100 agility.
                PlayerEntity.CurrentFatigue = PlayerEntity.CurrentFatigue - ((200 - PlayerEntity.Stats.LiveAgility) / 10);
                //max is .5f seconads at 100 agility;
                dodgeMaxTime = ((PlayerEntity.Stats.LiveAgility/2f)/100f) * dodgeTimeMult;
                //max is .1f at 100 agility;
                dodgingdistance = ((PlayerEntity.Stats.LiveAgility / 10f) / 100f) * dodgeDistanceMult;
            }

            //executes actual dodge routine, as long as player holds dodge key and movement direction and is not attacking.
            if (Input.GetKey(KeyCode.J) && weaponManager.IsAttacking == false)
            {
                //counts how long player is dodging/holding dodge key.
                dodgetimer += Time.deltaTime;

                //if then check for movement direction. Sets dodge direction based on detected movement direction.
                if (InputManager.Instance.HasAction(InputManager.Actions.MoveRight))
                    dodgeDirection = mainCamera.transform.right;
                else if (InputManager.Instance.HasAction(InputManager.Actions.MoveLeft))
                    dodgeDirection  = mainCamera.transform.right * -1;
                else if (InputManager.Instance.HasAction(InputManager.Actions.MoveForwards))
                    dodgeDirection = mainCamera.transform.forward;
                else if (InputManager.Instance.HasAction(InputManager.Actions.MoveBackwards))
                    dodgeDirection = mainCamera.transform.forward * -1;

                //sheathes weapons, executs dodge, and sets player hit avoidance to 100%,  as long as it is below max dodge time allowed.
                if (dodgetimer < dodgeMaxTime)
                {
                    GameManager.Instance.WeaponManager.Sheathed = true;
                    dodging = true;
                    PlayerEntity.BiographyAvoidHitMod = 100;
                }
                else
                {
                    dodging = false;
                    GameManager.Instance.WeaponManager.Sheathed = sheathedState;
                }
            }

            //resets dodge and dodge vars for next dodge when dodge key is released.
            if (Input.GetKeyUp(KeyCode.J))
            {
                dodging = false;
                TimeCovered = 0;
                dodgetimer = 0;
                fractionOfJourney = 0;
                PlayerEntity.BiographyAvoidHitMod = AvoidHitMod;
                GameManager.Instance.WeaponManager.Sheathed = sheathedState;
            }

            //ensures player is grounded and not against an object/wall to execute dodge.
            if(!touchingGround || touchingSides)
            {
                GameManager.Instance.WeaponManager.Sheathed = sheathedState;
                dodging = false;
            }

            //Executes Feign routine that moves player, as long as dodge key is pressed.
            if (dodging == true)
                    ExecFeignIn(dodgeDirection, dodgeMaxTime, dodgingdistance);
        }

        void ExecFeignIn(Vector3 direction, float duration, float distance)
        {
            // Distance moved equals elapsed time times speed.
            TimeCovered += Time.deltaTime;

            // Fraction of journey completed equals current time divided by total movement time.
            fractionOfJourney = TimeCovered / duration;

            //reprocesses time passed into a sin graph function to provide a ease out movement shape instead of basic linear movement.
            fractionOfJourney = fractionOfJourney * fractionOfJourney * fractionOfJourney * (fractionOfJourney * (6f * fractionOfJourney - 15f) + 10f);
            //Mathf.Sin(fractionOfJourney * Mathf.PI * 0.33f);

            dodgeCamera = mainCamera.transform.position - (mainCamera.transform.up * (fractionOfJourney / 10));

            mainCamera.transform.position = dodgeCamera;

            //sets movement direction and distance.
            motion = direction * distance;

            //moves player by taking the motion and then lerping it over time to provide a set movement distance and speed
            //for movement/code execution.
            playerController.Move(motion * (fractionOfJourney));

            //Ensures feignin stops if timecovered passes a 100 % of its value. Ensures weird outputs don't happen by ensuring time doesn't go over
            //100% of the execution time. Turns off FeignIn so FeignWait coroutine can start next phase of dodge.
            if (fractionOfJourney > .99f && !(fractionOfJourney < 0f))
            {
                //InvokeFeign = true;
                dodging = false;
            }
        }

        //Debug coroutine for fine tuning.
        IEnumerator debug()
        {
            while (true)
            {
                DaggerfallUI.Instance.PopupMessage("distance: " + dodgingdistance.ToString());
                //DaggerfallUI.Instance.PopupMessage("Sides: " + touchingSides.ToString());
                //DaggerfallUI.Instance.PopupMessage("Ground: " + touchingGround.ToString());
                //DaggerfallUI.Instance.PopupMessage("time: " + TimeCovered.ToString());
                DaggerfallUI.Instance.PopupMessage("time%: " + fractionOfJourney.ToString());
                yield return new WaitForSeconds(1.0f);
            }
        }
    }
}
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: MOD works in unity, not stand alone

Post by BadLuckBurt »

Check output_log.txt from the game, if theres an error it will show up in there
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

l3lessed
Posts: 1406
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: MOD works in unity, not stand alone

Post by l3lessed »

Thanks for the recommendation, but the weird thing is when I search the stand alone game folder, their is no output text. Same within the C# compiler and when I run it within the unity builder itself there are no errors reported at any step.

Other thing, my outfit manager mod, which has the exact same object setup for setting up and initiating the mod object script file, runs fine still when compiled and used in the stand alone game. This is telling me, I'm accessing something code wise I'm not suppose to be within the stand alone game. Hmmm.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: MOD works in unity, not stand alone

Post by BadLuckBurt »

l3lessed wrote: Wed May 06, 2020 4:38 pm Thanks for the recommendation, but the weird thing is when I search the stand alone game folder, their is no output text. Same within the C# compiler and when I run it within the unity builder itself there are no errors reported at any step.

Other thing, my outfit manager mod, which has the exact same object setup for setting up and initiating the mod object script file, runs fine still when compiled and used in the stand alone game. This is telling me, I'm accessing something code wise I'm not suppose to be within the stand alone game. Hmmm.
It's not in the game folder, Interkarma posted instructions on where to find it: viewtopic.php?f=5&t=2360
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

l3lessed
Posts: 1406
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: MOD works in unity, not stand alone

Post by l3lessed »

Thank you, as always. So, that helped. If I'm reading the error right, it can't find the mod object for loading the mod script file.
No mod loaders found for mod: Dodge Mod
The code and file setup is exactly the same as my outfit manager mod, that doesn't have an issue loading.

I'll keep digging.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: MOD works in unity, not stand alone

Post by BadLuckBurt »

Look higher up in the log or just throw it on Pastebin. You usually see that message because your mod script(s) have failed to compile.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
MasonFace
Posts: 543
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: MOD works in unity, not stand alone

Post by MasonFace »

I agree with BadLuckBurt; it could be a script failing to compile in MCS.

Are you using any Enums in your script? That can cause compilation issues.

If so, you can try to rewrite those parts using a struct of integers, or you can package your scripts into an assembly then load them using your mod initialization script.

TheLacus walked me through this in this thread if you want to read through it.

l3lessed
Posts: 1406
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: MOD works in unity, not stand alone

Post by l3lessed »

TY, got it.
Error (1061): Type `DaggerfallWorkshop.Game.WeaponManager' does not contain a definition for `IsAttacking' and no extension method `IsAttacking' of type `DaggerfallWorkshop.Game.WeaponManager' could be found. Are you missing an assembly reference?
Error (): 0(86,14): DaggerfallWorkshop.Game.DodgeMod.DodgeMod.Update()
It looks like the way I am calling and using the weapon manager object the game is unhappy with. I'll try setting it up using instances versus defining the object.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: MOD works in unity, not stand alone

Post by BadLuckBurt »

I just tossed your code into a file and let Unity do it's thing. I see 2 problems in VSCode, both the same thing in the Update method:

Code: Select all

if (Input.GetKey(KeyCode.J) && weaponManager.IsAttacking == false)
You try to access that weaponManager.IsAttacking twice and unless this is an addon for your custom branch where you've exposed that in the WeaponMAnager, there is no IsAttacking property in the regular weaponManager. There is an 'isAttacking' property in WeaponManager but that's private so you can't access that from your mod.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

l3lessed
Posts: 1406
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: MOD works in unity, not stand alone

Post by l3lessed »

Yeah, just compared base script to mine, and see that.

I had attempted to make it a public var a while back, as I thought it would be nice for modding to know when the player is attacking and allow easy on and off switching of it. Forgot I made those changes to the base script, like a nub, and here I am.

Okay, now time to go about this another way then. Is there any easy way to access player attacking and stop or start it?
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply