public static void OnUberStateChanged(int groupID, int stateID, byte type, float oldValue, float newValue)
        {
            if (uberStateLookup == null)
            {
                PopulateUberStates();
            }

            UberId key = new UberId(groupID, stateID);

            if (uberStateLookup.TryGetValue(key, out UberState cachedState))
            {
                UberState state = cachedState.Clone();
                state.Value = CreateValue(state.Type, newValue);
                var value = CreateValue(state.Type, oldValue);
                ResolveUberStateChange(state, value);
            }
            else if (serializableUberState((UberStateType)type))
            {
                var state = createUberStateEntry(key);
                state.Value = CreateValue(state.Type, oldValue);
                uberStateLookup.Add(key, state);
                state       = state.Clone();
                state.Value = CreateValue(state.Type, newValue);
                var value = CreateValue(state.Type, oldValue);
                ResolveUberStateChange(state, value);
            }
        }
Ejemplo n.º 2
0
 private static void HandleSpecial(UberState state)
 {
     if (state.Name == "arenaBByteStateSerialized" && state.Value.Byte == 4)
     {
         // lumaPoolsStateGroup.arenaByteStateSerialized
         new UberId(5377, 1373).State().Write(state.Value);
     }
     else if (state.Name == "craftCutsceneState" && state.Value.Byte != 0)
     {
         state.Write(new UberValue((byte)3));
     }
     else if (state.Name == "findToadQuestUberState" && state.Value.Int == 2)
     {
         Randomizer.InputUnlockCallback = () => {
             // this is really questionable!!
             var voiceState = new UberId(46462, 59806).State();
             if (!(voiceState.Value.Bool))
             {
                 voiceState.Write(new UberValue(true));
                 Stats stats = Randomizer.Memory.PlayerStats;
                 stats.MaxHealth += 10;
                 stats.MaxEnergy++;
                 Randomizer.Memory.PlayerStats = stats;
                 Randomizer.Memory.FillEnergy();
                 Randomizer.Memory.FillHealth();
             }
         }
     }
     ;
 }
        public static void ReadSeed()
        {
            var seedName = File.ReadAllText(Randomizer.SeedNameFile);

            if (seedName.Trim() != "")
            {
                pickupMap.Clear();
                foreach (var line in File.ReadLines(Randomizer.SeedFile))
                {
                    try {
                        var frags      = line.Split('|');
                        var uberId     = new UberId(int.Parse(frags[0]), int.Parse(frags[1]));
                        var pickupType = (PickupType)byte.Parse(frags[2]);
                        //                    Randomizer.Log($"uberId {uberId} -> {pickupType} {frags[3]}");
                        pickupMap[uberId] = BuildPickup(pickupType, frags[3]);
                    } catch (Exception e) {
                        Randomizer.Log($"Error parsing line: '{line}'\nError: {e.Message} \nStacktrace: {e.StackTrace}", false);
                    }
                }
                AHK.Print($"Seed {seedName} loaded", 300);
            }
            else
            {
                AHK.Print($"No seed loaded; Download a .wotwr file and double-click it to load one", 360);
            }
        }
 public LupoHintData(string name, string desc, int cost, UberId id)
 {
     Name = name;
     Desc = desc;
     Cost = cost;
     Id   = id;
 }
        private static UberState createUberStateEntry(UberId id)
        {
            if (!InterOp.get_uber_state_exists(id.GroupID, id.ID))
            {
                Randomizer.Error("cuse", $"Failed to find {id} in uber state system.", false);
                return(null);
            }

            byte[] buffer = new byte[256];
            int    len    = InterOp.get_uber_state_name(id.GroupID, id.ID, buffer, buffer.Length);
            string name   = System.Text.Encoding.ASCII.GetString(buffer, 0, len);

            len = InterOp.get_uber_state_group_name(id.GroupID, id.ID, buffer, buffer.Length);
            string groupName = System.Text.Encoding.ASCII.GetString(buffer, 0, len);

            var s = new UberState()
            {
                ID        = id.ID,
                GroupID   = id.GroupID,
                Name      = name,
                GroupName = groupName,
                Type      = InterOp.get_uber_state_type(id.GroupID, id.ID),
            };

            s.Value = CreateValue(s.Type, InterOp.get_uber_state_value(id.GroupID, id.ID));
            return(s);
        }
