Permalink
Browse files

Merge pull request #490 from fzurita/user_cheats_not_working

We are no longer ignoring country code when merging cheat files
  • Loading branch information...
xperia64 committed Oct 19, 2015
2 parents b29331f + 9a453ae commit ef222199a7a3e2d9b2e060ebdd065bc99b200bc6
@@ -121,29 +121,29 @@ protected void onCreate( Bundle savedInstanceState )
mRomCountryCode = extras.getByte( ActivityHelper.Keys.ROM_COUNTRY_CODE );
setContentView( R.layout.cheat_editor );
- reload( mRomCrc );
+ reload( mRomCrc, mRomCountryCode );
findViewById( R.id.imgBtnChtAdd ).setOnClickListener( this );
findViewById( R.id.imgBtnChtEdit ).setOnClickListener( this );
findViewById( R.id.imgBtnChtSave ).setOnClickListener( this );
findViewById( R.id.imgBtnChtInfo ).setOnClickListener( this );
getListView().setOnItemLongClickListener( this );
}
- private void reload( String crc )
+ private void reload( String crc, byte countryCode )
{
Log.v( "CheatEditorActivity", "building from CRC = " + crc );
if( crc == null )
return;
//Do this in a separate task since it takes longer
- ExtractCheatsTask cheatsTask = new ExtractCheatsTask(this, this, mAppData.mupencheat_default, crc);
+ ExtractCheatsTask cheatsTask = new ExtractCheatsTask(this, this, mAppData.mupencheat_default, crc, countryCode);
cheatsTask.execute((String) null);
//We don't extract user cheats in a separate task since there aren't as many
CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt, true );
userCheats.clear();
- userCheats.addAll( CheatUtils.populate( mRomCrc, usrcheat_txt, false, this ) );
+ userCheats.addAll( CheatUtils.populate( mRomCrc, mRomCountryCode, usrcheat_txt, false, this ) );
cheatListAdapter = new CheatListAdapter( this, userCheats );
setListAdapter( cheatListAdapter );
@@ -150,12 +150,15 @@ public static BufferedReader getCheatsLocation(String regularExpression, String
public static ArrayList<Cheat> populateWithPosition( BufferedReader startPosition,
- String crc, Context con )
+ String crc, byte countryCode, Context con )
{
CheatSection cheatSection;
try
{
- cheatSection = new CheatSection( crc, startPosition );
+ String countryString = String.format("%02x", countryCode).substring(0, 2);
+ String key = crc + "-C:" + countryString;
+
+ cheatSection = new CheatSection( key, startPosition );
}
catch (IOException e)
{
@@ -173,11 +176,11 @@ public static BufferedReader getCheatsLocation(String regularExpression, String
return populateCommon(cheatSection, crc, con);
}
- public static ArrayList<Cheat> populate( String crc, CheatFile mupencheat_txt,
+ public static ArrayList<Cheat> populate( String crc, byte countryCode, CheatFile mupencheat_txt,
boolean isSystemDefault, Context con )
{
-
- CheatSection cheatSection = mupencheat_txt.match( "^" + crc.replace( ' ', '-' ) + ".*" );
+ String countryString = String.format("%02x", countryCode).substring(0, 2);
+ CheatSection cheatSection = mupencheat_txt.match( "^" + crc.replace( ' ', '-') + "-C:" + countryString + ".*");
return populateCommon(cheatSection, crc, con);
}
@@ -297,11 +300,12 @@ public static BufferedReader getCheatsLocation(String regularExpression, String
public static void save(String crc, CheatFile mupencheat_txt, ArrayList<Cheat> cheats, String headerName,
byte countryCode, Context con, boolean isSystemDefault)
{
- CheatSection c = mupencheat_txt.match("^" + crc.replace(' ', '-') + ".*");
+ String countryString = String.format("%02x", countryCode).substring(0, 2);
+ CheatSection c = mupencheat_txt.match("^" + crc.replace(' ', '-') + "-C:" + countryString + ".*");
if (c == null)
{
// Game name and country code from header
- c = new CheatSection(crc.replace(' ', '-'), headerName, String.format("%02x", countryCode).substring(0, 2));
+ c = new CheatSection(crc.replace(' ', '-'), headerName, countryString);
mupencheat_txt.add(c);
}
@@ -298,7 +298,7 @@ private void refreshCheatsCategory()
if(mGamePrefs.isCheatOptionsShown)
{
ExtractCheatsTask cheatsTask = new ExtractCheatsTask(this, this, mAppData.mupencheat_txt,
- mRomCrc);
+ mRomCrc, mRomCountryCode);
cheatsTask.execute((String) null);
}
else
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import paulscode.android.mupen64plusae.cheat.CheatUtils;
+import paulscode.android.mupen64plusae.cheat.CheatFile.CheatSection;
import paulscode.android.mupen64plusae.cheat.CheatUtils.Cheat;
import android.content.Context;
import android.os.AsyncTask;
@@ -35,8 +36,8 @@
private final ExtractCheatListener mExtractCheatListener;
private final String mCheatPath;
private final String mCrc;
+ private final byte mCountryCode;
private final ArrayList<Cheat> mCheats;
-
public interface ExtractCheatListener
{
@@ -46,12 +47,13 @@
public ExtractCheatsTask( Context context, ExtractCheatListener extractCheatListener,
- String cheatPath, String crc)
+ String cheatPath, String crc, byte romCountryCode)
{
mContext = context;
mExtractCheatListener = extractCheatListener;
mCheatPath = cheatPath;
mCrc = crc;
+ mCountryCode = romCountryCode;
mCheats = new ArrayList<Cheat>();
}
@@ -71,7 +73,9 @@ private void buildCheatsCategory()
return;
// Get the appropriate section of the config file, using CRC as the key
- String regularExpression = "^" + mCrc.replace( ' ', '-' ) + ".*";
+
+ String countryString = String.format("%02x", mCountryCode).substring(0, 2);
+ String regularExpression = "^" + mCrc.replace( ' ', '-') + "-C:" + countryString + ".*";
BufferedReader cheatLocation = CheatUtils.getCheatsLocation(regularExpression, mCheatPath);
if( cheatLocation == null )
@@ -80,7 +84,7 @@ private void buildCheatsCategory()
return;
}
- mCheats.addAll( CheatUtils.populateWithPosition( cheatLocation, mCrc, mContext ) );
+ mCheats.addAll( CheatUtils.populateWithPosition( cheatLocation, mCrc, mCountryCode, mContext ) );
}
@Override

0 comments on commit ef22219

Please sign in to comment.