How to use CLLocationManager [self.locationManager startUpdatingHeading] without GPS? [duplicate] - objective-c

This question already has an answer here:
Something turns on GPS but what? How do I find which Object uses GPS?
(1 answer)
Closed 9 years ago.
If I used
[self.locationManager startUpdatingHeading];
An arrow shows up on status bar.
Does
[self.locationManager startUpdatingHeading];
uses GPS?
If it doesn't, why arrows does show up on statusbar?
Note: I've read the documentation. True heading is available only if location is enabled. What I am thinking is
Enable location
Get heading once.
Compute difference between true heading and magnetic heading.
Store that number in a static variable.
Disable location.
Every time heading is updated, get the magnetic heading, and then add the difference between true heading and magnetic heading.
Another thing I think might work is to set location accuracy to be so wide that it doesn't require GPS at all.
I wonder if it's possible. For example, can we disable location update programatically? As far as I know calling stopUpdatingLocation does not turn off location update (didUpdateToLocation no longer called but an ugly arrow is on status bar).
self.locationManager.locationServicesEnabled=false doesn't work because the property is a class property that's read only. Looks like there is no way to turn off locationServices and yet update heading. I may be wrong. Am I?
Basically I want to help my visitor see direction without excessive GPS.

Of course, startUpdatingHeading uses GPS.
From CLLocationManager Class Reference:
In iOS, a device with the appropriate hardware may also report heading information. When the value in the headingAvailable property is YES, you can use a location manager object to retrieve heading information. To begin the delivery of heading-related events, assign a delegate to the location manager object and call the location manager’s startUpdatingHeading method. If location updates are also enabled, the location manager returns both the true heading and magnetic heading values. If location updates are not enabled, the location manager returns only the magnetic heading value. These features are not available in OS X.

The Location Services are designed to be as efficient as possible, to minimise power consumption and increase battery life. For example, the API allow you to declare to the service how much measurement accuracy is required, because more accuracy requires more hardware and power. If you only require low accuracy (eg ~10km) you can simply use the cell towers for location info, which is cheap as the radio is already active. If you need more accuracy than that (eg. a few km) the hardware might switch to triangulation using WiFi hotspot information, which requires a medium amount of power. But for the highest accuracy, the system will enable the GPS unit, which consumes much more power.
However, if you only request heading information, the magnetometer alone will be used (provided the hardware supports it; ie. iPhone 4+ IIRC). The GPS unit will not be enabled in this instance. As per the CLLocationManager Reference:
If location updates are not enabled, the location manager returns only the magnetic heading value.
As for the arrow indicator in the status bar, this is displayed whenever any app uses Location Services. If you open the built-in Compass app, you'll notice the arrow is displayed there also, even though it only manages heading data.
Using stopUpdatingLocation is separate to stopUpdatingHeading and will only stop calling your location callback, while also powering down the hardware resources as appropriate.
As for locationServicesEnabled, this is set to YES if the services are enabled on the device (by the user), which is why the field is read-only.
So, simply call startUpdatingHeading and provided you don't call startUpdatingLocation, you don't need to worry about the GPS. The steps you mention are not necessary as CL is already doing the hard work for you.
This information is all covered in the reference:
CLLocationManager Reference:

Related

Can variables in memory by made immune to malicious memory editing?

