public static void Update() { if (NeedsNewGameInit) { NewGameInit(); } bool SkipListners = SkipListenersNextUpdate; SkipListenersNextUpdate = false; var memory = Randomizer.Memory; Dictionary <long, UberState> uberStates = memory.GetUberStates(); foreach (KeyValuePair <long, UberState> pair in uberStates) { try { UberState state = pair.Value; UberId key = state.GetUberId(); if (UberStates.TryGetValue(key, out UberState oldState)) { UberValue value = state.Value; UberValue oldValue = oldState.Value; if (value.Int != oldValue.Int) { var oldValFmt = oldState.FmtVal(); // get this now because we overwrite the value by reference if (ShouldRevert(state)) { Randomizer.Log($"Reverting state change of {state.Name} from {oldValFmt} to {state.FmtVal()}", false); memory.WriteUberState(oldState); continue; } HandleSpecial(state); UberStates[key].Value = state.Value; if (!SkipListners) { var pos = Randomizer.Memory.Position(); bool found = false; if (value.Int > 0) { found = SeedController.OnUberState(state); } if ((value.Int == 0 || !found) && !(state.GroupName == "statsUberStateGroup" || state.GroupName == "achievementsGroup")) { Randomizer.Log($"State change: {state.Name} {state.ID} {state.GroupName} {state.GroupID} {state.Type} {state.FmtVal()} (was {oldValFmt}, pos ({Math.Round(pos.X)},{Math.Round(pos.Y)}) )", false); } } } } else { UberStates[key] = state.Clone(); } } catch (Exception e) { Randomizer.Error($"USC.Update {pair}", e); } } }
public static void Update(bool NewGameInit = false) { var memory = Randomizer.Memory; Dictionary <long, UberState> uberStates = memory.GetUberStates(); foreach (KeyValuePair <long, UberState> pair in uberStates) { long key = pair.Key; UberState state = pair.Value; if (state.GroupName == "statsUberStateGroup" || (state.GroupName == "achievementsGroup" && state.Name == "spiritLightGainedCounter")) { continue; } if (UberStates.TryGetValue(key, out UberState oldState)) { UberValue value = state.Value; UberValue oldValue = oldState.Value; if (value.Int != oldValue.Int) { var pos = Randomizer.Memory.Position(); if (Ready) { if (value.Int > 0) { SeedController.OnUberState(state); if (!Randomizer.PleaseSave) { Randomizer.Log($"Potential pickup: {state.GroupName}.{state.Name} ({state.GroupID}, {state.ID}) at ({Math.Round(pos.X)},{Math.Round(pos.Y)}) {value.Int}", false); } } else { Randomizer.Log($"State change {state.GroupName}.{state.Name} ({state.GroupID}, {state.ID}) at ({Math.Round(pos.X)},{Math.Round(pos.Y)}): {oldValue.Int}->{value.Int}", false); } } UberStates[key].Value = state.Value; } } else { UberStates[key] = state.Clone(); } } if (!NewGameInit) { Ready = true; } }
public static void ResolveUberStateChange(UberState state, UberValue old) { try { UberId key = state.GetUberId(); if (!UberStates.TryGetValue(key, out UberState oldState)) { oldState = state.Clone(); oldState.Value = old; UberStates.Add(key, oldState); } UberValue value = state.Value; if (value.Int == old.Int) { return; } var oldValFmt = old.FmtVal(state.Type); // get this now because we overwrite the value by reference if (ShouldRevert(state)) { Randomizer.Log($"Reverting state change of {state.Name} from {oldValFmt} to {state.FmtVal()}", false); oldState.Write(); return; } HandleSpecial(state); UberStates[key].Value = state.Value; var pos = InterOp.get_position(); bool found = false; if (value.Int > 0) { var id = state.GetUberId(); if (SkipUberStateMapCount.GetOrElse(key, 0) > 0) { var p = id.toCond().Pickup().Concat(id.toCond(state.ValueAsInt()).Pickup()); if (p.NonEmpty) { SkipUberStateMapCount[key] -= 1; Randomizer.Log($"Suppressed granting {p} from {id}={state.ValueAsInt()}. Will suppress {SkipUberStateMapCount[key]} more times", false, "DEBUG"); return; } } found = SeedController.OnUberState(state); } if (SyncedUberStates.Contains(key)) { Randomizer.Client.SendUpdate(key, state.ValueAsFloat()); } BonusItemController.OnUberState(state); var zone = ZoneType.Void; if (InterOp.get_game_state() == GameState.Game) { zone = InterOp.get_player_area().toZone(); } if (!NeedsNewGameInit && (value.Int == 0 || !found) && !(state.GroupName == "statsUberStateGroup" || state.GroupName == "achievementsGroup" || state.GroupID == 8 || state.GroupID == 10)) { Randomizer.Debug($"State change: {state.GroupName}.{state.Name} ({state.GroupID}|{state.ID}) {state.Type} {oldValFmt}->{state.FmtVal()} at ({Math.Round(pos.X)}, {Math.Round(pos.Y)}) in {zone}"); } //Randomizer.Debug($"{state.GroupName}.{state.Name}, {state.GroupID}, {state.ID}, {state.Type}, {oldValFmt}, {state.FmtVal()}, {zone}, {Math.Round(pos.X)},{Math.Round(pos.Y)}"); } catch (Exception e) { Randomizer.Error($"USC.Update {state}", e); } }