Page 1 of 2

Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 1:14 pm
by Magicono43
So i'm trying to finalize the code of my latest mod, the hardest problem i'm having is making it full or at least mostly compatible with other mods as well. I'll give my current example, i'm using a method from FormulaHelper.cs that has inside of it, a call for a method that would be used for other mods to override/put in their own values.

Code: Select all

private static int CalculateAttackDamage(DaggerfallEntity attacker, DaggerfallEntity target, int enemyAnimStateRecord, int weaponAnimTime, DaggerfallUnityItem weapon)
{

// Mod hook for adjusting final hit chance mod. (is a no-op in DFU)
chanceToHitMod = AdjustWeaponHitChanceMod(attacker, target, chanceToHitMod, weaponAnimTime, weapon);

}

Code: Select all

private static int CalculateWeaponAttackDamage(DaggerfallEntity attacker, DaggerfallEntity target, int damageModifier, int weaponAnimTime, DaggerfallUnityItem weapon)
{

// Mod hook for adjusting final damage. (is a no-op in DFU)
damage = AdjustWeaponAttackDamage(attacker, target, damage, weaponAnimTime, weapon);

}
These two lines are currently being used by the "RoleplayRealism" mod to implement the bow draw time module of the mod. With the way my mod is currently made, this module would not function, because my mod overrides the method that this other override method is called.

If I try to put these "AdjustWeaponHitChanceMod" and "AdjustWeaponAttackDamage" inside my overridden method, I get a compile error since those are not inside my script, and if I try to call them from FormulaHelper like this "FormulaHelper.AdjustWeaponHitChanceMod" I get a compile error as well since these methods are private.

Anybody know anyway that I can get around this problem? I would really prefer not to make some good mods incompatible with my own, if possible.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 4:26 pm
by l3lessed
No, the developers would need to make the var routine into a public int vs the current private static int it is set to in Formulahelper.cs script. I'm sure there is a reason they have locked down that routine var from being easily manipulated.

The private static int, if you didn't know, means the routine can only be seen and accessed by the script file it is in, and once it is set, it cannot be reset from outside its script instance.

You're trying to access and change something your script file can never see or touch.

The work around you can try is finding the associated output public var and the number range of the var/stat you are trying to play with, have the formula output dump its number into a public var you can manipulate, and then manipulate the public var how you need to for your mod.

Your other long shot is to take the whole code block from Formulahelper.cs, move it into your mode script file, and then override the original values and code within the code flow. Aka, replicate what is happening in the Formulahelper script in your own mod scripts and then change the end accessible values after all the original code/calculations are done. It is repetitive and waste cpu cycles, but it may work as a more brute force method.

I could be wrong though, as my coding experience isn't as deep as many others.

Are you trying to mess with animation times, and if so, how? This is one area I have done a good amount of work in. :D

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 4:45 pm
by Magicono43
I pretty much already have everything I want altered as it should be using the built-in overrides that Hazelnut and others had added to the FormulaHelper script. The only issue is that if another mod is using a method call within the method that you have overridden, it obviously won't be able to function properly if one mod is overriding what it expects to be somewhere else.

What i'm probably going to try is just adding in the code that they would be trying to override, and maybe that will somehow come back to mine and do what their code is expecting to do, maybe.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 4:52 pm
by Ralzar
The best solution I can come up with atm:

1: set the dfmod to require load order after RP&R in the mod list
2: Have your script check if the archery stuff is enabled in RP&Rs mod settings by the user.
3: If enabled: Have your override contain the exact override code RP&R uses and then add your own stuff in the same override.

This way you will write over RP&Rs override, but with the exact same code.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 4:57 pm
by Magicono43
Ralzar wrote:
Tue Mar 24, 2020 4:52 pm
The best solution I can come up with atm:

1: set the dfmod to require load order after RP&R in the mod list
2: Have your script check if the archery stuff is enabled in RP&Rs mod settings by the user.
3: If enabled: Have your override contain the exact override code RP&R uses and then add your own stuff in the same override.

This way you will write over RP&Rs override, but with the exact same code.
That's basically what i'm going to try and do now. I'll just have it as a setting option "Roleplay Realism Compatibility Archery Patch" or something like that. Don't really like the solution, but at least it will work instead of making a mod feature incompatibility.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 5:16 pm
by Hazelnut
Magicono43 wrote:
Tue Mar 24, 2020 1:14 pm
If I try to put these "AdjustWeaponHitChanceMod" and "AdjustWeaponAttackDamage" inside my overridden method, I get a compile error since those are not inside my script, and if I try to call them from FormulaHelper like this "FormulaHelper.AdjustWeaponHitChanceMod" I get a compile error as well since these methods are private.

Anybody know anyway that I can get around this problem? I would really prefer not to make some good mods incompatible with my own, if possible.
Wait for the next build of DFU. I'm going to make them all public I think, it was an attempt to ensure modders overrode parts of the classic formula or the entire formula but not mix the two. I think it gives more problems than it solves. Already made quite a few public for Numidium, may as well do all of them I think.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 5:31 pm
by Magicono43
Hazelnut wrote:
Tue Mar 24, 2020 5:16 pm
Magicono43 wrote:
Tue Mar 24, 2020 1:14 pm
If I try to put these "AdjustWeaponHitChanceMod" and "AdjustWeaponAttackDamage" inside my overridden method, I get a compile error since those are not inside my script, and if I try to call them from FormulaHelper like this "FormulaHelper.AdjustWeaponHitChanceMod" I get a compile error as well since these methods are private.

Anybody know anyway that I can get around this problem? I would really prefer not to make some good mods incompatible with my own, if possible.
Wait for the next build of DFU. I'm going to make them all public I think, it was an attempt to ensure modders overrode parts of the classic formula or the entire formula but not mix the two. I think it gives more problems than it solves. Already made quite a few public for Numidium, may as well do all of them I think.
I can understand why people would make stuff private, it does make it harder to modify from the outside obviously. I still don't know all of the advantages and disadvantages of the different access modifiers.

Thanks for the heads-up on the next releases, i'll probably still try and make this band-aid fix work for now though.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 8:02 pm
by l3lessed
There really isn't advantages or disadvantages. It more about what you want to do and need to do.

It is common to put anything under static private classes to ensure cross coding/scripting risks are completely avoided. It's a coding practice to try and minimize the memory and cpu demand and protect the code from unintentional or even intentional modifications that could cause glitches, crashes, or even cheats via code injection.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 8:15 pm
by Magicono43
That's fair enough, I've mostly just been using "Private Static" as my default because I have been told it's usually good practice. Hopefully i'll learn to use the different types where necessary as I get better at C#.

Re: Anybody know how to get around this issue i'm having?

Posted: Tue Mar 24, 2020 8:40 pm
by Hazelnut
Why would you want to carry on trying to work around it? You can grab my branch and develop + test ready for when the next build is released, might be a better use of your time.

As for protection levels in object oriented languages, it's all about encapsulation but here we're taking shortcuts for expediency. I would not do the same in a professional capacity or if the software was being used for critical devices etc. :D