Let's say I am making a game and the player's health is stored in a variable float player_hp. While playing the game, a user can open a memory editor like Cheat Engine, do some clever searches through the memory, and find the location of the variable in memory. They can then edit it to be whatever they want, effectively allowing them to cheat.
Is there a fancy way to store my variables that will effectively stop users from maliciously editing them? Should I move them around in memory? Should I encrypt them or hash them?
If it matters, I am primarily using C++.
Disclaimer: I have no experience programming games, only making cheats for them.
Calculate all important variables such as health & ammo server side and replicate that data to the client. Pickups must also be validated by the server. If you serverside ammo, we'll just call PickUp(ammoCrate) if it's client sided.
You'll never stop everyone but I think it's important to make it annoying enough for 90% of people to stop trying to cheat. There's some basic stuff every game should have and then more advanced protections that popular games must have to avoid being destroyed by cheaters.
Encrypt commonly modified values such as health with a basic XOR like algorithm that changes over time. Change address of the key also and use a pointer to it, make the pointer more than 6 layers deep. This will force cheaters to make a script and use pattern scanning instead just a cheat table, that will stop most people.
Use IsDebuggerPresent() to detect debuggers being attached and then close the process. When you do "Find What Accesses" in Cheat Engine that will attach a debugger and if using default options will be detected by IsDebuggerPresent.
This can be hooked and patched, the next step is to manually check the BeingDebugged flag in the Process Environment Block
Get PEB pointer:
PEB* GetPEB()
{
#ifdef _WIN64
return (PEB*)__readgsword(0x60); //64 bit
#else
return (PEB*)__readfsdword(0x30); //32bit
#endif
}
Read the debugger flag:
bool IsDebugFlagSet(PEB* peb)
{
if (peb->BeingDebugged == 1) return true;
else return false;
}
If they're hooking IsDebuggerPresent() you can compare the bytes on disk to the bytes in memory at the beginning of the function and compare, or even easier just check the first byte and see if it's a relative jmp (x86 example)
Check for Hooks:
bool IsHooked(char* functionName, char* dllName)
{
BYTE* functionAddress = (BYTE*)GetProcAddress(GetModuleHandle(dllName), functionName);
return (*functionAddress == 0xE9);
}
Other tricks:
Hook LoadLibrary() & LDRLoadDLL() and stop them from loading rogue dlls
Scan running processes for memory editors by comparing the image name or image path using CreateToolHelp32Snapshot() against a blacklist
Fill all debug registers so debugger cannot be attached
Beyond these tricks you can use a commercial anticheat or kernel mode driver to protect your game, but the above tips will stop the average person.
Two ways to protect your data:
1) Only provide the user with binary files. Compiled code. Don't give them source code.
2) If your game is an online game, store sensitive data server side.
You should research an idea called "encapsulation" for use in designing APIs such that sensitive data is protected.

OS X Programmatically Set Default Output Device

I have been attempting to change which audio device my computer sends sound to. My end goal is to create a program that can make my laptop output to its built-in speakers even when headphones are plugged into the headphone jack.
I stumbled across this project, but the methods it uses (specifically AudioHardwareSetProperty) are deprecated. It also just doesn't work (it will say it changed the output device, but sound will still go to my headphones).
CoreAudio seems very poorly documented and I could not find ANY code online that did not use that function. I would go with the deprecated function if it did what I wanted, but it doesn't. I'm unsure weather it's broken or just doesn't do what I think it does, but that really doesn't matter in the end.
I attempted to look at the comments on AudioHardwareSetProperty but all I found was this in the discussion section:
Note that the value of the property should not be considered changed until the
HAL has called the listeners as many properties values are changed
asynchronously. Also note that the same functionality is provided by the
function AudioObjectGetPropertyData().
This is obviously not true, since I know for a fact that AudioObjectGetPropertyData is used for getting information about one specific audio device.
Is what I am trying to do possible with CoreAudio?

How are music commands handled?

In my keyboard I have some keys to play, pause, play next.... to control the music. I would like to know how this is done under the hood. Is it some sort of API in the operating system that passes the information on to the music player? Is the player reading for pressed keys and reacting to them?
Is there a unified way to control music players?
I will try to stay platform independent where I can, however, at some point I will have to strive to Windows.
First it is important that you understand what happens when you press a key; this page from Microsoft describes exactly the information I am about to summarize in this section. When you press a key, your keyboard generates a scan-code which uniquely identifies your pressed key. However, these scan-codes are keyboard-dependent and you will as good as never work directly with them. Windows, the OS, will translate the scan-codes to virtual-key-codes. Virtual-key-codes are OS-specific codes which resemble their respective scan-codes; virtual-key-codes are what you will usually, in the lowest level, be working with. I should also note that some virtual-key-codes are usually irrelevant to the programmer - such would be keys like "ctrl" which are used for OS commands.
The API for windows can be found in the above link, too, but as far as I know it is for C++; I do not know about Ruby itself.
Now, to your second question, whether the players reads for pressed keys and reacts to them. I am about to present a common principal that is used with keys, buttons, etc., in software design - the actual implementation of the Media Player is a different question. User inputs, which fully require user interaction, are usually implemented with the Oberserver-Oberservable pattern in object-oriented design; the following link explains this pattern for ruby.
In our case, we would have a KeyboardListener acting as Oberservable; it will 'request' from the OS that it would like to be informed when a key is pressed. As well, let us have a MusicManager which is capable of causing music to be player, paused, etc - it acts as Overserver. When a key is pressed the KeyboardListener instantiates an object containing information about what type of key was pressed and passes it to the MusicManager. This would be what happend under the hood, according to this implementation:
Press pause button
The OS informs the KeyboardListener that pause button was pressed
KeyboardListener creates an event containing what button was pressed and passes it to the MusicManager
MusicManager determines the cause of action
So why don't we just skip step 2 and go directly to 3? There are several reasons to do so but I will only provide one - it allows the software to be designed in a platform independent, maintainable way. The only code that has to be adopted will be the KeyboardListeners'; it will only need to alter its code on how it 'requests' the OS to be informed. Thus we will have a WindowsKeyboardListener, LinuxKeyboardListener, etc. Which particular Listener will actually be used is dependent upon the runtime environment.

