Esempio n. 1
0
    void Start()
    {
        checkAndLoadSpriteDump();
        VillagerRamOffset.text      = VillagerRootAddress;
        VillagerHouseRamOffset.text = VillagerHouseAddress;

        for (int i = 0; i < TenVillagers.Length; ++i)
        {
            int tmpVal = i; // non indexed so it doesn't screw up
            TenVillagers[i].GetComponent <Button>().onClick.AddListener(delegate { LoadVillager(tmpVal); });
        }

        VillagerPhrase.onValueChanged.AddListener(delegate { loadedVillager.CatchPhrase = VillagerPhrase.text; });
        MovingOutToggle.onValueChanged.AddListener(delegate { loadedVillager.MovingOut = MovingOutToggle.isOn; });
        ForceMoveOutToggle.onValueChanged.AddListener(delegate {
            ushort[] flags = loadedVillager.GetEventFlagsSave();
            flags[24]      = ForceMoveOutToggle.isOn ? (ushort)1 : (ushort)0;
            loadedVillager.SetEventFlagsSave(flags);
        });

        VillagerRamOffset.onValueChanged.AddListener(delegate { VillagerRootAddress = VillagerRamOffset.text; });
        VillagerHouseRamOffset.onValueChanged.AddListener(delegate { VillagerHouseAddress = VillagerHouseRamOffset.text; });

        DataButton.interactable = false;
    }
Esempio n. 2
0
    private void loadVillagerData(Villager2 v, VillagerHouse vh, bool raw = false)
    {
        try
        {
            Villager2     newV  = v;
            VillagerHouse newVH = vh;
            VillagerHouse loadedVillagerHouse = GetCurrentLoadedVillagerHouse(); // non indexed so search for the correct one
            int           index = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
            if (!raw && index != -1)
            {
                newV.SetMemories(loadedVillager.GetMemories());
                newV.SetEventFlagsSave(loadedVillager.GetEventFlagsSave());
                newV.CatchPhrase = GameInfo.Strings.GetVillagerDefaultPhrase(newV.InternalName);
            }

            if (index == -1)
            {
                //inject to earliest available house
                foreach (var house in loadedVillagerHouses)
                {
                    if (house.NPC1 == -1)
                    {
                        loadedVillagerHouse = house;
                        index      = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
                        house.NPC1 = (sbyte)currentlyLoadedVillagerIndex;
                        break;
                    }
                }

                if (index == -1)
                {
                    throw new Exception("Selected villager has no house, and no houses are available.");
                }
            }

            // check if they are moving in
            if (loadedVillagerHouse.WallUniqueID == WallType.HouseWallNForSale || loadedVillagerHouse.WallUniqueID == WallType.HouseWallNSoldOut)
            {
                loadedVillagerHouse.WallUniqueID = newVH.WallUniqueID;
            }
            if (checkIfMovingIn(loadedVillagerHouse))
            {
                newVH = combineHouseOrders(newVH, loadedVillagerHouse);
            }
            newVH.NPC1 = loadedVillagerHouse.NPC1;

            loadedVillagerHouses[index] = newVH;
            loadedVillager = newV;
            loadedVillagerShellsList[currentlyLoadedVillagerIndex] = newV;

            TenVillagers[currentlyLoadedVillagerIndex].texture = SpriteBehaviour.PullTextureFromParser(villagerSprites, newV.InternalName);
            setCurrentVillager(); // where the magic happens
            VillagerToUI(loadedVillager);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
            PopupHelper.CreateError(e.Message, 2f);
        }
    }
Esempio n. 3
0
    void Start()
    {
        checkAndLoadSpriteDump();
        VillagerRamOffset.text      = VillagerRootAddress;
        VillagerHouseRamOffset.text = VillagerHouseAddress;

        for (int i = 0; i < TenVillagers.Length; ++i)
        {
            int tmpVal = i; // non indexed so it doesn't screw up
            TenVillagers[i].GetComponent <Button>().onClick.AddListener(delegate { LoadVillager(tmpVal); });
        }

        VillagerPhrase.onValueChanged.AddListener(delegate { loadedVillager.CatchPhrase = VillagerPhrase.text; });
        VillagerFriendship.onValueChanged.AddListener(delegate { VillagerFriendship.text = setCurrentPlayerFriendship(int.Parse(VillagerFriendship.text)).ToString(); });
        MovingOutToggle.onValueChanged.AddListener(delegate {
            ushort[] flags = loadedVillager.GetEventFlagsSave();
            flags[5]       = 1; // flag 5 = MoveInCompletion
            flags[9]       = 0; // flag 9 = AbandonedHouse
            loadedVillager.SetEventFlagsSave(flags);
            loadedVillager.MovingOut = MovingOutToggle.isOn;
        });
        ForceMoveOutToggle.onValueChanged.AddListener(delegate {
            if (ForceMoveOutToggle.isOn)
            {
                loadedVillager.MovingOut = true;
            }
            ushort[] flags = loadedVillager.GetEventFlagsSave();
            flags[24]      = ForceMoveOutToggle.isOn ? (ushort)1 : (ushort)0; // flag 24 = ForceMoveOut
            flags[5]       = 1;                                               // flag 5 = MoveInCompletion
            flags[9]       = 0;                                               // flag 9 = AbandonedHouse
            loadedVillager.SetEventFlagsSave(flags);
        });

        VillagerRamOffset.onValueChanged.AddListener(delegate { VillagerRootAddress = VillagerRamOffset.text; });
        VillagerHouseRamOffset.onValueChanged.AddListener(delegate { VillagerHouseAddress = VillagerHouseRamOffset.text; });

        DataButton.interactable = false;
    }
