Modding Tutorials

Discuss modding questions and implementation details.
Post Reply
User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Modding Tutorials

Post by TheLacus »

The new mod settings format allow to choose a specific ui control (slider, checkbox etc.) for specific settings, instead of a raw string box for all.

This change was introduced months ago when LypyL wasn't around, so documentation was updated only on website. Legacy support for ini file was kept for 0.5 branch, and removed in 0.6 a month ago. Builds based on this branch are now being pushed, so this change has become effective.

Narf the Mouse
Posts: 833
Joined: Mon Nov 30, 2015 6:32 pm

Re: Modding Tutorials

Post by Narf the Mouse »

TheLacus wrote: Wed Dec 26, 2018 11:11 am The new mod settings format allow to choose a specific ui control (slider, checkbox etc.) for specific settings, instead of a raw string box for all.

This change was introduced months ago when LypyL wasn't around, so documentation was updated only on website. Legacy support for ini file was kept for 0.5 branch, and removed in 0.6 a month ago. Builds based on this branch are now being pushed, so this change has become effective.
Thanks for the info. :)
Previous experience tells me it's very easy to misunderstand the tone, intent, or meaning of what I've posted. If you have questions, ask.

User avatar
UserOfThisSite
Posts: 20
Joined: Thu Mar 07, 2019 10:05 pm

Re: Modding Tutorials

Post by UserOfThisSite »

Hey, I started with DFU modding today and explored the project, followed your first tutorials to see if everything is ok, so my question now is it possible to somehow alter existing scripts or intercept some of its methods? For example:

Image

As you can see "CalculateHitPointsPerLevelUp" now always returns non-random HP which are simply depend on your END and HP per level.

As I understand, currently mod files are simply loaded at the very beginning of the game and do something to the game, so what do I need to do intercept real "CalculateHitPointsPerLevelUp" with my "CalculateHitPointsPerLevelUp"? I need to create separate .cs file and somehow make it trigger whenever "CalculateHitPointsPerLevelUp" is triggered?




Edit:
I found this thread:
viewtopic.php?f=19&t=1122
So it's impossible for now to override formulas?




Edit#2:
What is it?

Code: Select all

Formula_2de_2i del;
if (formula_2de_2i.TryGetValue("CalculateHitPointsPerLevelUp", out del))
	return del(player);
Is it what I think? It first checks for something else (override?) and if exists, then it uses the modded formula, else it goes default one?
If I sound rude, please ignore it, that's how I communicate. I'm actually very non-emotional and thus the chances that I'm angry while posting are ~0%. I also use sarcasm very often.

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Modding Tutorials

Post by TheLacus »

UserOfThisSite wrote: Fri Mar 08, 2019 3:03 pm Hey, I started with DFU modding today and explored the project, followed your first tutorials to see if everything is ok, so my question now is it possible to somehow alter existing scripts or intercept some of its methods? For example:

Image

As you can see "CalculateHitPointsPerLevelUp" now always returns non-random HP which are simply depend on your END and HP per level.

As I understand, currently mod files are simply loaded at the very beginning of the game and do something to the game, so what do I need to do intercept real "CalculateHitPointsPerLevelUp" with my "CalculateHitPointsPerLevelUp"? I need to create separate .cs file and somehow make it trigger whenever "CalculateHitPointsPerLevelUp" is triggered?
Hi UserOfThisSite. Look at the first lines:

Code: Select all

Formula_2de_2i del;
if (formula_2de_2i.TryGetValue("CalculateHitPointsPerLevelUp", out del))
    return del(player);
This is where the method seek a callback to override default implementation. If you want to provide one, you need to push it to the dictionary formula_2de_2i.

Code: Select all

formula_2de_2i.Add("CalculateHitPointsPerLevelUp", (de1, de2, a, b) => {
    var player = de1 as PlayerEntity;
    return 0; // add implementation here
});
This page on micosoft docs explain how to use delegates. Good luck :)

