Friday, December 12, 2014

How to Sign Steam Dylib for Mac OS X in XCode


codesign --no-strict --verbose --force --sign "Developer ID Application" libsteam_api.dylib

Saturday, November 22, 2014

Clear Application Data with ADB at the command line

You can use package manager (pm) to clear data for installed apps (same as pressing the 'clear data' button in the app settings on your device).

Run this adb command, replacing 'com.company.games.game' with your package name from AndroidManfiest.xml

adb shell pm clear com.company.games.game

This method depends on the 'pm' tool being resident on the Android device, which is not always the case.

Thursday, November 20, 2014

Cocos2d-x v2.2 Fullscreen Linux Support

Add this method to CCEGLView.cpp and CCEGLView.h

void CCEGLView::setFrameSize(float width, float height, bool fullscreen)
{
bool eResult = false;
int u32GLFWFlags = GLFW_WINDOW;
if(fullscreen) {
u32GLFWFlags = GLFW_FULLSCREEN;
}
//create the window by glfw.
//check
CCAssert(width!=0&&height!=0, "invalid window's size equal 0");
//Inits GLFW
eResult = glfwInit() != GL_FALSE;
if (!eResult) {
CCAssert(0, "fail to init the glfw");
}
if(fullscreen) {
GLFWvidmode desktopMode;
glfwGetDesktopMode(&desktopMode);
CCLog("W: %d", (int)desktopMode.Width);
CCLog("H: %d", (int)desktopMode.Height);
height = (int)desktopMode.Height;
width = (int)desktopMode.Width;
}
/* Updates window hint */
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
int iDepth = 16; // set default value
/* Depending on video depth */
switch(iDepth)
{
/* 16-bit */
case 16:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 5, 6, 5, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false;
break;
}
/* 24-bit */
case 24:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 8, 8, 8, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false;
break;
}
/* 32-bit */
default:
case 32:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 8, (int)u32GLFWFlags) != GL_FALSE) ? true :false;
break;
}
}
/* Success? */
if(eResult)
{
glfwSetWindowSize(width, height);
// Move window to the upper left corner.
glfwSetWindowPos(0, 0);
glfwEnable(GLFW_MOUSE_CURSOR);
/* Updates actual size */
// glfwGetWindowSize(&width, &height);
CCEGLViewProtocol::setFrameSize(width, height);
/* Updates its title */
glfwSetWindowTitle("Cocos2dx-Linux");
//set the init flag
bIsInit = true;
//register the glfw key event
glfwSetKeyCallback(keyEventHandle);
//register the glfw char event
glfwSetCharCallback(charEventHandle);
//register the glfw mouse event
glfwSetMouseButtonCallback(mouseButtonEventHandle);
//register the glfw mouse pos event
glfwSetMousePosCallback(mousePosEventHandle);
//register the glfw keyboard event
glfwSetKeyCallback(keyboardEventHandle);
glfwSetWindowCloseCallback(closeEventHandle);


//Inits extensions
eResult = initExtensions();
if (!eResult) {
CCAssert(0, "fail to init the extensions of opengl");
}
initGL();
}
}

Tuesday, November 04, 2014

Android Lollipop Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)

Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)


  Index: Cocos2dxMusic.java
  ===================================================================
  --- Cocos2dxMusic.java (revision 21981)
  +++ Cocos2dxMusic.java (working copy)
  @@ -110,12 +110,12 @@
        Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic: background media player is null");
      } else {
        // if the music is playing or paused, stop it
  - this.mBackgroundMediaPlayer.stop();
  + //this.mBackgroundMediaPlayer.pause();
   
        this.mBackgroundMediaPlayer.setLooping(isLoop);
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + //this.mBackgroundMediaPlayer.prepare();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();
   
  @@ -129,6 +129,9 @@
    public void stopBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
        this.mBackgroundMediaPlayer.stop();
  + this.mBackgroundMediaPlayer.release();
  + this.mBackgroundMediaPlayer = null;
  + this.mCurrentPath = null;
   
        // should set the state, if not, the following sequence will be error
        // play -> pause -> stop -> resume
  @@ -152,10 +155,9 @@
   
    public void rewindBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
  - this.mBackgroundMediaPlayer.stop();
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + this.mBackgroundMediaPlayer.pause();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();
 

Sunday, August 10, 2014

NullPointerException at android.widget.ArrayAdapter.createViewFromResource


Crashes while using code like this:

AlertDialog.Builder builder = new AlertDialog.Builder(StatusMenuConflicts.this);
builder.setTitle("Star Traders RPG");
builder.setIcon(R.drawable.icon);
final String[] items = new String[6];
items[0] = getString(R.string.status);

The stack trace won't contain your code.

 java.lang.NullPointerException
        at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
        at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
        at android.widget.AbsListView.obtainView(AbsListView.java:1435)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1288)
        at android.widget.ListView.onMeasure(ListView.java:1199)
        at android.view.View.measure(View.java:8322)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
        at android.view.View.measure(View.java:8322)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
        at com.android.internal.widget.WeightedLinearLayout.onMeasure(WeightedLinearLayout.java:60)
        at android.view.View.measure(View.java:8322)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
        at android.view.View.measure(View.java:8322)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
        at android.view.View.measure(View.java:8322)
        at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
        at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3806)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)

The problem is that Android is looking for 6 elements in the Array you're passing in, but you've only defined one. Set the length of you String[] correctly and the code will work.

Friday, August 08, 2014

Interviews -- Reverse Singly Linked List, C++

Just seriously struggled through an interview on the phone. It's always the simple programming problems that seem the hardest when someone is watching you do it.

The question was "Write a simple function to reverse a linked list" and I couldn't get it right until 3 minutes after the interview was over. Every. Single. Time.

So here is the code I ended up with, given this basic Linked list.

struct List {
   int value;
   mySingleLinked* next;
};

Seems simple, right? See the comments ;)

// arg. i'm an idiot
List reverseLinkedList(List* head) {
    List *tempList, *nextList;

tempList = 0;
nextList = 0;

while (head != 0)
{
nextList = head->next;
head->next = tempList;
tempList = head;
head = nextList;
}
return tempList;
}

Wednesday, February 05, 2014

Quick AES Encrypt String with Botan C++

AutoSeeded_RNG rng;
SymmetricKey key(rng, 16); // a random 128-bit key
InitializationVector iv(rng, 16); // a random 128-bit IV
Pipe pipe(get_cipher("AES-128/CBC", key, iv, ENCRYPTION), new Hex_Encoder);
pipe.process_msg("secrets");
std::string m1 = pipe.read_all_as_string(0);
Pipe pipe2(new Hex_Decoder, get_cipher("AES-128/CBC", key, iv, DECRYPTION));
pipe2.process_msg(m1.c_str());
std::string m2 = pipe2.read_all_as_string(0);

Saturday, January 18, 2014

How to Screen Record Android Video

Launch into the command line with your Android 4.4 device connected to your computer and enter the command to record your screen:
adb shell screenrecord /sdcard/demo.mp4
You can further customize the speed at which it captures video, the length of time it records (the default duration is 3-minutes) and the size of the video in terms of resolution.
Another example of a command to record a video would be:
adb shell screenrecord --bit-rate 8000000 --time-limit 30 /sdcard/kitkat.mp4
The above command would record at 8Mbps, instead of the default 4Mbps, for a duration of 30-seconds and save it to the SD Card on your device with the name of KitKat. You can find a full list of commands for screenrecord here on the Android Developer Site.