Shop Inventory Mod

Talk about the mods you'd like to see in Daggerfall Unity. Give mod creators some ideas!
User avatar
Rand
Posts: 72
Joined: Sat Nov 23, 2019 5:10 am
Location: Canada

Re: Unleveled world

Post by Rand »

Okay, more staring at the code. Damn, I wish I knew more Unity/C-sharp. It looks like the items are generated for shop containers using the function in DaggerfallLoot.cs, starting line 164. Some of that is just opaque to me. An example:

Line 166: ItemGroups itemGroup = (ItemGroups)itemGroups;

Like, huh? It seems to be a function, but... :?

I have no idea what this means, either (what's with the ++ and -- symbols?):

if (qualityMod >= 4)
--qualityMod;
qualityMod++;

Anyway, I've noticed something. It looks like the arrays from DaggerfallLootDataTables.cs are read in order, and the second number of each hex pair is related to the appearance chance. This is modified slightly by the rarity (from ItemTemplates.txt). Weapons all seem to have the rarity 1 (meaning no change of chance to appear), while armors all see to be rarity 3. This seems to mean (based on line 194 of DaggerfallLoot.cs) that the armor's chance of appearing is 90% of the number in the array, so if it's 0x32, it's not 50%, it's 45%.

(I'm puzzled by the bits about shop quality and buildingData. I can't find where the numbers are being drawn from, and I have no idea of their magnitude.)

But wait, it gets worse. In standard Daggerfall Unity, armor shops use this array: { 0x02, 0x50, 0x03, 0x14 } this means check armor first, 50% chance (that turns into 45%), and if nothing, try for weapons at 20% chance. While weapon shops use this array: { 0x02, 0x1E, 0x03, 0x46 }. If I'm interpreting the code right from the DaggerfallLoot.cs code, this means that weapon shops check for armor FIRST (at 30%, lowered to 27%), and only if it doesn't pass, check for weapons at 70%. That means that the chance of a weapon is effectively 73% of 70%, or 51.1%.

At minimum, the array for itemGroupsWeaponSmith should be reversed, from { 0x02, 0x1E, 0x03, 0x46 }, to { 0x03, 0x46, 0x02, 0x1E }, then the percentages of generation should match what was intended.

Maybe I should let one of the devs know and let them check my analysis for accuracy so if I'm right, they can fix it in the next build.
Last edited by Rand on Mon Nov 25, 2019 7:03 am, edited 1 time in total.

User avatar
Rand
Posts: 72
Joined: Sat Nov 23, 2019 5:10 am
Location: Canada

Re: Unleveled world

Post by Rand »

Ralzar wrote: Sun Nov 24, 2019 8:19 pm No idea if it can be modded but I assume not. If there is no other way to achieve unleveled world than by compiling a seperate build, that should be something to consider after DFU is completely finished. I would really prefer this to be achieved through modding though.
Well, if the hardcode was exposed in a separate file, it could be modded, like in the newer Elder Scrolls where there are lists of various constants that can be altered using editors. Hazelnut (talking in the Daggerfall Equipment Rebalance topic) is thinking of exposing some code related to material quality and damage ranges, so perhaps he can also expose the item generation related hardcode as well.

This would allow a kind of item rebalance/shop availability mod that's prevalent in later games. :)

Ultimately, I don't know enough about Unity, Daggerfall Unity, and the process they've implemented, to determine if any of this is feasable. On first look, there are some mods that seem to add new items. Archeologists, for example, and that's by Hazelnut. Maybe he can give us an idea of how to proceed.

User avatar
Jay_H
Posts: 4072
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Shop Inventory Mod

Post by Jay_H »

At one of the participants' request, I have split this topic off into its own :)

User avatar
Rand
Posts: 72
Joined: Sat Nov 23, 2019 5:10 am
Location: Canada

Re: Shop Inventory Mod

Post by Rand »

Okay, more staring at half-understood code, and a bit of an ah-ha moment. Realized that some existing mods must redefine some code somehow, so I went looking.

"No Dice - RNG Remover on level up" (by monkeybtm6) must change compiled code. It's packaged in a .dfmod wrappper, but after looking at the hex of raw data and the helpfully included source script, I see that there's a way to override functions at least using inbuilt mod systems.

Specifically, monkeybtm6 overrides the "CalculateHitPointsPerLevelUp" function on (currently) line 265 of FormulaHelper.cs and "BonusPool" from (currently) line 398 of DaggerfallCharacterSheetWindow.cs.

The really interesting one is the one from FormulaHelper.cs. It defines:

public static int CalculateHitPointsPerLevelUp(PlayerEntity player)

And the lines we want to modify are from DaggerfallLootDataTables.cs, defined:

public static byte[] itemGroupsArmorer = new byte[] { 0x02, 0x50, 0x03, 0x14 };

So the question is can we override a byte[] one like an int one?

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

Re: Shop Inventory Mod

Post by BadLuckBurt »

Rand wrote: Tue Nov 26, 2019 4:12 pm Okay, more staring at half-understood code, and a bit of an ah-ha moment. Realized that some existing mods must redefine some code somehow, so I went looking.

"No Dice - RNG Remover on level up" (by monkeybtm6) must change compiled code. It's packaged in a .dfmod wrappper, but after looking at the hex of raw data and the helpfully included source script, I see that there's a way to override functions at least using inbuilt mod systems.
I don't know the fine details but some functions are exposed by request when modders need them so they can be hooked into or overwritten.

You can use Extract Text in the DFU Mod window to extract the source btw so you don't need to look at hexdata (or did you mean Daggerfall's own files?).

Anyway, just thought I'd mention that. Good luck with 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

.

User avatar
Rand
Posts: 72
Joined: Sat Nov 23, 2019 5:10 am
Location: Canada

Re: Shop Inventory Mod

Post by Rand »

BadLuckBurt wrote: Tue Nov 26, 2019 4:18 pm You can use Extract Text in the DFU Mod window to extract the source btw so you don't need to look at hexdata (or did you mean Daggerfall's own files?).
Both, actually. It's easy for me because with my setup I can send any file to WinHex with a right-click, so I do it pretty frequently. It's basically instant, so no futzing around with opening new editors, etc.. when I just want to (in this case) see if "CalculateHitPointsPerLevelUp" and "BonusPool" are in the file (and they were).

Plus I just download the source code as a set of files so I can run a more powerful global search than most standard utilities allow for. (Thanks again WinHex).

Thanks for the tip, though!

Post Reply