Exemplo n.º 1
0
        public Task StoreImageAsync(string url, Il2CppStructArray <byte> data)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(Task.CompletedTask);
            }

            // copy the byte[] on calling thread to avoid issues
            var stream = new MemoryStream(data);

            return(Task.Run(() =>
            {
                try
                {
                    if (myFileDatabase.FileStorage.Exists(url))
                    {
                        return;
                    }

                    myFileDatabase.FileStorage.Upload(url, url, stream);

                    var newImageInfo = new StoredImageInfo {
                        Id = url, LastAccessed = DateTime.MinValue
                    };
                    myImageInfos.Upsert(newImageInfo);
                }
                catch (LiteException ex)
                {
                    if (MelonDebug.IsEnabled())
                    {
                        MelonLogger.Warning($"Database exception in image store handler: {ex}");
                    }
                }
            }));
        }
Exemplo n.º 2
0
        public void Broadcaster_Msg(Il2CppStructArray <byte> messageBytes)
        {
            var msg    = Deserialize <JSRM_Message>(messageBytes);
            var player = SessionData.playersWithMod.FirstOrDefault(p => p.PeerID == msg.PeerID);

            if (player == null)
            {
                var newPlayer = new ModPlayer()
                {
                    PeerID     = msg.PeerID.Value,
                    PlayerName = msg.PlayerName
                };

                SessionData.playersWithMod.Add(newPlayer);

                if (!string.IsNullOrEmpty(newPlayer.PlayerName))
                {
                    SessionData.Chat.UpdateChatLog($"{newPlayer.PlayerName} has joined as Player {newPlayer.PeerID}!", "Notification");
                }
                else
                {
                    SessionData.Chat.UpdateChatLog($"Player {newPlayer.PeerID} has joined!", "Notification");
                }

                JSRM_Msg();
                return;
            }


            //SessionData.Chat.UpdateChatLog($"{player.PlayerName} has joined as Player {player.PeerID}!", "Notification");
        }
Exemplo n.º 3
0
        public override void OnLocalDie(PlayerControl Victim, DeathReason Reason)
        {
            if (!IsLocalPlayer())
            {
                return;
            }
            if (Victim.PlayerId != Player.PlayerId)
            {
                return;
            }

            Infected.Remove(Player.PlayerId);
            var TargetIds = new Il2CppStructArray <byte>(Infected.Count);
            var Index     = 0;

            foreach (var InfectedId in Infected)
            {
                TargetIds[Index] = InfectedId;
                Index++;
            }
            ConsoleTools.Info(TargetIds.Count.ToString());

            ExtraNetwork.Send(CustomRPC.ZombieChainKill, Writer => {
                Writer.WriteBytesAndSize(TargetIds);
            });

            KillTargets(TargetIds);
        }
        public Task StoreImageAsync(string url, Il2CppStructArray <byte> data)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(Task.CompletedTask);
            }

            return(Task.Run(() =>
            {
                try
                {
                    if (myFileDatabase.FileStorage.Exists(url))
                    {
                        return;
                    }

                    myFileDatabase.FileStorage.Upload(url, url, new MemoryStream(data));

                    var newImageInfo = new StoredImageInfo {
                        Id = url, LastAccessed = DateTime.MinValue
                    };
                    myImageInfos.Upsert(newImageInfo);
                }
                catch (LiteException ex)
                {
                    if (Imports.IsDebugMode())
                    {
                        MelonLogger.LogWarning($"Database exception in image store handler: {ex}");
                    }
                }
            }));
        }
        public static void Postfix(MeetingHud __instance, ref Il2CppStructArray <byte> __result)
        {
            if (!TryGetSpecialRole(out Mayor mayor) || !mayor.hasRevealed)
            {
                return;
            }

            foreach (PlayerVoteArea playerVoteArea in __instance.playerStates)
            {
                if (!playerVoteArea.didVote)
                {
                    continue;
                }

                int num = playerVoteArea.votedFor + 1;
                if (num < 0 || num >= __result.Length)
                {
                    continue;
                }

                if (playerVoteArea.TargetPlayerId != mayor.Owner.PlayerId)
                {
                    continue;
                }

                extraVote      = num;
                __result[num] += 1;
                return;
            }
        }
