Ejemplo n.º 1
0
        public override void Apply(UberStrike uberStrike)
        {
            var types = uberStrike.AssemblyCSharpFirstpass.GetTypes();

            foreach (var type in types)
            {
                if (!type.Name.EndsWith("WebServiceClient"))
                {
                    continue;
                }

                foreach (var method in type.Methods)
                {
                    foreach (var il in method.Body.Instructions)
                    {
                        if (il.OpCode == OpCodes.Ldstr)
                        {
                            var str = (string)il.Operand;
                            if (str.StartsWith("UberStrike.DataCenter.WebService.CWS.") && str.EndsWith("Contract.svc"))
                            {
                                str        = str.Replace("UberStrike.DataCenter.WebService.CWS.", string.Empty).Replace("Contract.svc", string.Empty);
                                il.Operand = str;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void Apply(UberStrike uberStrike)
        {
            var GameState_Type = uberStrike.AssemblyCSharp.Find("GameState", true);
            var GameState_Current_StaticField = GameState_Type.GetField("Current");
            var GaneState_RoomData_Property   = GameState_Type.FindProperty("RoomData");

            var WeaponController_Type         = uberStrike.AssemblyCSharp.Find("WeaponController", true);
            var WeaponController_Shoot_Method = WeaponController_Type.FindMethod("Shoot");
            var ilBody = WeaponController_Shoot_Method.Body;

            if (ilBody.Instructions.Count != 75)
            {
                throw new Exception("I think it has been patched or altered.");
            }

            /* Loads GameFlags.QuickSwitch onto the stack. */
            ilBody.Instructions.Insert(13, OpCodes.Ldc_I4_4.ToInstruction());
            /* Loads GameState.Current onto the stack. */
            ilBody.Instructions.Insert(14, OpCodes.Ldsfld.ToInstruction(GameState_Current_StaticField));

            var GameRoomData_TypeRef = new TypeRefUser(uberStrike.AssemblyCSharp, "UberStrike.Core.Models", "GameRoomData", uberStrike.AssemblyCSharpFirstpass.Assembly.ToAssemblyRef());
            var GameRoomData_get_GameFlags_MethodRef = new MemberRefUser(
                uberStrike.AssemblyCSharp,
                "get_GameFlags",
                MethodSig.CreateInstance(uberStrike.AssemblyCSharpFirstpass.CorLibTypes.Int32),
                GameRoomData_TypeRef
                );

            /* Calls GameState.Current.get_RoomData().get_GameFlags() */
            ilBody.Instructions.Insert(15, OpCodes.Callvirt.ToInstruction(GaneState_RoomData_Property.GetMethod));
            ilBody.Instructions.Insert(16, OpCodes.Callvirt.ToInstruction(GameRoomData_get_GameFlags_MethodRef));

            var GameFlags_TypeRef  = new TypeRefUser(uberStrike.AssemblyCSharp, "UberStrike.Realtime.UnitySdk", "GameFlags", uberStrike.AssemblyCSharpFirstpass.Assembly.ToAssemblyRef());
            var GAME_FLAGS_TypeRef = new TypeRefUser(uberStrike.AssemblyCSharp, string.Empty, "GAME_FLAGS", GameFlags_TypeRef);

            var GameFlags_IsFlagSet_MethodRef = new MemberRefUser(
                uberStrike.AssemblyCSharpFirstpass,
                "IsFlagSet",
                MethodSig.CreateStatic(
                    uberStrike.AssemblyCSharpFirstpass.CorLibTypes.Boolean,
                    GAME_FLAGS_TypeRef.ToTypeSig(),
                    uberStrike.AssemblyCSharpFirstpass.CorLibTypes.Int32
                    ),
                GameFlags_TypeRef
                );

            /* Calls GameFlags.IsFlagSet(,) */
            ilBody.Instructions.Insert(17, OpCodes.Call.ToInstruction(GameFlags_IsFlagSet_MethodRef));

            /* Branching out if GameFlags.IsFlagSet return true;. */
            ilBody.Instructions.Insert(18, OpCodes.Brtrue_S.ToInstruction(ilBody.Instructions[24]));
        }
Ejemplo n.º 3
0
        public override void Apply(UberStrike uberStrike)
        {
            var ApplicationDataManager_Type  = uberStrike.AssemblyCSharp.Find("ApplicationDataManager", true);
            var ApplicationDataManager_CCtor = ApplicationDataManager_Type.FindStaticConstructor();
            var ilBody = ApplicationDataManager_CCtor.Body;

            if (ilBody.Instructions.Count != 15)
            {
                throw new Exception("I think it has been patched or altered.");
            }

            var endOfPatch = ilBody.Instructions[4];

            /* UnityEngine.Application */
            var Application_TypeRef = new TypeRefUser(uberStrike.AssemblyCSharp, "UnityEngine", "Application", uberStrike.UnityEngine.Assembly.ToAssemblyRef());
            /* UnityEngine.Application.get_dataPath */
            var Application_get_dataPath = new MemberRefUser(
                uberStrike.AssemblyCSharp,
                "get_dataPath",
                MethodSig.CreateStatic(uberStrike.AssemblyCSharp.CorLibTypes.String),
                Application_TypeRef
                );

            /* Calls Application.dataPath */
            ilBody.Instructions.Insert(0, OpCodes.Call.ToInstruction(Application_get_dataPath));
            /* Loads ".uberstrok" onto the stack. */
            ilBody.Instructions.Insert(1, OpCodes.Ldstr.ToInstruction(".uberstrok"));

            /* System.IO.Path */
            var Path_TypeRef = new TypeRefUser(uberStrike.AssemblyCSharp, "System.IO", "Path", uberStrike.AssemblyCSharp.CorLibTypes.AssemblyRef);
            /* System.IO.Path.Combine(string, string) */
            var Path_Combine_MethodRef = new MemberRefUser(
                uberStrike.AssemblyCSharp,
                "Combine",
                MethodSig.CreateStatic(
                    uberStrike.AssemblyCSharp.CorLibTypes.String,
                    uberStrike.AssemblyCSharp.CorLibTypes.String,
                    uberStrike.AssemblyCSharp.CorLibTypes.String
                    ),
                Path_TypeRef
                );

            /* Calls Path.Combine(Application.dataPath, ".uberstrok") */
            ilBody.Instructions.Insert(2, OpCodes.Call.ToInstruction(Path_Combine_MethodRef));

            /* System.IO.File */
            var File_TypeRef = new TypeRefUser(uberStrike.AssemblyCSharp, "System.IO", "File", uberStrike.AssemblyCSharp.CorLibTypes.AssemblyRef);
            /* System.IO.Path.ReadAllText(string) */
            var File_ReadAllText_MethodRef = new MemberRefUser(
                uberStrike.AssemblyCSharp,
                "ReadAllText",
                MethodSig.CreateStatic(
                    uberStrike.AssemblyCSharp.CorLibTypes.String,
                    uberStrike.AssemblyCSharp.CorLibTypes.String
                    ),
                File_TypeRef
                );

            /* Calls File.ReadAllText(Path.Combine(Application.dataPath, ".uberstrok")) */
            ilBody.Instructions.Insert(3, OpCodes.Call.ToInstruction(File_ReadAllText_MethodRef));

            /* Duplicate the value on the stack again to set both the WebServiceBaseUrl & ImagePath */
            ilBody.Instructions.Insert(4, OpCodes.Dup.ToInstruction());

            var WebServiceBaseUrl_Field = ApplicationDataManager_Type.FindField("WebServiceBaseUrl");
            var ImagePath_Field         = ApplicationDataManager_Type.FindField("ImagePath");

            /*
             *  ApplicationDataManager.WebServiceBaseUrl = pop() stack
             *  ApplicationDataManager.ImagePath = pop() stack
             */
            ilBody.Instructions.Insert(5, OpCodes.Stsfld.ToInstruction(WebServiceBaseUrl_Field));
            ilBody.Instructions.Insert(6, OpCodes.Stsfld.ToInstruction(ImagePath_Field));

            /* Jump out of try-catch. */
            ilBody.Instructions.Insert(7, OpCodes.Leave_S.ToInstruction(endOfPatch));

            /* Clean stack. */
            ilBody.Instructions.Insert(8, OpCodes.Pop.ToInstruction());

            /* Loads "Failed to load '.uberstrok' host config." onto the stack. */
            ilBody.Instructions.Insert(9, OpCodes.Ldstr.ToInstruction("Failed to load '.uberstrok' host config."));

            /* ApplicationDataManager.LockApplication(string) */
            var ApplicationDataManager_LockApplication_Method = ApplicationDataManager_Type.FindMethod("LockApplication");

            ilBody.Instructions.Insert(10, OpCodes.Call.ToInstruction(ApplicationDataManager_LockApplication_Method));

            /* Jump out of try-catch. */
            ilBody.Instructions.Insert(11, OpCodes.Leave_S.ToInstruction(endOfPatch));

            /* Remove old instructions. */
            ilBody.Instructions.RemoveAt(12);
            ilBody.Instructions.RemoveAt(12);
            ilBody.Instructions.RemoveAt(12);
            ilBody.Instructions.RemoveAt(12);

            /* Register the exception handler. */
            ilBody.ExceptionHandlers.Add(new ExceptionHandler
            {
                CatchType    = uberStrike.AssemblyCSharp.CorLibTypes.Object.ToTypeDefOrRef(),
                HandlerType  = ExceptionHandlerType.Catch,
                HandlerStart = ilBody.Instructions[8],
                HandlerEnd   = endOfPatch,
                TryStart     = ilBody.Instructions[0],
                TryEnd       = ilBody.Instructions[8]
            });
        }
Ejemplo n.º 4
0
        public static int Main(string[] args)
        {
            const int UBERSTRIKE_STEAMAPP_ID = 291210;

            var sw = Stopwatch.StartNew();

            Console.WriteLine(" Searching for Steam installation...");

            var steamPath = default(string);

            try { steamPath = Steam.Path; }
            catch (DirectoryNotFoundException)
            {
                Console.Error.WriteLine(" Unable to find Steam installation.");
                return(1);
            }

            Console.WriteLine(" -----------------------------------");
            Console.WriteLine(" Path -> " + steamPath);
            Console.WriteLine(" Games ->");
            foreach (var keyValue in Steam.Apps)
            {
                var    app  = keyValue.Value;
                int    id   = app.Id;
                string name = app.Name;

                Console.WriteLine(id.ToString().PadLeft(" Games ->".Length) + " -> " + name);
            }
            Console.WriteLine(" -----------------------------------");
            Console.WriteLine(" Searching for UberStrike installation...");

            var uberStrikeApp = default(SteamApp);

            if (!Steam.Apps.TryGetValue(UBERSTRIKE_STEAMAPP_ID, out uberStrikeApp))
            {
                Console.Error.WriteLine(" Unable to find UberStrike manifest.");
                return(1);
            }

            var uberStrikePath = default(string);

            try { uberStrikePath = uberStrikeApp.Path; }
            catch
            {
                Console.Error.WriteLine(" Unable to parse UberStrike manifest.");
                return(1);
            }

            if (!Directory.Exists(uberStrikePath))
            {
                Console.Error.WriteLine(" Unable to find UberStrike installation directory.");
                return(1);
            }

            Console.WriteLine(" -----------------------------------");
            Console.WriteLine(" Path -> " + uberStrikePath);

            var uberStrike = new UberStrike(uberStrikePath);

            /*
             * Console.WriteLine(" Backups ->");
             *
             * var dlls = Directory.GetFiles(uberStrike.ManagedPath, "*.dll");
             * Directory.CreateDirectory(Path.Combine(uberStrike.ManagedPath, "backup"));
             * foreach (var dll in dlls)
             * {
             *  var fileName = Path.GetFileName(dll);
             *  var dst = Path.Combine(uberStrike.ManagedPath, "backup", fileName);
             *
             *  File.Copy(dll, dst, true);
             *
             *  Console.WriteLine(new string(' ', " Games ->".Length) + fileName + " -> " + "backup/" + fileName);
             * }
             *
             * Console.WriteLine(" -----------------------------------");
             */

            var patches = new Patch[]
            {
                new QuickSwitchPatch(),
                new WebServicesPatch(),
                new HostPatch()
            };

            Console.WriteLine(" Patches ->");
            foreach (var patch in patches)
            {
                var name = patch.GetType().Name;
                Console.Write(new string(' ', " Games ->".Length) + "applying " + name + " -> ");

                try
                {
                    patch.Apply(uberStrike);

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("done");
                    Console.ResetColor();
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("failed");
                    Console.ResetColor();
                }
            }

            Console.WriteLine(" Writing new assemblies...");
            try { uberStrike.Save("patched"); }
            catch { Console.Error.WriteLine("Failed to write."); }

            sw.Stop();

            Console.WriteLine(" -----------------------------------");
            Console.WriteLine($" Finished in {sw.Elapsed.TotalMilliseconds}ms");
            return(0);
        }