Skip to content

Commit

Permalink
Add pak file
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Apr 5, 2016
1 parent b7d5a8c commit 0d7be1f
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
12 changes: 12 additions & 0 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="in.celest.xash3d.InstallReceiver">
<intent-filter android:priority="100">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>

</application>
</manifest>
7 changes: 5 additions & 2 deletions android/build-manual.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ ANDROID_JAR=../android-13.jar
AAPT=./../aapt
DX=./../dx
APKBUILDER=./../apkbuilder
NAME=mod
NAME=gravgun
mkdir bin
mkdir bin/classes
mkdir assets/
$AAPT package -M AndroidManifest.xml -m -S res -I $ANDROID_JAR
$JAVA_HOME/bin/javac -d bin/classes -s bin/classes -cp $ANDROID_JAR src/in/celest/xash3d/LauncherActivity.java
$JAVA_HOME/bin/javac -d bin/classes -s bin/classes -cp $ANDROID_JAR src/in/celest/xash3d/*
$DX --dex --output=bin/classes.dex bin/classes/
$AAPT package -f -M AndroidManifest.xml -S res -I $ANDROID_JAR -F bin/$NAME.apk.unaligned
python2 makepak.py pak/ assets/extras.pak
zip -r bin/$NAME.apk.unaligned assets/
$APKBUILDER bin/$NAME.apk -u -nf libs/ -rj libs -f bin/classes.dex -z bin/$NAME.apk.unaligned
#java -jar /mnt/app/apktool/signapk.jar /mnt/app/apktool/testkey.x509.pem /mnt/app/apktool/testkey.pk8 bin/$NAME.apk bin/$NAME-signed.apk
Binary file added android/pak/models/p_gravcannon.mdl
Binary file not shown.
Binary file added android/pak/models/v_gravcannon.mdl
Binary file not shown.
Binary file added android/pak/models/w_gravcannon.mdl
Binary file not shown.
Binary file added android/pak/models/w_gravcannont.mdl
Binary file not shown.
9 changes: 9 additions & 0 deletions android/pak/sprites/weapon_gravgun.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
8
weapon 320 320hud1 80 120 80 20
weapon_s 320 320hud1 80 140 80 20
ammo 320 320hud2 0 34 18 18
crosshair 320 crosshairs 72 48 24 24
weapon 640 640hud2 0 135 170 45
weapon_s 640 640hud5 0 135 170 45
ammo 640 640hud7 0 96 24 24
crosshair 640 crosshairs 72 48 24 24
14 changes: 14 additions & 0 deletions android/src/in/celest/xash3d/InstallReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package in.celest.xash3d;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class InstallReceiver extends BroadcastReceiver {
private static final String TAG = "MOD_LAUNCHER";
@Override
public void onReceive(Context context, Intent arg1) {
Log.d( TAG, "Install received, extracting PAK" );
LauncherActivity.extractPAK( context, true );
}
}
87 changes: 87 additions & 0 deletions android/src/in/celest/xash3d/LauncherActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.content.SharedPreferences;
import java.lang.reflect.Method;
import java.io.FileOutputStream;
import java.io.File;
import java.io.InputStream;
import android.content.Context;
import android.util.Log;

public class LauncherActivity extends Activity {
private static final int PAK_VERSION = 1;
static Boolean isExtracting = false;
static EditText cmdArgs;
static SharedPreferences mPref;
private static final String TAG = "MOD_LAUNCHER";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -51,6 +60,7 @@ public void onClick(View v) {
launcher.addView(startButton);
setContentView(launcher);
mPref = getSharedPreferences("mod", 0);
extractPAK(this, false);
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
}

Expand All @@ -68,6 +78,83 @@ public void startXash(View view)
// Uncomment to set gamedir here
// intent.putExtra("gamedir", "mod" );
intent.putExtra("gamelibdir", getFilesDir().getAbsolutePath().replace("/files","/lib"));
intent.putExtra("pakfile", getFilesDir().getAbsolutePath() + "/extras.pak" );
startActivity(intent);
}
private static int chmod(String path, int mode) {
int ret = -1;
try
{
ret = Runtime.getRuntime().exec("chmod " + Integer.toOctalString(mode) + " " + path).waitFor();
Log.d(TAG, "chmod " + Integer.toOctalString(mode) + " " + path + ": " + ret );
}
catch(Exception e)
{
ret = -1;
Log.d(TAG, "chmod: Runtime not worked: " + e.toString() );
}
try
{
Class fileUtils = Class.forName("android.os.FileUtils");
Method setPermissions = fileUtils.getMethod("setPermissions",
String.class, int.class, int.class, int.class);
ret = (Integer) setPermissions.invoke(null, path,
mode, -1, -1);
}
catch(Exception e)
{
ret = -1;
Log.d(TAG, "chmod: FileUtils not worked: " + e.toString() );
}
return ret;
}

private static void extractFile(Context context, String path) {
try
{
InputStream is = null;
FileOutputStream os = null;
is = context.getAssets().open(path);
File out = new File(context.getFilesDir().getPath()+'/'+path);
out.getParentFile().mkdirs();
chmod( out.getParent(), 0777 );
os = new FileOutputStream(out);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
os.close();
is.close();
chmod( context.getFilesDir().getPath()+'/'+path, 0777 );
} catch( Exception e )
{
Log.e( TAG, "Failed to extract file:" + e.toString() );
e.printStackTrace();
}

}

public static void extractPAK(Context context, Boolean force) {
if(isExtracting)
return;
isExtracting = true;
try {
if( mPref == null )
mPref = context.getSharedPreferences("mod", 0);
if( mPref.getInt( "pakversion", 0 ) == PAK_VERSION && !force )
return;
extractFile(context, "extras.pak");

SharedPreferences.Editor editor = mPref.edit();
editor.putInt( "pakversion", PAK_VERSION );
editor.commit();
editor.apply();
} catch( Exception e )
{
Log.e( TAG, "Failed to extract PAK:" + e.toString() );
}
isExtracting = false;
}

}

0 comments on commit 0d7be1f

Please sign in to comment.