Exemplo n.º 6
0
        public static void Postfix(MeetingHud __instance, ref Il2CppStructArray <byte> __result)
        {
            AbilityBlackmail[] blackmailAbilities = Ability.GetAllAbilities <AbilityBlackmail>();
            if (blackmailAbilities.Length == 0)
            {
                return;
            }

            foreach (PlayerVoteArea playerVoteArea in __instance.playerStates)
            {
                if (!playerVoteArea.didVote)
                {
                    continue;
                }

                int num = playerVoteArea.votedFor + 1;
                if (num < 0 || num >= __result.Length)
                {
                    continue;
                }

                if (blackmailAbilities.Any(blackmail => playerVoteArea.TargetPlayerId == blackmail.BlackmailedPlayer?.PlayerId))
                {
                    __result[num] -= (byte)(MayorPatches.MeetingHudCalculateVotesPatch.extraVote == num ? 2 : 1);
                }
            }
        }
Exemplo n.º 7
0
        public override void VRChat_OnUiManagerInit()
        {
            var calibrateButton = GameObject.Find("UserInterface/QuickMenu/ShortcutMenu/CalibrateButton")
                                  .GetComponent <Button>();
            var oldCalibrate = calibrateButton.onClick;

            calibrateButton.onClick = new Button.ButtonClickedEvent();
            calibrateButton.onClick.AddListener(new Action(() =>
            {
                if (IkTweaksSettings.FullBodyVrIk)
                {
                    if (IkTweaksSettings.CalibrateUseUniversal)
                    {
                        CalibrationManager.Clear();
                    }
                    else
                    {
                        CalibrationManager.Clear(VRCPlayer.field_Internal_Static_VRCPlayer_0.prop_ApiAvatar_0.id);
                    }
                }

                oldCalibrate.Invoke();
            }));

            var steamVrControllerManager = CalibrationManager.GetControllerManager();
            var puckPrefab = steamVrControllerManager.field_Public_ArrayOf_GameObject_0.First(it =>
                                                                                              it != steamVrControllerManager.field_Public_GameObject_1 && it != steamVrControllerManager.field_Public_GameObject_0);
            var newPucks = new Il2CppReferenceArray <GameObject>(5 + 6);
            var newUints = new Il2CppStructArray <uint>(5 + 6);

            for (var i = 0; i < 5; i++)
            {
                newPucks[i] = steamVrControllerManager.field_Public_ArrayOf_GameObject_0[i];
                newUints[i] = steamVrControllerManager.field_Private_ArrayOf_UInt32_0[i];
            }

            ourRandomPuck = puckPrefab;

            var trackersParent = puckPrefab.transform.parent;

            for (var i = 0; i < 6; i++)
            {
                var newPuck = Object.Instantiate(puckPrefab, trackersParent, true);
                newPuck.name = "Puck" + (i + 4);
                newPuck.GetComponent <SteamVR_TrackedObject>().field_Public_EnumNPublicSealedvaNoHmDe18DeDeDeDeDeUnique_0 = SteamVR_TrackedObject.EnumNPublicSealedvaNoHmDe18DeDeDeDeDeUnique.None;
                newPuck.SetActive(false);
                newPucks[i + 5] = newPuck;
                newUints[i + 5] = UInt32.MaxValue;
            }

            steamVrControllerManager.field_Public_ArrayOf_GameObject_0 = newPucks;
            steamVrControllerManager.field_Private_ArrayOf_UInt32_0    = newUints;

            // only one of them is the correct type, so just try all of them
            steamVrControllerManager.field_Private_Action_0.TryCast <SteamVR_Events.Action <VREvent_t> >()?.action?.Invoke(new VREvent_t());
            steamVrControllerManager.field_Private_Action_1.TryCast <SteamVR_Events.Action <VREvent_t> >()?.action?.Invoke(new VREvent_t());
            steamVrControllerManager.field_Private_Action_2.TryCast <SteamVR_Events.Action <VREvent_t> >()?.action?.Invoke(new VREvent_t());
        }
Exemplo n.º 8
0
        public static void Serialize(MessageWriter writer, Il2CppStructArray <byte> clientVersion, string name, ISet <Mod> mods = null)
        {
            writer.Write(clientVersion);
            writer.Write(name);

            if (mods != null)
            {
                ModList.Serialize(writer, mods);
            }
        }
Exemplo n.º 9
0
        public Chat_Message(Il2CppStructArray <byte> messageBytes)
        {
            string       json    = SerialisationUtil.Deserialise <string>(messageBytes);
            Chat_Message message = Read(json);

            PeerID           = message.PeerID;
            Sender           = message.Sender;
            Message          = message.Message;
            IsPrivateMessage = message.IsPrivateMessage;
        }
