• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=mobrockers2;39853465]Use an arrayList if you don't know how many objects you want to put in it.[/QUOTE] But if you really insist on using regular arrays, I'd say keep count of how many items are in it in another variable.
In python I have two 1d numpy arrays, one for an x axis and one for a y axis of a contour graph. I'm trying to get a third, two dimensional array holding the values of a function at each point, ie array[0,1] = function(0,1) and so on, but I can't work out how to do it with pythons weird arrays. Here's what I have at the moment, maybe it'll help. [code]resolution = 50 plot_range = 0.3 x = np.array([]) y = np.array([]) c_pressure = np.array([],[]) #generate array of pressure drops and cost, varying d for i in range(resolution+1): x = np.append(x,0.05+(plot_range/resolution)*i) y = np.append(y,0.05+(plot_range/resolution)*i) c_pressure[x,y] = pressure_drop(x,y,5,5,5)[0][/code]
[QUOTE=Larikang;39837918]There are several problems here. First of all, I don't get that NameError. Are you sure this is the code you're running? Secondly n**0.5 always returns a float, even if n is a perfect square. Third, that loop will never terminate anyway, since the condition checks n and n is never modified. Recommendations: use math.sqrt, since that's what you're doing. Use the is_integer function instead of isinstance. [editline]7th March 2013[/editline] I can't comment on your math since I don't understand your explanation, but your j index is wrong. Since you start j at 5, you need to subtract one [I]before[/I] the loop starts (but after you check the loop condition). You can do this with the awesome "[URL="http://stackoverflow.com/questions/1642028/what-is-the-name-of-this-operator"]goes to[/URL]" operator: [cpp] for (int j = 5; j --> 0;) ... [/cpp][/QUOTE] You Sir are a genius! Can you explain a bit more when this operator is useful
[QUOTE=RandomDexter;39855327]You Sir are a genius! Can you explain a bit more when this operator is useful[/QUOTE] It's actually j-- > 0 written in a different way. So it's useful whenever you need to postfix-decrement. It's essentially the same as for(int j = 5; j > 0; --j) [editline]9th March 2013[/editline] You could've clicked the link
My trainer for AssaultCube is not working like it should be. The ammo hack worked before I started using the class, it'd increase the ammo instead of decrementing. Now, you shoot back with retarded amounts of recoil, literally flying around the map. The health one doesn't even have the right address, it just says 00000000. [cpp] // BrytEngine.h #pragma once #include <Windows.h> #include <iostream> class BrytEngineAC { public: bool Initialize(LPCSTR WndName); bool ReadMemory(DWORD BaseAddress, DWORD* DMAAddress, SIZE_T size); bool Enable(DWORD BaseAddress, int* Buffer, SIZE_T size); bool Enable(DWORD BaseAddress, BYTE* Buffer, SIZE_T size); HANDLE hProc; }; bool BrytEngineAC::Initialize(LPCSTR WndName) { /* BrytEngine(c) INITIALIZE: Use this function to set up handling to the window (FindWindow, OpenProcess, etc) */ std::cout << "BRYTENGINE AssaultCube Hack 1.0\n\n"; std::cout << " F8 IS GODMODE\n F9 IS UNLIMITED AMMO\n"; HWND hnd = FindWindow(NULL, WndName); if(!hnd) { std::cout << "\n\n!!!!!! Failed to Find Window !!!!!!\n\n"; return false; } DWORD procId; if(!GetWindowThreadProcessId(hnd, &procId)) { std::cout << "\n\n!!!!!! Failed to Get Process Id !!!!!!\n\n"; return false; } // Open the process with special priveleges BrytEngineAC::hProc = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ |PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION, false, procId); if(!hProc) { std::cout << "!!!!!! Failed to open process !!!!!!\n\n"; return false; } else return true; } bool BrytEngineAC::ReadMemory(DWORD BaseAddress, DWORD* DMAAddress, SIZE_T size) { /* BrytEngine(c) READMEMORY: Use this function to store DMAs into memory */ if(!ReadProcessMemory(BrytEngineAC::hProc, (LPCVOID)BaseAddress, &DMAAddress, size, NULL)) { std::cout << "\n!!!!!! Failed to read memory !!!!!!\n\n"; std::cout << "\n" << GetLastError() << "\n"; return false; } else return true; } bool BrytEngineAC::Enable(DWORD BaseAddress, int* Buffer, SIZE_T size) { /* BrytEngine(c) ENABLE: Use this function to write to process memory */ if(!WriteProcessMemory(BrytEngineAC::hProc, (LPVOID)BaseAddress, &Buffer, size, NULL)) { // If WriteProcessMemory() fails, output the error code std::cout << GetLastError() << "\n"; std::cout << "\n\n Failed to write health memory\n\n"; return false; } else return true; } bool BrytEngineAC::Enable(DWORD BaseAddress, BYTE* Buffer, SIZE_T size) { /* BrytEngine(c) ENABLE: Use this function to write to process memory */ if(!WriteProcessMemory(BrytEngineAC::hProc, (LPVOID)BaseAddress, &Buffer, size, NULL)) { // If WriteProcessMemory() fails, output the error code std::cout << GetLastError() << "\n"; std::cout << "\n\n Failed to write health memory\n\n"; return false; } else return true; }[/cpp] [cpp] //main.cpp #include "BrytEngine.h" DWORD RHealthAdd = 0x004DF73C; DWORD RAmmoAdd = 0x0045B75F; // Other options: 0x90, 0x90 (NOP) BYTE AmmoInc[2] = { 0xFF, 0x06 }; DWORD* HealthAdd; DWORD HOffset = 0x0000000F4; DWORD HealthAdd2; DWORD* AmmoAdd; bool HEnabled = false; bool AEnabled = false; int Health = 100; int main() { BrytEngineAC Trainer; Trainer.Initialize("AssaultCube"); Trainer.ReadMemory(RHealthAdd, HealthAdd, sizeof(DWORD)); HealthAdd2 = (DWORD)HealthAdd + HOffset; std::cout << "Health: " << HealthAdd << "\n"; std::cout << "Handle: " << Trainer.hProc; while(true) { if(GetAsyncKeyState(VK_F8)) Trainer.Enable((DWORD)HealthAdd, &Health, sizeof(DWORD)); if(GetAsyncKeyState(VK_F9)) Trainer.Enable(RAmmoAdd, AmmoInc, sizeof(BYTE[2])); } return 0; } [/cpp] help
[QUOTE=esalaka;39855441]It's actually j-- > 0 written in a different way. So it's useful whenever you need to postfix-decrement. It's essentially the same as for(int j = 5; j > 0; --j) [editline]9th March 2013[/editline] You could've clicked the link[/QUOTE] Oh, my bad. Thanks I encountered another problem. I need to scan sequence of chars and put them in an array. However, the damn scanf also scans the empty spaces, how do i avoid that?
[QUOTE=raccoon12;39856017]My trainer for AssaultCube is not working like it should be. The ammo hack worked before I started using the class, it'd increase the ammo instead of decrementing. Now, you shoot back with retarded amounts of recoil, literally flying around the map. The health one doesn't even have the right address, it just says 00000000. help[/QUOTE] Can dajoh explain why he rated me dumb? Is there an obvious error I'm missing?
It could be because you're making a trainer (stuff like that is generally frowned upon in here), or it could be because you're setting the memory addresses in your code, while it actually moves around from runtime to runtime. (I think, if you want to test it yourself, open up Cheat Engine and find it a couple of times and note the addresses)
[QUOTE=Gulen;39856938]It could be because you're making a trainer (stuff like that is generally frowned upon in here), or it could be because you're setting the memory addresses in your code, while it actually moves around from runtime to runtime. (I think, if you want to test it yourself, open up Cheat Engine and find it a couple of times and note the addresses)[/QUOTE] I'm reading the DMA stored in the static variable at run-time, then writing to that DMA. I'm not stupid.
How would I go about doubling the size of an array in C? I would need to use the malloc function right?
[QUOTE=W00tbeer1;39858495]How would I go about doubling the size of an array in C? I would need to use the malloc function right?[/QUOTE] Yes, and you'd have to allocate the original array with malloc. Then you could use realloc() on the original array to double it.
[QUOTE=account;39858606]Yes, and you'd have to allocate the original array with malloc. Then you could use realloc() on the original array to double it.[/QUOTE] Very new to C, so probably not doing this right: [CODE]array = malloc(sizeof(array)*2)[/CODE] Too confused haha.
Basically: [cpp]array = realloc(array, sizeof(array)*2);[/cpp]
Hmm, it seems to not be crashing now but I'm getting segmentation faults, so I guess that's progress. Thanks for the help.
[QUOTE=account;39858798]Basically: [cpp]array = realloc(array, sizeof(array)*2);[/cpp][/QUOTE] Except that sizeof(array) is the size of the pointer. Try again. If it's an array, it cannot be resized. If it was allocated by malloc, you'll have to keep track of its size by yourself.
I always seem to forget on what you can use sizeof. I thought I might be wrong, thanks for clarifying
[QUOTE=esalaka;39858991]Except that sizeof(array) is the size of the pointer. Try again. If it's an array, it cannot be resized. If it was allocated by malloc, you'll have to keep track of its size by yourself.[/QUOTE] Could I create a temporary array and copy the elements over? Would I need to use the free() function to accomplish that?
[QUOTE=W00tbeer1;39859037]Could I create a temporary array and copy the elements over? Would I need to use the free() function to accomplish that?[/QUOTE] Use an arrayList?
[QUOTE=raccoon12;39856678]Can dajoh explain why he rated me dumb? Is there an obvious error I'm missing?[/QUOTE] I rated you dumb because you're using a word that you don't know the meaning of (DMA). [QUOTE=dajoh;39849401]It won't even compile.[/QUOTE] Why did [b]you[/b] rate this post dumb? It doesn't compile: [url]http://codepad.org/PUyVFb6l[/url]
[QUOTE=W00tbeer1;39859037]Could I create a temporary array and copy the elements over? Would I need to use the free() function to accomplish that?[/QUOTE] Here's what you can do, now that esalaka straightened me out: [cpp]type * array = malloc(sizeof(type) * NUM_ELEMENTS); ... array = realloc(array, sizeof(type) * NUM_ELEMENTS * 2); [/cpp] Where type is your element type and NUM_ELEMENTS is your initial array length. If you're continuing to change the length, you could save the number of elements or the size in a variable that you update each time you increase the size as well. [editline]9th March 2013[/editline] [QUOTE=mobrockers2;39859067]Use an arrayList?[/QUOTE] He's in C, not C++.
[QUOTE=account;39859140]He's in C, not C++.[/QUOTE] C++ doesn't have an ArrayList either.
TIL
[QUOTE=dajoh;39859894]C++ doesn't have an ArrayList either.[/QUOTE] C++ has std::vector, though
[QUOTE=raccoon12;39856017]My trainer for AssaultCube is not working like it should be. The ammo hack worked before I started using the class, it'd increase the ammo instead of decrementing. Now, you shoot back with retarded amounts of recoil, literally flying around the map. The health one doesn't even have the right address, it just says 00000000. ... help[/QUOTE] Why are you doing this? AssaultCube is open source.
[QUOTE=Jookia;39861092]Why are you doing this? AssaultCube is open source.[/QUOTE] To learn.
currently trying to acquaint myself to C# by making a little spamming program, but I've run into a few issues. first and foremost, I'd like to be able to use keys for "pressing" buttons but ProcessCmdKey seems to be relative to the program itself (it works but only when I have the window selected; when I press ctrl+f in a chatbox on a different window such as steam chat, nothing happens). here's where I believe the issue lies: [IMG]http://puu.sh/2f8RH[/IMG] [URL="http://pastebin.com/mcGu5JsQ"]here's the code for form1[/URL] any help is appreciated of course
[QUOTE=RandomDexter;39856382] I encountered another problem. I need to scan sequence of chars and put them in an array. However, the damn scanf also scans the empty spaces, how do i avoid that?[/QUOTE] Anyone?
[cpp]if(character == ' ')[/cpp] ?
[QUOTE=Gulen;39863727][cpp]if(character == ' ')[/cpp] ?[/QUOTE] oh, sorry. Okey, this is how(allegedly) i hunt them down, but how do i eliminate them? this is the part of the code that reads the stdin [code] printf ("Insert the sequence of chars(from 'a' to '-'): "); for(int i = 0; i < lenghtofseq; i++){ testsubject202[i] =g etchar(); } [/code]
What do you mean it scans the empty spaces?
Sorry, you need to Log In to post a reply to this thread.