Sunday, February 28, 2010

Estimating The Cost of Game Piracy

The Motivation

A few years ago we had an idea on how to create a fairly hard to crack DRM.
Coming from a security background (among other things) we knew what most people in the field know - All defenses can be breached. It is simply a matter of resources.
In the case of game copy protection we knew that there are considerable resources invested by hackers and crackers to break copy protection. A good[1] copy protection can buy whoever is using it a few months at most. We figured that if we can make a sufficiently flexible and complex copy protection we can buy about 6 months for a given game before the protection is broken.
To see if this was a worthwhile cause we wanted to know what is the real value of a good copy protection. We also wanted to know if the 6 months we believed we can get would be good enough[2].

I believe that the value of a good copy protection should be the number of additional copies of a given game that would be sold if the game cannot be copied minus the number of copies that would have been sold if those resources would have gone to improving the game (or investing in marketing - in other words - the alternative cost).

It is very hard to say how many copies of a game could be sold if some additional funds are put into any aspect of making a game. It is also very hard to tell how much is lost due to the additional inconvenience introduced by some of the more intrusive protections[3].

On the other hand it might be possible to find out how many games could be sold if there was an unhackable copy protection.

Looking For Numbers

In my quest for numbers i ran a search to see if there were any research that could reasonably estimate how many copies of a given game could have been sold had it been protected.
Unfortunately none were available. What i found was plenty of articles citing the BSA and IIPA for pirated software numbers and estimates for the loss of income due to those pirated copies.
This might be considered good evidence but after taking a more in depth look at the numbers and methodology i decide i don't really trust the results (i might go more into that in a seperate article - but i am certainly not the first to question those surveys) .

I also found this very comprehensive article about game piracy in general. I recommend it to anyone who wants to get a good understanding of the different aspects of game piracy.

So the question remained - How do you measure the actual loss due to piracy?
If you want to compare things, finding something that is reasonably similar is a good start.
Like The Economist's Big Mac Index - you want a product that is arguably of the same quality, make, reputation etc' as possible if you want to make a good comparison.
I think that i found such a product for piracy loss research - Cross platform titles.

A Different Approach

There are two[4] 7th generation consoles on the market - Microsoft's Xbox 360 and Sony's Playstation 3.
These consoles are arguably[5] the same in terms of interface, level of graphics and the type quality and number of titles released for these consoles.
The Xbox 360 has been hacked many years ago (i think sometime in 2006).
The Ps3 on the other hand had not yet been hacked. Sony has made considerable efforts in securing the PS3 and so far - 4 years and counting - The PS3 had not been hacked.
My argument is that since the Xbox 360 had been hacked and the PS3 had not been hacked, the difference in sales of various titles should reflect the loss of revenue due to piracy.

In recent years more and more titles are being released to both consoles. These games constitute a comparable (identical?) product. Most cross platform titles look the same on both consoles, distributed enjoy the same publishing houses, have the same level of publicity and the same kind of gameplay, story and whatever other aspect you may choose to consider. They are also - for the most part (and for all games considered in this research) - released at the same time.

A good comparison should consider alternative or competing products. This aspect is much harder to account for. I cannot accurately or reasonably claim that it doesn't make any difference or that i can accurately measure or correct for it. I hope i can reasonably persuade you that it is of reduced importance because of two things:
1. If you look at the current (at the time of writing) top sellers lists of both the Xbox 360 and the PS3 you'll find that 5 of the top 10 sellers on the PS3 lists are cross platform titles (3 of them are the top sellers) and 6 of the top 10 sellers for the Xbox 360 are also cross platform.
2. To further reduce the impact of console specific titles on the overall numbers i tried to include as many games as i could find in the research.

Still, I acknowledge that competing exclusive titles have an impact on the overall results. But i think the numbers themselves demonstrate that this impact is not likely to be too significant.

Correcting For Console Sales Difference

The final significant difference between the consoles is the numbers of consoles sold.
Currently Wikipedia (no. for dec 2009) cites 33.5 million PS3 consoles sold vs. 39 million Xbox 360 consoles sold. For the sake of transparency i am showing the adjusted and unadjusted numbers.
It should be noted that without correcting for the number of consoles sold, the total number of copies sold from all titles i looked at are significantly higher on the xbox 360.

Commutative unadjusted game sales for 56 leading titles by console (unadjusted):
Without correcting by the number of consoles sold there is a predictably higher number of copies sold on the Xbox 360.

The Commutative game sales from 56 leading titles by console, adjusted by the number of consoles sold:
As you can see - once we adjust to the number of consoles soled the commutative number of copies sold is almost identical. The green line at the bottom shows the difference between the consoles.

Estimating The Cost Of Piracy

The following graph shows the ratio of adjusted PS3 sales and Xbox360 sales.
I believe that part of this ratio can, at least in part, be explained by piracy.

