Here is the Github Repo so far: https://github.com/magicono43/DFU-Mod_S ... g-Improved
Here is the simple mod initialization script:
Code: Select all
// Project: SkillLevelingImproved mod for Daggerfall Unity (http://www.dfworkshop.net)
// Copyright: Copyright (C) 2019 JayH
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Author: Kirk.O
// Last Edited: 6/3/2020, 9:30 AM
// Modifier:
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using UnityEngine;
namespace SkillLevelingImproved
{
public class SkillLevelingImproved : MonoBehaviour
{
static Mod mod;
[Invoke(StateManager.StateTypes.Start, 0)]
public static void Init(InitParams initParams)
{
mod = initParams.Mod;
var go = new GameObject("SkillLevelingImproved");
go.AddComponent<SkillLevelingImproved>();
}
void Awake()
{
InitMod();
mod.IsReady = true;
}
private static void InitMod()
{
Debug.Log("Begin mod init: SkillLevelingImproved");
Debug.Log("Finished mod init: SkillLevelingImproved");
}
#region Stuff Here
#endregion
}
}
Here is the code i'm trying to "override" a single method in the parent class "PlayerEntity.cs":
Code: Select all
using DaggerfallConnect;
using UnityEngine;
using System;
using DaggerfallWorkshop.Game.Entity;
namespace SkillLevelingImproved
//namespace DaggerfallWorkshop.Game.Entity
{
public class SkillTallyOverride : PlayerEntity
{
#region Constructors
public SkillTallyOverride(DaggerfallEntityBehaviour entityBehaviour)
: base(entityBehaviour)
{
}
#endregion
#region Public Methods
public override void TallySkill(DFCareer.Skills skill, short amount)
{
int skillId = (int)skill;
try
{
Debug.Log("AHHHHHHHHHHHHHHHH!!!!!!!!!!");
if(skillId == 3)
{
Debug.Log("You just jumped! You idiot!");
}
if (skillId == 0)
{
Debug.Log("You just slept for an hour! You coward!");
}
if (skillId == 18)
{
Debug.Log("You just climbed! You monkey!");
}
if (skillId != 27)
{
Debug.Log("You just did something other than Mysticism! You donkey!");
}
skillUses[skillId] += amount;
if (skillUses[skillId] > 20000)
skillUses[skillId] = 20000;
else if (skillUses[skillId] < 0)
{
skillUses[skillId] = 0;
}
}
catch (Exception ex)
{
string error = string.Format("Caught exception {0} with skillId {1}.", ex.Message, skillId);
if (skillUses == null || skillUses.Length == 0)
error += " skillUses is null or empty.";
Debug.Log(error);
}
}
#endregion
}
}
Code: Select all
/// <summary>
/// Tally skill usage.
/// </summary>
public override void TallySkill(DFCareer.Skills skill, short amount)
{
int skillId = (int)skill;
try
{
skillUses[skillId] += amount;
if (skillUses[skillId] > 20000)
skillUses[skillId] = 20000;
else if (skillUses[skillId] < 0)
{
skillUses[skillId] = 0;
}
}
catch (Exception ex)
{
string error = string.Format("Caught exception {0} with skillId {1}.", ex.Message, skillId);
if (skillUses == null || skillUses.Length == 0)
error += " skillUses is null or empty.";
Debug.Log(error);
}
}
So when I have the mod loaded, I should see debug log text going by whenever an skill tally event happens, but i'm not getting anything, which is completely spinning my head as to why from what I have read that overriding virtual methods should do, or using "new" to hide them, neither has worked. If you look in visual studio, the "override" part of my script points to the parent class of PlayerEntity.cs, but even though my script is technically the most derived overriding child for this method, it's not getting any of the calls redirected to it, it's all still just being brought to the PlayerEntity.cs version.
What am I missing here? Maybe i'm oversimplifying how an override of something should work in terms of a mod in this code-base? Really the only overrides that have worked so far have been the ones that have been registered beforehand with some of the modding support that have been made, such as UIFactory and the overrides for FormulaHelper.
But yeah, can anyone see what i'm missing here? Because I have no clue at all and would love to understand how to do something seemingly so simple properly for once.
Edit 1: After reading this fairly well written article: https://www.c-sharpcorner.com/article/u ... n-c-sharp/
I'm thinking that I need to make a new instance of PlayerEntity or something, but in the context that i'm trying to just override a single method, how would I even do that and where would I put the code for the new instance?
Code: Select all
PlayerEntity player = GameManager.Instance.PlayerEntity;