VGA programming without using interrupt (only registers)

I want to develop a VGA graphics driver (for Linux(Ubuntu)) with support for the basic primitives such as putpixel, drawline, fillrect and bitblt. I want to do it in protected mode.
I´ve been googling for a week and the following four links are the best I have found:
http://www.brackeen....vga/basics.html
http://www.osdever.n...VGA/vga/vga.htm
http://bos.asmhacker...sing%20bios.htm
Unfortunately, the first one uses a BIOS call so I cannot use it. The second link has lots of information on the VGA registers but no examples showing how to make them work together. The third example is a example to switch in 13h mode but i've tried it and nothing happened. Can you guys give me a hint? Thanks in advance!
--Vincenzo
my code at http://bos.asmhackers.net/docs/vga_without_bios/snippet_5/vga.php
works fine if you are in 32bit mode with full hardware access. Unfortunately I doubt that any Linux variant will let you directly access the VGA ports. I'm not sure how you develop this driver, but if you made sure that you have full access to the VGA ports it should work. In my example code I only switch between mode 0x03 and 0x13, but in the folders above you'll be able to find port values for most other common VGA modes, as well as C code to do the switch if you prefer that.
Christoffer code include files are found BOS operating system source code like text.inc and font8x16.inc
http://bos.asmhackers.net/downloads.php
This is coming many many years later but I think it's still very relevant and if somebody is struggling I hope they can find it useful.
First of all, it is completely possible to configure VGA only using registers without interrupts, as hard as it may be. A useful resource about registers and how to configure them can be found here, but unless you have a ton of time to spare to learn how to properly do all of it, move to the following section.
If you wish to really learn how to do it, I suggest going through with the documentation provided earlier. However, some of it is already done!
Chris Giese did a great job demonstrating exactly how to do this for MS-DOS system, and while you may think that doesn't help you, it really does.
Chris's code can be found here. If you want another useful codes check here as well.
Now, while it only works for MS-DOS it's actually easy to convert to other systems. The code already contains all data needed to configure the registers in many different modes. And that's the part that saves you a ton of time going through documentation.
The code uses functions outportb, inportb, which are MS-DOS functions, to write/read single byte to/from a port. Therefore, you have to redefine these functions to read/write for your own system. Redefinition complexity depends on the system you operate on.
In addition, you will also need to provide means to write to physical memory region between 0xA0000-0xBFFFF which corresponds to standard VGA memory area. Once you have that allocated, you need to also redefine the functions pokeb pokew peekb which will help you output things (text or pixel data) on the screen.
One last note: the code is already defined to work with many different modes including both text and display modes.

Is it possible to get active window & executable names in X11/Xlib?

After looking at RescueTime for windows/mac, it seems that there's a version for linux but doesn't seem up to date. Also, it's the weekends and I want to spend time playing with X11..
I'm thinking of making a simple productivity-polling app, that every short interval polls the active windows, and intercepts (and passes along) mouse and keyboard presses to measure productivity.
Is this possible at all? After checking Xlib I'm at a loss on where to find the binary name of an executable. etc.
Finding the PID (and by extension the backing executable) in X isn't necessarily possible (due to the fact that the window might not even be owned by a process on your current box).
See Getting pid and details for topmost window or How to get an X11 Window from a Process ID? for a solution which might work in a limited set of cases (by querying for the _NET_WM_PID property).