According to these results the estimated loss due to piracy is around 5-10%.
However it should be noted that this is the case if (and its a huge IF) all of the difference between the sales of these titles between consoles is solely due to piracy.
There are many other factors that may effect game sales.
If we make the assumption that game piracy incurs a significant loss and is by far the most significant possible factor effecting sales of these titles between consoles than this number may be accurate.

Personally i do not believe this to be the case. I believe that there are so many possible different contributing factors to the differences in sales between consoles that they must contribute (positively or negatively) to the sales of games between consoles.
In other words - i do not believe that there is enough of a difference in the number of copies sold to reasonably claim that piracy incurs a measurable loss on game sales.

[1] - Good at being a copy protection. The most successful copy protections tend to be pretty evil in what they actually do.
[2] - We were wrong btw. it seems that games sell mostly during the 2 months before Christmas. This is probably why many releases are targeted around that time.
[3] - Sony BMG's care is perhaps the most famously intrusive and destructive of those.
[4] - Well, Nintendo would have you believe that there are 3 but you can't really compare the level of graphics or the gameplay in Wii to the other consoles. Xbox360 and PS3 are consoles for gamers. Wii is the casual gamer console. You also can't reasonably claim that the titles released to the Xbox 360 and Ps3 are the same as the ones released on the Wii.
[5] - This is the subject of many arguments. For the sake of full disclosure i own an Xbox 360. I (no longer) claim it has better graphics than the PS3. Only that it both consoles are practically the same.

This is the list of title's whose sales numbers i used:
Army of Two
Assassin's Creed
Bad Company
Bound in Blood
Brutal Legend
Burnout Paradise
Dark Sector
Dead Space
Devil May Cry 4
DiRT 2
Fallout 3
Far Cry 2
FIFA Soccer 09
FIFA Soccer 10
Fight Night Round 3
Fight Night Round 4
Grand Theft Auto IV
Guitar Hero III
Hell's Highway
Los Angeles
Madden NFL 09
Madden NFL 10
Mirror's Edge
Modern Warfare 2
Modern Warfare
Mortal Kombat vs DC Universe
Need for Speed Carbon
PES 2009
Prince of Persia
Project Origin
Saints Row 2
Sid Meier's Civilization Revolution
Sonic Unleashed
SoulCalibur IV
Street Fighter IV
Tales of Vesperia
The Force Unleashed
The Simpsons Game
Tiger Woods PGA Tour 09
Top Spin 3
World at War
World in Flames
World Tour
WWE SmackDown vs Raw 2009
WWE SmackDown vs. Raw 2010

Wednesday, February 17, 2010

Aspect Based INotifyPropertyChanged Implementation

There are quite a few articles floating around about how to implement an aspect oriented version of INotifyPropertyChanged Interface.
My version is based on an article by Tamir Khason Posted on CodeProject.

The original version had some problems - placing the Attribute on both a Parent and Child class caused an exception to be thrown and because the interface was implemented at compile time by PostSharp* it could not be used without an unsafe cast.

My version requires that the class implement the interface directly, adds an interface that reports which property that also provides the pre-change value (useful when you want to save undo for example) and checks with any implementing class to see if anyone is registered (and skips all other checks if no one is listening...). We then check to see if there's any modification and only fire notification on change - this might not be the required behavior in all cases so the check can be easily removed.

So, performance is probably better, usage is pretty straight forward - implement INotifyPropertyChanged and IFirePropertyChanged and mark your class with the NotifyPropertyChanged attribute.
If this is implemented on a base class all children will also fire modification notification on all properties. I am adding a sample base class implementation as well.
Any class that extends this base class gets a free change notification for all properties.

Example Base Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoPropertyChangedWiring;
using System.ComponentModel;

namespace AutoPropertyChanged
/// <summary>
/// base class for any class that wishes to get INofityPropertyChanged for "free"
/// any class that extends this base class will get a PropertyChanged events, auto-implemented for all properties
/// </summary>
public abstract class PropertyChangeNotifier : INotifyPropertyChanged, IFirePropertyChanged
public event PropertyChangedEventHandler PropertyChanged;

public void FirePropertyChanged(string propertyName, object oldValue)
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));

public bool HasPropertyListeners
if (PropertyChanged == null)
return false;
return true;

Aspect Implementation and base class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using PostSharp.Extensibility;
using PostSharp.Laos;