Ejemplo n.º 6
0
 public UberStateModifier(UberId id, Func <UberValue, float> modifier, String modstr, int supCount = 0)
 {
     Id       = id;
     SupCount = supCount;
     Modifier = modifier;
     ModStr   = modstr;
 }
Ejemplo n.º 7
0
 public UberStateCondition(int groupId, int id, int target)
 {
     Id = new UberId(groupId, id);
     if (target > 0)
     {
         Target = target;
     }
 }
Ejemplo n.º 8
0
 public static UberValue?GetValue(this UberId id)
 {
     if (UberStates.TryGetValue(id, out UberState curr))
     {
         return(curr.Value);
     }
     return(null);
 }
Ejemplo n.º 9
0
        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 Network.UberStateUpdateMessage MakeUpdateMsg(this UberId id, float value) => new Network.UberStateUpdateMessage
 {
     State = new Network.UberId {
         // wolf started it :D
         Group = id.GroupID == 0 ? -1 : id.GroupID,
         State = id.ID == 0 ? -1 : id.ID
     },
     Value = value == 0f ? -1f : value
 };
 public static void RegisterCheckable(CheckableHint ch)
 {
     if (nextCheckable == 20)
     {
         Randomizer.Error("HC.RegisterCheckable", "Max 10 checkable hints supported");
         return;
     }
     CheckableHints[ch] = new UberId(6, nextCheckable++);
 }
        public static UberState State(this UberId id)
        {
            if (!UberStates.TryGetValue(id, out UberState s))
            {
                s = createUberStateEntry(id);
                UberStates.Add(id, s);
            }

            return(s);
        }
        public static Sellable OpherWeapon(AbilityType ability)
        {
            UberId fakeId = new UberId((int)FakeUberGroups.OPHER_WEAPON, (int)ability);

            if (pickupMap.TryGetValue(fakeId, out Pickup p) && p is Sellable)
            {
                return(p as Sellable);
            }
            Randomizer.Log($"Couldn't find a valid Sellable for {ability}...");
            return(new Resource(ResourceType.Energy));
        }
        public static Sellable TwillenShard(ShardType shard)
        {
            UberId fakeId = new UberId((int)FakeUberGroups.TWILLEN_SHARD, (int)shard);

            if (pickupMap.TryGetValue(fakeId, out Pickup p) && p is Sellable)
            {
                return(p as Sellable);
            }
            Randomizer.Log($"Couldn't find a valid Sellable for {shard}...");
            return(new Resource(ResourceType.Energy));
        }
 public UberStateCondition(int groupId, string rawTarget)
 {
     if (rawTarget.Contains("="))
     {
         var idAndTarget = rawTarget.Split('=');
         Id     = new UberId(groupId, int.Parse(idAndTarget[0]));
         Target = int.Parse(idAndTarget[1]);
     }
     else
     {
         Id     = new UberId(groupId, int.Parse(rawTarget));
         Target = null;
     }
 }
        public static void OnTree(AbilityType ability)
        {
            UberId fakeId = new UberId((int)FakeUberGroups.TREE, (int)ability);

            if (pickupMap.TryGetValue(fakeId, out Pickup p))
            {
                AHK.Print(p.ToString());
                p.Grant();
                Randomizer.PleaseSave = true;
            }
            else
            {
                Randomizer.Log($"Tree {ability} not found in seed. Get a seed from seedpack 10 or later.");
            }
        }
