Esempio n. 1
0
 public void Disconnect(bool AfterNextProcess)
 {
     if (AfterNextProcess)
     {
         this.onceOnly = true;
     }
     else
     {
         if (!this.IsConnected)
         {
             return;
         }
         FSUIPCConnection.RemoveOffset((IOffset)this);
     }
 }
Esempio n. 2
0
        public static void Process(byte ClassInstance, IEnumerable <string> GroupNames)
        {
            lock (FSUIPCConnection.dataGroups)
            {
                if (FSUIPCConnection.connections.ContainsKey(ClassInstance))
                {
                    ConnectionInfo connection = FSUIPCConnection.connections[ClassInstance];
                    if (connection.pView == IntPtr.Zero)
                    {
                        throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_NOTOPEN, "The connection to FSUIPC is not open.");
                    }
                    int            num1        = 80;
                    List <IOffset> offsetList1 = new List <IOffset>();
                    int            int32       = connection.pView.ToInt32();
                    int            num2        = int32;
                    int            num3        = 0;
                    int            num4        = 0;
                    List <IOffset> offsetList2 = new List <IOffset>();
                    foreach (string groupName in GroupNames)
                    {
                        if (!FSUIPCConnection.dataGroups.ContainsKey(groupName))
                        {
                            throw new Exception("Group '" + groupName + "' does not exsist.");
                        }
                        Dictionary <Guid, IOffset> dataGroup = FSUIPCConnection.dataGroups[groupName];
                        offsetList2.AddRange((IEnumerable <IOffset>)dataGroup.Values);
                    }
                    int num5 = (num1 << 8) + 97;
                    foreach (IOffset offset in offsetList2)
                    {
                        if (!offset.Write)
                        {
                            switch (offset.DataType)
                            {
                            case fsuipcDataType.TypeByteArray:
                                byte[] numArray = (byte[])offset.Value;
                                if (numArray != null)
                                {
                                    byte[] oldValue = (byte[])offset.OldValue;
                                    bool   flag     = true;
                                    for (int index = 0; index < oldValue.Length; ++index)
                                    {
                                        flag &= (int)oldValue[index] == (int)numArray[index];
                                    }
                                    offset.Write = !flag && (offset.WriteOnly || offset.FileAddress != 0);
                                    break;
                                }
                                break;

                            case fsuipcDataType.TypeBitArray:
                                BitArray bitArray = (BitArray)offset.Value;
                                if (bitArray != null)
                                {
                                    BitArray oldValue = (BitArray)offset.OldValue;
                                    bool     flag     = true;
                                    for (int index = 0; index < oldValue.Length; ++index)
                                    {
                                        flag &= oldValue[index] == bitArray[index];
                                    }
                                    offset.Write = !flag && (offset.WriteOnly || offset.FileAddress != 0);
                                    break;
                                }
                                break;
                            }
                        }
                        ++num4;
                    }
                    int num6 = 0;
                    int num7 = (num5 << 16) + 30060;
                    foreach (IOffset offset in offsetList2)
                    {
                        if (offset.OnceOnly)
                        {
                            offsetList1.Add(offset);
                        }
                        int[] source1 = (int[])null;
                        if (offset.Write)
                        {
                            source1 = new int[3]
                            {
                                2,
                                offset.Address,
                                offset.DataLength
                            };
                            num3 = source1.Length * 4;
                        }
                        else if (!offset.WriteOnly)
                        {
                            source1 = new int[4]
                            {
                                1,
                                offset.Address,
                                offset.DataLength,
                                num7
                            };
                            num3 = source1.Length * 4;
                            offset.FileAddress = num2 + num3;
                        }
                        if (source1 != null)
                        {
                            if ((long)(num2 - int32 + num3 + offset.DataLength + 4) > (long)FSUIPCConnection.MaximumDataSize)
                            {
                                throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_SIZE, "The amount of data requested exceeded the maximum allowed in one Process().");
                            }
                            byte[] source2 = new byte[source1[2]];
                            if (offset.Write)
                            {
                                switch (offset.DataType)
                                {
                                case fsuipcDataType.TypeByte:
                                    source2[0] = (byte)offset.Value;
                                    break;

                                case fsuipcDataType.TypeInt16:
                                    source2 = BitConverter.GetBytes((short)offset.Value);
                                    break;

                                case fsuipcDataType.TypeInt32:
                                    source2 = BitConverter.GetBytes((int)offset.Value);
                                    break;

                                case fsuipcDataType.TypeInt64:
                                    source2 = BitConverter.GetBytes((long)offset.Value);
                                    break;

                                case fsuipcDataType.TypeDouble:
                                    source2 = BitConverter.GetBytes((double)offset.Value);
                                    break;

                                case fsuipcDataType.TypeFloat:
                                    source2 = BitConverter.GetBytes((float)offset.Value);
                                    break;

                                case fsuipcDataType.TypeByteArray:
                                    source2 = (byte[])offset.Value;
                                    if (source2.Length != offset.DataLength)
                                    {
                                        throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_WRITE_OVERFLOW, "Offset for Offset " + offset.Address.ToString("X") + " is a ByteArray with a declared length of " + offset.DataLength.ToString() + " Bytes. The array you are trying to write is different from this. (" + source2.Length.ToString() + " bytes)");
                                    }
                                    source2.CopyTo((Array)offset.OldValue, 0);
                                    break;

                                case fsuipcDataType.TypeUInt16:
                                    source2 = BitConverter.GetBytes((ushort)offset.Value);
                                    break;

                                case fsuipcDataType.TypeUInt32:
                                    source2 = BitConverter.GetBytes((uint)offset.Value);
                                    break;

                                case fsuipcDataType.TypeUInt64:
                                    source2 = BitConverter.GetBytes((ulong)offset.Value);
                                    break;

                                case fsuipcDataType.TypeString:
                                    string s = (string)offset.Value;
                                    if (s.Length >= offset.DataLength)
                                    {
                                        s = s.Substring(0, offset.DataLength - 1);
                                    }
                                    source1[2] = s.Length + 1;
                                    source2    = new byte[source1[2]];
                                    Encoding.ASCII.GetBytes(s).CopyTo((Array)source2, 0);
                                    break;

                                case fsuipcDataType.TypeBitArray:
                                    BitArray bits = (BitArray)offset.Value;
                                    if (bits.Length != offset.DataLength * 8)
                                    {
                                        throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_WRITE_OVERFLOW, "Offset for Offset " + offset.Address.ToString("X") + " is a BitArray with a declared length of " + offset.DataLength.ToString() + " Bytes. The BitArray you are trying to write is different from this. (" + bits.Length.ToString() + " bits)");
                                    }
                                    offset.OldValue = (object)new BitArray(bits);
                                    bits.CopyTo((Array)source2, 0);
                                    break;

                                case fsuipcDataType.TypeSByte:
                                    source2[0] = (byte)offset.Value;
                                    break;
                                }
                            }
                            Marshal.Copy(source1, 0, new IntPtr(num2), source1.Length);
                            num2 += num3;
                            Marshal.Copy(source2, 0, new IntPtr(num2), source2.Length);
                            num2 += source2.Length;
                        }
                        ++num6;
                    }
                    Marshal.WriteInt32(new IntPtr(num2), 0);
                    IntPtr result = IntPtr.Zero;
                    int    num8   = 0;
                    while (Win32.SendMessageTimeout(connection.hWnd, connection.messageID, connection.atomFileName, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_BLOCK, 2000U, out result) == IntPtr.Zero && num8 < 10)
                    {
                        ++num8;
                        Thread.Sleep(100);
                    }
                    if (num8 >= 10)
                    {
                        if (Marshal.GetLastWin32Error() == 0)
                        {
                            throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_TIMEOUT, "SendMessage timed-out.  Tried 10 times.");
                        }
                        throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_SENDMSG, "Error sending message to FSUIPC.");
                    }
                    connection.pView.ToInt32();
                    int num9 = 0;
                    foreach (IOffset offset in offsetList2)
                    {
                        if (!offset.Write && !offset.WriteOnly)
                        {
                            byte[] numArray = new byte[offset.DataLength];
                            Marshal.Copy(new IntPtr(offset.FileAddress), numArray, 0, numArray.Length);
                            switch (offset.DataType)
                            {
                            case fsuipcDataType.TypeByte:
                                offset.Value = (object)numArray[0];
                                break;

                            case fsuipcDataType.TypeInt16:
                                offset.Value = (object)BitConverter.ToInt16(numArray, 0);
                                break;

                            case fsuipcDataType.TypeInt32:
                                offset.Value = (object)BitConverter.ToInt32(numArray, 0);
                                break;

                            case fsuipcDataType.TypeInt64:
                                offset.Value = (object)BitConverter.ToInt64(numArray, 0);
                                break;

                            case fsuipcDataType.TypeDouble:
                                offset.Value = (object)BitConverter.ToDouble(numArray, 0);
                                break;

                            case fsuipcDataType.TypeFloat:
                                offset.Value = (object)BitConverter.ToSingle(numArray, 0);
                                break;

                            case fsuipcDataType.TypeByteArray:
                                offset.Value    = (object)numArray;
                                offset.OldValue = (object)numArray;
                                break;

                            case fsuipcDataType.TypeUInt16:
                                offset.Value = (object)BitConverter.ToUInt16(numArray, 0);
                                break;

                            case fsuipcDataType.TypeUInt32:
                                offset.Value = (object)BitConverter.ToUInt32(numArray, 0);
                                break;

                            case fsuipcDataType.TypeUInt64:
                                offset.Value = (object)BitConverter.ToUInt64(numArray, 0);
                                break;

                            case fsuipcDataType.TypeString:
                                string str    = Encoding.ASCII.GetString(numArray);
                                int    length = str.IndexOf(char.MinValue);
                                offset.Value = length <= 0 ? (length != -1 ? (object)"" : (object)str) : (object)str.Substring(0, length);
                                break;

                            case fsuipcDataType.TypeBitArray:
                                offset.Value    = (object)new BitArray(numArray);
                                offset.OldValue = (object)new BitArray(numArray);
                                break;

                            case fsuipcDataType.TypeSByte:
                                offset.Value = (object)(sbyte)numArray[0];
                                break;
                            }
                        }
                        offset.Write = false;
                        ++num9;
                    }
                    foreach (IOffset Offset in offsetList1)
                    {
                        Offset.OnceOnly = false;
                        FSUIPCConnection.RemoveOffset(Offset);
                    }
                }
                else
                {
                    if ((int)ClassInstance == 0)
                    {
                        throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_NOTOPEN, "The connection to FSUIPC is not open.");
                    }
                    throw new FSUIPCException(FSUIPCError.FSUIPC_ERR_NOTOPEN, "The connection to class instance " + ClassInstance.ToString("D2") + " of WideClient.exe is not open.");
                }
            }
        }