Exemplo n.º 1
0
 public void WriteArray(Writer writer)
 {
     if (Settings.s.game == Settings.Game.R2Revolution)
     {
         Pointer.Goto(ref writer, Pointer.Current(writer) + 4);
         writer.Write((byte)arrayTypeNumber);
         writer.Write(arrayLength);
         writer.Write((byte)0);
         writer.Write((byte)0);
     }
     else
     {
         writer.Write(arrayTypeNumber);
         writer.Write(arrayLength);
         writer.Write((byte)0);
         writer.Write((byte)0);
         writer.Write((byte)0);
     }
     arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber);
     if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType)
     {
         Debug.LogWarning(currentbuf + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(writer));
     }
     if (valueArray != null && arrayLength == valueArray.Length)
     {
         for (uint i = 0; i < arrayLength; i++)
         {
             valueArray[i].Write(writer);
         }
     }
 }
Exemplo n.º 2
0
        public static DsgVarType GetDsgVarTypeFromArrayType(DsgVarType arrayType)
        {
            switch (arrayType)
            {
            case DsgVarType.ActionArray: return(DsgVarType.Action);

            case DsgVarType.FloatArray: return(DsgVarType.Float);

            case DsgVarType.IntegerArray: return(DsgVarType.Int);

            case DsgVarType.PersoArray: return(DsgVarType.Perso);

            case DsgVarType.SoundEventArray: return(DsgVarType.SoundEvent);

            case DsgVarType.SuperObjectArray: return(DsgVarType.SuperObject);

            case DsgVarType.TextArray: return(DsgVarType.Text);

            case DsgVarType.TextRefArray: return(DsgVarType.None);

            case DsgVarType.VectorArray: return(DsgVarType.Vector);

            case DsgVarType.WayPointArray: return(DsgVarType.Waypoint);
            }

            return(DsgVarType.None);
        }
Exemplo n.º 3
0
 public void ReadArray(Reader reader)
 {
     if (Settings.s.game == Settings.Game.R2Revolution)
     {
         reader.ReadUInt32();
         arrayTypeNumber = reader.ReadByte();
         arrayLength     = reader.ReadByte();
         reader.ReadBytes(2);                 // padding
     }
     else
     {
         arrayTypeNumber = reader.ReadUInt32();
         arrayLength     = reader.ReadByte();
         reader.ReadBytes(3);                 // padding
     }
     arrayType = Settings.s.aiTypes.GetDsgVarType(arrayTypeNumber);
     if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != arrayType)
     {
         Debug.LogWarning(currentbuf + " - " + type + " - " + arrayTypeNumber + " - " + arrayType + " - " + arrayLength + " - " + Pointer.Current(reader));
     }
     if (valueArray == null || arrayLength != valueArray.Length)
     {
         valueArray = new DsgVarValue[arrayLength];
         for (int i = 0; i < arrayLength; i++)
         {
             valueArray[i] = new DsgVarValue(arrayType, dsgMem);
         }
     }
     for (uint i = 0; i < arrayLength; i++)
     {
         valueArray[i].Read(reader);
     }
 }
Exemplo n.º 4
0
 // Create an empty array
 public Value(DsgVarType type, int length)
 {
     this.type = type;
     AsArray   = new Value[length];
     for (int i = 0; i < AsArray.Length; i++)
     {
         AsArray[i] = null;
     }
 }
Exemplo n.º 5
0
 public DsgVarListItem(int id, DsgVarType type, void *value, void *initValue, void *modelValue)
 {
     Id         = id;
     Type       = type;
     Value      = value;
     InitValue  = initValue;
     ModelValue = modelValue;
     ListItem   = null;
 }
Exemplo n.º 6
0
            public void InitValue(OpenSpace.ROM.DsgVarValue value)
            {
                this.type = value.dsgVarType;

                if (DsgVarInfoEntry.GetDsgVarTypeFromArrayType(type) != DsgVarType.None)
                {
                    AsArray = new Value[value.ValueArrayLength];
                    for (int i = 0; i < AsArray.Length; i++)
                    {
                        AsArray[i] = null;
                    }
                }
            }
