public static void Initialize(int port) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); bool bound = false; while (!bound) { try { _socket.Bind(new IPEndPoint(IPAddress.Any, port)); bound = true; } catch (SocketException e) { if (e.SocketErrorCode == SocketError.AddressAlreadyInUse) { port++; } else { throw e; } } } Log.Write(LogLevel.Info, "Listening on port {0}", port); _socket.Blocking = false; _receiveQueue = new List <NetPacket>(); _sendQueue = new List <NetPacket>(); net_forceLatency = ConVar.Register("net_forceLatency", 0, "Force network packets to be sent/arrive with latency.", ConVarFlags.None); }
public static void Connect_f(string[] args) { if (ConVar.GetValue <string>("nicknamee") == ("")) // baddd { Log.Write(LogLevel.Info, "You haven't set a nickname, set one now:)"); return; } if (args.Length != 2) { Log.Write(LogLevel.Info, "usage: connect [ip]"); return; } if (args[1] != "localhost") { ConVar.SetValue <bool>("sv_running", false); } var server = NetAddress.Resolve(args[1]); if (_currentServer != server) { _currentServer = server; State = ClientState.Challenging; _lastMessageReceivedAt = _clientTime; _lastConnectPacketTime = -999999; } }
/// <summary> /// kill client command /// </summary> /// <param name="name">player to kill</param> // Welcome to operation KillClient. In this operation you were given the choice to kill a client. You choose to so now we are at this function // Now, first things first we need to check if your the host and not just some random clinet trying to troll! // Right, so now we've past that we need to fetch our client, once we have him we'll just make him respawn. // once respawned we now increase his death count by one! Yes one, not two, not three - one! // now, i come to think about it this just seems pointles.. But oh well, what can you do - I don't like backspace or ctrl+z, so meh. public static void KillClient(string name) { // check that it's the server that used the command if (!ConVar.GetValue <bool>("sv_running")) { Log.Write(LogLevel.Error, "Server is not running."); return; } foreach (ServerClient client in _clients) { if (client != null) { if (client.Name.ToLower() == name.ToLower()) { // now to actually kill the client.. SendReliableCommand(null, "print \"{0} was killed...\"", client.Name); // spawn him client.Entity.Spawn(); // add up his death count client.Deaths = 123; } } } }
public static void Initialize(GraphicsDevice device) { _pointEffect = EffectManager.Load("PointLight", device); _dirAmbEffect = EffectManager.Load("Ambient", device); _halfPixel = new Vector2(0.5f / (float)device.PresentationParameters.BackBufferWidth, 0.5f / (float)device.PresentationParameters.BackBufferHeight); r_sunIntensity = ConVar.Register("r_sunIntensity", 1.6f, "Sun intensity, duh.", ConVarFlags.Archived); }
public static void ExportMain(string[] args) { var filename = args[1]; var outDir = "Export/QMaps/" + filename + ".gbh2map"; Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); ConVar.Initialize(); FileSystem.Initialize(); MapManager.Load("Maps/" + filename + ".gmp"); // export cell files var cellWidth = 32; var cellHeight = 32; var blockScale = 4.5f; var mapFile = File.Open(string.Format("{0}/cells.lua", outDir), FileMode.Create, FileAccess.Write); var mapWriter = new StreamWriter(mapFile); for (int x = 0; x < (256 / cellWidth); x++) { for (int y = 0; y < (256 / cellHeight); y++) { var cellName = string.Format("{0}_{1}_{2}", filename, x, y); var cellFile = File.OpenWrite(string.Format("{0}/cells/{1}.cell", outDir, cellName)); var cellWriter = new BinaryWriter(cellFile); for (int c = 0; c < 7; c++) { for (int b = (y * cellHeight); b < (y * cellHeight) + cellHeight; b++) { for (int a = (x * cellWidth); a < (x * cellWidth) + cellWidth; a++) { var block = MapManager.GetBlock(a, b, c); cellWriter.Write(block.Left.Value); cellWriter.Write(block.Right.Value); cellWriter.Write(block.Top.Value); cellWriter.Write(block.Bottom.Value); cellWriter.Write(block.Lid.Value); cellWriter.Write(block.SlopeType.Value); } } } cellFile.Close(); mapWriter.WriteLine(string.Format("class \"cells/{0}\" (GBHClass) {{ castShadows = false, renderingDistance = {1} }}", cellName, 300)); mapWriter.WriteLine(string.Format("object \"cells/{0}\" ({1}, {2}, {3}) {{}}", cellName, (x * cellWidth * blockScale), -(y * cellWidth * blockScale), 0)); } } }
public static void Initialize() { MainCamera = new PerspectiveCamera(MathHelper.ToRadians(30.0f), 1280f / 720f, 1.0f, 50.0f); MainCamera.Position = new Vector3(72.0f, -190.0f, 12.0f); FOV = ConVar.Register("FOV", 30.0f, "The field of view in degrees", ConVarFlags.Cheat); // TODO: dynamically obtain aspect ratio/FOV //ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(30f), 1280f / 720f, 1.0f, 50.0f); }
private static void ProcessPacket(NetAddress from, byte[] buffer) { if (ConVar.GetValue <bool>("sv_running")) { Server.ProcessPacket(from, buffer); } else { Client.ProcessPacket(from, buffer); } }
public static void Initialize(GraphicsDevice device) { // register convar r_hdr_enable = ConVar.Register("r_hdr_enable", true, "Enable high dynamic range rendering.", ConVarFlags.Archived); // create render targets int width = device.PresentationParameters.BackBufferWidth; int height = device.PresentationParameters.BackBufferHeight; _colorRT = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.Depth16); _depthRT = new RenderTarget2D(device, width, height, false, SurfaceFormat.Single, DepthFormat.Depth16); _normalRT = new RenderTarget2D(device, width, height, false, SurfaceFormat.Color, DepthFormat.Depth16); _lightRT = new RenderTarget2D(device, width, height, false, (r_hdr_enable.GetValue <bool>()) ? SurfaceFormat.Rgba1010102 : SurfaceFormat.Color, DepthFormat.Depth16); if (r_hdr_enable.GetValue <bool>()) { _hdrRT = new RenderTarget2D(device, width, height, false, SurfaceFormat.Rgba1010102, DepthFormat.None); _hdrBloomRT = new RenderTarget2D(device, width, height, false, SurfaceFormat.Rgba1010102, DepthFormat.None); int sampleEntries = 1; int startSize = Math.Min(width / 16, height / 16); int size = 16; for (size = 16; size < startSize; size *= 4) { sampleEntries++; } _lightDownsampleRTs = new RenderTarget2D[sampleEntries]; size /= 4; for (int i = 0; i < sampleEntries; i++) { _lightDownsampleRTs[i] = new RenderTarget2D(device, size, size, false, SurfaceFormat.Single, DepthFormat.None); size /= 4; } _avgLightRT = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Single, DepthFormat.None); } // load shaders _baseEffect = EffectManager.Load("BaseDraw", device); _compositeEffect = EffectManager.Load("ScreenComposite", device); _bloomEffect = EffectManager.Load("Bloom", device); _lightnessEffect = EffectManager.Load("Lightness", device); // light renderer LightRenderer.Initialize(device); // shadow renderer ShadowRenderer.Initialize(device); }
public static void Initialize() { cl_maxpackets = ConVar.Register("cl_maxpackets", 33, "", ConVarFlags.Archived); // FIXME: interpolation only works at server frame time cl_snapDelay = ConVar.Register("cl_snapDelay", 50, "Amount of time to delay the rendering by", ConVarFlags.Archived); _serverChannel = new NetChannel(NetChannelType.ClientToServer, NetAddress.Loopback); //_entities = new Entity[4096]; InitializeConnection(); State = ClientState.Idle; }
private static ConVar RegisterNew(string name, Type type, object defaultValue, string description, ConVarFlags flags) { var convar = new ConVar(name); convar._type = type; convar._value = defaultValue; convar._defaultValue = defaultValue; convar._description = description; convar._flags = flags; _convars.Add(name.ToLowerInvariant(), convar); return(convar); }
private static void ProcessOutOfBand(NetAddress from, byte[] packet) { var message = Encoding.UTF8.GetString(packet, 4, packet.Length - 4); var args = Command.Tokenize(message); if (args.Length == 0) { return; } switch (args[0]) { case "challengeResponse": if (State != ClientState.Challenging) { return; } _lastConnectPacketTime = -999999; _lastMessageReceivedAt = _clientTime; _challenge = int.Parse(args[1]); State = ClientState.Connecting; break; case "connectResponse": if (State != ClientState.Connecting) { return; } _clientNum = int.Parse(args[1]); if (!ConVar.GetValue <bool>("sv_running")) { Server.CreatePhysicsWorld(); MapManager.Load(string.Format("Maps/{0}.gmp", args[2])); } _lastConnectPacketTime = -999999; _lastMessageReceivedAt = _clientTime; _serverChannel = new NetChannel(NetChannelType.ClientToServer, from); InitializeConnection(); State = ClientState.Connected; break; } }
/// <summary> /// Global server initialization code /// </summary> public static void Initialize() { // temp stuff to keep in sync with client using Game.Time //_serverTime = Game.Time; ConVar.Register("sv_gravity", 0.5f, "Gravitational value", ConVarFlags.None); _clients = new ServerClient[24]; _rng = new Random(); // testing stuff: add local client //_clients[0] = new ServerClient(); //_clients[0].Channel = new NetChannel(NetChannelType.ServerToClient, NetAddress.Loopback); //_clients[0].Name = "me"; }
protected override void Initialize() { //EventInput.Initialize(this.Window); Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); Log.AddListener(new GameLogListener()); ConVar.Initialize(); FileSystem.Initialize(); StyleManager.Load("Styles/bil.sty"); MapManager.Load("Maps/MP1-comp.gmp"); MapGeometry.Initialize(); Camera.Initialize(); base.Initialize(); }
public static void Load(string filename) { if (filename.ToLowerInvariant() == _currentMap) { return; } _currentMap = filename.ToLowerInvariant(); ConVar.SetValue("mapname", Path.GetFileNameWithoutExtension(filename)); Stream mapFile = FileSystem.OpenCopy(filename); BinaryReader reader = new BinaryReader(mapFile); GBMPHeader header = new GBMPHeader(); header.Read(reader); if (header.Magic != 0x504D4247 || header.Version != 500) { throw new InvalidOperationException("this isn't a GBMP v.500"); } while (!mapFile.EndOfStream()) { GBMPChunk chunk = new GBMPChunk(); chunk.Read(reader); if (chunk.Type == 0x50414D44) // DMAP { LoadCompressedMap(mapFile); } else if (chunk.Type == 0x5448474C) // LGHT { LoadLights(mapFile, (chunk.Size / 16)); } else { mapFile.Position += chunk.Size; } } mapFile.Close(); CellManager.InitializeFromMap(); }
public static void HandleCommand(string[] args) { ConVar command = Find(args[0]); if (command == null) { return; } if (args.Length == 1) { Log.Write(LogLevel.Info, "\"{0}\" is:\"{1}^7\" default:\"{2}^7\"", command.Name, command.GetValue <string>(), command._defaultValue.ToString()); return; } command.SetValue <string>(args[1], false); }
/// <summary> /// 'kick' command handler /// </summary> /// <param name="name">player to kick</param> public static void Kick_f(string name) { if (!ConVar.GetValue <bool>("sv_running")) { Log.Write(LogLevel.Error, "Server is not running."); return; } foreach (ServerClient thisClient in _clients) { if (thisClient != null) { if (thisClient.Name.ToLower() == name.ToLower()) { DropClient(thisClient, "Player kicked"); } } } }
private static void UpdateSuggestions() { if (_typedInputBuffer.Contains(' ') || _typedInputBuffer == "") { _suggestions.Clear(); _currentSuggestion = 0; return; } if (_typedInputBuffer != _suggestionSource) { var suggestions = from command in ConVar.GetConVars() where command.Name.ToLower().StartsWith(_typedInputBuffer.ToLower()) && command.Name.ToLower() != _typedInputBuffer.ToLower() select command.Name; _suggestions = suggestions.ToList(); _currentSuggestion = -1; } }
public static void ExportMain(string[] args) { var filename = args[1]; var outDir = "Export/Maps/" + filename + "/"; Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir + "cells"); Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); ConVar.Initialize(); FileSystem.Initialize(); StyleManager.Load("Styles/" + filename + ".sty"); var bitmap = StyleManager.GetBitmap(); bitmap.Save(string.Format("{0}/{1}.png", outDir, filename), System.Drawing.Imaging.ImageFormat.Png); }
public void SendMessage(byte[] message) { // message header var outMessage = new BitStream(); outMessage.WriteUInt32(SequenceOut); SequenceOut++; // write the message outMessage.WriteBytes(message); NetManager.SendPacket(ChannelType, Address, outMessage.Bytes); // log the packet if (ConVar.GetValue <bool>("net_showpackets")) { Log.Write(LogLevel.Debug, "sending {0}b, seq={1}", outMessage.Bytes.Length, SequenceOut); } }
public static void Initialize(GraphicsDevice device) { _shadowEffect = EffectManager.Load("Shadow", device); _shadowMap = new RenderTarget2D(device, 2048, 2048, false, SurfaceFormat.Single, DepthFormat.Depth16); _shadowOcclusion = new RenderTarget2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None); _disabledShadowOcclusion = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Color, DepthFormat.None); shadowOcclusionTechniques[0] = _shadowEffect.Techniques["CreateShadowTerm2x2PCF"]; /*shadowOcclusionTechniques[1] = _shadowEffect.Techniques["CreateShadowTerm3x3PCF"]; * shadowOcclusionTechniques[2] = _shadowEffect.Techniques["CreateShadowTerm5x5PCF"]; * shadowOcclusionTechniques[3] = _shadowEffect.Techniques["CreateShadowTerm7x7PCF"];*/ _frustumCornersVS = new Vector3[8]; _frustumCornersWS = new Vector3[8]; _frustumCornersLS = new Vector3[8]; _farFrustumCornersVS = new Vector3[4]; sm_enable = ConVar.Register("sm_enable", true, "Enable shadow mapping", ConVarFlags.Archived); sm_filterType = ConVar.Register("sm_filterType", 0, "Defines the filtering algorithm to use for shadow mapping", ConVarFlags.Archived); }
/// <summary> /// Per-frame server processing function /// </summary> public static void Process() { if (!ConVar.GetValue <bool>("sv_running")) { return; } CellManager.Recenter(from client in _clients where client != null && client.Entity != null select client.Entity.Position); _residualTime += Game.FrameMsec; // 20 FPS = 50msec intervals while (_residualTime > 50) { _residualTime -= 50; _serverTime += 50; ProcessGame(); } }
/// <summary> /// 'status' command handler /// </summary> public static void Status_f() { if (!ConVar.GetValue <bool>("sv_running")) { Log.Write(LogLevel.Error, "Server is not running."); } else { Log.Write(LogLevel.Info, "map: {0}", _mapName); Log.Write(LogLevel.Info, "num name state address "); Log.Write(LogLevel.Info, "--- ------------------ ----- ---------------------"); foreach (ServerClient client in _clients) { if (client != null) { var num = client.ClientNum.ToString().PadLeft(3); var name = client.Name.ToString().PadRight(18); var state = " "; switch (client.State) { case ServerClientState.Connected: case ServerClientState.Initialized: state = "CNCT "; break; case ServerClientState.Zombie: state = "ZMBI "; break; } var ip = client.ExternalIP.ToString().PadRight(21); Log.Write(LogLevel.Info, "{0} {1} {2} {3}", num, name, state, ip); } } } }
public static void ToolMain(string[] args) { var filename = args[1]; var outMaterialFile = "Data/Styles/" + filename + ".material"; var outBitmap = "Data/Styles/" + filename + ".png"; Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); ConVar.Initialize(); FileSystem.Initialize(); StyleManager.Load("Styles/" + filename + ".sty"); // save the texture Vector2 uv; var bitmap = StyleManager.GetBitmap(); bitmap.Save(outBitmap, System.Drawing.Imaging.ImageFormat.Png); // create a material file var writer = new StreamWriter(outMaterialFile); for (int i = 0; i < 992; i++) { StyleManager.GetTileTextureBordered(i, out uv); writer.WriteLine(string.Format("gbh/{0}/{1}", filename, i)); writer.WriteLine("{"); writer.WriteLine(string.Format("\ttexture Styles/{0}.png", filename)); writer.WriteLine(string.Format("\tuv {0} {1} {2} {3}", uv.X, uv.Y, uv.X + 0.03125f, uv.Y + (0.03125f / 2))); writer.WriteLine("}"); writer.WriteLine(); } writer.Close(); }
private static void CheckConnectPacket() { switch (State) { case ClientState.Challenging: if ((_clientTime - _lastConnectPacketTime) > 2000) { NetManager.SendOOBPacket(NetChannelType.ClientToServer, _currentServer, "getchallenge"); _lastConnectPacketTime = (int)_clientTime; } break; case ClientState.Connecting: if ((_clientTime - _lastConnectPacketTime) > 2000) { // TODO: use a proper nickname here // TODO: make nickname changes *dynamic* :o var nicknameToUse = ConVar.GetValue <string>("nicknamee"); NetManager.SendOOBPacket(NetChannelType.ClientToServer, _currentServer, "connect {0} \"{1}\"", _challenge, nicknameToUse); _lastConnectPacketTime = (int)_clientTime; } break; } }
public static void ExecuteNow(string command) { string[] args = Tokenize(command); if (args.Length == 0) { return; } ConVar.HandleCommand(args); // some quick commands if (args[0] == "a") { args = new[] { "map", "mp1-comp" }; } else if (args[0] == "b") { args = new[] { "connect", "192.168.178.83:29960" }; } // quick hack to allow a connect command if (args[0] == "connect") { Client.Connect_f(args); } else if (args[0] == "map") { if (args.Length != 2) { Log.Write(LogLevel.Error, "Please enter the map name you want."); return; } var mapName = args[1]; MapManager.Load(string.Format("Maps/{0}.gmp", mapName)); Server.InitializeMap(mapName); Client.Connect_f(new[] { "connect", "localhost" }); } else if (args[0] == "say") { Client.SendReliableCommand(command); } if (args[0] == "quit") { Log.Write(LogLevel.Info, "Client shutting down.."); Environment.Exit(1); } // status command, mmk? if (args[0] == "status") { Server.Status_f(); } if (args[0] == "kick") { if (args.Length != 2) { Log.Write(LogLevel.Error, "Please enter the nickname of the user you want to kick."); return; } Server.Kick_f(args[1]); } if (args[0] == "clear") { Client.ClearConsole(); } // isn't this an odd place to do it if (args[0] == "nickname") { // TODO: Introduce a config saving system based on the quake one. if (args[1].Length > 18) { Log.Write(LogLevel.Error, "Your nickname is to long."); return; } ConVar.SetValue <string>("nicknamee", args[1]); var path = Directory.GetCurrentDirectory() + "\\config.ini"; IniFile ini = new IniFile(path); ini.IniWriteValue("CONFIG", "nickname", args[1]); } if (args[0] == "kill") { if (args.Length != 2) { Log.Write(LogLevel.Error, "You didn't specify the user to 'kill'."); return; } Server.KillClient(args[1]); /*SendReliableCommand(null, "print \"{0} drowned...\"", client.Name); * //client.Entity.Die(); * client.Entity.Spawn();*/ } }
public static void ExportMain(string[] args) { var filename = args[1]; var outDir = "Export/Maps/" + filename + "/"; Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir + "cells"); Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); ConVar.Initialize(); FileSystem.Initialize(); MapManager.Load("Maps/" + filename + ".gmp"); // export cell files var cellWidth = 32; var cellHeight = 32; var blockScale = 4.5f; var mapFile = File.Open(string.Format("{0}/cells.lua", outDir), FileMode.Create, FileAccess.Write); var mapWriter = new StreamWriter(mapFile); for (int x = 0; x < (256 / cellWidth); x++) { for (int y = 0; y < (256 / cellHeight); y++) { var cellName = string.Format("{0}_{1}_{2}", filename, x, y); var cellFile = File.OpenWrite(string.Format("{0}/cells/{1}.cell", outDir, cellName)); var cellWriter = new BinaryWriter(cellFile); for (int c = 0; c < 7; c++) { for (int b = (y * cellHeight); b < (y * cellHeight) + cellHeight; b++) { for (int a = (x * cellWidth); a < (x * cellWidth) + cellWidth; a++) { var block = MapManager.GetBlock(a, b, c); cellWriter.Write(block.Left.Value); cellWriter.Write(block.Right.Value); cellWriter.Write(block.Top.Value); cellWriter.Write(block.Bottom.Value); cellWriter.Write(block.Lid.Value); cellWriter.Write(block.SlopeType.Value); } } } cellFile.Close(); mapWriter.WriteLine(string.Format("class \"cells/{0}\" (GBHClass) {{ castShadows = false, renderingDistance = {1} }}", cellName, 300)); mapWriter.WriteLine(string.Format("object \"cells/{0}\" ({1}, {2}, {3}) {{}}", cellName, (x * cellWidth * blockScale), -(y * cellWidth * blockScale), 0)); } } mapWriter.Close(); // export lights mapFile = File.Open(string.Format("{0}/lights.lua", outDir), FileMode.Create, FileAccess.Write); mapWriter = new StreamWriter(mapFile); mapWriter.WriteLine("local l"); mapWriter.WriteLine("gbh_lights = {}"); foreach (var light in MapManager.Lights) { mapWriter.WriteLine(string.Format("l = light_from_table({{ pos = vector3({0}, {1}, {2}), diff = vector3({3}, {4}, {5}), range = {6}, coronaColour = V_ZERO }})", light.Position.X * 4.5f, light.Position.Y * -4.5f, light.Position.Z * 4.5f, light.Color.R / 255.0f, light.Color.G / 255.0f, light.Color.B / 255.0f, light.Radius * 4.5f)); mapWriter.WriteLine("l.enabled = true"); mapWriter.WriteLine("table.insert(gbh_lights, l)"); mapWriter.WriteLine(); } mapWriter.Close(); }
public static void Initialize() { // set the current culture to the invariant culture Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // initialize the logging service Log.Initialize(LogLevel.All); Log.AddListener(new ConsoleLogListener()); Log.AddListener(new GameLogListener()); Log.AddListener(new FileLogListener("GBHGame.log", false)); Log.Write(LogLevel.Info, "GBH2 v0 initializing"); Log.Write(LogLevel.Critical, "jeremych is an egghead and a nabsalad"); ConVar.Initialize(); FileSystem.Initialize(); Win32System.Initialize(); MapGeometry.Initialize(); //StyleManager.Load("Styles/bil.sty"); //MapManager.Load("Maps/MP1-comp.gmp"); Camera.Initialize(); NetManager.Initialize(29960); Client.Initialize(); Server.Initialize(); GameWindow.Initialize(); com_maxFPS = ConVar.Register("com_maxFPS", 0, "Maximum framerate for the game loop.", ConVarFlags.Archived); timescale = ConVar.Register("timescale", 1.0f, "Scale time by this amount", ConVarFlags.Cheat); sv_running = ConVar.Register("sv_running", true, "Is the server running?", ConVarFlags.ReadOnly); cl_running = ConVar.Register("cl_running", false, "Is the client running?", ConVarFlags.ReadOnly); sv_paused = ConVar.Register("sv_paused", false, "Is the server paused?", ConVarFlags.ReadOnly); cl_paused = ConVar.Register("cl_paused", false, "Is the client paused?", ConVarFlags.ReadOnly); net_showpackets = ConVar.Register("net_showpackets", false, "Show network packets.", ConVarFlags.None); mapname = ConVar.Register("mapname", "", "Current mapname", ConVarFlags.ReadOnly); nickname = ConVar.Register("nickname", Environment.GetEnvironmentVariable("username"), "Your nickname", ConVarFlags.Archived); Renderer.Initialize(); MaterialManager.ReadMaterialFile("base.material"); MaterialManager.ReadMaterialFile("Styles/bil.material"); ConsoleRenderer.Initialize(); //StyleManager.CreateTextures(Renderer.Device); MapRenderer.Initialize(Renderer.Device); DeferredRenderer.Initialize(Renderer.Device); Renderer2D.Initialize(Renderer.Device); // jeez, people these days just need to get a *proper* nickname if (ConVar.GetValue <string>("nicknamee") == Environment.GetEnvironmentVariable("username")) { Log.Write(LogLevel.Info, "It looks it's your first time running GBH2. Please type 'nickname <WANTED NICKNAME>' to set your nickname."); } var path = Directory.GetCurrentDirectory() + "\\config.ini"; IniFile ini = new IniFile(path); var value = ini.IniReadValue("CONFIG", "nickname"); if (value != null) { ConVar.SetValue <string>("nicknamee", value); } }
public static void Initialize() { ConVar.Register("cheats", false, "Enable cheats", ConVarFlags.None); }
private static void Walk() { Vector3 direction = Vector3.Zero; // possibly change this to be more shared (only do forward/backward difference) var heading = 0f; if (_command.TestButton(ClientButtons.Forward)) { heading = MathHelper.ToRadians(_entity.Rotation.Z); direction = new Vector3((float)Math.Sin(heading) * -1f, (float)Math.Cos(heading) * 1f, 0f); } if (_command.TestButton(ClientButtons.Backward)) { heading = MathHelper.ToRadians(_entity.Rotation.Z + 180f); direction = new Vector3((float)Math.Sin(heading) * -1f, (float)Math.Cos(heading) * 1f, 0f); } /*if (direction == Vector3.Zero) * { * return; * }*/ float slopeZ = 1.0f * _dT + 0.25f; var velocity = direction * _dT; velocity.Z = _entity.VelocityZ; velocity.Z -= ConVar.GetValue <float>("sv_gravity") * _dT; // perform collision tests JVector normal; float fraction; RigidBody body; JVector testDirection; if (direction != Vector3.Zero) { // X axis testDirection = new JVector(velocity.X, 0f, 0f); testDirection += new JVector(0.25f * direction.X, 0f, 0f); _pw.CollisionSystem.Raycast((_entity.Position + new Vector3(0f, 0f, slopeZ)).ToJVector(), testDirection, null, out body, out normal, out fraction); if (fraction <= 1.0f) { // hit a wall // float pedBorder = -0.25f; // if (testDirection.X < 0f) // { // pedBorder = -pedBorder; // } velocity.X = 0.0f; // _entity.Position = new Vector3(_entity.Position.X + (testDirection * fraction).X + pedBorder, _entity.Position.Y, _entity.Position.Z); } // Y axis testDirection = new JVector(0f, velocity.Y, 0f); testDirection += new JVector(0f, 0.25f * direction.Y, 0f); _pw.CollisionSystem.Raycast((_entity.Position + new Vector3(0f, 0f, slopeZ)).ToJVector(), testDirection, null, out body, out normal, out fraction); if (fraction <= 1.0f) { // hit a wall velocity.Y = 0.0f; } } // Z axis Vector3 basePosition = (_entity.Position + new Vector3(0f, 0f, slopeZ)); testDirection = new JVector(0f, 0f, velocity.Z - slopeZ); _pw.CollisionSystem.Raycast((basePosition).ToJVector(), testDirection, null, out body, out normal, out fraction); if (fraction <= 1.0f) { // hit the ground velocity.Z = 0.0f; _entity.Position = new Vector3(basePosition.X, basePosition.Y, basePosition.Z + (testDirection * fraction).Z); } _entity.Position += velocity; _entity.VelocityZ = velocity.Z; }