User avatar
UserOfThisSite
Posts: 20
Joined: Thu Mar 07, 2019 10:05 pm

Re: Modding Tutorials

Post by UserOfThisSite »

TheLacus wrote: Fri Mar 08, 2019 4:00 pm This is where the method seek a callback to override default implementation. If you want to provide one, you need to push it to the dictionary formula_2de_2i.
Yes, at first I thought it's some kind of debug/test stuff, then I realized that it's actually what I need.
Ok, so I managed to make a mod and after testing it even works!

Code: Select all

using UnityEngine;
using System.Collections;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Formulas;

public class MaxHPperLevel : MonoBehaviour
{
	void Start()
	{
		FormulaHelper.formula_2de_2i.Add ("CalculateHitPointsPerLevelUp", (de1, de2, a, b) =>
		{
			var player = de1 as PlayerEntity;
			int addHitPoints = player.Career.HitPointsPerLevel + FormulaHelper.HitPointsModifier (player.Stats.LiveEndurance);
			if (addHitPoints < 1)
			{
				addHitPoints = 1;
			}
			return addHitPoints;
		});
	}

	[Invoke (StateManager.StateTypes.Game, 0)]
	public static void Init (InitParams initParams)
	{
		GameObject GO = new GameObject ("MaxHPperLevel");
		MaxHPperLevel go = GO.AddComponent<MaxHPperLevel> ();
		ModManager.Instance.GetMod (initParams.ModTitle).IsReady = true;
	}
}
This makes you always get max HP on each level up.

I still need to find where "attributes per level up" is and then I'll be able to make StaticLeveling mod, that makes level non-random, the problem, that I can't find it anywhere, I searched for "level", "attribute", "Random.Range", but couldn't find anything related to it.
Image

Also where can I find custom class advantages/disadvantages point costs? I want to make a rebalance mod that makes you unable to create imba OP builds.
If I sound rude, please ignore it, that's how I communicate. I'm actually very non-emotional and thus the chances that I'm angry while posting are ~0%. I also use sarcasm very often.

User avatar
mikeprichard
Posts: 1037
Joined: Sun Feb 19, 2017 6:49 pm

Re: Modding Tutorials

Post by mikeprichard »

Oh wow, UserOfThisSite, so glad to see someone skilled and willing to implement these improvements I've been hoping for for a very long time! As one player who will always be using this mod (static leveling to "fix" Endurance and remove the annoying randomized stat/health points on level up) after you're able to complete it - thank you!

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Modding Tutorials

Post by pango »

UserOfThisSite wrote: Fri Mar 08, 2019 7:17 pm I still need to find where "attributes per level up" is and then I'll be able to make StaticLeveling mod, that makes level non-random, the problem, that I can't find it anywhere, I searched for "level", "attribute", "Random.Range", but couldn't find anything related to it.
There:
https://github.com/Interkarma/daggerfal ... ow.cs#L410
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
UserOfThisSite
Posts: 20
Joined: Thu Mar 07, 2019 10:05 pm

Re: Modding Tutorials

Post by UserOfThisSite »

pango wrote: Fri Mar 08, 2019 10:22 pm There:
https://github.com/Interkarma/daggerfal ... ow.cs#L410
Thank you, unfortunately, those aren't public and there're no public methods that can be overriden or that modify those values, as the result I see no way to change those values.

Right now the mod looks like this:

Code: Select all

using UnityEngine;
using System.Collections;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Formulas;
//using DaggerfallWorkshop.Game.UserInterfaceWindows;

public class ModStaticLeveling : MonoBehaviour
{
	void Start ()
	{
		FormulaHelper.formula_2de_2i.Add ("CalculateHitPointsPerLevelUp", (de1, de2, a, b) =>
		{
			var player = de1 as PlayerEntity;
			int setHitPoints = 25 + player.Career.HitPointsPerLevel + (player.Level - 1) * (player.Career.HitPointsPerLevel + FormulaHelper.HitPointsModifier (player.Stats.LiveEndurance));
			int addHitPoints = setHitPoints - player.MaxHealth;
			if (addHitPoints < 0)
			{
				addHitPoints = 0;
			}
			return addHitPoints;
		});
		//DaggerfallCharacterSheetWindow.minBonusPool = 6;
	}