Exemplo n.º 7
0
            public void InitValue(DsgVarValue value)
            {
                this.type = value.type;

                if (value.valueArray != null)
                {
                    AsArray = new Value[value.arrayLength];
                    for (int i = 0; i < AsArray.Length; i++)
                    {
                        AsArray[i] = new Value(value.valueArray[i]);
                    }
                }
            }
Exemplo n.º 8
0
        private static string GetDsgVarString(DsgVarType type, void *value)
        {
            if (value == null)
            {
                return("---");
            }

            switch (type)
            {
            case DsgVarType.Byte:
                return($"{*(sbyte*)value}");

            case DsgVarType.UByte:
                return($"{*(byte*)value}");

            case DsgVarType.Short:
                return($"{*(short*)value}");

            case DsgVarType.UShort:
                return($"{*(ushort*)value}");

            case DsgVarType.Int:
                return($"{*(int*)value}");

            case DsgVarType.UInt:
                return($"{*(uint*)value}");

            case DsgVarType.Float:
                return($"{*(float*)value}");

            case DsgVarType.Boolean:
                return($"{*(bool*)value}");

            case DsgVarType.Vector:
                Vector3 *vector = (Vector3 *)value;
                return($"({vector->x}, {vector->y}, {vector->z})");

            case DsgVarType.Text:
            // TODO

            case DsgVarType.SuperObject:
            case DsgVarType.Perso:
            // TODO

            default:
                return($"0x{*(int*)value:X}");
            }
        }
Exemplo n.º 9
0
        private static IconId GetDsgVarIcon(DsgVarType type)
        {
            switch (type)
            {
            case DsgVarType.Byte:
            case DsgVarType.UByte:
                return(IconId.Byte);

            case DsgVarType.Short:
            case DsgVarType.UShort:
                return(IconId.Short);

            case DsgVarType.Int:
            case DsgVarType.UInt:
                return(IconId.Int);

            case DsgVarType.Float:
                return(IconId.Float);

            case DsgVarType.Boolean:
                return(IconId.Boolean);

            case DsgVarType.Vector:
                return(IconId.Vector);

            case DsgVarType.Text:
                return(IconId.Text);

            case DsgVarType.SuperObject:
            case DsgVarType.Perso:
                return(IconId.Pointer);

            default:
                return(IconId.Empty);
            }
        }
Exemplo n.º 10
0
 public DsgVar(DsgVarType type, object modelValue)
 {
     this.Type       = type;
     this.ModelValue = modelValue;
 }
Exemplo n.º 11
0
 public DsgVarValue(DsgVarType type, DsgMem dsgMem)
 {
     this.type   = type;
     this.dsgMem = dsgMem;
 }
