Skip to content

Commit

Permalink
fixed repetition, proto for anim ports
Browse files Browse the repository at this point in the history
  • Loading branch information
ermaccer authored Aug 18, 2019
1 parent 3c9a342 commit 7b39368
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 22 deletions.
164 changes: 145 additions & 19 deletions source/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@

void eHooks::Init()
{
CIniReader ini("mugenhook.ini");
CIniReader ini("");
bGameModeTagShow = ini.ReadBoolean("Settings", "bGameModeTagShow", 0);
bGameModeSingleHide = ini.ReadBoolean("Settings", "bGameModeSingleHide", 0);
bGameModeSimulHide = ini.ReadBoolean("Settings", "bGameModeSimulHide", 0);
bGameModeTurnsHide = ini.ReadBoolean("Settings", "bGameModeTurnsHide", 0);
bHookCursorTable = ini.ReadBoolean("Settings", "bHookCursorTable", 0);
bRandomStageConfirmSounds = ini.ReadBoolean("Settings", "bRandomStageConfirmSounds", 0);
bChangeStrings= ini.ReadBoolean("Settings", "bChangeStrings", 0);

iSelectableFighters = ini.ReadInteger("Settings", "iSelectableFighters", 0);

stage_group = ini.ReadInteger("Settings", "iRandomStageGroup", 0);
stage_max = ini.ReadInteger("Settings", "iRandomStageRandomMax", 0);

if (bChangeStrings)
{
Patch<const char*>(0x40ADD8 + 3, ini.ReadString("Strings", "szGameModeSingle", "Single"));
Patch<const char*>(0x40AE04 + 3, ini.ReadString("Strings", "szGameModeSimul", "Simul"));
Patch<const char*>(0x40AE5F + 3, ini.ReadString("Strings", "szGameModeTurns", "Turns"));
Patch<const char*>(0x40AE30 + 3, ini.ReadString("Strings", "szGameModeTag", "Tag"));

Patch<const char*>(0x42BD3B + 7, ini.ReadString("Strings","szKeyA","A"));
Patch<const char*>(0x42BD46 + 7, ini.ReadString("Strings","szKeyB","B"));
Patch<const char*>(0x42BD51 + 7, ini.ReadString("Strings","szKeyC","C"));
Expand All @@ -28,17 +35,24 @@ void eHooks::Init()
Patch<const char*>(0x407E73 + 1, ini.ReadString("Strings", "szSelectStage", "Stage %i: %s"));
}

if (iSelectableFighters)
Patch<int>(0x4063F0, iSelectableFighters);

if (bHookCursorTable)
{
eHooks::CursorTabMan::Init();
eHooks::CursorTabMan::ReadFile("cfg\\soundAnn.dat");
CursorTabMan::Init();
CursorTabMan::ReadFile("cfg\\soundAnn.dat");
//CursorTabMan::AnimatedPortaits::ReadFile("cfg\\animatedPortraits.dat");
Patch<char>(0x406E51, 0xE9);
Patch<int>(0x406E51 + 1, (int)eHooks::HookCursorSounds - ((int)0x406E51 + 5));
}


if (bGameModeTagShow) Patch<char>(0x40AE10, 6);
if (bGameModeSimulHide) Patch<char>(0x40ADE4, 4);
if (bGameModeSingleHide) Patch<char>(0x40ADC2, 4);
if (bGameModeTurnsHide) Patch<char>(0x40AE3C, 4);

}

void __declspec(naked) eHooks::HookCursorSounds()
Expand All @@ -49,23 +63,30 @@ void __declspec(naked) eHooks::HookCursorSounds()
add eax, 14864
pushad
}
// C0 p2
FoundEntry = CursorTabMan::FindSound(*(int*)(cursor_eax + 14864 + 16), *(int*)(cursor_eax + 14864));
FoundEntryp2 = CursorTabMan::FindSound(*(int*)(cursor_eax + 14864 + 0xC0 + 16), *(int*)(cursor_eax + 14864 + 0xC0));
// p1.cursor.done.snd, group
*(int*)(*(int*)Mugen_ResourcesPointer + 0x340) = cursorTable[FoundEntry].snd_group;
// p1.cursor.done.snd, value
*(int*)(*(int*)Mugen_ResourcesPointer + 0x348) = cursorTable[FoundEntry].snd_select;
// p1.cursor.done.snd, group
*(int*)(*(int*)Mugen_ResourcesPointer + 0x344) = cursorTable[FoundEntryp2].snd_groupp2;
// p1.cursor.done.snd, value
*(int*)(*(int*)Mugen_ResourcesPointer + 0x34C) = cursorTable[FoundEntryp2].snd_selectp2;
CursorTabMan::ProcessSelectScreen();
_asm {
popad
jmp cursor_jmp
}
}

