public void AddModifier(StatModifier mod) { // Add the mod to the list of modifiers for this stat ModifierMap modMap = null; if (!Modifiers.TryGetValue(mod.statName, out modMap)) { Modifiers[mod.statName] = new ModifierMap(); } HashSet <StatModifier> modSet; if (!Modifiers[mod.statName].TryGetValue(mod.type, out modSet)) { Modifiers[mod.statName][mod.type] = new HashSet <StatModifier>(); } Modifiers[mod.statName][mod.type].Add(mod); // Add the mod stat as a dependant of the mod source if (mod.modSourceStat != null) { List <string> depList; if (!Dependants.TryGetValue(mod.modSourceStat, out depList)) { Dependants[mod.modSourceStat] = new List <string>(); } Dependants[mod.modSourceStat].Add(mod.statName); } UpdateModifiedValue(mod.statName); OnPropertyChange("ModifiedValues"); }
public void RegisterFunction(ulong address, TranslatedFunction func) { Targets.AddOrUpdate(address, func, (key, oldFunc) => func); long funcPtr = func.FuncPtr.ToInt64(); // Update all jump table entries that target this address. if (Dependants.TryGetValue(address, out List <int> myDependants)) { lock (myDependants) { foreach (int entry in myDependants) { IntPtr addr = GetEntryAddressJumpTable(entry); Marshal.WriteInt64(addr, 8, funcPtr); } } } }
private void UpdateModifiedValue(string name) { ModifiedValues[name] = LeveledValues[name]; ModifierMap modMap; if (Modifiers.TryGetValue(name, out modMap)) { HashSet <StatModifier> addMods; if (modMap.TryGetValue(ModifierType.Additive, out addMods)) { foreach (StatModifier modifier in addMods) { ModifiedValues[name] += modifier.ModValueWithTable(); } } HashSet <StatModifier> multMods; if (modMap.TryGetValue(ModifierType.Multiplicative, out multMods)) { float totalMult = 1.0f; foreach (StatModifier modifier in multMods) { totalMult += modifier.ModValueWithTable(); } ModifiedValues[name] *= totalMult; } } // Propagate changes to dependant stats List <string> depList; if (Dependants.TryGetValue(name, out depList)) { foreach (string dependant in depList) { UpdateModifiedValue(dependant); } } OnPropertyChange(name); }