Exemplo n.º 12
0
        public static string GetCSharpStringFromType(DsgVarType type)
        {
            string typeText = "";

            switch (type)
            {
            case DsgVarType.None:
                break;

            case DsgVarType.Boolean:
                typeText = "DsgVarBool"; break;

            case DsgVarType.Byte:
                typeText = "DsgVarByte"; break;

            case DsgVarType.UByte:
                typeText = "DsgVarUByte"; break;

            case DsgVarType.Short:
                typeText = "DsgVarShort"; break;

            case DsgVarType.UShort:
                typeText = "DsgVarUShort"; break;

            case DsgVarType.Int:
                typeText = "DsgVarInt"; break;

            case DsgVarType.UInt:
                typeText = "DsgVarUInt"; break;

            case DsgVarType.Float:
                typeText = "DsgVarFloat"; break;

            case DsgVarType.Vector:
                typeText = "Vector3"; break;

            case DsgVarType.List:
                typeText = "DsgVarList"; break;

            case DsgVarType.Comport:
                typeText = "Comport"; break;

            case DsgVarType.Action:
                typeText = "Action"; break;

            case DsgVarType.Caps:
                typeText = "Caps"; break;

            case DsgVarType.Input:
                typeText = "Input"; break;

            case DsgVarType.SoundEvent:
                typeText = "SoundEvent"; break;

            case DsgVarType.Light:
                typeText = "Light"; break;

            case DsgVarType.GameMaterial:
                typeText = "GameMaterial"; break;

            case DsgVarType.VisualMaterial:
                typeText = "VisualMaterial"; break;

            case DsgVarType.Perso:
                typeText = "Perso"; break;

            case DsgVarType.WayPoint:
                typeText = "WayPoint"; break;

            case DsgVarType.Graph:
                typeText = "Graph"; break;

            case DsgVarType.Text:
                typeText = "DsgVarString"; break;

            case DsgVarType.SuperObject:
                typeText = "SuperObject"; break;

            case DsgVarType.SOLinks:
                typeText = "SOLinks"; break;

            case DsgVarType.PersoArray:
                typeText = "List<Perso>"; break;

            case DsgVarType.VectorArray:
                typeText = "List<Vector3>"; break;

            case DsgVarType.FloatArray:
                typeText = "List<DsgVarFloat>"; break;

            case DsgVarType.IntegerArray:
                typeText = "List<DsgVarInt>"; break;

            case DsgVarType.WayPointArray:
                typeText = "List<WayPoint>"; break;

            case DsgVarType.TextArray:     // These are text references
                typeText = "List<DsgVarTextRef>"; break;

            case DsgVarType.TextRefArray:     // Don't know what these are then?
                typeText = "List<DsgVarTextRef2>"; break;

            case DsgVarType.GraphArray:
                typeText = "List<Graph>"; break;

            case DsgVarType.SOLinksArray:
                typeText = "List<SOLinks>"; break;

            case DsgVarType.SoundEventArray:
                typeText = "List<DsgVarSoundEvent>"; break;

            case DsgVarType.VisualMatArray:
                typeText = "List<VisualMaterial>"; break;

            case DsgVarType.Way:
                typeText = "Way"; break;

            case DsgVarType.ActionArray:
                typeText = "List<Action>"; break;

            case DsgVarType.SuperObjectArray:
                typeText = "List<SuperObject>"; break;
            }
            return(typeText);
        }
Exemplo n.º 13
0
        public void Run(RemoteInterface remoteInterface)
        {
            Interface             = remoteInterface;
            GlobalActions.Engine += CountFrames;
            random = new Random();

            World world             = new World(remoteInterface);
            List <TextOverlay> vars = new List <TextOverlay>();

            GlobalInput.Actions['g'] = () =>
            {
                foreach (TextOverlay overlay in vars)
                {
                    overlay.Hide();
                }
                vars = new List <TextOverlay>();

                vars.Add(new TextOverlay("Rayman Dsgvars=".Red(), 6, 5, 0).Show());

                world.ReadObjectNames();
                Dictionary <string, Pointer <SuperObject> > superObjects = world.GetActiveSuperObjects();

                Interface.Log("SUPEROBJECT NAMES:", LogType.Debug);
                foreach (KeyValuePair <string, Pointer <SuperObject> > o in superObjects)
                {
                    Interface.Log($"{o.Key} {o.Value}", LogType.Debug);
                }

                SuperObject *rayman = superObjects["Rayman"];
                Perso *      perso  = (Perso *)rayman->engineObjectPtr;

                DsgVar *dsgVars = *perso->brain->mind->dsgMem->dsgVar;

                Interface.Log("DSGVARS:", LogType.Debug);
                for (int i = 0; i < dsgVars->dsgVarInfosLength; i++)
                {
                    DsgVarInfo info = dsgVars->dsgVarInfos[i];
                    DsgVarType type = info.type;

                    Pointer <byte> buffer = perso->brain->mind->dsgMem->memoryBufferCurrent;
                    int            offset = info.offsetInBuffer;

                    string        name  = $"{Enum.GetName(typeof(DsgVarType), type)}!{i}";
                    Func <object> value = buffer.GetDisplayReference(type, offset);

                    if (value != null)
                    {
                        vars.Add(new TextOverlay(_ => $"{name.Yellow()}\\{value()}", 5, ((vars.Count + 1) * 5 * 2.6f + 5) < 1000 ? 5 : 505, (vars.Count * 5 * 2.6f + 5) % 980).Show());
                    }
                }
            };

            GlobalInput.Actions['r'] = () =>
            {
                RandomizeAllObjects(world);
            };

            RandomizeMode mode = new RandomizeModeInterval(randomizeInterval);

            GlobalActions.Engine += () =>
            {
                if (mode.ShouldRandomize())
                {
                    RandomizeAllObjects(world);
                }
            };
        }
