Skip to content

Some beginner questions about patching #54

Description

@ATLaptic

            Console.WriteLine("Type new player health:");
            string health = Console.ReadLine();
Patcher p = new Patcher("C:/Program Files (x86)/Steam/steamapps/common/Game/Game_Data/Managed/Assembly-CSharp.dll");
            Instruction HealthCode = Instruction.Create(OpCodes.Ldstr, "InputDataManager.inst.players[this.playerIndex].health = " + health + ";");
            Instruction HealthFind = Instruction.Create(OpCodes.Ldstr, "InputDataManager.inst.players[this.playerIndex].player.trail.UpdateTail(InputDataManager.inst.players[this.playerIndex].health, this.rb.position);");
            Target target = new Target()
            {
                Namespace = "",
                Class = "Player",
                Method = "Spawn",
                Instruction = HealthCode
            };
            target.Index = p.FindInstruction(target, HealthFind)+4;
            p.Patch(target);
           p.Save("C:/Program Files (x86)/Steam/steamapps/common/Game/Game_Data/Managed/Assembly-CSharp.dll")

For some reason when I try to save the patch it gives me this error at the last line
System.IO.IOException: 'The requested operation cannot be performed on a file with a user-mapped section open. :
I've checked process explorer and nothing else has the dll open. Is p.Save only used for saving a new version of the assembly and not for saving changes to the current one or something?

Also does setting an index after the last line of a method just makes the the instructions afterward?

 Instruction[] SpeedCodes = {
                Instruction.Create(OpCodes.Ldstr, "this.idleSpeed = 20f * " + speed +";"),
                Instruction.Create(OpCodes.Ldstr, "this.boostSpeed = 85f * " + speed +";"),
                Instruction.Create(OpCodes.Ldstr, "Vector3 temp = base.transform.localScale;"),
                Instruction.Create(OpCodes.Ldstr, "temp = new Vector3(" + xscale + "f, " + yscale + "f, 1f);"),
                Instruction.Create(OpCodes.Ldstr, "this.render.gameObject.transform.localScale = temp;"),
                 Instruction.Create(OpCodes.Ldstr, "this.rb.gameObject.transform.localScale = temp;")
            };
//the last instruction of the method
            Instruction SpawnFind = Instruction.Create(OpCodes.Ldstr, "this.Spawn();"); 
            int[] indexes =
            {
                p.FindInstruction(target, SpawnFind )+1,
               p.FindInstruction(target, SpawnFind )+2,
                p.FindInstruction(target, SpawnFind )+3,
               p.FindInstruction(target, SpawnFind )+4,
               p.FindInstruction(target, SpawnFind )+5,
               p.FindInstruction(target, SpawnFind )+6,
            };
            Target target2 = new Target()
            {
                Namespace = "",
                Class = "Player",
                Method = "Start",
                Instructions = SpeedCodes,
                Indices = indexes
            };

Thanks for any help you can give!
edit: after awhile I realized it's probably the path to the dll but I don't know what's wrong

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions