public void ApplyPatch() { PatcherDefaults.CompanionDllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.Explorables.dll"); var subject = new PatchRunner(""); subject.LoadAssembly(AssemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); Array.ForEach(Definitions, subject.ApplyPatch); subject.SaveAssembly(Path.Combine(TargetFolder, string.Format("{0}_{1}.dll", AssemblySrcName, PatchGroupName))); }
public void PageShowed() { if (patchRunner == null) { patchRunner = new PatchRunner(DetectionPage.Instance.Path); patchRunner.LoadData(); var updatesChecker = new UpdatesChecker(); updatesChecker.ShowDialog(); var thread = new Thread(() => { patchRunner.Patch(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); canGoNext = true; MainWindow.Instance.RevalidateButtons(); } }
public void ExceptionThrownOnInstructionCountMismatch() { var def = new PatchDefinition() { CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 0, TargetMethodInstructionCount = 666, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Nop), }, TargetMethodName = "System.Boolean Kerberos.Sots.Data.SQLite.SQLiteConnection::TryLogQuery(System.String)", } }, Description = "Disable SQL logging" }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); try { subject.ApplyPatch(def); Assert.Fail("Expected an exception"); } catch (Exception ex) { Assert.AreEqual(typeof (ApplicationException), ex.GetType()); } }
public void CanReplaceDesignInfoLoader() { var def = new PatchDefinition() { Name = "TestPatch_AddStartingDeployedShips", Version = 1, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 41, //0 POS needed for the param, TargetMethodInstructionCount = 442, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Nop), new CodeLine(OpCodes.Ldarg_1), //db new CodeLine(OpCodes.Ldarg_2), //playerId new CodeLine(OpCodes.Call, "Kerberos.Sots.Data.DesignInfo sotsos.managedcompanion.Sotsos_Helpers::GetGatesShipDesignForPlayer(Kerberos.Sots.Data.GameDatabase,System.Int32)"), new CodeLine(OpCodes.Stloc_0),//store in var 0 - designInfo new CodeLine(OpCodes.Nop) }, TargetMethodName = "System.Void Kerberos.Sots.Strategy.GameSession::AddStartingDeployedShips(Kerberos.Sots.Data.GameDatabase,System.Int32)", } }, Description = "debug gate ship issue" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + "tst1.dll"); //Empirical assert //TODO: write port for verifying }
public void CanAdjustAdmiralDialog() { /* IL_0000: ldc.i4.s 100 IL_0002: call void [mscorlib]System.Threading.Thread::Sleep(int32) */ var def = new PatchDefinition() { Name = "AdmiralDialogPlus", Version = 1, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = 5, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Ldarg_0), new CodeLine(OpCodes.Ldfld, "Kerberos.Sots.App Kerberos.Sots.UI.Dialog::_app"), new CodeLine(OpCodes.Ldarg_0), new CodeLine(OpCodes.Call, "System.String Kerberos.Sots.UI.PanelBinding::get_ID()"), new CodeLine(OpCodes.Call, "System.Void sotsos.managedcompanion.Sotsos_AdmiralManagerDialog_Handler::Initialise(Kerberos.Sots.App,System.String)"), }, TargetMethodName = "System.Void Kerberos.Sots.UI.AdmiralManagerDialog::Initialize()", }, new CodeBlock() { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = 878, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Ldarg_1), new CodeLine(OpCodes.Ldarg_2), new CodeLine(OpCodes.Ldarg_3), new CodeLine(OpCodes.Call, "System.Boolean sotsos.managedcompanion.Sotsos_AdmiralManagerDialog_Handler::ProcessMessage(System.String,System.String,System.String[])"), new CodeLine(OpCodes.Brfalse, "GOTO_1", null), new CodeLine(OpCodes.Ldarg_0), new CodeLine(OpCodes.Call ,"System.Void Kerberos.Sots.UI.AdmiralManagerDialog::RefreshDisplay()"), new CodeLine(OpCodes.Ret), new CodeLine(OpCodes.Nop, null, "GOTO_1") }, TargetMethodName = "System.Void Kerberos.Sots.UI.AdmiralManagerDialog::OnPanelMessage(System.String,System.String,System.String[])", }, new CodeBlock() { InsertOffset = 50, TargetMethodInstructionCount = 1932, Lines = new List<CodeLine>() { // public static List<AdmiralInfo> FilterAdmirals(List<AdmiralInfo> admirals) new CodeLine(OpCodes.Ldloc_3), new CodeLine(OpCodes.Call, "System.Collections.Generic.List`1<Kerberos.Sots.Data.AdmiralInfo> sotsos.managedcompanion.Sotsos_AdmiralManagerDialog_Handler::FilterAdmirals(System.Collections.Generic.List`1<Kerberos.Sots.Data.AdmiralInfo>)"), new CodeLine(OpCodes.Stloc_3) }, TargetMethodName = "System.Void Kerberos.Sots.UI.AdmiralManagerDialog::RefreshDisplay()", }, }, Description = "Better admiral dialog" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + ".admiral.dll"); }
public void CanPatchSotsManagedDllWithSqlLoggingNoop() { var def = new PatchDefinition() { Name = "TestPatchone", Version = 333, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = 43, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Nop), new CodeLine(OpCodes.Ldc_I4_0), new CodeLine(OpCodes.Stloc_0), new CodeLine(OpCodes.Br_S, "GOTO_1", null), new CodeLine(OpCodes.Ldloc_0, null, "GOTO_1"), new CodeLine(OpCodes.Ret) }, TargetMethodName = "System.Boolean Kerberos.Sots.Data.SQLite.SQLiteConnection::TryLogQuery(System.String)", } }, Description = "Disable SQL logging" }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatches(new List<PatchDefinition>() {def}); subject.SaveAssembly(assemblySrcName + "tst2.dll"); //Empirical assert //TODO: write port for verifying }
public void CanPatchSotsManagedDllWithNumTurnsHack() { var def = new PatchDefinition() { CodeBlocks = new List<CodeBlock>() { new CodeBlock() { Lines = new List<CodeLine>() { new CodeLine(OpCodes.Ldarg_0), // this. new CodeLine(OpCodes.Call, "Kerberos.Sots.App Kerberos.Sots.GameState::get_App()"), // base.App new CodeLine(OpCodes.Ldstr, "systemDetailsWidget"), // target panel name new CodeLine(OpCodes.Ldarg_0), // this. new CodeLine(OpCodes.Call, "System.Int32 Kerberos.Sots.GameStates.StarMapState::get_SelectedSystem()"), // this.SelectedSystem new CodeLine(OpCodes.Ldc_I4_1), //true new CodeLine(OpCodes.Ldc_I4_1), //true new CodeLine(OpCodes.Ret), new CodeLine(OpCodes.Call, "System.Void Kerberos.Sots.UI.StarSystemUI::SyncSystemDetailsWidget(Kerberos.Sots.App,System.String,System.Int32,System.Boolean,System.Boolean)"), // this.SelectedSystem }, TargetMethodName = "System.Void Kerberos.Sots.GameStates.StarMapState::UICommChannel_OnPanelMessage(System.String,System.String,System.String[])", InsertOffset = 1121, TargetMethodInstructionCount = 1495, } }, Description = "Automatically update the number of turns left to complete the build order for the star system on slider change." }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + "tst3.dll"); //Empirical assert //TODO: write port for verifying }
public void CanPatchSimpleExit() { var def = new PatchDefinition() { Name = "TestPatchOne", Version = 3, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = 43, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Nop), new CodeLine(OpCodes.Ldc_I4_0), new CodeLine(OpCodes.Ret), }, TargetMethodName = "System.Boolean Kerberos.Sots.Data.SQLite.SQLiteConnection::TryLogQuery(System.String)", } }, Description = "Disable SQL logging" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + "tst1.dll"); //Empirical assert //TODO: write port for verifying }
public void CanHackScriptHost() { /* IL_0000: ldc.i4.s 100 IL_0002: call void [mscorlib]System.Threading.Thread::Sleep(int32) */ var def = new PatchDefinition() { Name = "ScriptHostWaithax", Version = 1, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 52, //0 POS needed for the param, TargetMethodInstructionCount = 59, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Ldc_I4_S, (sbyte)1), //todo: object param //System.Void Sleep(System.Int32) new CodeLine(OpCodes.Call, "System.Void System.Threading.Thread::Sleep(System.Int32)"), }, TargetMethodName = "System.Void Kerberos.Sots.Engine.ScriptHost::ThreadProc(System.Object)", } }, Description = "Script host hacking" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + "shost100.dll"); }
public void CanCallMethodsFromCompanionModule() { var def = new PatchDefinition() { Name = "TestPatchCompanion", Version = 1, CodeBlocks = new List<CodeBlock>() { new CodeBlock() { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = 43, Lines = new List<CodeLine>() { new CodeLine(OpCodes.Nop), new CodeLine(OpCodes.Ldstr, "testing companion call"), new CodeLine(OpCodes.Call, "System.Void sotsos.managedcompanion.Sotsos_DebugHelper::SotsosLogMessage(System.String)"), new CodeLine(OpCodes.Ldc_I4_0), new CodeLine(OpCodes.Ret), }, TargetMethodName = "System.Boolean Kerberos.Sots.Data.SQLite.SQLiteConnection::TryLogQuery(System.String)", } }, Description = "Test companion module" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(assemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(assemblySrcName + "tst1.dll"); //Empirical assert //TODO: write port for verifying }
public void InjectModuleAssetCache() { throw new NotImplementedException(); PatcherDefaults.CompanionDllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.Explorables.dll"); var subject = new PatchRunner(""); subject.LoadAssembly(AssemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); //subject.ApplyPatch(_defCacheHooks); subject.SaveAssembly(AssemblySrcName + ".assetcache.dll"); }
public void InjectDesignInfoDebug() { PatcherDefaults.CompanionDllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.Explorables.dll"); var def = new PatchDefinition { Name = "DebugHelperSummariseDesign", Version = 1, CodeBlocks = new List<CodeBlock> { new CodeBlock { InsertOffset = Sotsos_DebugHelper.DebugDesign_TargetMethod_InstructionOffset, //0 POS needed for the param, TargetMethodInstructionCount = -1, Lines = new List<CodeLine> { new CodeLine(OpCodes.Ldarg_0), new CodeLine(OpCodes.Ldarg_1), new CodeLine(OpCodes.Ldarg_2), new CodeLine(OpCodes.Call, Sotsos_DebugHelper.DebugDesign_InjectMethod_Signature), }, TargetMethodName = Sotsos_DebugHelper.DebugDesign_TargetMethod_Signature, } }, Description = "Debug helper for summarise design ctd" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(AssemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(AssemblySrcName + ".debugsummarise.dll"); }
public void InjectDebugTaxRevenue() { PatcherDefaults.CompanionDllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.Explorables.dll"); PatcherDefaults.DllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.dll"); var def = new PatchDefinition { Name = "DebugTaxRevenue", Version = 1, CodeBlocks = new List<CodeBlock> { new CodeBlock { InsertOffset = 0, //0 POS needed for the param, TargetMethodInstructionCount = -1, Lines = new List<CodeLine> { new CodeLine(OpCodes.Ldarg_0), new CodeLine(OpCodes.Ldarg_1), new CodeLine(OpCodes.Ldarg_2), new CodeLine(OpCodes.Call, Sotsos_DebugHelper.DebugGetTaxRevenue_InjectMethod_Signature), new CodeLine(OpCodes.Pop) }, TargetMethodName = Sotsos_DebugHelper.DebugGetTaxRevenue_TargetMethod_Signature, } }, Description = "Debug helper for tax revenue ctd" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); //subject.LoadAssembly(AssemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.LoadAssembly(PatcherDefaults.DllPath, new FileInfo(PatcherDefaults.DllPath).DirectoryName ); subject.ApplyPatch(def); subject.SaveAssembly(PatcherDefaults.DllPath + ".dbgtax.dll"); }
public void AllowConsole() { PatcherDefaults.CompanionDllPath = Path.Combine(Directory.GetCurrentDirectory(), "sots2_managed.Explorables.dll"); var def = new PatchDefinition { Name = "AllowConsole", Version = 1, CodeBlocks = new List<CodeBlock> { new CodeBlock { InsertOffset = 0, TargetMethodInstructionCount = 2, Lines = new List<CodeLine> { new CodeLine(OpCodes.Ldc_I4_1), new CodeLine(OpCodes.Ret), }, TargetMethodName = "System.Boolean Kerberos.Sots.Engine.ScriptHost::get_AllowConsole()", } }, Description = "Enable console" //insert "return false" to the beginning of the method }; var subject = new PatchRunner(""); subject.LoadAssembly(AssemblySrcName, Path.Combine(Directory.GetCurrentDirectory(), "TestData")); subject.ApplyPatch(def); subject.SaveAssembly(AssemblySrcName + ".debugconsole.dll"); }