namespace AutoPropertyChangedWiring {

public interface IFirePropertyChanged
void FirePropertyChanged(String propertyName,Object oldValue);
Boolean HasPropertyListeners{get;}
[Serializable, AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = false, Inherited = true),
MulticastAttributeUsage(MulticastTargets.Class, AllowMultiple = false, Inheritance = MulticastInheritance.Strict, AllowExternalAssemblies = true)]
public sealed class NotifyPropertyChangedAttribute : CompoundAspect {
public int AspectPriority { get; set; }

public override void ProvideAspects(object element, LaosReflectionAspectCollection collection) {
Type targetType = (Type)element;
foreach (var info in targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(pi => pi.GetSetMethod() != null)) {
collection.AddAspect(info.GetSetMethod(), new NotifyPropertyChangedAspect(info.Name) { AspectPriority = AspectPriority });

internal sealed class NotifyPropertyChangedAspect : OnMethodBoundaryAspect {
private readonly string _propertyName;
private object oldValue;
private Boolean fireEvent;
public NotifyPropertyChangedAspect(string propertyName) {
if (string.IsNullOrEmpty(propertyName)) throw new ArgumentNullException("propertyName");
_propertyName = propertyName;

public override void OnEntry(MethodExecutionEventArgs eventArgs) {
var instance = eventArgs.Instance as IFirePropertyChanged;
fireEvent = true;
//check if anyone is listening.
if (!instance.HasPropertyListeners)
//no one is listening, no point in moving on.
fireEvent = false;
return; //no need for the other checks

var targetType = eventArgs.Instance.GetType();
var setSetMethod = targetType.GetProperty(_propertyName);
if (setSetMethod == null) throw new AccessViolationException();
oldValue = setSetMethod.GetValue(eventArgs.Instance,null);
var newValue = eventArgs.GetReadOnlyArgumentArray()[0];

if (IsEqual(oldValue,newValue)) //nothing changed, nothing to do..
eventArgs.FlowBehavior = FlowBehavior.Return;
protected static Boolean IsEqual(Object left, Object right)
//both are null == both are equal.
if (left == null && right == null)
return true;

//at least one is not null, if its left - lets use it for the "Equals" method.
if (left != null)
return left.Equals(right);
else //left is null, but both are not null - which means right is not null and they are not equal.
return false;
public override void OnSuccess(MethodExecutionEventArgs eventArgs) {
if (!fireEvent)
return; //no need to fire the event.
var instance = eventArgs.Instance as IFirePropertyChanged;



* - This probably goes without saying - Using aspects requires Postsharp to be installed (v1.5)

Monday, February 15, 2010

Simple Technologies For Better Car Safety

I've been thinking about car accidents recently, or rather, about ways to prevent them.
I believe that at some point in the coming decades cars or whatever form of personalized transport we use will be fully computerized. Ultimately i do not think that regular public transportation will ever replace personalized transportation, but i do think we might have some form of automated point to point mass transportation system.

There are many different technologies currently being developed in the area of driving assistance, and some systems have even been implemented. Usually the way this works is that advancements are first implemented in luxury cars, and some of these technologies eventually become more widespread.
Some of these advancements involve various driving assistance systems, systems that "see" the road and can provide warnings and braking assistance in case the driver gets too close.

These technologies have a long way to go before they can be truly effective in preventing car accidents in common road cars. But i think that it is possible to implement some simpler technologies that may help us get closer to this future, and help us reduce car accidents in all cars.

Enhanced Brake Warning:
The first idea is to implement a slightly more sophisticated brake light system.
Current braking lights are pretty much boolean - on or off.
I think it shouldn't bee too complicated to have levels - say 3 levels (maybe even three lights) indicating "slow" brake "medium" brake and "hard" brake.
Modern cars have computers that control and monitor many of the car and engine functions, it shouldn't be too hard to implement a system that controls the brake light by the actual deceleration of the car instead of their current boolean implementation.
Why will this help? The way things work at the moment, when you see a brake light you don't know how quickly and how hard you need to brake. Your brain has to watch the car ahead and calculate the deceleration before you can decide how hard to brake. I think this period of time can be reduced and help prevent or reduce the damage in many accidents.

Inter-Car Signaling:
The Second idea is a little more complicated, but still in the not-too-hard category.
There are various radar and vision based technologies used to measure the distance and velocity of nearby vehicles. These are pretty expensive at the moment and don't work well enough to depend on.
It should be relatively cheap to implement the following:
If a standardized radio transmitter , broadcasting a low power signal with a known, well defined (and fixed) frequency and power. It should be relatively simple (and cheap) to roughly determine the distance between a receiver and a near by source. The idea is to optimize such a system to detect the distance between the receiver - your car - and the transmitter of the car ahead of you, behind you, and in your general area. to be affective and reduce interference the signal should be relatively weak and pretty directional.
By placing the transmitters in the corners of the car and designating a specific signature for each transmitter, it is possible to get a pretty good idea of the relative position of adjacent cars.
If we also broadcast the speed of the car using these transmitters we can very accurately know if a car ahead of us is braking, if there might be a car coming fast in our direction when crossing an intersection.

It should be pretty cheap to manufacture if standardized, and more importantly if mandated by governments. this kind of device can be easily installed on existing cars.
The system can be used for anything from advanced warnings for dangerous situations to actively engaging the brakes in dangerous situations - this last option would probably be only applicable to computer controlled cars.

I believe that the future of transportation is in more advanced version of computer controlled transportation. I think that computer controlled transportation can be far more efficient in traffic direction and possibly make car accidents a thing of the past.