(C#) Why are the in-Game values not changed by my program? - c#

I am relatively new to coding. I wanted to create a trainer for the game Assault Cube. I have already implemented an "unlimited ammo" option which works perfectly fine and now i want to make a god mode (unlimited health) option. It doesn't work, and I dont understand why. I have taken the correct offsets from the game (checked with cheat-engine), did all the stuff I did with the ammo also with the health and added the new health values that should be frozen. Is there a problem in the program? Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Memory;
namespace AssaultHack
{
public partial class Form1 : Form
{
Mem meme = new Mem();
public static string RifleAmmo = "ac_client.exe+0x00109B74,150";
public static string PlayerHealth = "ac_client.exe+0x0010A280,338,34,98,8";
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
int PID = meme.GetProcIdFromName("ac_client");
if(PID > 0)
{
meme.OpenProcess(PID);
Thread WA = new Thread(writeAmmo) { IsBackground = true };
Thread PH = new Thread(godMode) { IsBackground = true };
PH.Start();
WA.Start();
}
}
private void writeAmmo()
{
while(true)
{
if (checkBox1.Checked)
{
meme.WriteMemory(RifleAmmo, "int", "99999");
Thread.Sleep(2);
}
Thread.Sleep(2);
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void godMode()
{
while(true)
{
if (checkBox2.Checked)
{
meme.WriteMemory(PlayerHealth, "int", "99999");
Thread.Sleep(2);
}
Thread.Sleep(2);
}
}
}
}

In all the games there are 2 types of vars:
1.netvars: this type of vars is managed by the host of the server and you cant change them only if you was the host of the server (in this case you can change all the players vars) or if you exploited the send socket in the server
2.localvars: this type of vars is stored and managed in your game data locally and you can change this vars anytime like: field of view/viewMatrix/angles.
In your case Assault Cube the health/shield/xyz/score/ammo is netvars and you cant change them only if you was the host. but you can reverse enginner the game to find things that can help you to create exploit like flying/etc...

Related

C# startup form unable to be shown

This is my first assignment using C# and I've learned briefly about programming with Python in my pre-u. The C# form that I would like to show the user upon logging in can't be shown and instead, the program displays the Built errors msg, where I click on 'Yes' to continue running the last successful build. However, it will show one of the previous forms (which I have deleted from the program) instead - making it hard for me to test run and check for any other errors in my program.
The form I would like to show is TechnicianHome.
Error
There were built errors. Would you like to continue and run the last successful build?
Any help is much appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ASSIGNMENT
{
public partial class TechnicianHome : Form
{
public static string name;
public TechnicianHome()
{
InitializeComponent();
}
public TechnicianHome (string n)
{
InitializeComponent();
name = n;
}
private void TechnicianHome_Load(object sender, EventArgs e)
{
lblWelcome.Text = "Welcome" + name;
}
private void button1_Click(object sender, EventArgs e)
{
ServiceRequests vr = new ServiceRequests();
this.Hide();
vr.ShowDialog();
}
private void button1_Click_1(object sender, EventArgs e)
{
UpdateProfile up = new UpdateProfile();
this.Hide();
up.ShowDialog();
}
}
}

MouseKeyHook 'CallbackOnCollectedDelegate' Issue

I am using Gma.System.MouseKeyHook and getting the following exception:
Managed Debugging Assistant 'CallbackOnCollectedDelegate'
Message=Managed Debugging Assistant 'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected delegate of type 'Gma.System.MouseKeyHook!Gma.System.MouseKeyHook.WinApi.HookProcedure::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.'
I've tried to handle the function calls and subscription. However, the issue still persists. Also I try to run it many times, occasionally it gives a 'NullReferenceException' as well. It also confused me a lot, maybe those issues are correlated.
using Gma.System.MouseKeyHook;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
// Uses a MouseKeyHook Library license at
https://github.com/gmamaladze/globalmousekeyhook/blob/master/LICENSE.txt
namespace TransparentClickTest {
public partial class Form1 : Form {
public Form1() {
//GC.TryStartNoGCRegion(100);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Red;
TransparencyKey = Color.Red;
InitializeComponent();
OnDown();
}
protected virtual void OnUp() {
Hook.GlobalEvents().MouseUp += (sender, e) => {
try {
label1.Text = "Mouse Up!!!";
Hook.GlobalEvents().Dispose();
OnDown();
}
catch(Exception e2) {
Hook.GlobalEvents().Dispose();
OnDown();
}
};
}
protected virtual void OnDown() {
Hook.GlobalEvents().MouseDown += (sender, e) => {
try {
label1.Text = $"Mouse {e.Button} Down at {e.X}, {e.Y}";
Opacity = 1;
Hook.GlobalEvents().Dispose();
OnUp();
}
catch(Exception e1) {
Hook.GlobalEvents().Dispose();
OnUp();
}
};
}
private void PictureBox1_Click(object sender, EventArgs e) {
}
private void Label1_Click(object sender, EventArgs e) {
}
}
}
add this: private static IKeyboardMouseEvents HookEvents = null;
use HookEvents.MouseDown replace Hook.GlobalEvents().MouseDown

Use object between multiple functions

I am creating a spam email checker. One method scans the email, another adds a known flag to an array of words and phrases to check against; both methods are part of Tester class. Currently I have a button per method, however each event creates its own spam object. How do I get both events to use the same object, allowing the scan to recognize the flag I just added?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW8_DR
{
public partial class Spam_Scanner : Form
{
public Spam_Scanner()
{
InitializeComponent();
}
private void testButton_Click(object sender, EventArgs e)
{
Tester scan = new Tester();
scan.tester(Convert.ToString(emailBox.Text));
this.SpamRatingBox.Text = string.Format("{0:N1}%", Tester.countSpam / Tester.wordCount * 100);
this.WordsBox.Text = Tester.posSpam;
this.OutputPanal.Visible = true;
this.pictureBox1.Visible = false;
}
private void addButton_Click(object sender, EventArgs e)
{
Tester scan = new Tester();
scan.addSpam(Convert.ToString(addFlagBox.Text));
this.addFlagBox.Text = "";
}
}
}
Move the Tester variable to the class field, like this:
public partial class Spam_Scanner : Form
{
Tester scan;
public Spam_Scanner()
{
InitializeComponent();
scan = new Tester();
}
private void testButton_Click(object sender, EventArgs e)
{
scan.tester(Convert.ToString(emailBox.Text));
this.SpamRatingBox.Text = string.Format("{0:N1}%", Tester.countSpam / Tester.wordCount * 100);
this.WordsBox.Text = Tester.posSpam;
this.OutputPanal.Visible = true;
this.pictureBox1.Visible = false;
}
private void addButton_Click(object sender, EventArgs e)
{
scan.addSpam(Convert.ToString(addFlagBox.Text));
this.addFlagBox.Text = "";
}
}
Variables declared inside of a method (as yours are) have method scope, so they can't be seen by other methods.
Instead, declare the variable in the class scope so that both the class's methods can see it.
public partial class Spam_Scanner : Form
{
private Tester scan;
private void testButton_Click(object sender, EventArgs e)
{
scan = new Tester();
...
}
private void addButton_Click(object sender, EventArgs e)
{
scan.addSpam(Convert.ToString(addFlagBox.Text));
...
}
}
Depending on the order of button clicks, you may want to initialize the variable in the declaration rather than in the testButton_Click method, but thats up to you. The important thing to remember is that scopes can see their own members, and all scopes they are nested in. Thus, methods can see class-scope variables, but not each other's.

Webbrowser control doenst show sites correctly

I'm creating a custom internet browser in c# using the webbrowser control.
And it works i can load sites and browse around and all that.
But with some sites (with alot of pictures and such) he wont put everything in the right spot so i will get text blocks inside images and vice versa.
How do i solve this ?
My code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WB1.Navigate("http://nos.nl");
}
private void GoBtn_Click(object sender, EventArgs e)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
private void AddRsBsr_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
}
private void BackBtn_Click(object sender, EventArgs e)
{
WB1.GoBack();
}
private void StopBtn_Click(object sender, EventArgs e)
{
WB1.Stop();
}
private void HomeBtn_Click(object sender, EventArgs e)
{
WB1.Navigate("http://google.nl");
}
}
}
Now i know my code isn't clean and all but im doing that right now while waiting and hoping for an answer.
Thanks !
The WebBrowser component defaults to rendering in ... IE7 mode.
To have it behave as IE10/11 you need to make the registry changed described here (FEATURE_BROWSER_EMULATION): http://msdn.microsoft.com/en-us/library/ie/ee330730(v=vs.85).aspx

