Пример #1
0
 private static void ClearLocalBlips()
 {
     lock (BlipCleanup)
     {
         for (var index = BlipCleanup.Count - 1; index >= 0; index--)
         {
             var b = new Blip(BlipCleanup[index]);
             if (b.Exists())
             {
                 b.Delete();
             }
         }
         BlipCleanup.Clear();
     }
 }
Пример #2
0
        public void DecodeNativeCall(NativeData obj)
        {
            if (!NativeWhitelist.IsAllowed(obj.Hash) && obj.Internal == false)
            {
                throw new ArgumentException("Hash \"" + obj.Hash.ToString("X") + "\" is not allowed!");
            }
            else if (obj.Hash == (ulong)Hash.REQUEST_SCRIPT_AUDIO_BANK)
            {
                if (!SoundWhitelist.IsAllowed(((StringArgument)obj.Arguments[0]).Data))
                {
                    throw new ArgumentException("Such SoundSet is not allowed!");
                }
            }
            else if (obj.Hash == (ulong)Hash.PLAY_SOUND_FRONTEND)
            {
                if (!SoundWhitelist.IsAllowed(((StringArgument)obj.Arguments[1]).Data) || !SoundWhitelist.IsAllowed(((StringArgument)obj.Arguments[2]).Data))
                {
                    throw new ArgumentException("SoundSet/Name is not allowed!");
                }
            }


            var list = new List <InputArgument>();

            var nativeType = CheckNativeHash(obj.Hash);

            LogManager.DebugLog("NATIVE TYPE IS " + nativeType);
            int playerHealth = Game.Player.Character.Health;

            if (((int)nativeType & (int)Enums.NativeType.VehicleWarp) > 0)
            {
                int veh  = ((EntityArgument)obj.Arguments[1]).NetHandle;
                var item = NetEntityHandler.NetToStreamedItem(veh);
                if (item != null && !item.StreamedIn)
                {
                    NetEntityHandler.StreamIn(item);
                }
            }

            if (((int)nativeType & (int)Enums.NativeType.EntityWarp) > 0)
            {
                float x = ((FloatArgument)obj.Arguments[1]).Data;
                float y = ((FloatArgument)obj.Arguments[2]).Data;
                float z = ((FloatArgument)obj.Arguments[3]).Data;

                int interior;
                if ((interior = Function.Call <int>(Hash.GET_INTERIOR_AT_COORDS, x, y, z)) != 0)
                {
                    Function.Call((Hash)0x2CA429C029CCF247, interior); // LOAD_INTERIOR
                    Function.Call(Hash.SET_INTERIOR_ACTIVE, interior, true);
                    Function.Call(Hash.DISABLE_INTERIOR, interior, false);
                    if (Function.Call <bool>(Hash.IS_INTERIOR_CAPPED, interior))
                    {
                        Function.Call(Hash.CAP_INTERIOR, interior, false);
                    }
                }
            }

            var objectList = DecodeArgumentList(obj.Arguments.ToArray());

            var enumerable = objectList as object[] ?? objectList.ToArray();

            list.AddRange(enumerable.Select(ob => ob is OutputArgument ? (OutputArgument)ob : new InputArgument(ob)));

            if (enumerable.Any())
            {
                LogManager.DebugLog("NATIVE CALL ARGUMENTS: " + enumerable.Aggregate((f, s) => f + ", " + s) + ", RETURN TYPE: " + obj.ReturnType);
            }
            Model model = null;

            if (((int)nativeType & (int)Enums.NativeType.NeedsModel) > 0)
            {
                LogManager.DebugLog("REQUIRES MODEL");
                int position = 0;
                if (((int)nativeType & (int)Enums.NativeType.NeedsModel1) > 0)
                {
                    position = 0;
                }
                if (((int)nativeType & (int)Enums.NativeType.NeedsModel2) > 0)
                {
                    position = 1;
                }
                if (((int)nativeType & (int)Enums.NativeType.NeedsModel3) > 0)
                {
                    position = 2;
                }
                LogManager.DebugLog("POSITION IS " + position);
                var modelObj  = obj.Arguments[position];
                int modelHash = 0;
                if (modelObj is UIntArgument)
                {
                    modelHash = unchecked ((int)((UIntArgument)modelObj).Data);
                }
                else if (modelObj is IntArgument)
                {
                    modelHash = ((IntArgument)modelObj).Data;
                }
                LogManager.DebugLog("MODEL HASH IS " + modelHash);
                model = new Model(modelHash);

                if (model.IsValid)
                {
                    LogManager.DebugLog("MODEL IS VALID, REQUESTING");
                    model.Request(10000);
                }
            }

            if (((int)nativeType & (int)Enums.NativeType.NeedsAnimDict) > 0)
            {
                var animDict = ((StringArgument)obj.Arguments[1]).Data;
                Util.Util.LoadDict(animDict);
            }

            if (((int)nativeType & (int)Enums.NativeType.PtfxAssetRequest) != 0)
            {
                var animDict = ((StringArgument)obj.Arguments[0]).Data;

                Util.Util.LoadPtfxAsset(animDict);
                Function.Call(Hash._SET_PTFX_ASSET_NEXT_CALL, animDict);

                list.RemoveAt(0);
            }

            if (((int)nativeType & (int)Enums.NativeType.ReturnsEntity) > 0)
            {
                var entId = Function.Call <int>((Hash)obj.Hash, list.ToArray());
                lock (EntityCleanup) EntityCleanup.Add(entId);
                if (obj.ReturnType is IntArgument)
                {
                    SendNativeCallResponse(obj.Id, entId);
                }

                if (model != null)
                {
                    model.MarkAsNoLongerNeeded();
                }
                return;
            }

            if (nativeType == Enums.NativeType.ReturnsBlip)
            {
                var blipId = Function.Call <int>((Hash)obj.Hash, list.ToArray());
                lock (BlipCleanup) BlipCleanup.Add(blipId);
                if (obj.ReturnType is IntArgument)
                {
                    SendNativeCallResponse(obj.Id, blipId);
                }
                return;
            }

            if (((int)nativeType & (int)Enums.NativeType.TimeSet) > 0)
            {
                var newHours   = ((IntArgument)obj.Arguments[0]).Data;
                var newMinutes = ((IntArgument)obj.Arguments[1]).Data;
                Time = new TimeSpan(newHours, newMinutes, 0);
            }

            if (((int)nativeType & (int)Enums.NativeType.WeatherSet) > 0)
            {
                var newWeather = ((IntArgument)obj.Arguments[0]).Data;
                if (newWeather >= 0 && newWeather < Enums._weather.Length)
                {
                    Weather = Enums._weather[newWeather];
                    Function.Call((Hash)obj.Hash, Enums._weather[newWeather]);
                    return;
                }
            }

            var tmpArgs = obj.Arguments;

            if (!ReplacePointerNatives(obj.Hash, ref list, ref tmpArgs))
            {
                return;
            }

            if (obj.ReturnType == null)
            {
                Function.Call((Hash)obj.Hash, list.ToArray());
            }
            else
            {
                if (obj.ReturnType is IntArgument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <int>((Hash)obj.Hash, list.ToArray()));
                }
                else if (obj.ReturnType is UIntArgument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <uint>((Hash)obj.Hash, list.ToArray()));
                }
                else if (obj.ReturnType is StringArgument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <string>((Hash)obj.Hash, list.ToArray()));
                }
                else if (obj.ReturnType is FloatArgument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <float>((Hash)obj.Hash, list.ToArray()));
                }
                else if (obj.ReturnType is BooleanArgument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <bool>((Hash)obj.Hash, list.ToArray()));
                }
                else if (obj.ReturnType is Vector3Argument)
                {
                    SendNativeCallResponse(obj.Id, Function.Call <Vector3>((Hash)obj.Hash, list.ToArray()));
                }
            }

            if (((int)nativeType & (int)Enums.NativeType.PlayerSkinChange) > 0)
            {
                Ped PlayerChar = Game.Player.Character;
                PlayerChar.Style.SetDefaultClothes();
                PlayerChar.MaxHealth = 200;
                PlayerChar.Health    = playerHealth;
            }
        }