void eHooks::PrintCharacterNames()
{
MugenCharacter* CharactersArray = *(MugenCharacter**)0x503394;
std::ofstream oFile("characters.txt", std::ofstream::binary);

if (CharactersArray)
{
for (int i = 0; i < row * column; i++)
{
std::string strName(CharactersArray[i].name, strlen(CharactersArray[i].name));
oFile << "Character: " << strName << " ID:" << std::to_string(CharactersArray[i].id) << std::endl;
}
}

}



void eHooks::CursorTabMan::Init()
{
Expand All @@ -78,9 +99,10 @@ void eHooks::CursorTabMan::Init()
if (line)
{
CIniReader system(line);
int row = system.ReadInteger("Select Info", "rows",0);
int column = system.ReadInteger("Select Info", "columns", 0);

row = system.ReadInteger("Select Info", "rows",0);
column = system.ReadInteger("Select Info", "columns", 0);
sscanf(system.ReadString("Select Info", "p1.cursor.done.snd", 0), "%d,%d", &select_default_grp, &select_default_sound);
sscanf(system.ReadString("Select Info", "p2.cursor.done.snd", 0), "%d,%d", &select_default_grp2, &select_default_sound2);
memSize = row * column;
}
}
Expand All @@ -89,7 +111,9 @@ void eHooks::CursorTabMan::Init()


cursorTable = std::make_unique<eCursorEntry[]>(memSize);
printf("CursorTabMan: Init, allocated %d\n", memSize * sizeof(eCursorEntry));
animTable = std::make_unique<ePortraitEntry[]>(memSize);
printf("CursorTabMan: Init allocated %d bytes\n", memSize * sizeof(eCursorEntry));
printf("Animated Portraits: Init allocated %d bytes\n", memSize * sizeof(ePortraitEntry));
}

void eHooks::CursorTabMan::ReadFile(const char * file)
Expand Down Expand Up @@ -135,9 +159,56 @@ void eHooks::CursorTabMan::ReadFile(const char * file)
}

}
printf("CursorTabMan: Found %d entities!\n", lastEntry + 1);
printf("CursorTabMan: Found %d entities!\n", lastEntry);
fclose(pFile);
}

}

void eHooks::CursorTabMan::ProcessSelectScreen()
{
FoundEntry = CursorTabMan::FindSound(*(int*)(cursor_eax + 14864 + 16), *(int*)(cursor_eax + 14864));
FoundEntryp2 = CursorTabMan::FindSound(*(int*)(cursor_eax + 14864 + 0xC0 + 16), *(int*)(cursor_eax + 14864 + 0xC0));


int PlayeroneSelected = (*(int*)(cursor_eax + 14592));
int PlayeroneSelectedTurns = (*(int*)(cursor_eax + 14592 + 36));
int PlayertwoSelected = (*(int*)(cursor_eax + 14592 + 4));
int PlayertwoSelectedTurns = (*(int*)(cursor_eax + 14592 + 36 + 116));
int PlayerTraining = (*(int*)(cursor_eax + 14864 + 24));



// fix for repeating turns/training/watch sounds

if (PlayertwoSelectedTurns == 0)
{
*(int*)(*(int*)Mugen_ResourcesPointer + 0x344) = cursorTable[FoundEntryp2].snd_groupp2;
*(int*)(*(int*)Mugen_ResourcesPointer + 0x34C) = cursorTable[FoundEntryp2].snd_selectp2;
}
else {
*(int*)(*(int*)Mugen_ResourcesPointer + 0x344) = select_default_grp2;
*(int*)(*(int*)Mugen_ResourcesPointer + 0x34C) = select_default_sound2;
}

if (PlayerTraining == 1)
{
*(int*)(*(int*)Mugen_ResourcesPointer + 0x340) = cursorTable[FoundEntry].snd_group;
*(int*)(*(int*)Mugen_ResourcesPointer + 0x348) = cursorTable[FoundEntry].snd_select;
}
else {
*(int*)(*(int*)Mugen_ResourcesPointer + 0x340) = select_default_grp;
*(int*)(*(int*)Mugen_ResourcesPointer + 0x348) = select_default_sound;
}



// we're at select screen anyway
if (bRandomStageConfirmSounds)
{
*(int*)(*(int*)Mugen_ResourcesPointer + 0x36C) = stage_group;
*(int*)(*(int*)Mugen_ResourcesPointer + 0x36C + 4) = rand() % stage_max;
}
}