Exemplo n.º 10
0
        public static T ReadMessage <T>(Il2CppStructArray <byte> serializedMessage)
        {
            var modMessage = Il2CppSystem.Text.Encoding.Default.GetString(serializedMessage);

            return(JsonConvert.DeserializeObject <T>(modMessage));

            //throw new System.Exception("This code was broken in BTD6 update 27.0");
            // commented code below broke in update 27.0
            //return SerialisationUtil.Deserialise<T>(serializedMessage);
        }
Exemplo n.º 11
0
        public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable)
        {
            var il2cppArray = new Il2CppStructArray <byte>(data.Length);

            for (int i = 0; i < data.Length; i++)
            {
                il2cppArray[i] = data[i];
            }

            return(LoadImage_iCall(tex.Pointer, il2cppArray.Pointer, markNonReadable));
        }
Exemplo n.º 12
0
            public static void Postfix(MeetingHud __instance,
                                       [HarmonyArgument(0)] Il2CppStructArray <MeetingHud.VoterState> states,
                                       [HarmonyArgument(1)] GameData.PlayerInfo exiled,
                                       [HarmonyArgument(2)] bool tie)
            {
                // __instance.exiledPlayer = __instance.wasTie ? null : __instance.exiledPlayer;
                var exiledString = exiled == null ? "null" : exiled.PlayerName;

                PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"Exiled PlayerName = {exiledString}");

                PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"Was a tie = {tie}");
            }
Exemplo n.º 13
0
        public override void OnApplicationStart()
        {
            var bitmap = Icons.ResourceManager.GetObject("Alt");

            if (bitmap != null)
            {
                MemoryStream memory = new MemoryStream();
                (bitmap as Bitmap)?.Save(memory, ImageFormat.Png);
                Alt = memory.ToArray();
                memory.Close();
            }
        }
Exemplo n.º 14
0
        static bool Prefix(MeetingHud __instance, ref Il2CppStructArray <byte> __result)
        {
            Il2CppStructArray <byte> array = new Il2CppStructArray <byte>(11);

            for (int i = 0; i < __instance.playerStates.Length; i++)
            {
                PlayerVoteArea playerVoteArea = __instance.playerStates[i];
                if (playerVoteArea.didVote)
                {
                    int num = (int)(playerVoteArea.votedFor + 1);
                    if (num >= 0 && num < array.Length)
                    {
                        Il2CppStructArray <byte> array2 = array;
                        int num2 = num;
                        // Mayor count vote twice
                        if (Mayor.mayor != null && playerVoteArea.TargetPlayerId == (sbyte)Mayor.mayor.PlayerId)
                        {
                            array2[num2] += 2;
                        }
                        else
                        {
                            array2[num2] += 1;
                        }
                    }
                }
            }

            // Swapper swap votes
            PlayerVoteArea swapped1 = null;
            PlayerVoteArea swapped2 = null;

            foreach (PlayerVoteArea playerVoteArea in __instance.playerStates)
            {
                if (playerVoteArea.TargetPlayerId == Swapper.playerId1)
                {
                    swapped1 = playerVoteArea;
                }
                if (playerVoteArea.TargetPlayerId == Swapper.playerId2)
                {
                    swapped2 = playerVoteArea;
                }
            }

            if (swapped1 != null && swapped2 != null && swapped1.TargetPlayerId + 1 >= 0 && swapped1.TargetPlayerId + 1 < array.Length && swapped2.TargetPlayerId + 1 >= 0 && swapped2.TargetPlayerId + 1 < array.Length)
            {
                byte tmp = array[swapped1.TargetPlayerId + 1];
                array[swapped1.TargetPlayerId + 1] = array[swapped2.TargetPlayerId + 1];
                array[swapped2.TargetPlayerId + 1] = tmp;
            }

            __result = array;
            return(false);
        }
Exemplo n.º 15
0
        static void Postfix(byte FEFHEFFFBBI, Il2CppStructArray <byte> NMIBFBOGFCJ)
        {
            if (!Jester.jesterEnabled)
            {
                return;
            }

            if (PlayerController.getPlayerById(FEFHEFFFBBI).hasComponent("Jester"))
            {
                GameData.Instance.GetPlayerById(FEFHEFFFBBI).DEPNCDAJFGJ = null;
            }
        }
Exemplo n.º 16
0
 public static AssetBundleCreateRequest LoadFromMemoryAsync(Il2CppStructArray <byte> binary, uint crc)
 {
     if (binary == null)
     {
         throw new System.ArgumentException("The binary cannot be null or empty.");
     }
     if (LoadFromMemoryAsync_InternalDelegateField == null)
     {
         throw new System.NullReferenceException("The LoadFromMemoryAsync_InternalDelegateField cannot be null.");
     }
     System.IntPtr intPtr = LoadFromMemoryAsync_InternalDelegateField(IL2CPP.Il2CppObjectBaseToPtrNotNull(binary), crc);
     return((intPtr != System.IntPtr.Zero) ? new AssetBundleCreateRequest(intPtr) : null);
 }