	[Invoke (StateManager.StateTypes.Game, 0)]
	public static void Init (InitParams initParams)
	{
		GameObject go = new GameObject ("ModStaticLeveling");
		go.AddComponent<ModStaticLeveling> ();
		ModManager.Instance.GetMod (initParams.ModTitle).IsReady = true;
	}
}
mikeprichard wrote: Fri Mar 08, 2019 9:33 pm Oh wow, UserOfThisSite, so glad to see someone skilled and willing to implement these improvements I've been hoping for for a very long time! As one player who will always be using this mod (static leveling to "fix" Endurance and remove the annoying randomized stat/health points on level up) after you're able to complete it - thank you!
Endurance now retroactive stat at last!
Now, whenever you level up, the game checks how much HP you have, then it checks how much HP you must have according to formula 25 + MaxHPperLVL + (YourLvl-1) * (MaxHPperLVL + ENDmod), then it adds N hp to you, where N is the difference.
Image
On this image you can see that my character has 157 HP, I got 80 END on 1st level, then 86 END, then 91 END, custom class has 30 HP per level. At first I got +33 HP, then +33 HP, then +36 HP. +1 for additional END mod on this level and +2 from previous levels.
Unfortunately you still need to wait for the next level for new END to apply. For example, when on 3rd level I still got 86 END, I received +33 HP and increased END to 91, but I still had the same HP, only on the next level the game calculated the real HP.

You can download this mod here:
https://mega.nz/#!CYAV0YJI!Mp8EOdhThz0c ... pExGjjxYXs

Put it into "Daggerfall\DaggerfallUnity_Data\StreamingAssets\Mods" folder.
The mod still doesn't change attributes per level and it's still random 4-6, unfortunately I can't change it due to its protection. Mod script simply can't access it.
If I sound rude, please ignore it, that's how I communicate. I'm actually very non-emotional and thus the chances that I'm angry while posting are ~0%. I also use sarcasm very often.

User avatar
mikeprichard
Posts: 1037
Joined: Sun Feb 19, 2017 6:49 pm

Re: Modding Tutorials

Post by mikeprichard »

Thanks, I'll try it out when I can!
UserOfThisSite wrote: Fri Mar 08, 2019 11:57 pm The mod still doesn't change attributes per level and it's still random 4-6, unfortunately I can't change it due to its protection. Mod script simply can't access it.
Darn, that's really too bad. I guess nobody knows a way around this? Was hoping things like this would be fully moddable.

User avatar
UserOfThisSite
Posts: 20
Joined: Thu Mar 07, 2019 10:05 pm

Re: Modding Tutorials

Post by UserOfThisSite »

mikeprichard wrote: Sat Mar 09, 2019 12:04 am Thanks, I'll try it out when I can!
UserOfThisSite wrote: Fri Mar 08, 2019 11:57 pm The mod still doesn't change attributes per level and it's still random 4-6, unfortunately I can't change it due to its protection. Mod script simply can't access it.
Darn, that's really too bad. I guess nobody knows a way around this? Was hoping things like this would be fully moddable.
It's very easy, someone simply need to change those values to public, it's few seconds work. For example I can do that for my own Daggerfall, but then it won't be a mod any longer, but a hack. If DFU devs change those values to public on some newer version, then I'll update my mod.

Oh, and forgot to add, this will work for existing game with no problem, you'll immediately get all the HP you lack on level up.
If I sound rude, please ignore it, that's how I communicate. I'm actually very non-emotional and thus the chances that I'm angry while posting are ~0%. I also use sarcasm very often.

Post Reply