Ejemplo n.º 17
0
 public static void OnLupoState(UberId id)
 {
     if (SeedController.HintsDisabled)
     {
         return;
     }
     if (LupoZoneIds.ContainsKey(id))
     {
         ProgressWithHints(LupoZoneIds[id], true);
     }
     else if (id.ID == 41666)
     {
         AHK.SendPlainText(new PlainText($"Bought Hint: {GetKeySkillHintTwo()}", 300));
     }
 }
        public static UberValue?ValueOpt(this UberId id)
        {
            if (UberStates.TryGetValue(id, out UberState curr))
            {
                return(curr?.Value);
            }
            var state = createUberStateEntry(id);

            try {
                UberStates.Add(id, state);
            }
            catch (Exception e) {
                Randomizer.Warn("ValueOpt", $"{e}", false);
            }
            return(state?.Value);
        }
 private static void HandleSpecial(UberState state)
 {
     if (state.Name == "arenaBByteStateSerialized" && state.Value.Byte == 4)
     {
         // lumaPoolsStateGroup.arenaByteStateSerialized
         new UberId(5377, 1373).State().Write(state.Value);
     }
     else if (state.Name == "craftCutsceneState" && 0 < state.Value.Byte && state.Value.Byte < 3)
     {
         state.Write(new UberValue((byte)3));
         // Give diamond in the rough pickup.
         new UberId(23987, 14832).State().Write(new UberValue(true));
     }
     // the below is a fix for a vanilla bug where you can just miss getting voice if you
     else if (state.Name == "findToadQuestUberState" && state.Value.Int == 2 ||       // (a) skip the kwolok cutscene too fast
              state.Name == "cleanseWellspringQuestUberState" && state.Value.Int == 4 // (b) come to kwolok after wellspring and get the cutscenes stacked awkwardly
              )
     {
         Randomizer.InputUnlockCallback = () => {
             // this is really questionable!!
             var voiceState = new UberId(46462, 59806).State();
             if (!voiceState.Value.Bool)
             {
                 voiceState.Write(new UberValue(true));
                 InterOp.set_max_health(InterOp.get_max_health() + 10);
                 InterOp.set_max_energy(InterOp.get_max_energy() + 1);
                 InterOp.fill_health();
                 InterOp.fill_energy();
                 InterOp.save();
             }
             // should happen in both branches
             if (SeedController.Flags.Contains(Flag.ALLWISPS))
             {
                 HintsController.ProgressWithHints();
             }
         }
     }
     ;
 }
Ejemplo n.º 20
0
 public static void Int(UberId id, int val               = 1) => UberSet.Int(id, UberGet.value(id).Int + val);
Ejemplo n.º 21
0
 public static void Int(UberId id, int val) => id.State().Write(new UberValue(val));
Ejemplo n.º 22
0
 public static void Float(UberId id, float val) => id.State().Write(new UberValue(val));
Ejemplo n.º 23
0
 public UberStateCondition(UberId id, int?target)
 {
     Id     = id;
     Target = target;
 }
Ejemplo n.º 24
0
 public static void Byte(UberId id, byte val) => id.State().Write(new UberValue(val));
Ejemplo n.º 25
0
 public static void Toggle(UberId id) => UberSet.Bool(id, UberGet.value(id).Bool);
 public static UberStateCondition toCond(this UberId id, int?target = null) => new UberStateCondition(id, target);
Ejemplo n.º 27
0
 public static void Byte(UberId id, byte val             = 1) => UberSet.Byte(id, (byte)(UberGet.value(id).Byte + val));
Ejemplo n.º 28
0
 public Relic(ZoneType zone) : base(BonusType.Relic)
 {
     zoneId = ZoneToId[zone];
     Zone   = zone;
 }
 public static void Refresh(this UberId id) => InterOp.refresh_uber_state(id.GroupID, id.ID);
Ejemplo n.º 30
0
 public static void Float(UberId id, float val           = 1) => UberSet.Float(id, UberGet.value(id).Float + val);