Exemplo n.º 1
0
        //As the param is a long, it's little endian. We have to account for this whenever the param is going to be used as a value for a byte array
        //If it's an address, we can leave it as is.
        //If it's something such as SET or Replace X with Y, we always flip as we need to go to big endian
        //If it's something like a bitwise operation, we read the values from left to right when pulling them from memory. As such, we also always convert to big endian
        private static BlastUnit GenerateUnit(string domain, long address, long param1, long param2, int precision, int lifetime, int executeFrame, bool loop,
                                              BGValueModes mode, string note, Random rand)
        {
            try
            {
                MemoryInterface mi = null;
                if (domain.Contains("[V]"))
                {
                    if (!MemoryDomains.VmdPool.ContainsKey(domain))
                    {
                        return(null);
                    }
                    mi = MemoryDomains.VmdPool[domain];
                }
                else
                {
                    if (!MemoryDomains.MemoryInterfaces.ContainsKey(domain))
                    {
                        return(null);
                    }
                    mi = MemoryDomains.MemoryInterfaces[domain];
                }

                byte[]     value     = new byte[precision];
                byte[]     _temp     = new byte[precision];
                BigInteger tiltValue = 0;

                if (param1Bytes == null)
                {
                    param1Bytes = CorruptCore_Extensions.GetByteArrayValue(precision, param1, true);
                }
                if (param2Bytes == null)
                {
                    param2Bytes = CorruptCore_Extensions.GetByteArrayValue(precision, param2, true);
                }

                //Use >= as Size is 1 indexed whereas address is 0 indexed
                if (address + value.Length > mi.Size)
                {
                    return(null);
                }

                switch (mode)
                {
                case BGValueModes.ADD:
                    tiltValue = new BigInteger(param1Bytes);
                    break;

                case BGValueModes.SUBTRACT:
                    tiltValue = new BigInteger(param1Bytes) * -1;
                    break;

                case BGValueModes.RANDOM:
                    for (int i = 0; i < value.Length; i++)
                    {
                        value[i] = (byte)rand.Next(0, 255);
                    }
                    break;

                case BGValueModes.RANDOM_RANGE:
                    long temp = rand.NextLong(param1, param2);
                    value = CorruptCore_Extensions.GetByteArrayValue(precision, temp, true);
                    break;

                case BGValueModes.REPLACE_X_WITH_Y:
                    if (mi.PeekBytes(address, address + precision, mi.BigEndian)
                        .SequenceEqual(param1Bytes))
                    {
                        value = param2Bytes;
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case BGValueModes.SET:
                    value = CorruptCore_Extensions.GetByteArrayValue(precision, param1, true);
                    break;

                case BGValueModes.SHIFT_RIGHT:
                    value    = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    address += param1;
                    if (address >= mi.Size)
                    {
                        return(null);
                    }
                    break;

                case BGValueModes.SHIFT_LEFT:
                    value    = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    address -= param1;
                    if (address < 0)
                    {
                        return(null);
                    }
                    break;


                //Bitwise operations
                case BGValueModes.BITWISE_AND:
                    _temp = param1Bytes;
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < value.Length; i++)
                    {
                        value[i] = (byte)(value[i] & _temp[i]);
                    }
                    break;

                case BGValueModes.BITWISE_COMPLEMENT:
                    _temp = param1Bytes;
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < value.Length; i++)
                    {
                        value[i] = (byte)(value[i] & _temp[i]);
                    }
                    break;

                case BGValueModes.BITWISE_OR:
                    _temp = param1Bytes;
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < value.Length; i++)
                    {
                        value[i] = (byte)(value[i] | _temp[i]);
                    }
                    break;

                case BGValueModes.BITWISE_XOR:
                    _temp = param1Bytes;
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < value.Length; i++)
                    {
                        value[i] = (byte)(value[i] ^ _temp[i]);
                    }
                    break;

                case BGValueModes.BITWISE_SHIFT_LEFT:
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < param1; i++)
                    {
                        CorruptCore_Extensions.ShiftLeft(value);
                    }
                    break;

                case BGValueModes.BITWISE_SHIFT_RIGHT:
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < param1; i++)
                    {
                        CorruptCore_Extensions.ShiftRight(value);
                    }
                    break;

                case BGValueModes.BITWISE_ROTATE_LEFT:
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < param1; i++)
                    {
                        CorruptCore_Extensions.RotateLeft(value);
                    }
                    break;

                case BGValueModes.BITWISE_ROTATE_RIGHT:
                    value = mi.PeekBytes(address, address + precision, mi.BigEndian);
                    for (int i = 0; i < param1; i++)
                    {
                        CorruptCore_Extensions.RotateRight(value);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
                }

                var bu = new BlastUnit(value, domain, address, precision, mi.BigEndian, executeFrame, lifetime, note)
                {
                    TiltValue = tiltValue,
                    Loop      = loop
                };

                return(bu);
            }
            catch (Exception ex)
            {
                throw new NetCore.CustomException("Something went wrong in the RTC ValueGenerator Generator. " + ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 2
0
 public static byte[] read32bits(MemoryInterface mi, long address)
 {
     return(mi.PeekBytes(address, 4));
 }
Exemplo n.º 3
0
        public void GetSavestateInfo()
        {
            MemoryInterface mi = WGH_Core.currentMemoryInterface;

            if (mi != null && mi.dolphinSavestateVersion())
            {
                byte[] bytes;
                byte[] sram_pattern  = { 0x5B, 0x43, 0x6F, 0x72, 0x65, 0x54, 0x69, 0x6D, 0x69, 0x6E, 0x67, 0x5D };
                byte[] aram_pattern  = { 0x5B, 0x50, 0x72, 0x6F, 0x63, 0x65, 0x73, 0x73, 0x6F, 0x72, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x40, 0x5D };
                byte[] exram_pattern = { 0x5B, 0x4D, 0x65, 0x6D, 0x6F, 0x72, 0x79, 0x20, 0x46, 0x61, 0x6B, 0x65, 0x56, 0x4D, 0x45, 0x4D, 0x40, 0x40, 0x40, 0x5D };
                int    sram_offset   = 0;
                int    aram_offset   = 0;
                int    exram_offset  = 0;

                //getMemorySize() returns a long whereas peekbytes uses an int. Dolphin savestates should never be 2GB large so this shouldn't be a problem
                bytes = mi.PeekBytes(0, Convert.ToInt32(mi.getMemorySize()));

                int offset = 0;

                //Search for the sram
                for (int i = 0; i < bytes.Length - sram_pattern.Length; i++)
                {
                    bool found = true;
                    for (offset = 0; offset < sram_pattern.Length; offset++)
                    {
                        if (bytes[i + offset] != sram_pattern[offset])
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found)
                    {
                        sram_offset = i + offset;
                        break;
                    }
                }


                //Search for the aram
                for (int i = 0; i < bytes.Length - aram_pattern.Length; i++)
                {
                    bool found = true;
                    for (offset = 0; offset < aram_pattern.Length; offset++)
                    {
                        if (bytes[i + offset] != aram_pattern[offset])
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found)
                    {
                        aram_offset = i + offset;
                        break;
                    }
                }


                //Search for the exram
                for (int i = 0; i < bytes.Length - exram_pattern.Length; i++)
                {
                    bool found = true;
                    for (offset = 0; offset < exram_pattern.Length; offset++)
                    {
                        if (bytes[i + offset] != exram_pattern[offset])
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found)
                    {
                        exram_offset = i + offset;
                        break;
                    }
                }

                sramOffset.Text    = sram_offset.ToString();
                sramAlignment.Text = (sram_offset % 4).ToString();

                //Sram is always 24MB so we can make this assumption
                //sram_size = SRAM_SIZE;

                //Check for the exram. If it doesn't exist, we have gamecube so it's aram
                if ((Encoding.Default.GetString(mi.PeekBytes(exram_offset + 4, 14)) == "[Memory EXRAM]"))
                {
                    //aram_size = ARAM_SIZE;
                    aramexramLabel.Text     = "ARAM";
                    aramexramOffset.Text    = aram_offset.ToString();
                    aramexramAlignment.Text = (aram_offset % 4).ToString();
                }
                else
                {
                    //exram_size = EXRAM_SIZE;
                    aramexramLabel.Text     = "EXRAM";
                    aramexramOffset.Text    = exram_offset.ToString();
                    aramexramAlignment.Text = (exram_offset % 4).ToString();
                }
                //Set the vector engine alignment value. Just use the sram alignment
                WGH_Core.ghForm.vectorOffset.Value = (sram_offset % 4);
            }
            else
            {
            }
        }