How to get a value from an Array via a class in Winforms using C#

I have a class called Game.cs and in the class I have the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Simon
{
class Game
{
public int[] TheArray = new int[1000];
private bool m_Play;
public bool Play
{
set { m_Play = value; }
get { return m_Play; }
}
public Game()
{
Random rnd = new Random();
for (int i = 0; i < 8; i++)
{
TheArray[i] = rnd.Next(0, 4); // between 0 and 3
}
}
}
}
I want to be able to call TheArray from my form. I want the loop to iterate based on the times I click button5 and then I want to click my buttons programmatically based on what my array returns. On my form I have 4 buttons called, button1,button2,button3 and button4.
Once I click on button5 my code needs to click the button based on the array each time it loops through TheArray
So far I have this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Simon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Game m_game;
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("box1");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("box2");
}
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("box3");
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("box4");
}
private void button5_Click(object sender, EventArgs e)
{
// Determine which button to click based on TheArray
}
}
}
To click on the buttons based on the array (I'm assuming 0 in the array corresponds to button1, etc, you could try something like this:
private void button5_Click(object sender, EventArgs e)
{
Button[] button = { button1, button2, button3, button4 };
for (int i = 0; i < m_game.TheArray.Length; i++)
{
button[m_game.TheArray[i]].PerformClick();
}
}
As a side note, as #ThunderGr pointed out in a comment, you'd have to create an instance of your game or else make it static.
In the form declaration define Game MyGameClass=new Game();.
You code has lots of gaps, though. In order to get the last int, you need to also define a public int CurrentInt=0; in the Game Class and do a CurrentInt++; from within Game().
Now, you can do a int theInt=MyGameClass.TheArray[MyGameClass.CurrentInt]; from within the button5 event and implement a switch statement to find which button to click.
Of course, this is still inefficient.
Perhaps it would be better if you declared a public int GetLastInt() in Game that would return TheArray[CurrentInt];.

Categories

Resources