Skip to content

Instantly share code, notes, and snippets.

@pqlx
Created August 3, 2018 14:59
Show Gist options
  • Save pqlx/f5355cc7b2aad218711b5eeb08bd3334 to your computer and use it in GitHub Desktop.
Save pqlx/f5355cc7b2aad218711b5eeb08bd3334 to your computer and use it in GitHub Desktop.
get almost perfect .proto files back
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using ProtoBuf;
using MAPAPI;
using PSXAPI;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
DumpFromNamespace("MAPAPI.Request", map_requests);
DumpFromNamespace("MAPAPI.Response", map_responses);
DumpFromNamespace("PSXAPI.Request", game_requests);
DumpFromNamespace("PSXAPI.Response", game_responses);
DumpFromNamespace("PSXAPI.Response.Payload", game_responses_payloads);
Console.ReadLine();
}
static void DumpFromNamespace(string _namespace, string[] types)
{
Random r = new Random();
foreach (string type in types)
{
Type t;
if(_namespace.StartsWith("PSXAPI"))
t = typeof(PSXAPI.Request.Achievements).Assembly.GetType(_namespace + "." + type);
else
t = typeof(MAPAPI.Request.DeleteMap).Assembly.GetType(_namespace + "." + type);
if (!t.IsDefined(typeof(ProtoContractAttribute), false) || t.IsEnum)
{
continue;
}
Console.WriteLine(t);
string proto = typeof(Serializer)
.GetMethod("GetProto", new Type[] { })
.MakeGenericMethod(t)
.Invoke(null, new object[] { }).ToString();
proto = proto.Replace(" [default = 00000000-0000-0000-0000-000000000000]", "");
proto = proto.Replace(" None", " NoneValue");
proto = proto.Replace("return", "_return");
if (!proto.Contains("package " + _namespace))
{
proto = proto.Replace("syntax = \"proto2\";", "syntax = \"proto2\";\n" + "package " + _namespace + r.Next(1, Int32.MaxValue) + ";");
}
else
{
proto = proto.Replace("package " + _namespace, "package " + _namespace + r.Next(1, Int32.MaxValue));
}
var reg = new Regex(@"((?!{\n\s+)enum\s+(.+)\s*\{[a-zA-Z0-9\s=;_,/]+\})(?!\s//PREFIX_AGDFASBV)");
Match m;
List<List<string>> ids = new List<List<string>>();
while (true)
{
string id = r.Next(1, Int32.MaxValue).ToString();
m = reg.Match(proto);
if(!m.Success)
{
break;
}
ids.Add(new List<string>(new string[] { id, m.Groups[2].ToString() }));
proto = reg.Replace(proto, "message PREFIX_AGDFASBV" + id + " {\n $0 //PREFIX_AGDFASBV\n};", 1);
if(!reg.Match(proto).Success)
{
break;
}
if(!m.Success)
{
continue;
}
}
foreach(var id in ids)
{
string random = id[0];
string enum_name = id[1];
reg = new Regex("(repeated|optional|required) (" + enum_name + ")");
proto = reg.Replace(proto, "$1 PREFIX_AGDFASBV" + random + ".$2");
}
System.IO.File.WriteAllText(@"D:\Games\PokeOne\PSXAPI\ConsoleApp1\output\" + _namespace + @"\" + type + ".proto", proto);
}
}
static string[] map_requests =
{
"DeleteMap",
"DestroyMapSession",
"JoinMapSession",
"Login",
"Ping",
"QueryDestroyMapSession",
"RenameMap",
"RequestMap",
"StickyNote",
"UploadMap",
};
static string[] map_responses =
{
"Area",
"AreaList",
"BackgroundType",
"ConfirmDestroySession",
"CreateLINK",
"CreateNPC",
"DebugMessage",
"DeleteMap",
"DrawTile",
"DrawTileStruct",
"EncounterRates",
"EncounterTimes",
"Error",
"ErrorType",
"EvolutionArea",
"FishingType",
"HandleObject",
"HeightChangeStruct",
"HeightTile",
"HeightTilesStruct",
"LeaveSession",
"LINKData",
"LinkPair",
"LinkType",
"MapDump",
"MapList",
"MapObjectStruct",
"MapServerMap",
"MapSettings",
"MoveLINK",
"MoveNPC",
"MoveObject",
"NodeList",
"NPCData",
"NPCObjectStruct",
"NPCSettingStruct",
"PaintPrimitive",
"PaintWall",
"PlayerMouse",
"Rarity",
"RenameMap",
"ResizeMap",
"Settings",
"ShiftMap",
"StickyNote",
"tileInfo",
"UploadResponse",
"wallTypes",
"Zone",
"ZoneItem",
"ZonePokemon",
"Zones"
};
static string[] game_requests = {
"Achievements",
"Area",
"Areas",
"Badges",
"BattleBroadcast",
"BattleItem",
"BattleMove",
"BattleRun",
"BattleShift",
"BattleSwitch",
"BattleTimer",
"ChatJoin",
"ChatJoinAction",
"ChatMessage",
"CheckEmail",
"CheckGuild",
"CheckUser",
"ClientPlatform",
"CreateUser",
"Effect",
"EffectAction",
"Evolve",
"Evs",
"EvsAction",
"FlyEnter",
"FlyExit",
"FlyMove",
"Friends",
"FriendsAction",
"Guild",
"GuildAction",
"GuildEmblem",
"HoldItem",
"Ignore",
"IgnoreAction",
"Inventory",
"Items",
"Ivs",
"IvsAction",
"Learn",
"LobbyAccept",
"LobbyActorState",
"LobbyKick",
"LobbyLeave",
"LobbyMessage",
"LobbyPokemon",
"LobbySettings",
"LobbySwitch",
"Login",
"Logout",
"Loot",
"Lootbox",
"LootboxAction",
"LootboxType",
"LootVote",
"Message",
"MessageEvent",
"MilkDrink",
"Mount",
"Move",
"MoveAction",
"Password",
"PasswordAction",
"Path",
"Ping",
"PlayerDirection",
"Pokedex",
"Pokemon",
"Quest",
"QuestAction",
"Release",
"Reorder",
"Request",
"RequestType",
"Script",
"Search",
"Skin",
"SkinAction",
"Skins",
"SkinType",
"Spin",
"SpinBet",
"Stats",
"StatsSettings",
"Surf",
"Swap",
"Sync",
"Talk",
"Time",
"Trade",
"TradeAction",
"Transfer",
"Upgrade",
"UpgradeType",
"UseItem",
"VerifyEmail",
"VerifyEmailAction",
};
static string[] game_responses =
{
"Achievement",
"Achievements",
"ActorTimer",
"Area",
"Areas",
"Badge",
"Badges",
"Battle",
"BattleBroadcast",
"BattleItem",
"BattleItemResult",
"BattleSide",
"Broadcast",
"BroadcastMessageType",
"ChatJoin",
"ChatJoinResult",
"ChatMessage",
"CheckEmail",
"CheckEmailResult",
"CheckGuild",
"CheckGuildResult",
"CheckUser",
"CheckUserResult",
"CreateUser",
"CreateUserResult",
"DailyLootbox",
"DebugMessage",
"Discovered",
"Effect",
"EffectUpdateType",
"EncounterReset",
"Equip",
"EquipFly",
"EvolutionResult",
"Evolve",
"Evs",
"EvsResult",
"Fishing",
"FlyStart",
"FlyUsers",
"Friends",
"FriendsAction",
"GameDayTime",
"GameSeason",
"Gender",
"Greeting",
"Guild",
"GuildActionResult",
"GuildEmblem",
"GuildMember",
"GuildRank",
"GuildResult",
"HoldItem",
"HoldItemResult",
"Ignore",
"IgnoreAction",
"Inventory",
"InventoryItem",
"InventoryPokemon",
"ItemCategory",
"ItemPocket",
"Items",
"ItemTarget",
"Ivs",
"IvsResult",
"Learn",
"LearnResult",
"Level",
"Lobby",
"LobbyMessage",
"LobbyRemove",
"LobbyRemoveReason",
"Login",
"LoginError",
"LoginResult",
"Logout",
"Loot",
"Lootbox",
"LootboxAction",
"LootboxType",
"LootVote",
"LootVoteResult",
"MapUsers",
"MemberRank",
"Message",
"MessageEvent",
"Money",
"Mount",
"MountType",
"Move",
"MoveAction",
"MovePlayer",
"MovePlayerAction",
"Party",
"PartyPokemon",
"PartyRemove",
"PartyRemoveReason",
"Password",
"PasswordResult",
"Path",
"Ping",
"PlayerDirection",
"Pokedex",
"PokedexUpdate",
"Pokemon",
"Quest",
"QuestProgressType",
"QuestType",
"RegionUpdate",
"Release",
"ReleaseResult",
"Reorder",
"Request",
"RequestType",
"Script",
"ScriptRequestType",
"Search",
"Skin",
"SkinAction",
"Skins",
"Spin",
"StaffRank",
"Stats",
"StatsResult",
"Style",
"Sync",
"Thunder",
"Time",
"Trade",
"TradeError",
"TradeUpdateType",
"Transfer",
"TransferResult",
"Upgrade",
"UpgradeResult",
"UseItem",
"UseItemResult",
"VerifyEmail",
"VerifyEmailResult",
"WeatherState",
};
static string[] game_responses_payloads =
{
"AbilitySlotType",
"Achievement",
"ActorAvatarType",
"ActorTeam",
"ActorType",
"AreaPokemon",
"Banned",
"BattleActive",
"BattleMove",
"BattlePokemon",
"BattlePokemonStats",
"BattleRequest",
"BattleRequestData",
"BattleSide",
"ChatMessage",
"Effect",
"EffectUseType",
"EggState",
"FlyUser",
"FlyUserAction",
"FlyUserActionData",
"FlyUserData",
"FlyUserPosition",
"Friend",
"Ignore",
"LobbyActor",
"LootboxRoll",
"LootType",
"MapUser",
"MapUserAction",
"MapUserActionData",
"MapUserData",
"MapUserPosition",
"PartyMember",
"PokeboxSummary",
"PokedexEntry",
"PokedexEntryState",
"Pokemon",
"PokemonCondition",
"PokemonData",
"PokemonGender",
"PokemonID",
"PokemonMove",
"PokemonMoveID",
"PokemonNatures",
"PokemonStats",
"QuestReward",
"Script",
"Skin",
"SkinType",
"SpinColumn",
"SpinMode",
"SpinWinningSymbol",
"Stats",
"UserSkins",
"ZMove",
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment