Esempio n. 1
0
        private static byte[] CapBlastUnit(byte[] input)
        {
            switch (input.Length)
            {
            case 1:
                if (CorruptCore_Extensions.GetDecimalValue(input, false) > byte.MaxValue)
                {
                    return(getByteArray(1, 0xFF));
                }

                break;

            case 2:
                if (CorruptCore_Extensions.GetDecimalValue(input, false) > ushort.MaxValue)
                {
                    return(getByteArray(2, 0xFF));
                }

                break;

            case 4:
                if (CorruptCore_Extensions.GetDecimalValue(input, false) > uint.MaxValue)
                {
                    return(getByteArray(2, 0xFF));
                }

                break;
            }
            return(input);
        }
Esempio n. 2
0
        public static bool LoadState_NET(StashKey sk, bool applyBlastLayer = true)
        {
            if (sk == null)
            {
                return(false);
            }

            bool useStates = (AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES] as bool? ?? false);

            if (useStates)
            {
                StashKey.SetCore(sk);
                string gameSystem = sk.SystemName;
                string gameName   = CorruptCore_Extensions.MakeSafeFilename(sk.GameName, '-');
                string key        = sk.ParentKey;
                StashKeySavestateLocation stateLocation = sk.StateLocation;

                string theoreticalSaveStateFilename = Path.Combine(RtcCore.workingDir, stateLocation.ToString(), gameName + "." + key + ".timejump.State");

                if (File.Exists(theoreticalSaveStateFilename))
                {
                    if (!LocalNetCoreRouter.QueryRoute <bool>(NetcoreCommands.VANGUARD, NetcoreCommands.LOADSAVESTATE, new object[] { theoreticalSaveStateFilename, stateLocation }, true))
                    {
                        MessageBox.Show($"Error loading savestate : An internal error has occurred.\n Are you sure your savestate matches the game, your syncsettings match, and the savestate is supported by this version of {RtcCore.VanguardImplementationName}?");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show($"Error loading savestate : (File {theoreticalSaveStateFilename} not found)");
                    return(false);
                }
            }

            if (applyBlastLayer && sk?.BlastLayer?.Layer?.Count > 0)
            {
                CorruptBL = sk.BlastLayer;
                sk.BlastLayer.Apply(true);
            }
            return(true);
        }
Esempio n. 3
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);
            }
        }