public void Render(MapObject mapObject) { MapPoint cellPoint = new MapPoint(0, 0, 0); Map map = new Map(1, MapSize.One); map[cellPoint] = new MapCell(new MapPlace(), null); if (mapObject is MapPlace) { map[cellPoint].Place = mapObject as MapPlace; } if (mapObject is MapWall) { map[cellPoint].SetWall(MapDirection.North, mapObject as MapWall); map[cellPoint].SetWall(MapDirection.East, mapObject as MapWall); map[cellPoint].SetWall(MapDirection.West, mapObject as MapWall); map[cellPoint].SetWall(MapDirection.South, mapObject as MapWall); } MapState mapState = new MapState(map); if (mapObject is MapActiveObject) { mapState.AddActiveObject(mapObject as MapActiveObject, cellPoint); } GameMap gameMap = new GameMap(mapState); Renderer.SetMap(gameMap, new MapCellRange(cellPoint, cellPoint)); Renderer.Render(); }
public void HandleInput(double frameTime) { //Update model model.MousePosition = input.WindowToWorldPosition(input.MouseWindowPosition, display, false); //Change in mouse cursor position in world coordinates Vector change = input.WindowToWorldPosition(input.MouseWindowPositionChange, display, true); //Navigation if (input.MouseButtonPressed(HMouseButton.LeftButton) && input.MouseButtonPressed(HMouseButton.RightButton)) { display.Zoom -= change.Y; if (display.Zoom < 5) display.Zoom = 5; else if (display.Zoom > 1000) display.Zoom = 1000; model.Zoom = display.Zoom; } else if (input.MouseButtonPressed(HMouseButton.RightButton)) { display.CameraX -= change.X; display.CameraY -= change.Y; } //Drawing else if (input.MouseButtonPressed(HMouseButton.LeftButton)) { //Mouse click if (!lmbDown) { lmbDown = true; if (!string.IsNullOrEmpty(model.CurrentObject) && model.CurrentTool == EditorModel.Tool.CreateObject && model.TileMap != null) { MapObject o = new MapObject(model.ResourceManager.GetObjectDescriptor(model.CurrentObject),model.ResourceManager, renderer, new Vector(model.MousePosition.X, model.MousePosition.Y)); model.Objects.Add(o); model.Changed = true; Log.Write("Spawned " + model.CurrentObject + " at " + model.MousePosition); } else if (model.CurrentTool == EditorModel.Tool.SelectObject) { bool anythingSelected = false; foreach (MapObject o in model.Objects) { if (model.MousePosition.X >= o.Left && model.MousePosition.X <= o.Right && model.MousePosition.Y >= o.Bottom && model.MousePosition.Y <= o.Top) { model.SelectedObject = o; anythingSelected = true; } } if (!anythingSelected) model.SelectedObject = null; } } //Mouse button down switch (model.CurrentTool) { case EditorModel.Tool.DrawTile: if (model.TileMap != null && model.CurrentTile != null) { Vector tilePos; try { if (model.DrawToLayer - 1 >= 0 && model.DrawToLayer <= model.TileMap.Layers) { tilePos = model.TileMap.WorldToTilePosition(input.WindowToWorldPosition(input.MouseWindowPosition,display, false)); model.TileMap.SetTile((int)tilePos.X, (int)tilePos.Y, model.DrawToLayer-1, model.CurrentTile); } } catch (IndexOutOfRangeException e) { Log.Write("Attempted to set tile outside the boundaries: " + e.Message, Log.WARNING); } model.Changed = true; } break; case EditorModel.Tool.SelectObject: //Move objects if (model.SelectedObject != null) { double x = model.SelectedObject.Position.X + change.X, y = model.SelectedObject.Position.Y + change.Y; model.SelectedObject.Position.X = x; model.SelectedObject.Position.Y = y; if (model.SnapToGrid) { int nx = (int)Math.Round((x+model.GridOffsetX)/(double)model.GridSizeX); x = nx * model.GridSizeX + model.GridOffsetX; int ny = (int)Math.Round((y+model.GridOffsetY)/(double)model.GridSizeY); y = ny * model.GridSizeY + model.GridOffsetY; } model.SelectedObject.DisplayPosition.X = x; model.SelectedObject.DisplayPosition.Y = y; model.Changed = true; //Pan the window if neccesary if (input.MouseWindowPosition.X >= display.WindowWidth-boundarySize) { display.CameraX += (boundarySize-(display.WindowWidth-input.MouseWindowPosition.X))*frameTime; if (display.CameraX + display.ViewportWidth / 2 < model.TileMap.Right) model.SelectedObject.DisplayPosition.X += (boundarySize-(display.WindowWidth-input.MouseWindowPosition.X))*frameTime; } if (input.MouseWindowPosition.X <= boundarySize) { display.CameraX -= (boundarySize - input.MouseWindowPosition.X)*frameTime; if (display.CameraX - display.ViewportWidth / 2 > model.TileMap.Left) model.SelectedObject.DisplayPosition.X -= (boundarySize - input.MouseWindowPosition.X)*frameTime; } if (input.MouseWindowPosition.Y >= display.WindowHeight-boundarySize) { display.CameraY -= (boundarySize-(display.WindowHeight-input.MouseWindowPosition.Y))*frameTime; if (display.CameraY - display.ViewportHeight / 2 > model.TileMap.Bottom) model.SelectedObject.DisplayPosition.Y -= (boundarySize-(display.WindowHeight-input.MouseWindowPosition.Y))*frameTime; } if (input.MouseWindowPosition.Y <= boundarySize) { display.CameraY += (boundarySize - input.MouseWindowPosition.Y)*frameTime; if (display.CameraY + display.ViewportHeight / 2 < model.TileMap.Top) model.SelectedObject.DisplayPosition.Y += (boundarySize - input.MouseWindowPosition.Y)*frameTime; } } break; } } else { if (lmbDown && model.CurrentTool == EditorModel.Tool.SelectObject) { if (model.SelectedObject != null) model.SelectedObject.Position.Set(model.SelectedObject.DisplayPosition); } lmbDown = false; } //Keypresses if (model.CurrentTool == EditorModel.Tool.SelectObject) { if (input.KeyPressed(HKey.Delete) && model.SelectedObject != null) { model.Objects.Remove(model.SelectedObject); model.SelectedObject = null; } } if (model.TileMap != null) { if (display.CameraY + display.ViewportHeight / 2 > model.TileMap.Top) display.CameraY = model.TileMap.Top - display.ViewportHeight/2; if (display.CameraY - display.ViewportHeight / 2 < model.TileMap.Bottom) display.CameraY = model.TileMap.Bottom + display.ViewportHeight/2; if (display.CameraX + display.ViewportWidth / 2 > model.TileMap.Right) display.CameraX = model.TileMap.Right - display.ViewportWidth/2; if (display.CameraX - display.ViewportWidth / 2 < model.TileMap.Left) display.CameraX = model.TileMap.Left + display.ViewportWidth/2; } }
public void OnTick(object sender, EventArgs e) { // Load maps from "AutoloadMaps" if (!_hasLoaded) { AutoloadMaps(); _hasLoaded = true; } _menuPool.ProcessMenus(); PropStreamer.Tick(); if (PropStreamer.EntityCount > 0 || PropStreamer.RemovedObjects.Count > 0 || PropStreamer.Markers.Count > 0 || PropStreamer.Pickups.Count > 0) { _currentEntitiesItem.Enabled = true; _currentEntitiesItem.Description = ""; } else { _currentEntitiesItem.Enabled = false; _currentEntitiesItem.Description = Translation.Translate("There are no current entities."); } if (Game.IsControlPressed(0, Control.LookBehind) && Game.IsControlJustPressed(0, Control.FrontendLb) && !_menuPool.IsAnyMenuOpen() && _settings.Gamepad) { _mainMenu.Visible = !_mainMenu.Visible; } if (_settings.AutosaveInterval != -1 && DateTime.Now.Subtract(_lastAutosave).Minutes >= _settings.AutosaveInterval && PropStreamer.EntityCount > 0 && _changesMade > 0 && PropStreamer.EntityCount != _loadedEntities) { SaveMap("Autosave.xml", MapSerializer.Format.NormalXml); _lastAutosave = DateTime.Now; } if (_currentObjectsMenu.Visible) { if (Game.IsControlJustPressed(0, Control.PhoneLeft)) { if (_currentObjectsMenu.CurrentSelection <= 100) { _currentObjectsMenu.CurrentSelection = 0; } else { _currentObjectsMenu.CurrentSelection -= 100; } } if (Game.IsControlJustPressed(0, Control.PhoneRight)) { if (_currentObjectsMenu.CurrentSelection >= _currentObjectsMenu.Size - 101) { _currentObjectsMenu.CurrentSelection = _currentObjectsMenu.Size - 1; } else { _currentObjectsMenu.CurrentSelection += 100; } } } // // BELOW ONLY WHEN MAP EDITOR IS ACTIVE // if (!IsInFreecam) return; if(_settings.InstructionalButtons && !_objectsMenu.Visible) Function.Call(Hash._0x0DF606929C105BE1, _scaleform.Handle, 255, 255, 255, 255, 0); Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.CharacterWheel); Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.SelectWeapon); Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.FrontendPause); Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.NextCamera); Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.Phone); Function.Call(Hash.HIDE_HUD_AND_RADAR_THIS_FRAME); if (Game.IsControlJustPressed(0, Control.Enter) && !_isChoosingObject) { var oldType = _currentObjectType; _currentObjectType = ObjectTypes.Prop; if(oldType != _currentObjectType) RedrawObjectsMenu(type: _currentObjectType); _isChoosingObject = true; _snappedProp = null; _selectedProp = null; _menuPool.CloseAllMenus(); if (_quitWithSearchVisible && oldType == _currentObjectType) { _searchMenu.Visible = true; OnIndexChange(_searchMenu, _searchMenu.CurrentSelection); } else { _objectsMenu.Visible = true; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } _objectsMenu.Subtitle.Caption = "~b~" + Translation.Translate("PLACE") + " " + _currentObjectType.ToString().ToUpper(); } if (Game.IsControlJustPressed(0, Control.NextCamera) && !_isChoosingObject) { var oldType = _currentObjectType; _currentObjectType = ObjectTypes.Vehicle; if (oldType != _currentObjectType) RedrawObjectsMenu(type: _currentObjectType); _isChoosingObject = true; _snappedProp = null; _selectedProp = null; _menuPool.CloseAllMenus(); if (_quitWithSearchVisible && oldType == _currentObjectType) { _searchMenu.Visible = true; OnIndexChange(_searchMenu, _searchMenu.CurrentSelection); } else { _objectsMenu.Visible = true; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } _objectsMenu.Subtitle.Caption = "~b~" + Translation.Translate("PLACE") + " " + _currentObjectType.ToString().ToUpper(); } if (Game.IsControlJustPressed(0, Control.FrontendPause) && !_isChoosingObject) { var oldType = _currentObjectType; _currentObjectType = ObjectTypes.Ped; if (oldType != _currentObjectType) RedrawObjectsMenu(type: _currentObjectType); _isChoosingObject = true; _snappedProp = null; _selectedProp = null; _menuPool.CloseAllMenus(); if (_quitWithSearchVisible && oldType == _currentObjectType) { _searchMenu.Visible = true; OnIndexChange(_searchMenu, _searchMenu.CurrentSelection); } else { _objectsMenu.Visible = true; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } _objectsMenu.Subtitle.Caption = "~b~" + Translation.Translate("PLACE") + " " + _currentObjectType.ToString().ToUpper(); } if (Game.IsControlJustPressed(0, Control.Phone) && !_isChoosingObject && !_menuPool.IsAnyMenuOpen()) { _snappedProp = null; _selectedProp = null; _snappedMarker = null; _selectedMarker = null; var tmpMark = new Marker() { Red = Color.Yellow.R, Green = Color.Yellow.G, Blue = Color.Yellow.B, Alpha = Color.Yellow.A, Scale = new Vector3(0.75f, 0.75f, 0.75f), Type = MarkerType.UpsideDownCone, Position = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character), Id = _markerCounter, }; PropStreamer.Markers.Add(tmpMark); _snappedMarker = tmpMark; _markerCounter++; _changesMade++; AddItemToEntityMenu(_snappedMarker); } if (Game.IsControlJustPressed(0, Control.ThrowGrenade) && !_isChoosingObject && !_menuPool.IsAnyMenuOpen()) { _snappedProp = null; _selectedProp = null; _snappedMarker = null; _selectedMarker = null; var pickup = PropStreamer.CreatePickup(new Model((int) ObjectDatabase.PickupHash.Parachute), VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character), 0f, 100, false); _changesMade++; AddItemToEntityMenu(pickup); _snappedProp = new Prop(pickup.ObjectHandle); } if (_isChoosingObject) { if (_previewProp != null) { _previewProp.Rotation = _previewProp.Rotation + (_zAxis ? new Vector3(0f, 0f, 2.5f) : new Vector3(2.5f, 0f, 0f)); if (_zAxis && IsPed(_previewProp)) _previewProp.Heading = _previewProp.Rotation.Z; DrawEntityBox(_previewProp, Color.White); } if (Game.IsControlJustPressed(0, Control.SelectWeapon)) _zAxis = !_zAxis; if (_objectPreviewCamera == null) { _objectPreviewCamera = World.CreateCamera(new Vector3(1200.016f, 4000.998f, 86.05062f), new Vector3(0f, 0f, 0f), 60f); _objectPreviewCamera.PointAt(_objectPreviewPos); } if (Game.IsControlPressed(0, Control.MoveDownOnly)) { _objectPreviewCamera.Position -= new Vector3(0f, 0.5f, 0f); } if (Game.IsControlPressed(0, Control.MoveUpOnly)) { _objectPreviewCamera.Position += new Vector3(0f, 0.5f, 0f); } if (Game.IsControlJustPressed(0, Control.PhoneLeft)) { if (_objectsMenu.CurrentSelection <= 100) { _objectsMenu.CurrentSelection = 0; OnIndexChange(_objectsMenu, 0); } else { _objectsMenu.CurrentSelection -= 100; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } } if (Game.IsControlJustPressed(0, Control.PhoneRight)) { if (_objectsMenu.CurrentSelection >= _objectsMenu.Size - 101) { _objectsMenu.CurrentSelection = _objectsMenu.Size - 1; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } else { _objectsMenu.CurrentSelection += 100; OnIndexChange(_objectsMenu, _objectsMenu.CurrentSelection); } } World.RenderingCamera = _objectPreviewCamera; if (Game.IsControlJustPressed(0, Control.PhoneCancel) && !_searchResultsOn) { _isChoosingObject = false; _objectsMenu.Visible = false; _previewProp?.Delete(); } if (Game.IsControlJustPressed(0, Control.PhoneCancel) && _searchResultsOn) { //RedrawObjectsMenu(type: _currentObjectType); _searchMenu.Visible = false; _objectsMenu.Visible = true; OnIndexChange(_objectsMenu, 0); _searchResultsOn = false; _objectsMenu.Subtitle.Caption = "~b~" + Translation.Translate("PLACE") + " " + _currentObjectType.ToString().ToUpper(); } if (Game.IsControlJustPressed(0, Control.Jump)) { string query = Game.GetUserInput(255); if(String.IsNullOrWhiteSpace(query)) return; if (query[0] == ' ') query = query.Remove(0, 1); _objectsMenu.Visible = false; RedrawSearchMenu(query, _currentObjectType); if(_searchMenu.Size != 0) OnIndexChange(_searchMenu, 0); _searchMenu.Subtitle.Caption = "~b~" + Translation.Translate("SEARCH RESULTS FOR") + " \"" + query.ToUpper() + "\""; _searchMenu.Visible = true; _searchResultsOn = true; } return; } World.RenderingCamera = _mainCamera; var res = UIMenu.GetScreenResolutionMantainRatio(); var safe = UIMenu.GetSafezoneBounds(); if (_settings.PropCounterDisplay) { const int interval = 45; new UIResText(Translation.Translate("PICKUPS"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - (90 + (5 * interval))), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.Pickups.Count.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - (102 + (5 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - (100 + (5 * interval))), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); new UIResText(Translation.Translate("MARKERS"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - (90 + (4 * interval))), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.Markers.Count.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - (102 + (4 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - (100 + (4 * interval))), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); new UIResText(Translation.Translate("WORLD"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - (90 + (3 * interval))), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.RemovedObjects.Count.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - (102 + (3 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - (100 + (3 * interval))), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); new UIResText(Translation.Translate("PROPS"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - (90 + (2*interval))), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.PropCount.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - (102 + (2 * interval))), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - (100 + (2 * interval))), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); new UIResText(Translation.Translate("VEHICLES"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - (90 + interval)), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.Vehicles.Count.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - (102 + interval)), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - (100 + interval)), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); new UIResText(Translation.Translate("PEDS"), new Point((int)(res.Width) - safe.X - 90, (int)(res.Height) - safe.Y - 90), 0.3f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new UIResText(PropStreamer.Peds.Count.ToString(), new Point((int)(res.Width) - safe.X - 20, (int)(res.Height) - safe.Y - 102), 0.5f, Color.White, Font.ChaletLondon, UIResText.Alignment.Right).Draw(); new Sprite("timerbars", "all_black_bg", new Point((int)(res.Width) - safe.X - 248, (int)(res.Height) - safe.Y - 100), new Size(250, 37), 0f, Color.FromArgb(180, 255, 255, 255)).Draw(); } int wi = (int)(res.Width*0.5); int he = (int)(res.Height * 0.5); Entity hitEnt = VectorExtensions.RaycastEntity(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation); if (_settings.CrosshairType == CrosshairType.Crosshair) { var crossColor = _crosshairPath; if (hitEnt != null && hitEnt.Handle != 0 && !PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) crossColor = _crosshairBluePath; else if (hitEnt != null && hitEnt.Handle != 0 && PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) crossColor = _crosshairYellowPath; Sprite.DrawTexture(crossColor, new Point(wi - 15, he - 15), new Size(30, 30)); } //Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.CharacterWheel); //Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.SelectWeapon); //Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)Control.FrontendPause); Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0); Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)Control.LookLeftRight); Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)Control.LookUpDown); Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)Control.CursorX); Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)Control.CursorY); Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)Control.FrontendPauseAlternate); var mouseX = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.LookLeftRight); var mouseY = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.LookUpDown); mouseX *= -1; mouseY *= -1; switch (Game.CurrentInputMode) { case InputMode.MouseAndKeyboard: mouseX *= _settings.CameraSensivity; mouseY *= _settings.CameraSensivity; break; case InputMode.GamePad: mouseX *= _settings.GamepadCameraSensitivity; mouseY *= _settings.GamepadCameraSensitivity; break; } float movementModifier = 1f; if (Game.IsControlPressed(0, Control.Sprint)) movementModifier = 5f; else if (Game.IsControlPressed(0, Control.CharacterWheel)) movementModifier = 0.3f; switch (Game.CurrentInputMode) { case InputMode.MouseAndKeyboard: float baseSpeed = _settings.KeyboardMovementSensitivity / 30f; // 1 - 60, baseSpeed = 0.03 - 2 movementModifier *= baseSpeed; break; case InputMode.GamePad: float gamepadSpeed = _settings.GamepadMovementSensitivity / 30f; // 1 - 60, baseSpeed = 0.03 - 2 movementModifier *= gamepadSpeed; break; } float modifier = 1f; if (Game.IsControlPressed(0, Control.Sprint)) modifier = 5f; else if (Game.IsControlPressed(0, Control.CharacterWheel)) modifier = 0.3f; if (_selectedProp == null && _selectedMarker == null) { if(!_menuPool.IsAnyMenuOpen() || Game.CurrentInputMode == InputMode.GamePad) _mainCamera.Rotation = new Vector3(_mainCamera.Rotation.X + mouseY, _mainCamera.Rotation.Y, _mainCamera.Rotation.Z + mouseX); var dir = VectorExtensions.RotationToDirection(_mainCamera.Rotation); var rotLeft = _mainCamera.Rotation + new Vector3(0, 0, -10); var rotRight = _mainCamera.Rotation + new Vector3(0, 0, 10); var right = VectorExtensions.RotationToDirection(rotRight) - VectorExtensions.RotationToDirection(rotLeft); var newPos = _mainCamera.Position; if (Game.IsControlPressed(0, Control.MoveUpOnly)) { newPos += dir* movementModifier; } if (Game.IsControlPressed(0, Control.MoveDownOnly)) { newPos -= dir* movementModifier; } if (Game.IsControlPressed(0, Control.MoveLeftOnly)) { newPos += right* movementModifier; } if (Game.IsControlPressed(0, Control.MoveRightOnly)) { newPos -= right* movementModifier; } _mainCamera.Position = newPos; Game.Player.Character.PositionNoOffset = _mainCamera.Position - dir*8f; if (_snappedProp != null) { if (!IsProp(_snappedProp)) _snappedProp.Position = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, _snappedProp); else _snappedProp.PositionNoOffset = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, _snappedProp); if (Game.IsControlPressed(0, Control.CursorScrollUp) || Game.IsControlPressed(0, Control.FrontendRb)) { _snappedProp.Rotation = _snappedProp.Rotation - new Vector3(0f, 0f, modifier); if (IsPed(_snappedProp)) _snappedProp.Heading = _snappedProp.Rotation.Z; } if (Game.IsControlPressed(0, Control.CursorScrollDown) || Game.IsControlPressed(0, Control.FrontendLb)) { _snappedProp.Rotation = _snappedProp.Rotation + new Vector3(0f, 0f, modifier); if (IsPed(_snappedProp)) _snappedProp.Heading = _snappedProp.Rotation.Z; } if (Game.IsControlJustPressed(0, Control.CreatorDelete)) { RemoveItemFromEntityMenu(_snappedProp); if (PropStreamer.IsPickup(_snappedProp.Handle)) { PropStreamer.RemovePickup(_snappedProp.Handle); } else { PropStreamer.RemoveEntity(_snappedProp.Handle); if (PropStreamer.Identifications.ContainsKey(_snappedProp.Handle)) PropStreamer.Identifications.Remove(_snappedProp.Handle); } _snappedProp = null; _changesMade++; } if (Game.IsControlJustPressed(0, Control.Attack)) { if (PropStreamer.IsPickup(_snappedProp.Handle)) { PropStreamer.GetPickup(_snappedProp.Handle).UpdatePos(); } _snappedProp = null; _changesMade++; } InstructionalButtonsStart(); InstructionalButtonsSnapped(); InstructionalButtonsEnd(); } else if (_snappedMarker != null) { _snappedMarker.Position = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); if (Game.IsControlPressed(0, Control.CursorScrollUp) || Game.IsControlPressed(0, Control.FrontendRb)) { _snappedMarker.Rotation = _snappedMarker.Rotation - new Vector3(0f, 0f, modifier); } if (Game.IsControlPressed(0, Control.CursorScrollDown) || Game.IsControlPressed(0, Control.FrontendLb)) { _snappedMarker.Rotation = _snappedMarker.Rotation + new Vector3(0f, 0f, modifier); } if (Game.IsControlJustPressed(0, Control.CreatorDelete)) { RemoveMarkerFromEntityMenu(_snappedMarker.Id); PropStreamer.Markers.Remove(_snappedMarker); _snappedMarker = null; _changesMade++; } if (Game.IsControlJustPressed(0, Control.Attack)) { _snappedMarker = null; _changesMade++; } InstructionalButtonsStart(); InstructionalButtonsSnapped(); InstructionalButtonsEnd(); } else if(_snappedProp == null && _snappedMarker == null) { if (_settings.CrosshairType == CrosshairType.Orb) { var pos = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); var color = Color.FromArgb(255, 200, 20, 20); if (hitEnt != null && hitEnt.Handle != 0 && !PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) color = Color.FromArgb(255, 20, 20, 255); else if (hitEnt != null && hitEnt.Handle != 0 && PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) color = Color.FromArgb(255, 200, 200, 20); Function.Call(Hash.DRAW_MARKER, 28, pos.X, pos.Y, pos.Z, 0f, 0f, 0f, 0f, 0f, 0f, 0.20f, 0.20f, 0.20f, color.R, color.G, color.B, color.A, false, true, 2, false, false, false, false); } if (Game.IsControlJustPressed(0, Control.Aim)) { if (hitEnt != null && PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) { if (PropStreamer.IsPickup(hitEnt.Handle)) _snappedProp = new Prop(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_AN_OBJECT, hitEnt.Handle)) _snappedProp = new Prop(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_A_VEHICLE, hitEnt.Handle)) _snappedProp = new Vehicle(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_A_PED, hitEnt.Handle)) _snappedProp = new Ped(hitEnt.Handle); _changesMade++; } else { var pos = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); Marker mark = PropStreamer.Markers.FirstOrDefault(m => (m.Position - pos).Length() < 2f); if (mark != null) { _snappedMarker = mark; _changesMade++; } } } if (Game.IsControlJustPressed(0, Control.Attack)) { if (hitEnt != null && PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) { if (PropStreamer.IsPickup(hitEnt.Handle)) _selectedProp = new Prop(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_AN_OBJECT, hitEnt.Handle)) _selectedProp = new Prop(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_A_VEHICLE, hitEnt.Handle)) _selectedProp = new Vehicle(hitEnt.Handle); else if (Function.Call<bool>(Hash.IS_ENTITY_A_PED, hitEnt.Handle)) _selectedProp = new Ped(hitEnt.Handle); RedrawObjectInfoMenu(_selectedProp, true); _menuPool.CloseAllMenus(); _objectInfoMenu.Visible = true; if(_settings.SnapCameraToSelectedObject) _mainCamera.PointAt(_selectedProp); _changesMade++; } else { var pos = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); Marker mark = PropStreamer.Markers.FirstOrDefault(m => (m.Position - pos).Length() < 2f); if (mark != null) { _selectedMarker = mark; RedrawObjectInfoMenu(_selectedMarker, true); _menuPool.CloseAllMenus(); _objectInfoMenu.Visible = true; _changesMade++; } } } if (Game.IsControlJustReleased(0, Control.LookBehind)) { if (hitEnt != null) { if (PropStreamer.IsPickup(hitEnt.Handle)) { var oldPickup = PropStreamer.GetPickup(hitEnt.Handle); var newPickup = PropStreamer.CreatePickup(new Model(oldPickup.PickupHash), oldPickup.Position, new Prop(oldPickup.ObjectHandle).Rotation.Z, oldPickup.Amount, oldPickup.Dynamic); AddItemToEntityMenu(newPickup); _snappedProp = new Prop(newPickup.ObjectHandle); } else if (Function.Call<bool>(Hash.IS_ENTITY_AN_OBJECT, hitEnt.Handle)) { var isDoor = PropStreamer.Doors.Contains(hitEnt.Handle); AddItemToEntityMenu(_snappedProp = PropStreamer.CreateProp(hitEnt.Model, hitEnt.Position, hitEnt.Rotation, (!PropStreamer.StaticProps.Contains(hitEnt.Handle) && !isDoor), q: Quaternion.GetEntityQuaternion(hitEnt), force: true, drawDistance: _settings.DrawDistance)); if (isDoor) { _snappedProp.FreezePosition = false; PropStreamer.Doors.Add(_snappedProp.Handle); } } else if (Function.Call<bool>(Hash.IS_ENTITY_A_VEHICLE, hitEnt.Handle)) AddItemToEntityMenu(_snappedProp = PropStreamer.CreateVehicle(hitEnt.Model, hitEnt.Position, hitEnt.Rotation.Z, !PropStreamer.StaticProps.Contains(hitEnt.Handle), drawDistance: _settings.DrawDistance)); else if (Function.Call<bool>(Hash.IS_ENTITY_A_PED, hitEnt.Handle)) { AddItemToEntityMenu(_snappedProp = Function.Call<Ped>(Hash.CLONE_PED, ((Ped)hitEnt).Handle, hitEnt.Rotation.Z, 1, 1)); if(_snappedProp != null) PropStreamer.Peds.Add(_snappedProp.Handle); if (_settings.DrawDistance != -1) _snappedProp.LodDistance = _settings.DrawDistance; if (PropStreamer.StaticProps.Contains(hitEnt.Handle)) { _snappedProp.FreezePosition = true; PropStreamer.StaticProps.Add(_snappedProp.Handle); } if(!PropStreamer.ActiveScenarios.ContainsKey(_snappedProp.Handle)) PropStreamer.ActiveScenarios.Add(_snappedProp.Handle, "None"); if(PropStreamer.ActiveRelationships.ContainsKey(hitEnt.Handle)) PropStreamer.ActiveRelationships.Add(_snappedProp.Handle, PropStreamer.ActiveRelationships[hitEnt.Handle]); else if (!PropStreamer.ActiveRelationships.ContainsKey(_snappedProp.Handle)) PropStreamer.ActiveRelationships.Add(_snappedProp.Handle, DefaultRelationship.ToString()); if(PropStreamer.ActiveWeapons.ContainsKey(hitEnt.Handle)) PropStreamer.ActiveWeapons.Add(_snappedProp.Handle, PropStreamer.ActiveWeapons[hitEnt.Handle]); else if(!PropStreamer.ActiveWeapons.ContainsKey(_snappedProp.Handle)) PropStreamer.ActiveWeapons.Add(_snappedProp.Handle, WeaponHash.Unarmed); } _changesMade++; } else { var pos = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); Marker mark = PropStreamer.Markers.FirstOrDefault(m => (m.Position - pos).Length() < 2f); if (mark != null) { var tmpMark = new Marker() { BobUpAndDown = mark.BobUpAndDown, Red = mark.Red, Green = mark.Green, Blue = mark.Blue, Alpha = mark.Alpha, Position = mark.Position, RotateToCamera = mark.RotateToCamera, Rotation = mark.Rotation, Scale = mark.Scale, Type = mark.Type, Id = _markerCounter, }; _markerCounter++; AddItemToEntityMenu(tmpMark); PropStreamer.Markers.Add(tmpMark); _snappedMarker = tmpMark; _changesMade++; } } } if (Game.IsControlJustPressed(0, Control.CreatorDelete)) { if (hitEnt != null && PropStreamer.GetAllHandles().Contains(hitEnt.Handle)) { RemoveItemFromEntityMenu(hitEnt); if (PropStreamer.Identifications.ContainsKey(hitEnt.Handle)) PropStreamer.Identifications.Remove(hitEnt.Handle); if (PropStreamer.ActiveScenarios.ContainsKey(hitEnt.Handle)) PropStreamer.ActiveScenarios.Remove(hitEnt.Handle); if (PropStreamer.ActiveRelationships.ContainsKey(hitEnt.Handle)) PropStreamer.ActiveRelationships.Remove(hitEnt.Handle); if (PropStreamer.ActiveWeapons.ContainsKey(hitEnt.Handle)) PropStreamer.ActiveWeapons.Remove(hitEnt.Handle); PropStreamer.RemoveEntity(hitEnt.Handle); _changesMade++; } else if(hitEnt != null && !PropStreamer.GetAllHandles().Contains(hitEnt.Handle) && Function.Call<bool>(Hash.IS_ENTITY_AN_OBJECT, hitEnt.Handle)) { MapObject tmpObj = new MapObject() { Hash = hitEnt.Model.Hash, Position = hitEnt.Position, Rotation = hitEnt.Rotation, Quaternion = Quaternion.GetEntityQuaternion(hitEnt), Type = ObjectTypes.Prop, Id = _mapObjCounter.ToString(), }; _mapObjCounter++; PropStreamer.RemovedObjects.Add(tmpObj); AddItemToEntityMenu(tmpObj); hitEnt.Delete(); _changesMade++; } else { var pos = VectorExtensions.RaycastEverything(new Vector2(0f, 0f), _mainCamera.Position, _mainCamera.Rotation, Game.Player.Character); Marker mark = PropStreamer.Markers.FirstOrDefault(m => (m.Position - pos).Length() < 2f); if (mark != null) { PropStreamer.Markers.Remove(mark); RemoveMarkerFromEntityMenu(mark.Id); _changesMade++; } } } InstructionalButtonsStart(); InstructionalButtonsFreelook(); InstructionalButtonsEnd(); } } else if(_selectedProp != null)//_selectedProp isnt null { var tmp = _controlsRotate ? Color.FromArgb(200, 200, 20, 20) : Color.FromArgb(200, 200, 200, 10); var modelDims = _selectedProp.Model.GetDimensions(); Function.Call(Hash.DRAW_MARKER, 0, _selectedProp.Position.X, _selectedProp.Position.Y, _selectedProp.Position.Z + modelDims.Z + 2f, 0f, 0f, 0f, 0f, 0f, 0f, 2f, 2f, 2f, tmp.R, tmp.G, tmp.B, tmp.A, 1, 0, 2, 2, 0, 0, 0); DrawEntityBox(_selectedProp, tmp); if (Game.IsControlJustReleased(0, Control.Duck)) { _controlsRotate = !_controlsRotate; } if (Game.IsControlPressed(0, Control.FrontendRb)) { float pedMod = 0f; if (_selectedProp is Ped) pedMod = -1f; if (!_controlsRotate) { if (!IsProp(_selectedProp)) _selectedProp.Position = _selectedProp.Position + new Vector3(0f, 0f, (modifier / 4) + pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position + new Vector3(0f, 0f, (modifier/4) + pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X, _selectedProp.Rotation.Y, _selectedProp.Rotation.Z - (modifier / 4)).ToQuaternion(); if (IsPed(_selectedProp)) _selectedProp.Heading = _selectedProp.Rotation.Z; } if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } _changesMade++; } if (Game.IsControlPressed(0, Control.FrontendLb)) { float pedMod = 0f; if (_selectedProp is Ped) pedMod = 1f; if (!_controlsRotate) { if (!IsProp(_selectedProp)) _selectedProp.Position = _selectedProp.Position - new Vector3(0f, 0f, (modifier/4) + pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position - new Vector3(0f, 0f, (modifier / 4) + pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X, _selectedProp.Rotation.Y, _selectedProp.Rotation.Z + (modifier / 4)).ToQuaternion(); if (IsPed(_selectedProp)) _selectedProp.Heading = _selectedProp.Rotation.Z; } _changesMade++; if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } } if (Game.IsControlPressed(0, Control.MoveUpOnly)) { float pedMod = 0f; if (IsPed(_selectedProp)) pedMod = -1f; if (!_controlsRotate) { var dir = VectorExtensions.RotationToDirection(_mainCamera.Rotation)*(modifier/4); if (!IsProp(_selectedProp) ) _selectedProp.Position = _selectedProp.Position + new Vector3(dir.X, dir.Y, pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position + new Vector3(dir.X, dir.Y, pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X + (modifier / 4), _selectedProp.Rotation.Y, _selectedProp.Rotation.Z).ToQuaternion(); } _changesMade++; if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } } if (Game.IsControlPressed(0, Control.MoveDownOnly)) { float pedMod = 0f; if (_selectedProp is Ped) pedMod = 1f; if (!_controlsRotate) { var dir = VectorExtensions.RotationToDirection(_mainCamera.Rotation)*(modifier/4); if (!IsProp(_selectedProp) ) _selectedProp.Position = _selectedProp.Position - new Vector3(dir.X, dir.Y, pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position - new Vector3(dir.X, dir.Y, pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X - (modifier / 4), _selectedProp.Rotation.Y, _selectedProp.Rotation.Z).ToQuaternion(); } _changesMade++; if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } } if (Game.IsControlPressed(0, Control.MoveLeftOnly)) { float pedMod = 0f; if (_selectedProp is Ped) pedMod = -1f; if (!_controlsRotate) { var rotLeft = _mainCamera.Rotation + new Vector3(0, 0, -10); var rotRight = _mainCamera.Rotation + new Vector3(0, 0, 10); var right = (VectorExtensions.RotationToDirection(rotRight) - VectorExtensions.RotationToDirection(rotLeft))*(modifier/2); if (!IsProp(_selectedProp) ) _selectedProp.Position = _selectedProp.Position + new Vector3(right.X, right.Y, pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position + new Vector3(right.X, right.Y, pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X, _selectedProp.Rotation.Y + (modifier / 4), _selectedProp.Rotation.Z).ToQuaternion(); } _changesMade++; if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } } if (Game.IsControlPressed(0, Control.MoveRightOnly)) { float pedMod = 0f; if (_selectedProp is Ped) pedMod = 1f; if (!_controlsRotate) { var rotLeft = _mainCamera.Rotation + new Vector3(0, 0, -10); var rotRight = _mainCamera.Rotation + new Vector3(0, 0, 10); var right = (VectorExtensions.RotationToDirection(rotRight) - VectorExtensions.RotationToDirection(rotLeft))*(modifier/2); if (!IsProp(_selectedProp) ) _selectedProp.Position = _selectedProp.Position - new Vector3(right.X, right.Y, pedMod); else _selectedProp.PositionNoOffset = _selectedProp.Position - new Vector3(right.X, right.Y, pedMod); } else { _selectedProp.Quaternion = new Vector3(_selectedProp.Rotation.X, _selectedProp.Rotation.Y - (modifier / 4), _selectedProp.Rotation.Z).ToQuaternion(); } _changesMade++; if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } } if (Game.IsControlJustReleased(0, Control.MoveLeftOnly) || Game.IsControlJustReleased(0, Control.MoveRightOnly) || Game.IsControlJustReleased(0, Control.MoveUpOnly) || Game.IsControlJustReleased(0, Control.MoveDownOnly) || Game.IsControlJustReleased(0, Control.FrontendLb) || Game.IsControlJustReleased(0, Control.FrontendRb)) { RedrawObjectInfoMenu(_selectedProp, false); } if (Game.IsControlJustReleased(0, Control.LookBehind)) { Entity mainProp = new Prop(0); if (PropStreamer.IsPickup(_selectedProp.Handle)) { var oldPickup = PropStreamer.GetPickup(_selectedProp.Handle); var newPickup = PropStreamer.CreatePickup(new Model(oldPickup.PickupHash), oldPickup.Position, new Prop(oldPickup.ObjectHandle).Rotation.Z, oldPickup.Amount, oldPickup.Dynamic); AddItemToEntityMenu(newPickup); mainProp = new Prop(newPickup.ObjectHandle); } else if (_selectedProp is Prop) { var isDoor = PropStreamer.Doors.Contains(_selectedProp.Handle); AddItemToEntityMenu(mainProp = PropStreamer.CreateProp(_selectedProp.Model, _selectedProp.Position, _selectedProp.Rotation, (!PropStreamer.StaticProps.Contains(_selectedProp.Handle) && !isDoor), force: true, q: Quaternion.GetEntityQuaternion(_selectedProp), drawDistance: _settings.DrawDistance)); if (isDoor) { mainProp.FreezePosition = false; PropStreamer.Doors.Add(mainProp.Handle); } } else if (_selectedProp is Vehicle) AddItemToEntityMenu(mainProp = PropStreamer.CreateVehicle(_selectedProp.Model, _selectedProp.Position, _selectedProp.Rotation.Z, !PropStreamer.StaticProps.Contains(_selectedProp.Handle), drawDistance: _settings.DrawDistance)); else if (_selectedProp is Ped) { AddItemToEntityMenu(mainProp = Function.Call<Ped>(Hash.CLONE_PED, ((Ped) _selectedProp).Handle, _selectedProp.Rotation.Z, 1, 1)); PropStreamer.Peds.Add(mainProp.Handle); if(!PropStreamer.ActiveScenarios.ContainsKey(mainProp.Handle)) PropStreamer.ActiveScenarios.Add(mainProp.Handle, "None"); if (_settings.DrawDistance != -1) mainProp.LodDistance = _settings.DrawDistance; if (PropStreamer.ActiveRelationships.ContainsKey(_selectedProp.Handle)) PropStreamer.ActiveRelationships.Add(mainProp.Handle, PropStreamer.ActiveRelationships[_selectedProp.Handle]); else if (!PropStreamer.ActiveRelationships.ContainsKey(mainProp.Handle)) PropStreamer.ActiveRelationships.Add(mainProp.Handle, DefaultRelationship.ToString()); if(PropStreamer.ActiveWeapons.ContainsKey(_selectedProp.Handle)) PropStreamer.ActiveWeapons.Add(mainProp.Handle, PropStreamer.ActiveWeapons[_selectedProp.Handle]); else if(!PropStreamer.ActiveRelationships.ContainsKey(mainProp.Handle)) PropStreamer.ActiveWeapons.Add(mainProp.Handle, WeaponHash.Unarmed); } _changesMade++; _selectedProp = mainProp; if(_settings.SnapCameraToSelectedObject) _mainCamera.PointAt(_selectedProp); if(_selectedProp != null) RedrawObjectInfoMenu(_selectedProp, true); } if (Game.IsControlJustPressed(0, Control.CreatorDelete)) { if (PropStreamer.Identifications.ContainsKey(_selectedProp.Handle)) PropStreamer.Identifications.Remove(_selectedProp.Handle); if (PropStreamer.ActiveScenarios.ContainsKey(_selectedProp.Handle)) PropStreamer.ActiveScenarios.Remove(_selectedProp.Handle); if (PropStreamer.ActiveRelationships.ContainsKey(_selectedProp.Handle)) PropStreamer.ActiveRelationships.Remove(_selectedProp.Handle); if (PropStreamer.ActiveWeapons.ContainsKey(_selectedProp.Handle)) PropStreamer.ActiveWeapons.Remove(_selectedProp.Handle); RemoveItemFromEntityMenu(_selectedProp); PropStreamer.RemoveEntity(_selectedProp.Handle); _selectedProp = null; _objectInfoMenu.Visible = false; _mainCamera.StopPointing(); _changesMade++; } if (Game.IsControlJustPressed(0, Control.PhoneCancel) || Game.IsControlJustPressed(0, Control.Attack)) { if (PropStreamer.IsPickup(_selectedProp.Handle)) { PropStreamer.GetPickup(_selectedProp.Handle).UpdatePos(); } _selectedProp = null; _objectInfoMenu.Visible = false; _mainCamera.StopPointing(); _changesMade++; } InstructionalButtonsStart(); InstructionalButtonsSelected(); InstructionalButtonsEnd(); } else if (_selectedMarker != null) // marker isn't null { if (Game.IsControlJustReleased(0, Control.Duck)) { _controlsRotate = !_controlsRotate; } if (Game.IsControlPressed(0, Control.FrontendRb)) { if (!_controlsRotate) _selectedMarker.Position += new Vector3(0f, 0f, (modifier / 4)); else _selectedMarker.Rotation += new Vector3(0f, 0f, modifier); _changesMade++; } if (Game.IsControlPressed(0, Control.FrontendLb)) { if (!_controlsRotate) _selectedMarker.Position -= new Vector3(0f, 0f, (modifier / 4)); else _selectedMarker.Rotation -= new Vector3(0f, 0f, modifier); _changesMade++; } if (Game.IsControlPressed(0, Control.MoveUpOnly)) { if (!_controlsRotate) { var dir = VectorExtensions.RotationToDirection(_mainCamera.Rotation) * (modifier / 4); _selectedMarker.Position += new Vector3(dir.X, dir.Y, 0f); } else _selectedMarker.Rotation += new Vector3(modifier, 0f, 0f); _changesMade++; } if (Game.IsControlPressed(0, Control.MoveDownOnly)) { if (!_controlsRotate) { var dir = VectorExtensions.RotationToDirection(_mainCamera.Rotation) * (modifier / 4); _selectedMarker.Position -= new Vector3(dir.X, dir.Y, 0f); } else _selectedMarker.Rotation -= new Vector3(modifier, 0f, 0f); _changesMade++; } if (Game.IsControlPressed(0, Control.MoveLeftOnly)) { if (!_controlsRotate) { var rotLeft = _mainCamera.Rotation + new Vector3(0, 0, -10); var rotRight = _mainCamera.Rotation + new Vector3(0, 0, 10); var right = (VectorExtensions.RotationToDirection(rotRight) - VectorExtensions.RotationToDirection(rotLeft)) * (modifier / 2); _selectedMarker.Position += new Vector3(right.X, right.Y, 0f); } else _selectedMarker.Rotation += new Vector3(0f, modifier, 0f); _changesMade++; } if (Game.IsControlPressed(0, Control.MoveRightOnly)) { if (!_controlsRotate) { var rotLeft = _mainCamera.Rotation + new Vector3(0, 0, -10); var rotRight = _mainCamera.Rotation + new Vector3(0, 0, 10); var right = (VectorExtensions.RotationToDirection(rotRight) - VectorExtensions.RotationToDirection(rotLeft)) * (modifier / 2); _selectedMarker.Position -= new Vector3(right.X, right.Y, 0f); } else _selectedMarker.Rotation -= new Vector3(0f, modifier, 0f); _changesMade++; } if (Game.IsControlJustReleased(0, Control.MoveLeftOnly) || Game.IsControlJustReleased(0, Control.MoveRightOnly) || Game.IsControlJustReleased(0, Control.MoveUpOnly) || Game.IsControlJustReleased(0, Control.MoveDownOnly) || Game.IsControlJustReleased(0, Control.FrontendLb) || Game.IsControlJustReleased(0, Control.FrontendRb)) { RedrawObjectInfoMenu(_selectedMarker, false); } if (Game.IsControlJustReleased(0, Control.LookBehind)) { var tmpMark = new Marker() { BobUpAndDown = _selectedMarker.BobUpAndDown, Red = _selectedMarker.Red, Green = _selectedMarker.Green, Blue = _selectedMarker.Blue, Alpha = _selectedMarker.Alpha, Position = _selectedMarker.Position, RotateToCamera = _selectedMarker.RotateToCamera, Rotation = _selectedMarker.Rotation, Scale = _selectedMarker.Scale, Type = _selectedMarker.Type, Id = _markerCounter, }; _markerCounter++; PropStreamer.Markers.Add(tmpMark); AddItemToEntityMenu(tmpMark); _selectedMarker = tmpMark; RedrawObjectInfoMenu(_selectedMarker, true); _changesMade++; } if (Game.IsControlJustPressed(0, Control.CreatorDelete)) { PropStreamer.Markers.Remove(_selectedMarker); RemoveMarkerFromEntityMenu(_selectedMarker.Id); _selectedMarker = null; _objectInfoMenu.Visible = false; _mainCamera.StopPointing(); _changesMade++; } if (Game.IsControlJustPressed(0, Control.PhoneCancel) || Game.IsControlJustPressed(0, Control.Attack)) { _selectedMarker = null; _objectInfoMenu.Visible = false; _mainCamera.StopPointing(); _changesMade++; } InstructionalButtonsStart(); InstructionalButtonsSelected(); InstructionalButtonsEnd(); } }
public void AddItemToEntityMenu(MapObject obj) { if(obj == null) return; var name = ObjectDatabase.MainDb.ContainsValue(obj.Hash) ? ObjectDatabase.MainDb.First(pair => pair.Value == obj.Hash).Key : "Unknown World Prop"; _currentObjectsMenu.AddItem(new UIMenuItem("~h~[WORLD]~h~ " + name, obj.Id.ToString())); _currentObjectsMenu.RefreshIndex(); }
private void LoadMap(string filename, MapSerializer.Format format) { if (String.IsNullOrWhiteSpace(filename) || !File.Exists(filename)) { if (File.Exists(filename + ".xml") && format == MapSerializer.Format.NormalXml) { LoadMap(filename + ".xml", MapSerializer.Format.NormalXml); return; } if(File.Exists(filename + ".ini") && format == MapSerializer.Format.SimpleTrainer) { LoadMap(filename + ".ini", MapSerializer.Format.SimpleTrainer); return; } if (File.Exists(filename + ".xml") && format == MapSerializer.Format.Menyoo) { LoadMap(filename + ".xml", MapSerializer.Format.Menyoo); return; } if (File.Exists(filename + ".SP00N") && format == MapSerializer.Format.SpoonerLegacy) { LoadMap(filename + ".SP00N", MapSerializer.Format.SpoonerLegacy); return; } UI.Notify("~b~~h~Map Editor~h~~w~~n~" + Translation.Translate("The filename was empty or the file does not exist!")); return; } var handles = new List<int>(); var des = new MapSerializer(); try { var map2Load = des.Deserialize(filename, format); if (map2Load == null) return; if (map2Load.Metadata != null && map2Load.Metadata.LoadingPoint.HasValue) { Game.Player.Character.Position = map2Load.Metadata.LoadingPoint.Value; Wait(500); } foreach (MapObject o in map2Load.Objects) { if(o == null) continue; _loadedEntities++; switch (o.Type) { case ObjectTypes.Prop: var newProp = PropStreamer.CreateProp(ObjectPreview.LoadObject(o.Hash), o.Position, o.Rotation, o.Dynamic && !o.Door, o.Quaternion == new Quaternion() {X = 0, Y = 0, Z = 0, W = 0} ? null : o.Quaternion, drawDistance: _settings.DrawDistance); AddItemToEntityMenu(newProp); if (o.Door) { PropStreamer.Doors.Add(newProp.Handle); newProp.FreezePosition = false; } if (o.Id != null && !PropStreamer.Identifications.ContainsKey(newProp.Handle)) { PropStreamer.Identifications.Add(newProp.Handle, o.Id); handles.Add(newProp.Handle); } break; case ObjectTypes.Vehicle: Vehicle tmpVeh; AddItemToEntityMenu(tmpVeh = PropStreamer.CreateVehicle(ObjectPreview.LoadObject(o.Hash), o.Position, o.Rotation.Z, o.Dynamic, drawDistance: _settings.DrawDistance)); tmpVeh.PrimaryColor = (VehicleColor) o.PrimaryColor; tmpVeh.SecondaryColor = (VehicleColor)o.SecondaryColor; if (o.Id != null && !PropStreamer.Identifications.ContainsKey(tmpVeh.Handle)) { PropStreamer.Identifications.Add(tmpVeh.Handle, o.Id); handles.Add(tmpVeh.Handle); } if (o.SirensActive) { PropStreamer.ActiveSirens.Add(tmpVeh.Handle); tmpVeh.SirenActive = true; } break; case ObjectTypes.Ped: Ped pedid; AddItemToEntityMenu(pedid = PropStreamer.CreatePed(ObjectPreview.LoadObject(o.Hash), o.Position - new Vector3(0f, 0f, 1f), o.Rotation.Z, o.Dynamic, drawDistance: _settings.DrawDistance)); if((o.Action == null || o.Action == "None") && !PropStreamer.ActiveScenarios.ContainsKey(pedid.Handle)) PropStreamer.ActiveScenarios.Add(pedid.Handle, "None"); else if (o.Action != null && o.Action != "None" && !PropStreamer.ActiveScenarios.ContainsKey(pedid.Handle)) { PropStreamer.ActiveScenarios.Add(pedid.Handle, o.Action); if (o.Action == "Any" || o.Action == "Any - Walk") Function.Call(Hash.TASK_USE_NEAREST_SCENARIO_TO_COORD, pedid.Handle, pedid.Position.X, pedid.Position.Y, pedid.Position.Z, 100f, -1); else if(o.Action == "Any - Warp") Function.Call(Hash.TASK_USE_NEAREST_SCENARIO_TO_COORD_WARP, pedid.Handle, pedid.Position.X, pedid.Position.Y, pedid.Position.Z, 100f, -1); else if (o.Action == "Wander") pedid.Task.WanderAround(); else { Function.Call(Hash.TASK_START_SCENARIO_IN_PLACE, pedid.Handle, ObjectDatabase.ScrenarioDatabase[o.Action], 0, 0); } } if (o.Id != null && !PropStreamer.Identifications.ContainsKey(pedid.Handle)) { PropStreamer.Identifications.Add(pedid.Handle, o.Id); handles.Add(pedid.Handle); } if (o.Relationship == null) PropStreamer.ActiveRelationships.Add(pedid.Handle, DefaultRelationship.ToString()); else { PropStreamer.ActiveRelationships.Add(pedid.Handle, o.Relationship); if (o.Relationship != DefaultRelationship.ToString()) { ObjectDatabase.SetPedRelationshipGroup(pedid, o.Relationship); } } if (o.Weapon == null) PropStreamer.ActiveWeapons.Add(pedid.Handle, WeaponHash.Unarmed); else { PropStreamer.ActiveWeapons.Add(pedid.Handle, o.Weapon.Value); if (o.Weapon != WeaponHash.Unarmed) { pedid.Weapons.Give(o.Weapon.Value, 999, true, true); } } break; case ObjectTypes.Pickup: var newPickup = PropStreamer.CreatePickup(o.Hash, o.Position, o.Rotation.Z, o.Amount, o.Dynamic, o.Quaternion); newPickup.Timeout = o.RespawnTimer; AddItemToEntityMenu(newPickup); if (o.Id != null && !PropStreamer.Identifications.ContainsKey(newPickup.ObjectHandle)) { PropStreamer.Identifications.Add(newPickup.ObjectHandle, o.Id); handles.Add(newPickup.ObjectHandle); } break; } } foreach (MapObject o in map2Load.RemoveFromWorld) { if(o == null) continue; PropStreamer.RemovedObjects.Add(o); Prop returnedProp = Function.Call<Prop>(Hash.GET_CLOSEST_OBJECT_OF_TYPE, o.Position.X, o.Position.Y, o.Position.Z, 1f, o.Hash, 0); if (returnedProp == null || returnedProp.Handle == 0) continue; MapObject tmpObj = new MapObject() { Hash = returnedProp.Model.Hash, Position = returnedProp.Position, Rotation = returnedProp.Rotation, Quaternion = Quaternion.GetEntityQuaternion(returnedProp), Type = ObjectTypes.Prop, Id = _mapObjCounter.ToString(), }; _mapObjCounter++; AddItemToEntityMenu(tmpObj); returnedProp.Delete(); } foreach (Marker marker in map2Load.Markers) { if(marker == null) continue; _markerCounter++; marker.Id = _markerCounter; PropStreamer.Markers.Add(marker); AddItemToEntityMenu(marker); } if (_settings.LoadScripts && format == MapSerializer.Format.NormalXml && File.Exists(new FileInfo(filename).Directory.FullName + "\\" + Path.GetFileNameWithoutExtension(filename) + ".js")) { JavascriptHook.StartScript(File.ReadAllText(new FileInfo(filename).Directory.FullName + "\\" + Path.GetFileNameWithoutExtension(filename) + ".js"), handles); } if (map2Load.Metadata != null && map2Load.Metadata.TeleportPoint.HasValue) { Game.Player.Character.Position = map2Load.Metadata.TeleportPoint.Value; } PropStreamer.CurrentMapMetadata = map2Load.Metadata ?? new MapMetadata(); PropStreamer.CurrentMapMetadata.Filename = filename; UI.Notify("~b~~h~Map Editor~h~~w~~n~" + Translation.Translate("Loaded map") + " ~h~" + filename + "~h~."); } catch (Exception e) { UI.Notify("~r~~h~Map Editor~h~~w~~n~" + Translation.Translate("Map failed to load, see error below.")); UI.Notify(e.Message); File.AppendAllText("scripts\\MapEditor.log", DateTime.Now + " MAP FAILED TO LOAD:\r\n" + e.ToString() + "\r\n"); } }
public static void MoveToMemory(Entity i) { var obj = new MapObject() { Dynamic = !StaticProps.Contains(i.Handle), Hash = i.Model.Hash, Position = i.Position, Quaternion = Quaternion.GetEntityQuaternion(i), Rotation = i.Rotation, Type = ObjectTypes.Prop, }; MemoryObjects.Add(obj); StreamedInHandles.Remove(i.Handle); StaticProps.Remove(i.Handle); i.Delete(); }
public static void MoveFromMemory(MapObject obj) { var prop = obj; Prop newProp = World.CreateProp(new Model(prop.Hash), prop.Position, prop.Rotation, false, false); newProp.FreezePosition = !prop.Dynamic; StreamedInHandles.Add(newProp.Handle); if (!prop.Dynamic) { StaticProps.Add(newProp.Handle); newProp.FreezePosition = true; } if (prop.Quaternion != null) Quaternion.SetEntityQuaternion(newProp, prop.Quaternion); newProp.Position = prop.Position; MemoryObjects.Remove(prop); }
internal Map Deserialize(string path, Format format) { string tip = ""; switch (format) { case Format.NormalXml: XmlSerializer reader = new XmlSerializer(typeof(Map)); var file = new StreamReader(path); var map = (Map)reader.Deserialize(file); file.Close(); return(map); case Format.Menyoo: var spReader = new XmlSerializer(typeof(MenyooCompatibility.SpoonerPlacements)); var spFile = new StreamReader(path); var spMap = (MenyooCompatibility.SpoonerPlacements)spReader.Deserialize(spFile); spFile.Close(); var outputMap = new Map(); foreach (var placement in spMap.Placement) { var obj = new MapObject(); switch (placement.Type) { case 3: // Props { obj.Type = ObjectTypes.Prop; } break; case 1: // Peds { obj.Type = ObjectTypes.Ped; } break; case 2: // Vehicles { obj.Type = ObjectTypes.Vehicle; } break; } obj.Dynamic = placement.Dynamic; obj.Hash = Convert.ToInt32(placement.ModelHash, 16); obj.Position = new Vector3(placement.PositionRotation.X, placement.PositionRotation.Y, placement.PositionRotation.Z); obj.Rotation = new Vector3(placement.PositionRotation.Pitch, placement.PositionRotation.Roll, placement.PositionRotation.Yaw); outputMap.Objects.Add(obj); } return(outputMap); case Format.SimpleTrainer: { var tmpMap = new Map(); string currentSection = ""; string oldSection = ""; Dictionary <string, string> tmpData = new Dictionary <string, string>(); foreach (string line in File.ReadAllLines(path)) { if (line.StartsWith("[") && line.EndsWith("]")) { oldSection = currentSection; currentSection = line; tip = currentSection; if (oldSection == "" || oldSection == "[Player]") { continue; } Vector3 pos = new Vector3(float.Parse(tmpData["x"], CultureInfo.InvariantCulture), float.Parse(tmpData["y"], CultureInfo.InvariantCulture), float.Parse(tmpData["z"], CultureInfo.InvariantCulture)); Vector3 rot = new Vector3(float.Parse(tmpData["qz"]), float.Parse(tmpData["qw"]), float.Parse(tmpData["h"])); Quaternion q = new Quaternion() { X = Parse(tmpData["qx"]), Y = Parse(tmpData["qy"]), Z = Parse(tmpData["qz"]), W = Parse(tmpData["qw"]), }; int mod = Convert.ToInt32(tmpData["Model"], CultureInfo.InvariantCulture); int dyn = Convert.ToInt32(tmpData["Dynamic"], CultureInfo.InvariantCulture); tmpMap.Objects.Add(new MapObject() { Hash = mod, Position = pos, Rotation = rot, Dynamic = dyn == 1, Quaternion = q }); tmpData = new Dictionary <string, string>(); continue; } if (currentSection == "[Player]") { continue; } string[] spl = line.Split('='); tmpData.Add(spl[0], spl[1]); } Vector3 lastPos = new Vector3(float.Parse(tmpData["x"], CultureInfo.InvariantCulture), float.Parse(tmpData["y"], CultureInfo.InvariantCulture), float.Parse(tmpData["z"], CultureInfo.InvariantCulture)); Vector3 lastRot = new Vector3(float.Parse(tmpData["qz"]), float.Parse(tmpData["qw"]), float.Parse(tmpData["h"])); Quaternion lastQ = new Quaternion() { X = Parse(tmpData["qx"]), Y = Parse(tmpData["qy"]), Z = Parse(tmpData["qz"]), W = Parse(tmpData["qw"]), }; int lastMod = Convert.ToInt32(tmpData["Model"], CultureInfo.InvariantCulture); int lastDyn = Convert.ToInt32(tmpData["Dynamic"], CultureInfo.InvariantCulture); tmpMap.Objects.Add(new MapObject() { Hash = lastMod, Position = lastPos, Rotation = lastRot, Dynamic = lastDyn == 1, Quaternion = lastQ }); return(tmpMap); } case Format.SpoonerLegacy: { var tmpMap = new Map(); string currentSection = ""; string oldSection = ""; Dictionary <string, string> tmpData = new Dictionary <string, string>(); foreach (string line in File.ReadAllLines(path)) { if (line.StartsWith("[") && line.EndsWith("]")) { oldSection = currentSection; currentSection = line; tip = currentSection; if (!tmpData.ContainsKey("Type")) { continue; } Vector3 pos = new Vector3(float.Parse(tmpData["X"], CultureInfo.InvariantCulture), float.Parse(tmpData["Y"], CultureInfo.InvariantCulture), float.Parse(tmpData["Z"], CultureInfo.InvariantCulture)); Vector3 rot = new Vector3(float.Parse(tmpData["Pitch"]), float.Parse(tmpData["Roll"]), float.Parse(tmpData["Yaw"])); int mod = Convert.ToInt32("0x" + tmpData["Hash"], 16); tmpMap.Objects.Add(new MapObject() { Hash = mod, Position = pos, Rotation = rot, Type = tmpData["Type"] == "1" ? ObjectTypes.Ped : tmpData["Type"] == "2" ? ObjectTypes.Vehicle : ObjectTypes.Prop, }); tmpData = new Dictionary <string, string>(); continue; } string[] spl = line.Split('='); if (spl.Length >= 2) { tmpData.Add(spl[0].Trim(), spl[1].Trim()); } } return(tmpMap); } default: throw new NotImplementedException("This is not implemented yet."); } }