btower

Members
  • Content count

    87
  • Joined

  • Last visited

Community Reputation

1661 Excellent

About btower

  • Rank
    GDNet+
  1. Because users can get creative in ways you might have not imagined; they might be able to circumvent your verifyUserInput method in a way that you did not expect. Use parameters in queries instead, which accept data for the types they really are irrespective of its content.   I.e.  SELECT * FROM MyTable WHERE SomeField=@MyParameter And then you define the type and value of @MyParameter -- the specific implementation details depend on the programming language, API and SQL language you're using.
  2. Unity Unity Code Help

    In that case it seems like you forgot to actually fill in the BallPrefab variable using the Inspector window (You should assign a prefab to the variable). BallPrefab must be declared as a public field (not a property or a method) for it to actually appear in the Inspector window.   How to do this is also explained in the video I linked earlier.
  3. Unity Unity Code Help

      I would say so too, but I saw a video of a Unity 5 primer this week where the programmer actually makes the same mistake, explains, fixes and tests it. See https://youtu.be/6eVfcEYxBPg?t=54m47s
  4. Unity Unity Code Help

    I'm not 100% sure if this is it (I haven't tested it), but if you're using Unity 5 then Instantiate will not return what you expect in your code. Instantiate will return an object of type Transform, from which you can use the GetComponent<Rigidbody>() method to get the actual Rigidbody you are looking for.   So instead of this: Rigidbody rbBall; rbBall = Instantiate(BallPrefab,trans.position,trans.rotation) as Rigidbody; rbBall.AddForce(trans.forward * Speed); Use this: Rigidbody rbBall; var ballTransform = Instantiate(BallPrefab,trans.position,trans.rotation) as Transform; rbBall = ballTransform.GetComponent<Rigidbody>(); rbBall.AddForce(trans.forward * Speed);
  5.   Right click on the Solution (in the Solution Explorer inside Visual Studio) and select Enable NuGet Package Restore. Then try building the solution again. NuGet should then automatically download any missing package, if able.
  6. Minecraft stores modified chunks, in full, on the disk and loads them when the chunk is needed again. So in order words, once a part of the procedurally generated world is modified and this modification cannot be deduced from the procedural system itself, that part of the world needs to be saved and is no longer procedural.
  7. File Loading Module

    I think the main problem with this design is the genericness of the FileLoadingManager. If you rename this class to MeshLoadingManager, things will be more logical, and also the return types of various loading functions in the class is alot easier to comprehend (i.e. the LoadFile method returns an object of type IMesh).   You will then need different types of LoadingManagers for each type of object you want to load (i.e. Mesh, Sound, Texture, etc). You can then make a generic FileLoadingManager that contains a MeshLoadingManager, SoundLoadingManager, TextureLoadingManager and so on, with a file extension map to the different types of loading managers.   I would also rename the classes to FileLoader, MeshLoader and I wouldn't make them a singleton.   Hopefully you can adjust your design based on the above.
  8. The .NET Panel class has a method named PointToClient that accepts a Point as input. The Point should be in screen coordinates (in your case; the mouse cursor position relative to the screen itself), the result is a Point that is relative to the Panel.
  9. Dynamically create VertexType struct?

    It does have to map 1 to 1 with the layout, indeed. But the pSysMem pointer doesn't have to be an array (or pointer) of type SVertex. You can create a byte array and fill it using the same method I used in the aforementioned example. You can use assimp's aiMesh to check if the layout has the position, normal, and so on and add them to the array of bytes in the same order as you did in the input layout.   I hope that suits your needs. Here is quick&dirty example (don't use it directly, it's just to show how it would work, I didnt try to compile it):     HRESULT SMesh::CreateVB(ID3D11DeviceContext* dc, ID3D11Device* device, aiMesh * mesh) {  HRESULT hr;    int singleVertexSize = 3*3; // in bytes (x,y,z = 3 floats); always has position, so no need to check that  if (mesh->HasNormals()) singleVertexSize += 3*3; // x,y,z = 3 floats  if (mesh->HasTexCoords()) singleVertexSize += 2*3; // u,v = 2 floats  ZeroMemory( &bufferDesc, sizeof(bufferDesc) );     bufferDesc.Usage            = D3D11_USAGE_DEFAULT;     bufferDesc.ByteWidth        = singleVertexSize * mesh->mNumVertices;     bufferDesc.BindFlags        = D3D11_BIND_VERTEX_BUFFER;     bufferDesc.CPUAccessFlags   = 0;     bufferDesc.MiscFlags        = 0;  vertexCount = mesh->mNumVertices;  char * pmem = new char[singleVertexSize];  float * fp;  for (int i = 0; i < mesh->mNumVertices; ++i)  {   fp = (float*)pmem;   *fp = mesh->mVertices[i].x;   *(fp+1) = mesh->mVertices[i].y;   *(fp+2) = mesh->mVertices[i].z;   if (mesh->HasNormals())   {    *(fp+3) = mesh->mNormals[i].x;    *(fp+4) = mesh->mNormals[i].y;    *(fp+5) = mesh->mNormals[i].z;   }   if (mesh->HasTexCoords())   {    *(fp+6) = mesh->mTexCoords[i].u;    *(fp+7) = mesh->mTexCoords[i].v;   }   pmem += singleVertexSize;  }    //ZeroMemory( &InitData, sizeof(InitData) );   not really needed, you fill all members below explicitly..  InitData.pSysMem = pmem;  InitData.SysMemPitch = 0;  InitData.SysMemSlicePitch = 0;  hr = device->CreateBuffer( &bufferDesc, &InitData, &vertexBuffer[0] );  delete [] pmem;  return hr; }
  10. Dynamically create VertexType struct?

    Dynamically generating an input layout based on what you need doesn't need to be complex at all. See below for a quick example.   The exciting part is ensuring a specific input layout is only loaded once and used across multiple meshes. I'm not sure if that's what you were asking?     D3D11_INPUT_ELEMENT_DESC dynamicLayout[MAX_ELEMENTS_YOU_SUPPORT]; int lastIndex = 0; aiMesh * mesh; // <- assumed that your assimp mesh is in here // repeat the sample below for normal, texcoord, tangents, etcetera.. if (mesh->HasPosition()) {  dynamicLayout[lastIndex].SemanticName = "POSITION";  dynamicLayout[lastIndex].SemanticIndex = 0;  dynamicLayout[lastIndex].Format = DXGI_FORMAT_R32G32B32_FLOAT;  dynamicLayout[lastIndex].InputSlot = 0;  dynamicLayout[lastIndex].AlignedByteOffset = 0;  dynamicLayout[lastIndex].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;  dynamicLayout[lastIndex].InstanceDataStepRate = 0;  ++lastIndex; } ID3D11InputLayout * layout; // output is stored in here, you need this later on when rendering HRESULT result = d3ddevice->CreateInputLayout(dynamicLayout, lastIndex, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout); if (FAILED(result)) {  //error handling } // after the input layout is created, you don't need the dynamicLayout array anymore, so it can go out-of-scope or you can delete it if it was dynamically allocated.
  11. Big Array to String Speed

    How about the following: [source lang="csharp"] //this just generates a "big string array" to play with List<string> bigList = new List<string>(); for (int i = 0; i < 25000; ++i) bigList.Add("someMediumLengthString"); string[] bigStringArray = bigList.ToArray(); //measure time DateTime start = DateTime.Now; //now we do the part that matters string ourHugeCombinedString = string.Join<string>('\n'.ToString(), bigStringArray); //print out the time it took to make the giant string TimeSpan timeToMakeCombinedString = DateTime.Now.Subtract(start); System.Diagnostics.Debug.WriteLine(timeToMakeCombinedString.TotalMilliseconds.ToString()); //prints out "2,0001" on my system, so 2 ms![/source]
  12. UDP and TCP

    UDP with guaranteed delivery is not "basically TCP annihilating the advantage of UDP"... TCP is much more than that. TCP doesn't just guarantee delivery, it also guarantee's the packets to arrive in order, and it also manages flow of packets (flow control). You should just use UDP. For an excellent resource explaining all the details, see: [url="http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/"]http://gafferongames...ers/udp-vs-tcp/[/url]
  13. A few quick math questions

    I refer you to this blog post I found that explains all the concepts above in plain English with game-related examples. Sounds like it's exactly what you're looking for: [url="http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/"]http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/[/url] Hope it helps!
  14. Signing a message

    I've written this once for VB.NET. I hope you can read it and easily convert it to C#. It's not very difficult to do in .NET. I just use these two small helper classes for it. As you mentioned, you found a lot of pointers on how to generate the certificate itself - so I won't explain that here. [CODE] Imports System.IO Imports System.Security.Cryptography Imports System.Security.Cryptography.X509Certificates Namespace Security.Cryptography ''' <summary> ''' Provides methods to sign and verify SHA1/RSA 1024 bits signatures. ''' </summary> ''' <remarks></remarks> <DebuggerNonUserCode()> _ Public NotInheritable Class SHA1RSASigner ''' <summary> ''' Signs a string using SHA-1 hashing, then 1024 bits RSA signing (private key is necessairy) and returns the result base64 encoded. ''' </summary> ''' <param name="cert">A certificate containing a private key. This will be used to make an authentic signature.</param> ''' <param name="stringToSign">The string to make a signature for.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function CreateSignatureBase64(ByVal cert As Certificate, ByVal stringToSign As String) As String If (cert Is Nothing) Then Return String.Empty If (Not cert.HasPrivateKey) Then Return String.Empty If (String.IsNullOrEmpty(stringToSign)) Then Return String.Empty Dim bytes() As Byte = Encoding.ASCII.GetBytes(stringToSign) Dim sha As New SHA1Managed sha.Initialize() Dim shaDigest() As Byte = sha.ComputeHash(bytes) Dim rsa As RSACryptoServiceProvider = cert.GetRSACryptoServiceProvider() Dim rsaDigest() As Byte = rsa.SignHash(shaDigest, CryptoConfig.MapNameToOID("SHA1")) Return Convert.ToBase64String(rsaDigest) End Function ''' <summary> ''' Verifies a (plain-text) String based on a digital signature that is SHA-1 hashed, then RSA 1024 bits signed and finally base64 encoded. ''' </summary> ''' <param name="publicKey">The public key of the one who signed the message (the iDEAL acquirer's certificate).</param> ''' <param name="originalString">Plain-text string containing the signed text.</param> ''' <param name="base64TokenToVerify">The base64 encoded digital signature created by the sender (iDEAL acquirer).</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function VerifySignatureBase64(ByVal publicKey As Certificate, ByVal originalString As String, ByVal base64TokenToVerify As String) As Boolean If (publicKey Is Nothing) Then Return False If (String.IsNullOrEmpty(originalString)) Then Return False If (String.IsNullOrEmpty(base64TokenToVerify)) Then Return False Dim bytes() As Byte = Encoding.ASCII.GetBytes(originalString) Dim sha As New SHA1Managed sha.Initialize() Dim shaDigestOriginal() As Byte = sha.ComputeHash(bytes) bytes = Convert.FromBase64String(base64TokenToVerify) Dim rsa As RSACryptoServiceProvider = publicKey.GetRSACryptoServiceProvider() Return rsa.VerifyHash(shaDigestOriginal, CryptoConfig.MapNameToOID("SHA1"), bytes) End Function End Class End Namespace [/CODE] [CODE] Imports System.IO Imports System.Security.Cryptography Imports System.Security.Cryptography.X509Certificates Namespace Security.Cryptography ''' <summary> ''' Represents a X509 certificate (PKCS #12). ''' </summary> ''' <remarks></remarks> <DebuggerNonUserCode()> _ Public NotInheritable Class Certificate Private _certificate As X509Certificate2 #Region " Properties " ''' <summary> ''' Gets the fingerprint of the certificate. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property FingerPrint() As String Get If (_certificate Is Nothing) Then Return String.Empty Return _certificate.Thumbprint End Get End Property ''' <summary> ''' Gets wether this certificate contains a private key. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property HasPrivateKey() As Boolean Get If (_certificate Is Nothing) Then Return False Return _certificate.HasPrivateKey End Get End Property ''' <summary> ''' Gets the private key of this certificate, if available. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property PrivateKey() As String Get If ((_certificate Is Nothing) OrElse (_certificate.PrivateKey Is Nothing)) Then Throw New CertificateException("This certificate does not contain a private key.") Try Return _certificate.PrivateKey.ToXmlString(True) Catch ex As Exception Throw New CertificateException(String.Concat(ex.Message, " See InnerException for more details."), ex) End Try End Get End Property ''' <summary> ''' Gets the public key of this certificate, if available. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property PublicKey() As String Get If ((_certificate Is Nothing) OrElse (_certificate.PublicKey Is Nothing) OrElse (_certificate.PublicKey.Key Is Nothing)) Then Throw New CertificateException("This certificate does not contain a public key.") Try Return _certificate.PublicKey.Key.ToXmlString(False) Catch ex As Exception Throw New CertificateException(String.Concat(ex.Message, " See InnerException for more details."), ex) End Try End Get End Property #End Region ''' <summary> ''' Loads an existing certificate based on a PKCS #12 file. ''' </summary> ''' <param name="fileName">Virtual path to a PKCS #12 certificate file. Supports CER (publickey) and P12 (privatekey) files.</param> ''' <param name="password">Optional password if the file requires one.</param> Public Sub New(ByVal fileName As String, Optional ByVal password As String = Nothing) Try Dim certificateBytes() As Byte Dim context As HttpContext = HttpContext.Current If (context Is Nothing) Then certificateBytes = File.ReadAllBytes(fileName.Replace("/"c, "\"c).Replace("~", Environment.CurrentDirectory)) Else certificateBytes = File.ReadAllBytes(context.Request.MapPath(fileName)) End If If ((certificateBytes IsNot Nothing) AndAlso (certificateBytes.Length > 0)) Then _certificate = New X509Certificate2(certificateBytes, password, X509KeyStorageFlags.Exportable Or X509KeyStorageFlags.MachineKeySet Or X509KeyStorageFlags.PersistKeySet) End If Catch ex As Exception Throw New CertificateException(String.Concat("Failed to load certificate file: ", ex.Message, " See InnerException for more details."), ex) End Try End Sub ''' <summary> ''' Creates an RSA Crypto Service provider that is initialized with this certificate's key. The private key is used, if possible. Keysize is set to 1024 bits. ''' </summary> Public Function GetRSACryptoServiceProvider() As RSACryptoServiceProvider RSACryptoServiceProvider.UseMachineKeyStore = True Dim result As New RSACryptoServiceProvider result.KeySize = 1024 If (Me.HasPrivateKey) Then result.FromXmlString(Me.PrivateKey) Else result.FromXmlString(Me.PublicKey) End If Return result End Function End Class End Namespace [/CODE]
  15. Socket Programming

    Did you try the 2nd suggestion I wrote? Background threads are killed automatically once the process stops. By default, threads you create in C# are not background threads (iirc). You can set the IsBackground property of the thread you're running (before you start it of course).