Exemplo n.º 17
0
        public static Texture2D?LoadTexture(Il2CppStructArray <byte> bytes)
        {
            var texture = new Texture2D(2, 2, TextureFormat.ARGB32, true);
            var success = ourLoadTextureDelegate(texture.Pointer, bytes.Pointer, 1);

            if (success == 0)
            {
                Object.Destroy(texture);
                return(null);
            }

            return(texture);
        }
Exemplo n.º 18
0
        public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable)
        {
            var il2cppArray = new Il2CppStructArray <byte>(data.Length);

            for (int i = 0; i < data.Length; i++)
            {
                il2cppArray[i] = data[i];
            }

            var ret = ICallHelper.GetICall <d_LoadImage>("UnityEngine.ImageConversion::LoadImage")
                      .Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable);

            return(ret);
        }
Exemplo n.º 19
0
 public static void VotingComplete(
     Il2CppStructArray <byte> COMOIMMLKHF,
     GameData.LGBOMGHJELL EAFLJGMBLCH,
     bool EMBDDLIPBME)
 {
     if (EAFLJGMBLCH != null)
     {
         Process.Eject(EAFLJGMBLCH);
         Stats.Eject(EAFLJGMBLCH);
     }
     else
     {
         MOD.log.LogMessage("Skipado");
     }
 }
Exemplo n.º 20
0
        public void DC_Msg(Il2CppStructArray <byte> messageBytes)
        {
            var msg = new PeerDisconnectedMessage(messageBytes);

            var player = SessionData.playersWithMod.FirstOrDefault(p => p.PeerID == msg.PeerID);

            if (player != null)
            {
                SessionData.Chat.UpdateChatLog($"{player.PlayerName} has left.", "Notification");
                SessionData.playersWithMod.Remove(player);
                return;
            }

            SessionData.Chat.UpdateChatLog($"Player {msg.PeerID} has left.", "Notification");
        }
Exemplo n.º 21
0
        private static void Post_TryGetReplicator(ref bool __result, Il2CppStructArray <byte> bytes, ref IReplicator id, ref int packetIndex)
        {
            var pIndex = bytes[2];

            if (pIndex >= CustomReplicatorProvider.PACKET_OFFSET && Marshaller.SizeWithIDs == bytes.Length) //It's custom Replicator
            {
                //Read Replicator Index
                Buffer.BlockCopy(bytes, 0, SNet_Replication.m_ushortConverter, 0, 2);
                int replicatorIndex = SNet_Replication.m_ushortConverter[0];

                packetIndex = pIndex;

                __result = CustomReplicatorManager.TryGetReplicator(replicatorIndex, out id);
            }
        }
Exemplo n.º 22
0
 public static unsafe Texture2D loadTextureFromResources(string path)
 {
     try {
         Texture2D texture     = new Texture2D(2, 2, TextureFormat.ARGB32, true);
         Assembly  assembly    = Assembly.GetExecutingAssembly();
         Stream    stream      = assembly.GetManifestResourceStream(path);
         var       length      = stream.Length;
         var       byteTexture = new Il2CppStructArray <byte>(length);
         stream.Read(new Span <byte>(IntPtr.Add(byteTexture.Pointer, IntPtr.Size * 4).ToPointer(), (int)length));
         ImageConversion.LoadImage(texture, byteTexture, false);
         return(texture);
     } catch {
         System.Console.WriteLine("Error loading texture from resources: " + path);
     }
     return(null);
 }
 public static bool LoadImage(Texture2D tex, Il2CppStructArray <byte> data, bool markNonReadable)
 {
     if (tex == null)
     {
         throw new ArgumentException("The texture cannot be null.");
     }
     if (data == null)
     {
         throw new ArgumentException("The data cannot be null.");
     }
     if (LoadImageDelegateField == null)
     {
         throw new NullReferenceException("The LoadImageDelegateField cannot be null.");
     }
     return(LoadImageDelegateField(IL2CPP.Il2CppObjectBaseToPtr(tex), IL2CPP.Il2CppObjectBaseToPtr(data), markNonReadable));
 }
Exemplo n.º 24
0
            public static void Postfix(ref Il2CppStructArray <byte> __result)
            {
                ModList.Update();

                var handshake = MessageWriter.Get(SendOption.Reliable);

                handshake.Write(__result);

                ModdedHandshakeC2S.Serialize(
                    handshake,
                    ModList.Current.Count
                    );

                __result = handshake.ToByteArray(false);
                handshake.Recycle();
            }