int eHooks::CursorTabMan::FindSound(int row, int col)
Expand All @@ -155,3 +226,58 @@ int eHooks::CursorTabMan::FindSound(int row, int col)
}
return iFind;
}

void eHooks::CursorTabMan::AnimatedPortaits::ReadFile(const char * file)
{
FILE* pFile = fopen(file, "rb");
if (!pFile)
{
printf("CursorTabMan: Animated Portraits: ERROR: Could not open %s!\n", file);
}
if (pFile)
{
printf("CursorTabMan: Animated Portraits: Reading %s\n", file);
char line[1536];
while (fgets(line, sizeof(line), pFile))
{
// check if comment
if (line[0] == ';' || line[0] == '#' || line[0] == '\n')
continue;

int row_id = 0;
if (sscanf(line, "%d", &row_id) == 1)
{

int column_id = 0;
int maxframes = 0;
int frametime = 0;
sscanf(line, "%d %d %d %d", &row_id, &column_id, &maxframes, &frametime);

// create thing
ePortraitEntry ent;
ent.id_row = row_id;
ent.id_column = column_id;
ent.frametime = frametime;
ent.max_frames = maxframes;

animTable[lastAnim] = ent;
lastAnim++;
}

}
printf("CursorTabMan: Animated Portraits: Found %d entities!\n", lastAnim);
fclose(pFile);
}
}

int eHooks::CursorTabMan::AnimatedPortaits::DisplaySprites(int a1, int a2, int a3, int a4, int a5, float x, float y)
{
printf("%X %X %X %X %X %f %f\n", a1, a2, a3, a4, a5, x, y);
return ((int(__cdecl*)(int, int, int, int, int, float, float))0x411C00)(a1, a2, a3, a4,a5,x,y);
}

int eHooks::CursorTabMan::AnimatedPortaits::LoadSprites(int a1, int a2)
{
return ((int(__cdecl*)(int, int))0x467B30)(a1, a2);

}
49 changes: 46 additions & 3 deletions source/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ struct eCursorEntry {
int snd_selectp2;
};

struct ePortraitEntry {
int id_row;
int id_column;
int max_frames;
int frametime;
};

struct MugenCharacter {
int id;
int unknown;
char name[48];
char filename[512];
char foldername[512];
int unknown_2;
float scale;
};

namespace eHooks {

Expand All @@ -27,6 +43,21 @@ namespace eHooks {
static int FoundEntry;
static int FoundEntryp2;
static int Mugen_ResourcesPointer = 0x503388;
static int Mugen_CharactersPointer = 0x503394;
static int Mugen_DataPointer = 0x5040E8;


static int row, column;

// random stage sounds
static int stage_group;
static int stage_max;

// default sounds
static int select_default_grp;
static int select_default_sound;
static int select_default_grp2;
static int select_default_sound2;

// settings
static bool bGameModeTagShow;
Expand All @@ -35,15 +66,27 @@ namespace eHooks {
static bool bGameModeTurnsHide;
static bool bHookCursorTable;
static bool bChangeStrings;
static bool bRandomStageConfirmSounds;
static int iSelectableFighters;

static int lastEntry = 0;
static std::unique_ptr<eCursorEntry[]> cursorTable;

void Init();
static int lastAnim = 0;
static std::unique_ptr<eCursorEntry[]> cursorTable;
static std::unique_ptr<ePortraitEntry[]> animTable;
void Init();
void HookCursorSounds();
void PrintCharacterNames();


namespace CursorTabMan {
void Init();
void ReadFile(const char* file);
void ProcessSelectScreen();
namespace AnimatedPortaits {
void ReadFile(const char* file);
int DisplaySprites(int a1, int a2, int a3, int a4, int a5, float x, float y);
int LoadSprites(int a1, int a2);
}
int FindSound(int row, int col);
}
}

0 comments on commit 7b39368

Please sign in to comment.