Skip to content

Commit

Permalink
only save ip/port changes if actually changed, reconnect fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftyBoss committed Jul 10, 2022
1 parent 4f2bb98 commit 3c4a20a
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 103 deletions.
8 changes: 5 additions & 3 deletions include/Keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Keyboard {
return nullptr;
};

bool isKeyboardCancelled() const { return mIsCancelled; }

bool isThreadDone() { return mThread->isDone(); }

void setHeaderText(const char16_t* text) { mHeaderText = text; }
Expand All @@ -35,13 +37,13 @@ class Keyboard {
al::AsyncFunctorThread* mThread;
nn::swkbd::String mResultString;

bool mIsDoneKeyboard;

sead::FixedSafeString<0x10> mInitialText;
KeyboardSetup mSetupFunc;

const char16_t *mHeaderText = u"Enter Server IP Here!";
const char16_t *mSubText = u"Must be a Valid Address.";
const char16_t* mSubText = u"Must be a Valid Address.";

bool mIsCancelled = false;

char* mWorkBuf;
int mWorkBufSize;
Expand Down
2 changes: 1 addition & 1 deletion include/SocketBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SocketBase {

const char *getStateChar();
u8 getLogState();
s32 getSocket();
s32 getFd();

void set_sock_flags(int flags);

Expand Down
2 changes: 2 additions & 0 deletions include/game/StageScene/StageSceneStateServerConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class StageSceneStateServerConfig : public al::HostStateBase<al::Scene>, public
void exeGamemodeConfig();
void exeGamemodeSelect();
void exeSaveData();
void exeConnectError();

void endSubMenu();

Expand Down Expand Up @@ -84,4 +85,5 @@ namespace {
NERVE_HEADER(StageSceneStateServerConfig, GamemodeConfig)
NERVE_HEADER(StageSceneStateServerConfig, GamemodeSelect)
NERVE_HEADER(StageSceneStateServerConfig, SaveData)
NERVE_HEADER(StageSceneStateServerConfig, ConnectError)
}
53 changes: 22 additions & 31 deletions include/nn/swkbd/swkbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

#include <cstdint>
#include <cstdlib>
#include "types.h"
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef unsigned char uchar;

namespace nn
{
namespace nn {

namespace applet {
enum ExitReason {
Normal = 0,
Canceled = 1,
Abnormal = 2,
Unexpected = 10
};
}

namespace swkbd
{
enum Preset
Expand Down Expand Up @@ -103,40 +113,18 @@ namespace nn
Max_DictionaryLang
};

enum CloseResult
{
Enter,
Cancel
};

struct DictionaryInfo
{
uint offset; // 0x0
ushort size; // 0x4
DictionaryLang lang; // 0x6
};

// KeyboardMode keyboardMode; // 0x0
// const char okText[0x8]; // 0x8
// char leftOptionalSymbolKey; // 0x10
// char rightOptionalSymbolKey; // 0x12
// bool isPredictionEnabled; // 0x14
// InvalidChar invalidCharFlag; // 0x18
// InitialCursorPos initialCursorPos; // 0x1C
// const char headerText[0x40]; // 0x20
// const char subText[0x80]; // 0x28
// const char guideText[0x100]; // 0x30
// int textMaxLength; // 0x38
// int textMinLength; // 0x3C
// PasswordMode passwordMode; // 0x40
// InputFormMode inputFormMode; // 0x44
// bool isUseNewLine; // 0x48
// bool isUseUtf8; // 0x49
// bool isUseBlurBackground; // 0x4A
// int _initialStringOffset; // 0x4C
// int _initialStringLength; // 0x50
// int _userDictionaryOffset; // 0x54
// int _userDictionaryNum; // 0x58
// bool _isUseTextCheck; // 0x5C
// void *_textCheckCallback; // 0x60
// int* separateTextPos; // 0x68
// DictionaryInfo* _customizedDicInfoList; // 0x70
// unsigned char _customizedDicCount; // 0x78
// unsigned char* _reserved; // 0x80

struct KeyboardConfig
{
Expand Down Expand Up @@ -193,6 +181,7 @@ namespace nn

ulong GetRequiredWorkBufferSize(bool);
ulong GetRequiredStringBufferSize(void);
nn::applet::ExitReason getExitReason();
void MakePreset(nn::swkbd::KeyboardConfig *,nn::swkbd::Preset);
//void SetHeaderText(nn::swkbd::KeyboardConfig *,char16_t const*);
//void SetSubText(nn::swkbd::KeyboardConfig*, char16_t const*);
Expand All @@ -211,7 +200,9 @@ namespace nn
void SetInitialText(nn::swkbd::ShowKeyboardArg *,char16_t const*);
void SetInitialTextUtf8(nn::swkbd::ShowKeyboardArg *,char const*);
//void SetUserWordList(nn::swkbd::ShowKeyboardArg *,nn::swkbd::UserWord const*,int);
void ShowKeyboard(nn::swkbd::String *,nn::swkbd::ShowKeyboardArg const&);
int ShowKeyboard(nn::swkbd::String*, nn::swkbd::ShowKeyboardArg const&);

__attribute__((used)) static nn::applet::ExitReason g_ExitReason;

} // namespace swkbd
} // namespace nn
19 changes: 13 additions & 6 deletions include/server/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "game/GameData/GameDataHolderWriter.h"
#include "game/GameData/GameDataFunction.h"

#include "heap/seadFrameHeap.h"
#include "heap/seadHeap.h"
#include "layouts/HideAndSeekIcon.h"
#include "rs/util.hpp"
Expand Down Expand Up @@ -180,8 +181,8 @@ class Client {

static void updateShines();

static void openKeyboardIP();
static void openKeyboardPort();
static bool openKeyboardIP();
static bool openKeyboardPort();

static GameModeInfoBase* getModeInfo() {
return sInstance ? sInstance->mModeInfo : nullptr;
Expand All @@ -196,7 +197,15 @@ class Client {

static bool isModeActive() { return sInstance ? sInstance->mIsModeActive : false; }

static bool isSelectedMode(GameMode mode) { return sInstance ? sInstance->mCurMode->getMode() == mode: false; }
static bool isSelectedMode(GameMode mode) {
return sInstance ? sInstance->mCurMode->getMode() == mode : false;
}

static void showConnect();

static void showConnectError(const char16_t* msg);

static void hideConnect();

void resetCollectedShines();

Expand Down Expand Up @@ -227,8 +236,6 @@ class Client {
al::AsyncFunctorThread *mReadThread = nullptr; // TODO: use this thread to send any queued packets
// al::AsyncFunctorThread *mRecvThread; // TODO: use this thread to recieve packets and update PuppetInfo

sead::SafeArray<UIDIndexNode, MAXPUPINDEX> puppetPlayerID;

int mConnectCount = 0;

nn::account::Uid mUserID;
Expand Down Expand Up @@ -286,7 +293,7 @@ class Client {

u8 mScenario = 0;

sead::Heap *mHeap = nullptr; // Heap that Client::sInstance was created in
sead::FrameHeap *mHeap = nullptr; // Custom FrameHeap used for all Client related memory

// --- Mode Info ---

Expand Down
11 changes: 3 additions & 8 deletions source/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ Keyboard::Keyboard(ulong strSize) : mResultString(strSize) {

mCustomizeDicSize = 0x400;
mCustomizeDicBuf = (char*)malloc(mCustomizeDicSize);

mIsDoneKeyboard = false;

}

void Keyboard::keyboardThread() {

mIsDoneKeyboard = false;

nn::swkbd::ShowKeyboardArg keyboardArg = nn::swkbd::ShowKeyboardArg();
nn::swkbd::MakePreset(&keyboardArg.keyboardConfig, nn::swkbd::Preset::Default);
Expand All @@ -44,10 +40,9 @@ void Keyboard::keyboardThread() {
nn::swkbd::SetInitialTextUtf8(&keyboardArg, mInitialText.cstr());
}

nn::swkbd::ShowKeyboard(&mResultString, keyboardArg);

mIsDoneKeyboard = true;

mIsCancelled =
nn::swkbd::ShowKeyboard(&mResultString, keyboardArg) == 671; // no idea what 671 could be

}

void Keyboard::openKeyboard(const char* initialText, KeyboardSetup setupFunc) {
Expand Down
2 changes: 1 addition & 1 deletion source/puppets/PuppetMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void initPuppetActors(al::Scene *scene, al::ActorInitInfo const &rootInfo, char
}

// create a debug puppet for testing purposes
createPuppetActorFromFactory(rootInfo, playerPlacement, true);
// createPuppetActorFromFactory(rootInfo, playerPlacement, true);
}

al::initPlacementObjectMap(scene, rootInfo, listName); // run init for ObjectList after we init our puppet actors
Expand Down
Loading

0 comments on commit 3c4a20a

Please sign in to comment.