Exemplo n.º 25
0
            public static bool Prefix(out Il2CppStructArray <byte> __result)
            {
                var handshake = MessageWriter.Get(SendOption.Reliable);

                ModdedHandshakeC2S.Serialize(
                    handshake,
                    Constants.GetBroadcastVersionBytes(),
                    SaveManager.PlayerName,
                    ModList.GetCurrent()
                    );

                __result = handshake.ToByteArray(false);
                handshake.Recycle();

                return(false);
            }
Exemplo n.º 26
0
 public static bool Prefix(MeetingHud __instance, ref Il2CppStructArray <byte> __result)
 {
     byte[] array = new byte[11];
     foreach (PlayerVoteArea player in __instance.HBDFFAHBIGI)
     {
         if (player.didVote)
         {
             int num = (int)(player.votedFor + 1);
             if (num >= 0 && num < array.Length)
             {
                 byte[] array2         = array;
                 int    num2           = num;
                 byte   voteImportance = player.NameText.Text == PlayerControlPatch.Mayor.nameText.Text ? (byte)2 : (byte)1;
                 array2[num2] += voteImportance;
             }
         }
     }
     __result = array;
     return(false);
 }
Exemplo n.º 27
0
            public static bool Prefix(MeetingHud __instance)
            {
                if (__instance.playerStates.All((ps) => ps.isDead || ps.didVote))
                {
                    var self = CalculateVotes(__instance);
                    Il2CppStructArray <byte> selfIl2 = self;
                    bool tie;


                    var maxIdx = Extensions.IndexOfMax(selfIl2, (Func <byte, int>)((p) => (int)p), out tie) - 1;
                    var exiled = GameData.Instance.AllPlayers.ToArray().FirstOrDefault(v => (int)v.PlayerId == maxIdx);
                    var array  = new byte[10];
                    foreach (var playerVoteArea in __instance.playerStates)
                    {
                        array[(int)playerVoteArea.TargetPlayerId] = playerVoteArea.GetState();
                    }
                    RpcVotingComplete(__instance, array, exiled, tie);
                }

                return(false);
            }
Exemplo n.º 28
0
        public Chat_Message(Il2CppStructArray <byte> messageBytes)
        {
            var          json    = Il2CppSystem.Text.Encoding.Default.GetString(messageBytes);
            Chat_Message message = Read(json);

            PeerID           = message.PeerID;
            Sender           = message.Sender;
            Message          = message.Message;
            IsPrivateMessage = message.IsPrivateMessage;

            //throw new System.Exception("This code was broken in BTD6 update 27.0");
            // commented code below broke in update 27.0
            //string json = SerialisationUtil.Deserialise<string>(messageBytes);

            // this code is commented because code above is broken

            /*Chat_Message message = Read(json);
             * PeerID = message.PeerID;
             * Sender = message.Sender;
             * Message = message.Message;
             * IsPrivateMessage = message.IsPrivateMessage;*/
        }
Exemplo n.º 29
0
            public static void Postfix(
                GameData __instance,
                [HarmonyArgument(0)] byte playerId,
                [HarmonyArgument(1)] ref Il2CppStructArray <byte> tasks
                )
            {
                var player = __instance.GetPlayerById(playerId);
                var role   = player.GetRole();

                if (role == null)
                {
                    return;
                }

                var list = new PlayerTaskList(player);

                role.AssignTasks(list, tasks.ToList().ConvertAll(i => new GameData.TaskInfo(i, 0)));

                Rpc <CustomSelectTasks> .Instance.Send(GameData.Instance, list);

                // we do not prevent setting default tasks to not break things like Impostor server
            }
        public static Il2CppStructArray <byte> EncodeToEXR(Texture2D tex, Texture2D.EXRFlags flags)
        {
            if (tex == null)
            {
                throw new ArgumentException("The texture cannot be null.");
            }
            if (EncodeToEXRDelegateField == null)
            {
                throw new NullReferenceException("The EncodeToEXRDelegateField cannot be null.");
            }
            Il2CppStructArray <byte> il2CppStructArray;
            IntPtr encodeToEXRDelegateField = EncodeToEXRDelegateField(IL2CPP.Il2CppObjectBaseToPtr(tex), flags);

            if (encodeToEXRDelegateField != IntPtr.Zero)
            {
                il2CppStructArray = new Il2CppStructArray <byte>(encodeToEXRDelegateField);
            }
            else
            {
                il2CppStructArray = null;
            }
            return(il2CppStructArray);
        }