Esempio n. 4
0
    private void loadVillagerData(Villager2 v, VillagerHouse vh, bool raw = false)
    {
        try
        {
            Villager2     newV  = v;
            VillagerHouse newVH = vh;
            if (!raw)
            {
                newV.SetMemories(loadedVillager.GetMemories());
                newV.SetEventFlagsSave(loadedVillager.GetEventFlagsSave());
                newV.CatchPhrase = GameInfo.Strings.GetVillagerDefaultPhrase(newV.InternalName);
            }

            VillagerHouse loadedVillagerHouse = GetCurrentLoadedVillagerHouse(); // non indexed so search for the correct one
            int           index = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
            if (index == -1)
            {
                throw new Exception("The villager being replaced doesn't have a house on your island.");
            }

            // check if they are moving in
            if (checkIfMovingIn(loadedVillagerHouse))
            {
                newVH = combineHouseOrders(newVH, loadedVillagerHouse);
            }
            newVH.NPC1 = loadedVillagerHouse.NPC1;

            loadedVillagerHouses[index] = newVH;
            loadedVillager = newV;
            loadedVillagerShellsList[currentlyLoadedVillagerIndex] = newV;

            TenVillagers[currentlyLoadedVillagerIndex].texture = SpriteBehaviour.PullTextureFromParser(villagerSprites, newV.InternalName);
            setCurrentVillager(); // where the magic happens
            VillagerToUI(loadedVillager);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
            PopupHelper.CreateError(e.Message, 2f);
        }
    }
Esempio n. 5
0
        public async Task <bool> InjectVillager(VillagerRequest vr, CancellationToken token)
        {
            var vd    = vr.Item;
            var index = vr.Index;

            if (VillagerHouses == null || VillagerShells == null || Connection == null || Bot == null)
            {
                return(false);
            }

            VillagerHouse?house = VillagerHouses.Find(x => x.NPC1 == (sbyte)index);

            if (house == null)
            {
                LogUtil.LogInfo($"House {index} requested but does not exist. Injecting to first available house", Bot.Config.IP);
                for (int i = 0; i < VillagerHouses.Count; ++i)
                {
                    if (VillagerHouses[i].HouseStatus == 0)
                    {
                        house = VillagerHouses[i];
                        break;
                    }
                }
            }

            if (house == null)
            {
                LogUtil.LogInfo($"No house found to inject to.", Bot.Config.IP);
                return(false);
            }

            var houseIndex = VillagerHouses.IndexOf(house);

            var villagerToInject   = (byte[])vd.Villager.Clone();
            var villagerAsVillager = new Villager2(villagerToInject);

            LogUtil.LogInfo($"Beginning injection for: {GameInfo.Strings.GetVillager(villagerAsVillager.InternalName)}", Bot.Config.IP);

            // update moving out state
            villagerAsVillager.MoveType  = 0;
            villagerAsVillager.MovingOut = true;
            ushort[] flags = villagerAsVillager.GetEventFlagsSave();
            flags[05] = 1; // flag 5 = MoveInCompletion
            flags[09] = 0; // flag 9 = AbandonedHouse
            flags[24] = 0; // flag 24 = ForceMoveOut
            villagerAsVillager.SetEventFlagsSave(flags);

            var houseToInject = (byte[])vd.House.Clone();
            var houseAsHouse  = new VillagerHouse(houseToInject)
            {
                HouseStatus = house.HouseStatus == 0 ? 2 : house.HouseStatus,
                NPC1        = house.NPC1 == -1 ? (sbyte)index : house.NPC1,
                NPC2        = house.NPC2
            };

            // inject villager
            await Connection.WriteBytesAsync(villagerAsVillager.Data, (uint)OffsetHelper.VillagerAddress + ((uint)index *Villager2.SIZE), token).ConfigureAwait(false);

            await Connection.WriteBytesAsync(villagerAsVillager.Data, (uint)OffsetHelper.VillagerAddress + ((uint)index *Villager2.SIZE) + (uint)OffsetHelper.BackupSaveDiff, token).ConfigureAwait(false);

            // inject house
            await Connection.WriteBytesAsync(houseAsHouse.Data, (uint)OffsetHelper.VillagerHouseAddress + ((uint)houseIndex *VillagerHouse.SIZE), token).ConfigureAwait(false);

            await Connection.WriteBytesAsync(houseAsHouse.Data, (uint)OffsetHelper.VillagerHouseAddress + ((uint)houseIndex *VillagerHouse.SIZE) + (uint)OffsetHelper.BackupSaveDiff, token).ConfigureAwait(false);

            LogUtil.LogInfo($"Villager injection complete.", Bot.Config.IP);
            vr.OnFinish?.Invoke(true);
            return(true);
        }