Exemplo n.º 14
0
        internal static Func <object> GetDisplayReference(this Pointer <byte> buffer, DsgVarType type, int offset)
        {
            int value = buffer + offset;

            switch (type)
            {
            case DsgVarType.Boolean:
                return(() => *(bool *)value);

            case DsgVarType.Byte:
                return(() => *(sbyte *)value);

            case DsgVarType.UByte:
                return(() => *(byte *)value);

            case DsgVarType.Short:
                return(() => *(short *)value);

            case DsgVarType.UShort:
                return(() => *(ushort *)value);

            case DsgVarType.Int:
                return(() => *(int *)value);

            case DsgVarType.UInt:
                return(() => *(uint *)value);

            case DsgVarType.Float:
                return(() => *(float *)value);

            case DsgVarType.WayPoint:
                break;

            case DsgVarType.Perso:
                break;

            case DsgVarType.List:
                break;

            case DsgVarType.Vector:
                return(() => *(Vector3 *)value);

            case DsgVarType.Comport:
                break;

            case DsgVarType.Action:
                break;

            case DsgVarType.Text:
                break;

            case DsgVarType.GameMaterial:
                break;

            case DsgVarType.Caps:
                break;

            case DsgVarType.Graph:
                break;

            case DsgVarType.PersoArray:
                break;

            case DsgVarType.VectorArray:
                break;

            case DsgVarType.FloatArray:
                break;

            case DsgVarType.IntegerArray:
                break;

            case DsgVarType.WayPointArray:
                break;

            case DsgVarType.TextArray:
                break;

            case DsgVarType.SuperObject:
                break;
            }

            return(null);
        }
Exemplo n.º 15
0
        private void RandomizeObject(SuperObject *superObject)
        {
            Perso *perso = (Perso *)superObject->engineObjectPtr;

            Brain *brain = perso->brain;

            if (brain == null)
            {
                return;
            }

            DsgMem *dsgMem = brain->mind->dsgMem;

            if (dsgMem == null)
            {
                return;
            }

            DsgVar *dsgVars = *dsgMem->dsgVar;

            for (int i = 0; i < dsgVars->dsgVarInfosLength; i++)
            {
                if (random.NextDouble() > randomizeChance)
                {
                    continue;
                }

                DsgVarInfo info = dsgVars->dsgVarInfos[i];
                DsgVarType type = info.type;

                byte *buffer = dsgMem->memoryBufferCurrent;
                int   ptr    = (int)buffer + info.offsetInBuffer;

                switch (type)
                {
                case DsgVarType.Boolean:
                    *(bool *)ptr = random.Next(0, 2) == 0;
                    break;

                case DsgVarType.Byte:
                    *(sbyte *)ptr = (sbyte)random.Next(-127, 128);
                    break;

                case DsgVarType.UByte:
                    *(byte *)ptr = (byte)random.Next(0, 256);
                    break;

                case DsgVarType.Short:
                    *(short *)ptr = (short)random.Next();
                    break;

                case DsgVarType.UShort:
                    *(ushort *)ptr = (ushort)random.Next();
                    break;

                case DsgVarType.Int:
                    *(int *)ptr = random.Next();
                    break;

                case DsgVarType.UInt:
                    *(uint *)ptr = (uint)random.Next();
                    break;

                case DsgVarType.Float:
                    *(float *)ptr += random.RandomFloat(-10f, 10f);
                    break;

                case DsgVarType.Vector:
                    Vector3 *vector = (Vector3 *)ptr;
                    vector->X += random.RandomFloat(-10f, 10f);
                    vector->Y += random.RandomFloat(-10f, 10f);
                    vector->Z += random.RandomFloat(-10f, 10f);
                    break;

                case DsgVarType.IntegerArray:
                    int *array = brain->mind->GetDsgVar <int>(i, buffer, out byte size);
                    for (int j = 0; j < size; j++)
                    {
                        array[j] = random.Next();
                    }
                    break;
                }
            }
        }