Skip to content

Instantly share code, notes, and snippets.

@odanado
Created August 3, 2020 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odanado/e778fc77f980c891904f2b1e612f71b0 to your computer and use it in GitHub Desktop.
Save odanado/e778fc77f980c891904f2b1e612f71b0 to your computer and use it in GitHub Desktop.
cal_offset.cpp
#include<cstdio>
typedef unsigned long long UInt64;
typedef unsigned int UInt32;
UInt64 seed1 = 0xC6942472D331BF96;
UInt64 LCGseed;
int offset;
const int Probability_Table[6][5] ={ /*謎の確率テーブル*/
{ 50,100,100,100,100 },
{ 50, 50,100,100,100 },
{ 30, 50,100,100,100 },
{ 25, 30, 50,100,100 },
{ 20, 25, 33, 50,100 },
{ 100,100,100,100,100 } } ;
void init_LCGseed();
UInt64 next_LCGseed(UInt64 _seed);
void PT(int n);
void Extra();
void BW1_offset(bool continueFlag,bool saveFlag);
void BW2_offset(bool continueFlag,bool saveFlag,bool linkFlag);
int main()
{
while (true)
{
int n;
offset = 0;
printf("seed1=");
scanf("%I64X",&seed1);
printf("seed1=%I64X\n",seed1);
printf("BW1?BW2?(1 or 2):");
scanf("%d",&n);
if (n==1)
{
printf("\n・最初からはじめた時\n");
BW1_offset(0,0);
BW1_offset(0,1);
printf("・続きからはじめた時\n");
BW1_offset(1,1);
}
else if (n==2)
{
printf("\n・最初からはじめた時\n");
BW2_offset(0,0,0);
BW2_offset(0,1,0);
BW2_offset(0,1,1);
printf("・続きからはじめた時\n");
BW2_offset(1,0,0);
BW2_offset(1,0,1);
}
else
{
printf("BW%d???\n\n",n);
}
}
return 0;
}
void init_LCGseed()
{
offset = 0;
LCGseed = seed1;
}
UInt64 next_LCGseed()
{
offset++;
LCGseed = LCGseed * 0x5D588B656C078965 + 0x269EC3;
return (LCGseed);
}
void PT(int _n)
{
/* n回 PTを実行 */
for (int k = 0; k < _n; k++)
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 5; j++)
{
if(Probability_Table[i][j] == 100)
{
/* 確率が100なら、次の行へ */
break;
}
int R = ((next_LCGseed()>>32)*101)>>32;
if (R <= Probability_Table[i][j])
{
/* 取得した確率がテーブルの位置の値以下なら次の行へ */
break;
}
}
}
}
}
void Extra()
{
while (true)
{
int R1 = (((next_LCGseed())>>32)*15)>>32;
int R2 = (((next_LCGseed())>>32)*15)>>32;
int R3 = (((next_LCGseed())>>32)*15)>>32;
if (!(R1==R2 || R2==R3 || R3==R1))
{
break;
}
}
}
void BW1_offset(bool continueFlag,bool saveFlag)
{
init_LCGseed();
if (continueFlag)
{
PT(5);
printf("offset = %d\n\n",offset);
}
else
{
if (saveFlag)
{
PT(2);
}
else
{
PT(3);
}
UInt32 PID = next_LCGseed()>>32;
/* チラーミィ用のIDらしい */
next_LCGseed();
UInt64 R = next_LCGseed();
UInt32 TID = (((R>>32)*0xFFFFFFFF)>>32)&0xFFFF;
UInt32 SID = (((R>>32)*0xFFFFFFFF)>>48)&0xFFFF;
if (saveFlag)
{
printf("セーブデータあり\n");
}
else
{
printf("セーブデータなし\n");
}
printf("TID:%d,SID:%d\n",TID,SID);
printf("PID:%08X\n",PID);
printf("offset = %d\n\n",offset);
if (!saveFlag)
{
next_LCGseed();
}
PT(4);
/*
この先にブラックシティの住人の消費があるらしい
13人選ぶらしいので、この時点での、変数offsetの値+13?
セーブデータありの実機で御三家受け取ると、offset+13の位置の性格を受け取った
95AB34D68227C56C なら ようき
*/
/* printf("offset = %d\n\n",offset+13); */
}
}
void BW2_offset(bool continueFlag,bool saveFlag,bool linkFlag)
{
init_LCGseed();
if (continueFlag)
{
PT(1);
if (linkFlag)
{
printf("思い出リンクあり\n");
next_LCGseed();
next_LCGseed();
}
else
{
printf("思い出リンクなし\n");
next_LCGseed();
next_LCGseed();
next_LCGseed();
}
PT(4);
Extra();
printf("offset = %d\n\n",offset);
}
else
{
int n1,n2;
if (saveFlag)
{
if (linkFlag)
{
n1 = 2;
}
else
{
n1 = 3;
}
n2 = 2;
}
else
{
n1 = 2;
n2 = 4;
}
PT(1);
for (int i = 0; i < n1; i++)
{
next_LCGseed();
}
PT(1);
for (int i = 0; i < n2; i++)
{
next_LCGseed();
}
if (saveFlag)
{
UInt32 PID = next_LCGseed()>>32;
/* チラーミィ用のIDらしい */
/* 影響無いらしいから、xorとか抜かしてもいいよね・・・? */
next_LCGseed();
UInt64 R = next_LCGseed();
UInt32 TID = (((R>>32)*0xFFFFFFFF)>>32)&0xFFFF;
UInt32 SID = (((R>>32)*0xFFFFFFFF)>>48)&0xFFFF;
printf("セーブデータあり\n");
if (linkFlag)
{
printf("思い出リンクあり\n");
}
else
{
printf("思い出リンクなし\n");
}
printf("TID:%d,SID:%d\n",TID,SID);
printf("PID:%08X\n",PID);
printf("offset = %d\n\n",offset);
}
else
{
PT(1);
next_LCGseed();
next_LCGseed();
UInt32 PID = next_LCGseed()>>32;
/* チラーミィ用のIDらしい */
/* 影響無いらしいから、xorとか抜かしてもいいよね・・・? */
next_LCGseed();
UInt64 R = next_LCGseed();
UInt32 TID = (((R>>32)*0xFFFFFFFF)>>32)&0xFFFF;
UInt32 SID = (((R>>32)*0xFFFFFFFF)>>48)&0xFFFF;
printf("セーブデータなし\n");
printf("TID:%d,SID:%d\n",TID,SID,offset);
printf("PID:%08X\n",PID);
printf("offset = %d\n\n",offset);
}
}
}
/*
* 参考
* http://rusted-coil.squares.net/pokemon/ran/ran_2.htm
* http://note.chiebukuro.yahoo.co.jp/detail/n166836
* バトルサブウェイ乱数補助ツール
* offsetKeisanのソースコード
* プラスルツールのソースコード
*
*/
/*
*
* 製作:odan
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment