if (DDText.getText(0x17) == "XX") parameters = new string[] { "-InstallerVersion", "", "", "st" }; // st == steam else parameters = new string[] { "-InstallerVersion", "", "" }; parameters[1] = SelfUpdater.CurrentBuildVersion.ToString(); parameters[2] = DDText.getText(0); // , , “ru”, “de”, “en” .. local.txt . UpdateManager.SetCommandLineParameters(parameters); // System.Diagnostics.Process UpdateManager.StartApplication();
if (DDText.getText(0x17) == "XX")
- A string from the local.txt file next to the launcher.parameters[1] = SelfUpdater.CurrentBuildVersion
- The launcher version is quietly twitching from it, although the check in the client is strange, as I learned later, and you can simply specify a number much larger than the current one, “in reserve”, since The check goes only to obsolescence, so skazat, versions through the comparison of numbers "less-more".parameters[2] = DDText.getText(0)
- Having forged the version, I learned that it is the language of the game, in the format of “ru”, “de”, “en”, etc. static SelfUpdater() { currentBuildVersion = 0x75; // 117, .. 1.17 . }
StrongholdKingdoms.exe -InstallerVersion 117 ru
StrongholdKingdoms.exe -InstallerVersion 100500 ru
System.Reflection.Assembly A = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.StartupPath + @"\BotDLL.dll"); Type ClassType = A.GetType("BotDLL.Main", true); object Obj = Activator.CreateInstance(ClassType); System.Reflection.MethodInfo MI = ClassType.GetMethod("Inject"); MI.Invoke(Obj, null);
System.Reflection.Assembly
- This is the thing that is responsible for creating links to files when connecting them to the project, only from code. And it also stores information about the versions of your project and copyrights (yes, the same AssemblyInfo.cs in all your projects).Assembly.LoadFrom(System.Windows.Forms.Application.StartupPath + @"\BotDLL.dll")
- Load our library.return (this.HasLoggedIn || (this.Username.Length > 0));
if (!IsStarted) { System.Reflection.Assembly A = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.StartupPath + @"\BotDLL.dll"); Type ClassType = A.GetType("BotDLL.Main", true); object Obj = Activator.CreateInstance(ClassType); System.Reflection.MethodInfo MI = ClassType.GetMethod("Inject"); MI.Invoke(Obj, null); IsStarted = true; } return (this.HasLoggedIn || (this.Username.Length > 0));
public void Inject() { AllocConsole(); Console.Title = "SHKBot"; Console.WriteLine("DLL !"); Thread Th = new Thread(SHK); Th.Start(); BotForm FBot = new BotForm(); FBot.Show(); } … [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool AllocConsole();
InterfaceMgr.Instance.selectVillage(VillageID); GameEngine.Instance.downloadCurrentVillage();
public void SHK() { Console.WriteLine(" !"); while (!GameEngine.Instance.World.isDownloadComplete()) { Console.WriteLine(" !"); Thread.Sleep(5000); // 5 sec Console.Clear(); } Console.WriteLine(" ! ."); Console.WriteLine("\n======| DEBUG INFO |======"); Console.WriteLine(RemoteServices.Instance.UserID); Console.WriteLine(RemoteServices.Instance.UserName); List<int> VillageIDs = GameEngine.Instance.World.getListOfUserVillages(); foreach (int VillageID in VillageIDs) { WorldMap.VillageData Village = GameEngine.Instance.World.getVillageData(VillageID); Console.WriteLine("[] " + Village.m_villageName + " - " + VillageID); InterfaceMgr.Instance.selectVillage(VillageID); GameEngine.Instance.downloadCurrentVillage(); } Console.WriteLine("======| ========== |======\n"); while (true) { try { // - } catch (Exception ex) { Console.WriteLine("\n======| EX INFO |======"); Console.WriteLine(ex); Console.WriteLine("======| ======= |======\n"); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using Kingdoms; using System.CodeDom.Compiler; using Microsoft.CSharp; using System.Reflection; namespace BotDLL { public partial class BotForm : Form { Thread TradeThread; bool IsTrading = false; public void Log(string Text) { Console.WriteLine(Text); richTextBox_Log.Text = Text + "\r\n" + richTextBox_Log.Text; } public BotForm() { CheckForIllegalCrossThreadCalls = false; InitializeComponent(); this.Show(); Log(" ."); listBox_ResList.SelectedIndex = 0; Log(" ..."); TradeThread = new Thread(Trade); TradeThread.Start(); } private void button_Trade_Click(object sender, EventArgs e) { // if (GameEngine.Instance.World.isDownloadComplete() && textBox_TradeTargetID.Text.Length > 0) { try { if (!IsTrading) // { button_Trade.Text = ""; IsTrading = true; // } else // { button_Trade.Text = ""; IsTrading = false; } } catch (Exception ex) { Console.WriteLine("\n======| EX INFO |======"); Log(ex.ToString()); Console.WriteLine("======| ======= |======\n"); } } } public void Trade() { Log(" !"); int Sleep = 0; while (true) // { Sleep = 60 + new Random().Next(-5, 60); if (IsTrading) { Log("[" + DateTime.Now + "] \"" + listBox_ResList.SelectedItem.ToString() + "\""); // ID int ResID = int.Parse(listBox_ResList.SelectedItem.ToString().Replace(" ", "").Split('-')[0]); int TargetID = int.Parse(textBox_TradeTargetID.Text); // ID - List<int> VillageIDs = GameEngine.Instance.World.getListOfUserVillages(); // foreach (int VillageID in VillageIDs) // { // ( ) if (GameEngine.Instance.getVillage(VillageID) != null) { // WorldMap.VillageData Village = GameEngine.Instance.World.getVillageData(VillageID); VillageMap Map = GameEngine.Instance.getVillage(VillageID); // int ResAmount = (int)Map.getResourceLevel(ResID); // - int MerchantsCount = Map.calcTotalTradersAtHome(); // - Log(" " + VillageID + " " + MerchantsCount + " "); // int SendWithOne = int.Parse(textBox_ResCount.Text); // - int MaxAmount = MerchantsCount * SendWithOne; // - if (ResAmount < MaxAmount) // MerchantsCount = (int)(ResAmount / SendWithOne); // if (MerchantsCount > 0) // { TargetID = GameEngine.Instance.World.getRegionCapitalVillage(Village.regionID); // , textBox_TradeTargetID.Text = TargetID.ToString(); // GameEngine.Instance.getVillage(VillageID).stockExchangeTrade(TargetID, ResID, MerchantsCount * SendWithOne, false); AllVillagesPanel.travellersChanged(); // ( ) GUI- } } } Log(" " + Sleep + " " + DateTime.Now.AddSeconds(Sleep).ToString("HH:mm:ss")); Console.WriteLine(); } Thread.Sleep(Sleep * 1000); // , . . } } private void BotForm_FormClosing(object sender, FormClosingEventArgs e) { try { TradeThread.Abort(); } catch {} } private void button_MapEditing_Click(object sender, EventArgs e) { button_MapEditing.Text = (!GameEngine.Instance.World.MapEditing).ToString(); GameEngine.Instance.World.MapEditing = !GameEngine.Instance.World.MapEditing; } private void button_Exec_Click(object sender, EventArgs e) { if (richTextBox_In.Text.Length == 0 || !GameEngine.Instance.World.isDownloadComplete()) return; richTextBox_Out.Text = ""; // *** Example form input has code in a text box string lcCode = richTextBox_In.Text; ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler(); CompilerParameters loParameters = new CompilerParameters(); // *** Start by adding any referenced assemblies loParameters.ReferencedAssemblies.Add("System.dll"); loParameters.ReferencedAssemblies.Add("System.Data.dll"); loParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll"); loParameters.ReferencedAssemblies.Add("StrongholdKingdoms.exe"); // *** Must create a fully functional assembly as a string lcCode = @"using System; using System.IO; using System.Windows.Forms; using System.Collections.Generic; using System.Text; using Kingdoms; namespace NSpace { public class NClass { public object DynamicCode(params object[] Parameters) { " + lcCode + @" return null; } } }"; // *** Load the resulting assembly into memory loParameters.GenerateInMemory = false; // *** Now compile the whole thing CompilerResults loCompiled = loCompiler.CompileAssemblyFromSource(loParameters, lcCode); if (loCompiled.Errors.HasErrors) { string lcErrorMsg = ""; lcErrorMsg = loCompiled.Errors.Count.ToString() + " Errors:"; for (int x = 0; x < loCompiled.Errors.Count; x++) lcErrorMsg = lcErrorMsg + "\r\nLine: " + loCompiled.Errors[x].Line.ToString() + " - " + loCompiled.Errors[x].ErrorText; richTextBox_Out.Text = lcErrorMsg + "\r\n\r\n" + lcCode; return; } Assembly loAssembly = loCompiled.CompiledAssembly; // *** Retrieve an obj ref – generic type only object loObject = loAssembly.CreateInstance("NSpace.NClass"); if (loObject == null) { richTextBox_Out.Text = "Couldn't load class."; return; } object[] loCodeParms = new object[1]; loCodeParms[0] = "SHKBot"; try { object loResult = loObject.GetType().InvokeMember( "DynamicCode", BindingFlags.InvokeMethod, null, loObject, loCodeParms); //DateTime ltNow = (DateTime)loResult; if (loResult != null) richTextBox_Out.Text = "Method Call Result:\r\n\r\n" + loResult.ToString(); } catch (Exception ex) { Console.WriteLine("\n======| EX INFO |======"); Console.WriteLine(ex); Console.WriteLine("======| ======= |======\n"); } } } }
Source: https://habr.com/ru/post/225663/
All Articles