private void RandomizeAllObjects(World world) { world.ReadObjectNames(); Dictionary <string, Pointer <SuperObject> > superObjects = world.GetActiveSuperObjects(); foreach (SuperObject *superObject in superObjects.Values) { Perso *perso = (Perso *)superObject->engineObjectPtr; int aiModelID = perso->stdGamePtr->modelID; string aiModelName = world.ObjectNames[ObjectSet.Model][aiModelID]; if (aiModelName == "DS1_GEN_PTC_GenCKS" || aiModelName == "DS1_GEN_PTC_GenBigFile") { perso->brain = null; continue; } RandomizeObject(superObject); } SuperObject *global = superObjects["global"]; DsgMem * dsgMem = ((Perso *)global->engineObjectPtr)->brain->mind->dsgMem; DsgVar * dsgVars = *dsgMem->dsgVar; DsgVarInfo info = dsgVars->dsgVarInfos[63]; bool *bool63 = (bool *)((int)dsgMem->memoryBufferCurrent + info.offsetInBuffer); *bool63 = false; }
public Dictionary <string, Pointer <SuperObject> > GetActiveSuperObjects() { const int offDynamWorld = 0x0500FD0; Dictionary <string, Pointer <SuperObject> > result = new Dictionary <string, Pointer <SuperObject> >(); SuperObject *superObject = (SuperObject *)Memory.GetPointerAtOffset(offDynamWorld, 0x8, 0x0); while (superObject != null) { Perso *perso = (Perso *)superObject->engineObjectPtr; if (perso != null) { StandardGame *offStdGame = perso->stdGamePtr; int nameIndex = offStdGame->instanceID; string name = $"unknown_{(int)superObject:X}"; if (nameIndex >= 0 && nameIndex < ObjectNames[ObjectSet.Instance].Length) { name = ObjectNames[ObjectSet.Instance][nameIndex]; } if (!result.ContainsKey(name)) { result.Add(name, superObject); } } superObject = superObject->nextBrother; } return(result); }
public Dictionary <string, Pointer <Perso> > GetAlwaysObjects() { int *off_NumAlways = (int *)0x004A6B18; Dictionary <string, Pointer <Perso> > result = new Dictionary <string, Pointer <Perso> >(); int numAlways = *off_NumAlways; ListItem *currentItem = ((ListItem *)(off_NumAlways + 1))->next; // skip the first item, since it's a header while (currentItem != null) { Perso *perso = currentItem->data; result.Add(ObjectNames[ObjectSet.Instance][perso->stdGamePtr->instanceID], perso); currentItem = currentItem->next; } return(result); }
public int GenerateAlwaysObject(SuperObject *spawnedBy, Perso *alwaysPerso, Vector3 position) { if (spawnedBy == null) { throw new NullReferenceException("GenerateAlwaysObject: spawnedBy is not allowed to be null!"); } int[] interp = { 0x00000042, // Func_GenerateObj 0x03020000, (int)alwaysPerso, // arg0, Perso to generate 0x17030000, // arg1, Vector3 0x00000000, 0x10030000, BitConverter.ToInt32(BitConverter.GetBytes(position.X), 0), // x 0x0D040000, BitConverter.ToInt32(BitConverter.GetBytes(position.Y), 0), // y 0x0D040000, BitConverter.ToInt32(BitConverter.GetBytes(position.Z), 0), // z 0x0D040000, }; // TODO: use ArrayPtr() IntPtr interpArray = Marshal.AllocHGlobal(interp.Length * 4); for (int i = 0; i < interp.Length; i++) { Marshal.WriteInt32(interpArray, i * 4, interp[i]); } IntPtr paramArray = Marshal.AllocHGlobal(0x20 * 4); IntPtr interpPtrStart = interpArray + 0x8; // we start at the second node of the interpreter tree EngineFunctions.MiscFunction.Call((int)spawnedBy, (int)interpPtrStart, (int)paramArray); return(*(int *)paramArray.ToPointer()); }
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); } }; }
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; } } }