Ejemplo n.º 1
0
        public const NetDeliveryMethod SYNC_MESSAGE_TYPE = NetDeliveryMethod.UnreliableSequenced; // unreliable_sequenced

        #endregion


        public Main()
        {
            res    = UIMenu.GetScreenResolutionMantainRatio();
            screen = GTA.UI.Screen.Resolution;

            LogManager.RuntimeLog("\r\n>> [" + DateTime.Now + "] GTA Network Initialization.");

            World.DestroyAllCameras();

            CrossReference.EntryPoint = this;

            GameSettings   = Misc.GameSettings.LoadGameSettings();
            PlayerSettings = Util.Util.ReadSettings(GTANInstallDir + "\\settings.xml");

            CefUtil.DISABLE_CEF = PlayerSettings.DisableCEF;
            DebugInfo.ShowFps   = PlayerSettings.ShowFPS;
            EnableMediaStream   = PlayerSettings.MediaStream;
            EnableDevTool       = PlayerSettings.CEFDevtool;

            _threadJumping = new Queue <Action>();

            NetEntityHandler = new Streamer.Streamer();
            CameraManager    = new CameraManager();

            Watcher                = new SyncEventWatcher(this);
            VehicleSyncManager     = new UnoccupiedVehicleSync();
            WeaponInventoryManager = new WeaponManager();

            Npcs         = new Dictionary <string, SyncPed>();
            _tickNatives = new Dictionary <string, NativeData>();
            _dcNatives   = new Dictionary <string, NativeData>();

            EntityCleanup = new List <int>();
            BlipCleanup   = new List <int>();

            _emptyVehicleMods = new Dictionary <int, int>();
            for (var i = 0; i < 50; i++)
            {
                _emptyVehicleMods.Add(i, 0);
            }

            Chat             = new ClassicChat();
            Chat.OnComplete += ChatOnComplete;

            _backupChat = (ClassicChat)Chat;

            LogManager.RuntimeLog("Attaching OnTick loop.");

            Tick += OnTick;

            KeyDown += OnKeyDown;

            KeyUp += (sender, args) =>
            {
                if (args.KeyCode == Keys.Escape && _wasTyping)
                {
                    _wasTyping = false;
                }
            };

            _config = new NetPeerConfiguration("GTANETWORK")
            {
                Port = 8888, ConnectionTimeout = 30f
            };
            _config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);

            LogManager.RuntimeLog("Building menu.");
            _menuPool = new MenuPool();
            BuildMainMenu();

            //Function.Call(Hash._ENABLE_MP_DLC_MAPS, true); // _ENABLE_MP_DLC_MAPS
            Function.Call(Hash._USE_FREEMODE_MAP_BEHAVIOR, true); // _ENABLE_MP_DLC_MAPS
            Function.Call(Hash._LOAD_MP_DLC_MAPS);                // _LOAD_MP_DLC_MAPS / _USE_FREEMODE_MAP_BEHAVIOR

            MainMenuCamera = World.CreateCamera(new Vector3(743.76f, 1070.7f, 350.24f), new Vector3(), GameplayCamera.FieldOfView);
            MainMenuCamera.PointAt(new Vector3(707.86f, 1228.09f, 333.66f));

            RelGroup       = World.AddRelationshipGroup("SYNCPED");
            FriendRelGroup = World.AddRelationshipGroup("SYNCPED_TEAMMATES");

            RelGroup.SetRelationshipBetweenGroups(Game.Player.Character.RelationshipGroup, Relationship.Pedestrians, true);
            FriendRelGroup.SetRelationshipBetweenGroups(Game.Player.Character.RelationshipGroup, Relationship.Companion, true);

            SocialClubName = Game.Player.Name;

            LogManager.RuntimeLog("Getting welcome message.");
            GetWelcomeMessage();

            var t = new Thread(UpdateSocialClubAvatar)
            {
                IsBackground = true
            };

            t.Start();

            //Function.Call(Hash.SHUTDOWN_LOADING_SCREEN);

            Audio.SetAudioFlag(AudioFlags.LoadMPData, true);
            Audio.SetAudioFlag(AudioFlags.DisableBarks, true);
            Audio.SetAudioFlag(AudioFlags.DisableFlightMusic, true);
            Audio.SetAudioFlag(AudioFlags.PoliceScannerDisabled, true);
            Audio.SetAudioFlag(AudioFlags.OnlyAllowScriptTriggerPoliceScanner, true);
            Function.Call(Hash._FORCE_AMBIENT_SIREN, false); //_FORCE_AMBIENT_SIREN

            // disable fire dep dispatch service
            Function.Call(Hash.ENABLE_DISPATCH_SERVICE, 4, false); // ENABLE_DISPATCH_SERVICE

            GlobalVariable.Get(2576573).Write(1);                  //Enable MP cars?

            LogManager.RuntimeLog("Reading whitelists.");
            ThreadPool.QueueUserWorkItem(delegate
            {
                NativeWhitelist.Init();
                SoundWhitelist.Init();
            });

            //var fetchThread = new Thread((ThreadStart) delegate
            //{
            //    var list = Process.GetProcessesByName("GameOverlayUI");
            //    if (!list.Any()) return;
            //    for (var index = list.Length - 1; index >= 0; index--) list[index].Kill();
            //});

            //fetchThread.Start();

            if (!PlayerSettings.DisableCEF)
            {
                LogManager.RuntimeLog("Initializing CEF.");
                CEFManager.InitializeCef();
            }

            LogManager.RuntimeLog("Rebuilding Server Browser.");
            RebuildServerBrowser();

            LogManager.RuntimeLog("Checking game files integrity.");
            IntegrityCheck();
        }
Ejemplo n.º 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;
            }
        }